Search in sources :

Example 16 with TmfCommonProjectElement

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

the class TracePackageImportOperation method deleteExistingTraces.

private IStatus deleteExistingTraces(IProgressMonitor progressMonitor) {
    for (TracePackageElement packageElement : fImportTraceElements) {
        TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
        if (!isFilesChecked(traceElement)) {
            continue;
        }
        TmfCommonProjectElement projectElement = getMatchingProjectElement(traceElement);
        try {
            if (projectElement instanceof TmfExperimentElement) {
                Display.getDefault().syncExec(() -> projectElement.closeEditors());
                projectElement.deleteSupplementaryFolder();
                projectElement.getResource().delete(true, SubMonitor.convert(progressMonitor));
            } else if (projectElement instanceof TmfTraceElement) {
                ((TmfTraceElement) projectElement).delete(SubMonitor.convert(progressMonitor), true);
            }
        } catch (CoreException e) {
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e);
        }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)

Example 17 with TmfCommonProjectElement

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

the class XMLAnalysesManagerPreferencePage method deleteAnalyses.

/**
 * Delete analyses, remove the corresponding files, and close the editors, if
 * opened.
 */
private void deleteAnalyses() {
    // Get list of files
    TableItem[] selection = fAnalysesTable.getSelection();
    List<String> filesToDeleteList = Lists.newArrayList();
    for (TableItem item : selection) {
        filesToDeleteList.add(ELEMENT_SEP + item.getText());
    }
    final String filesToDelete = Joiner.on(LINE_SEP).join(filesToDeleteList);
    boolean confirm = MessageDialog.openQuestion(getShell(), Messages.ManageXMLAnalysisDialog_DeleteFile, Messages.ManageXMLAnalysisDialog_DeleteConfirmation + StringUtils.repeat(LINE_SEP, 2) + filesToDelete);
    if (confirm) {
        Set<IEditorReference> editorReferences = getEditorReferences();
        Collection<String> toDeleteSupFiles = Lists.newArrayList();
        Collection<String> toDeleteFiles = Lists.newArrayList();
        for (TableItem item : selection) {
            String itemTitle = XmlUtils.createXmlFileString(item.getText());
            // If opened, close the editor before deleting the file
            editorReferences.forEach(editorReference -> {
                if (editorReference.getTitle().equals(itemTitle)) {
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editorReference.getEditor(false), false);
                }
            });
            // disabled
            if (XmlUtils.isAnalysisEnabled(itemTitle)) {
                toDeleteSupFiles.add(itemTitle);
            }
            toDeleteFiles.add(itemTitle);
        }
        Collection<TmfCommonProjectElement> elements = deleteSupplementaryFiles(toDeleteSupFiles);
        XmlUtils.deleteFiles(toDeleteFiles);
        fillAnalysesTable();
        handleSelection(fAnalysesTable.getSelection());
        XmlAnalysisModuleSource.notifyModuleChange();
        refreshProject(elements);
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) TableItem(org.eclipse.swt.widgets.TableItem) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)

Example 18 with TmfCommonProjectElement

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

the class SelectTraceTypeHandler method isEnabled.

// ------------------------------------------------------------------------
// Validation
// ------------------------------------------------------------------------
@Override
public boolean isEnabled() {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    ISelection selection = selectionProvider.getSelection();
    // Make sure selection contains only traces
    fSelection = null;
    if (selection instanceof TreeSelection) {
        fSelection = (TreeSelection) selection;
        Iterator<Object> iterator = fSelection.iterator();
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (!(element instanceof TmfCommonProjectElement)) {
                return false;
            }
        }
    }
    // If we get here, either nothing is selected or everything is a trace
    return !selection.isEmpty();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)

Example 19 with TmfCommonProjectElement

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

the class SelectSupplementaryResourcesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    Group contextGroup = new Group(composite, SWT.SHADOW_NONE);
    contextGroup.setText(Messages.SelectSpplementaryResources_ResourcesGroupTitle);
    contextGroup.setLayout(new GridLayout(2, false));
    contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    fTreeViewer = new CheckboxTreeViewer(contextGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    Tree tree = fTreeViewer.getTree();
    tree.setLayoutData(data);
    fTreeViewer.setContentProvider(new ITreeContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // Do nothing
        }

        @Override
        public void dispose() {
        // Do nothing
        }

        @Override
        public boolean hasChildren(Object element) {
            return element instanceof TmfCommonProjectElement;
        }

        @Override
        public Object getParent(Object element) {
            if (element instanceof IResource) {
                getParentElement((IResource) element);
            }
            return null;
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Object[]) {
                return (Object[]) inputElement;
            }
            return null;
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof TmfCommonProjectElement) {
                return fResourceMap.get((TmfCommonProjectElement) parentElement).toArray();
            }
            return null;
        }
    });
    fTreeViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IResource) {
                IResource resource = (IResource) element;
                TmfCommonProjectElement projectElement = getParentElement(resource);
                // remove .tracing/<supplementary folder> segments
                IPath suppFolderPath = projectElement.getTraceSupplementaryFolder(projectElement.getElementPath()).getFullPath();
                return resource.getFullPath().removeFirstSegments(suppFolderPath.segmentCount()).toString();
            } else if (element instanceof TmfCommonProjectElement) {
                TmfCommonProjectElement projectElement = (TmfCommonProjectElement) element;
                return projectElement.getElementPath();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof IResource) {
                return RESOURCE_IMAGE;
            } else if (element instanceof TmfTraceElement) {
                return TRACE_IMAGE;
            } else if (element instanceof TmfExperimentElement) {
                return EXPERIMENT_IMAGE;
            }
            return null;
        }
    });
    fTreeViewer.setInput(fResourceMap.keySet().toArray());
    fTreeViewer.expandAll();
    setAllChecked(true);
    fTreeViewer.addCheckStateListener(event -> {
        if (event.getElement() instanceof TmfCommonProjectElement) {
            fTreeViewer.setSubtreeChecked(event.getElement(), event.getChecked());
            fTreeViewer.setGrayed(event.getElement(), false);
        } else if (event.getElement() instanceof IResource) {
            TmfCommonProjectElement projectElement = getParentElement((IResource) event.getElement());
            int checkedCount = 0;
            Collection<IResource> resources = fResourceMap.get(projectElement);
            for (IResource resource : resources) {
                if (fTreeViewer.getChecked(resource)) {
                    checkedCount++;
                }
            }
            if (checkedCount == resources.size()) {
                fTreeViewer.setChecked(projectElement, true);
                fTreeViewer.setGrayed(projectElement, false);
            } else if (checkedCount > 0) {
                fTreeViewer.setGrayChecked(projectElement, true);
            } else {
                fTreeViewer.setGrayChecked(projectElement, false);
            }
        }
    });
    fTreeViewer.addSelectionChangedListener(event -> updateOKButtonEnablement());
    Composite btComp = new Composite(contextGroup, SWT.NONE);
    FillLayout layout = new FillLayout(SWT.VERTICAL);
    layout.spacing = 4;
    btComp.setLayout(layout);
    GridData gd = new GridData();
    gd.verticalAlignment = SWT.CENTER;
    btComp.setLayoutData(gd);
    final Button selectAll = new Button(btComp, SWT.PUSH);
    selectAll.setText(Messages.Dialog_SelectAll);
    selectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setAllChecked(true);
            updateOKButtonEnablement();
        }
    });
    final Button deselectAll = new Button(btComp, SWT.PUSH);
    deselectAll.setText(Messages.Dialog_DeselectAll);
    deselectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setAllChecked(false);
            updateOKButtonEnablement();
        }
    });
    getShell().setMinimumSize(new Point(300, 150));
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IResource(org.eclipse.core.resources.IResource)

Example 20 with TmfCommonProjectElement

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

the class RcpCliParser method openTraceIfNecessary.

private static WaitAllTracesOpened openTraceIfNecessary(IProject project, List<Path> tracePaths, Collection<TmfCommonProjectElement> existingTraces, IProgressMonitor monitor) {
    WaitAllTracesOpened waitService = new WaitAllTracesOpened(tracePaths, existingTraces);
    if (!existingTraces.isEmpty()) {
        Display.getDefault().asyncExec(() -> {
            for (TmfCommonProjectElement existingTrace : existingTraces) {
                if (monitor.isCanceled()) {
                    return;
                }
                try {
                    IStatus status = TmfOpenTraceHelper.openFromElement(existingTrace);
                    if (!status.isOK() || (status.getCode() != IStatus.OK)) {
                        waitService.registerStatus(new Path(existingTrace.getLocation().getPath()), status);
                    }
                } catch (Exception e) {
                    // Some other exception occurred, the trace will likely
                    // never be opened, catch the exception and send to
                    // waitService
                    waitService.registerException(new Path(existingTrace.getLocation().getPath()), e);
                }
            }
        });
    }
    if (tracePaths.isEmpty()) {
        return waitService;
    }
    TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
    if (!tracePaths.isEmpty()) {
        Display.getDefault().asyncExec(() -> {
            for (Path tracePath : tracePaths) {
                if (monitor.isCanceled()) {
                    return;
                }
                try {
                    IStatus status = TmfOpenTraceHelper.openTraceFromPath(destinationFolder, tracePath.toOSString(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
                    if (!status.isOK() || (status.getCode() != IStatus.OK)) {
                        waitService.registerStatus(tracePath, status);
                    }
                } catch (CoreException e) {
                    waitService.registerException(tracePath, e);
                }
            }
        });
    }
    return waitService;
}
Also used : Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) CoreException(org.eclipse.core.runtime.CoreException)

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