KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.swt.events.SelectionAdapter;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Combo;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.DirectoryDialog;
24 import org.eclipse.swt.widgets.FileDialog;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
27
28 import org.eclipse.jdt.ui.wizards.NewElementWizardPage;
29
30 public abstract class JavadocWizardPage extends NewElementWizardPage {
31
32     protected JavadocWizardPage(String JavaDoc pageName) {
33         super(pageName);
34         setTitle(JavadocExportMessages.JavadocWizardPage_javadocwizardpage_description);
35     }
36
37     protected Button createButton(Composite composite, int style, String JavaDoc message, GridData gd) {
38         Button button= new Button(composite, style);
39         button.setText(message);
40         button.setLayoutData(gd);
41         return button;
42     }
43
44     protected GridLayout createGridLayout(int columns) {
45         return new GridLayout(columns, false);
46
47     }
48
49     protected GridData createGridData(int flag, int hspan, int vspan, int indent) {
50         GridData gd= new GridData(flag);
51         gd.horizontalIndent= indent;
52         gd.horizontalSpan= hspan;
53         gd.verticalSpan= vspan;
54         return gd;
55     }
56
57     protected GridData createGridData(int flag, int hspan, int indent) {
58         GridData gd= new GridData(flag);
59         gd.horizontalIndent= indent;
60         gd.horizontalSpan= hspan;
61         return gd;
62     }
63
64     protected GridData createGridData(int hspan) {
65         GridData gd= new GridData();
66         gd.horizontalSpan= hspan;
67         return gd;
68     }
69
70     protected Label createLabel(Composite composite, int style, String JavaDoc message, GridData gd) {
71         Label label= new Label(composite, style);
72         label.setText(message);
73         label.setLayoutData(gd);
74         return label;
75     }
76
77     protected Text createText(Composite composite, int style, String JavaDoc message, GridData gd) {
78         Text text= new Text(composite, style);
79         if (message != null)
80             text.setText(message);
81         text.setLayoutData(gd);
82         return text;
83     }
84     
85     protected Combo createCombo(Composite composite, int style, String JavaDoc message, GridData gd) {
86         Combo combo= new Combo(composite, style);
87         if (message != null)
88             combo.setText(message);
89         combo.setLayoutData(gd);
90         return combo;
91     }
92
93     protected void handleFileBrowseButtonPressed(Text text, String JavaDoc[] extensions, String JavaDoc title) {
94         FileDialog dialog= new FileDialog(text.getShell());
95         dialog.setText(title);
96         dialog.setFilterExtensions(extensions);
97         String JavaDoc dirName= text.getText();
98         if (!dirName.equals("")) { //$NON-NLS-1$
99
File JavaDoc path= new File JavaDoc(dirName);
100             if (path.exists())
101                 dialog.setFilterPath(dirName);
102
103         }
104         String JavaDoc selectedDirectory= dialog.open();
105         if (selectedDirectory != null)
106             text.setText(selectedDirectory);
107     }
108
109     protected String JavaDoc handleFolderBrowseButtonPressed(String JavaDoc dir, String JavaDoc title, String JavaDoc message) {
110         DirectoryDialog dialog= new DirectoryDialog(getShell());
111         dialog.setFilterPath(dir);
112         dialog.setText(title);
113         dialog.setMessage(message);
114         String JavaDoc res= dialog.open();
115         if (res != null) {
116             File JavaDoc file= new File JavaDoc(res);
117             if (file.isDirectory())
118                 return res;
119         }
120         return dir;
121     }
122
123     protected static class EnableSelectionAdapter extends SelectionAdapter {
124         private Control[] fEnable;
125         private Control[] fDisable;
126
127         protected EnableSelectionAdapter(Control[] enable, Control[] disable) {
128             super();
129             fEnable= enable;
130             fDisable= disable;
131         }
132
133         public void widgetSelected(SelectionEvent e) {
134             for (int i= 0; i < fEnable.length; i++) {
135                 fEnable[i].setEnabled(true);
136             }
137             for (int i= 0; i < fDisable.length; i++) {
138                 fDisable[i].setEnabled(false);
139             }
140             validate();
141         }
142         //copied from WizardNewProjectCreationPage
143
public void validate() {
144         }
145
146     } //end class EnableSelectionAdapter
147

148     protected static class ToggleSelectionAdapter extends SelectionAdapter {
149         Control[] controls;
150
151         protected ToggleSelectionAdapter(Control[] controls) {
152             this.controls= controls;
153         }
154
155         public void widgetSelected(SelectionEvent e) {
156
157             for (int i= 0; i < controls.length; i++) {
158                 Control control= controls[i];
159                 control.setEnabled(!control.getEnabled());
160             }
161             validate();
162         }
163
164         public void validate() {
165         }
166
167     } //end class ToggleSelection Adapter
168

169 }
170
Popular Tags