Search in sources :

Example 1 with TmfExperimentElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement 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;
}
Also used : TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) IWorkspace(org.eclipse.core.resources.IWorkspace) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with TmfExperimentElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement 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";
        }
    });
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) DefaultCondition(org.eclipse.swtbot.swt.finder.waits.DefaultCondition) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IProject(org.eclipse.core.resources.IProject) NewExperimentOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.NewExperimentOperation) WaitTimeoutException(org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ExecutionException(org.eclipse.core.commands.ExecutionException) WorkbenchException(org.eclipse.ui.WorkbenchException) WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) NotHandledException(org.eclipse.core.commands.NotHandledException) ParseException(org.eclipse.jface.bindings.keys.ParseException)

Example 3 with TmfExperimentElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement in project tracecompass by tracecompass.

the class ImportTraceWizardPage method validateOptionsGroup.

@Override
protected boolean validateOptionsGroup() {
    if (fCreateExperimentCheckbox != null && fCreateExperimentCheckbox.getSelection()) {
        String name = fExperimentNameText.getText().trim();
        // verify if experiment name is empty
        if (name.isEmpty()) {
            setMessage(null);
            setErrorMessage(Messages.ImportTraceWizard_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(Messages.ImportTraceWizard_ErrorExperimentNameInvalid, name));
            return false;
        }
        // verify if experiment already exists
        if (fExperimentFolderElement != null) {
            TmfExperimentElement element = fExperimentFolderElement.getExperiment(name);
            if (element != null) {
                setMessage(null);
                setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorExperimentAlreadyExists, name));
                return false;
            }
            IFolder expResource = fExperimentFolderElement.getResource();
            IResource res = expResource.findMember(name);
            if (res != null) {
                setMessage(null);
                setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorResourceAlreadyExists, name));
                return false;
            }
        }
    }
    if (fTimeRangeCheckbox != null && fTimeRangeCheckbox.getSelection() && !validateTimeRange()) {
        fStartTimestamp = null;
        fEndTimestamp = null;
        setMessage(null);
        setErrorMessage(Messages.ImportTraceWizard_TimeRangeErrorMessage);
        return false;
    }
    setErrorMessage(null);
    return true;
}
Also used : IWorkspace(org.eclipse.core.resources.IWorkspace) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with TmfExperimentElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement in project tracecompass by tracecompass.

the class ExportTracePackageWizardPage method createElementViewerInput.

@Override
protected Object createElementViewerInput() {
    List<TracePackageTraceElement> traceElements = new ArrayList<>();
    for (TmfCommonProjectElement projectElement : fSelectedTraces) {
        TracePackageTraceElement traceElement;
        if (projectElement instanceof TmfExperimentElement) {
            TmfExperimentElement experimentElement = (TmfExperimentElement) projectElement;
            traceElement = new TracePackageExperimentElement(null, experimentElement);
            for (TmfTraceElement expTrace : experimentElement.getTraces()) {
                ((TracePackageExperimentElement) traceElement).addExpTrace(expTrace.getElementPath());
            }
        } else {
            traceElement = new TracePackageTraceElement(null, projectElement);
        }
        // Trace files
        TracePackageFilesElement filesElement = new TracePackageFilesElement(traceElement, projectElement.getResource());
        filesElement.setChecked(true);
        // Supplementary files
        try {
            String supplementaryFolder = projectElement.getResource().getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
            TracePackageSupplFilesElement suppFilesElement = new TracePackageSupplFilesElement(null);
            IResource[] supplementaryResources = projectElement.getSupplementaryResources();
            for (IResource res : supplementaryResources) {
                String name = supplementaryFolder == null ? res.getName() : res.getLocation().makeRelativeTo(new Path(supplementaryFolder)).toString();
                new TracePackageSupplFileElement(res, name, suppFilesElement);
            }
            if (supplementaryFolder != null) {
                // If the supplementary folder path is in a shadow project,
                // the resources must be taken from the parent project.
                IFolder projectSupplementaryFolder = projectElement.getProject().getSupplementaryFolder();
                IPath path = new Path(supplementaryFolder).append(TmfCommonConstants.TRACE_PROPERTIES_FOLDER);
                IFolder propertiesFolder = projectSupplementaryFolder.getFolder(path.makeRelativeTo(projectSupplementaryFolder.getLocation()));
                if (propertiesFolder.exists()) {
                    for (IResource res : propertiesFolder.members()) {
                        String name = res.getLocation().makeRelativeTo(new Path(supplementaryFolder)).toString();
                        new TracePackageSupplFileElement(res, name, suppFilesElement);
                    }
                }
            }
            if (suppFilesElement.getChildren().length > 0) {
                traceElement.addChild(suppFilesElement);
            }
        } catch (CoreException e) {
            // Should not happen
            // $NON-NLS-1$
            Activator.getDefault().logError("Error finding supplementary files", e);
        }
        // Bookmarks
        IFile bookmarksFile = projectElement.getBookmarksFile();
        if (bookmarksFile != null && bookmarksFile.exists()) {
            IMarker[] findMarkers;
            try {
                findMarkers = bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
                if (findMarkers.length > 0) {
                    new TracePackageBookmarkElement(traceElement, null);
                }
            } catch (CoreException e) {
                // Should not happen since we just checked bookmarksFile.exists() but log it just in case
                // $NON-NLS-1$
                Activator.getDefault().logError("Error finding bookmarks", e);
            }
        }
        traceElements.add(traceElement);
    }
    return traceElements.toArray(new TracePackageTraceElement[] {});
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) ArrayList(java.util.ArrayList) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) CoreException(org.eclipse.core.runtime.CoreException) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with TmfExperimentElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement in project tracecompass by tracecompass.

the class TracePackageImportOperation method getMatchingProjectElement.

/**
 * Return the matching TmfTraceElement for a given trace element.
 */
private TmfCommonProjectElement getMatchingProjectElement(TracePackageTraceElement tracePackageElement) {
    if (tracePackageElement instanceof TracePackageExperimentElement) {
        for (TmfExperimentElement experiment : fTmfExperimentFolder.getExperiments()) {
            if (experiment.getName().equals(tracePackageElement.getImportName())) {
                return experiment;
            }
        }
    } else {
        IPath tracePath = fTmfTraceFolder.getPath().append(tracePackageElement.getDestinationElementPath());
        List<TmfTraceElement> traces = fTmfTraceFolder.getTraces();
        for (TmfTraceElement t : traces) {
            if (t.getPath().equals(tracePath)) {
                return t;
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)

Aggregations

TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)42 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)27 CoreException (org.eclipse.core.runtime.CoreException)15 ISelection (org.eclipse.jface.viewers.ISelection)14 TmfExperimentFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder)13 IResource (org.eclipse.core.resources.IResource)12 IFolder (org.eclipse.core.resources.IFolder)11 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 TmfTraceFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IPath (org.eclipse.core.runtime.IPath)9 TmfProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement)9 HashSet (java.util.HashSet)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 Shell (org.eclipse.swt.widgets.Shell)7 IProject (org.eclipse.core.resources.IProject)6 IStatus (org.eclipse.core.runtime.IStatus)5 Collection (java.util.Collection)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4