1 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 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 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)); formText.setImage("search", lp.get(PDEPluginImages.DESC_PSEARCH_OBJ)); formText.setImage("hierarchy", lp.get(PDEPluginImages.DESC_CALLEES)); formText.setImage("dependencies", lp.get(PDEPluginImages.DESC_CALLERS)); formText.addHyperlinkListener(new HyperlinkAdapter() { 72 public void linkActivated(HyperlinkEvent e) { 73 if (e.getHref().equals("unused")) doFindUnusedDependencies(); 75 else if (e.getHref().equals("loops")) doFindLoops(); 77 else if (e.getHref().equals("references")) new OpenPluginReferencesAction(PluginRegistry.findModel(getProject())).run(); 79 else if (e.getHref().equals("hierarchy")) 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); 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 |