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.build;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.pde.core.build.IBuild;
014: import org.eclipse.pde.core.build.IBuildEntry;
015: import org.eclipse.pde.core.build.IBuildModel;
016: import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
017: import org.eclipse.pde.internal.ui.IHelpContextIds;
018: import org.eclipse.pde.internal.ui.IPDEUIConstants;
019: import org.eclipse.pde.internal.ui.PDEPlugin;
020: import org.eclipse.pde.internal.ui.PDEPluginImages;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
023: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
024: import org.eclipse.pde.internal.ui.editor.context.InputContext;
025: import org.eclipse.swt.SWT;
026: import org.eclipse.swt.events.SelectionAdapter;
027: import org.eclipse.swt.events.SelectionEvent;
028: import org.eclipse.swt.layout.GridData;
029: import org.eclipse.swt.widgets.Button;
030: import org.eclipse.swt.widgets.Label;
031: import org.eclipse.ui.PlatformUI;
032: import org.eclipse.ui.forms.IManagedForm;
033: import org.eclipse.ui.forms.editor.FormEditor;
034: import org.eclipse.ui.forms.widgets.FormToolkit;
035: import org.eclipse.ui.forms.widgets.ScrolledForm;
036:
037: public class BuildPage extends PDEFormPage {
038: public static final String PAGE_ID = "build"; //$NON-NLS-1$
039: private BuildClasspathSection fClasspathSection;
040: private BuildContentsSection fSrcSection;
041: private BuildContentsSection fBinSection;
042: private RuntimeInfoSection fRuntimeSection;
043:
044: private Button fCustomButton;
045:
046: public BuildPage(FormEditor editor) {
047: super (editor, PAGE_ID, PDEUIMessages.BuildPage_name);
048: }
049:
050: /* (non-Javadoc)
051: * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
052: */
053: protected String getHelpResource() {
054: return IPDEUIConstants.PLUGIN_DOC_ROOT
055: + "guide/tools/editors/manifest_editor/build.htm"; //$NON-NLS-1$
056: }
057:
058: protected void createFormContent(IManagedForm mform) {
059: super .createFormContent(mform);
060: FormToolkit toolkit = mform.getToolkit();
061: ScrolledForm form = mform.getForm();
062: form.setImage(PDEPlugin.getDefault().getLabelProvider().get(
063: PDEPluginImages.DESC_BUILD_EXEC));
064: form.setText(PDEUIMessages.BuildEditor_BuildPage_title);
065: form.getBody().setLayout(
066: FormLayoutFactory.createFormGridLayout(true, 2));
067:
068: fCustomButton = toolkit.createButton(form.getBody(),
069: getCustomText(), SWT.CHECK);
070: fCustomButton.setAlignment(SWT.LEFT);
071:
072: Label label = toolkit.createLabel(form.getBody(), null);
073: label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
074:
075: fCustomButton.addSelectionListener(new SelectionAdapter() {
076: public void widgetSelected(SelectionEvent e) {
077: boolean isCustom = fCustomButton.getSelection();
078: IBuildEntry customEntry = getCustomBuildEntry();
079: setCustomEntryValue(customEntry, isCustom);
080: handleCustomCheckState(isCustom);
081: }
082: });
083:
084: fRuntimeSection = new RuntimeInfoSection(this , form.getBody());
085:
086: fBinSection = new BinSection(this , form.getBody());
087: fBinSection.getSection().setLayoutData(
088: new GridData(GridData.FILL_BOTH));
089:
090: fSrcSection = new SrcSection(this , form.getBody());
091: fSrcSection.getSection().setLayoutData(
092: new GridData(GridData.FILL_BOTH));
093:
094: fClasspathSection = new BuildClasspathSection(this , form
095: .getBody());
096:
097: mform.addPart(fRuntimeSection);
098: mform.addPart(fSrcSection);
099: mform.addPart(fBinSection);
100: mform.addPart(fClasspathSection);
101:
102: handleCustomCheckState(getCustomSelection());
103: PlatformUI.getWorkbench().getHelpSystem().setHelp(
104: form.getBody(), IHelpContextIds.BUILD_PAGE);
105: }
106:
107: private IBuildModel getBuildModel() {
108: InputContext context = getPDEEditor().getContextManager()
109: .findContext(BuildInputContext.CONTEXT_ID);
110: return (IBuildModel) context.getModel();
111: }
112:
113: private IBuildEntry getCustomBuildEntry() {
114: IBuildModel buildModel = getBuildModel();
115: IBuildEntry customEntry = buildModel.getBuild().getEntry(
116: IBuildPropertiesConstants.PROPERTY_CUSTOM);
117:
118: if (customEntry != null)
119: return customEntry;
120:
121: try {
122: customEntry = buildModel.getFactory().createEntry(
123: IBuildPropertiesConstants.PROPERTY_CUSTOM);
124: buildModel.getBuild().add(customEntry);
125: } catch (CoreException e) {
126: PDEPlugin.logException(e);
127: }
128: return customEntry;
129: }
130:
131: private boolean getCustomSelection() {
132: IBuildModel model = getBuildModel();
133: IBuild build = model.getBuild();
134: IBuildEntry customEntry = build
135: .getEntry(IBuildPropertiesConstants.PROPERTY_CUSTOM);
136: if (customEntry == null || customEntry.getTokens().length == 0)
137: return false;
138: return customEntry.getTokens()[0].equals("true"); //$NON-NLS-1$
139: }
140:
141: private void handleCustomCheckState(boolean isCustom) {
142: fCustomButton.setSelection(isCustom);
143: enableAllSections(!isCustom);
144: }
145:
146: public void enableAllSections(boolean enable) {
147: fRuntimeSection.enableSection(enable);
148: fBinSection.enableSection(enable);
149: fSrcSection.enableSection(enable);
150: fClasspathSection.enableSection(enable);
151: }
152:
153: private void setCustomEntryValue(IBuildEntry customEntry,
154: boolean isCustom) {
155: String[] tokens = customEntry.getTokens();
156: try {
157: if (tokens.length != 0) {
158: for (int i = 0; i < tokens.length; i++)
159: customEntry.removeToken(tokens[i]);
160: }
161: if (isCustom)
162: customEntry.addToken("true"); //$NON-NLS-1$
163: else
164: getBuildModel().getBuild().remove(customEntry);
165: } catch (CoreException e) {
166: PDEPlugin.logException(e);
167: }
168: }
169:
170: private String getCustomText() {
171: return PDEUIMessages.BuildPage_custom;
172: }
173:
174: }
|