KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > DependencyAnalysisSection


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.editor.plugin;
12
13 import org.eclipse.jface.dialogs.MessageDialog;
14 import org.eclipse.pde.core.IBaseModel;
15 import org.eclipse.pde.core.plugin.IPlugin;
16 import org.eclipse.pde.core.plugin.IPluginModel;
17 import org.eclipse.pde.core.plugin.IPluginModelBase;
18 import org.eclipse.pde.core.plugin.PluginRegistry;
19 import org.eclipse.pde.internal.core.builders.DependencyLoop;
20 import org.eclipse.pde.internal.core.builders.DependencyLoopFinder;
21 import org.eclipse.pde.internal.ui.PDELabelProvider;
22 import org.eclipse.pde.internal.ui.PDEPlugin;
23 import org.eclipse.pde.internal.ui.PDEPluginImages;
24 import org.eclipse.pde.internal.ui.PDEUIMessages;
25 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
26 import org.eclipse.pde.internal.ui.editor.PDESection;
27 import org.eclipse.pde.internal.ui.search.dependencies.UnusedDependenciesAction;
28 import org.eclipse.pde.internal.ui.views.dependencies.OpenPluginDependenciesAction;
29 import org.eclipse.pde.internal.ui.views.dependencies.OpenPluginReferencesAction;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.ui.forms.events.HyperlinkAdapter;
32 import org.eclipse.ui.forms.events.HyperlinkEvent;
33 import org.eclipse.ui.forms.widgets.ExpandableComposite;
34 import org.eclipse.ui.forms.widgets.FormText;
35 import org.eclipse.ui.forms.widgets.FormToolkit;
36 import org.eclipse.ui.forms.widgets.Section;
37
38 public class DependencyAnalysisSection extends PDESection {
39     private FormText formText;
40
41     public DependencyAnalysisSection(PDEFormPage page, Composite parent, int style) {
42         super(page, parent, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | style);
43         createClient(getSection(), page.getEditor().getToolkit());
44     }
45
46     private String JavaDoc getFormText() {
47         boolean editable = getPage().getModel().isEditable();
48         if (getPage().getModel() instanceof IPluginModel) {
49             if (editable)
50                 return PDEUIMessages.DependencyAnalysisSection_plugin_editable;
51             return PDEUIMessages.DependencyAnalysisSection_plugin_notEditable;
52         }
53         if (editable)
54             return PDEUIMessages.DependencyAnalysisSection_fragment_editable;
55         return PDEUIMessages.DependencyAnalysisSection_fragment_notEditable;
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.pde.internal.ui.neweditor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
60      */

61     protected void createClient(Section section, FormToolkit toolkit) {
62         section.setText(PDEUIMessages.DependencyAnalysisSection_title);
63
64         formText = toolkit.createFormText(section, true);
65         formText.setText(getFormText(), true, false);
66         PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
67         formText.setImage("loops", lp.get(PDEPluginImages.DESC_LOOP_OBJ)); //$NON-NLS-1$
68
formText.setImage("search", lp.get(PDEPluginImages.DESC_PSEARCH_OBJ)); //$NON-NLS-1$
69
formText.setImage("hierarchy", lp.get(PDEPluginImages.DESC_CALLEES)); //$NON-NLS-1$
70
formText.setImage("dependencies", lp.get(PDEPluginImages.DESC_CALLERS)); //$NON-NLS-1$
71
formText.addHyperlinkListener(new HyperlinkAdapter() {
72             public void linkActivated(HyperlinkEvent e) {
73                 if (e.getHref().equals("unused")) //$NON-NLS-1$
74
doFindUnusedDependencies();
75                 else if (e.getHref().equals("loops")) //$NON-NLS-1$
76
doFindLoops();
77                 else if (e.getHref().equals("references")) //$NON-NLS-1$
78
new OpenPluginReferencesAction(PluginRegistry.findModel(getProject())).run();
79                 else if (e.getHref().equals("hierarchy")) //$NON-NLS-1$
80
new OpenPluginDependenciesAction(PluginRegistry.findModel(getProject())).run();
81             }
82         });
83         
84         section.setClient(formText);
85     }
86
87     protected void doFindLoops() {
88         IBaseModel model = getPage().getModel();
89         if (model instanceof IPluginModel) {
90             IPlugin plugin = ((IPluginModel)model).getPlugin();
91             DependencyLoop[] loops = DependencyLoopFinder.findLoops(plugin);
92             if (loops.length == 0)
93                 MessageDialog.openInformation(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.DependencyAnalysisSection_loops, PDEUIMessages.DependencyAnalysisSection_noCycles); //
94
else {
95                 LoopDialog dialog = new LoopDialog(PDEPlugin.getActiveWorkbenchShell(), loops);
96                 dialog.open();
97             }
98         }
99     }
100
101     protected void doFindUnusedDependencies() {
102         IBaseModel model = getPage().getModel();
103         if (model instanceof IPluginModelBase) {
104             new UnusedDependenciesAction((IPluginModelBase)model, false).run();
105         }
106     }
107
108 }
109
Popular Tags