KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javadocexport > JavadocSpecificsWizardPage


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.jdt.internal.ui.javadocexport;
12
13 import java.io.File JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Path;
18
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 import org.eclipse.jface.dialogs.Dialog;
33
34 import org.eclipse.ui.PlatformUI;
35
36 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
37 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
38 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
39 import org.eclipse.jdt.internal.ui.util.SWTUtil;
40
41 public class JavadocSpecificsWizardPage extends JavadocWizardPage {
42
43     private Button fAntBrowseButton;
44     private Button fCheckbrowser;
45     private Text fAntText;
46     private Button fOverViewButton;
47     private Button fOverViewBrowseButton;
48     private Button fAntButton;
49     private Combo fSourceCombo;
50     
51     private Composite fLowerComposite;
52     private Text fOverViewText;
53     private Text fExtraOptionsText;
54     private Text fVMOptionsText;
55
56     private StatusInfo fOverviewStatus;
57     private StatusInfo fAntStatus;
58     
59     private JavadocTreeWizardPage fFirstPage;
60
61     private JavadocOptionsManager fStore;
62
63     private final int OVERVIEWSTATUS= 1;
64     private final int ANTSTATUS= 2;
65
66     protected JavadocSpecificsWizardPage(String JavaDoc pageName, JavadocTreeWizardPage firstPage, JavadocOptionsManager store) {
67         super(pageName);
68         setDescription(JavadocExportMessages.JavadocSpecificsWizardPage_description);
69
70         fStore= store;
71
72         fOverviewStatus= new StatusInfo();
73         fAntStatus= new StatusInfo();
74         fFirstPage= firstPage;
75     }
76
77     /*
78      * @see IDialogPage#createControl(Composite)
79      */

80     public void createControl(Composite parent) {
81         initializeDialogUnits(parent);
82
83         fLowerComposite= new Composite(parent, SWT.NONE);
84         fLowerComposite.setLayoutData(createGridData(GridData.FILL_BOTH, 1, 0));
85
86         GridLayout layout= createGridLayout(3);
87         layout.marginHeight= 0;
88         fLowerComposite.setLayout(layout);
89
90         createExtraOptionsGroup(fLowerComposite);
91         createAntGroup(fLowerComposite);
92
93         setControl(fLowerComposite);
94         Dialog.applyDialogFont(fLowerComposite);
95         PlatformUI.getWorkbench().getHelpSystem().setHelp(fLowerComposite, IJavaHelpContextIds.JAVADOC_SPECIFICS_PAGE);
96
97     } //end method createControl
98

99     private void createExtraOptionsGroup(Composite composite) {
100         Composite c= new Composite(composite, SWT.NONE);
101         c.setLayout(createGridLayout(3));
102         c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 3, 0));
103         ((GridLayout) c.getLayout()).marginWidth= 0;
104
105         fOverViewButton= createButton(c, SWT.CHECK, JavadocExportMessages.JavadocSpecificsWizardPage_overviewbutton_label, createGridData(1));
106         fOverViewText= createText(c, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
107         //there really aught to be a way to specify this
108
((GridData) fOverViewText.getLayoutData()).widthHint= 200;
109         fOverViewBrowseButton= createButton(c, SWT.PUSH, JavadocExportMessages.JavadocSpecificsWizardPage_overviewbrowse_label, createGridData(GridData.HORIZONTAL_ALIGN_END, 1, 0));
110         SWTUtil.setButtonDimensionHint(fOverViewBrowseButton);
111
112         String JavaDoc str= fStore.getOverview();
113         if (str.length() == 0) {
114             //default
115
fOverViewText.setEnabled(false);
116             fOverViewBrowseButton.setEnabled(false);
117         } else {
118             fOverViewButton.setSelection(true);
119             fOverViewText.setText(str);
120         }
121
122         createLabel(composite, SWT.NONE, JavadocExportMessages.JavadocSpecificsWizardPage_vmoptionsfield_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 3, 0));
123         fVMOptionsText= createText(composite, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL, 3, 0));
124         fVMOptionsText.setText(fStore.getVMParams());
125         
126         
127         createLabel(composite, SWT.NONE, JavadocExportMessages.JavadocSpecificsWizardPage_extraoptionsfield_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 3, 0));
128         fExtraOptionsText= createText(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL, 3, 0));
129         //fExtraOptionsText.setSize(convertWidthInCharsToPixels(60), convertHeightInCharsToPixels(10));
130

131         fExtraOptionsText.setText(fStore.getAdditionalParams());
132         
133         Composite inner= new Composite(composite, SWT.NONE);
134         inner.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false, 3, 1));
135         GridLayout layout= new GridLayout(2, false);
136         layout.marginHeight= 0;
137         layout.marginWidth= 0;
138         inner.setLayout(layout);
139         
140         createLabel(inner, SWT.NONE, JavadocExportMessages.JavadocSpecificsWizardPage_sourcecompatibility_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 0));
141
142         fSourceCombo= createCombo(inner, SWT.NONE, fStore.getSource(), createGridData(1));
143         String JavaDoc[] versions= { "-", "1.3", "1.4", "1.5", "1.6" };//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
144
fSourceCombo.setItems(versions);
145         fSourceCombo.setText(fStore.getSource());
146         
147         
148         //Listeners
149
fOverViewButton.addSelectionListener(new ToggleSelectionAdapter(new Control[] { fOverViewBrowseButton, fOverViewText }) {
150             public void validate() {
151                 doValidation(OVERVIEWSTATUS);
152             }
153         });
154
155         fOverViewText.addModifyListener(new ModifyListener() {
156             public void modifyText(ModifyEvent e) {
157                 doValidation(OVERVIEWSTATUS);
158             }
159         });
160
161         fOverViewBrowseButton.addSelectionListener(new SelectionAdapter() {
162             public void widgetSelected(SelectionEvent event) {
163                 handleFileBrowseButtonPressed(fOverViewText, new String JavaDoc[] { "*.html" }, JavadocExportMessages.JavadocSpecificsWizardPage_overviewbrowsedialog_title); //$NON-NLS-1$
164
}
165         });
166
167     }
168
169     private void createAntGroup(Composite composite) {
170         Composite c= new Composite(composite, SWT.NONE);
171         c.setLayout(createGridLayout(3));
172         c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 3, 0));
173         ((GridLayout) c.getLayout()).marginWidth= 0;
174
175         fAntButton= createButton(c, SWT.CHECK, JavadocExportMessages.JavadocSpecificsWizardPage_antscriptbutton_label, createGridData(3));
176         createLabel(c, SWT.NONE, JavadocExportMessages.JavadocSpecificsWizardPage_antscripttext_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 0));
177         fAntText= createText(c, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
178         //there really aught to be a way to specify this
179
((GridData) fAntText.getLayoutData()).widthHint= 200;
180
181         fAntText.setText(fStore.getAntpath());
182
183         fAntBrowseButton= createButton(c, SWT.PUSH, JavadocExportMessages.JavadocSpecificsWizardPage_antscriptbrowse_label, createGridData(GridData.HORIZONTAL_ALIGN_END, 1, 0));
184         SWTUtil.setButtonDimensionHint(fAntBrowseButton);
185         fAntText.setEnabled(false);
186         fAntBrowseButton.setEnabled(false);
187         
188         fCheckbrowser= createButton(c, SWT.CHECK, JavadocExportMessages.JavadocSpecificsWizardPage_openbrowserbutton_label, createGridData(3));
189         fCheckbrowser.setSelection(fStore.doOpenInBrowser());
190
191         fAntButton.addSelectionListener(new ToggleSelectionAdapter(new Control[] { fAntText, fAntBrowseButton }) {
192             public void validate() {
193                 doValidation(ANTSTATUS);
194             }
195         });
196
197         fAntText.addModifyListener(new ModifyListener() {
198             public void modifyText(ModifyEvent e) {
199                 doValidation(ANTSTATUS);
200             }
201         });
202
203         fAntBrowseButton.addSelectionListener(new SelectionAdapter() {
204             public void widgetSelected(SelectionEvent event) {
205                 String JavaDoc temp= fAntText.getText();
206                 IPath path= Path.fromOSString(temp);
207                 String JavaDoc file= path.lastSegment();
208                 if (file == null)
209                     file= "javadoc.xml";//$NON-NLS-1$
210
path= path.removeLastSegments(1);
211
212                 String JavaDoc selected= handleFolderBrowseButtonPressed(path.toOSString(), JavadocExportMessages.JavadocSpecificsWizardPage_antscriptbrowsedialog_title, JavadocExportMessages.JavadocSpecificsWizardPage_antscriptbrowsedialog_label);
213
214                 path= Path.fromOSString(selected).append(file);
215                 fAntText.setText(path.toOSString());
216
217             }
218         });
219     } //end method createExtraOptionsGroup
220

221     private void doValidation(int val) {
222         switch (val) {
223
224             case OVERVIEWSTATUS :
225                 fOverviewStatus= new StatusInfo();
226                 if (fOverViewButton.getSelection()) {
227                     String JavaDoc filename= fOverViewText.getText();
228                     if (filename.length() == 0) {
229                         fOverviewStatus.setError(JavadocExportMessages.JavadocSpecificsWizardPage_overviewnotfound_error);
230                     } else {
231                         File JavaDoc file= new File JavaDoc(filename);
232                         String JavaDoc ext= filename.substring(filename.lastIndexOf('.') + 1);
233                         if (!file.isFile()) {
234                             fOverviewStatus.setError(JavadocExportMessages.JavadocSpecificsWizardPage_overviewnotfound_error);
235                         } else if (!ext.equalsIgnoreCase("html")) { //$NON-NLS-1$
236
fOverviewStatus.setError(JavadocExportMessages.JavadocSpecificsWizardPage_overviewincorrect_error);
237                         }
238                     }
239                 }
240                 break;
241             case ANTSTATUS :
242                 fAntStatus= new StatusInfo();
243                 if (fAntButton.getSelection()) {
244                     String JavaDoc filename= fAntText.getText();
245                     if (filename.length() == 0) {
246                         fOverviewStatus.setError(JavadocExportMessages.JavadocSpecificsWizardPage_antfileincorrect_error);
247                     } else {
248                         File JavaDoc file= new File JavaDoc(filename);
249                         String JavaDoc ext= filename.substring(filename.lastIndexOf('.') + 1);
250                         if (file.isDirectory() || !(ext.equalsIgnoreCase("xml"))) //$NON-NLS-1$
251
fAntStatus.setError(JavadocExportMessages.JavadocSpecificsWizardPage_antfileincorrect_error);
252                         else if (file.exists())
253                             fAntStatus.setWarning(JavadocExportMessages.JavadocSpecificsWizardPage_antfileoverwrite_warning);
254                     }
255                 }
256                 break;
257         }
258
259         updateStatus(findMostSevereStatus());
260
261     }
262
263     /*
264      * @see JavadocWizardPage#onFinish()
265      */

266
267     protected void updateStore() {
268
269         fStore.setVMParams(fVMOptionsText.getText());
270         fStore.setAdditionalParams(fExtraOptionsText.getText());
271
272         if (fOverViewText.getEnabled())
273             fStore.setOverview(fOverViewText.getText());
274         else
275             fStore.setOverview(""); //$NON-NLS-1$
276

277         //for now if there are multiple then the ant file is not stored for specific projects
278
if (fAntText.getEnabled()) {
279             fStore.setGeneralAntpath(fAntText.getText());
280         }
281         fStore.setOpenInBrowser(fCheckbrowser.getSelection());
282         fStore.setSource(fSourceCombo.getText());
283
284     }
285
286     public void setVisible(boolean visible) {
287         super.setVisible(visible);
288         if (visible) {
289             doValidation(OVERVIEWSTATUS);
290             doValidation(ANTSTATUS);
291             fCheckbrowser.setVisible(!fFirstPage.getCustom());
292         }
293     }
294
295     public void init() {
296         updateStatus(new StatusInfo());
297     }
298
299     private IStatus findMostSevereStatus() {
300         return StatusUtil.getMostSevere(new IStatus[] { fAntStatus, fOverviewStatus });
301     }
302
303     public boolean generateAnt() {
304         return fAntButton.getSelection();
305     }
306
307 }
308
Popular Tags