Search in sources :

Example 11 with TmfCommonProjectElement

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

the class NewTmfViewAction method run.

@Override
public void run() {
    ITmfTrace pinnedTrace = fPinnedTrace;
    if (fNewInstance) {
        if (pinnedTrace == null) {
            return;
        }
        /* We need to wait for the trace to be opened before opening the view */
        IFile file = TmfTraceManager.getInstance().getTraceContext(pinnedTrace).getEditorFile();
        Object element = new TmfEditorLinkHelper().findSelection(new FileEditorInput(file)).getFirstElement();
        if (element instanceof TmfCommonProjectElement) {
            OpenProjectElementJob openJob = new OpenProjectElementJob((TmfCommonProjectElement) element, file);
            openJob.schedule();
            Thread waitThread = new Thread() {

                @Override
                public void run() {
                    while (!TmfTraceManager.getInstance().getOpenedTraces().contains(openJob.getTrace())) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                            return;
                        }
                    }
                    Display.getDefault().asyncExec(() -> {
                        IViewPart view = TmfViewFactory.newView(fViewId, true);
                        if (view instanceof ITmfPinnable) {
                            ((ITmfPinnable) view).setPinned(openJob.getTrace());
                        }
                    });
                }
            };
            waitThread.start();
        }
        return;
    }
    IViewPart view = TmfViewFactory.newView(fViewId, true);
    if (pinnedTrace != null && view instanceof ITmfPinnable) {
        ((ITmfPinnable) view).setPinned(pinnedTrace);
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) OpenProjectElementJob(org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper.OpenProjectElementJob) TmfEditorLinkHelper(org.eclipse.tracecompass.internal.tmf.ui.project.model.TmfEditorLinkHelper) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)

Example 12 with TmfCommonProjectElement

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

the class TrimTraceDialog method validateNewTraceName.

private void validateNewTraceName() {
    String newTraceName = fNewElementName.getText();
    TmfCommonProjectElement element = fElement;
    IWorkspace workspace = element.getResource().getWorkspace();
    IStatus nameStatus = workspace.validateName(newTraceName, IResource.FOLDER);
    if ("".equals(newTraceName)) {
        // $NON-NLS-1$
        updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null));
        return;
    }
    if (!nameStatus.isOK()) {
        updateStatus(nameStatus);
        return;
    }
    IContainer parentFolder = element.getResource().getParent();
    if (parentFolder.findMember(newTraceName) != null) {
        updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null));
        return;
    }
    TmfTraceFolder tracesFolderElement = element.getProject().getTracesFolder();
    if (tracesFolderElement != null) {
        IFolder tracesFolder = tracesFolderElement.getResource();
        IPath traceDestinationPath = new Path(newTraceName);
        if (tracesFolder.getFolder(traceDestinationPath).exists()) {
            updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null));
            return;
        }
    }
    // $NON-NLS-1$
    updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, ""));
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) IWorkspace(org.eclipse.core.resources.IWorkspace) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 13 with TmfCommonProjectElement

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

the class TracePackageImportOperation method importSupplFiles.

private IStatus importSupplFiles(TracePackageTraceElement packageElement, IProgressMonitor monitor) {
    List<Pair<String, String>> fileNameAndLabelPairs = new ArrayList<>();
    Map<String, String> suppFilesRename = new HashMap<>();
    for (TracePackageElement element : packageElement.getChildren()) {
        if (element instanceof TracePackageSupplFilesElement) {
            for (TracePackageElement child : element.getChildren()) {
                if (child.isChecked()) {
                    TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child;
                    if (packageElement instanceof TracePackageExperimentElement) {
                        String oldExpName = getOldExpName(supplFile);
                        if (!packageElement.getImportName().equals(oldExpName)) {
                            suppFilesRename.put(supplFile.getText(), supplFile.getText().replace(oldExpName, packageElement.getImportName()));
                        }
                    }
                    fileNameAndLabelPairs.add(new Pair<>(checkNotNull(supplFile.getText()), checkNotNull(new Path(supplFile.getText()).lastSegment())));
                }
            }
        }
    }
    if (!fileNameAndLabelPairs.isEmpty()) {
        TmfCommonProjectElement projectElement = getMatchingProjectElement(packageElement);
        if (projectElement != null) {
            ArchiveFile archiveFile = getSpecifiedArchiveFile();
            projectElement.refreshSupplementaryFolder();
            IPath destinationContainerPath;
            if (packageElement instanceof TracePackageExperimentElement) {
                destinationContainerPath = projectElement.getProject().getSupplementaryFolder().getFullPath();
            } else {
                // Project/Traces/A/B -> A/B
                final TmfTraceFolder tracesFolder = fTmfTraceFolder.getProject().getTracesFolder();
                if (tracesFolder == null) {
                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation);
                }
                IPath traceFolderRelativePath = fTmfTraceFolder.getPath().makeRelativeTo(tracesFolder.getPath());
                // Project/.tracing/A/B/
                IFolder traceSupplementaryFolder = fTmfTraceFolder.getTraceSupplementaryFolder(traceFolderRelativePath.toString());
                destinationContainerPath = traceSupplementaryFolder.getFullPath();
            }
            // Remove the .tracing segment at the beginning so that a file
            // in folder .tracing/A/B/ imports to destinationContainerPath/A/B/
            Path baseSourcePath = new Path(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME);
            return importFiles(archiveFile, fileNameAndLabelPairs, destinationContainerPath, baseSourcePath, suppFilesRename, monitor);
        }
    }
    return Status.OK_STATUS;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) ArrayList(java.util.ArrayList) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with TmfCommonProjectElement

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

the class TracePackageExportOperation method exportTraceFiles.

private void exportTraceFiles(IProgressMonitor monitor, Node traceNode, TracePackageFilesElement element) throws CoreException {
    Document doc = traceNode.getOwnerDocument();
    TmfCommonProjectElement traceElement = ((TracePackageTraceElement) element.getParent()).getTraceElement();
    IResource resource = traceElement.getResource();
    final TmfProjectModelElement tracesFolder = traceElement.getProject().getTracesFolder();
    if (tracesFolder == null) {
        return;
    }
    IPath traceFolderPath = tracesFolder.getPath();
    // project/Traces/A/B/Kernel -> A/B/Kernel
    IPath relativeToExportFolder = resource.getFullPath().makeRelativeTo(traceFolderPath);
    // project/.traceExport/A/B
    IFolder folder = fExportFolder.getFolder(relativeToExportFolder.removeLastSegments(1));
    TraceUtils.createFolder(folder, SubMonitor.convert(monitor));
    createExportResource(folder, resource);
    Element fileElement = doc.createElement(ITracePackageConstants.TRACE_FILE_ELEMENT);
    fileElement.setAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB, relativeToExportFolder.toString());
    traceNode.appendChild(fileElement);
    // Always export the top-most folder containing the trace or the
    // trace itself
    IResource exportedResource = fExportFolder.findMember(relativeToExportFolder.segment(0));
    fResources.add(exportedResource);
}
Also used : IPath(org.eclipse.core.runtime.IPath) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Element(org.w3c.dom.Element) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) TmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) Document(org.w3c.dom.Document) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with TmfCommonProjectElement

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

the class TracePackageExportOperation method exportCommon.

private Node exportCommon(IProgressMonitor monitor, Node tmfNode, TracePackageTraceElement tracePackageElement, String elementString) throws InterruptedException, CoreException {
    TmfCommonProjectElement commonElement = tracePackageElement.getTraceElement();
    Element commonXmlElement = tmfNode.getOwnerDocument().createElement(elementString);
    commonXmlElement.setAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB, commonElement.getResource().getName());
    commonXmlElement.setAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB, commonElement.getTraceType());
    Node commonNode = tmfNode.appendChild(commonXmlElement);
    for (TracePackageElement element : tracePackageElement.getChildren()) {
        ModalContext.checkCanceled(monitor);
        if (!element.isChecked()) {
            continue;
        }
        if (element instanceof TracePackageSupplFilesElement) {
            exportSupplementaryFiles(monitor, commonNode, commonElement, (TracePackageSupplFilesElement) element);
        } else if (element instanceof TracePackageBookmarkElement) {
            exportBookmarks(monitor, commonNode, (TracePackageBookmarkElement) element);
        } else if (element instanceof TracePackageFilesElement && commonElement instanceof TmfTraceElement) {
            exportTraceFiles(monitor, commonNode, (TracePackageFilesElement) element);
        }
        monitor.worked(1);
    }
    return commonNode;
}
Also used : TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Element(org.w3c.dom.Element) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) Node(org.w3c.dom.Node) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)

Aggregations

TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)24 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)10 CoreException (org.eclipse.core.runtime.CoreException)8 IResource (org.eclipse.core.resources.IResource)7 IPath (org.eclipse.core.runtime.IPath)7 IStatus (org.eclipse.core.runtime.IStatus)7 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)7 ArrayList (java.util.ArrayList)6 Path (org.eclipse.core.runtime.Path)6 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)6 TmfTraceFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder)6 IFile (org.eclipse.core.resources.IFile)5 IFolder (org.eclipse.core.resources.IFolder)5 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)5 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)5 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)5 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)5 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)5 IProject (org.eclipse.core.resources.IProject)4 Status (org.eclipse.core.runtime.Status)4