KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > views > dependencies > DependenciesView


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.pde.internal.ui.views.dependencies;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.Preferences;
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.action.IContributionItem;
21 import org.eclipse.jface.action.IToolBarManager;
22 import org.eclipse.jface.action.Separator;
23 import org.eclipse.jface.action.SubContributionItem;
24 import org.eclipse.jface.viewers.IStructuredSelection;
25 import org.eclipse.osgi.util.NLS;
26 import org.eclipse.pde.core.plugin.IPlugin;
27 import org.eclipse.pde.core.plugin.IPluginModel;
28 import org.eclipse.pde.core.plugin.IPluginModelBase;
29 import org.eclipse.pde.core.plugin.PluginRegistry;
30 import org.eclipse.pde.internal.core.PDECore;
31 import org.eclipse.pde.internal.core.builders.DependencyLoop;
32 import org.eclipse.pde.internal.core.builders.DependencyLoopFinder;
33 import org.eclipse.pde.internal.ui.IHelpContextIds;
34 import org.eclipse.pde.internal.ui.IPreferenceConstants;
35 import org.eclipse.pde.internal.ui.PDEPlugin;
36 import org.eclipse.pde.internal.ui.PDEPluginImages;
37 import org.eclipse.pde.internal.ui.PDEUIMessages;
38 import org.eclipse.pde.internal.ui.editor.plugin.LoopDialog;
39 import org.eclipse.swt.custom.BusyIndicator;
40 import org.eclipse.swt.graphics.Image;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.ui.IActionBars;
43 import org.eclipse.ui.IMemento;
44 import org.eclipse.ui.IPropertyListener;
45 import org.eclipse.ui.IViewSite;
46 import org.eclipse.ui.IWorkbenchPart;
47 import org.eclipse.ui.IWorkbenchPartSite;
48 import org.eclipse.ui.PartInitException;
49 import org.eclipse.ui.PlatformUI;
50 import org.eclipse.ui.part.IPage;
51 import org.eclipse.ui.part.IPageBookViewPage;
52 import org.eclipse.ui.part.PageBook;
53 import org.eclipse.ui.part.PageBookView;
54
55 public class DependenciesView extends PageBookView implements
56         IPreferenceConstants, IHelpContextIds {
57     
58     static class DummyPart implements IWorkbenchPart {
59         public void addPropertyListener(IPropertyListener listener) {/* dummy */
60         }
61
62         public void createPartControl(Composite parent) {/* dummy */
63         }
64
65         public void dispose() {/* dummy */
66         }
67
68         public Object JavaDoc getAdapter(Class JavaDoc adapter) {
69             return null;
70         }
71
72         public IWorkbenchPartSite getSite() {
73             return null;
74         }
75
76         public String JavaDoc getTitle() {
77             return null;
78         }
79
80         public Image getTitleImage() {
81             return null;
82         }
83
84         public String JavaDoc getTitleToolTip() {
85             return null;
86         }
87
88         public void removePropertyListener(IPropertyListener listener) {/* dummy */
89         }
90
91         public void setFocus() {/* dummy */
92         }
93     }
94
95     class ShowLoopsAction extends Action {
96
97         public ShowLoopsAction() {
98             super("", AS_PUSH_BUTTON); //$NON-NLS-1$
99
setText(PDEUIMessages.DependenciesView_ShowLoopsAction_label);
100             setDescription(PDEUIMessages.DependenciesView_ShowLoopsAction_description);
101             setToolTipText(PDEUIMessages.DependenciesView_ShowLoopsAction_tooltip);
102             setImageDescriptor(PDEPluginImages.DESC_DEP_LOOP);
103             setDisabledImageDescriptor(PDEPluginImages.DESC_DEP_LOOP_DISABLED);
104             setEnabled(false);
105         }
106
107         /*
108          * @see Action#actionPerformed
109          */

110         public void run() {
111             LoopDialog dialog = new LoopDialog(PDEPlugin
112                     .getActiveWorkbenchShell(), fLoops);
113             dialog.open();
114         }
115     }
116
117     class ShowCalleesAction extends Action {
118
119         public ShowCalleesAction() {
120             super("", AS_RADIO_BUTTON); //$NON-NLS-1$
121
setText(PDEUIMessages.DependenciesView_ShowCalleesAction_label);
122             setDescription(PDEUIMessages.DependenciesView_ShowCalleesAction_description);
123             setToolTipText(PDEUIMessages.DependenciesView_ShowCalleesAction_tooltip);
124             setImageDescriptor(PDEPluginImages.DESC_CALLEES);
125             setDisabledImageDescriptor(PDEPluginImages.DESC_CALLEES_DISABLED);
126         }
127
128         /*
129          * @see Action#actionPerformed
130          */

131         public void run() {
132             if (isChecked()) {
133                 fPreferences.setValue(DEPS_VIEW_SHOW_CALLERS, false);
134                 setViewType(false);
135             }
136         }
137     }
138
139     class ShowCallersAction extends Action {
140         public ShowCallersAction() {
141             super("", AS_RADIO_BUTTON); //$NON-NLS-1$
142
setText(PDEUIMessages.DependenciesView_ShowCallersAction_label);
143             setDescription(PDEUIMessages.DependenciesView_ShowCallersAction_description);
144             setToolTipText(PDEUIMessages.DependenciesView_ShowCallersAction_tooltip);
145             setImageDescriptor(PDEPluginImages.DESC_CALLERS);
146             setDisabledImageDescriptor(PDEPluginImages.DESC_CALLERS_DISABLED);
147         }
148
149         /*
150          * @see Action#actionPerformed
151          */

152         public void run() {
153             if (isChecked()) {
154                 fPreferences.setValue(DEPS_VIEW_SHOW_CALLERS, true);
155                 setViewType(true);
156             }
157         }
158     }
159
160     class ShowListAction extends Action {
161         public ShowListAction() {
162             super("", AS_RADIO_BUTTON); //$NON-NLS-1$
163
setText(PDEUIMessages.DependenciesView_ShowListAction_label);
164             setDescription(PDEUIMessages.DependenciesView_ShowListAction_description);
165             setToolTipText(PDEUIMessages.DependenciesView_ShowListAction_tooltip);
166             setImageDescriptor(PDEPluginImages.DESC_FLAT_LAYOUT);
167             setDisabledImageDescriptor(PDEPluginImages.DESC_FLAT_LAYOUT_DISABLED);
168         }
169
170         /*
171          * @see Action#actionPerformed
172          */

173         public void run() {
174             if (isChecked()) {
175                 fPreferences.setValue(DEPS_VIEW_SHOW_LIST, true);
176                 setPresentation(true);
177             }
178         }
179     }
180
181     class ShowTreeAction extends Action {
182
183         public ShowTreeAction() {
184             super("", AS_RADIO_BUTTON); //$NON-NLS-1$
185
setText(PDEUIMessages.DependenciesView_ShowTreeAction_label);
186             setDescription(PDEUIMessages.DependenciesView_ShowTreeAction_description);
187             setToolTipText(PDEUIMessages.DependenciesView_ShowTreeAction_tooltip);
188             setImageDescriptor(PDEPluginImages.DESC_HIERARCHICAL_LAYOUT);
189             setDisabledImageDescriptor(PDEPluginImages.DESC_HIERARCHICAL_LAYOUT_DISABLED);
190         }
191
192         /*
193          * @see Action#actionPerformed
194          */

195         public void run() {
196             if (isChecked()) {
197                 fPreferences.setValue(DEPS_VIEW_SHOW_LIST, false);
198                 setPresentation(false);
199             }
200         }
201     }
202     
203     class ShowStateAction extends Action {
204         
205         public ShowStateAction() {
206             super(PDEUIMessages.DependenciesView_showStateAction_label, IAction.AS_CHECK_BOX);
207             setDescription(PDEUIMessages.DependenciesView_showStateAction_description);
208             setToolTipText(PDEUIMessages.DependenciesView_showStateAction_toolTip);
209             setImageDescriptor(PDEPluginImages.DESC_REQ_PLUGINS_OBJ);
210             setId(SHOW_STATE_ACTION_ID);
211         }
212         
213         /*
214          * @see Action#actionPerformed
215          */

216         public void run() {
217             fPreferences.setValue(DEPS_VIEW_SHOW_STATE, isChecked());
218             enableStateView(isChecked());
219         }
220     }
221
222     protected static final IWorkbenchPart PART_CALLEES_LIST = new DummyPart();
223
224     protected static final IWorkbenchPart PART_CALLEES_TREE = new DummyPart();
225
226     protected static final IWorkbenchPart PART_CALLERS_LIST = new DummyPart();
227
228     protected static final IWorkbenchPart PART_CALLERS_TREE = new DummyPart();
229     
230     protected static final IWorkbenchPart PART_STATE_TREE = new DummyPart();
231
232     public static final String JavaDoc TREE_ACTION_GROUP = "tree"; //$NON-NLS-1$
233

234     protected static final String JavaDoc MEMENTO_KEY_INPUT = "inputPluginId"; //$NON-NLS-1$
235

236     protected static final String JavaDoc SHOW_STATE_ACTION_ID = "show.state.action"; //$NON-NLS-1$
237

238     private static final DependencyLoop[] NO_LOOPS = new DependencyLoop[0];
239     
240     private Map JavaDoc fPagesToParts;
241
242     private Map JavaDoc fPartsToPages;
243
244     private Object JavaDoc fInput;
245
246     private Preferences fPreferences = PDEPlugin.getDefault()
247             .getPluginPreferences();
248
249     private ShowCalleesAction fShowCallees;
250
251     private ShowCallersAction fShowCallers;
252
253     private ShowListAction fShowList;
254
255     private ShowTreeAction fShowTree;
256     
257     private ShowLoopsAction fShowLoops;
258
259     // history of input elements (as Strings). No duplicates
260
private ArrayList JavaDoc fInputHistory;
261     
262     private DependencyLoop[] fLoops;
263     
264     private HistoryDropDownAction fHistoryDropDownAction;
265     
266     private Action fShowState;
267     
268     private IWorkbenchPart fLastDependenciesPart = null;
269     /**
270      *
271      */

272     public DependenciesView() {
273         super();
274         fPartsToPages = new HashMap JavaDoc(4);
275         fPagesToParts = new HashMap JavaDoc(4);
276         fInputHistory= new ArrayList JavaDoc();
277         fLoops = NO_LOOPS;
278     }
279
280     private void contributeToActionBars(IActionBars actionBars) {
281         contributeToLocalToolBar(actionBars.getToolBarManager());
282         actionBars.updateActionBars();
283     }
284
285     private void contributeToLocalToolBar(IToolBarManager manager) {
286         manager.add(new Separator(TREE_ACTION_GROUP));
287         manager.add(new Separator("type")); //$NON-NLS-1$
288
manager.appendToGroup("type", fShowCallees); //$NON-NLS-1$
289
manager.appendToGroup("type", fShowCallers); //$NON-NLS-1$
290
manager.add(new Separator("presentation")); //$NON-NLS-1$
291
manager.appendToGroup("presentation", fShowTree); //$NON-NLS-1$
292
manager.appendToGroup("presentation", fShowList); //$NON-NLS-1$
293
manager.add(new Separator("history")); //$NON-NLS-1$
294
manager.add(fShowLoops);
295         manager.add(fHistoryDropDownAction);
296         manager.add(new Separator("state")); //$NON-NLS-1$
297
manager.add(fShowState);
298         if (PART_STATE_TREE.equals(getCurrentContributingPart()))
299             enableDependenciesActions(false);
300     }
301
302     /*
303      * (non-Javadoc)
304      *
305      * @see org.eclipse.ui.part.PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook)
306      */

307     protected IPage createDefaultPage(PageBook book) {
308         if (fInput == null || fPreferences.getBoolean(DEPS_VIEW_SHOW_STATE))
309             return createPage(PART_STATE_TREE);
310         return createPage(getDefaultPart());
311     }
312     
313     private IWorkbenchPart getDefaultPart() {
314         if (fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS)) {
315             if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) {
316                 return PART_CALLERS_LIST;
317             }
318             return PART_CALLERS_TREE;
319         }
320         if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) {
321             return PART_CALLEES_LIST;
322         }
323         return PART_CALLEES_TREE;
324     }
325
326     /**
327      * part of the part constants
328      */

329     private IPageBookViewPage createPage(IWorkbenchPart part) {
330         IPageBookViewPage page;
331         if (part == PART_CALLEES_TREE) {
332             page = new DependenciesViewTreePage(this,
333                     new CalleesTreeContentProvider(this));
334         } else if (part == PART_CALLEES_LIST) {
335             page = new DependenciesViewListPage(this,
336                     new CalleesListContentProvider(this));
337         } else if (part == PART_CALLERS_TREE) {
338             page = new DependenciesViewTreePage(this,
339                     new CallersTreeContentProvider(this));
340         } else if (part == PART_CALLERS_LIST){
341             page = new DependenciesViewListPage(this,
342                     new CallersListContentProvider(this));
343         } else {
344             page = new StateViewPage(this);
345         }
346
347         initPage(page);
348         page.createControl(getPageBook());
349         fPartsToPages.put(part, page);
350         fPagesToParts.put(page, part);
351         return page;
352     }
353
354     /*
355      * (non-Javadoc)
356      *
357      * @see org.eclipse.ui.part.PageBookView#createPartControl(org.eclipse.swt.widgets.Composite)
358      */

359     public void createPartControl(Composite parent) {
360         super.createPartControl(parent);
361         fShowCallees = new ShowCalleesAction();
362         fShowCallees.setChecked(!fPreferences
363                 .getBoolean(DEPS_VIEW_SHOW_CALLERS));
364         fShowCallers = new ShowCallersAction();
365         fShowCallers
366                 .setChecked(fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS));
367
368         fShowTree = new ShowTreeAction();
369         fShowTree.setChecked(!fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST));
370         fShowList = new ShowListAction();
371         fShowList.setChecked(fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST));
372         
373         fShowLoops = new ShowLoopsAction();
374         fShowLoops.setEnabled(fLoops != NO_LOOPS);
375         
376         fHistoryDropDownAction= new HistoryDropDownAction(this);
377         fHistoryDropDownAction.setEnabled(!fInputHistory.isEmpty());
378         
379         fShowState = new ShowStateAction();
380         fShowState.setChecked(fInput == null || fPreferences.getBoolean(DEPS_VIEW_SHOW_STATE));
381         
382         IActionBars actionBars = getViewSite().getActionBars();
383         contributeToActionBars(actionBars);
384
385         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.DEPENDENCIES_VIEW);
386     }
387
388     /*
389      * (non-Javadoc)
390      *
391      * @see org.eclipse.ui.part.PageBookView#doCreatePage(org.eclipse.ui.IWorkbenchPart)
392      */

393     protected PageRec doCreatePage(IWorkbenchPart part) {
394         IPageBookViewPage page = (IPageBookViewPage) fPartsToPages.get(part);
395         if (page == null && !fPartsToPages.containsKey(part)) {
396             page = createPage(part);
397         }
398         if (page != null) {
399             return new PageRec(part, page);
400         }
401         return null;
402     }
403
404     /*
405      * (non-Javadoc)
406      *
407      * @see org.eclipse.ui.part.PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart,
408      * org.eclipse.ui.part.PageBookView.PageRec)
409      */

410     protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
411         IPage page = pageRecord.page;
412         page.dispose();
413         pageRecord.dispose();
414
415         // empty cross-reference cache
416
fPartsToPages.remove(part);
417     }
418
419     /*
420      * (non-Javadoc)
421      *
422      * @see org.eclipse.ui.part.PageBookView#getBootstrapPart()
423      */

424     protected IWorkbenchPart getBootstrapPart() {
425         if (fInput == null || fPreferences.getBoolean(DEPS_VIEW_SHOW_STATE))
426             return PART_STATE_TREE;
427         return getDefaultPart();
428     }
429
430     /*
431      * (non-Javadoc)
432      *
433      * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite,
434      * org.eclipse.ui.IMemento)
435      */

436     public void init(IViewSite site, IMemento memento) throws PartInitException {
437         super.init(site, memento);
438         if(memento == null)
439             return;
440         String JavaDoc id = memento.getString(MEMENTO_KEY_INPUT);
441         if (id != null) {
442             IPluginModelBase plugin = PluginRegistry.findModel(id);
443             if (plugin != null) {
444                 fInput = plugin;
445                 addHistoryEntry(id);
446                 findLoops();
447             }
448         }
449     }
450
451     /*
452      * (non-Javadoc)
453      *
454      * @see org.eclipse.ui.part.PageBookView#isImportant(org.eclipse.ui.IWorkbenchPart)
455      */

456     protected boolean isImportant(IWorkbenchPart part) {
457         return part instanceof DummyPart;
458     }
459
460     public void openTo(Object JavaDoc object) {
461         // if we are suppose to open to a element and we are in state mode, disable state mode and set focus
462
if (getCurrentContributingPart() == PART_STATE_TREE) {
463             fShowState.setChecked(false);
464             fShowState.run();
465         }
466         if (object != null && !object.equals(fInput)) {
467             if(object instanceof IPluginModelBase){
468                 String JavaDoc id =((IPluginModelBase)object).getPluginBase().getId();
469                 addHistoryEntry(id);
470             }
471         }
472         updateInput(object);
473     }
474     
475     public void openCallersFor(Object JavaDoc object) {
476         if (getCurrentContributingPart() == PART_STATE_TREE)
477             fLastDependenciesPart = (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) ? PART_CALLERS_LIST :
478                 PART_CALLERS_TREE;
479         else if (!fShowCallers.isChecked() && fShowCallees.isChecked()) {
480             fShowCallers.setChecked(true);
481             fShowCallees.setChecked(false);
482             fShowCallers.run();
483         }
484         openTo(object);
485     }
486     
487     public void openCalleesFor(Object JavaDoc object) {
488         if (getCurrentContributingPart() == PART_STATE_TREE)
489             fLastDependenciesPart = (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) ? PART_CALLEES_LIST :
490                 PART_CALLEES_TREE;
491         else if (!fShowCallees.isChecked() && fShowCallers.isChecked()) {
492             fShowCallees.setChecked(true);
493             fShowCallers.setChecked(false);
494             fShowCallees.run();
495         }
496         openTo(object);
497     }
498
499     private void updateInput(Object JavaDoc object) {
500         fInput = object;
501         findLoops();
502         ((DependenciesViewPage) getCurrentPage()).setInput(object);
503     }
504
505     /**
506      *
507      */

508     private void findLoops() {
509         fLoops = NO_LOOPS;
510         if (fInput != null && fInput instanceof IPluginModel) {
511             BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell()
512                     .getDisplay(), new Runnable JavaDoc() {
513                 /*
514                  * (non-Javadoc)
515                  *
516                  * @see java.lang.Runnable#run()
517                  */

518                 public void run() {
519                     IPlugin plugin = ((IPluginModel) fInput).getPlugin();
520                     DependencyLoop[] loops = DependencyLoopFinder
521                             .findLoops(plugin);
522                     if (loops.length > 0) {
523                         fLoops = loops;
524                     }
525                 }
526             });
527         }
528         if(fShowLoops != null)
529             fShowLoops.setEnabled(fLoops != NO_LOOPS);
530     }
531
532     /*
533      * (non-Javadoc)
534      *
535      * @see org.eclipse.ui.part.ViewPart#saveState(org.eclipse.ui.IMemento)
536      */

537     public void saveState(IMemento memento) {
538         super.saveState(memento);
539         if (fInput != null && fInput instanceof IPluginModelBase) {
540             String JavaDoc inputPluginId = ((IPluginModelBase) fInput).getPluginBase()
541                     .getId();
542             memento.putString(MEMENTO_KEY_INPUT, inputPluginId);
543         }
544     }
545
546     void setPresentation(boolean listNotTree) {
547         IWorkbenchPart currentPart = getCurrentContributingPart();
548         if (listNotTree) {
549             if (currentPart == PART_CALLEES_TREE) {
550                 partActivated(PART_CALLEES_LIST);
551             } else if (currentPart == PART_CALLERS_TREE) {
552                 partActivated(PART_CALLERS_LIST);
553             }
554
555         } else {
556             if (currentPart == PART_CALLEES_LIST) {
557                 partActivated(PART_CALLEES_TREE);
558             } else if (currentPart == PART_CALLERS_LIST) {
559                 partActivated(PART_CALLERS_TREE);
560             }
561
562         }
563     }
564
565     void setViewType(boolean callers) {
566         IWorkbenchPart currentPart = getCurrentContributingPart();
567         if (callers) {
568             if (currentPart == PART_CALLEES_TREE) {
569                 partActivated(PART_CALLERS_TREE);
570             } else if (currentPart == PART_CALLEES_LIST) {
571                 partActivated(PART_CALLERS_LIST);
572             }
573
574         } else {
575             if (currentPart == PART_CALLERS_TREE) {
576                 partActivated(PART_CALLEES_TREE);
577             } else if (currentPart == PART_CALLERS_LIST) {
578                 partActivated(PART_CALLEES_LIST);
579             }
580
581         }
582     }
583
584     /*
585      * (non-Javadoc)
586      *
587      * @see org.eclipse.ui.part.PageBookView#showPageRec(org.eclipse.ui.part.PageBookView.PageRec)
588      */

589     protected void showPageRec(PageRec pageRec) {
590         IPage currPage = getCurrentPage();
591         // if we try to show the same page, just call super and return, no use calling any custom functions
592
if (pageRec.page.equals(currPage)) {
593             super.showPageRec(pageRec);
594             return;
595         }
596         IStructuredSelection selection = null;
597         if (currPage instanceof DependenciesViewPage) {
598             selection = ((DependenciesViewPage)currPage).getSelection();
599             ((DependenciesViewPage)currPage).setActive(false);
600         } else if (currPage instanceof StateViewPage) {
601             ((StateViewPage)currPage).setActive(false);
602         }
603         IPage p = pageRec.page;
604         if (p instanceof DependenciesViewPage) {
605             ((DependenciesViewPage) p).setInput(fInput);
606             // configure view before actually showing it
607
((DependenciesViewPage) p).setActive(true);
608         }
609         super.showPageRec(pageRec);
610         if (p instanceof DependenciesViewPage) {
611             updateTitle(fInput);
612             ((DependenciesViewPage) p).setSelection(selection);
613         } else if (p instanceof StateViewPage){
614             ((StateViewPage)p).setActive(true);
615         }
616     }
617
618     void updateTitle(Object JavaDoc newInput) {
619         if (newInput == null) {
620             updateTitle(""); //$NON-NLS-1$
621
} else if (!newInput.equals(PDECore.getDefault().getModelManager())) {
622             String JavaDoc name = PDEPlugin.getDefault().getLabelProvider().getText(
623                     newInput);
624             String JavaDoc title;
625             if (getCurrentContributingPart() == PART_CALLEES_TREE) {
626                 title = NLS.bind(PDEUIMessages.DependenciesView_callees_tree_title, name);
627             } else if (getCurrentContributingPart() == PART_CALLEES_LIST) {
628                 title = NLS.bind(PDEUIMessages.DependenciesView_callees_list_title, name);
629             } else if (getCurrentContributingPart() == PART_CALLERS_TREE) {
630                 title = NLS.bind(PDEUIMessages.DependenciesView_callers_tree_title, name);
631             } else {
632                 title = NLS.bind(PDEUIMessages.DependenciesView_callers_list_title, name);
633             }
634             if(fLoops != NO_LOOPS){
635                 title = title + " " + PDEUIMessages.DependenciesView_cycles_title; //$NON-NLS-1$
636
}
637             updateTitle(title);
638         }
639     }
640     
641     void updateTitle(String JavaDoc description) {
642         setContentDescription(description);
643         setTitleToolTip(getTitle());
644     }
645     
646     /**
647      * Adds the entry if new. Inserted at the beginning of the history entries list.
648      * @param entry The new entry
649      */

650     private void addHistoryEntry(String JavaDoc entry) {
651         if (fInputHistory.contains(entry)) {
652             fInputHistory.remove(entry);
653         }
654         fInputHistory.add(0, entry);
655         if (fHistoryDropDownAction != null)
656             fHistoryDropDownAction.setEnabled(true);
657     }
658     
659     private void updateHistoryEntries() {
660         for (int i= fInputHistory.size() - 1; i >= 0; i--) {
661             String JavaDoc type= (String JavaDoc) fInputHistory.get(i);
662             if (PluginRegistry.findModel(type)==null) {
663                 fInputHistory.remove(i);
664             }
665         }
666         if (fHistoryDropDownAction != null)
667             fHistoryDropDownAction.setEnabled(!fInputHistory.isEmpty());
668     }
669     
670     /**
671      * Goes to the selected entry, without updating the order of history entries.
672      * @param entry The entry to open
673      */

674     public void gotoHistoryEntry(String JavaDoc entry) {
675         if (fInputHistory.contains(entry)) {
676             updateInput(PluginRegistry.findModel(entry));
677         }
678     }
679     
680     /**
681      * Gets all history entries.
682      * @return All history entries
683      */

684     public String JavaDoc[] getHistoryEntries() {
685         if (fInputHistory.size() > 0) {
686             updateHistoryEntries();
687         }
688         return (String JavaDoc[]) fInputHistory.toArray(new String JavaDoc[fInputHistory.size()]);
689     }
690     
691     /**
692      * Sets the history entries
693      * @param elems The history elements to set
694      */

695     public void setHistoryEntries(String JavaDoc[] elems) {
696         fInputHistory.clear();
697         for (int i= 0; i < elems.length; i++) {
698             fInputHistory.add(elems[i]);
699         }
700         updateHistoryEntries();
701     }
702     /**
703      * @return Returns the fInput.
704      */

705     public String JavaDoc getInput() {
706         if(fInput!=null){
707             return ((IPluginModelBase)fInput).getPluginBase().getId();
708         }
709         return null;
710     }
711     
712     public boolean isShowingCallers() {
713         return fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS);
714     }
715     
716     protected void enableStateView(boolean enabled) {
717         if (enabled) {
718             fLastDependenciesPart = getCurrentContributingPart();
719             partActivated(DependenciesView.PART_STATE_TREE);
720         } else {
721             if (fLastDependenciesPart != null)
722                 partActivated(fLastDependenciesPart);
723             else
724                 partActivated(getDefaultPart());
725             fLastDependenciesPart = null;
726         }
727         enableDependenciesActions(!enabled);
728         getViewSite().getActionBars().getToolBarManager().update(true);
729     }
730     
731     // hide the table/tree, caller/callee, history and other action not applicable when showing the State view page
732
private void enableDependenciesActions(boolean enabled) {
733         IContributionItem[] items = getViewSite().getActionBars().getToolBarManager().getItems();
734         for (int i = 0; i < items.length; i++) {
735             if (!(SHOW_STATE_ACTION_ID.equals(items[i].getId()) || "state".equals(items[i].getId())) //$NON-NLS-1$
736
&& !(items[i] instanceof SubContributionItem)) //$NON-NLS-1$
737
items[i].setVisible(enabled);
738         }
739     }
740 }
741
Popular Tags