001: /*******************************************************************************
002: * Copyright (c) 2005, 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.wizards.exports;
011:
012: import org.eclipse.core.runtime.Path;
013: import org.eclipse.jface.dialogs.IDialogSettings;
014: import org.eclipse.pde.internal.core.TargetPlatformHelper;
015: import org.eclipse.pde.internal.core.exports.FeatureExportOperation;
016: import org.eclipse.pde.internal.ui.PDEUIMessages;
017: import org.eclipse.pde.internal.ui.util.SWTUtil;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.ModifyEvent;
020: import org.eclipse.swt.events.ModifyListener;
021: import org.eclipse.swt.events.SelectionAdapter;
022: import org.eclipse.swt.events.SelectionEvent;
023: import org.eclipse.swt.layout.GridData;
024: import org.eclipse.swt.layout.GridLayout;
025: import org.eclipse.swt.widgets.Button;
026: import org.eclipse.swt.widgets.Combo;
027: import org.eclipse.swt.widgets.Composite;
028: import org.eclipse.swt.widgets.Control;
029: import org.eclipse.swt.widgets.Text;
030:
031: public class ExportOptionsTab extends AbstractExportTab {
032:
033: protected static final String S_JAR_FORMAT = "exportUpdate"; //$NON-NLS-1$
034: private static final String S_EXPORT_SOURCE = "exportSource"; //$NON-NLS-1$
035: private static final String S_SAVE_AS_ANT = "saveAsAnt"; //$NON-NLS-1$
036: private static final String S_ANT_FILENAME = "antFileName"; //$NON-NLS-1$
037: private static final String S_QUALIFIER = "qualifier"; //$NON-NLS-1$
038: private static final String S_QUALIFIER_NAME = "qualifierName"; //$NON-NLS-1$
039:
040: private Button fIncludeSource;
041: protected Button fJarButton;
042: private Button fSaveAsAntButton;
043: private Combo fAntCombo;
044: private Button fBrowseAnt;
045:
046: private Button fQualifierButton;
047: private Text fQualifierText;
048:
049: public ExportOptionsTab(BaseExportWizardPage page) {
050: super (page);
051: }
052:
053: protected Control createControl(Composite parent) {
054: Composite container = new Composite(parent, SWT.NONE);
055: container.setLayout(new GridLayout());
056: container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
057:
058: addSourceOption(container);
059: addJAROption(container);
060: addCrossPlatformOption(container);
061: addQualifierOption(container);
062: addAntSection(container);
063:
064: return container;
065: }
066:
067: protected void addSourceOption(Composite comp) {
068: fIncludeSource = new Button(comp, SWT.CHECK);
069: fIncludeSource
070: .setText(PDEUIMessages.ExportWizard_includeSource);
071: }
072:
073: protected void addJAROption(Composite comp) {
074: fJarButton = new Button(comp, SWT.CHECK);
075: fJarButton.setText(getJarButtonText());
076: fJarButton.addSelectionListener(new SelectionAdapter() {
077: public void widgetSelected(SelectionEvent e) {
078: }
079: });
080: }
081:
082: protected String getJarButtonText() {
083: return PDEUIMessages.BaseExportWizardPage_packageJARs;
084: }
085:
086: protected void addCrossPlatformOption(Composite comp) {
087: }
088:
089: protected void addAntSection(Composite container) {
090: Composite comp = new Composite(container, SWT.NONE);
091: GridLayout layout = new GridLayout(3, false);
092: layout.marginHeight = layout.marginWidth = 0;
093: comp.setLayout(layout);
094: comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
095:
096: fSaveAsAntButton = new Button(comp, SWT.CHECK);
097: fSaveAsAntButton.setText(PDEUIMessages.ExportWizard_antCheck);
098: GridData gd = new GridData();
099: gd.horizontalSpan = 1;
100: fSaveAsAntButton.setLayoutData(gd);
101:
102: fAntCombo = new Combo(comp, SWT.NONE);
103: fAntCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
104:
105: fBrowseAnt = new Button(comp, SWT.PUSH);
106: fBrowseAnt.setText(PDEUIMessages.ExportWizard_browse);
107: fBrowseAnt.setLayoutData(new GridData());
108: SWTUtil.setButtonDimensionHint(fBrowseAnt);
109: }
110:
111: protected void addQualifierOption(Composite container) {
112: Composite comp = new Composite(container, SWT.NONE);
113: GridLayout layout = new GridLayout(2, false);
114: layout.marginHeight = layout.marginWidth = 0;
115: comp.setLayout(layout);
116: comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
117:
118: fQualifierButton = new Button(comp, SWT.CHECK);
119: fQualifierButton
120: .setText(PDEUIMessages.AdvancedPluginExportPage_qualifier);
121:
122: fQualifierText = new Text(comp, SWT.SINGLE | SWT.BORDER);
123: fQualifierText.setLayoutData(new GridData(
124: GridData.FILL_HORIZONTAL));
125: fQualifierText.addModifyListener(new ModifyListener() {
126: public void modifyText(ModifyEvent e) {
127: fPage.pageChanged();
128: }
129: });
130: }
131:
132: protected void initialize(IDialogSettings settings) {
133: fIncludeSource.setSelection(settings
134: .getBoolean(S_EXPORT_SOURCE));
135: fJarButton.setSelection(getInitialJarButtonSelection(settings));
136: fSaveAsAntButton.setSelection(settings
137: .getBoolean(S_SAVE_AS_ANT));
138: initializeCombo(settings, S_ANT_FILENAME, fAntCombo);
139: fAntCombo.setEnabled(fSaveAsAntButton.getSelection());
140: fBrowseAnt.setEnabled(fSaveAsAntButton.getSelection());
141: fQualifierButton.setSelection(settings.getBoolean(S_QUALIFIER));
142: fQualifierText.setText(getInitialQualifierText(settings));
143: fQualifierText.setEnabled(fQualifierButton.getSelection());
144: hookListeners();
145: }
146:
147: protected void saveSettings(IDialogSettings settings) {
148: settings.put(S_JAR_FORMAT, fJarButton.getSelection());
149: settings.put(S_EXPORT_SOURCE, fIncludeSource.getSelection());
150: settings.put(S_SAVE_AS_ANT, fSaveAsAntButton.getSelection());
151: settings.put(S_QUALIFIER, fQualifierButton.getSelection());
152: settings.put(S_QUALIFIER_NAME, fQualifierText.getText());
153: saveCombo(settings, S_ANT_FILENAME, fAntCombo);
154: }
155:
156: private String getInitialQualifierText(IDialogSettings settings) {
157: String qualifier = settings.get(S_QUALIFIER_NAME);
158: if (qualifier == null || qualifier.equals("")) //$NON-NLS-1$
159: return FeatureExportOperation.getDate();
160: return qualifier;
161: }
162:
163: protected boolean getInitialJarButtonSelection(
164: IDialogSettings settings) {
165: String selected = settings.get(S_JAR_FORMAT);
166: return selected == null ? TargetPlatformHelper
167: .getTargetVersion() >= 3.1 : "true".equals(selected); //$NON-NLS-1$
168: }
169:
170: protected void hookListeners() {
171: fJarButton.addSelectionListener(new SelectionAdapter() {
172: public void widgetSelected(SelectionEvent e) {
173: ((BaseExportWizardPage) fPage)
174: .adjustAdvancedTabsVisibility();
175: }
176: });
177: fSaveAsAntButton.addSelectionListener(new SelectionAdapter() {
178: public void widgetSelected(SelectionEvent e) {
179: fAntCombo.setEnabled(fSaveAsAntButton.getSelection());
180: fBrowseAnt.setEnabled(fSaveAsAntButton.getSelection());
181: fPage.pageChanged();
182: }
183: });
184:
185: fBrowseAnt.addSelectionListener(new SelectionAdapter() {
186: public void widgetSelected(SelectionEvent e) {
187: chooseFile(fAntCombo, "*.xml"); //$NON-NLS-1$
188: }
189: });
190:
191: fAntCombo.addSelectionListener(new SelectionAdapter() {
192: public void widgetSelected(SelectionEvent e) {
193: fPage.pageChanged();
194: }
195: });
196:
197: fAntCombo.addModifyListener(new ModifyListener() {
198: public void modifyText(ModifyEvent e) {
199: fPage.pageChanged();
200: }
201: });
202: fQualifierButton.addSelectionListener(new SelectionAdapter() {
203: public void widgetSelected(SelectionEvent e) {
204: fQualifierText.setEnabled(fQualifierButton
205: .getSelection());
206: fPage.pageChanged();
207: }
208: });
209: }
210:
211: protected String validate() {
212: if (fSaveAsAntButton.getSelection()
213: && fAntCombo.getText().trim().length() == 0)
214: return PDEUIMessages.ExportWizard_status_noantfile;
215: return null;
216: }
217:
218: protected String validateAntCombo() {
219: String path = new Path(fAntCombo.getText()).lastSegment();
220: if ("build.xml".equals(path)) //$NON-NLS-1$
221: return PDEUIMessages.ExportOptionsTab_antReservedMessage;
222: return null;
223: }
224:
225: protected boolean doExportSource() {
226: return fIncludeSource.getSelection();
227: }
228:
229: protected boolean useJARFormat() {
230: return fJarButton.getSelection();
231: }
232:
233: protected boolean doGenerateAntFile() {
234: return fSaveAsAntButton.getSelection();
235: }
236:
237: protected String getAntBuildFileName() {
238: return fSaveAsAntButton.getSelection() ? fAntCombo.getText()
239: : null;
240: }
241:
242: protected String getQualifier() {
243: if (fQualifierText.isEnabled()) {
244: String qualifier = fQualifierText.getText().trim();
245: if (qualifier.length() > 0)
246: return qualifier;
247: }
248: return null;
249: }
250:
251: }
|