1 11 package org.eclipse.ui.internal.wizards.datatransfer; 12 13 import java.io.File ; 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.Hashtable ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.eclipse.core.resources.IContainer; 23 import org.eclipse.core.runtime.IPath; 24 import org.eclipse.core.runtime.IProgressMonitor; 25 import org.eclipse.core.runtime.IStatus; 26 import org.eclipse.core.runtime.Path; 27 import org.eclipse.jface.dialogs.ErrorDialog; 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.jface.dialogs.IDialogSettings; 30 import org.eclipse.jface.dialogs.MessageDialog; 31 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 32 import org.eclipse.jface.operation.IRunnableWithProgress; 33 import org.eclipse.jface.viewers.IStructuredSelection; 34 import org.eclipse.jface.viewers.ITreeContentProvider; 35 import org.eclipse.swt.SWT; 36 import org.eclipse.swt.custom.BusyIndicator; 37 import org.eclipse.swt.events.FocusEvent; 38 import org.eclipse.swt.events.FocusListener; 39 import org.eclipse.swt.events.KeyEvent; 40 import org.eclipse.swt.events.KeyListener; 41 import org.eclipse.swt.events.SelectionAdapter; 42 import org.eclipse.swt.events.SelectionEvent; 43 import org.eclipse.swt.events.SelectionListener; 44 import org.eclipse.swt.layout.GridData; 45 import org.eclipse.swt.layout.GridLayout; 46 import org.eclipse.swt.widgets.Button; 47 import org.eclipse.swt.widgets.Combo; 48 import org.eclipse.swt.widgets.Composite; 49 import org.eclipse.swt.widgets.DirectoryDialog; 50 import org.eclipse.swt.widgets.Event; 51 import org.eclipse.swt.widgets.Group; 52 import org.eclipse.swt.widgets.Label; 53 import org.eclipse.swt.widgets.Listener; 54 import org.eclipse.swt.widgets.Shell; 55 import org.eclipse.ui.IWorkbench; 56 import org.eclipse.ui.PlatformUI; 57 import org.eclipse.ui.dialogs.FileSystemElement; 58 import org.eclipse.ui.dialogs.WizardResourceImportPage; 59 import org.eclipse.ui.internal.ide.dialogs.IElementFilter; 60 import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog; 61 import org.eclipse.ui.model.WorkbenchContentProvider; 62 import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; 63 import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider; 64 import org.eclipse.ui.wizards.datatransfer.ImportOperation; 65 66 69 public class WizardFileSystemResourceImportPage1 extends WizardResourceImportPage 70 implements Listener { 71 protected Combo sourceNameField; 73 74 protected Button overwriteExistingResourcesCheckbox; 75 76 protected Button createContainerStructureButton; 77 78 protected Button createOnlySelectedButton; 79 80 protected Button sourceBrowseButton; 81 82 protected Button selectTypesButton; 83 84 protected Button selectAllButton; 85 86 protected Button deselectAllButton; 87 88 private boolean entryChanged = false; 90 91 private final static String STORE_SOURCE_NAMES_ID = "WizardFileSystemResourceImportPage1.STORE_SOURCE_NAMES_ID"; 94 private final static String STORE_OVERWRITE_EXISTING_RESOURCES_ID = "WizardFileSystemResourceImportPage1.STORE_OVERWRITE_EXISTING_RESOURCES_ID"; 96 private final static String STORE_CREATE_CONTAINER_STRUCTURE_ID = "WizardFileSystemResourceImportPage1.STORE_CREATE_CONTAINER_STRUCTURE_ID"; 98 private static final String SELECT_TYPES_TITLE = DataTransferMessages.DataTransfer_selectTypes; 99 100 private static final String SELECT_ALL_TITLE = DataTransferMessages.DataTransfer_selectAll; 101 102 private static final String DESELECT_ALL_TITLE = DataTransferMessages.DataTransfer_deselectAll; 103 104 private static final String SELECT_SOURCE_TITLE = DataTransferMessages.FileImport_selectSourceTitle; 105 106 private static final String SELECT_SOURCE_MESSAGE = DataTransferMessages.FileImport_selectSource; 107 108 protected static final String SOURCE_EMPTY_MESSAGE = DataTransferMessages.FileImport_sourceEmpty; 109 110 113 protected WizardFileSystemResourceImportPage1(String name, 114 IWorkbench aWorkbench, IStructuredSelection selection) { 115 super(name, selection); 116 } 117 118 124 public WizardFileSystemResourceImportPage1(IWorkbench aWorkbench, 125 IStructuredSelection selection) { 126 this("fileSystemImportPage1", aWorkbench, selection); setTitle(DataTransferMessages.DataTransfer_fileSystemTitle); 128 setDescription(DataTransferMessages.FileImport_importFileSystem); 129 } 130 131 152 protected Button createButton(Composite parent, int id, String label, 153 boolean defaultButton) { 154 ((GridLayout) parent.getLayout()).numColumns++; 156 157 Button button = new Button(parent, SWT.PUSH); 158 button.setFont(parent.getFont()); 159 160 GridData buttonData = new GridData(GridData.FILL_HORIZONTAL); 161 button.setLayoutData(buttonData); 162 163 button.setData(new Integer (id)); 164 button.setText(label); 165 166 if (defaultButton) { 167 Shell shell = parent.getShell(); 168 if (shell != null) { 169 shell.setDefaultButton(button); 170 } 171 button.setFocus(); 172 } 173 return button; 174 } 175 176 182 protected final void createButtonsGroup(Composite parent) { 183 Composite buttonComposite = new Composite(parent, SWT.NONE); 185 GridLayout layout = new GridLayout(); 186 layout.numColumns = 3; 187 layout.makeColumnsEqualWidth = true; 188 buttonComposite.setLayout(layout); 189 buttonComposite.setFont(parent.getFont()); 190 GridData buttonData = new GridData(GridData.VERTICAL_ALIGN_FILL 191 | GridData.HORIZONTAL_ALIGN_FILL); 192 buttonData.horizontalSpan = 2; 193 buttonComposite.setLayoutData(buttonData); 194 195 selectTypesButton = createButton(buttonComposite, 197 IDialogConstants.SELECT_TYPES_ID, SELECT_TYPES_TITLE, false); 198 199 SelectionListener listener = new SelectionAdapter() { 200 public void widgetSelected(SelectionEvent e) { 201 handleTypesEditButtonPressed(); 202 } 203 }; 204 selectTypesButton.addSelectionListener(listener); 205 setButtonLayoutData(selectTypesButton); 206 207 selectAllButton = createButton(buttonComposite, 208 IDialogConstants.SELECT_ALL_ID, SELECT_ALL_TITLE, false); 209 210 listener = new SelectionAdapter() { 211 public void widgetSelected(SelectionEvent e) { 212 setAllSelections(true); 213 updateWidgetEnablements(); 214 } 215 }; 216 selectAllButton.addSelectionListener(listener); 217 setButtonLayoutData(selectAllButton); 218 219 deselectAllButton = createButton(buttonComposite, 220 IDialogConstants.DESELECT_ALL_ID, DESELECT_ALL_TITLE, false); 221 222 listener = new SelectionAdapter() { 223 public void widgetSelected(SelectionEvent e) { 224 setAllSelections(false); 225 updateWidgetEnablements(); 226 } 227 }; 228 deselectAllButton.addSelectionListener(listener); 229 setButtonLayoutData(deselectAllButton); 230 231 } 232 233 236 public void createControl(Composite parent) { 237 super.createControl(parent); 238 validateSourceGroup(); 239 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), 240 IDataTransferHelpContextIds.FILE_SYSTEM_IMPORT_WIZARD_PAGE); 241 } 242 243 246 protected void createOptionsGroupButtons(Group optionsGroup) { 247 248 overwriteExistingResourcesCheckbox = new Button(optionsGroup, SWT.CHECK); 250 overwriteExistingResourcesCheckbox.setFont(optionsGroup.getFont()); 251 overwriteExistingResourcesCheckbox.setText(DataTransferMessages.FileImport_overwriteExisting); 252 253 createContainerStructureButton = new Button(optionsGroup, SWT.RADIO); 255 createContainerStructureButton.setFont(optionsGroup.getFont()); 256 createContainerStructureButton.setText(DataTransferMessages.FileImport_createComplete); 257 createContainerStructureButton.setSelection(false); 258 259 createOnlySelectedButton = new Button(optionsGroup, SWT.RADIO); 261 createOnlySelectedButton.setFont(optionsGroup.getFont()); 262 createOnlySelectedButton.setText(DataTransferMessages.FileImport_createSelectedFolders); 263 createOnlySelectedButton.setSelection(true); 264 265 } 266 267 270 protected void createRootDirectoryGroup(Composite parent) { 271 Composite sourceContainerGroup = new Composite(parent, SWT.NONE); 272 GridLayout layout = new GridLayout(); 273 layout.numColumns = 3; 274 sourceContainerGroup.setLayout(layout); 275 sourceContainerGroup.setFont(parent.getFont()); 276 sourceContainerGroup.setLayoutData(new GridData( 277 GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); 278 279 Label groupLabel = new Label(sourceContainerGroup, SWT.NONE); 280 groupLabel.setText(getSourceLabel()); 281 groupLabel.setFont(parent.getFont()); 282 283 sourceNameField = new Combo(sourceContainerGroup, SWT.BORDER); 285 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL 286 | GridData.GRAB_HORIZONTAL); 287 data.widthHint = SIZING_TEXT_FIELD_WIDTH; 288 sourceNameField.setLayoutData(data); 289 sourceNameField.setFont(parent.getFont()); 290 291 sourceNameField.addSelectionListener(new SelectionAdapter() { 292 public void widgetSelected(SelectionEvent e) { 293 updateFromSourceField(); 294 } 295 }); 296 297 sourceNameField.addKeyListener(new KeyListener() { 298 301 public void keyPressed(KeyEvent e) { 302 entryChanged = true; 304 } 305 306 309 public void keyReleased(KeyEvent e) { 310 } 311 }); 312 313 sourceNameField.addFocusListener(new FocusListener() { 314 317 public void focusGained(FocusEvent e) { 318 } 320 321 324 public void focusLost(FocusEvent e) { 325 if (entryChanged) { 327 entryChanged = false; 328 updateFromSourceField(); 329 } 330 331 } 332 }); 333 334 sourceBrowseButton = new Button(sourceContainerGroup, SWT.PUSH); 336 sourceBrowseButton.setText(DataTransferMessages.DataTransfer_browse); 337 sourceBrowseButton.addListener(SWT.Selection, this); 338 sourceBrowseButton.setLayoutData(new GridData( 339 GridData.HORIZONTAL_ALIGN_FILL)); 340 sourceBrowseButton.setFont(parent.getFont()); 341 setButtonLayoutData(sourceBrowseButton); 342 } 343 344 347 348 private void updateFromSourceField() { 349 350 setSourceName(sourceNameField.getText()); 351 updateWidgetEnablements(); 353 } 354 355 360 protected MinimizedFileSystemElement createRootElement( 361 Object fileSystemObject, IImportStructureProvider provider) { 362 boolean isContainer = provider.isFolder(fileSystemObject); 363 String elementLabel = provider.getLabel(fileSystemObject); 364 365 MinimizedFileSystemElement dummyParent = new MinimizedFileSystemElement( 368 "", null, true); dummyParent.setPopulated(); 370 MinimizedFileSystemElement result = new MinimizedFileSystemElement( 371 elementLabel, dummyParent, isContainer); 372 result.setFileSystemObject(fileSystemObject); 373 374 result.getFiles(provider); 376 377 return dummyParent; 378 } 379 380 383 protected void createSourceGroup(Composite parent) { 384 385 createRootDirectoryGroup(parent); 386 createFileSelectionGroup(parent); 387 createButtonsGroup(parent); 388 } 389 390 393 protected void enableButtonGroup(boolean enable) { 394 selectTypesButton.setEnabled(enable); 395 selectAllButton.setEnabled(enable); 396 deselectAllButton.setEnabled(enable); 397 } 398 399 403 protected boolean ensureSourceIsValid() { 404 if (new File (getSourceDirectoryName()).isDirectory()) { 405 return true; 406 } 407 408 setErrorMessage(DataTransferMessages.FileImport_invalidSource); 409 sourceNameField.setFocus(); 410 return false; 411 } 412 413 416 protected boolean executeImportOperation(ImportOperation op) { 417 initializeOperation(op); 418 419 try { 420 getContainer().run(true, true, op); 421 } catch (InterruptedException e) { 422 return false; 423 } catch (InvocationTargetException e) { 424 displayErrorDialog(e.getTargetException()); 425 return false; 426 } 427 428 IStatus status = op.getStatus(); 429 if (!status.isOK()) { 430 ErrorDialog 431 .openError(getContainer().getShell(), DataTransferMessages.FileImport_importProblems, 432 null, status); 434 return false; 435 } 436 437 return true; 438 } 439 440 447 public boolean finish() { 448 if (!ensureSourceIsValid()) { 449 return false; 450 } 451 452 saveWidgetValues(); 453 454 Iterator resourcesEnum = getSelectedResources().iterator(); 455 List fileSystemObjects = new ArrayList (); 456 while (resourcesEnum.hasNext()) { 457 fileSystemObjects.add(((FileSystemElement) resourcesEnum.next()) 458 .getFileSystemObject()); 459 } 460 461 if (fileSystemObjects.size() > 0) { 462 return importResources(fileSystemObjects); 463 } 464 465 MessageDialog.openInformation(getContainer().getShell(), 466 DataTransferMessages.DataTransfer_information, 467 DataTransferMessages.FileImport_noneSelected); 468 469 return false; 470 } 471 472 476 protected ITreeContentProvider getFileProvider() { 477 return new WorkbenchContentProvider() { 478 public Object [] getChildren(Object o) { 479 if (o instanceof MinimizedFileSystemElement) { 480 MinimizedFileSystemElement element = (MinimizedFileSystemElement) o; 481 return element.getFiles( 482 FileSystemStructureProvider.INSTANCE).getChildren( 483 element); 484 } 485 return new Object [0]; 486 } 487 }; 488 } 489 490 495 protected MinimizedFileSystemElement getFileSystemTree() { 496 497 File sourceDirectory = getSourceDirectory(); 498 if (sourceDirectory == null) { 499 return null; 500 } 501 502 return selectFiles(sourceDirectory, 503 FileSystemStructureProvider.INSTANCE); 504 } 505 506 510 protected ITreeContentProvider getFolderProvider() { 511 return new WorkbenchContentProvider() { 512 public Object [] getChildren(Object o) { 513 if (o instanceof MinimizedFileSystemElement) { 514 MinimizedFileSystemElement element = (MinimizedFileSystemElement) o; 515 return element.getFolders( 516 FileSystemStructureProvider.INSTANCE).getChildren( 517 element); 518 } 519 return new Object [0]; 520 } 521 522 public boolean hasChildren(Object o) { 523 if (o instanceof MinimizedFileSystemElement) { 524 MinimizedFileSystemElement element = (MinimizedFileSystemElement) o; 525 if (element.isPopulated()) { 526 return getChildren(element).length > 0; 527 } 528 529 return true; 531 } 532 return false; 533 } 534 }; 535 } 536 537 541 protected File getSourceDirectory() { 542 return getSourceDirectory(this.sourceNameField.getText()); 543 } 544 545 551 private File getSourceDirectory(String path) { 552 File sourceDirectory = new File (getSourceDirectoryName(path)); 553 if (!sourceDirectory.exists() || !sourceDirectory.isDirectory()) { 554 return null; 555 } 556 557 return sourceDirectory; 558 } 559 560 565 private String getSourceDirectoryName() { 566 return getSourceDirectoryName(this.sourceNameField.getText()); 567 } 568 569 574 private String getSourceDirectoryName(String sourceName) { 575 IPath result = new Path(sourceName.trim()); 576 577 if (result.getDevice() != null && result.segmentCount() == 0) { 578 result = result.addTrailingSeparator(); 579 } else { 580 result = result.removeTrailingSeparator(); 581 } 582 583 return result.toOSString(); 584 } 585 586 589 protected String getSourceLabel() { 590 return DataTransferMessages.FileImport_fromDirectory; 591 } 592 593 598 public void handleEvent(Event event) { 599 if (event.widget == sourceBrowseButton) { 600 handleSourceBrowseButtonPressed(); 601 } 602 603 super.handleEvent(event); 604 } 605 606 610 protected void handleSourceBrowseButtonPressed() { 611 612 String currentSource = this.sourceNameField.getText(); 613 DirectoryDialog dialog = new DirectoryDialog( 614 sourceNameField.getShell(), SWT.SAVE); 615 dialog.setText(SELECT_SOURCE_TITLE); 616 dialog.setMessage(SELECT_SOURCE_MESSAGE); 617 dialog.setFilterPath(getSourceDirectoryName(currentSource)); 618 619 String selectedDirectory = dialog.open(); 620 if (selectedDirectory != null) { 621 if ((getSourceDirectory(selectedDirectory) == null) 623 || selectedDirectory.equals(currentSource)) { 624 return; 625 } 626 setErrorMessage(null); 628 setSourceName(selectedDirectory); 629 selectionGroup.setFocus(); 630 } 631 } 632 633 638 protected void handleTypesEditButtonPressed() { 639 640 super.handleTypesEditButtonPressed(); 641 } 642 643 646 protected boolean importResources(List fileSystemObjects) { 647 ImportOperation operation = new ImportOperation(getContainerFullPath(), 648 getSourceDirectory(), FileSystemStructureProvider.INSTANCE, 649 this, fileSystemObjects); 650 651 operation.setContext(getShell()); 652 return executeImportOperation(operation); 653 } 654 655 658 protected void initializeOperation(ImportOperation op) { 659 op.setCreateContainerStructure(createContainerStructureButton 660 .getSelection()); 661 op.setOverwriteResources(overwriteExistingResourcesCheckbox 662 .getSelection()); 663 } 664 665 673 protected boolean isExportableExtension(String extension) { 674 if (selectedTypes == null) { 675 return true; 676 } 677 678 Iterator itr = selectedTypes.iterator(); 679 while (itr.hasNext()) { 680 if (extension.equalsIgnoreCase((String ) itr.next())) { 681 return true; 682 } 683 } 684 685 return false; 686 } 687 688 691 protected void resetSelection() { 692 693 MinimizedFileSystemElement currentRoot = getFileSystemTree(); 694 this.selectionGroup.setRoot(currentRoot); 695 696 } 697 698 702 protected void restoreWidgetValues() { 703 IDialogSettings settings = getDialogSettings(); 704 if (settings != null) { 705 String [] sourceNames = settings.getArray(STORE_SOURCE_NAMES_ID); 706 if (sourceNames == null) { 707 return; } 709 710 for (int i = 0; i < sourceNames.length; i++) { 712 sourceNameField.add(sourceNames[i]); 713 } 714 715 overwriteExistingResourcesCheckbox.setSelection(settings 717 .getBoolean(STORE_OVERWRITE_EXISTING_RESOURCES_ID)); 718 719 boolean createStructure = settings 720 .getBoolean(STORE_CREATE_CONTAINER_STRUCTURE_ID); 721 createContainerStructureButton.setSelection(createStructure); 722 createOnlySelectedButton.setSelection(!createStructure); 723 724 } 725 } 726 727 731 protected void saveWidgetValues() { 732 IDialogSettings settings = getDialogSettings(); 733 if (settings != null) { 734 String [] sourceNames = settings.getArray(STORE_SOURCE_NAMES_ID); 736 if (sourceNames == null) { 737 sourceNames = new String [0]; 738 } 739 740 sourceNames = addToHistory(sourceNames, getSourceDirectoryName()); 741 settings.put(STORE_SOURCE_NAMES_ID, sourceNames); 742 743 settings.put(STORE_OVERWRITE_EXISTING_RESOURCES_ID, 745 overwriteExistingResourcesCheckbox.getSelection()); 746 747 settings.put(STORE_CREATE_CONTAINER_STRUCTURE_ID, 748 createContainerStructureButton.getSelection()); 749 750 } 751 } 752 753 758 protected MinimizedFileSystemElement selectFiles( 759 final Object rootFileSystemObject, 760 final IImportStructureProvider structureProvider) { 761 762 final MinimizedFileSystemElement[] results = new MinimizedFileSystemElement[1]; 763 764 BusyIndicator.showWhile(getShell().getDisplay(), new Runnable () { 765 public void run() { 766 results[0] = createRootElement(rootFileSystemObject, 768 structureProvider); 769 } 770 }); 771 772 return results[0]; 773 } 774 775 780 protected void setAllSelections(boolean value) { 781 super.setAllSelections(value); 782 } 783 784 791 protected void setSourceName(String path) { 792 793 if (path.length() > 0) { 794 795 String [] currentItems = this.sourceNameField.getItems(); 796 int selectionIndex = -1; 797 for (int i = 0; i < currentItems.length; i++) { 798 if (currentItems[i].equals(path)) { 799 selectionIndex = i; 800 } 801 } 802 if (selectionIndex < 0) { 803 int oldLength = currentItems.length; 804 String [] newItems = new String [oldLength + 1]; 805 System.arraycopy(currentItems, 0, newItems, 0, oldLength); 806 newItems[oldLength] = path; 807 this.sourceNameField.setItems(newItems); 808 selectionIndex = oldLength; 809 } 810 this.sourceNameField.select(selectionIndex); 811 812 resetSelection(); 813 } 814 } 815 816 819 protected void setupSelectionsBasedOnSelectedTypes() { 820 ProgressMonitorDialog dialog = new ProgressMonitorJobsDialog( 821 getContainer().getShell()); 822 final Map selectionMap = new Hashtable (); 823 824 final IElementFilter filter = new IElementFilter() { 825 826 public void filterElements(Collection files, 827 IProgressMonitor monitor) throws InterruptedException { 828 if (files == null) { 829 throw new InterruptedException (); 830 } 831 Iterator filesList = files.iterator(); 832 while (filesList.hasNext()) { 833 if (monitor.isCanceled()) { 834 throw new InterruptedException (); 835 } 836 checkFile(filesList.next()); 837 } 838 } 839 840 public void filterElements(Object [] files, IProgressMonitor monitor) 841 throws InterruptedException { 842 if (files == null) { 843 throw new InterruptedException (); 844 } 845 for (int i = 0; i < files.length; i++) { 846 if (monitor.isCanceled()) { 847 throw new InterruptedException (); 848 } 849 checkFile(files[i]); 850 } 851 } 852 853 private void checkFile(Object fileElement) { 854 MinimizedFileSystemElement file = (MinimizedFileSystemElement) fileElement; 855 if (isExportableExtension(file.getFileNameExtension())) { 856 List elements = new ArrayList (); 857 FileSystemElement parent = file.getParent(); 858 if (selectionMap.containsKey(parent)) { 859 elements = (List ) selectionMap.get(parent); 860 } 861 elements.add(file); 862 selectionMap.put(parent, elements); 863 } 864 } 865 866 }; 867 868 IRunnableWithProgress runnable = new IRunnableWithProgress() { 869 public void run(final IProgressMonitor monitor) 870 throws InterruptedException { 871 monitor 872 .beginTask( 873 DataTransferMessages.ImportPage_filterSelections, IProgressMonitor.UNKNOWN); 874 getSelectedResources(filter, monitor); 875 } 876 }; 877 878 try { 879 dialog.run(true, true, runnable); 880 } catch (InvocationTargetException exception) { 881 return; 883 } catch (InterruptedException exception) { 884 return; 886 } 887 getShell().update(); 891 if (selectionMap != null) { 895 updateSelections(selectionMap); 896 } 897 } 898 899 902 public void setVisible(boolean visible) { 903 super.setVisible(visible); 904 resetSelection(); 905 if (visible) { 906 this.sourceNameField.setFocus(); 907 } 908 } 909 910 915 protected void updateSelections(Map map) { 916 super.updateSelections(map); 917 } 918 919 923 protected void updateWidgetEnablements() { 924 super.updateWidgetEnablements(); 925 enableButtonGroup(ensureSourceIsValid()); 926 } 927 928 932 protected boolean validateSourceGroup() { 933 File sourceDirectory = getSourceDirectory(); 934 if (sourceDirectory == null) { 935 setMessage(SOURCE_EMPTY_MESSAGE); 936 enableButtonGroup(false); 937 return false; 938 } 939 940 if (sourceConflictsWithDestination(new Path(sourceDirectory.getPath()))) { 941 setMessage(null); 942 setErrorMessage(getSourceConflictMessage()); 943 enableButtonGroup(false); 944 return false; 945 } 946 947 List resourcesToExport = selectionGroup.getAllWhiteCheckedItems(); 948 if (resourcesToExport.size() == 0){ 949 setMessage(null); 950 setErrorMessage(DataTransferMessages.FileImport_noneSelected); 951 return false; 952 } 953 954 enableButtonGroup(true); 955 setErrorMessage(null); 956 return true; 957 } 958 959 967 protected boolean sourceConflictsWithDestination(IPath sourcePath) { 968 969 IContainer container = getSpecifiedContainer(); 970 if (container == null) { 971 return false; 972 } 973 974 IPath destinationLocation = getSpecifiedContainer().getLocation(); 975 if (destinationLocation != null) { 976 return destinationLocation.isPrefixOf(sourcePath); 977 } 978 return false; 981 } 982 983 } 984 | Popular Tags |