Search in sources :

Example 6 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteProfilesPreferencePage method newProfile.

private RemoteImportProfileElement newProfile(TracePackageElement previous) {
    RemoteImportProfileElement profile = new RemoteImportProfileElement(null, RemoteMessages.RemoteProfilesPreferencePage_DefaultProfileName);
    RemoteImportConnectionNodeElement node = new RemoteImportConnectionNodeElement(profile, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeName, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeURI);
    RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(node, DEFAULT_ROOT_IMPORT_PATH);
    TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
    new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
    int index = previous == null ? fProfiles.size() : fProfiles.indexOf(previous) + 1;
    fProfiles.add(index, profile);
    newElementAdded(profile);
    return profile;
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)

Example 7 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteProfilesPreferencePage method createVerticalButtonBar.

private Composite createVerticalButtonBar(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    fAddButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_AddButton);
    fAddButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
            if (selection.isEmpty()) {
                newProfile(null);
            } else if (selection.getFirstElement() instanceof TracePackageElement) {
                TracePackageElement previous = (TracePackageElement) selection.getFirstElement();
                if (previous instanceof RemoteImportProfileElement) {
                    newProfile(previous);
                } else if (previous instanceof RemoteImportConnectionNodeElement) {
                    newConnectionNode(previous.getParent(), previous);
                } else if (previous instanceof RemoteImportTraceGroupElement) {
                    newTraceGroup(previous.getParent(), previous);
                } else if (previous instanceof TracePackageTraceElement) {
                    newTrace(previous.getParent(), previous);
                }
            }
        }
    });
    fRemoveButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_RemoveButton);
    fRemoveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
            for (Object item : selection.toList()) {
                if (item instanceof RemoteImportProfileElement) {
                    fProfiles.remove(item);
                } else if (item instanceof TracePackageElement) {
                    TracePackageElement element = (TracePackageElement) item;
                    element.getParent().removeChild(element);
                }
            }
            fTreeViewer.refresh();
            validate();
        }
    });
    new Label(composite, SWT.NONE);
    fImportButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_ImportButton);
    fImportButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = TmfFileDialogFactory.create(Display.getCurrent().getActiveShell(), SWT.OPEN);
            dialog.setText(RemoteMessages.RemoteProfilesPreferencePage_ImportFileDialogTitle);
            // $NON-NLS-1$ //$NON-NLS-2$
            dialog.setFilterExtensions(new String[] { "*.xml", "*" });
            String path = dialog.open();
            if (path != null) {
                List<RemoteImportProfileElement> profiles = readProfiles(path, new NullProgressMonitor());
                fProfiles.addAll(profiles);
                fTreeViewer.refresh();
                for (RemoteImportProfileElement profile : profiles) {
                    fTreeViewer.expandToLevel(profile, AbstractTreeViewer.ALL_LEVELS);
                }
                fTreeViewer.setSelection(new StructuredSelection(profiles));
                validate();
            }
        }
    });
    fExportButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_ExportButton);
    fExportButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = TmfFileDialogFactory.create(Display.getCurrent().getActiveShell(), SWT.SAVE);
            dialog.setText(RemoteMessages.RemoteProfilesPreferencePage_ExportFileDialogTitle);
            // $NON-NLS-1$ //$NON-NLS-2$
            dialog.setFilterExtensions(new String[] { "*.xml", "*" });
            String path = dialog.open();
            if (path != null) {
                IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
                List<RemoteImportProfileElement> profiles = new ArrayList<>();
                for (Object element : selection.toList()) {
                    if (element instanceof RemoteImportProfileElement) {
                        profiles.add((RemoteImportProfileElement) element);
                    }
                }
                writeProfiles(profiles, path);
            }
        }
    });
    new Label(composite, SWT.NONE);
    fMoveUpButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_MoveUpButton);
    fMoveUpButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
            Object element = selection.getFirstElement();
            if (element instanceof RemoteImportProfileElement) {
                int index = fProfiles.indexOf(element);
                if (index > 0) {
                    RemoteImportProfileElement profile = fProfiles.remove(index);
                    fProfiles.add(index - 1, profile);
                    Object[] expanded = fTreeViewer.getExpandedElements();
                    fTreeViewer.refresh();
                    fTreeViewer.setExpandedElements(expanded);
                    enableButtons(selection);
                }
            } else if (element instanceof TracePackageElement) {
                TracePackageElement child = (TracePackageElement) element;
                TracePackageElement parentElement = child.getParent();
                int index = parentElement.indexOf(child);
                if (index > 0) {
                    parentElement.removeChild(child);
                    parentElement.addChild(index - 1, child);
                    Object[] expanded = fTreeViewer.getExpandedElements();
                    fTreeViewer.refresh(parentElement);
                    fTreeViewer.setExpandedElements(expanded);
                    enableButtons(selection);
                }
            }
        }
    });
    fMoveDownButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_MoveDownButton);
    fMoveDownButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
            Object element = selection.getFirstElement();
            if (element instanceof RemoteImportProfileElement) {
                int index = fProfiles.indexOf(selection.getFirstElement());
                if (index >= 0 && index < fProfiles.size() - 1) {
                    RemoteImportProfileElement profile = fProfiles.remove(index);
                    fProfiles.add(index + 1, profile);
                    Object[] expanded = fTreeViewer.getExpandedElements();
                    fTreeViewer.refresh();
                    fTreeViewer.setExpandedElements(expanded);
                    enableButtons(selection);
                }
            } else if (element instanceof TracePackageElement) {
                TracePackageElement child = (TracePackageElement) element;
                TracePackageElement parentElement = child.getParent();
                int index = parentElement.indexOf(child);
                if (index >= 0 && index < parentElement.getChildren().length - 1) {
                    parentElement.removeChild(child);
                    parentElement.addChild(index + 1, child);
                    Object[] expanded = fTreeViewer.getExpandedElements();
                    fTreeViewer.refresh(parentElement);
                    fTreeViewer.setExpandedElements(expanded);
                    enableButtons(selection);
                }
            }
        }
    });
    return composite;
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) List(java.util.List) ArrayList(java.util.ArrayList) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 8 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement 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 9 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class ExportTracePackageWizardPage method finish.

/**
 * Finish the wizard page
 *
 * @return true on success
 */
public boolean finish() {
    if (!checkForOverwrite()) {
        return false;
    }
    saveWidgetValues();
    TracePackageTraceElement[] traceExportElements = (TracePackageTraceElement[]) getElementViewer().getInput();
    boolean useCompression = fCompressContentsCheckbox.getSelection();
    boolean useTar = fTargzFormatButton.getSelection();
    String fileName = getFilePathValue();
    final TracePackageExportOperation exporter = new TracePackageExportOperation(traceExportElements, useCompression, useTar, fileName);
    try {
        getContainer().run(true, true, exporter::run);
        IStatus status = exporter.getStatus();
        if (status.getSeverity() == IStatus.ERROR) {
            handleErrorStatus(status);
        }
    } catch (InvocationTargetException e) {
        handleError(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return exporter.getStatus().getSeverity() == IStatus.OK;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class ImportTracePackageWizardPage method checkForConflict.

private boolean checkForConflict() {
    TracePackageElement[] packageElements = (TracePackageElement[]) getElementViewer().getInput();
    List<TracePackageExperimentElement> experimentElements = new ArrayList<>();
    List<TracePackageTraceElement> traceElements = new ArrayList<>();
    Map<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentTracesMap = new HashMap<>();
    // List of experiment to rename
    List<TracePackageExperimentElement> experimentToRename = new ArrayList<>();
    // Conflict traces that are not in an experiment
    List<TracePackageTraceElement> unhandledTraces = new ArrayList<>();
    // Process package element to separate experiments and traces
    for (TracePackageElement packageElement : packageElements) {
        TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
        if (AbstractTracePackageOperation.isFilesChecked(traceElement)) {
            if (traceElement instanceof TracePackageExperimentElement) {
                TracePackageExperimentElement experimentElement = (TracePackageExperimentElement) traceElement;
                experimentElements.add(experimentElement);
                if (experimentExists(experimentElement)) {
                    experimentToRename.add(experimentElement);
                }
            } else {
                traceElements.add(traceElement);
            }
        }
    }
    for (TracePackageTraceElement traceElement : traceElements) {
        processTrace(experimentElements, traceElement, experimentTracesMap, unhandledTraces);
    }
    boolean result = true;
    if (!experimentTracesMap.isEmpty() || !experimentToRename.isEmpty()) {
        result &= handleExperimentConflict(experimentTracesMap, experimentToRename);
    }
    if (!unhandledTraces.isEmpty()) {
        result &= handleTracesConflict(unhandledTraces);
    }
    return result;
}
Also used : TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) ArrayList(java.util.ArrayList) List(java.util.List) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Aggregations

TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)32 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)23 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)22 RemoteImportConnectionNodeElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement)9 RemoteImportTraceGroupElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)9 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)9 ArrayList (java.util.ArrayList)8 RemoteImportProfileElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)8 Element (org.w3c.dom.Element)7 IPath (org.eclipse.core.runtime.IPath)6 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)6 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)6 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)6 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)6 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)6 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)6 Path (org.eclipse.core.runtime.Path)4 Node (org.w3c.dom.Node)4 URI (java.net.URI)3 HashMap (java.util.HashMap)3