KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > build > BuildPage


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.build;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.pde.core.build.IBuild;
15 import org.eclipse.pde.core.build.IBuildEntry;
16 import org.eclipse.pde.core.build.IBuildModel;
17 import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
18 import org.eclipse.pde.internal.ui.IHelpContextIds;
19 import org.eclipse.pde.internal.ui.IPDEUIConstants;
20 import org.eclipse.pde.internal.ui.PDEPlugin;
21 import org.eclipse.pde.internal.ui.PDEPluginImages;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
24 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
25 import org.eclipse.pde.internal.ui.editor.context.InputContext;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.ui.PlatformUI;
33 import org.eclipse.ui.forms.IManagedForm;
34 import org.eclipse.ui.forms.editor.FormEditor;
35 import org.eclipse.ui.forms.widgets.FormToolkit;
36 import org.eclipse.ui.forms.widgets.ScrolledForm;
37
38 public class BuildPage extends PDEFormPage {
39     public static final String JavaDoc PAGE_ID = "build"; //$NON-NLS-1$
40
private BuildClasspathSection fClasspathSection;
41     private BuildContentsSection fSrcSection;
42     private BuildContentsSection fBinSection;
43     private RuntimeInfoSection fRuntimeSection;
44     
45     private Button fCustomButton;
46     
47     public BuildPage(FormEditor editor) {
48         super(editor, PAGE_ID, PDEUIMessages.BuildPage_name);
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
53      */

54     protected String JavaDoc getHelpResource() {
55         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/manifest_editor/build.htm"; //$NON-NLS-1$
56
}
57     
58     protected void createFormContent(IManagedForm mform) {
59         super.createFormContent(mform);
60         FormToolkit toolkit = mform.getToolkit();
61         ScrolledForm form = mform.getForm();
62         form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_BUILD_EXEC));
63         form.setText(PDEUIMessages.BuildEditor_BuildPage_title);
64         form.getBody().setLayout(FormLayoutFactory.createFormGridLayout(true, 2));
65
66         fCustomButton =
67             toolkit.createButton(
68                 form.getBody(),
69                 getCustomText(),
70                 SWT.CHECK);
71         fCustomButton.setAlignment(SWT.LEFT);
72         
73         Label label = toolkit.createLabel(form.getBody(), null);
74         label.setLayoutData(new GridData (GridData.FILL_HORIZONTAL));
75         
76         fCustomButton.addSelectionListener(new SelectionAdapter() {
77             public void widgetSelected(SelectionEvent e) {
78                 boolean isCustom = fCustomButton.getSelection();
79                 IBuildEntry customEntry = getCustomBuildEntry();
80                 setCustomEntryValue(customEntry, isCustom);
81                 handleCustomCheckState(isCustom);
82             }
83         });
84         
85         fRuntimeSection = new RuntimeInfoSection(this, form.getBody());
86         
87         fBinSection = new BinSection(this, form.getBody());
88         fBinSection.getSection().setLayoutData(new GridData(GridData.FILL_BOTH));
89
90         fSrcSection = new SrcSection(this, form.getBody());
91         fSrcSection.getSection().setLayoutData(new GridData(GridData.FILL_BOTH));
92
93         fClasspathSection = new BuildClasspathSection(this, form.getBody());
94         
95         mform.addPart(fRuntimeSection);
96         mform.addPart(fSrcSection);
97         mform.addPart(fBinSection);
98         mform.addPart(fClasspathSection);
99
100         handleCustomCheckState(getCustomSelection());
101         PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.BUILD_PAGE);
102     }
103
104     private IBuildModel getBuildModel() {
105         InputContext context = getPDEEditor().getContextManager()
106                 .findContext(BuildInputContext.CONTEXT_ID);
107         return (IBuildModel) context.getModel();
108     }
109
110     private IBuildEntry getCustomBuildEntry(){
111         IBuildModel buildModel = getBuildModel();
112         IBuildEntry customEntry =
113             buildModel.getBuild().getEntry(IBuildPropertiesConstants.PROPERTY_CUSTOM);
114             
115         if (customEntry!=null)
116             return customEntry;
117                             
118         try {
119             customEntry =
120                 buildModel.getFactory().createEntry(IBuildPropertiesConstants.PROPERTY_CUSTOM);
121             buildModel.getBuild().add(customEntry);
122         } catch (CoreException e) {
123             PDEPlugin.logException(e);
124         }
125         return customEntry;
126     }
127     
128     private boolean getCustomSelection(){
129         IBuildModel model = getBuildModel();
130         IBuild build = model.getBuild();
131         IBuildEntry customEntry = build.getEntry(IBuildPropertiesConstants.PROPERTY_CUSTOM);
132         if (customEntry ==null || customEntry.getTokens().length ==0)
133             return false;
134         return customEntry.getTokens()[0].equals("true"); //$NON-NLS-1$
135
}
136     
137     private void handleCustomCheckState(boolean isCustom){
138         fCustomButton.setSelection(isCustom);
139         enableAllSections(!isCustom);
140     }
141     
142     public void enableAllSections(boolean enable){
143         fRuntimeSection.enableSection(enable);
144         fBinSection.enableSection(enable);
145         fSrcSection.enableSection(enable);
146         fClasspathSection.enableSection(enable);
147     }
148
149     private void setCustomEntryValue(IBuildEntry customEntry, boolean isCustom){
150         String JavaDoc[] tokens = customEntry.getTokens();
151         try {
152             if (tokens.length != 0) {
153                 for (int i = 0; i < tokens.length; i++)
154                     customEntry.removeToken(tokens[i]);
155             }
156             if (isCustom)
157                 customEntry.addToken("true"); //$NON-NLS-1$
158
else
159                 getBuildModel().getBuild().remove(customEntry);
160         } catch (CoreException e) {
161             PDEPlugin.logException(e);
162         }
163     }
164     
165     private String JavaDoc getCustomText() {
166         return PDEUIMessages.BuildPage_custom;
167     }
168
169 }
170
Popular Tags