001: /*******************************************************************************
002: * Copyright (c) 2003, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.plugin;
011:
012: import org.eclipse.jface.dialogs.MessageDialog;
013: import org.eclipse.pde.core.IBaseModel;
014: import org.eclipse.pde.core.plugin.IPlugin;
015: import org.eclipse.pde.core.plugin.IPluginModel;
016: import org.eclipse.pde.core.plugin.IPluginModelBase;
017: import org.eclipse.pde.core.plugin.PluginRegistry;
018: import org.eclipse.pde.internal.core.builders.DependencyLoop;
019: import org.eclipse.pde.internal.core.builders.DependencyLoopFinder;
020: import org.eclipse.pde.internal.ui.PDELabelProvider;
021: import org.eclipse.pde.internal.ui.PDEPlugin;
022: import org.eclipse.pde.internal.ui.PDEPluginImages;
023: import org.eclipse.pde.internal.ui.PDEUIMessages;
024: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
025: import org.eclipse.pde.internal.ui.editor.PDESection;
026: import org.eclipse.pde.internal.ui.search.dependencies.UnusedDependenciesAction;
027: import org.eclipse.pde.internal.ui.views.dependencies.OpenPluginDependenciesAction;
028: import org.eclipse.pde.internal.ui.views.dependencies.OpenPluginReferencesAction;
029: import org.eclipse.swt.widgets.Composite;
030: import org.eclipse.ui.forms.events.HyperlinkAdapter;
031: import org.eclipse.ui.forms.events.HyperlinkEvent;
032: import org.eclipse.ui.forms.widgets.ExpandableComposite;
033: import org.eclipse.ui.forms.widgets.FormText;
034: import org.eclipse.ui.forms.widgets.FormToolkit;
035: import org.eclipse.ui.forms.widgets.Section;
036:
037: public class DependencyAnalysisSection extends PDESection {
038: private FormText formText;
039:
040: public DependencyAnalysisSection(PDEFormPage page,
041: Composite parent, int style) {
042: super (page, parent, ExpandableComposite.TITLE_BAR
043: | ExpandableComposite.TWISTIE | style);
044: createClient(getSection(), page.getEditor().getToolkit());
045: }
046:
047: private String getFormText() {
048: boolean editable = getPage().getModel().isEditable();
049: if (getPage().getModel() instanceof IPluginModel) {
050: if (editable)
051: return PDEUIMessages.DependencyAnalysisSection_plugin_editable;
052: return PDEUIMessages.DependencyAnalysisSection_plugin_notEditable;
053: }
054: if (editable)
055: return PDEUIMessages.DependencyAnalysisSection_fragment_editable;
056: return PDEUIMessages.DependencyAnalysisSection_fragment_notEditable;
057: }
058:
059: /* (non-Javadoc)
060: * @see org.eclipse.pde.internal.ui.neweditor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
061: */
062: protected void createClient(Section section, FormToolkit toolkit) {
063: section.setText(PDEUIMessages.DependencyAnalysisSection_title);
064:
065: formText = toolkit.createFormText(section, true);
066: formText.setText(getFormText(), true, false);
067: PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
068: formText.setImage(
069: "loops", lp.get(PDEPluginImages.DESC_LOOP_OBJ)); //$NON-NLS-1$
070: formText.setImage(
071: "search", lp.get(PDEPluginImages.DESC_PSEARCH_OBJ)); //$NON-NLS-1$
072: formText.setImage(
073: "hierarchy", lp.get(PDEPluginImages.DESC_CALLEES)); //$NON-NLS-1$
074: formText.setImage(
075: "dependencies", lp.get(PDEPluginImages.DESC_CALLERS)); //$NON-NLS-1$
076: formText.addHyperlinkListener(new HyperlinkAdapter() {
077: public void linkActivated(HyperlinkEvent e) {
078: if (e.getHref().equals("unused")) //$NON-NLS-1$
079: doFindUnusedDependencies();
080: else if (e.getHref().equals("loops")) //$NON-NLS-1$
081: doFindLoops();
082: else if (e.getHref().equals("references")) //$NON-NLS-1$
083: new OpenPluginReferencesAction(PluginRegistry
084: .findModel(getProject())).run();
085: else if (e.getHref().equals("hierarchy")) //$NON-NLS-1$
086: new OpenPluginDependenciesAction(PluginRegistry
087: .findModel(getProject())).run();
088: }
089: });
090:
091: section.setClient(formText);
092: }
093:
094: protected void doFindLoops() {
095: IBaseModel model = getPage().getModel();
096: if (model instanceof IPluginModel) {
097: IPlugin plugin = ((IPluginModel) model).getPlugin();
098: DependencyLoop[] loops = DependencyLoopFinder
099: .findLoops(plugin);
100: if (loops.length == 0)
101: MessageDialog
102: .openInformation(
103: PDEPlugin.getActiveWorkbenchShell(),
104: PDEUIMessages.DependencyAnalysisSection_loops,
105: PDEUIMessages.DependencyAnalysisSection_noCycles); //
106: else {
107: LoopDialog dialog = new LoopDialog(PDEPlugin
108: .getActiveWorkbenchShell(), loops);
109: dialog.open();
110: }
111: }
112: }
113:
114: protected void doFindUnusedDependencies() {
115: IBaseModel model = getPage().getModel();
116: if (model instanceof IPluginModelBase) {
117: new UnusedDependenciesAction((IPluginModelBase) model,
118: false).run();
119: }
120: }
121:
122: }
|