KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.product;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.jface.dialogs.MessageDialog;
18 import org.eclipse.pde.core.IBaseModel;
19 import org.eclipse.pde.internal.core.iproduct.IProduct;
20 import org.eclipse.pde.internal.core.iproduct.IProductModel;
21 import org.eclipse.pde.internal.ui.IHelpContextIds;
22 import org.eclipse.pde.internal.ui.IPDEUIConstants;
23 import org.eclipse.pde.internal.ui.PDELabelProvider;
24 import org.eclipse.pde.internal.ui.PDEPlugin;
25 import org.eclipse.pde.internal.ui.PDEPluginImages;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
28 import org.eclipse.pde.internal.ui.editor.LaunchShortcutOverviewPage;
29 import org.eclipse.pde.internal.ui.wizards.product.SynchronizationOperation;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.ui.PlatformUI;
32 import org.eclipse.ui.forms.IManagedForm;
33 import org.eclipse.ui.forms.editor.FormEditor;
34 import org.eclipse.ui.forms.events.HyperlinkEvent;
35 import org.eclipse.ui.forms.widgets.FormText;
36 import org.eclipse.ui.forms.widgets.FormToolkit;
37 import org.eclipse.ui.forms.widgets.ScrolledForm;
38 import org.eclipse.ui.forms.widgets.Section;
39 import org.eclipse.ui.progress.IProgressService;
40
41
42 public class OverviewPage extends LaunchShortcutOverviewPage {
43     
44     public static final String JavaDoc PAGE_ID = "overview"; //$NON-NLS-1$
45

46     public OverviewPage(FormEditor editor) {
47         super(editor, PAGE_ID, PDEUIMessages.OverviewPage_title);
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
52      */

53     protected String JavaDoc getHelpResource() {
54         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/product_editor/overview.htm"; //$NON-NLS-1$
55
}
56     
57     /* (non-Javadoc)
58      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
59      */

60     protected void createFormContent(IManagedForm managedForm) {
61         super.createFormContent(managedForm);
62         ScrolledForm form = managedForm.getForm();
63         FormToolkit toolkit = managedForm.getToolkit();
64         form.setText(PDEUIMessages.OverviewPage_title);
65         form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PRODUCT_DEFINITION));
66         fillBody(managedForm, toolkit);
67         PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.OVERVIEW_PAGE);
68     }
69
70     private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
71         Composite body = managedForm.getForm().getBody();
72         body.setLayout(FormLayoutFactory.createFormTableWrapLayout(true, 2));
73
74         ProductInfoSection section = new ProductInfoSection(this, body);
75         
76         managedForm.addPart(section);
77         if (getModel().isEditable()) {
78             createTestingSection(body, toolkit);
79             createExportingSection(body, toolkit);
80         }
81     }
82     
83     private void createTestingSection(Composite parent, FormToolkit toolkit) {
84         Section section = createStaticSection(toolkit, parent, PDEUIMessages.Product_OverviewPage_testing);
85         FormText text = createClient(section, getLauncherText(false, PDEUIMessages.Product_overview_testing), toolkit);
86         PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
87         text.setImage("run", lp.get(PDEPluginImages.DESC_RUN_EXC)); //$NON-NLS-1$
88
text.setImage("debug", lp.get(PDEPluginImages.DESC_DEBUG_EXC)); //$NON-NLS-1$
89
text.setImage("profile", lp.get(PDEPluginImages.DESC_PROFILE_EXC)); //$NON-NLS-1$
90
section.setClient(text);
91     }
92     
93     private void createExportingSection(Composite parent, FormToolkit toolkit) {
94         Section section = createStaticSection(toolkit, parent, PDEUIMessages.OverviewPage_exportingTitle);
95         section.setClient(createClient(section, PDEUIMessages.Product_overview_exporting, toolkit));
96     }
97     
98     public void linkActivated(HyperlinkEvent e) {
99         String JavaDoc href = (String JavaDoc) e.getHref();
100         if (href.equals("action.synchronize")) { //$NON-NLS-1$
101
handleSynchronize(true);
102         } else if (href.equals("action.export")) { //$NON-NLS-1$
103
if (getPDEEditor().isDirty())
104                 getPDEEditor().doSave(null);
105             new ProductExportAction(getPDEEditor()).run();
106         } else if (href.equals("configuration")) { //$NON-NLS-1$
107
String JavaDoc pageId = getProduct().useFeatures() ? ConfigurationPage.FEATURE_ID : ConfigurationPage.PLUGIN_ID;
108             getEditor().setActivePage(pageId);
109         } else
110             super.linkActivated(e);
111     }
112     
113     protected Object JavaDoc getLaunchObject() {
114         Object JavaDoc file = getEditorInput().getAdapter(IFile.class);
115         if (file != null)
116             return file;
117         return ((IProductModel)getPDEEditor().getAggregateModel()).getUnderlyingResource();
118     }
119     
120     protected void preLaunch() {
121         handleSynchronize(false);
122     }
123     
124     private void handleSynchronize(boolean alert) {
125         try {
126             IProgressService service = PlatformUI.getWorkbench().getProgressService();
127             IProject project = getPDEEditor().getCommonProject();
128             SynchronizationOperation op = new SynchronizationOperation(getProduct(), getSite().getShell(), project);
129             service.runInUI(service, op, PDEPlugin.getWorkspace().getRoot());
130         } catch (InterruptedException JavaDoc e) {
131         } catch (InvocationTargetException JavaDoc e) {
132             if (alert) MessageDialog.openError(getSite().getShell(), "Synchronize", e.getTargetException().getMessage()); //$NON-NLS-1$
133
}
134     }
135     
136     private IProduct getProduct() {
137         IBaseModel model = getPDEEditor().getAggregateModel();
138         return ((IProductModel)model).getProduct();
139     }
140     
141     protected short getIndent() {
142         return 35;
143     }
144     
145 }
146
Popular Tags