2828import org .eclipse .swt .events .KeyEvent ;
2929import org .eclipse .swt .events .ModifyEvent ;
3030import org .eclipse .swt .events .ModifyListener ;
31+ import org .eclipse .swt .events .SelectionAdapter ;
3132import org .eclipse .swt .events .SelectionEvent ;
3233import org .eclipse .swt .events .SelectionListener ;
3334import org .eclipse .swt .layout .GridData ;
4647 * @author Kondal Kolipaka <[email protected] > 4748 *
4849 */
49- public class ImportIDFProjectWizardPage extends WizardPage {
50+ public class ImportIDFProjectWizardPage extends WizardPage
51+ {
5052
5153 private Text projectName ;
5254 private Text location ;
5355 private IWorkspaceRoot root ;
5456
5557 /**
56- * True if the user entered a non-empty string in the project name field. In that state, we avoid
57- * automatically filling the project name field with the directory name (last segment of the location) he
58- * has entered.
58+ * True if the user entered a non-empty string in the project name field. In that state, we avoid automatically
59+ * filling the project name field with the directory name (last segment of the location) he has entered.
5960 */
6061 boolean projectNameSetByUser ;
62+ private Button copyCheckbox ;
63+ private boolean copyProject ;
6164
62- protected ImportIDFProjectWizardPage () {
65+ protected ImportIDFProjectWizardPage ()
66+ {
6367 super (Messages .ImportIDFProjectWizardPage_0 );
6468 setTitle (Messages .ImportIDFProjectWizardPage_1 );
6569 setDescription (Messages .ImportIDFProjectWizardPage_2 );
@@ -68,7 +72,8 @@ protected ImportIDFProjectWizardPage() {
6872 }
6973
7074 @ Override
71- public void createControl (Composite parent ) {
75+ public void createControl (Composite parent )
76+ {
7277 Composite comp = new Composite (parent , SWT .NONE );
7378 GridLayout layout = new GridLayout ();
7479 comp .setLayout (layout );
@@ -77,9 +82,27 @@ public void createControl(Composite parent) {
7782 addProjectNameSelector (comp );
7883 addSourceSelector (comp );
7984 setControl (comp );
85+ createOptions (comp );
8086 }
8187
82- public void addProjectNameSelector (Composite parent ) {
88+ public void createOptions (Composite comp )
89+ {
90+ copyCheckbox = new Button (comp , SWT .CHECK );
91+ copyCheckbox .setText (Messages .ImportIDFProjectWizardPage_CopyIntoWorkspace );
92+ copyCheckbox .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
93+ copyCheckbox .addSelectionListener (new SelectionAdapter ()
94+ {
95+ @ Override
96+ public void widgetSelected (SelectionEvent e )
97+ {
98+ copyProject = copyCheckbox .getSelection ();
99+ }
100+ });
101+
102+ }
103+
104+ public void addProjectNameSelector (Composite parent )
105+ {
83106 Group group = new Group (parent , SWT .NONE );
84107 GridLayout layout = new GridLayout ();
85108 layout .numColumns = 2 ;
@@ -89,21 +112,26 @@ public void addProjectNameSelector(Composite parent) {
89112
90113 projectName = new Text (group , SWT .BORDER );
91114 projectName .setLayoutData (new GridData (SWT .FILL , SWT .FILL , true , true ));
92- projectName .addModifyListener (new ModifyListener () {
115+ projectName .addModifyListener (new ModifyListener ()
116+ {
93117 @ Override
94- public void modifyText (ModifyEvent e ) {
118+ public void modifyText (ModifyEvent e )
119+ {
95120 validatePage ();
96- if (getProjectName ().isEmpty ()) {
121+ if (getProjectName ().isEmpty ())
122+ {
97123 projectNameSetByUser = false ;
98124 }
99125 }
100126 });
101127
102128 // Note that the modify listener gets called not only when the user enters text but also when we
103129 // programatically set the field. This listener only gets called when the user modifies the field
104- projectName .addKeyListener (new KeyAdapter () {
130+ projectName .addKeyListener (new KeyAdapter ()
131+ {
105132 @ Override
106- public void keyPressed (KeyEvent e ) {
133+ public void keyPressed (KeyEvent e )
134+ {
107135 projectNameSetByUser = true ;
108136 }
109137 });
@@ -113,44 +141,61 @@ public void keyPressed(KeyEvent e) {
113141 * Validates the contents of the page, setting the page error message and Finish button state accordingly
114142 *
115143 */
116- protected void validatePage () {
144+ protected void validatePage ()
145+ {
117146 // Don't generate an error if project name or location is empty, but do disable Finish button.
118147 String msg = null ;
119148 boolean complete = true ; // ultimately treated as false if msg != null
120149
121150 String name = getProjectName ();
122- if (name .isEmpty ()) {
151+ if (name .isEmpty ())
152+ {
123153 complete = false ;
124- } else {
154+ }
155+ else
156+ {
125157 IStatus status = ResourcesPlugin .getWorkspace ().validateName (name , IResource .PROJECT );
126- if (!status .isOK ()) {
158+ if (!status .isOK ())
159+ {
127160 msg = status .getMessage ();
128- } else {
161+ }
162+ else
163+ {
129164 IProject project = root .getProject (name );
130- if (project .exists ()) {
165+ if (project .exists ())
166+ {
131167 msg = Messages .ImportIDFProjectWizardPage_4 ;
132168
133169 }
134170 }
135171 }
136- if (msg == null ) {
172+ if (msg == null )
173+ {
137174 String loc = getLocation ();
138- if (loc .isEmpty ()) {
175+ if (loc .isEmpty ())
176+ {
139177 complete = false ;
140- } else {
178+ }
179+ else
180+ {
141181 final File file = new File (loc );
142- if (file .isDirectory ()) {
182+ if (file .isDirectory ())
183+ {
143184 // Ensure we can create files in the directory.
144185 if (!file .canWrite ())
145186 msg = Messages .ImportIDFProjectWizardPage_5 ;
146187 // Set the project name to the directory name but not if the user has supplied a name
147188 // (bugzilla 368987). Use a job to ensure proper sequence of activity, as setting the Text
148189 // will invoke the listener, which will invoke this method.
149- else if (!projectNameSetByUser && !name .equals (file .getName ())) {
150- WorkbenchJob wjob = new WorkbenchJob ("update project name" ) { //$NON-NLS-1$
190+ else if (!projectNameSetByUser && !name .equals (file .getName ()))
191+ {
192+ WorkbenchJob wjob = new WorkbenchJob ("update project name" ) //$NON-NLS-1$
193+ {
151194 @ Override
152- public IStatus runInUIThread (IProgressMonitor monitor ) {
153- if (!projectName .isDisposed ()) {
195+ public IStatus runInUIThread (IProgressMonitor monitor )
196+ {
197+ if (!projectName .isDisposed ())
198+ {
154199 projectName .setText (file .getName ());
155200 }
156201 return Status .OK_STATUS ;
@@ -159,7 +204,9 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
159204 wjob .setSystem (true );
160205 wjob .schedule ();
161206 }
162- } else {
207+ }
208+ else
209+ {
163210 msg = Messages .ImportIDFProjectWizardPage_6 ;
164211 }
165212 }
@@ -171,11 +218,13 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
171218
172219 /** @deprecated Replaced by {@link #validatePage()} */
173220 @ Deprecated
174- public void validateProjectName () {
221+ public void validateProjectName ()
222+ {
175223 validatePage ();
176224 }
177225
178- public void addSourceSelector (Composite parent ) {
226+ public void addSourceSelector (Composite parent )
227+ {
179228 Group group = new Group (parent , SWT .NONE );
180229 GridLayout layout = new GridLayout ();
181230 layout .numColumns = 2 ;
@@ -185,9 +234,11 @@ public void addSourceSelector(Composite parent) {
185234
186235 location = new Text (group , SWT .BORDER );
187236 location .setLayoutData (new GridData (SWT .FILL , SWT .FILL , true , true ));
188- location .addModifyListener (new ModifyListener () {
237+ location .addModifyListener (new ModifyListener ()
238+ {
189239 @ Override
190- public void modifyText (ModifyEvent e ) {
240+ public void modifyText (ModifyEvent e )
241+ {
191242 validatePage ();
192243 }
193244 });
@@ -196,9 +247,11 @@ public void modifyText(ModifyEvent e) {
196247 Button browse = new Button (group , SWT .NONE );
197248 browse .setLayoutData (new GridData (SWT .FILL , SWT .FILL , false , true ));
198249 browse .setText (Messages .ImportIDFProjectWizardPage_8 );
199- browse .addSelectionListener (new SelectionListener () {
250+ browse .addSelectionListener (new SelectionListener ()
251+ {
200252 @ Override
201- public void widgetSelected (SelectionEvent e ) {
253+ public void widgetSelected (SelectionEvent e )
254+ {
202255 DirectoryDialog dialog = new DirectoryDialog (location .getShell ());
203256 dialog .setMessage (Messages .ImportIDFProjectWizardPage_9 );
204257 String dir = dialog .open ();
@@ -207,23 +260,32 @@ public void widgetSelected(SelectionEvent e) {
207260 }
208261
209262 @ Override
210- public void widgetDefaultSelected (SelectionEvent e ) {
263+ public void widgetDefaultSelected (SelectionEvent e )
264+ {
211265 }
212266 });
213267 }
214268
215269 /** @deprecated Replaced by {@link #validatePage()} */
216270 @ Deprecated
217- void validateSource () {
271+ void validateSource ()
272+ {
218273 validatePage ();
219274 }
220-
221- public String getProjectName () {
275+
276+ public String getProjectName ()
277+ {
222278 return projectName .getText ().trim ();
223279 }
224280
225- public String getLocation () {
281+ public String getLocation ()
282+ {
226283 return location .getText ().trim ();
227284 }
228285
286+ public boolean canCopyIntoWorkspace ()
287+ {
288+ return copyProject ;
289+ }
290+
229291}
0 commit comments