KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > wizards > datatransfer > WizardFileSystemImportPage1


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.wizards.datatransfer;
12
13 import java.io.File JavaDoc;
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.*;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.jface.dialogs.*;
20 import org.eclipse.jface.viewers.*;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.*;
25 import org.eclipse.ui.*;
26 import org.eclipse.ui.dialogs.*;
27
28 /**
29  * Page 1 of the base resource import-from-file-system Wizard
30  * @deprecated use WizardFileSystemResourceImportPage1
31  */

32 /*package*/ class WizardFileSystemImportPage1 extends WizardImportPage implements ISelectionChangedListener, Listener {
33     private List JavaDoc selectedResources;
34     private FileSystemElement root;
35
36     // widgets
37
protected Combo typesToImportField;
38     protected Button typesToImportEditButton;
39     protected Combo sourceNameField;
40     protected Button sourceBrowseButton;
41     protected Button importAllResourcesRadio;
42     protected Button importTypedResourcesRadio;
43     protected Button detailsButton;
44     protected Label detailsDescriptionLabel;
45     protected Button overwriteExistingResourcesCheckbox;
46     protected Button createContainerStructureCheckbox;
47     
48     // constants
49
private static final int SIZING_TEXT_FIELD_WIDTH = 250;
50     private static final String JavaDoc TYPE_DELIMITER = DataTransferMessages.getString("DataTransfer.typeDelimiter"); //$NON-NLS-1$
51

52     // dialog store id constants
53
private final static String JavaDoc STORE_SOURCE_NAMES_ID = "WizardFileSystemImportPage1.STORE_SOURCE_NAMES_ID";//$NON-NLS-1$
54
private final static String JavaDoc STORE_IMPORT_ALL_RESOURCES_ID = "WizardFileSystemImportPage1.STORE_IMPORT_ALL_FILES_ID";//$NON-NLS-1$
55
private final static String JavaDoc STORE_OVERWRITE_EXISTING_RESOURCES_ID = "WizardFileSystemImportPage1.STORE_OVERWRITE_EXISTING_RESOURCES_ID";//$NON-NLS-1$
56
private final static String JavaDoc STORE_CREATE_CONTAINER_STRUCTURE_ID = "WizardFileSystemImportPage1.STORE_CREATE_CONTAINER_STRUCTURE_ID";//$NON-NLS-1$
57
private final static String JavaDoc STORE_SELECTED_TYPES_ID = "WizardFileSystemImportPage1.STORE_SELECTED_TYPES_ID";//$NON-NLS-1$
58
/**
59  * Creates an instance of this class
60  */

61 protected WizardFileSystemImportPage1(String JavaDoc name, IWorkbench aWorkbench, IStructuredSelection selection) {
62     super(name,selection);
63 }
64 /**
65  * Creates an instance of this class
66  */

67 public WizardFileSystemImportPage1(IWorkbench aWorkbench, IStructuredSelection selection) {
68     this("fileSystemImportPage1", aWorkbench, selection);//$NON-NLS-1$
69
setTitle(DataTransferMessages.getString("DataTransfer.fileSystemTitle")); //$NON-NLS-1$
70
setDescription(DataTransferMessages.getString("FileImport.importFileSystem")); //$NON-NLS-1$
71
}
72 /**
73  * Adds the recursive contents of the passed file system element to this
74  * page's collection of selected resources.
75  */

76 protected void addToSelectedResources(FileSystemElement element) {
77     if (element.isDirectory()) {
78         Object JavaDoc[] children = element.getFolders().getChildren(element);
79         for (int i = 0; i < children.length; ++i) {
80             addToSelectedResources((FileSystemElement) children[i]);
81         }
82         children = element.getFiles().getChildren(element);
83         for (int i = 0; i < children.length; ++i) {
84             addToSelectedResources((FileSystemElement) children[i]);
85         }
86     } else
87         selectedResources.add(element);
88 }
89 /**
90  * Create the import options specification widgets.
91  */

92 protected void createOptionsGroup(Composite parent) {
93     // options group
94
Composite optionsGroup = new Composite(parent, SWT.NONE);
95     GridLayout layout = new GridLayout();
96     layout.marginHeight = 0;
97     optionsGroup.setLayout(layout);
98     optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
99
100     // overwrite... checkbox
101
overwriteExistingResourcesCheckbox = new Button(optionsGroup,SWT.CHECK);
102     overwriteExistingResourcesCheckbox.setText(DataTransferMessages.getString("FileImport.overwriteExisting")); //$NON-NLS-1$
103

104     // create containers checkbox
105
createContainerStructureCheckbox = new Button(optionsGroup,SWT.CHECK);
106     createContainerStructureCheckbox.setText(DataTransferMessages.getString("FileImport.createComplete")); //$NON-NLS-1$
107
}
108 /**
109  * Create the import source specification widgets
110  */

111 protected void createSourceGroup(Composite parent) {
112     Composite sourceContainerGroup = new Composite(parent,SWT.NONE);
113     GridLayout layout = new GridLayout();
114     layout.numColumns = 3;
115     sourceContainerGroup.setLayout(layout);
116     sourceContainerGroup.setLayoutData(
117         new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
118
119     new Label(sourceContainerGroup,SWT.NONE).setText(getSourceLabel());
120
121     // source name entry field
122
sourceNameField = new Combo(sourceContainerGroup,SWT.BORDER);
123     sourceNameField.addListener(SWT.Modify,this);
124     sourceNameField.addListener(SWT.Selection,this);
125     GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
126     data.widthHint = SIZING_TEXT_FIELD_WIDTH;
127     sourceNameField.setLayoutData(data);
128
129     // source browse button
130
sourceBrowseButton = new Button(sourceContainerGroup,SWT.PUSH);
131     sourceBrowseButton.setText(DataTransferMessages.getString("DataTransfer.browse")); //$NON-NLS-1$
132
sourceBrowseButton.addListener(SWT.Selection,this);
133     sourceBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
134
135     // source types group
136
Composite sourceTypesGroup = new Composite(parent,SWT.NONE);
137     layout = new GridLayout();
138     layout.numColumns = 3;
139     sourceTypesGroup.setLayout(layout);
140     sourceTypesGroup.setLayoutData(
141         new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
142
143     // all types radio
144
importAllResourcesRadio = new Button(sourceTypesGroup,SWT.RADIO);
145     importAllResourcesRadio.setText(DataTransferMessages.getString("DataTransfer.allTypes")); //$NON-NLS-1$
146
importAllResourcesRadio.addListener(SWT.Selection,this);
147     data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
148     data.horizontalSpan = 3;
149     importAllResourcesRadio.setLayoutData(data);
150
151     // import specific types radio
152
importTypedResourcesRadio = new Button(sourceTypesGroup,SWT.RADIO);
153     importTypedResourcesRadio.setText(DataTransferMessages.getString("FileImport.filesofType")); //$NON-NLS-1$
154
importTypedResourcesRadio.addListener(SWT.Selection,this);
155
156     // types combo
157
typesToImportField = new Combo(sourceTypesGroup, SWT.NONE);
158     data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
159     data.widthHint = SIZING_TEXT_FIELD_WIDTH;
160     typesToImportField.setLayoutData(data);
161     typesToImportField.addListener(SWT.Modify, this);
162
163     // types edit button
164
typesToImportEditButton = new Button(sourceTypesGroup, SWT.PUSH);
165     typesToImportEditButton.setText(DataTransferMessages.getString("FileImport.edit")); //$NON-NLS-1$
166
typesToImportEditButton.setLayoutData(new GridData(
167         GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_END));
168     typesToImportEditButton.addListener(SWT.Selection, this);
169
170     // details of files to import group
171
Composite fileDetailsGroup = new Composite(parent, SWT.NONE);
172     layout = new GridLayout();
173     layout.numColumns = 2;
174     fileDetailsGroup.setLayout(layout);
175     fileDetailsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
176
177     // details button
178
detailsButton = new Button(fileDetailsGroup,SWT.PUSH);
179     detailsButton.setText(DataTransferMessages.getString("DataTransfer.details")); //$NON-NLS-1$
180
detailsButton.addListener(SWT.Selection,this);
181
182     // details label
183
detailsDescriptionLabel = new Label(fileDetailsGroup,SWT.NONE);
184     data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
185     detailsDescriptionLabel.setLayoutData(data);
186
187     // initial setup
188
typesToImportField.setEnabled(false);
189     typesToImportEditButton.setEnabled(false);
190     importAllResourcesRadio.setSelection(true);
191     resetSelection();
192     sourceNameField.setFocus();
193 }
194 /**
195  * Display the appropriate string representing a selection of the
196  * passed size.
197  */

198 protected void displaySelectedCount(int selectedFileCount) {
199     if (selectedFileCount == 1)
200         detailsDescriptionLabel.setText(
201             DataTransferMessages.getString("DataTransfer.oneSelected")); //$NON-NLS-1$
202
else
203         detailsDescriptionLabel.setText(DataTransferMessages.format("FileImport.filesSelected",new Object JavaDoc[] {String.valueOf(selectedFileCount)})); //$NON-NLS-1$
204
}
205 /**
206  * Answer a boolean indicating whether the specified source currently exists
207  * and is valid
208  */

209 protected boolean ensureSourceIsValid() {
210     if (new File JavaDoc(getSourceDirectoryName()).isDirectory())
211         return true;
212
213     displayErrorDialog(DataTransferMessages.getString("FileImport.invalidSource")); //$NON-NLS-1$
214
sourceNameField.setFocus();
215     return false;
216 }
217 /**
218  * Execute the passed import operation. Answer a boolean indicating success.
219  */

220 protected boolean executeImportOperation(ImportOperation op) {
221     initializeOperation(op);
222      
223     try {
224         getContainer().run(true, true, op);
225     } catch (InterruptedException JavaDoc e) {
226         return false;
227     } catch (InvocationTargetException JavaDoc e) {
228         displayErrorDialog(e.getTargetException().getMessage());
229         return false;
230     }
231
232     IStatus status = op.getStatus();
233     if (!status.isOK()) {
234         ErrorDialog.openError(getContainer().getShell(),
235             DataTransferMessages.getString("FileImport.importProblems"), //$NON-NLS-1$
236
null, // no special message
237
status);
238         return false;
239     }
240
241     return true;
242 }
243 /**
244  * The Finish button was pressed. Try to do the required work now and answer
245  * a boolean indicating success. If false is returned then the wizard will
246  * not close.
247  */

248 public boolean finish() {
249     if (!ensureSourceIsValid())
250         return false;
251
252     if (selectedResources == null && importAllResourcesRadio.getSelection()) {
253         // about to invoke the operation so save our state
254
saveWidgetValues();
255
256         return importAllResources();
257     } else {
258         // ensure that files of appropriate extension will be marked as selected
259
if (selectedResources == null) {
260             if (getFileSystemTree() == null)
261                 return false;
262         }
263
264         // about to invoke the operation so save our state
265
saveWidgetValues();
266
267         if (selectedResources.size() > 0) {
268             List JavaDoc fileSystemObjects = new ArrayList(selectedResources.size());
269             Iterator resourcesEnum = selectedResources.iterator();
270             while (resourcesEnum.hasNext())
271                 fileSystemObjects.add(
272                     ((FileSystemElement)resourcesEnum.next()).getFileSystemObject());
273     
274             return importResources(fileSystemObjects);
275         }
276
277         MessageDialog.openInformation(
278             getContainer().getShell(),
279             DataTransferMessages.getString("DataTransfer.information"), //$NON-NLS-1$
280
DataTransferMessages.getString("FileImport.noneSelected")); //$NON-NLS-1$
281

282         return false;
283     }
284 }
285 /**
286  * Answer the root FileSystemElement that represents the contents of
287  * the currently-specified source. If this FileSystemElement is not
288  * currently defined then create and return it.
289  */

290 protected FileSystemElement getFileSystemTree() {
291     if (root != null)
292         return root;
293         
294     File JavaDoc sourceDirectory = getSourceDirectory();
295     if (sourceDirectory == null)
296         return null;
297
298     return selectFiles(sourceDirectory, FileSystemStructureProvider.INSTANCE);
299 }
300 /**
301  * Answer self's import source root element
302  */

303 protected FileSystemElement getRoot() {
304     return root;
305 }
306 /**
307  * Answer self's current collection of selected resources
308  */

309 protected List JavaDoc getSelectedResources() {
310     return selectedResources;
311 }
312 /**
313  * Returns a File object representing the currently-named source directory iff
314  * it exists as a valid directory, or <code>null</code> otherwise.
315  */

316 protected File JavaDoc getSourceDirectory() {
317     File JavaDoc sourceDirectory = new File JavaDoc(getSourceDirectoryName());
318     if (!sourceDirectory.exists() || !sourceDirectory.isDirectory()) {
319         displayErrorDialog(DataTransferMessages.getString("FileImport.invalidSource")); //$NON-NLS-1$
320
sourceNameField.setFocus();
321         return null;
322     }
323
324     return sourceDirectory;
325 }
326 /**
327  * Answer the directory name specified as being the import source.
328  * Note that if it ends with a separator then the separator is first
329  * removed so that java treats it as a proper directory
330  */

331 private String JavaDoc getSourceDirectoryName() {
332     IPath result = new Path(sourceNameField.getText().trim());
333
334     if (result.getDevice() != null && result.segmentCount() == 0) // something like "c:"
335
result = result.addTrailingSeparator();
336     else
337         result = result.removeTrailingSeparator();
338
339     return result.toOSString();
340 }
341 /**
342  * Answer the string to display as the label for the source specification field
343  */

344 protected String JavaDoc getSourceLabel() {
345     return DataTransferMessages.getString("FileImport.sourceTitle"); //$NON-NLS-1$
346
}
347 /**
348  * Returns a collection of the currently-specified resource types,
349  * or <code>null</code> to indicate that all types should be imported.
350  */

351 protected List JavaDoc getTypesToImport() {
352     if (importAllResourcesRadio.getSelection())
353         return null;
354                     
355     List JavaDoc result = new ArrayList();
356     StringTokenizer tokenizer = new StringTokenizer(typesToImportField.getText(),TYPE_DELIMITER);
357     
358     while (tokenizer.hasMoreTokens()) {
359         String JavaDoc currentExtension = tokenizer.nextToken().trim();
360         if (!currentExtension.equals(""))//$NON-NLS-1$
361
result.add(currentExtension);
362     }
363         
364     return result;
365 }
366 /**
367  * Returns an array of the currently-specified resource types,
368  * or <code>null</code> to indicate that all types should be imported.
369  */

370 protected String JavaDoc[] getTypesToImportArray() {
371     List JavaDoc typesToImport = getTypesToImport();
372     if (typesToImport == null)
373         return null;
374         
375     String JavaDoc result[] = new String JavaDoc[typesToImport.size()];
376     typesToImport.toArray(result);
377
378     return result;
379 }
380 /**
381  * Open a selection dialog and note the selections
382  */

383 protected void handleDetailsButtonPressed() {
384     FileSystemElement rootElement = getFileSystemTree();
385     
386     if (rootElement != null) {
387         List JavaDoc newSelections = queryResourcesToImport(rootElement);
388         
389         if (newSelections != null) {
390             selectedResources = newSelections;
391             displaySelectedCount(selectedResources.size());
392         }
393     }
394 }
395 /**
396  * Handle all events and enablements for widgets in this dialog
397  */

398 public void handleEvent(Event e) {
399     Widget source = e.widget;
400
401     if (source == sourceNameField)
402         resetSelection();
403     else if (source == sourceBrowseButton)
404         handleSourceBrowseButtonPressed();
405     else if (source == importAllResourcesRadio)
406         resetSelection();
407     else if (source == importTypedResourcesRadio) {
408         resetSelection();
409         typesToImportField.setFocus();
410     } else if (source == detailsButton)
411         handleDetailsButtonPressed();
412     else if (source == typesToImportField)
413         resetSelection();
414     else if (source == typesToImportEditButton)
415         handleTypesEditButtonPressed();
416
417     super.handleEvent(e);
418 }
419 /**
420  * Open an appropriate source browser so that the user can specify a source
421  * to import from
422  */

423 protected void handleSourceBrowseButtonPressed() {
424     DirectoryDialog dialog = new DirectoryDialog(sourceNameField.getShell(),SWT.SAVE);
425     dialog.setMessage(DataTransferMessages.getString("FileImport.selectSource")); //$NON-NLS-1$
426
dialog.setFilterPath(getSourceDirectoryName());
427     
428     String JavaDoc selectedDirectory = dialog.open();
429     if (selectedDirectory != null) {
430         if (!selectedDirectory.equals(getSourceDirectoryName())) {
431             resetSelection();
432             sourceNameField.setText(selectedDirectory);
433         }
434     }
435 }
436 /**
437  * Open a registered type selection dialog and note the selections
438  * in self's types-to-export field
439  */

440 protected void handleTypesEditButtonPressed() {
441     IFileEditorMapping editorMappings[] =
442         PlatformUI.getWorkbench().getEditorRegistry().getFileEditorMappings();
443
444     List JavaDoc selectedTypes = getTypesToImport();
445     List JavaDoc initialSelections = new ArrayList();
446     for (int i = 0; i < editorMappings.length; i++) {
447         IFileEditorMapping mapping = editorMappings[i];
448         if (selectedTypes.contains(mapping.getExtension()))
449             initialSelections.add(mapping);
450     }
451
452     ListSelectionDialog dialog =
453         new ListSelectionDialog(
454             getContainer().getShell(),
455             editorMappings,
456             FileEditorMappingContentProvider.INSTANCE,
457             FileEditorMappingLabelProvider.INSTANCE,
458             DataTransferMessages.getString("FileImport.selectTypes")); //$NON-NLS-1$
459

460     dialog.setInitialSelections(initialSelections.toArray());
461     dialog.setTitle(DataTransferMessages.getString("FileImport.typeSelectionTitle")); //$NON-NLS-1$
462
dialog.open();
463
464     Object JavaDoc[] newSelectedTypes = dialog.getResult();
465     if (newSelectedTypes != null) { // ie.- did not press Cancel
466
List JavaDoc result = new ArrayList(newSelectedTypes.length);
467         for (int i = 0; i < newSelectedTypes.length; i++)
468             result.add(((IFileEditorMapping)newSelectedTypes[i]).getExtension());
469         setTypesToImport(result);
470     }
471 }
472 /**
473  * Recursively import all resources starting at the user-specified source location.
474  * Answer a boolean indicating success.
475  */

476 protected boolean importAllResources() {
477     return executeImportOperation(
478         new ImportOperation(
479             getContainerFullPath(),
480             getSourceDirectory(),
481             FileSystemStructureProvider.INSTANCE,
482             this));
483 }
484 /**
485  * Import the resources with extensions as specified by the user
486  */

487 protected boolean importResources(List JavaDoc fileSystemObjects) {
488     return executeImportOperation(
489         new ImportOperation(
490             getContainerFullPath(),
491             getSourceDirectory(),
492             FileSystemStructureProvider.INSTANCE,
493             this,
494             fileSystemObjects));
495 }
496 /**
497  * Initializes the specified operation appropriately.
498  */

499 protected void initializeOperation(ImportOperation op) {
500     op.setCreateContainerStructure(createContainerStructureCheckbox.getSelection());
501     op.setOverwriteResources(overwriteExistingResourcesCheckbox.getSelection());
502 }
503 /**
504  * Opens a resource selection dialog with the passed root as input, and returns
505  * a collection with the resources that were subsequently specified for import
506  * by the user, or <code>null</code> if the dialog was canceled.
507  */

508 protected List JavaDoc queryResourcesToImport(FileSystemElement rootElement) {
509     FileSelectionDialog dialog = new FileSelectionDialog(getContainer().getShell(), rootElement, DataTransferMessages.getString("FileImport.selectResources")); //$NON-NLS-1$
510
dialog.setInitialSelections(selectedResources.toArray());
511     dialog.setExpandAllOnOpen(true);
512     dialog.open();
513     if (dialog.getResult() == null)
514         return null;
515     return Arrays.asList(dialog.getResult());
516
517 }
518 /**
519  * Reset the selected resources collection and update the ui appropriately
520  */

521 protected void resetSelection() {
522     detailsDescriptionLabel.setText(DataTransferMessages.getString("DataTransfer.allFiles")); //$NON-NLS-1$
523
selectedResources = null;
524     root = null;
525 }
526 /**
527  * Use the dialog store to restore widget values to the values that they held
528  * last time this wizard was used to completion
529  */

530 protected void restoreWidgetValues() {
531     IDialogSettings settings = getDialogSettings();
532     if(settings != null) {
533         String JavaDoc[] sourceNames = settings.getArray(STORE_SOURCE_NAMES_ID);
534         if (sourceNames == null)
535             return; // ie.- no values stored, so stop
536

537         // set all/specific types radios and related enablements
538
boolean importAll = settings.getBoolean(STORE_IMPORT_ALL_RESOURCES_ID);
539         importAllResourcesRadio.setSelection(importAll);
540         importTypedResourcesRadio.setSelection(!importAll);
541
542         // set filenames history
543
sourceNameField.setText(sourceNames[0]);
544         for (int i = 0; i < sourceNames.length; i++)
545             sourceNameField.add(sourceNames[i]);
546
547         // set selected types
548
String JavaDoc[] selectedTypes = settings.getArray(STORE_SELECTED_TYPES_ID);
549         if (selectedTypes.length > 0)
550             typesToImportField.setText(selectedTypes[0]);
551         for (int i = 0; i < selectedTypes.length; i++)
552             typesToImportField.add(selectedTypes[i]);
553             
554         // radio buttons and checkboxes
555
overwriteExistingResourcesCheckbox.setSelection(
556             settings.getBoolean(STORE_OVERWRITE_EXISTING_RESOURCES_ID));
557
558         createContainerStructureCheckbox.setSelection(
559             settings.getBoolean(STORE_CREATE_CONTAINER_STRUCTURE_ID));
560         
561     }
562 }
563 /**
564  * Since Finish was pressed, write widget values to the dialog store so that they
565  * will persist into the next invocation of this wizard page
566  */

567 protected void saveWidgetValues() {
568     IDialogSettings settings = getDialogSettings();
569     if(settings != null) {
570         // update source names history
571
String JavaDoc[] sourceNames = settings.getArray(STORE_SOURCE_NAMES_ID);
572         if (sourceNames == null)
573             sourceNames = new String JavaDoc[0];
574
575         sourceNames = addToHistory(sourceNames,getSourceDirectoryName());
576         settings.put(
577             STORE_SOURCE_NAMES_ID,
578             sourceNames);
579
580         // update specific types to import history
581
String JavaDoc[] selectedTypesNames = settings.getArray(STORE_SELECTED_TYPES_ID);
582         if (selectedTypesNames == null)
583             selectedTypesNames = new String JavaDoc[0];
584
585         if (importTypedResourcesRadio.getSelection())
586             selectedTypesNames = addToHistory(selectedTypesNames,typesToImportField.getText());
587             
588         settings.put(
589             STORE_SELECTED_TYPES_ID,
590             selectedTypesNames);
591
592         // radio buttons and checkboxes
593
settings.put(
594             STORE_IMPORT_ALL_RESOURCES_ID,
595             importAllResourcesRadio.getSelection());
596     
597         settings.put(
598             STORE_OVERWRITE_EXISTING_RESOURCES_ID,
599             overwriteExistingResourcesCheckbox.getSelection());
600
601         settings.put(
602             STORE_CREATE_CONTAINER_STRUCTURE_ID,
603             createContainerStructureCheckbox.getSelection());
604     
605     }
606 }
607 /**
608  * Invokes a file selection operation using the specified file system and
609  * structure provider. If the user specifies files to be imported then
610  * this selection is cached for later retrieval and is returned.
611  */

612 protected FileSystemElement selectFiles(Object JavaDoc rootFileSystemObject,IImportStructureProvider structureProvider) {
613     try {
614         SelectFilesOperation op =
615             new SelectFilesOperation(rootFileSystemObject,structureProvider);
616         op.setDesiredExtensions(getTypesToImportArray());
617         getContainer().run(true, true, op);
618         root = op.getResult();
619         setSelectedResources(new ArrayList());
620         addToSelectedResources(root);
621     } catch (InterruptedException JavaDoc e) {
622         return null;
623     } catch (InvocationTargetException JavaDoc e) {
624         displayErrorDialog(e.getTargetException().getMessage());
625         return null;
626     }
627
628     return root;
629 }
630 /**
631  * Respond to the user selecting/deselecting items in the
632  * extensions list
633  */

634 public void selectionChanged(SelectionChangedEvent event) {
635     if (importTypedResourcesRadio.getSelection())
636         resetSelection();
637 }
638 /**
639  * Set self's import source root element
640  */

641 protected void setRoot(FileSystemElement value) {
642     root = value;
643 }
644 /**
645  * Set self's current collection of selected resources
646  */

647 protected void setSelectedResources(List JavaDoc value) {
648     selectedResources = value;
649 }
650 /**
651  * Populate self's import types field based upon the passed types collection
652  */

653 protected void setTypesToImport(List JavaDoc types) {
654     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
655     for (int i = 0; i < types.size(); ++i) {
656         if (i != 0) {
657             result.append(TYPE_DELIMITER);
658             result.append(" ");//$NON-NLS-1$
659
}
660         result.append(types.get(i));
661     }
662     typesToImportField.setText(result.toString());
663 }
664 /**
665  * Set the enablements of self's widgets
666  */

667 protected void updateWidgetEnablements() {
668     typesToImportField.setEnabled(importTypedResourcesRadio.getSelection());
669     typesToImportEditButton.setEnabled(importTypedResourcesRadio.getSelection());
670 }
671 /**
672  * Answer a boolean indicating whether self's source specification
673  * widgets currently all contain valid values.
674  */

675 protected boolean validateSourceGroup() {
676     return !getSourceDirectoryName().equals("");//$NON-NLS-1$
677
}
678 }
679
Popular Tags