KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > FeatureFormPage


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.feature;
12
13 import org.eclipse.jface.action.IStatusLineManager;
14 import org.eclipse.pde.internal.core.ifeature.IFeature;
15 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
16 import org.eclipse.pde.internal.ui.IHelpContextIds;
17 import org.eclipse.pde.internal.ui.IPDEUIConstants;
18 import org.eclipse.pde.internal.ui.PDELabelProvider;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.PDEPluginImages;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
23 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
24 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
25 import org.eclipse.pde.internal.ui.editor.build.BuildPage;
26 import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
27 import org.eclipse.swt.SWTException;
28 import org.eclipse.swt.custom.BusyIndicator;
29 import org.eclipse.swt.layout.GridData;
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.events.HyperlinkEvent;
34 import org.eclipse.ui.forms.events.IHyperlinkListener;
35 import org.eclipse.ui.forms.widgets.ExpandableComposite;
36 import org.eclipse.ui.forms.widgets.FormText;
37 import org.eclipse.ui.forms.widgets.FormToolkit;
38 import org.eclipse.ui.forms.widgets.ScrolledForm;
39 import org.eclipse.ui.forms.widgets.Section;
40 import org.eclipse.ui.forms.widgets.TableWrapData;
41
42 /**
43  * Feature page.
44  */

45 public class FeatureFormPage extends PDEFormPage implements IHyperlinkListener {
46     public static final String JavaDoc PAGE_ID = "feature"; //$NON-NLS-1$
47

48     private FeatureSpecSection fSpecSection;
49
50     private PortabilitySection fPortabilitySection;
51
52     public FeatureFormPage(PDEFormEditor editor, String JavaDoc title) {
53         super(editor, PAGE_ID, title);
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
58      */

59     protected String JavaDoc getHelpResource() {
60         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/feature_editor/overview.htm"; //$NON-NLS-1$
61
}
62     
63     protected void createFormContent(IManagedForm managedForm) {
64         super.createFormContent(managedForm);
65         ScrolledForm form = managedForm.getForm();
66         FormToolkit toolkit = managedForm.getToolkit();
67         form.getBody().setLayout(FormLayoutFactory.createFormTableWrapLayout(true, 2));
68         // Set form header image
69
form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FTR_XML_OBJ));
70         
71         TableWrapData twd;
72
73         Composite left = toolkit.createComposite(form.getBody());
74         left.setLayout(FormLayoutFactory.createFormPaneTableWrapLayout(false, 1));
75
76         twd = new TableWrapData(TableWrapData.FILL_GRAB);
77         left.setLayoutData(twd);
78
79         Composite right = toolkit.createComposite(form.getBody());
80         right.setLayout(FormLayoutFactory.createFormPaneTableWrapLayout(false, 1));
81
82         twd = new TableWrapData(TableWrapData.FILL_GRAB);
83         right.setLayoutData(twd);
84
85         fSpecSection = new FeatureSpecSection(this, left);
86         fPortabilitySection = new PortabilitySection(this, left);
87         twd = new TableWrapData();
88         twd.grabHorizontal = true;
89         fPortabilitySection.getSection().setLayoutData(twd);
90
91         createContentSection(managedForm, right, toolkit);
92         createPackagingSection(managedForm, right, toolkit);
93         createPublishingSection(managedForm, right, toolkit);
94
95         managedForm.addPart(fSpecSection);
96         managedForm.addPart(fPortabilitySection);
97
98         PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(),IHelpContextIds.MANIFEST_FEATURE_OVERVIEW);
99         initialize();
100     }
101
102     public void initialize() {
103         IFeatureModel model = (IFeatureModel) getModel();
104         IFeature feature = model.getFeature();
105         getManagedForm().getForm().setText(
106                 model.getResourceString(feature.getLabel()));
107     }
108
109     private Section createContentSection(IManagedForm managedForm,
110             Composite parent, FormToolkit toolkit) {
111         Section section = createStaticSection(parent, toolkit);
112         FormText text;
113         section
114                 .setText(PDEUIMessages.FeatureEditor_InfoPage_ContentSection_title);
115         text = createClient(section, PDEUIMessages.FeatureEditor_InfoPage_ContentSection_text, toolkit);
116         PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider();
117         text.setImage("page", lp.get(PDEPluginImages.DESC_PAGE_OBJ, //$NON-NLS-1$
118
SharedLabelProvider.F_EDIT));
119         return section;
120     }
121
122     private Section createPackagingSection(IManagedForm managedForm,
123             Composite parent, FormToolkit toolkit) {
124         Section section = createStaticSection(parent, toolkit);
125         section
126                 .setText(PDEUIMessages.FeatureEditor_InfoPage_PackagingSection_title);
127         // ImageHyperlink info = new ImageHyperlink(section, SWT.NULL);
128
// toolkit.adapt(info, true, true);
129
// Image image =
130
// PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_HELP);
131
// info.setImage(image);
132
// info.addHyperlinkListener(new HyperlinkAdapter() {
133
// public void linkActivated(HyperlinkEvent e) {
134
// WorkbenchHelp
135
// .displayHelpResource(PDEPlugin.getResourceString("OverviewPage.help.deploy"));
136
// //$NON-NLS-1$
137
// }
138
// });
139
// info.setBackground(section.getTitleBarGradientBackground());
140
// section.setTextClient(info);
141
createClient(section, PDEUIMessages.FeatureEditor_InfoPage_PackagingSection_text, toolkit);
142         return section;
143     }
144
145     private Section createPublishingSection(IManagedForm managedForm,
146             Composite parent, FormToolkit toolkit) {
147         Section section = createStaticSection(parent, toolkit);
148         section
149                 .setText(PDEUIMessages.FeatureEditor_InfoPage_PublishingSection_title);
150         // ImageHyperlink info = new ImageHyperlink(section, SWT.NULL);
151
// toolkit.adapt(info, true, true);
152
// Image image =
153
// PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_HELP);
154
// info.setImage(image);
155
// info.addHyperlinkListener(new HyperlinkAdapter() {
156
// public void linkActivated(HyperlinkEvent e) {
157
// WorkbenchHelp
158
// .displayHelpResource(PDEPlugin.getResourceString("OverviewPage.help.deploy"));
159
// //$NON-NLS-1$
160
// }
161
// });
162
// info.setBackground(section.getTitleBarGradientBackground());
163
// section.setTextClient(info);
164
createClient(section, PDEUIMessages.FeatureEditor_InfoPage_PublishingSection_text, toolkit);
165         return section;
166     }
167
168     private FormText createClient(Section section, String JavaDoc content,
169             FormToolkit toolkit) {
170         FormText text = toolkit.createFormText(section, true);
171         try {
172             text.setText(content, true, false);
173         } catch (SWTException e) {
174             text.setText(e.getMessage(), false, false);
175         }
176         section.setClient(text);
177         section.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
178         text.addHyperlinkListener(this);
179         return text;
180     }
181
182     private Section createStaticSection(Composite parent, FormToolkit toolkit) {
183         Section section = toolkit.createSection(parent,
184                 ExpandableComposite.TITLE_BAR);
185         section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
186         section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
187         GridData data = new GridData(GridData.FILL_HORIZONTAL);
188         section.setLayoutData(data);
189         // toolkit.createCompositeSeparator(section);
190
return section;
191     }
192
193     /*
194      * (non-Javadoc)
195      *
196      * @see org.eclipse.ui.forms.events.HyperlinkListener#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
197      */

198     public void linkActivated(HyperlinkEvent e) {
199         String JavaDoc href = (String JavaDoc) e.getHref();
200         // try page references
201
if (href.equals("info")) //$NON-NLS-1$
202
getEditor().setActivePage(InfoFormPage.PAGE_ID);
203         if (href.equals("plugins")) //$NON-NLS-1$
204
getEditor().setActivePage(FeatureReferencePage.PAGE_ID);
205         else if (href.equals("features")) //$NON-NLS-1$
206
getEditor().setActivePage(FeatureIncludesPage.PAGE_ID);
207         else if (href.equals("dependencies")) //$NON-NLS-1$
208
getEditor().setActivePage(FeatureDependenciesPage.PAGE_ID);
209         else if (href.equals("installHandler")) //$NON-NLS-1$
210
getEditor().setActivePage(FeatureAdvancedPage.PAGE_ID);
211         else if (href.equals("build")) //$NON-NLS-1$
212
getEditor().setActivePage(BuildPage.PAGE_ID);
213         else if (href.equals("synchronize")) { //$NON-NLS-1$ {
214
getEditor().setActivePage(FeatureReferencePage.PAGE_ID);
215             final FeatureEditorContributor contributor = (FeatureEditorContributor) getPDEEditor()
216                     .getContributor();
217             BusyIndicator.showWhile(e.display, new Runnable JavaDoc() {
218                 public void run() {
219                     contributor.getSynchronizeAction().run();
220                 }
221             });
222         } else if (href.equals("export")) { //$NON-NLS-1$
223
getEditor().doSave(null);
224             final FeatureEditorContributor contributor = (FeatureEditorContributor) getPDEEditor()
225                     .getContributor();
226             BusyIndicator.showWhile(e.display, new Runnable JavaDoc() {
227                 public void run() {
228                     contributor.getBuildAction().run();
229                 }
230             });
231         } else if (href.equals("siteProject")) { //$NON-NLS-1$
232
getEditor().doSave(null);
233             final FeatureEditorContributor contributor = (FeatureEditorContributor) getPDEEditor()
234                     .getContributor();
235             BusyIndicator.showWhile(e.display, new Runnable JavaDoc() {
236                 public void run() {
237                     contributor.getNewSiteAction().run();
238                 }
239             });
240         }
241     }
242
243     /*
244      * (non-Javadoc)
245      *
246      * @see org.eclipse.ui.forms.events.HyperlinkListener#linkEntered(org.eclipse.ui.forms.events.HyperlinkEvent)
247      */

248     public void linkEntered(HyperlinkEvent e) {
249         IStatusLineManager mng = getEditor().getEditorSite().getActionBars()
250                 .getStatusLineManager();
251         mng.setMessage(e.getLabel());
252     }
253
254     /*
255      * (non-Javadoc)
256      *
257      * @see org.eclipse.ui.forms.events.HyperlinkListener#linkExited(org.eclipse.ui.forms.events.HyperlinkEvent)
258      */

259     public void linkExited(HyperlinkEvent e) {
260         IStatusLineManager mng = getEditor().getEditorSite().getActionBars()
261                 .getStatusLineManager();
262         mng.setMessage(null);
263     }
264 }
265
Popular Tags