KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > JavaOutlineInformationControl


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.text;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.OperationCanceledException;
21
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.custom.BusyIndicator;
24 import org.eclipse.swt.events.KeyAdapter;
25 import org.eclipse.swt.events.KeyEvent;
26 import org.eclipse.swt.graphics.Color;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.swt.widgets.Text;
31 import org.eclipse.swt.widgets.Tree;
32 import org.eclipse.swt.widgets.TreeItem;
33 import org.eclipse.swt.widgets.Widget;
34
35 import org.eclipse.jface.action.Action;
36 import org.eclipse.jface.action.IAction;
37 import org.eclipse.jface.action.IMenuManager;
38 import org.eclipse.jface.action.Separator;
39 import org.eclipse.jface.resource.JFaceResources;
40 import org.eclipse.jface.viewers.AbstractTreeViewer;
41 import org.eclipse.jface.viewers.TreeViewer;
42 import org.eclipse.jface.viewers.Viewer;
43 import org.eclipse.jface.viewers.ViewerFilter;
44
45 import org.eclipse.ui.IDecoratorManager;
46 import org.eclipse.ui.IEditorPart;
47 import org.eclipse.ui.IWorkbenchPage;
48 import org.eclipse.ui.PlatformUI;
49 import org.eclipse.ui.keys.KeySequence;
50 import org.eclipse.ui.keys.SWTKeySupport;
51
52 import org.eclipse.jdt.core.ICompilationUnit;
53 import org.eclipse.jdt.core.IJavaElement;
54 import org.eclipse.jdt.core.IMember;
55 import org.eclipse.jdt.core.IMethod;
56 import org.eclipse.jdt.core.IType;
57 import org.eclipse.jdt.core.ITypeHierarchy;
58 import org.eclipse.jdt.core.ITypeRoot;
59 import org.eclipse.jdt.core.JavaModelException;
60
61 import org.eclipse.jdt.internal.corext.util.Messages;
62 import org.eclipse.jdt.internal.corext.util.MethodOverrideTester;
63 import org.eclipse.jdt.internal.corext.util.SuperTypeHierarchyCache;
64
65 import org.eclipse.jdt.ui.JavaElementLabels;
66 import org.eclipse.jdt.ui.OverrideIndicatorLabelDecorator;
67 import org.eclipse.jdt.ui.ProblemsLabelDecorator;
68 import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
69
70 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
71 import org.eclipse.jdt.internal.ui.JavaPlugin;
72 import org.eclipse.jdt.internal.ui.JavaPluginImages;
73 import org.eclipse.jdt.internal.ui.JavaUIMessages;
74 import org.eclipse.jdt.internal.ui.actions.CategoryFilterActionGroup;
75 import org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter;
76 import org.eclipse.jdt.internal.ui.util.StringMatcher;
77 import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
78 import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
79 import org.eclipse.jdt.internal.ui.viewsupport.MemberFilter;
80
81 /**
82  * Show outline in light-weight control.
83  *
84  * @since 2.1
85  */

86 public class JavaOutlineInformationControl extends AbstractInformationControl {
87
88     private KeyAdapter fKeyAdapter;
89     private OutlineContentProvider fOutlineContentProvider;
90     private IJavaElement fInput= null;
91
92     private OutlineSorter fOutlineSorter;
93
94     private OutlineLabelProvider fInnerLabelProvider;
95
96     private boolean fShowOnlyMainType;
97     private LexicalSortingAction fLexicalSortingAction;
98     private SortByDefiningTypeAction fSortByDefiningTypeAction;
99     private ShowOnlyMainTypeAction fShowOnlyMainTypeAction;
100     private Map JavaDoc fTypeHierarchies= new HashMap JavaDoc();
101     
102     /**
103      * Category filter action group.
104      * @since 3.2
105      */

106     private CategoryFilterActionGroup fCategoryFilterActionGroup;
107     private String JavaDoc fPattern;
108
109     private class OutlineLabelProvider extends AppearanceAwareLabelProvider {
110
111         private boolean fShowDefiningType;
112
113         private OutlineLabelProvider() {
114             super(AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.F_APP_TYPE_SIGNATURE | JavaElementLabels.ALL_CATEGORY, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS);
115         }
116
117         /*
118          * @see ILabelProvider#getText
119          */

120         public String JavaDoc getText(Object JavaDoc element) {
121             String JavaDoc text= super.getText(element);
122             if (fShowDefiningType) {
123                 try {
124                     IType type= getDefiningType(element);
125                     if (type != null) {
126                         StringBuffer JavaDoc buf= new StringBuffer JavaDoc(super.getText(type));
127                         buf.append(JavaElementLabels.CONCAT_STRING);
128                         buf.append(text);
129                         return buf.toString();
130                     }
131                 } catch (JavaModelException e) {
132                 }
133             }
134             return text;
135         }
136
137         /*
138          * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getForeground(java.lang.Object)
139          */

140         public Color getForeground(Object JavaDoc element) {
141             if (fOutlineContentProvider.isShowingInheritedMembers()) {
142                 if (element instanceof IJavaElement) {
143                     IJavaElement je= (IJavaElement)element;
144                     if (fInput.getElementType() == IJavaElement.CLASS_FILE)
145                         je= je.getAncestor(IJavaElement.CLASS_FILE);
146                     else
147                         je= je.getAncestor(IJavaElement.COMPILATION_UNIT);
148                     if (fInput.equals(je)) {
149                         return null;
150                     }
151                 }
152                 return JFaceResources.getColorRegistry().get(ColoredViewersManager.INHERITED_COLOR_NAME);
153             }
154             return null;
155         }
156
157         public void setShowDefiningType(boolean showDefiningType) {
158             fShowDefiningType= showDefiningType;
159         }
160
161         public boolean isShowDefiningType() {
162             return fShowDefiningType;
163         }
164         
165         private IType getDefiningType(Object JavaDoc element) throws JavaModelException {
166             int kind= ((IJavaElement) element).getElementType();
167         
168             if (kind != IJavaElement.METHOD && kind != IJavaElement.FIELD && kind != IJavaElement.INITIALIZER) {
169                 return null;
170             }
171             IType declaringType= ((IMember) element).getDeclaringType();
172             if (kind != IJavaElement.METHOD) {
173                 return declaringType;
174             }
175             ITypeHierarchy hierarchy= getSuperTypeHierarchy(declaringType);
176             if (hierarchy == null) {
177                 return declaringType;
178             }
179             IMethod method= (IMethod) element;
180             MethodOverrideTester tester= new MethodOverrideTester(declaringType, hierarchy);
181             IMethod res= tester.findDeclaringMethod(method, true);
182             if (res == null || method.equals(res)) {
183                 return declaringType;
184             }
185             return res.getDeclaringType();
186         }
187     }
188
189
190     private class OutlineTreeViewer extends TreeViewer {
191
192         private boolean fIsFiltering= false;
193
194         private OutlineTreeViewer(Tree tree) {
195             super(tree);
196             
197         }
198
199         /**
200          * {@inheritDoc}
201          */

202         protected Object JavaDoc[] getFilteredChildren(Object JavaDoc parent) {
203             Object JavaDoc[] result = getRawChildren(parent);
204             int unfilteredChildren= result.length;
205             ViewerFilter[] filters = getFilters();
206             if (filters != null) {
207                 for (int i= 0; i < filters.length; i++)
208                     result = filters[i].filter(this, parent, result);
209             }
210             fIsFiltering= unfilteredChildren != result.length;
211             return result;
212         }
213
214         /**
215          * {@inheritDoc}
216          */

217         protected void internalExpandToLevel(Widget node, int level) {
218             if (!fIsFiltering && node instanceof TreeItem && getMatcher() == null) {
219                 TreeItem treeItem= (TreeItem)node;
220                 if (treeItem.getParentItem() != null && treeItem.getData() instanceof IJavaElement) {
221                     IJavaElement je= (IJavaElement) treeItem.getData();
222                     if (je.getElementType() == IJavaElement.IMPORT_CONTAINER || isInnerType(je)) {
223                         setExpanded(treeItem, false);
224                         return;
225                     }
226                 }
227             }
228             super.internalExpandToLevel(node, level);
229         }
230
231         private boolean isInnerType(IJavaElement element) {
232             if (element != null && element.getElementType() == IJavaElement.TYPE) {
233                 IType type= (IType)element;
234                 try {
235                     return type.isMember();
236                 } catch (JavaModelException e) {
237                     IJavaElement parent= type.getParent();
238                     if (parent != null) {
239                         int parentElementType= parent.getElementType();
240                         return (parentElementType != IJavaElement.COMPILATION_UNIT && parentElementType != IJavaElement.CLASS_FILE);
241                     }
242                 }
243             }
244             return false;
245         }
246     }
247
248
249     private class OutlineContentProvider extends StandardJavaElementContentProvider {
250
251         private boolean fShowInheritedMembers;
252
253         /**
254          * Creates a new Outline content provider.
255          *
256          * @param showInheritedMembers <code>true</code> iff inherited members are shown
257          */

258         private OutlineContentProvider(boolean showInheritedMembers) {
259             super(true);
260             fShowInheritedMembers= showInheritedMembers;
261         }
262
263         public boolean isShowingInheritedMembers() {
264             return fShowInheritedMembers;
265         }
266
267         public void toggleShowInheritedMembers() {
268             Tree tree= getTreeViewer().getTree();
269
270             tree.setRedraw(false);
271             fShowInheritedMembers= !fShowInheritedMembers;
272             getTreeViewer().refresh();
273             getTreeViewer().expandToLevel(2);
274
275             // reveal selection
276
Object JavaDoc selectedElement= getSelectedElement();
277             if (selectedElement != null)
278                 getTreeViewer().reveal(selectedElement);
279
280             tree.setRedraw(true);
281         }
282
283         /**
284          * {@inheritDoc}
285          */

286         public Object JavaDoc[] getChildren(Object JavaDoc element) {
287             if (fShowOnlyMainType) {
288                 if (element instanceof ITypeRoot) {
289                     element= ((ITypeRoot)element).findPrimaryType();
290                 }
291
292                 if (element == null)
293                     return NO_CHILDREN;
294             }
295
296             if (fShowInheritedMembers && element instanceof IType) {
297                 IType type= (IType)element;
298                 if (type.getDeclaringType() == null) {
299                     ITypeHierarchy th= getSuperTypeHierarchy(type);
300                     if (th != null) {
301                         List JavaDoc children= new ArrayList JavaDoc();
302                         IType[] superClasses= th.getAllSupertypes(type);
303                         children.addAll(Arrays.asList(super.getChildren(type)));
304                         for (int i= 0, scLength= superClasses.length; i < scLength; i++)
305                             children.addAll(Arrays.asList(super.getChildren(superClasses[i])));
306                         return children.toArray();
307                     }
308                 }
309             }
310             return super.getChildren(element);
311         }
312
313         /**
314          * {@inheritDoc}
315          */

316         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
317             super.inputChanged(viewer, oldInput, newInput);
318             fTypeHierarchies.clear();
319         }
320
321         /**
322          * {@inheritDoc}
323          */

324         public void dispose() {
325             super.dispose();
326             if (fCategoryFilterActionGroup != null) {
327                 fCategoryFilterActionGroup.dispose();
328                 fCategoryFilterActionGroup= null;
329             }
330             fTypeHierarchies.clear();
331         }
332     }
333
334
335     private class ShowOnlyMainTypeAction extends Action {
336
337         private static final String JavaDoc STORE_GO_INTO_TOP_LEVEL_TYPE_CHECKED= "GoIntoTopLevelTypeAction.isChecked"; //$NON-NLS-1$
338

339         private TreeViewer fOutlineViewer;
340
341         private ShowOnlyMainTypeAction(TreeViewer outlineViewer) {
342             super(TextMessages.JavaOutlineInformationControl_GoIntoTopLevelType_label, IAction.AS_CHECK_BOX);
343             setToolTipText(TextMessages.JavaOutlineInformationControl_GoIntoTopLevelType_tooltip);
344             setDescription(TextMessages.JavaOutlineInformationControl_GoIntoTopLevelType_description);
345
346             JavaPluginImages.setLocalImageDescriptors(this, "gointo_toplevel_type.gif"); //$NON-NLS-1$
347

348             PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.GO_INTO_TOP_LEVEL_TYPE_ACTION);
349
350             fOutlineViewer= outlineViewer;
351
352             boolean showclass= getDialogSettings().getBoolean(STORE_GO_INTO_TOP_LEVEL_TYPE_CHECKED);
353             setTopLevelTypeOnly(showclass);
354         }
355
356         /*
357          * @see org.eclipse.jface.action.Action#run()
358          */

359         public void run() {
360             setTopLevelTypeOnly(!fShowOnlyMainType);
361         }
362
363         private void setTopLevelTypeOnly(boolean show) {
364             fShowOnlyMainType= show;
365             setChecked(show);
366
367             Tree tree= fOutlineViewer.getTree();
368             tree.setRedraw(false);
369
370             fOutlineViewer.refresh(false);
371             if (!fShowOnlyMainType)
372                 fOutlineViewer.expandToLevel(2);
373
374
375             // reveal selection
376
Object JavaDoc selectedElement= getSelectedElement();
377             if (selectedElement != null)
378                 fOutlineViewer.reveal(selectedElement);
379
380             tree.setRedraw(true);
381
382             getDialogSettings().put(STORE_GO_INTO_TOP_LEVEL_TYPE_CHECKED, show);
383         }
384     }
385
386     private class OutlineSorter extends AbstractHierarchyViewerSorter {
387
388         /*
389          * @see org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter#getHierarchy(org.eclipse.jdt.core.IType)
390          * @since 3.2
391          */

392         protected ITypeHierarchy getHierarchy(IType type) {
393             return getSuperTypeHierarchy(type);
394         }
395
396         /*
397          * @see org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter#isSortByDefiningType()
398          * @since 3.2
399          */

400         public boolean isSortByDefiningType() {
401             return fSortByDefiningTypeAction.isChecked();
402         }
403
404         /*
405          * @see org.eclipse.jdt.internal.ui.typehierarchy.AbstractHierarchyViewerSorter#isSortAlphabetically()
406          * @since 3.2
407          */

408         public boolean isSortAlphabetically() {
409             return fLexicalSortingAction.isChecked();
410         }
411     }
412
413
414     private class LexicalSortingAction extends Action {
415
416         private static final String JavaDoc STORE_LEXICAL_SORTING_CHECKED= "LexicalSortingAction.isChecked"; //$NON-NLS-1$
417

418         private TreeViewer fOutlineViewer;
419
420         private LexicalSortingAction(TreeViewer outlineViewer) {
421             super(TextMessages.JavaOutlineInformationControl_LexicalSortingAction_label, IAction.AS_CHECK_BOX);
422             setToolTipText(TextMessages.JavaOutlineInformationControl_LexicalSortingAction_tooltip);
423             setDescription(TextMessages.JavaOutlineInformationControl_LexicalSortingAction_description);
424
425             JavaPluginImages.setLocalImageDescriptors(this, "alphab_sort_co.gif"); //$NON-NLS-1$
426

427             fOutlineViewer= outlineViewer;
428
429             boolean checked=getDialogSettings().getBoolean(STORE_LEXICAL_SORTING_CHECKED);
430             setChecked(checked);
431             PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LEXICAL_SORTING_BROWSING_ACTION);
432         }
433
434         public void run() {
435             valueChanged(isChecked(), true);
436         }
437
438         private void valueChanged(final boolean on, boolean store) {
439             setChecked(on);
440             BusyIndicator.showWhile(fOutlineViewer.getControl().getDisplay(), new Runnable JavaDoc() {
441                 public void run() {
442                     fOutlineViewer.refresh(false);
443                 }
444             });
445
446             if (store)
447                 getDialogSettings().put(STORE_LEXICAL_SORTING_CHECKED, on);
448         }
449     }
450
451
452     private class SortByDefiningTypeAction extends Action {
453
454         private static final String JavaDoc STORE_SORT_BY_DEFINING_TYPE_CHECKED= "SortByDefiningType.isChecked"; //$NON-NLS-1$
455

456         private TreeViewer fOutlineViewer;
457
458         /**
459          * Creates the action.
460          *
461          * @param outlineViewer the outline viewer
462          */

463         private SortByDefiningTypeAction(TreeViewer outlineViewer) {
464             super(TextMessages.JavaOutlineInformationControl_SortByDefiningTypeAction_label);
465             setDescription(TextMessages.JavaOutlineInformationControl_SortByDefiningTypeAction_description);
466             setToolTipText(TextMessages.JavaOutlineInformationControl_SortByDefiningTypeAction_tooltip);
467
468             JavaPluginImages.setLocalImageDescriptors(this, "definingtype_sort_co.gif"); //$NON-NLS-1$
469

470             fOutlineViewer= outlineViewer;
471
472             PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SORT_BY_DEFINING_TYPE_ACTION);
473
474             boolean state= getDialogSettings().getBoolean(STORE_SORT_BY_DEFINING_TYPE_CHECKED);
475             setChecked(state);
476             fInnerLabelProvider.setShowDefiningType(state);
477         }
478
479         /*
480          * @see Action#actionPerformed
481          */

482         public void run() {
483             BusyIndicator.showWhile(fOutlineViewer.getControl().getDisplay(), new Runnable JavaDoc() {
484                 public void run() {
485                     fInnerLabelProvider.setShowDefiningType(isChecked());
486                     getDialogSettings().put(STORE_SORT_BY_DEFINING_TYPE_CHECKED, isChecked());
487
488                     setMatcherString(fPattern, false);
489                     fOutlineViewer.refresh(true);
490
491                     // reveal selection
492
Object JavaDoc selectedElement= getSelectedElement();
493                     if (selectedElement != null)
494                         fOutlineViewer.reveal(selectedElement);
495                 }
496             });
497         }
498     }
499     
500     /**
501      * String matcher that can match two patterns.
502      *
503      * @since 3.2
504      */

505     private static class OrStringMatcher extends StringMatcher {
506         
507         private StringMatcher fMatcher1;
508         private StringMatcher fMatcher2;
509         
510         private OrStringMatcher(String JavaDoc pattern1, String JavaDoc pattern2, boolean ignoreCase, boolean foo) {
511             super("", false, false); //$NON-NLS-1$
512
fMatcher1= new StringMatcher(pattern1, ignoreCase, false);
513             fMatcher2= new StringMatcher(pattern2, ignoreCase, false);
514         }
515         
516         public boolean match(String JavaDoc text) {
517             return fMatcher2.match(text) || fMatcher1.match(text);
518         }
519         
520     }
521
522
523     /**
524      * Creates a new Java outline information control.
525      *
526      * @param parent
527      * @param shellStyle
528      * @param treeStyle
529      * @param commandId
530      */

531     public JavaOutlineInformationControl(Shell parent, int shellStyle, int treeStyle, String JavaDoc commandId) {
532         super(parent, shellStyle, treeStyle, commandId, true);
533     }
534
535     /**
536      * {@inheritDoc}
537      */

538     protected Text createFilterText(Composite parent) {
539         Text text= super.createFilterText(parent);
540         text.addKeyListener(getKeyAdapter());
541         return text;
542     }
543
544     /**
545      * {@inheritDoc}
546      */

547     protected TreeViewer createTreeViewer(Composite parent, int style) {
548         Tree tree= new Tree(parent, SWT.SINGLE | (style & ~SWT.MULTI));
549         GridData gd= new GridData(GridData.FILL_BOTH);
550         gd.heightHint= tree.getItemHeight() * 12;
551         tree.setLayoutData(gd);
552
553         final TreeViewer treeViewer= new OutlineTreeViewer(tree);
554         ColoredViewersManager.install(treeViewer);
555
556         // Hard-coded filters
557
treeViewer.addFilter(new NamePatternFilter());
558         treeViewer.addFilter(new MemberFilter());
559
560         fInnerLabelProvider= new OutlineLabelProvider();
561         fInnerLabelProvider.addLabelDecorator(new ProblemsLabelDecorator(null));
562         IDecoratorManager decoratorMgr= PlatformUI.getWorkbench().getDecoratorManager();
563         if (decoratorMgr.getEnabled("org.eclipse.jdt.ui.override.decorator")) //$NON-NLS-1$
564
fInnerLabelProvider.addLabelDecorator(new OverrideIndicatorLabelDecorator(null));
565
566         treeViewer.setLabelProvider(fInnerLabelProvider);
567
568         fLexicalSortingAction= new LexicalSortingAction(treeViewer);
569         fSortByDefiningTypeAction= new SortByDefiningTypeAction(treeViewer);
570         fShowOnlyMainTypeAction= new ShowOnlyMainTypeAction(treeViewer);
571         fCategoryFilterActionGroup= new CategoryFilterActionGroup(treeViewer, getId(), getInputForCategories());
572
573         fOutlineContentProvider= new OutlineContentProvider(false);
574         treeViewer.setContentProvider(fOutlineContentProvider);
575         fOutlineSorter= new OutlineSorter();
576         treeViewer.setComparator(fOutlineSorter);
577         treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
578
579
580         treeViewer.getTree().addKeyListener(getKeyAdapter());
581
582         return treeViewer;
583     }
584
585     /**
586      * {@inheritDoc}
587      */

588     protected String JavaDoc getStatusFieldText() {
589         KeySequence[] sequences= getInvokingCommandKeySequences();
590         if (sequences == null || sequences.length == 0)
591             return ""; //$NON-NLS-1$
592

593         String JavaDoc keySequence= sequences[0].format();
594
595         if (fOutlineContentProvider.isShowingInheritedMembers())
596             return Messages.format(JavaUIMessages.JavaOutlineControl_statusFieldText_hideInheritedMembers, keySequence);
597         else
598             return Messages.format(JavaUIMessages.JavaOutlineControl_statusFieldText_showInheritedMembers, keySequence);
599     }
600
601     /*
602      * @see org.eclipse.jdt.internal.ui.text.AbstractInformationControl#getId()
603      * @since 3.0
604      */

605     protected String JavaDoc getId() {
606         return "org.eclipse.jdt.internal.ui.text.QuickOutline"; //$NON-NLS-1$
607
}
608
609     /**
610      * {@inheritDoc}
611      */

612     public void setInput(Object JavaDoc information) {
613         if (information == null || information instanceof String JavaDoc) {
614             inputChanged(null, null);
615             return;
616         }
617         IJavaElement je= (IJavaElement)information;
618         ICompilationUnit cu= (ICompilationUnit)je.getAncestor(IJavaElement.COMPILATION_UNIT);
619         if (cu != null)
620             fInput= cu;
621         else
622             fInput= je.getAncestor(IJavaElement.CLASS_FILE);
623
624         inputChanged(fInput, information);
625         
626         fCategoryFilterActionGroup.setInput(getInputForCategories());
627     }
628
629     private KeyAdapter getKeyAdapter() {
630         if (fKeyAdapter == null) {
631             fKeyAdapter= new KeyAdapter() {
632                 public void keyPressed(KeyEvent e) {
633                     int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e);
634                     KeySequence keySequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
635                     KeySequence[] sequences= getInvokingCommandKeySequences();
636                     if (sequences == null)
637                         return;
638                     for (int i= 0; i < sequences.length; i++) {
639                         if (sequences[i].equals(keySequence)) {
640                             e.doit= false;
641                             toggleShowInheritedMembers();
642                             return;
643                         }
644                     }
645                 }
646             };
647         }
648         return fKeyAdapter;
649     }
650
651     /**
652      * {@inheritDoc}
653      */

654     protected void handleStatusFieldClicked() {
655         toggleShowInheritedMembers();
656     }
657
658     protected void toggleShowInheritedMembers() {
659         long flags= fInnerLabelProvider.getTextFlags();
660         flags ^= JavaElementLabels.ALL_POST_QUALIFIED;
661         fInnerLabelProvider.setTextFlags(flags);
662         fOutlineContentProvider.toggleShowInheritedMembers();
663         updateStatusFieldText();
664         fCategoryFilterActionGroup.setInput(getInputForCategories());
665     }
666
667     /*
668      * @see org.eclipse.jdt.internal.ui.text.AbstractInformationControl#fillViewMenu(org.eclipse.jface.action.IMenuManager)
669      */

670     protected void fillViewMenu(IMenuManager viewMenu) {
671         super.fillViewMenu(viewMenu);
672         viewMenu.add(fShowOnlyMainTypeAction);
673
674         viewMenu.add(new Separator("Sorters")); //$NON-NLS-1$
675
viewMenu.add(fLexicalSortingAction);
676
677         viewMenu.add(fSortByDefiningTypeAction);
678         
679         fCategoryFilterActionGroup.setInput(getInputForCategories());
680         fCategoryFilterActionGroup.contributeToViewMenu(viewMenu);
681     }
682     
683     /*
684      * @see org.eclipse.jdt.internal.ui.text.AbstractInformationControl#setMatcherString(java.lang.String, boolean)
685      * @since 3.2
686      */

687     protected void setMatcherString(String JavaDoc pattern, boolean update) {
688         fPattern= pattern;
689         if (pattern.length() == 0 || !fSortByDefiningTypeAction.isChecked()) {
690             super.setMatcherString(pattern, update);
691             return;
692         }
693         
694         boolean ignoreCase= pattern.toLowerCase().equals(pattern);
695         String JavaDoc pattern2= "*" + JavaElementLabels.CONCAT_STRING + pattern; //$NON-NLS-1$
696
fStringMatcher= new OrStringMatcher(pattern, pattern2, ignoreCase, false);
697
698         if (update)
699             stringMatcherUpdated();
700         
701     }
702
703     private IJavaElement[] getInputForCategories() {
704         if (fInput == null)
705             return new IJavaElement[0];
706         
707         if (fOutlineContentProvider.isShowingInheritedMembers()) {
708             IJavaElement p= fInput;
709             if (p instanceof ITypeRoot) {
710                 p= ((ITypeRoot)p).findPrimaryType();
711             }
712             while (p != null && !(p instanceof IType)) {
713                 p= p.getParent();
714             }
715             if (!(p instanceof IType))
716                 return new IJavaElement[] {fInput};
717             
718             ITypeHierarchy hierarchy= getSuperTypeHierarchy((IType)p);
719             if (hierarchy == null)
720                 return new IJavaElement[] {fInput};
721             
722             IType[] supertypes= hierarchy.getAllSupertypes((IType)p);
723             IJavaElement[] result= new IJavaElement[supertypes.length + 1];
724             result[0]= fInput;
725             System.arraycopy(supertypes, 0, result, 1, supertypes.length);
726             return result;
727         } else {
728             return new IJavaElement[] {fInput};
729         }
730     }
731     
732     private ITypeHierarchy getSuperTypeHierarchy(IType type) {
733         ITypeHierarchy th= (ITypeHierarchy)fTypeHierarchies.get(type);
734         if (th == null) {
735             try {
736                 th= SuperTypeHierarchyCache.getTypeHierarchy(type, getProgressMonitor());
737             } catch (JavaModelException e) {
738                 return null;
739             } catch (OperationCanceledException e) {
740                 return null;
741             }
742             fTypeHierarchies.put(type, th);
743         }
744         return th;
745     }
746
747     private IProgressMonitor getProgressMonitor() {
748         IWorkbenchPage wbPage= JavaPlugin.getActivePage();
749         if (wbPage == null)
750             return null;
751
752         IEditorPart editor= wbPage.getActiveEditor();
753         if (editor == null)
754             return null;
755
756         return editor.getEditorSite().getActionBars().getStatusLineManager().getProgressMonitor();
757     }
758     
759 }
760
Popular Tags