KickJava   Java API By Example, From Geeks To Geeks.

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


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.editor.plugin;
12 import java.lang.reflect.InvocationTargetException JavaDoc;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.dialogs.MessageDialog;
18 import org.eclipse.jface.operation.IRunnableWithProgress;
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.pde.core.build.IBuild;
22 import org.eclipse.pde.core.build.IBuildEntry;
23 import org.eclipse.pde.core.build.IBuildModel;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25 import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
26 import org.eclipse.pde.internal.ui.IHelpContextIds;
27 import org.eclipse.pde.internal.ui.IPDEUIConstants;
28 import org.eclipse.pde.internal.ui.PDELabelProvider;
29 import org.eclipse.pde.internal.ui.PDEPlugin;
30 import org.eclipse.pde.internal.ui.PDEPluginImages;
31 import org.eclipse.pde.internal.ui.PDEUIMessages;
32 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
33 import org.eclipse.pde.internal.ui.editor.LaunchShortcutOverviewPage;
34 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
35 import org.eclipse.pde.internal.ui.editor.build.BuildInputContext;
36 import org.eclipse.pde.internal.ui.editor.build.BuildPage;
37 import org.eclipse.pde.internal.ui.editor.context.InputContext;
38 import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
39 import org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction;
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.ui.IEditorInput;
43 import org.eclipse.ui.PartInitException;
44 import org.eclipse.ui.PlatformUI;
45 import org.eclipse.ui.forms.IManagedForm;
46 import org.eclipse.ui.forms.editor.FormEditor;
47 import org.eclipse.ui.forms.events.HyperlinkEvent;
48 import org.eclipse.ui.forms.widgets.FormText;
49 import org.eclipse.ui.forms.widgets.FormToolkit;
50 import org.eclipse.ui.forms.widgets.ScrolledForm;
51 import org.eclipse.ui.forms.widgets.Section;
52 import org.eclipse.ui.forms.widgets.TableWrapData;
53 import org.eclipse.ui.part.FileEditorInput;
54 import org.eclipse.ui.progress.IProgressService;
55 import org.osgi.service.prefs.BackingStoreException;
56
57
58 public class OverviewPage extends LaunchShortcutOverviewPage {
59     public static final String JavaDoc PAGE_ID = "overview"; //$NON-NLS-1$
60
private PluginExportAction fExportAction;
61     private GeneralInfoSection fInfoSection;
62     private boolean fDisposed = false;
63
64     public OverviewPage(FormEditor editor) {
65         super(editor, PAGE_ID, PDEUIMessages.OverviewPage_tabName);
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
70      */

71     protected String JavaDoc getHelpResource() {
72         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/manifest_editor/overview.htm"; //$NON-NLS-1$
73
}
74     
75     protected void createFormContent(IManagedForm managedForm) {
76         super.createFormContent(managedForm);
77         ScrolledForm form = managedForm.getForm();
78         FormToolkit toolkit = managedForm.getToolkit();
79         if (isFragment()) {
80             form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FRAGMENT_MF_OBJ));
81         } else {
82             form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PLUGIN_MF_OBJ));
83         }
84         form.setText(PDEUIMessages.ManifestEditor_OverviewPage_title);
85         fillBody(managedForm, toolkit);
86         PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.MANIFEST_PLUGIN_OVERVIEW);
87     }
88     
89     private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
90         Composite body = managedForm.getForm().getBody();
91         body.setLayout(FormLayoutFactory.createFormTableWrapLayout(true, 2));
92
93         Composite left = toolkit.createComposite(body);
94         left.setLayout(FormLayoutFactory.createFormPaneTableWrapLayout(false, 1));
95         left.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
96         if (isFragment())
97             fInfoSection = new FragmentGeneralInfoSection(this, left);
98         else
99             fInfoSection = new PluginGeneralInfoSection(this, left);
100         managedForm.addPart(fInfoSection);
101         if (isBundle())
102             managedForm.addPart(new ExecutionEnvironmentSection(this, left));
103             
104         Composite right = toolkit.createComposite(body);
105         right.setLayout(FormLayoutFactory.createFormPaneTableWrapLayout(false, 1));
106         right.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
107         createContentSection(managedForm, right, toolkit);
108         if (isEditable() || getPDEEditor().hasInputContext(PluginInputContext.CONTEXT_ID))
109             createExtensionSection(managedForm, right, toolkit);
110         if (isEditable()) {
111             createTestingSection(managedForm, isBundle() ? right : left, toolkit);
112         }
113         if (isEditable())
114             createExportingSection(managedForm, right, toolkit);
115     }
116     
117     private void createContentSection(IManagedForm managedForm,
118             Composite parent, FormToolkit toolkit) {
119         String JavaDoc sectionTitle;
120         if(isFragment()){
121             sectionTitle = PDEUIMessages.ManifestEditor_ContentSection_ftitle;
122         }else{
123             sectionTitle = PDEUIMessages.ManifestEditor_ContentSection_title;
124         }
125         Section section = createStaticSection(
126                             toolkit,
127                             parent,
128                             sectionTitle);
129
130         Composite container = createStaticSectionClient(toolkit, section);
131         
132         FormText text = createClient(container, isFragment() ? PDEUIMessages.OverviewPage_fContent : PDEUIMessages.OverviewPage_content, toolkit);
133         PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
134         text.setImage("page", lp.get(PDEPluginImages.DESC_PAGE_OBJ, SharedLabelProvider.F_EDIT)); //$NON-NLS-1$
135

136         if (!isBundle() && isEditable()){
137             String JavaDoc content;
138             if(isFragment()){
139                 content = PDEUIMessages.OverviewPage_fOsgi;
140             }else{
141                 content = PDEUIMessages.OverviewPage_osgi;
142             }
143             text = createClient(container, content, toolkit);
144         }
145         section.setClient(container);
146     }
147     
148     private void createExtensionSection(IManagedForm managedForm,
149             Composite parent, FormToolkit toolkit) {
150         String JavaDoc sectionTitle = PDEUIMessages.ManifestEditor_ExtensionSection_title;
151         Section section = createStaticSection(
152                             toolkit,
153                             parent,
154                             sectionTitle);
155
156         Composite container = createStaticSectionClient(toolkit, section);
157         
158         FormText text = createClient(container, isFragment() ? PDEUIMessages.OverviewPage_fExtensionContent : PDEUIMessages.OverviewPage_extensionContent, toolkit);
159         PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
160         text.setImage("page", lp.get(PDEPluginImages.DESC_PAGE_OBJ, SharedLabelProvider.F_EDIT)); //$NON-NLS-1$
161

162         section.setClient(container);
163     }
164     
165     private void createTestingSection(IManagedForm managedForm,
166             Composite parent, FormToolkit toolkit) {
167         Section section = createStaticSection(toolkit, parent, PDEUIMessages.ManifestEditor_TestingSection_title);
168         PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
169         
170         Composite container = createStaticSectionClient(toolkit, section);
171         
172         String JavaDoc prefixText = (!((ManifestEditor)getEditor()).showExtensionTabs()) ? PDEUIMessages.OverviewPage_OSGiTesting :
173             isFragment() ? PDEUIMessages.OverviewPage_fTesting : PDEUIMessages.OverviewPage_testing;
174         FormText text = createClient(container, getLauncherText(!((ManifestEditor)getEditor()).showExtensionTabs(), prefixText), toolkit);
175         text.setImage("run", lp.get(PDEPluginImages.DESC_RUN_EXC)); //$NON-NLS-1$
176
text.setImage("debug", lp.get(PDEPluginImages.DESC_DEBUG_EXC)); //$NON-NLS-1$
177
text.setImage("profile", lp.get(PDEPluginImages.DESC_PROFILE_EXC)); //$NON-NLS-1$
178
section.setClient(container);
179     }
180     
181     private void createExportingSection(IManagedForm managedForm,
182             Composite parent, FormToolkit toolkit) {
183         Section section = createStaticSection(toolkit, parent, PDEUIMessages.ManifestEditor_DeployingSection_title);
184         Composite container = createStaticSectionClient(toolkit, section);
185         createClient(container, isFragment() ? PDEUIMessages.OverviewPage_fDeploying : PDEUIMessages.OverviewPage_deploying, toolkit);
186         section.setClient(container);
187     }
188     
189     /**
190      * @param toolkit
191      * @param parent
192      * @return
193      */

194     protected Composite createStaticSectionClient(FormToolkit toolkit,
195             Composite parent) {
196         Composite container = toolkit.createComposite(parent, SWT.NONE);
197         container.setLayout(FormLayoutFactory.createSectionClientTableWrapLayout(false, 1));
198         TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
199         container.setLayoutData(data);
200         return container;
201     }
202     
203     private boolean isFragment() {
204         IPluginModelBase model = (IPluginModelBase) getPDEEditor().getContextManager().getAggregateModel();
205         return model.isFragmentModel();
206     }
207     
208     private boolean isBundle() {
209         return getPDEEditor().getContextManager().findContext(BundleInputContext.CONTEXT_ID) != null;
210     }
211
212     private boolean isEditable() {
213         IPluginModelBase model = (IPluginModelBase) getPDEEditor().getContextManager().getAggregateModel();
214         return model.isEditable();
215     }
216
217     /*
218      * (non-Javadoc)
219      *
220      * @see org.eclipse.ui.forms.events.HyperlinkListener#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
221      */

222     public void linkActivated(HyperlinkEvent e) {
223         String JavaDoc href = (String JavaDoc) e.getHref();
224         // try page references
225
if (href.equals("dependencies")) //$NON-NLS-1$
226
getEditor().setActivePage(DependenciesPage.PAGE_ID);
227         else if (href.equals("runtime")) //$NON-NLS-1$
228
getEditor().setActivePage(RuntimePage.PAGE_ID);
229         else if (href.equals("extensions")) { //$NON-NLS-1$
230
if (getEditor().setActivePage(ExtensionsPage.PAGE_ID) == null)
231                 activateExtensionPages(ExtensionsPage.PAGE_ID);
232         } else if (href.equals("ex-points")) { //$NON-NLS-1$
233
if (getEditor().setActivePage(ExtensionPointsPage.PAGE_ID) == null)
234                 activateExtensionPages(ExtensionPointsPage.PAGE_ID);
235         } else if (href.equals("build")) { //$NON-NLS-1$
236
if (!getPDEEditor().hasInputContext(BuildInputContext.CONTEXT_ID)) {
237                 if (!MessageDialog.openQuestion(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OverviewPage_buildTitle, PDEUIMessages.OverviewPage_buildQuestion))
238                     return;
239                 IFile file = getPDEEditor().getCommonProject().getFile("build.properties"); //$NON-NLS-1$
240
WorkspaceBuildModel model = new WorkspaceBuildModel(file);
241                 model.save();
242                 IEditorInput in = new FileEditorInput(file);
243                 getPDEEditor().getContextManager().putContext(in, new BuildInputContext(getPDEEditor(), in, false));
244             }
245             getEditor().setActivePage(BuildPage.PAGE_ID);
246         } else if (href.equals("export")) { //$NON-NLS-1$
247
getExportAction().run();
248         } else if (href.equals("action.convert")) { //$NON-NLS-1$
249
handleConvert();
250         } else if (href.equals("organize")) { //$NON-NLS-1$
251
getEditor().doSave(null);
252             OrganizeManifestsAction organizeAction = new OrganizeManifestsAction();
253             organizeAction.selectionChanged(null, new StructuredSelection(getPDEEditor().getCommonProject()));
254             organizeAction.run(null);
255         } else
256             super.linkActivated(e);
257     }
258     
259     protected Object JavaDoc getLaunchObject() {
260         return getPDEEditor().getCommonProject();
261     }
262     
263     private PluginExportAction getExportAction() {
264         if (fExportAction == null)
265             fExportAction = new PluginExportAction((PDEFormEditor) getEditor());
266         return fExportAction;
267     }
268     
269     private void handleConvert() {
270         try {
271             // remove listeners of Info section before we convert. If we don't
272
// we may get a model changed event while disposing the page. Bug 156414
273
fInfoSection.removeListeners();
274             PDEFormEditor editor = getPDEEditor();
275             IPluginModelBase model = (IPluginModelBase)editor.getAggregateModel();
276             IRunnableWithProgress op = new CreateManifestOperation(model);
277             IProgressService service = PlatformUI.getWorkbench().getProgressService();
278             editor.doSave(null);
279             service.runInUI(service, op, PDEPlugin.getWorkspace().getRoot());
280             updateBuildProperties();
281             editor.doSave(null);
282         } catch (InvocationTargetException JavaDoc e) {
283             MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OverviewPage_error, e.getCause().getMessage());
284             // if convert failed and this OverviewPage hasn't been removed from the editor, reattach listeners
285
if (!fDisposed)
286                 fInfoSection.addListeners();
287         } catch (InterruptedException JavaDoc e) {
288             // if convert failed and this OverviewPage hasn't been removed from the editor, reattach listeners
289
if (!fDisposed)
290                 fInfoSection.addListeners();
291         }
292     }
293     
294     private void updateBuildProperties() throws InvocationTargetException JavaDoc {
295        try {
296         InputContext context = getPDEEditor().getContextManager().findContext(BuildInputContext.CONTEXT_ID);
297         if (context != null) {
298                IBuildModel buildModel = (IBuildModel)context.getModel();
299                IBuild build = buildModel.getBuild();
300                IBuildEntry entry = build.getEntry("bin.includes"); //$NON-NLS-1$
301
if (entry == null) {
302                    entry = buildModel.getFactory().createEntry("bin.includes"); //$NON-NLS-1$
303
build.add(entry);
304                }
305                if (!entry.contains("META-INF")) //$NON-NLS-1$
306
entry.addToken("META-INF/"); //$NON-NLS-1$
307
}
308         } catch (CoreException e) {
309             throw new InvocationTargetException JavaDoc(e);
310         }
311     }
312     
313     private void activateExtensionPages(String JavaDoc activePageId) {
314         MessageDialog mdiag = new MessageDialog(PDEPlugin.getActiveWorkbenchShell(),
315                 PDEUIMessages.OverviewPage_extensionPageMessageTitle, null,
316                 PDEUIMessages.OverviewPage_extensionPageMessageBody,
317                 MessageDialog.QUESTION, new String JavaDoc[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
318         if (mdiag.open() != Window.OK)
319             return;
320         try {
321             ManifestEditor manifestEditor = (ManifestEditor)getEditor();
322             manifestEditor.addExtensionTabs();
323             manifestEditor.setShowExtensions(true);
324             manifestEditor.setActivePage(activePageId);
325         } catch (PartInitException e) {
326         } catch (BackingStoreException e) {
327         }
328     }
329     
330     public void dispose() {
331         fDisposed = true;
332         super.dispose();
333     }
334     
335     protected short getIndent() {
336         return 5;
337     }
338 }
339
Popular Tags