KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > ExportOptionsTab


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.wizards.exports;
12
13 import org.eclipse.core.runtime.Path;
14 import org.eclipse.jface.dialogs.IDialogSettings;
15 import org.eclipse.pde.internal.core.TargetPlatformHelper;
16 import org.eclipse.pde.internal.core.exports.FeatureExportOperation;
17 import org.eclipse.pde.internal.ui.PDEUIMessages;
18 import org.eclipse.pde.internal.ui.util.SWTUtil;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.ModifyEvent;
21 import org.eclipse.swt.events.ModifyListener;
22 import org.eclipse.swt.events.SelectionAdapter;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Combo;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Text;
31
32 public class ExportOptionsTab extends AbstractExportTab {
33
34     protected static final String JavaDoc S_JAR_FORMAT = "exportUpdate"; //$NON-NLS-1$
35
private static final String JavaDoc S_EXPORT_SOURCE="exportSource"; //$NON-NLS-1$
36
private static final String JavaDoc S_SAVE_AS_ANT = "saveAsAnt"; //$NON-NLS-1$
37
private static final String JavaDoc S_ANT_FILENAME = "antFileName"; //$NON-NLS-1$
38
private static final String JavaDoc S_QUALIFIER = "qualifier"; //$NON-NLS-1$
39
private static final String JavaDoc S_QUALIFIER_NAME = "qualifierName"; //$NON-NLS-1$
40

41     private Button fIncludeSource;
42     protected Button fJarButton;
43     private Button fSaveAsAntButton;
44     private Combo fAntCombo;
45     private Button fBrowseAnt;
46     
47     private Button fQualifierButton;
48     private Text fQualifierText;
49
50     public ExportOptionsTab(BaseExportWizardPage page) {
51         super(page);
52     }
53
54     protected Control createControl(Composite parent) {
55         Composite container = new Composite(parent, SWT.NONE);
56         container.setLayout(new GridLayout());
57         container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
58         
59         addSourceOption(container);
60         addJAROption(container);
61         addCrossPlatformOption(container);
62         addQualifierOption(container);
63         addAntSection(container);
64                                     
65         return container;
66     }
67     
68     protected void addSourceOption(Composite comp) {
69         fIncludeSource = new Button(comp, SWT.CHECK);
70         fIncludeSource.setText(PDEUIMessages.ExportWizard_includeSource);
71     }
72     
73     protected void addJAROption(Composite comp) {
74         fJarButton = new Button(comp, SWT.CHECK);
75         fJarButton.setText(getJarButtonText());
76         fJarButton.addSelectionListener(new SelectionAdapter() {
77             public void widgetSelected(SelectionEvent e) {
78             }
79         });
80     }
81     
82     protected String JavaDoc getJarButtonText() {
83         return PDEUIMessages.BaseExportWizardPage_packageJARs;
84     }
85
86     protected void addCrossPlatformOption(Composite comp) {
87     }
88     
89     protected void addAntSection(Composite container) {
90         Composite comp = new Composite(container, SWT.NONE);
91         GridLayout layout = new GridLayout(3, false);
92         layout.marginHeight = layout.marginWidth = 0;
93         comp.setLayout(layout);
94         comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
95         
96         fSaveAsAntButton = new Button(comp, SWT.CHECK);
97         fSaveAsAntButton.setText(PDEUIMessages.ExportWizard_antCheck);
98         GridData gd = new GridData();
99         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.setText(PDEUIMessages.AdvancedPluginExportPage_qualifier);
120         
121         fQualifierText = new Text(comp, SWT.SINGLE|SWT.BORDER);
122         fQualifierText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
123         fQualifierText.addModifyListener(new ModifyListener() {
124             public void modifyText(ModifyEvent e) {
125                 fPage.pageChanged();
126             }
127         });
128     }
129
130     protected void initialize(IDialogSettings settings) {
131         fIncludeSource.setSelection(settings.getBoolean(S_EXPORT_SOURCE));
132         fJarButton.setSelection(getInitialJarButtonSelection(settings));
133         fSaveAsAntButton.setSelection(settings.getBoolean(S_SAVE_AS_ANT));
134         initializeCombo(settings, S_ANT_FILENAME, fAntCombo);
135         fAntCombo.setEnabled(fSaveAsAntButton.getSelection());
136         fBrowseAnt.setEnabled(fSaveAsAntButton.getSelection());
137         fQualifierButton.setSelection(settings.getBoolean(S_QUALIFIER));
138         fQualifierText.setText(getInitialQualifierText(settings));
139         fQualifierText.setEnabled(fQualifierButton.getSelection());
140         hookListeners();
141     }
142
143     protected void saveSettings(IDialogSettings settings) {
144         settings.put(S_JAR_FORMAT, fJarButton.getSelection());
145         settings.put(S_EXPORT_SOURCE, fIncludeSource.getSelection());
146         settings.put(S_SAVE_AS_ANT, fSaveAsAntButton.getSelection());
147         settings.put(S_QUALIFIER, fQualifierButton.getSelection());
148         settings.put(S_QUALIFIER_NAME, fQualifierText.getText());
149         saveCombo(settings, S_ANT_FILENAME, fAntCombo);
150     }
151     
152     private String JavaDoc getInitialQualifierText(IDialogSettings settings) {
153         String JavaDoc qualifier = settings.get(S_QUALIFIER_NAME);
154         if(qualifier == null || qualifier.equals("")) //$NON-NLS-1$
155
return FeatureExportOperation.getDate();
156         return qualifier;
157     }
158     
159     protected boolean getInitialJarButtonSelection(IDialogSettings settings){
160         String JavaDoc selected = settings.get(S_JAR_FORMAT);
161         return selected == null
162                     ? TargetPlatformHelper.getTargetVersion() >= 3.1
163                     : "true".equals(selected); //$NON-NLS-1$
164
}
165     
166     protected void hookListeners() {
167         fJarButton.addSelectionListener(new SelectionAdapter() {
168             public void widgetSelected(SelectionEvent e) {
169                 ((BaseExportWizardPage)fPage).adjustAdvancedTabsVisibility();
170             }
171         });
172         fSaveAsAntButton.addSelectionListener(new SelectionAdapter() {
173             public void widgetSelected(SelectionEvent e) {
174                 fAntCombo.setEnabled(fSaveAsAntButton.getSelection());
175                 fBrowseAnt.setEnabled(fSaveAsAntButton.getSelection());
176                 fPage.pageChanged();
177             }}
178         );
179         
180         fBrowseAnt.addSelectionListener(new SelectionAdapter() {
181             public void widgetSelected(SelectionEvent e) {
182                 chooseFile(fAntCombo, "*.xml"); //$NON-NLS-1$
183
}
184         });
185         
186         fAntCombo.addSelectionListener(new SelectionAdapter() {
187             public void widgetSelected(SelectionEvent e) {
188                 fPage.pageChanged();
189             }
190         });
191         
192         fAntCombo.addModifyListener(new ModifyListener() {
193             public void modifyText(ModifyEvent e) {
194                 fPage.pageChanged();
195             }
196         });
197         fQualifierButton.addSelectionListener(new SelectionAdapter() {
198             public void widgetSelected(SelectionEvent e) {
199                 fQualifierText.setEnabled(fQualifierButton.getSelection());
200                 fPage.pageChanged();
201             }}
202         );
203     }
204     
205     protected String JavaDoc validate() {
206         if (fSaveAsAntButton.getSelection() && fAntCombo.getText().trim().length() == 0)
207             return PDEUIMessages.ExportWizard_status_noantfile;
208         return null;
209     }
210     
211     protected String JavaDoc validateAntCombo() {
212         String JavaDoc path = new Path(fAntCombo.getText()).lastSegment();
213         if ("build.xml".equals(path)) //$NON-NLS-1$
214
return PDEUIMessages.ExportOptionsTab_antReservedMessage;
215         return null;
216     }
217     
218     protected boolean doExportSource() {
219         return fIncludeSource.getSelection();
220     }
221     
222     protected boolean useJARFormat() {
223         return fJarButton.getSelection();
224     }
225     
226     protected boolean doGenerateAntFile() {
227         return fSaveAsAntButton.getSelection();
228     }
229
230     protected String JavaDoc getAntBuildFileName() {
231         return fSaveAsAntButton.getSelection() ? fAntCombo.getText() : null;
232     }
233     
234     protected String JavaDoc getQualifier() {
235         if(fQualifierText.isEnabled()) {
236             String JavaDoc qualifier = fQualifierText.getText().trim();
237             if (qualifier.length() > 0)
238                 return qualifier;
239         }
240         return null;
241     }
242     
243 }
244
Popular Tags