1 package com
.intellij
.openapi
.roots
.ui
.configuration
;
3 import com
.intellij
.openapi
.actionSystem
.Presentation
;
4 import com
.intellij
.openapi
.ui
.popup
.ListItemDescriptor
;
5 import com
.intellij
.ui
.navigation
.History
;
6 import com
.intellij
.ui
.navigation
.Place
;
7 import com
.intellij
.ui
.popup
.list
.GroupedItemsListRenderer
;
8 import org
.jetbrains
.annotations
.NotNull
;
11 import javax
.swing
.event
.ListSelectionEvent
;
12 import javax
.swing
.event
.ListSelectionListener
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
19 public class SidePanel
extends JPanel
{
21 private final JList myList
;
22 private final DefaultListModel myModel
;
23 private final Place
.Navigator myNavigator
;
24 private final ArrayList
<Place
> myPlaces
= new ArrayList
<Place
>();
26 private final Map
<Integer
, String
> myIndex2Separator
= new HashMap
<Integer
, String
>();
27 private final Map
<Place
, Presentation
> myPlace2Presentation
= new HashMap
<Place
, Presentation
>();
28 private final History myHistory
;
30 public SidePanel(Place
.Navigator navigator
, History history
) {
32 myNavigator
= navigator
;
34 setLayout(new BorderLayout());
36 myModel
= new DefaultListModel();
37 myList
= new JList(myModel
);
39 final ListItemDescriptor descriptor
= new ListItemDescriptor() {
40 public String
getTextFor(final Object value
) {
41 return myPlace2Presentation
.get(value
).getText();
44 public String
getTooltipFor(final Object value
) {
45 return getTextFor(value
);
48 public Icon
getIconFor(final Object value
) {
50 //return myPlace2Presentation.get(value).getIcon();
53 public boolean hasSeparatorAboveOf(final Object value
) {
54 final int index
= myPlaces
.indexOf(value
);
55 return myIndex2Separator
.get(index
) != null;
58 public String
getCaptionAboveOf(final Object value
) {
59 return myIndex2Separator
.get(myPlaces
.indexOf(value
));
63 myList
.setCellRenderer(new GroupedItemsListRenderer(descriptor
));
66 add(new JScrollPane(myList
), BorderLayout
.CENTER
);
67 myList
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
69 myList
.addListSelectionListener(new ListSelectionListener() {
70 public void valueChanged(final ListSelectionEvent e
) {
71 if (e
.getValueIsAdjusting()) return;
72 final Object value
= myList
.getSelectedValue();
74 myNavigator
.navigateTo(((Place
)value
), false);
80 public void addPlace(Place place
, @NotNull Presentation presentation
) {
81 myModel
.addElement(place
);
83 myPlace2Presentation
.put(place
, presentation
);
88 public void addSeparator(String text
) {
89 myIndex2Separator
.put(myPlaces
.size(), text
);
92 public Collection
<Place
> getPlaces() {
96 public void select(final Place place
) {
97 myList
.setSelectedValue(place
, true);