use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder in project tracecompass by tracecompass.
the class XMLAnalysesManagerPreferencePage method deleteSupplementaryFiles.
/**
* Delete the supplementary files associated with XML analysis files.
*
* @param xmlFiles
* the xml analysis files (with extension)
* @return the list of elements that should be re-opened
*/
private static Collection<TmfCommonProjectElement> deleteSupplementaryFiles(Collection<String> xmlFiles) {
// 1. Look for all traces that have these analyses
// 2. Close them if they are opened, but remember them
// 3. Delete the related supplementary files
Collection<TmfCommonProjectElement> toReopen = new ArrayList<>();
List<IResource> resourceToDelete = new ArrayList<>();
Set<String> ids = Sets.newHashSet();
xmlFiles.forEach(xmlFile -> ids.addAll(XmlUtils.getAnalysisIdsFromFile(xmlFile)));
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(0);
for (IProject project : projects) {
TmfProjectElement pElement = TmfProjectRegistry.getProject(project);
if (pElement != null) {
List<TmfCommonProjectElement> tElements = new ArrayList<>();
TmfTraceFolder tracesFolder = pElement.getTracesFolder();
if (tracesFolder != null) {
tElements.addAll(tracesFolder.getTraces());
}
TmfExperimentFolder experimentsFolder = pElement.getExperimentsFolder();
if (experimentsFolder != null) {
tElements.addAll(experimentsFolder.getExperiments());
}
Set<IEditorReference> editorReferences = getEditorReferences();
for (TmfCommonProjectElement tElement : tElements) {
for (IResource resource : tElement.getSupplementaryResources()) {
for (String id : ids) {
if (resource.getName().startsWith(id)) {
resourceToDelete.add(resource);
}
}
}
IFile file = tElement.getBookmarksFile();
FileEditorInput input = new FileEditorInput(file);
boolean open = Iterables.any(editorReferences, editorReference -> {
try {
return editorReference.getEditorInput().equals(input);
} catch (PartInitException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Activator.logError("Failed to test the " + tElement.getName() + " editor", e);
return false;
}
});
if (open) {
toReopen.add(tElement);
}
tElement.closeEditors();
}
}
}
for (IResource resource : resourceToDelete) {
try {
resource.delete(false, null);
} catch (CoreException e) {
Activator.logError(NLS.bind(Messages.ManageXMLAnalysisDialog_DeleteFileError, resource.getName()));
}
}
return toReopen;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder in project tracecompass by tracecompass.
the class RemoteFetchLogWizardRemotePage method determinePageCompletion.
@Override
protected boolean determinePageCompletion() {
if (getElementViewer().getCheckedElements().length <= 0) {
return false;
}
validateProject();
if ((fExperimentName != null) && (fCreateExperimentCheckbox.getSelection())) {
String name = fExperimentNameText.getText().trim();
// verify if experiment name is empty
if (name.isEmpty()) {
setMessage(null);
setErrorMessage(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorEmptyExperimentName);
return false;
}
// verify that name is a valid resource name
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if ((workspace != null) && (!workspace.validateName(name, IResource.FILE).isOK())) {
setMessage(null);
setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorExperimentNameInvalid, name));
return false;
}
TmfExperimentFolder experimentFolder = fExperimentFolderElement;
if (experimentFolder != null) {
TmfExperimentElement element = experimentFolder.getExperiment(name);
// verify if experiment already exists
if (element != null) {
setMessage(null);
setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorExperimentAlreadyExists, name));
return false;
}
// verify if a resource already exists in the experiment folder
IFolder expResource = experimentFolder.getResource();
IResource res = expResource.findMember(name);
if (res != null) {
setMessage(null);
setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorResourceAlreadyExists, name));
return false;
}
}
}
return true;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder in project tracecompass by tracecompass.
the class RemoteFetchLogWizardRemotePage method finish.
/**
* Finishes the wizard page.
*
* @return <code>true</code> if successful else <code>false</code>
*/
public boolean finish() {
boolean result;
if (!fIsVisible) {
result = updateViewer();
if (!result) {
return false;
}
}
result = validateProject();
if (!result) {
return false;
}
Object[] elements = getElementViewer().getCheckedElements();
final RemoteImportTracesOperation importOperation = new RemoteImportTracesOperation(getContainer().getShell(), fTmfTraceFolder, elements, fOverwriteAll);
final List<IResource> traceResources = new ArrayList<>();
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
importOperation.run(monitor);
traceResources.addAll(importOperation.getImportedResources());
monitor.done();
}
});
if ((fExperimentName != null) && fCreateExperimentCheckbox.getSelection() && (!traceResources.isEmpty())) {
final IFolder[] experimentFolders = new IFolder[1];
final TmfExperimentFolder root = fExperimentFolderElement;
final IStatus[] operationStatus = new IStatus[1];
final String experimentName = fExperimentNameText.getText().trim();
// just safety guards
if ((root == null) || (experimentName.isEmpty())) {
return true;
}
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
operationStatus[0] = null;
final NewExperimentOperation operation = new NewExperimentOperation(root, experimentName);
operation.run(monitor);
monitor.done();
operationStatus[0] = operation.getStatus();
experimentFolders[0] = operation.getExperimentFolder();
}
});
final IFolder expFolder = experimentFolders[0];
final TmfTraceFolder parentTraceFolder = fTmfTraceFolder;
// just safety guards
if ((expFolder == null) || (parentTraceFolder == null)) {
return true;
}
if ((operationStatus[0] != null) && (operationStatus[0].isOK())) {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
operationStatus[0] = null;
final SelectTracesOperation operation = new SelectTracesOperation(root, expFolder, parentTraceFolder, traceResources);
operation.run(monitor);
monitor.done();
operationStatus[0] = operation.getStatus();
}
});
}
}
} catch (InvocationTargetException e) {
handleError(Messages.TracePackageExtractManifestOperation_ErrorReadingManifest, e);
return false;
} catch (InterruptedException e) {
// Cancelled
return false;
}
IStatus status = importOperation.getStatus();
if (status.getSeverity() == IStatus.ERROR) {
handleErrorStatus(status);
return false;
}
disconnectAllRemoteHosts();
return true;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder in project tracecompass by tracecompass.
the class SWTBotUtils method createExperiment.
/**
* Creates an experiment
*
* @param bot
* a given workbench bot
* @param projectName
* the name of the project, creates the project if needed
* @param expName
* the experiment name
*/
public static void createExperiment(SWTWorkbenchBot bot, String projectName, @NonNull final String expName) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
assertNotNull(expFolder);
NewExperimentOperation operation = new NewExperimentOperation(expFolder, expName);
operation.run(new NullProgressMonitor());
bot.waitUntil(new DefaultCondition() {
@Override
public boolean test() throws Exception {
TmfExperimentElement experiment = expFolder.getExperiment(expName);
return experiment != null;
}
@Override
public String getFailureMessage() {
return "Experiment (" + expName + ") couldn't be created";
}
});
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder in project tracecompass by tracecompass.
the class SWTBotUtils method clearExperimentFolder.
/**
* Clear the experiment folder
*
* @param bot
* a given workbench bot
* @param projectName
* the name of the project (needs to exist)
*/
public static void clearExperimentFolder(SWTWorkbenchBot bot, String projectName) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
if (expFolder == null) {
return;
}
expFolder.getExperiments().forEach(experiment -> {
IResource resource = experiment.getResource();
try {
// Close the experiment if open
experiment.closeEditors();
IPath path = resource.getLocation();
if (path != null) {
// Delete supplementary files
experiment.deleteSupplementaryFolder();
}
// Finally, delete the experiment
resource.delete(true, null);
} catch (CoreException e) {
fail(e.getMessage());
}
});
bot.waitUntil(new DefaultCondition() {
private int fExperimentNb = 0;
@Override
public boolean test() throws Exception {
List<TmfExperimentElement> experiments = expFolder.getExperiments();
fExperimentNb = experiments.size();
return fExperimentNb == 0;
}
@Override
public String getFailureMessage() {
return "Experiment Folder not empty (" + fExperimentNb + ")";
}
});
}
Aggregations