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.
16 package com
.intellij
.openapi
.roots
.ui
.configuration
;
18 import com
.intellij
.openapi
.actionSystem
.Presentation
;
19 import com
.intellij
.openapi
.ui
.popup
.ListItemDescriptor
;
20 import com
.intellij
.ui
.navigation
.History
;
21 import com
.intellij
.ui
.navigation
.Place
;
22 import com
.intellij
.ui
.popup
.list
.GroupedItemsListRenderer
;
23 import org
.jetbrains
.annotations
.NotNull
;
26 import javax
.swing
.event
.ListSelectionEvent
;
27 import javax
.swing
.event
.ListSelectionListener
;
29 import java
.util
.ArrayList
;
30 import java
.util
.Collection
;
31 import java
.util
.HashMap
;
34 public class SidePanel
extends JPanel
{
36 private final JList myList
;
37 private final DefaultListModel myModel
;
38 private final Place
.Navigator myNavigator
;
39 private final ArrayList
<Place
> myPlaces
= new ArrayList
<Place
>();
41 private final Map
<Integer
, String
> myIndex2Separator
= new HashMap
<Integer
, String
>();
42 private final Map
<Place
, Presentation
> myPlace2Presentation
= new HashMap
<Place
, Presentation
>();
43 private final History myHistory
;
45 public SidePanel(Place
.Navigator navigator
, History history
) {
47 myNavigator
= navigator
;
49 setLayout(new BorderLayout());
51 myModel
= new DefaultListModel();
52 myList
= new JList(myModel
);
54 final ListItemDescriptor descriptor
= new ListItemDescriptor() {
55 public String
getTextFor(final Object value
) {
56 return myPlace2Presentation
.get(value
).getText();
59 public String
getTooltipFor(final Object value
) {
60 return getTextFor(value
);
63 public Icon
getIconFor(final Object value
) {
65 //return myPlace2Presentation.get(value).getIcon();
68 public boolean hasSeparatorAboveOf(final Object value
) {
69 final int index
= myPlaces
.indexOf(value
);
70 return myIndex2Separator
.get(index
) != null;
73 public String
getCaptionAboveOf(final Object value
) {
74 return myIndex2Separator
.get(myPlaces
.indexOf(value
));
78 myList
.setCellRenderer(new GroupedItemsListRenderer(descriptor
));
81 add(new JScrollPane(myList
), BorderLayout
.CENTER
);
82 myList
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
84 myList
.addListSelectionListener(new ListSelectionListener() {
85 public void valueChanged(final ListSelectionEvent e
) {
86 if (e
.getValueIsAdjusting()) return;
87 final Object value
= myList
.getSelectedValue();
89 myNavigator
.navigateTo(((Place
)value
), false);
95 public void addPlace(Place place
, @NotNull Presentation presentation
) {
96 myModel
.addElement(place
);
98 myPlace2Presentation
.put(place
, presentation
);
103 public void addSeparator(String text
) {
104 myIndex2Separator
.put(myPlaces
.size(), text
);
107 public Collection
<Place
> getPlaces() {
111 public void select(final Place place
) {
112 myList
.setSelectedValue(place
, true);