001: /*******************************************************************************
002: * Copyright (c) 2000, 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 java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.resources.IFile;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.jface.dialogs.IDialogConstants;
017: import org.eclipse.jface.dialogs.MessageDialog;
018: import org.eclipse.jface.operation.IRunnableWithProgress;
019: import org.eclipse.jface.viewers.StructuredSelection;
020: import org.eclipse.jface.window.Window;
021: import org.eclipse.pde.core.build.IBuild;
022: import org.eclipse.pde.core.build.IBuildEntry;
023: import org.eclipse.pde.core.build.IBuildModel;
024: import org.eclipse.pde.core.plugin.IPluginModelBase;
025: import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
026: import org.eclipse.pde.internal.ui.IHelpContextIds;
027: import org.eclipse.pde.internal.ui.IPDEUIConstants;
028: import org.eclipse.pde.internal.ui.PDELabelProvider;
029: import org.eclipse.pde.internal.ui.PDEPlugin;
030: import org.eclipse.pde.internal.ui.PDEPluginImages;
031: import org.eclipse.pde.internal.ui.PDEUIMessages;
032: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
033: import org.eclipse.pde.internal.ui.editor.ILauncherFormPageHelper;
034: import org.eclipse.pde.internal.ui.editor.LaunchShortcutOverviewPage;
035: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
036: import org.eclipse.pde.internal.ui.editor.PDELauncherFormEditor;
037: import org.eclipse.pde.internal.ui.editor.build.BuildInputContext;
038: import org.eclipse.pde.internal.ui.editor.build.BuildPage;
039: import org.eclipse.pde.internal.ui.editor.context.InputContext;
040: import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
041: import org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction;
042: import org.eclipse.swt.SWT;
043: import org.eclipse.swt.widgets.Composite;
044: import org.eclipse.ui.IEditorInput;
045: import org.eclipse.ui.PartInitException;
046: import org.eclipse.ui.PlatformUI;
047: import org.eclipse.ui.forms.IManagedForm;
048: import org.eclipse.ui.forms.events.HyperlinkEvent;
049: import org.eclipse.ui.forms.widgets.FormText;
050: import org.eclipse.ui.forms.widgets.FormToolkit;
051: import org.eclipse.ui.forms.widgets.ScrolledForm;
052: import org.eclipse.ui.forms.widgets.Section;
053: import org.eclipse.ui.forms.widgets.TableWrapData;
054: import org.eclipse.ui.part.FileEditorInput;
055: import org.eclipse.ui.progress.IProgressService;
056: import org.osgi.service.prefs.BackingStoreException;
057:
058: public class OverviewPage extends LaunchShortcutOverviewPage {
059: public static final String PAGE_ID = "overview"; //$NON-NLS-1$
060: private PluginExportAction fExportAction;
061: private GeneralInfoSection fInfoSection;
062: private boolean fDisposed = false;
063: private ILauncherFormPageHelper fLauncherHelper;
064:
065: public OverviewPage(PDELauncherFormEditor editor) {
066: super (editor, PAGE_ID, PDEUIMessages.OverviewPage_tabName);
067: }
068:
069: /* (non-Javadoc)
070: * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
071: */
072: protected String getHelpResource() {
073: return IPDEUIConstants.PLUGIN_DOC_ROOT
074: + "guide/tools/editors/manifest_editor/overview.htm"; //$NON-NLS-1$
075: }
076:
077: protected void createFormContent(IManagedForm managedForm) {
078: super .createFormContent(managedForm);
079: ScrolledForm form = managedForm.getForm();
080: FormToolkit toolkit = managedForm.getToolkit();
081: if (isFragment()) {
082: form.setImage(PDEPlugin.getDefault().getLabelProvider()
083: .get(PDEPluginImages.DESC_FRAGMENT_MF_OBJ));
084: } else {
085: form.setImage(PDEPlugin.getDefault().getLabelProvider()
086: .get(PDEPluginImages.DESC_PLUGIN_MF_OBJ));
087: }
088: form.setText(PDEUIMessages.ManifestEditor_OverviewPage_title);
089: fillBody(managedForm, toolkit);
090: PlatformUI.getWorkbench().getHelpSystem().setHelp(
091: form.getBody(),
092: IHelpContextIds.MANIFEST_PLUGIN_OVERVIEW);
093: }
094:
095: private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
096: Composite body = managedForm.getForm().getBody();
097: body.setLayout(FormLayoutFactory.createFormTableWrapLayout(
098: true, 2));
099:
100: Composite left = toolkit.createComposite(body);
101: left.setLayout(FormLayoutFactory.createFormPaneTableWrapLayout(
102: false, 1));
103: left.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
104: if (isFragment())
105: fInfoSection = new FragmentGeneralInfoSection(this , left);
106: else
107: fInfoSection = new PluginGeneralInfoSection(this , left);
108: managedForm.addPart(fInfoSection);
109: if (isBundle())
110: managedForm.addPart(new ExecutionEnvironmentSection(this ,
111: left));
112:
113: Composite right = toolkit.createComposite(body);
114: right.setLayout(FormLayoutFactory
115: .createFormPaneTableWrapLayout(false, 1));
116: right.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
117: createContentSection(managedForm, right, toolkit);
118: if (isEditable()
119: || getPDEEditor().hasInputContext(
120: PluginInputContext.CONTEXT_ID))
121: createExtensionSection(managedForm, right, toolkit);
122: if (isEditable()) {
123: createTestingSection(managedForm,
124: isBundle() ? right : left, toolkit);
125: }
126: if (isEditable())
127: createExportingSection(managedForm, right, toolkit);
128: }
129:
130: private void createContentSection(IManagedForm managedForm,
131: Composite parent, FormToolkit toolkit) {
132: String sectionTitle;
133: if (isFragment()) {
134: sectionTitle = PDEUIMessages.ManifestEditor_ContentSection_ftitle;
135: } else {
136: sectionTitle = PDEUIMessages.ManifestEditor_ContentSection_title;
137: }
138: Section section = createStaticSection(toolkit, parent,
139: sectionTitle);
140:
141: Composite container = createStaticSectionClient(toolkit,
142: section);
143:
144: FormText text = createClient(container,
145: isFragment() ? PDEUIMessages.OverviewPage_fContent
146: : PDEUIMessages.OverviewPage_content, toolkit);
147: PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
148: text
149: .setImage(
150: "page", lp.get( PDEPluginImages.DESC_PAGE_OBJ, SharedLabelProvider.F_EDIT)); //$NON-NLS-1$
151:
152: if (!isBundle() && isEditable()) {
153: String content;
154: if (isFragment()) {
155: content = PDEUIMessages.OverviewPage_fOsgi;
156: } else {
157: content = PDEUIMessages.OverviewPage_osgi;
158: }
159: text = createClient(container, content, toolkit);
160: }
161: section.setClient(container);
162: }
163:
164: private void createExtensionSection(IManagedForm managedForm,
165: Composite parent, FormToolkit toolkit) {
166: String sectionTitle = PDEUIMessages.ManifestEditor_ExtensionSection_title;
167: Section section = createStaticSection(toolkit, parent,
168: sectionTitle);
169:
170: Composite container = createStaticSectionClient(toolkit,
171: section);
172:
173: FormText text = createClient(
174: container,
175: isFragment() ? PDEUIMessages.OverviewPage_fExtensionContent
176: : PDEUIMessages.OverviewPage_extensionContent,
177: toolkit);
178: PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
179: text
180: .setImage(
181: "page", lp.get( PDEPluginImages.DESC_PAGE_OBJ, SharedLabelProvider.F_EDIT)); //$NON-NLS-1$
182:
183: section.setClient(container);
184: }
185:
186: private void createTestingSection(IManagedForm managedForm,
187: Composite parent, FormToolkit toolkit) {
188: Section section = createStaticSection(toolkit, parent,
189: PDEUIMessages.ManifestEditor_TestingSection_title);
190: PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
191:
192: Composite container = createStaticSectionClient(toolkit,
193: section);
194:
195: String prefixText = (!((ManifestEditor) getEditor())
196: .showExtensionTabs()) ? PDEUIMessages.OverviewPage_OSGiTesting
197: : isFragment() ? PDEUIMessages.OverviewPage_fTesting
198: : PDEUIMessages.OverviewPage_testing;
199: FormText text = createClient(container, getLauncherText(
200: getLauncherHelper().isOSGi(), prefixText), toolkit);
201: text.setImage("run", lp.get(PDEPluginImages.DESC_RUN_EXC)); //$NON-NLS-1$
202: text.setImage("debug", lp.get(PDEPluginImages.DESC_DEBUG_EXC)); //$NON-NLS-1$
203: text.setImage(
204: "profile", lp.get(PDEPluginImages.DESC_PROFILE_EXC)); //$NON-NLS-1$
205: section.setClient(container);
206: }
207:
208: private void createExportingSection(IManagedForm managedForm,
209: Composite parent, FormToolkit toolkit) {
210: Section section = createStaticSection(toolkit, parent,
211: PDEUIMessages.ManifestEditor_DeployingSection_title);
212: Composite container = createStaticSectionClient(toolkit,
213: section);
214: createClient(container,
215: isFragment() ? PDEUIMessages.OverviewPage_fDeploying
216: : PDEUIMessages.OverviewPage_deploying, toolkit);
217: section.setClient(container);
218: }
219:
220: /**
221: * @param toolkit
222: * @param parent
223: * @return
224: */
225: protected Composite createStaticSectionClient(FormToolkit toolkit,
226: Composite parent) {
227: Composite container = toolkit.createComposite(parent, SWT.NONE);
228: container.setLayout(FormLayoutFactory
229: .createSectionClientTableWrapLayout(false, 1));
230: TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
231: container.setLayoutData(data);
232: return container;
233: }
234:
235: private boolean isFragment() {
236: IPluginModelBase model = (IPluginModelBase) getPDEEditor()
237: .getContextManager().getAggregateModel();
238: return model.isFragmentModel();
239: }
240:
241: private boolean isBundle() {
242: return getPDEEditor().getContextManager().findContext(
243: BundleInputContext.CONTEXT_ID) != null;
244: }
245:
246: private boolean isEditable() {
247: IPluginModelBase model = (IPluginModelBase) getPDEEditor()
248: .getContextManager().getAggregateModel();
249: return model.isEditable();
250: }
251:
252: /*
253: * (non-Javadoc)
254: *
255: * @see org.eclipse.ui.forms.events.HyperlinkListener#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
256: */
257: public void linkActivated(HyperlinkEvent e) {
258: String href = (String) e.getHref();
259: // try page references
260: if (href.equals("dependencies")) //$NON-NLS-1$
261: getEditor().setActivePage(DependenciesPage.PAGE_ID);
262: else if (href.equals("runtime")) //$NON-NLS-1$
263: getEditor().setActivePage(RuntimePage.PAGE_ID);
264: else if (href.equals("extensions")) { //$NON-NLS-1$
265: if (getEditor().setActivePage(ExtensionsPage.PAGE_ID) == null)
266: activateExtensionPages(ExtensionsPage.PAGE_ID);
267: } else if (href.equals("ex-points")) { //$NON-NLS-1$
268: if (getEditor().setActivePage(ExtensionPointsPage.PAGE_ID) == null)
269: activateExtensionPages(ExtensionPointsPage.PAGE_ID);
270: } else if (href.equals("build")) { //$NON-NLS-1$
271: if (!getPDEEditor().hasInputContext(
272: BuildInputContext.CONTEXT_ID)) {
273: if (!MessageDialog.openQuestion(PDEPlugin
274: .getActiveWorkbenchShell(),
275: PDEUIMessages.OverviewPage_buildTitle,
276: PDEUIMessages.OverviewPage_buildQuestion))
277: return;
278: IFile file = getPDEEditor().getCommonProject().getFile(
279: "build.properties"); //$NON-NLS-1$
280: WorkspaceBuildModel model = new WorkspaceBuildModel(
281: file);
282: model.save();
283: IEditorInput in = new FileEditorInput(file);
284: getPDEEditor().getContextManager()
285: .putContext(
286: in,
287: new BuildInputContext(getPDEEditor(),
288: in, false));
289: }
290: getEditor().setActivePage(BuildPage.PAGE_ID);
291: } else if (href.equals("export")) { //$NON-NLS-1$
292: getExportAction().run();
293: } else if (href.equals("action.convert")) { //$NON-NLS-1$
294: handleConvert();
295: } else if (href.equals("organize")) { //$NON-NLS-1$
296: getEditor().doSave(null);
297: OrganizeManifestsAction organizeAction = new OrganizeManifestsAction();
298: organizeAction.selectionChanged(null,
299: new StructuredSelection(getPDEEditor()
300: .getCommonProject()));
301: organizeAction.run(null);
302: } else
303: super .linkActivated(e);
304: }
305:
306: private PluginExportAction getExportAction() {
307: if (fExportAction == null)
308: fExportAction = new PluginExportAction(
309: (PDEFormEditor) getEditor());
310: return fExportAction;
311: }
312:
313: private void handleConvert() {
314: try {
315: // remove listeners of Info section before we convert. If we don't
316: // we may get a model changed event while disposing the page. Bug 156414
317: fInfoSection.removeListeners();
318: PDEFormEditor editor = getPDEEditor();
319: IPluginModelBase model = (IPluginModelBase) editor
320: .getAggregateModel();
321: IRunnableWithProgress op = new CreateManifestOperation(
322: model);
323: IProgressService service = PlatformUI.getWorkbench()
324: .getProgressService();
325: editor.doSave(null);
326: service.runInUI(service, op, PDEPlugin.getWorkspace()
327: .getRoot());
328: updateBuildProperties();
329: editor.doSave(null);
330: } catch (InvocationTargetException e) {
331: MessageDialog.openError(
332: PDEPlugin.getActiveWorkbenchShell(),
333: PDEUIMessages.OverviewPage_error, e.getCause()
334: .getMessage());
335: // if convert failed and this OverviewPage hasn't been removed from the editor, reattach listeners
336: if (!fDisposed)
337: fInfoSection.addListeners();
338: } catch (InterruptedException e) {
339: // if convert failed and this OverviewPage hasn't been removed from the editor, reattach listeners
340: if (!fDisposed)
341: fInfoSection.addListeners();
342: }
343: }
344:
345: private void updateBuildProperties()
346: throws InvocationTargetException {
347: try {
348: InputContext context = getPDEEditor().getContextManager()
349: .findContext(BuildInputContext.CONTEXT_ID);
350: if (context != null) {
351: IBuildModel buildModel = (IBuildModel) context
352: .getModel();
353: IBuild build = buildModel.getBuild();
354: IBuildEntry entry = build.getEntry("bin.includes"); //$NON-NLS-1$
355: if (entry == null) {
356: entry = buildModel.getFactory().createEntry(
357: "bin.includes"); //$NON-NLS-1$
358: build.add(entry);
359: }
360: if (!entry.contains("META-INF")) //$NON-NLS-1$
361: entry.addToken("META-INF/"); //$NON-NLS-1$
362: }
363: } catch (CoreException e) {
364: throw new InvocationTargetException(e);
365: }
366: }
367:
368: private void activateExtensionPages(String activePageId) {
369: MessageDialog mdiag = new MessageDialog(PDEPlugin
370: .getActiveWorkbenchShell(),
371: PDEUIMessages.OverviewPage_extensionPageMessageTitle,
372: null,
373: PDEUIMessages.OverviewPage_extensionPageMessageBody,
374: MessageDialog.QUESTION, new String[] {
375: IDialogConstants.YES_LABEL,
376: IDialogConstants.NO_LABEL }, 0);
377: if (mdiag.open() != Window.OK)
378: return;
379: try {
380: ManifestEditor manifestEditor = (ManifestEditor) getEditor();
381: manifestEditor.addExtensionTabs();
382: manifestEditor.setShowExtensions(true);
383: manifestEditor.setActivePage(activePageId);
384: } catch (PartInitException e) {
385: } catch (BackingStoreException e) {
386: }
387: }
388:
389: public void dispose() {
390: fDisposed = true;
391: super .dispose();
392: }
393:
394: protected short getIndent() {
395: return 5;
396: }
397:
398: protected ILauncherFormPageHelper getLauncherHelper() {
399: if (fLauncherHelper == null)
400: fLauncherHelper = new PluginLauncherFormPageHelper(
401: getPDELauncherEditor());
402: return fLauncherHelper;
403: }
404: }
|