2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.ide
.structureView
.impl
;
19 import com
.intellij
.ide
.structureView
.StructureView
;
20 import com
.intellij
.ide
.structureView
.StructureViewModel
;
21 import com
.intellij
.openapi
.fileEditor
.FileEditor
;
22 import com
.intellij
.openapi
.util
.Disposer
;
23 import com
.intellij
.ui
.TabbedPaneWrapper
;
24 import org
.jetbrains
.annotations
.NotNull
;
27 import javax
.swing
.event
.ChangeEvent
;
28 import javax
.swing
.event
.ChangeListener
;
33 public class StructureViewComposite
implements StructureView
{
34 @NotNull private final StructureViewDescriptor
[] myStructureViews
;
35 @NotNull private StructureViewDescriptor mySelectedViewDescriptor
;
36 @NotNull private final TabbedPaneWrapper myTabbedPaneWrapper
;
38 public static class StructureViewDescriptor
{
39 public final String title
;
40 public final StructureView structureView
;
41 public final Icon icon
;
43 public StructureViewDescriptor(final String title
, @NotNull StructureView structureView
, Icon icon
) {
45 this.structureView
= structureView
;
50 public StructureViewComposite(@NotNull StructureViewDescriptor
... views
) {
51 myStructureViews
= views
;
52 for (StructureViewDescriptor descriptor
: views
) {
53 Disposer
.register(this, descriptor
.structureView
);
55 mySelectedViewDescriptor
= views
[0];
56 myTabbedPaneWrapper
= new TabbedPaneWrapper(this);
57 for (StructureViewDescriptor descriptor
: views
) {
58 myTabbedPaneWrapper
.addTab(descriptor
.title
, descriptor
.icon
, descriptor
.structureView
.getComponent(), null);
60 myTabbedPaneWrapper
.setSelectedIndex(0);
61 myTabbedPaneWrapper
.addChangeListener(new ChangeListener() {
62 public void stateChanged(ChangeEvent e
) {
63 int index
= myTabbedPaneWrapper
.getSelectedIndex();
64 mySelectedViewDescriptor
= myStructureViews
[index
];
69 public StructureView
getSelectedStructureView() {
70 return mySelectedViewDescriptor
.structureView
;
73 public void setStructureView(int index
, StructureViewDescriptor view
) {
74 myStructureViews
[index
] = view
;
75 Disposer
.register(this, view
.structureView
);
78 public FileEditor
getFileEditor() {
79 return getSelectedStructureView().getFileEditor();
82 public boolean navigateToSelectedElement(final boolean requestFocus
) {
83 return getSelectedStructureView().navigateToSelectedElement(requestFocus
);
86 public JComponent
getComponent() {
87 return myTabbedPaneWrapper
.getComponent();
90 public void dispose() {
93 public void centerSelectedRow() {
94 getSelectedStructureView().centerSelectedRow();
97 public void restoreState() {
98 for (StructureViewDescriptor descriptor
: myStructureViews
) {
99 descriptor
.structureView
.restoreState();
103 public void storeState() {
104 for (StructureViewDescriptor descriptor
: myStructureViews
) {
105 descriptor
.structureView
.storeState();
110 public StructureViewDescriptor
[] getStructureViews() {
111 return myStructureViews
;
114 public StructureViewModel
getTreeModel() {
115 return getSelectedStructureView().getTreeModel();