add file color for navigation list items which are not PsiElements but could fetch...
[fedora-idea.git] / platform / lang-impl / src / com / intellij / ide / util / MemberChooser.java
blob8270e260e752cd7ba56e7a822a82c5ef4f198bc4
1 /*
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.util;
19 import com.intellij.codeInsight.generation.*;
20 import com.intellij.ide.IdeBundle;
21 import com.intellij.openapi.actionSystem.*;
22 import com.intellij.openapi.application.ApplicationManager;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.ui.DialogWrapper;
25 import com.intellij.openapi.ui.VerticalFlowLayout;
26 import com.intellij.openapi.util.IconLoader;
27 import com.intellij.openapi.util.Pair;
28 import com.intellij.openapi.util.Ref;
29 import com.intellij.openapi.util.SystemInfo;
30 import com.intellij.psi.codeStyle.CodeStyleSettings;
31 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
32 import com.intellij.ui.ColoredTreeCellRenderer;
33 import com.intellij.ui.NonFocusableCheckBox;
34 import com.intellij.ui.TreeSpeedSearch;
35 import com.intellij.ui.TreeToolTipHandler;
36 import com.intellij.ui.treeStructure.Tree;
37 import com.intellij.util.Icons;
38 import com.intellij.util.SmartList;
39 import com.intellij.util.containers.Convertor;
40 import com.intellij.util.containers.FactoryMap;
41 import com.intellij.util.containers.HashMap;
42 import com.intellij.util.ui.UIUtil;
43 import com.intellij.util.ui.tree.TreeUtil;
44 import org.jetbrains.annotations.NonNls;
45 import org.jetbrains.annotations.NotNull;
46 import org.jetbrains.annotations.Nullable;
48 import javax.swing.*;
49 import javax.swing.event.TreeSelectionEvent;
50 import javax.swing.event.TreeSelectionListener;
51 import javax.swing.tree.DefaultMutableTreeNode;
52 import javax.swing.tree.DefaultTreeModel;
53 import javax.swing.tree.TreePath;
54 import javax.swing.tree.TreeSelectionModel;
55 import java.awt.*;
56 import java.awt.event.*;
57 import java.util.*;
58 import java.util.List;
60 public class MemberChooser<T extends ClassMember> extends DialogWrapper implements TypeSafeDataProvider {
61 protected Tree myTree;
62 private DefaultTreeModel myTreeModel;
63 private JCheckBox myCopyJavadocCheckbox;
64 private JCheckBox myInsertOverrideAnnotationCheckbox;
66 private final ArrayList<MemberNode> mySelectedNodes = new ArrayList<MemberNode>();
68 private boolean mySorted = false;
69 private boolean myShowClasses = true;
70 private boolean myAllowEmptySelection = false;
71 private boolean myAllowMultiSelection;
72 private final Project myProject;
73 private final boolean myIsInsertOverrideVisible;
74 private final JComponent myHeaderPanel;
76 private T[] myElements;
77 private final HashMap<MemberNode,ParentNode> myNodeToParentMap = new HashMap<MemberNode, ParentNode>();
78 private final HashMap<ClassMember, MemberNode> myElementToNodeMap = new HashMap<ClassMember, MemberNode>();
79 private final ArrayList<ContainerNode> myContainerNodes = new ArrayList<ContainerNode>();
80 private LinkedHashSet<T> mySelectedElements;
82 @NonNls private static final String PROP_SORTED = "MemberChooser.sorted";
83 @NonNls private static final String PROP_SHOWCLASSES = "MemberChooser.showClasses";
84 @NonNls private static final String PROP_COPYJAVADOC = "MemberChooser.copyJavadoc";
86 public MemberChooser(T[] elements,
87 boolean allowEmptySelection,
88 boolean allowMultiSelection,
89 @NotNull Project project) {
90 this(elements, allowEmptySelection, allowMultiSelection, project, false);
93 public MemberChooser(T[] elements,
94 boolean allowEmptySelection,
95 boolean allowMultiSelection,
96 @NotNull Project project,
97 boolean isInsertOverrideVisible) {
98 this(elements, allowEmptySelection, allowMultiSelection, project, isInsertOverrideVisible, null);
101 public MemberChooser(T[] elements,
102 boolean allowEmptySelection,
103 boolean allowMultiSelection,
104 @NotNull Project project,
105 boolean isInsertOverrideVisible,
106 JComponent headerPanel
108 super(project, true);
109 myAllowEmptySelection = allowEmptySelection;
110 myAllowMultiSelection = allowMultiSelection;
111 myProject = project;
112 myIsInsertOverrideVisible = isInsertOverrideVisible;
113 myHeaderPanel = headerPanel;
114 myTree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));
115 resetElements(elements);
116 init();
119 public void resetElements(T[] elements) {
120 myElements = elements;
121 mySelectedNodes.clear();
122 myNodeToParentMap.clear();
123 myElementToNodeMap.clear();
124 myContainerNodes.clear();
126 ApplicationManager.getApplication().runReadAction(new Runnable() {
127 public void run() {
128 myTreeModel = buildModel();
132 myTree.setModel(myTreeModel);
133 myTree.setRootVisible(false);
135 doSort();
137 TreeUtil.expandAll(myTree);
138 myCopyJavadocCheckbox = new NonFocusableCheckBox(IdeBundle.message("checkbox.copy.javadoc"));
139 if (myIsInsertOverrideVisible) {
140 myInsertOverrideAnnotationCheckbox = new NonFocusableCheckBox(IdeBundle.message("checkbox.insert.at.override"));
143 myTree.doLayout();
147 * should be invoked in read action
149 private DefaultTreeModel buildModel() {
150 final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
151 final Ref<Integer> count = new Ref<Integer>(0);
152 final FactoryMap<MemberChooserObject,ParentNode> map = new FactoryMap<MemberChooserObject,ParentNode>() {
153 protected ParentNode create(final MemberChooserObject key) {
154 ParentNode node = null;
155 if (key instanceof PsiElementMemberChooserObject) {
156 final ContainerNode containerNode = new ContainerNode(rootNode, key, count);
157 node = containerNode;
158 myContainerNodes.add(containerNode);
160 if (node == null) {
161 node = new ParentNode(rootNode, key, count);
163 return node;
167 for (T object : myElements) {
168 final ParentNode parentNode = map.get(object.getParentNodeDelegate());
169 final MemberNode elementNode = new MemberNode(parentNode, object, count);
170 myNodeToParentMap.put(elementNode, parentNode);
171 myElementToNodeMap.put(object, elementNode);
173 return new DefaultTreeModel(rootNode);
176 public void selectElements(ClassMember[] elements) {
177 ArrayList<TreePath> selectionPaths = new ArrayList<TreePath>();
178 for (ClassMember element : elements) {
179 MemberNode treeNode = myElementToNodeMap.get(element);
180 if (treeNode != null) {
181 selectionPaths.add(new TreePath(treeNode.getPath()));
184 myTree.setSelectionPaths(selectionPaths.toArray(new TreePath[selectionPaths.size()]));
188 protected Action[] createActions() {
189 if (myAllowEmptySelection) {
190 return new Action[]{getOKAction(), new SelectNoneAction(), getCancelAction()};
192 else {
193 return new Action[]{getOKAction(), getCancelAction()};
197 protected void doHelpAction() {
200 protected List<JComponent> customizeOptionsPanel() {
201 final SmartList<JComponent> list = new SmartList<JComponent>();
203 if (myIsInsertOverrideVisible) {
204 CodeStyleSettings styleSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings();
205 myInsertOverrideAnnotationCheckbox.setSelected(styleSettings.INSERT_OVERRIDE_ANNOTATION);
206 list.add(myInsertOverrideAnnotationCheckbox);
209 myCopyJavadocCheckbox.setSelected(PropertiesComponent.getInstance().isTrueValue(PROP_COPYJAVADOC));
210 list.add(myCopyJavadocCheckbox);
211 return list;
214 protected JComponent createSouthPanel() {
215 JPanel panel = new JPanel(new GridBagLayout());
217 JPanel optionsPanel = new JPanel(new VerticalFlowLayout());
218 for (final JComponent component : customizeOptionsPanel()) {
219 optionsPanel.add(component);
222 panel.add(
223 optionsPanel,
224 new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
225 new Insets(0, 0, 0, 5), 0, 0)
228 if (myElements == null || myElements.length == 0) {
229 setOKActionEnabled(false);
231 panel.add(
232 super.createSouthPanel(),
233 new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.SOUTH, GridBagConstraints.NONE,
234 new Insets(0, 0, 0, 0), 0, 0)
236 return panel;
239 @Override
240 protected JComponent createNorthPanel() {
241 return myHeaderPanel;
244 protected JComponent createCenterPanel() {
245 JPanel panel = new JPanel(new BorderLayout());
247 // Toolbar
249 DefaultActionGroup group = new DefaultActionGroup();
251 fillToolbarActions(group);
253 group.addSeparator();
255 ExpandAllAction expandAllAction = new ExpandAllAction();
256 expandAllAction.registerCustomShortcutSet(
257 new CustomShortcutSet(
258 KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)),
259 myTree);
260 group.add(expandAllAction);
262 CollapseAllAction collapseAllAction = new CollapseAllAction();
263 collapseAllAction.registerCustomShortcutSet(
264 new CustomShortcutSet(
265 KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)),
266 myTree);
267 group.add(collapseAllAction);
269 panel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(),
270 BorderLayout.NORTH);
272 // Tree
274 myTree.setCellRenderer(new ColoredTreeCellRenderer() {
275 public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded,
276 boolean leaf, int row, boolean hasFocus) {
277 if (value instanceof ElementNode) {
278 ((ElementNode) value).getDelegate().renderTreeNode(this, tree);
283 UIUtil.setLineStyleAngled(myTree);
284 myTree.setRootVisible(false);
285 myTree.setShowsRootHandles(true);
286 myTree.addKeyListener(new TreeKeyListener());
287 myTree.addTreeSelectionListener(new MyTreeSelectionListener());
289 if (!myAllowMultiSelection) {
290 myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
293 if (getRootNode().getChildCount() > 0) {
294 myTree.expandRow(0);
295 myTree.setSelectionRow(1);
297 TreeUtil.expandAll(myTree);
298 new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
299 @Nullable
300 public String convert(TreePath path) {
301 final MemberChooserObject delegate = ((ElementNode)path.getLastPathComponent()).getDelegate();
302 return delegate.getText();
305 myTree.addMouseListener(
306 new MouseAdapter() {
307 public void mouseClicked(MouseEvent e) {
308 if (e.getClickCount() == 2) {
309 if (myTree.getPathForLocation(e.getX(), e.getY()) != null) {
310 doOKAction();
316 TreeToolTipHandler.install(myTree);
317 TreeUtil.installActions(myTree);
318 JScrollPane scrollPane = new JScrollPane(myTree);
319 scrollPane.setPreferredSize(new Dimension(350, 450));
320 panel.add(scrollPane, BorderLayout.CENTER);
322 return panel;
325 protected void fillToolbarActions(DefaultActionGroup group) {
326 SortEmAction sortAction = new SortEmAction();
327 sortAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_MASK)), myTree);
328 setSorted(PropertiesComponent.getInstance().isTrueValue(PROP_SORTED));
329 group.add(sortAction);
331 ShowContainersAction showContainersAction = getShowContainersAction();
332 showContainersAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK)), myTree);
333 setShowClasses(PropertiesComponent.getInstance().isTrueValue(PROP_SHOWCLASSES));
334 group.add(showContainersAction);
337 protected String getDimensionServiceKey() {
338 return "#com.intellij.ide.util.MemberChooser";
341 public JComponent getPreferredFocusedComponent() {
342 return myTree;
345 @Nullable
346 private LinkedHashSet<T> getSelectedElementsList() {
347 return getExitCode() == OK_EXIT_CODE ? mySelectedElements : null;
350 @Nullable
351 public List<T> getSelectedElements() {
352 final LinkedHashSet<T> list = getSelectedElementsList();
353 return list == null ? null : new ArrayList<T>(list);
356 @Nullable
357 public T[] getSelectedElements(T[] a) {
358 LinkedHashSet<T> list = getSelectedElementsList();
359 if (list == null) return null;
360 return list.toArray(a);
363 protected final boolean areElementsSelected() {
364 return mySelectedElements != null && !mySelectedElements.isEmpty();
367 public void setCopyJavadocVisible(boolean state) {
368 myCopyJavadocCheckbox.setVisible(state);
371 public boolean isCopyJavadoc() {
372 return myCopyJavadocCheckbox.isSelected();
375 public boolean isInsertOverrideAnnotation () {
376 return myIsInsertOverrideVisible && myInsertOverrideAnnotationCheckbox.isSelected();
379 private boolean isSorted() {
380 return mySorted;
383 private void setSorted(boolean sorted) {
384 if (mySorted == sorted) return;
385 mySorted = sorted;
386 doSort();
389 private void doSort() {
390 Pair<ElementNode,List<ElementNode>> pair = storeSelection();
392 Enumeration<ParentNode> children = getRootNodeChildren();
393 while (children.hasMoreElements()) {
394 ParentNode classNode = children.nextElement();
395 sortNode(classNode, mySorted);
396 myTreeModel.nodeStructureChanged(classNode);
399 restoreSelection(pair);
402 private static void sortNode(ParentNode node, boolean sorted) {
403 ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>();
404 Enumeration<MemberNode> children = node.children();
405 while (children.hasMoreElements()) {
406 arrayList.add(children.nextElement());
409 Collections.sort(arrayList, sorted ? new AlphaComparator() : new OrderComparator());
411 replaceChildren(node, arrayList);
414 private static void replaceChildren(final DefaultMutableTreeNode node, final Collection<? extends ElementNode> arrayList) {
415 node.removeAllChildren();
416 for (ElementNode child : arrayList) {
417 node.add(child);
421 private void setShowClasses(boolean showClasses) {
422 myShowClasses = showClasses;
424 Pair<ElementNode,List<ElementNode>> selection = storeSelection();
426 DefaultMutableTreeNode root = getRootNode();
427 if (!myShowClasses || myContainerNodes.isEmpty()) {
428 List<ParentNode> otherObjects = new ArrayList<ParentNode>();
429 Enumeration<ParentNode> children = getRootNodeChildren();
430 ParentNode newRoot = new ParentNode(null, new MemberChooserObjectBase(getAllContainersNodeName()), new Ref<Integer>(0));
431 while (children.hasMoreElements()) {
432 final ParentNode nextElement = children.nextElement();
433 if (nextElement instanceof ContainerNode) {
434 final ContainerNode containerNode = (ContainerNode)nextElement;
435 Enumeration<MemberNode> memberNodes = containerNode.children();
436 List<MemberNode> memberNodesList = new ArrayList<MemberNode>();
437 while (memberNodes.hasMoreElements()) {
438 memberNodesList.add(memberNodes.nextElement());
440 for (MemberNode memberNode : memberNodesList) {
441 newRoot.add(memberNode);
443 } else {
444 otherObjects.add(nextElement);
447 replaceChildren(root, otherObjects);
448 sortNode(newRoot, mySorted);
449 if (newRoot.children().hasMoreElements()) root.add(newRoot);
451 else {
452 Enumeration<ParentNode> children = getRootNodeChildren();
453 if (children.hasMoreElements()) {
454 ParentNode allClassesNode = children.nextElement();
455 Enumeration<MemberNode> memberNodes = allClassesNode.children();
456 ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>();
457 while (memberNodes.hasMoreElements()) {
458 arrayList.add(memberNodes.nextElement());
460 for (MemberNode memberNode : arrayList) {
461 myNodeToParentMap.get(memberNode).add(memberNode);
464 replaceChildren(root, myContainerNodes);
466 myTreeModel.nodeStructureChanged(root);
468 TreeUtil.expandAll(myTree);
470 restoreSelection(selection);
473 protected String getAllContainersNodeName() {
474 return IdeBundle.message("node.memberchooser.all.classes");
477 private Enumeration<ParentNode> getRootNodeChildren() {
478 return getRootNode().children();
481 private DefaultMutableTreeNode getRootNode() {
482 return (DefaultMutableTreeNode)myTreeModel.getRoot();
485 private Pair<ElementNode,List<ElementNode>> storeSelection() {
486 List<ElementNode> selectedNodes = new ArrayList<ElementNode>();
487 TreePath[] paths = myTree.getSelectionPaths();
488 if (paths != null) {
489 for (TreePath path : paths) {
490 selectedNodes.add((ElementNode)path.getLastPathComponent());
493 TreePath leadSelectionPath = myTree.getLeadSelectionPath();
494 return Pair.create(leadSelectionPath != null ? (ElementNode)leadSelectionPath.getLastPathComponent() : null, selectedNodes);
498 private void restoreSelection(Pair<ElementNode,List<ElementNode>> pair) {
499 List<ElementNode> selectedNodes = pair.second;
501 DefaultMutableTreeNode root = getRootNode();
503 ArrayList<TreePath> toSelect = new ArrayList<TreePath>();
504 for (ElementNode node : selectedNodes) {
505 if (root.isNodeDescendant(node)) {
506 toSelect.add(new TreePath(node.getPath()));
510 if (!toSelect.isEmpty()) {
511 myTree.setSelectionPaths(toSelect.toArray(new TreePath[toSelect.size()]));
514 ElementNode leadNode = pair.first;
515 if (leadNode != null) {
516 myTree.setLeadSelectionPath(new TreePath(leadNode.getPath()));
520 public void dispose() {
521 PropertiesComponent instance = PropertiesComponent.getInstance();
522 instance.setValue(PROP_SORTED, Boolean.toString(isSorted()));
523 instance.setValue(PROP_SHOWCLASSES, Boolean.toString(myShowClasses));
524 instance.setValue(PROP_COPYJAVADOC, Boolean.toString(myCopyJavadocCheckbox.isSelected()));
526 getContentPane().removeAll();
527 mySelectedNodes.clear();
528 myElements = null;
529 super.dispose();
532 public void calcData(final DataKey key, final DataSink sink) {
533 if (key.equals(LangDataKeys.PSI_ELEMENT)) {
534 if (mySelectedElements != null && !mySelectedElements.isEmpty()) {
535 T selectedElement = mySelectedElements.iterator().next();
536 if (selectedElement instanceof ClassMemberWithElement) {
537 sink.put(LangDataKeys.PSI_ELEMENT, ((ClassMemberWithElement) selectedElement).getElement());
543 private class MyTreeSelectionListener implements TreeSelectionListener {
544 public void valueChanged(TreeSelectionEvent e) {
545 TreePath[] paths = e.getPaths();
546 if (paths == null) return;
547 for (int i = 0; i < paths.length; i++) {
548 Object node = paths[i].getLastPathComponent();
549 if (node instanceof MemberNode) {
550 final MemberNode memberNode = (MemberNode)node;
551 if (e.isAddedPath(i)) {
552 if (!mySelectedNodes.contains(memberNode)) {
553 mySelectedNodes.add(memberNode);
556 else {
557 mySelectedNodes.remove(memberNode);
561 mySelectedElements = new LinkedHashSet<T>();
562 for (MemberNode selectedNode : mySelectedNodes) {
563 mySelectedElements.add((T)selectedNode.getDelegate());
568 private abstract static class ElementNode extends DefaultMutableTreeNode {
569 private final int myOrder;
570 private final MemberChooserObject myDelegate;
572 public ElementNode(@Nullable DefaultMutableTreeNode parent, MemberChooserObject delegate, Ref<Integer> order) {
573 myOrder = order.get();
574 order.set(myOrder + 1);
575 myDelegate = delegate;
576 if (parent != null) {
577 parent.add(this);
581 public MemberChooserObject getDelegate() {
582 return myDelegate;
585 public int getOrder() {
586 return myOrder;
590 private static class MemberNode extends ElementNode {
591 public MemberNode(ParentNode parent, ClassMember delegate, Ref<Integer> order) {
592 super(parent, delegate, order);
596 private static class ParentNode extends ElementNode {
597 public ParentNode(@Nullable DefaultMutableTreeNode parent, MemberChooserObject delegate, Ref<Integer> order) {
598 super(parent, delegate, order);
602 private static class ContainerNode extends ParentNode {
603 public ContainerNode(DefaultMutableTreeNode parent, MemberChooserObject delegate, Ref<Integer> order) {
604 super(parent, delegate, order);
608 private class SelectNoneAction extends AbstractAction {
609 public SelectNoneAction() {
610 super(IdeBundle.message("action.select.none"));
613 public void actionPerformed(ActionEvent e) {
614 myTree.clearSelection();
615 doOKAction();
619 private class TreeKeyListener extends KeyAdapter {
620 public void keyPressed(KeyEvent e) {
621 TreePath path = myTree.getLeadSelectionPath();
622 if (path == null) return;
623 final Object lastComponent = path.getLastPathComponent();
624 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
625 if (lastComponent instanceof ParentNode) return;
626 doOKAction();
627 e.consume();
629 else if (e.getKeyCode() == KeyEvent.VK_INSERT) {
630 if (lastComponent instanceof ElementNode) {
631 final ElementNode node = (ElementNode)lastComponent;
632 if (!mySelectedNodes.contains(node)) {
633 if (node.getNextNode() != null) {
634 myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
637 else {
638 if (node.getNextNode() != null) {
639 myTree.removeSelectionPath(new TreePath(node.getPath()));
640 myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
641 myTree.repaint();
644 e.consume();
650 private class SortEmAction extends ToggleAction {
651 public SortEmAction() {
652 super(IdeBundle.message("action.sort.alphabetically"),
653 IdeBundle.message("action.sort.alphabetically"), IconLoader.getIcon("/objectBrowser/sorted.png"));
656 public boolean isSelected(AnActionEvent event) {
657 return isSorted();
660 public void setSelected(AnActionEvent event, boolean flag) {
661 setSorted(flag);
665 protected ShowContainersAction getShowContainersAction() {
666 return new ShowContainersAction(IdeBundle.message("action.show.classes"), Icons.CLASS_ICON);
669 protected class ShowContainersAction extends ToggleAction {
670 public ShowContainersAction(final String text, final Icon icon) {
671 super(text, text, icon);
674 public boolean isSelected(AnActionEvent event) {
675 return myShowClasses;
678 public void setSelected(AnActionEvent event, boolean flag) {
679 setShowClasses(flag);
682 public void update(AnActionEvent e) {
683 super.update(e);
684 Presentation presentation = e.getPresentation();
685 presentation.setEnabled(myContainerNodes.size() > 1);
689 private class ExpandAllAction extends AnAction {
690 public ExpandAllAction() {
691 super(IdeBundle.message("action.expand.all"), IdeBundle.message("action.expand.all"),
692 IconLoader.getIcon("/actions/expandall.png"));
695 public void actionPerformed(AnActionEvent e) {
696 TreeUtil.expandAll(myTree);
700 private class CollapseAllAction extends AnAction {
701 public CollapseAllAction() {
702 super(IdeBundle.message("action.collapse.all"), IdeBundle.message("action.collapse.all"),
703 IconLoader.getIcon("/actions/collapseall.png"));
706 public void actionPerformed(AnActionEvent e) {
707 TreeUtil.collapseAll(myTree, 1);
711 private static class AlphaComparator implements Comparator<ElementNode> {
712 public int compare(ElementNode n1, ElementNode n2) {
713 return n1.getDelegate().getText().compareToIgnoreCase(n2.getDelegate().getText());
717 private static class OrderComparator implements Comparator<ElementNode> {
718 public int compare(ElementNode n1, ElementNode n2) {
719 if (n1.getDelegate() instanceof ClassMemberWithElement
720 && n2.getDelegate() instanceof ClassMemberWithElement) {
721 return ((ClassMemberWithElement)n1.getDelegate()).getElement().getTextOffset()
722 - ((ClassMemberWithElement)n2.getDelegate()).getElement().getTextOffset();
724 return n1.getOrder() - n2.getOrder();