import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation;
import org.eclipse.tracecompass.internal.tmf.ui.views.statistics.TmfStatisticsViewImpl;
import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
* Finishes the wizard
*/
protected void importFinish() {
+ importFinish(ImportConfirmation.CONTINUE);
+ }
+
+ /**
+ * Finishes the wizard
+ *
+ * @param confirmationMode
+ * a confirmation value
+ * Note: Only {@link ImportConfirmation#RENAME_ALL},
+ * {@link ImportConfirmation#OVERWRITE_ALL},
+ * {@link ImportConfirmation#CONTINUE} are supported
+ */
+ protected void importFinish(ImportConfirmation confirmationMode) {
SWTBotShell shell = fBot.activeShell();
final SWTBotButton finishButton = fBot.button("Finish");
finishButton.click();
+ if (confirmationMode == ImportConfirmation.RENAME_ALL) {
+ fBot.waitUntil(Conditions.shellIsActive("Confirmation"));
+ SWTBotShell shell2 = fBot.activeShell();
+ SWTBotButton button = shell2.bot().button("Rename All");
+ button.click();
+ } else if (confirmationMode == ImportConfirmation.OVERWRITE_ALL) {
+ fBot.waitUntil(Conditions.shellIsActive("Confirmation"));
+ SWTBotShell shell2 = fBot.activeShell();
+ SWTBotButton button = shell2.bot().button("Overwrite All");
+ button.click();
+ }
fBot.waitUntil(Conditions.shellCloses(shell));
SWTBotUtils.waitForJobs();
}
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation;
import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
*/
@Test
public void testImportWithExperimentValidation() throws Exception {
- testImport(ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, false, false);
+ testImport(ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, false, false, true, ImportConfirmation.CONTINUE);
}
/**
*/
@Test
public void testImportFromDirectoryOverwrite() throws Exception {
- testImport(0, false, false);
+ testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
}
+ /**
+ * Test import from directory, overwrite all
+ *
+ * @throws Exception
+ * on error
+ */
+ @Test
+ public void testImportFromDirectoryOverwriteRenameAll() throws Exception {
+ testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
+ testImport(0, false, false, true, true, ImportConfirmation.RENAME_ALL);
+ }
+
+ /**
+ * Test import from directory, overwrite all
+ *
+ * @throws Exception
+ * on error
+ */
+ @Test
+ public void testImportFromDirectoryOverwriteOverwriteAll() throws Exception {
+ testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
+ testImport(0, false, false, true, true, ImportConfirmation.OVERWRITE_ALL);
+ }
+
/**
* Test import from archive
*
*/
@Test
public void testImportFromArchiveOverwrite() throws Exception {
- testImport(0, false, true);
+ testImport(0, false, true, true, false, ImportConfirmation.CONTINUE);
testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
}
}
private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception {
- testImport(options, testViews, fromArchive, true);
+ testImport(options, testViews, fromArchive, true, true, ImportConfirmation.CONTINUE);
}
- private void testImport(int options, boolean testViews, boolean fromArchive, boolean defaultExperiment) throws Exception {
+ private void testImport(int options, boolean testViews, boolean fromArchive, boolean defaultExperiment, boolean clearTraces, ImportConfirmation confirmationMode) throws Exception {
String expectedSourceLocation = null;
@NonNull String experimentName;
}
checkFinishButton(true);
- importFinish();
+ importFinish(confirmationMode);
IPath expectedElementPath = new Path(TRACE_NAME);
if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
expectedElementPath = new Path(TRACE_FOLDER).append(expectedElementPath);
}
- checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName);
+ if (confirmationMode == ImportConfirmation.RENAME_ALL) {
+ IPath expectedElementPathRenamed = new Path(TRACE_NAME + "(2)");
+ checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName, expectedElementPathRenamed);
+ } else {
+ checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName, null);
+ }
+
TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
if (testViews) {
testViews(tmfEd);
fBot.closeAllEditors();
SWTBotUtils.clearExperimentFolder(fBot, TRACE_PROJECT_NAME);
- SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+ if (clearTraces) {
+ SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+ }
}
private void testImportAndExtractArchives(int options, boolean testViews, boolean fromArchive) throws Exception {
}
private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
- checkOptions(optionFlags, expectedSourceLocation, expectedElementPath, null);
+ checkOptions(optionFlags, expectedSourceLocation, expectedElementPath, null, null);
}
- private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath, String experimentName) throws CoreException {
+ private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath, String experimentName, IPath expectedElementPathRenamed) throws CoreException {
IProject project = getProjectResource();
assertTrue(project.exists());
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPath);
assertEquals(expectedPath, traceResource.getFullPath());
+ if (expectedElementPathRenamed != null) {
+ IPath expectedPathRenamed = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPathRenamed);
+ IResource traceResourceRenamed = traces.get(1).getResource();
+ assertEquals(expectedPathRenamed, traceResourceRenamed.getFullPath());
+ }
+
String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
assertNotNull(sourceLocation);
assertEquals(expectedSourceLocation, sourceLocation);
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
// ------------------------------------------------------------------------
private ImportConfirmation checkForNameClash(IPath tracePath) throws InterruptedException {
// handle rename
- if (getExistingTrace(tracePath) != null) {
+ if (getExistingResource(tracePath) != null) {
if ((fConfirmationMode == ImportConfirmation.RENAME_ALL) ||
(fConfirmationMode == ImportConfirmation.OVERWRITE_ALL) ||
(fConfirmationMode == ImportConfirmation.SKIP_ALL)) {
private int promptForOverwrite(IPath tracePath) {
final MessageDialog dialog = new MessageDialog(fShell,
- null, null, NLS.bind(Messages.ImportTraceWizard_TraceAlreadyExists, tracePath.makeRelativeTo(fTraceFolderElement.getProject().getPath())),
+ Messages.ImportTraceWizard_MessageTitle, null, NLS.bind(Messages.ImportTraceWizard_TraceAlreadyExists, tracePath.makeRelativeTo(fTraceFolderElement.getProject().getPath())),
MessageDialog.QUESTION, new String[] {
ImportConfirmation.RENAME.getInName(),
ImportConfirmation.RENAME_ALL.getInName(),
return returnValue[0];
}
- private String rename(IPath tracePath) {
- TmfTraceElement trace = getExistingTrace(tracePath);
- if (trace == null) {
+ private static String rename(IPath tracePath) {
+ IResource existingResource = getExistingResource(tracePath);
+ if (existingResource == null) {
return tracePath.lastSegment();
}
// Not using IFolder on purpose to leave the door open to import
// directly into an IProject
- IContainer folder = (IContainer) trace.getParent().getResource();
+ IContainer folder = existingResource.getParent();
+
int i = 2;
while (true) {
- String name = trace.getName() + '(' + Integer.toString(i++) + ')';
+ String name = existingResource.getName() + '(' + Integer.toString(i++) + ')';
IResource resource = folder.findMember(name);
if (resource == null) {
return name;
}
private void delete(IPath tracePath, IProgressMonitor monitor) throws CoreException {
- TmfTraceElement trace = getExistingTrace(tracePath);
- if (trace == null) {
+ IResource existingResource = getExistingResource(tracePath);
+ if (existingResource == null) {
+ return;
+ }
+ TmfTraceElement existingTraceElement = getExistingTrace(tracePath);
+ if (existingTraceElement != null) {
+ // Delete existing TmfTraceElement
+ existingTraceElement.delete(monitor);
return;
}
- trace.delete(monitor);
+ // Delete resource existing in workspace
+ existingResource.delete(true, monitor);
}
private TmfTraceElement getExistingTrace(IPath tracePath) {
}
return null;
}
+
+ private static IResource getExistingResource(IPath tracePath) {
+ // Look for existing resource
+ return ResourcesPlugin.getWorkspace().getRoot().findMember(tracePath);
+ }
}