diff options
author | Marc-Andre Laperle | 2014-08-29 17:59:25 +0000 |
---|---|---|
committer | Marc-Andre Laperle | 2014-09-15 19:58:12 +0000 |
commit | 25a1589d03a9ae04419d7a9b3622d35ffb628332 (patch) | |
tree | 98955339501dc945dff79550591caaed996736f1 | |
parent | 4a1be43acb9ed32e97b5998409911fec298bb8c5 (diff) | |
download | org.eclipse.linuxtools-25a1589d03a9ae04419d7a9b3622d35ffb628332.tar.gz org.eclipse.linuxtools-25a1589d03a9ae04419d7a9b3622d35ffb628332.tar.xz org.eclipse.linuxtools-25a1589d03a9ae04419d7a9b3622d35ffb628332.zip |
tmf: Provide (internal) API to customize Import Trace Wizard Page
Change-Id: I0471a64f000c06fcbe274aaa765154c1cec76503
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/32560
Tested-by: Hudson CI
2 files changed, 315 insertions, 152 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizard.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizard.java index de26c9c5cc..9a386f7ea6 100644 --- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizard.java +++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizard.java @@ -41,7 +41,6 @@ public class ImportTraceWizard extends Wizard implements IImportWizard { // Attributes // ------------------------------------------------------------------------ - private IWorkbench fWorkbench; private IStructuredSelection fSelection; private ImportTraceWizardPage fTraceImportWizardPage; @@ -66,7 +65,6 @@ public class ImportTraceWizard extends Wizard implements IImportWizard { @Override public void init(IWorkbench workbench, IStructuredSelection selection) { - fWorkbench = workbench; fSelection = selection; setWindowTitle(Messages.ImportTraceWizard_DialogTitle); @@ -77,7 +75,7 @@ public class ImportTraceWizard extends Wizard implements IImportWizard { @Override public void addPages() { super.addPages(); - fTraceImportWizardPage = new ImportTraceWizardPage(fWorkbench, fSelection); + fTraceImportWizardPage = new ImportTraceWizardPage(fSelection); addPage(fTraceImportWizardPage); } diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java index 84d97660c6..d1d9edb250 100644 --- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java +++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java @@ -92,14 +92,12 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.IWorkbench; import org.eclipse.ui.dialogs.FileSystemElement; import org.eclipse.ui.dialogs.IOverwriteQuery; import org.eclipse.ui.dialogs.WizardResourceImportPage; import org.eclipse.ui.internal.ide.DialogUtil; import org.eclipse.ui.internal.ide.dialogs.IElementFilter; import org.eclipse.ui.internal.wizards.datatransfer.ArchiveFileManipulations; -import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages; import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider; import org.eclipse.ui.internal.wizards.datatransfer.TarEntry; import org.eclipse.ui.internal.wizards.datatransfer.TarException; @@ -137,19 +135,42 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { // ------------------------------------------------------------------------ // Constants // ------------------------------------------------------------------------ - private static final String IMPORT_WIZARD_PAGE = "ImportTraceWizardPage"; //$NON-NLS-1$ - private static final String IMPORT_WIZARD_ROOT_DIRECTORY_ID = IMPORT_WIZARD_PAGE + ".import_root_directory_id"; //$NON-NLS-1$ - private static final String IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID = IMPORT_WIZARD_PAGE + ".import_archive_file_name_id"; //$NON-NLS-1$ - private static final String IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID = IMPORT_WIZARD_PAGE + ".import_unrecognized_traces_id"; //$NON-NLS-1$ - private static final String IMPORT_WIZARD_PRESERVE_FOLDERS_ID = IMPORT_WIZARD_PAGE + ".import_preserve_folders_id"; //$NON-NLS-1$ - private static final String IMPORT_WIZARD_IMPORT_FROM_DIRECTORY = IMPORT_WIZARD_PAGE + ".import_from_directory"; //$NON-NLS-1$ + private static final String IMPORT_WIZARD_PAGE_NAME = "ImportTraceWizardPage"; //$NON-NLS-1$ + private static final String IMPORT_WIZARD_ROOT_DIRECTORY_ID = ".import_root_directory_id"; //$NON-NLS-1$; + private static final String IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID = ".import_archive_file_name_id"; //$NON-NLS-1$ + private static final String IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID = ".import_unrecognized_traces_id"; //$NON-NLS-1$ + private static final String IMPORT_WIZARD_PRESERVE_FOLDERS_ID = ".import_preserve_folders_id"; //$NON-NLS-1$ + private static final String IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID = ".import_from_directory"; //$NON-NLS-1$ private static final String SEPARATOR = ":"; //$NON-NLS-1$ - private static final String AUTO_DETECT = Messages.ImportTraceWizard_AutoDetection; // constant from WizardArchiveFileResourceImportPage1 private static final String[] FILE_IMPORT_MASK = { "*.jar;*.zip;*.tar;*.tar.gz;*.tgz", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$ private static final String TRACE_IMPORT_TEMP_FOLDER = ".traceImport"; //$NON-NLS-1$ + /** + * A special trace type value to communicate that automatic trace type + * detection will occur instead of setting a specific trace type when + * importing the traces. + */ + protected static final String TRACE_TYPE_AUTO_DETECT = Messages.ImportTraceWizard_AutoDetection; + + /** + * Preserve the folder structure of the import traces. + */ + protected static final int OPTION_PRESERVE_FOLDER_STRUCTURE = 1 << 1; + /** + * Create links to the trace files instead of copies. + */ + protected static final int OPTION_CREATE_LINKS_IN_WORKSPACE = 1 << 2; + /** + * Import files that were not recognized as the selected trace type. + */ + protected static final int OPTION_IMPORT_UNRECOGNIZED_TRACES = 1 << 3; + /** + * Overwrite existing resources without prompting. + */ + protected static final int OPTION_OVERWRITE_EXISTING_RESOURCES = 1 << 4; + // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ @@ -178,11 +199,11 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { // Flag to remember the "create links" checkbox when it gets disabled by // the import from archive radio button private Boolean fPreviousCreateLinksValue = true; + /** The archive name field */ - private Combo fArchiveNameField; + protected Combo fArchiveNameField; /** The archive browse button. */ protected Button fArchiveBrowseButton; - /** The directory name field */ protected Combo directoryNameField; /** The directory browse button. */ @@ -215,47 +236,6 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { */ protected ImportTraceWizardPage(String name, IStructuredSelection selection) { super(name, selection); - } - - /** - * Create the import source selection widget. (Copied from WizardResourceImportPage - * but instead always uses the internal ResourceTreeAndListGroup to keep compatibility - * with Kepler) - */ - @Override - protected void createFileSelectionGroup(Composite parent) { - - //Just create with a dummy root. - fSelectionGroup = new ResourceTreeAndListGroup(parent, - new FileSystemElement("Dummy", null, true),//$NON-NLS-1$ - getFolderProvider(), new WorkbenchLabelProvider(), - getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, - DialogUtil.inRegularFontMode(parent)); - - ICheckStateListener listener = new ICheckStateListener() { - @Override - public void checkStateChanged(CheckStateChangedEvent event) { - updateWidgetEnablements(); - } - }; - - WorkbenchViewerComparator comparator = new WorkbenchViewerComparator(); - fSelectionGroup.setTreeComparator(comparator); - fSelectionGroup.setListComparator(comparator); - fSelectionGroup.addCheckStateListener(listener); - - } - - /** - * Constructor - * - * @param workbench - * The workbench reference. - * @param selection - * The current selection - */ - public ImportTraceWizardPage(IWorkbench workbench, IStructuredSelection selection) { - this(IMPORT_WIZARD_PAGE, selection); setTitle(Messages.ImportTraceWizard_FileSystemTitle); setDescription(Messages.ImportTraceWizard_ImportTrace); @@ -296,6 +276,45 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { } } + /** + * Constructor + * + * @param selection + * The current selection + */ + public ImportTraceWizardPage(IStructuredSelection selection) { + this(IMPORT_WIZARD_PAGE_NAME, selection); + } + + /** + * Create the import source selection widget. (Copied from + * WizardResourceImportPage but instead always uses the internal + * ResourceTreeAndListGroup to keep compatibility with Kepler) + */ + @Override + protected void createFileSelectionGroup(Composite parent) { + + // Just create with a dummy root. + fSelectionGroup = new ResourceTreeAndListGroup(parent, + new FileSystemElement("Dummy", null, true),//$NON-NLS-1$ + getFolderProvider(), new WorkbenchLabelProvider(), + getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, + DialogUtil.inRegularFontMode(parent)); + + ICheckStateListener listener = new ICheckStateListener() { + @Override + public void checkStateChanged(CheckStateChangedEvent event) { + updateWidgetEnablements(); + } + }; + + WorkbenchViewerComparator comparator = new WorkbenchViewerComparator(); + fSelectionGroup.setTreeComparator(comparator); + fSelectionGroup.setListComparator(comparator); + fSelectionGroup.addCheckStateListener(listener); + + } + // ------------------------------------------------------------------------ // WizardResourceImportPage // ------------------------------------------------------------------------ @@ -359,9 +378,9 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { * @param parent * the parent composite */ - private void createSourceSelectionGroup(Composite workArea) { + protected void createSourceSelectionGroup(Composite parent) { - Composite sourceGroup = new Composite(workArea, SWT.NONE); + Composite sourceGroup = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 3; layout.makeColumnsEqualWidth = false; @@ -375,17 +394,8 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { .setText(Messages.ImportTraceWizard_DirectoryLocation); // import location entry combo - directoryNameField = new Combo(sourceGroup, SWT.BORDER); - - GridData directoryPathData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); - directoryPathData.widthHint = new PixelConverter(directoryNameField).convertWidthInCharsToPixels(25); - directoryNameField.setLayoutData(directoryPathData); - - // browse button - directoryBrowseButton = new Button(sourceGroup, SWT.PUSH); - directoryBrowseButton - .setText(Messages.ImportTraceWizard_BrowseButton); - setButtonLayoutData(directoryBrowseButton); + directoryNameField = createPathSelectionCombo(sourceGroup); + createDirectoryBrowseButton(sourceGroup); // import from archive radio button fImportFromArchiveRadio = new Button(sourceGroup, SWT.RADIO); @@ -393,33 +403,54 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { .setText(Messages.ImportTraceWizard_ArchiveLocation); // import location entry combo - fArchiveNameField = new Combo(sourceGroup, SWT.BORDER); - - GridData archivePathData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); - archivePathData.widthHint = new PixelConverter(fArchiveNameField).convertWidthInCharsToPixels(25); - fArchiveNameField.setLayoutData(archivePathData); // browse button - fArchiveBrowseButton = new Button(sourceGroup, SWT.PUSH); - fArchiveBrowseButton.setText(DataTransferMessages.DataTransfer_browse); - setButtonLayoutData(fArchiveBrowseButton); + fArchiveNameField = createPathSelectionCombo(sourceGroup); + createArchiveBrowseButton(sourceGroup); fImportFromDirectoryRadio.setSelection(true); fArchiveNameField.setEnabled(false); fArchiveBrowseButton.setEnabled(false); - directoryBrowseButton.addSelectionListener(new SelectionAdapter() { + fImportFromDirectoryRadio.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - handleSourceDirectoryBrowseButtonPressed(); + directoryRadioSelected(); } - }); - fArchiveBrowseButton.addSelectionListener(new SelectionAdapter() { + fImportFromArchiveRadio.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - handleArchiveBrowseButtonPressed(); + archiveRadioSelected(); } }); + } + + /** + * Select or deselect all files in the file selection group + * + * @param checked + * whether or not the files should be checked + */ + protected void setFileSelectionGroupChecked(boolean checked) { + if (fSelectionGroup != null) { + fSelectionGroup.setAllSelections(checked); + } + } + + /** + * Create a combo that will be used to select a path to specify the source + * of the import. The parent is assumed to have a GridLayout. + * + * @param parent + * the parent composite + * @return the created path selection combo + */ + protected Combo createPathSelectionCombo(Composite parent) { + Combo pathSelectionCombo = new Combo(parent, SWT.BORDER); + + GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); + layoutData.widthHint = new PixelConverter(pathSelectionCombo).convertWidthInCharsToPixels(25); + pathSelectionCombo.setLayoutData(layoutData); TraverseListener traverseListener = new TraverseListener() { @Override @@ -458,54 +489,90 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { } }; - directoryNameField.addModifyListener(modifyListner); - directoryNameField.addTraverseListener(traverseListener); - directoryNameField.addFocusListener(focusAdapter); - directoryNameField.addSelectionListener(selectionAdapter); - fArchiveNameField.addModifyListener(modifyListner); - fArchiveNameField.addTraverseListener(traverseListener); - fArchiveNameField.addFocusListener(focusAdapter); - fArchiveNameField.addSelectionListener(selectionAdapter); + pathSelectionCombo.addModifyListener(modifyListner); + pathSelectionCombo.addTraverseListener(traverseListener); + pathSelectionCombo.addFocusListener(focusAdapter); + pathSelectionCombo.addSelectionListener(selectionAdapter); - fImportFromDirectoryRadio.addSelectionListener(new SelectionAdapter() { + return pathSelectionCombo; + } + + /** + * Create the directory browse button. + * + * @param parent + * the parent composite + */ + protected void createDirectoryBrowseButton(Composite parent) { + directoryBrowseButton = createPathSelectionBrowseButton(parent); + directoryBrowseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - directoryRadioSelected(); + handleSourceDirectoryBrowseButtonPressed(); } }); + } - fImportFromArchiveRadio.addSelectionListener(new SelectionAdapter() { + /** + * Create the archive browse button. + * + * @param parent + * the parent composite + */ + protected void createArchiveBrowseButton(Composite parent) { + fArchiveBrowseButton = createPathSelectionBrowseButton(parent); + fArchiveBrowseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - archiveRadioSelected(); + handleArchiveBrowseButtonPressed(FILE_IMPORT_MASK); } }); } + /** + * Create a browse button that will be used to browse for a path to specify + * the source of the import. The parent is assumed to have a GridLayout. + * + * @param parent + * the parent composite + * @return the created path selection combo + */ + protected Button createPathSelectionBrowseButton(Composite parent) { + Button pathSelectionBrowseButton = new Button(parent, SWT.PUSH); + pathSelectionBrowseButton.setText(Messages.ImportTraceWizard_BrowseButton); + setButtonLayoutData(pathSelectionBrowseButton); + + return pathSelectionBrowseButton; + } + private void archiveRadioSelected() { - if (fImportFromArchiveRadio.getSelection()) { + if (!isImportFromDirectory()) { directoryNameField.setEnabled(false); directoryBrowseButton.setEnabled(false); fArchiveNameField.setEnabled(true); fArchiveBrowseButton.setEnabled(true); updateFromSourceField(); fArchiveNameField.setFocus(); - fPreviousCreateLinksValue = fCreateLinksInWorkspaceButton.getSelection(); - fCreateLinksInWorkspaceButton.setSelection(false); - fCreateLinksInWorkspaceButton.setEnabled(false); + if (fCreateLinksInWorkspaceButton != null) { + fPreviousCreateLinksValue = fCreateLinksInWorkspaceButton.getSelection(); + fCreateLinksInWorkspaceButton.setSelection(false); + fCreateLinksInWorkspaceButton.setEnabled(false); + } } } private void directoryRadioSelected() { - if (fImportFromDirectoryRadio.getSelection()) { + if (isImportFromDirectory()) { directoryNameField.setEnabled(true); directoryBrowseButton.setEnabled(true); fArchiveNameField.setEnabled(false); fArchiveBrowseButton.setEnabled(false); updateFromSourceField(); directoryNameField.setFocus(); - fCreateLinksInWorkspaceButton.setSelection(fPreviousCreateLinksValue); - fCreateLinksInWorkspaceButton.setEnabled(true); + if (fCreateLinksInWorkspaceButton != null) { + fCreateLinksInWorkspaceButton.setSelection(fPreviousCreateLinksValue); + fCreateLinksInWorkspaceButton.setEnabled(true); + } } } @@ -563,16 +630,19 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { } // If it is valid then proceed to populate setErrorMessage(null); - setSourceName(selectedDirectory); + setSourcePath(selectedDirectory); } } /** * Handle the button pressed event + * + * @param extensions + * file extensions used to filter files shown to the user */ - private void handleArchiveBrowseButtonPressed() { + protected void handleArchiveBrowseButtonPressed(String[] extensions) { FileDialog dialog = new FileDialog(fArchiveNameField.getShell(), SWT.SHEET); - dialog.setFilterExtensions(FILE_IMPORT_MASK); + dialog.setFilterExtensions(extensions); dialog.setText(Messages.ImportTraceWizard_SelectTraceArchiveTitle); String fileName = fArchiveNameField.getText().trim(); if (!fileName.isEmpty()) { @@ -585,21 +655,28 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { String selectedArchive = dialog.open(); if (selectedArchive != null) { setErrorMessage(null); - setSourceName(selectedArchive); + setSourcePath(selectedArchive); updateWidgetEnablements(); } } private File getSourceDirectory() { + if (directoryNameField == null) { + return null; + } return getSourceDirectory(directoryNameField.getText()); } private File getSourceArchiveFile() { + if (fArchiveNameField == null) { + return null; + } + return getSourceArchiveFile(fArchiveNameField.getText()); } private String getSourceContainerPath() { - if (fImportFromDirectoryRadio.getSelection()) { + if (isImportFromDirectory()) { File sourceDirectory = getSourceDirectory(); if (sourceDirectory != null) { return sourceDirectory.getAbsolutePath(); @@ -641,16 +718,35 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { } private void updateFromSourceField() { - setSourceName(getSourceField().getText()); + setSourcePath(getSourceField().getText()); updateWidgetEnablements(); } private Combo getSourceField() { + if (directoryNameField == null) { + return fArchiveNameField; + } + return directoryNameField.isEnabled() ? directoryNameField : fArchiveNameField; } - private void setSourceName(String path) { + /** + * Set the source path that was selected by the user by various input + * methods (Browse button, typing, etc). + * + * Clients can also call this to set the path programmatically (hard-coded + * initial path) and this can also be overridden to be notified when the + * source path changes. + * + * @param path + * the source path + */ + protected void setSourcePath(String path) { Combo sourceField = getSourceField(); + if (sourceField == null) { + return; + } + if (path.length() > 0) { String[] currentItems = sourceField.getItems(); int selectionIndex = -1; @@ -696,7 +792,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { FileSystemObjectImportStructureProvider importStructureProvider = null; // Import from directory - if (fImportFromDirectoryRadio.getSelection()) { + if (isImportFromDirectory()) { importStructureProvider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null); File sourceDirectory = getSourceDirectory(); if (sourceDirectory == null) { @@ -948,7 +1044,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { String[] availableTraceTypes = TmfTraceType.getAvailableTraceTypes(); String[] traceTypeList = new String[availableTraceTypes.length + 1]; - traceTypeList[0] = AUTO_DETECT; + traceTypeList[0] = TRACE_TYPE_AUTO_DETECT; for (int i = 0; i < availableTraceTypes.length; i++) { traceTypeList[i + 1] = availableTraceTypes[i]; } @@ -957,7 +1053,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { @Override public void widgetSelected(SelectionEvent e) { updateWidgetEnablements(); - boolean enabled = fTraceTypes.getText().equals(AUTO_DETECT); + boolean enabled = fTraceTypes.getText().equals(TRACE_TYPE_AUTO_DETECT); fImportUnrecognizedButton.setEnabled(enabled); } }); @@ -1009,7 +1105,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { @Override public boolean validateSourceGroup() { - File source = fImportFromDirectoryRadio.getSelection() ? getSourceDirectory() : getSourceArchiveFile(); + File source = isImportFromDirectory() ? getSourceDirectory() : getSourceArchiveFile(); if (source == null) { setMessage(Messages.ImportTraceWizard_SelectTraceSourceEmpty); setErrorMessage(null); @@ -1022,7 +1118,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { return false; } - if (!fImportFromDirectoryRadio.getSelection()) { + if (!isImportFromDirectory()) { if (!ensureTarSourceIsValid(source.getAbsolutePath()) && !ensureZipSourceIsValid(source.getAbsolutePath())) { setMessage(null); setErrorMessage(Messages.ImportTraceWizard_BadArchiveFormat); @@ -1054,40 +1150,58 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { return true; } + private boolean isImportFromDirectory() { + return fImportFromDirectoryRadio != null && fImportFromDirectoryRadio.getSelection(); + } + @Override protected void restoreWidgetValues() { super.restoreWidgetValues(); IDialogSettings settings = getDialogSettings(); boolean value; - if (settings.get(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID) == null) { - value = true; - } else { - value = settings.getBoolean(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID); + if (fImportUnrecognizedButton != null) { + if (settings.get(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID)) == null) { + value = true; + } else { + value = settings.getBoolean(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID)); + } + fImportUnrecognizedButton.setSelection(value); } - fImportUnrecognizedButton.setSelection(value); - if (settings.get(IMPORT_WIZARD_PRESERVE_FOLDERS_ID) == null) { - value = true; - } else { - value = settings.getBoolean(IMPORT_WIZARD_PRESERVE_FOLDERS_ID); + if (fPreserveFolderStructureButton != null) { + if (settings.get(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID)) == null) { + value = true; + } else { + value = settings.getBoolean(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID)); + } + fPreserveFolderStructureButton.setSelection(value); } - fPreserveFolderStructureButton.setSelection(value); - if (settings.get(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY) == null) { + if (settings.get(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID)) == null) { value = true; } else { - value = settings.getBoolean(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY); + value = settings.getBoolean(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID)); } - restoreComboValues(directoryNameField, settings, IMPORT_WIZARD_ROOT_DIRECTORY_ID); - restoreComboValues(fArchiveNameField, settings, IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID); - fImportFromDirectoryRadio.setSelection(value); - fImportFromArchiveRadio.setSelection(!value); - if (value) { - directoryRadioSelected(); - } else { - archiveRadioSelected(); + if (directoryNameField != null) { + restoreComboValues(directoryNameField, settings, getPageStoreKey(IMPORT_WIZARD_ROOT_DIRECTORY_ID)); + } + if (fArchiveNameField != null) { + restoreComboValues(fArchiveNameField, settings, getPageStoreKey(IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID)); + } + + if (fImportFromDirectoryRadio != null) { + fImportFromDirectoryRadio.setSelection(value); + if (value) { + directoryRadioSelected(); + } + } + if (fImportFromArchiveRadio != null) { + fImportFromArchiveRadio.setSelection(!value); + if (!value) { + archiveRadioSelected(); + } } } @@ -1095,12 +1209,24 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { protected void saveWidgetValues() { // Persist dialog settings IDialogSettings settings = getDialogSettings(); - settings.put(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID, fImportUnrecognizedButton.getSelection()); - settings.put(IMPORT_WIZARD_PRESERVE_FOLDERS_ID, fPreserveFolderStructureButton.getSelection()); - settings.put(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY, fImportFromDirectoryRadio.getSelection()); + if (fImportUnrecognizedButton != null) { + settings.put(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID), fImportUnrecognizedButton.getSelection()); + } + if (fPreserveFolderStructureButton != null) { + settings.put(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID), fPreserveFolderStructureButton.getSelection()); + } + settings.put(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID), isImportFromDirectory()); + + if (directoryNameField != null) { + saveComboValues(directoryNameField, settings, getPageStoreKey(IMPORT_WIZARD_ROOT_DIRECTORY_ID)); + } + if (fArchiveNameField != null) { + saveComboValues(fArchiveNameField, settings, getPageStoreKey(IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID)); + } + } - saveComboValues(directoryNameField, settings, IMPORT_WIZARD_ROOT_DIRECTORY_ID); - saveComboValues(fArchiveNameField, settings, IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID); + private String getPageStoreKey(String key) { + return getName() + key; } private static void restoreComboValues(Combo combo, IDialogSettings settings, String key) { @@ -1136,9 +1262,9 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { * @return <code>true</code> if successful else <code>false</code> */ public boolean finish() { - String traceTypeName = fTraceTypes.getText(); + String traceTypeName = getImportTraceTypeId(); String traceId = null; - if (!AUTO_DETECT.equals(traceTypeName)) { + if (!TRACE_TYPE_AUTO_DETECT.equals(traceTypeName)) { String tokens[] = traceTypeName.split(SEPARATOR, 2); if (tokens.length < 2) { return false; @@ -1151,8 +1277,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { IPath baseSourceContainerPath = new Path(getSourceContainerPath()); boolean importFromArchive = getSourceArchiveFile() != null; + int importOptionFlags = getImportOptionFlags(); + final TraceValidateAndImportOperation operation = new TraceValidateAndImportOperation(traceId, baseSourceContainerPath, getContainerFullPath(), importFromArchive, - fImportUnrecognizedButton.getSelection(), fOverwriteExistingResourcesCheckbox.getSelection(), fCreateLinksInWorkspaceButton.getSelection(), fPreserveFolderStructureButton.getSelection()); + importOptionFlags); IStatus status = Status.OK_STATUS; try { @@ -1188,6 +1316,44 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { return true; } + /** + * Get the trace type id to import as. This can also return + * {@link #TRACE_TYPE_AUTO_DETECT} to communicate that automatic trace type + * detection will occur instead of setting a specific trace type when + * importing the traces. + * + * @return the trace type id or {@link #TRACE_TYPE_AUTO_DETECT} + */ + protected String getImportTraceTypeId() { + return fTraceTypes.getText(); + } + + /** + * Get import options in the form of flags (bits). + * + * @return the import flags. + * @see #OPTION_CREATE_LINKS_IN_WORKSPACE + * @see #OPTION_IMPORT_UNRECOGNIZED_TRACES + * @see #OPTION_OVERWRITE_EXISTING_RESOURCES + * @see #OPTION_PRESERVE_FOLDER_STRUCTURE + */ + protected int getImportOptionFlags() { + int flags = 0; + if (fCreateLinksInWorkspaceButton != null && fCreateLinksInWorkspaceButton.getSelection()) { + flags |= OPTION_CREATE_LINKS_IN_WORKSPACE; + } + if (fImportUnrecognizedButton != null && fImportUnrecognizedButton.getSelection()) { + flags |= OPTION_IMPORT_UNRECOGNIZED_TRACES; + } + if (fOverwriteExistingResourcesCheckbox != null && fOverwriteExistingResourcesCheckbox.getSelection()) { + flags |= OPTION_OVERWRITE_EXISTING_RESOURCES; + } + if (fPreserveFolderStructureButton != null && fPreserveFolderStructureButton.getSelection()) { + flags |= OPTION_PRESERVE_FOLDER_STRUCTURE; + } + return flags; + } + @Override public void dispose() { super.dispose(); @@ -1204,22 +1370,20 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { private IPath fDestinationContainerPath; private IPath fBaseSourceContainerPath; private boolean fImportFromArchive; - private boolean fImportUnrecognizedTraces; - private boolean fLink; - private boolean fPreserveFolderStructure; + private int fImportOptionFlags; private ImportConfirmation fConfirmationMode = ImportConfirmation.SKIP; - private TraceValidateAndImportOperation(String traceId, IPath baseSourceContainerPath, IPath destinationContainerPath, boolean importFromArchive, boolean doImport, boolean overwrite, boolean link, boolean preserveFolderStructure) { + private TraceValidateAndImportOperation(String traceId, IPath baseSourceContainerPath, IPath destinationContainerPath, boolean importFromArchive, int importOptionFlags) { fTraceType = traceId; fBaseSourceContainerPath = baseSourceContainerPath; fDestinationContainerPath = destinationContainerPath; + fImportOptionFlags = importOptionFlags; fImportFromArchive = importFromArchive; - fImportUnrecognizedTraces = doImport; - if (overwrite) { + + boolean overwriteExistingResources = (importOptionFlags & OPTION_OVERWRITE_EXISTING_RESOURCES) != 0; + if (overwriteExistingResources) { fConfirmationMode = ImportConfirmation.OVERWRITE_ALL; } - fLink = link; - fPreserveFolderStructure = preserveFolderStructure; } public void run(IProgressMonitor progressMonitor) { @@ -1402,7 +1566,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { // We need to figure out the new destination path relative to the selected "base" source directory. // Here for example, the selected source directory is /home/user - if (fPreserveFolderStructure) { + if ((fImportOptionFlags & OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) { // /home/user/bar/foo/trace -> /home/user/bar/foo IPath sourceContainerPath = resourcePath.removeLastSegments(1); if (fBaseSourceContainerPath.equals(resourcePath)) { @@ -1431,7 +1595,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { // the trace did not match any trace type } if (traceTypeHelper == null) { - if (fImportUnrecognizedTraces) { + if ((fImportOptionFlags & OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) { importResource(fileSystemElement, monitor); } return; @@ -1507,7 +1671,8 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { IPath containerPath = fileSystemElement.getDestinationContainerPath(); IPath tracePath = containerPath.addTrailingSeparator().append(fileSystemElement.getLabel()); - if (fileSystemElement.isDirectory() && (!fLink)) { + boolean createLinksInWorkspace = (fImportOptionFlags & OPTION_CREATE_LINKS_IN_WORKSPACE) != 0; + if (fileSystemElement.isDirectory() && !createLinksInWorkspace) { containerPath = tracePath; Object[] array = fileSystemElement.getFiles().getChildren(); @@ -1536,7 +1701,7 @@ public class ImportTraceWizardPage extends WizardResourceImportPage { operation.setCreateContainerStructure(false); operation.setOverwriteResources(false); - operation.setCreateLinks(fLink); + operation.setCreateLinks(createLinksInWorkspace); operation.setVirtualFolders(false); operation.run(new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); |