Search in sources :

Example 1 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class TmfFilterContentHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    ITmfFilterTreeNode node = null;
    if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {
        node = new TmfFilterRootNode();
    } else if (localName.equals(TmfFilterNode.NODE_NAME)) {
        node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
        traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
        ((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
        TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
        if (helper != null) {
            ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
        }
        ((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
        node = new TmfFilterAndNode(null);
    } else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {
        node = new TmfFilterOrNode(null);
    } else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {
        node = new TmfFilterContainsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterContainsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {
        node = new TmfFilterEqualsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterEqualsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {
        node = new TmfFilterMatchesNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        ((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));
    } else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {
        node = new TmfFilterCompareNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);
        if (value != null) {
            ((TmfFilterCompareNode) node).setType(Type.valueOf(value));
        }
        value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);
        if (value != null) {
            if (value.equals(Integer.toString(-1))) {
                ((TmfFilterCompareNode) node).setResult(-1);
            } else if (value.equals(Integer.toString(1))) {
                ((TmfFilterCompareNode) node).setResult(1);
            } else {
                ((TmfFilterCompareNode) node).setResult(0);
            }
        }
    // Backward compatibility with event type filter node
    } else if (localName.equals(EVENTTYPE_NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String label = atts.getValue(NAME_ATTR);
        if (label != null) {
            // Backward compatibility with renamed LTTng Kernel Trace
            if (label.equals(LTTNG_KERNEL_TRACE)) {
                label = LINUX_KERNEL_TRACE;
            }
            String traceTypeId = TmfTraceType.getTraceTypeId(label);
            TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
            if (helper == null) {
                // Backward compatibility with category-less custom trace types
                for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
                    if (h.getName().equals(label)) {
                        label = h.getLabel();
                        helper = h;
                        break;
                    }
                }
            }
            if (helper != null) {
                ((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
                ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
            }
            ((TmfFilterTraceTypeNode) node).setName(label);
        }
    }
    String value = atts.getValue(ITmfFilterWithNot.NOT_ATTRIBUTE);
    if (node instanceof ITmfFilterWithNot && Boolean.TRUE.toString().equalsIgnoreCase(value)) {
        ((ITmfFilterWithNot) node).setNot(true);
    }
    if (node instanceof ITmfFilterWithValue) {
        ((ITmfFilterWithValue) node).setValue(atts.getValue(ITmfFilterWithValue.VALUE_ATTRIBUTE));
    }
    fFilterTreeStack.addFirst(node);
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) ITmfFilterWithValue(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue) TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAspectNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAspectNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode) ITmfFilterWithNot(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot)

Example 2 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class TmfEventsTable method createPopupMenu.

// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
/**
 * Create a pop-up menu.
 */
private void createPopupMenu() {
    final IAction copyAction = new Action(Messages.TmfEventsTable_CopyToClipboardActionText) {

        @Override
        public void run() {
            ITmfTrace trace = fTrace;
            if (trace == null || (fSelectedRank == -1 && fSelectedBeginRank == -1)) {
                return;
            }
            List<TmfEventTableColumn> columns = new ArrayList<>();
            for (int i : fTable.getColumnOrder()) {
                TableColumn column = fTable.getColumns()[i];
                // Omit the margin column and hidden columns
                if (isVisibleEventColumn(column)) {
                    columns.add(fColumns.get(i));
                }
            }
            long start = Math.min(fSelectedBeginRank, fSelectedRank);
            long end = Math.max(fSelectedBeginRank, fSelectedRank);
            final ITmfFilter filter = (ITmfFilter) fTable.getData(Key.FILTER_OBJ);
            IRunnableWithProgress operation = new CopyToClipboardOperation(trace, filter, columns, start, end);
            try {
                PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation);
            } catch (InvocationTargetException e) {
                // $NON-NLS-1$
                Activator.getDefault().logError("Invocation target exception copying to clipboard ", e);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    };
    final IAction showTableAction = new Action(Messages.TmfEventsTable_ShowTableActionText) {

        @Override
        public void run() {
            fTableComposite.setVisible(true);
            fSashForm.layout();
        }
    };
    final IAction hideTableAction = new Action(Messages.TmfEventsTable_HideTableActionText) {

        @Override
        public void run() {
            fTableComposite.setVisible(false);
            fSashForm.layout();
        }
    };
    final IAction showRawAction = new Action(Messages.TmfEventsTable_ShowRawActionText) {

        @Override
        public void run() {
            fRawViewer.setVisible(true);
            fSashForm.layout();
            final int index = fTable.getSelectionIndex();
            if (index >= 1) {
                fRawViewer.selectAndReveal(index - 1);
            }
        }
    };
    final IAction hideRawAction = new Action(Messages.TmfEventsTable_HideRawActionText) {

        @Override
        public void run() {
            fRawViewer.setVisible(false);
            fSashForm.layout();
        }
    };
    final IAction openModelAction = new Action(Messages.TmfEventsTable_OpenModelActionText) {

        @Override
        public void run() {
            final TableItem[] items = fTable.getSelection();
            if (items.length != 1) {
                return;
            }
            final TableItem item = items[0];
            final Object eventData = item.getData();
            if (eventData instanceof ITmfModelLookup) {
                String modelURI = ((ITmfModelLookup) eventData).getModelUri();
                if (modelURI != null) {
                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    IFile file = null;
                    final URI uri = URI.createURI(modelURI);
                    if (uri.isPlatformResource()) {
                        IPath path = new Path(uri.toPlatformString(true));
                        file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
                    } else if (uri.isFile() && !uri.isRelative()) {
                        file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(uri.toFileString()));
                    }
                    if (file != null) {
                        try {
                            /*
                                 * create a temporary validation marker on the
                                 * model file, remove it afterwards thus,
                                 * navigation works with all model editors
                                 * supporting the navigation to a marker
                                 */
                            IMarker marker = file.createMarker(EValidator.MARKER);
                            marker.setAttribute(EValidator.URI_ATTRIBUTE, modelURI);
                            marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
                            IDE.openEditor(activePage, marker, OpenStrategy.activateOnOpen());
                            marker.delete();
                        } catch (CoreException e) {
                            TraceUtils.displayErrorMsg(e);
                        }
                    } else {
                        final Exception e = new FileNotFoundException('\'' + modelURI + '\'' + '\n' + Messages.TmfEventsTable_OpenModelUnsupportedURI);
                        TraceUtils.displayErrorMsg(e);
                    }
                }
            }
        }
    };
    final IAction exportToTextAction = new Action(Messages.TmfEventsTable_Export_to_text) {

        @Override
        public void run() {
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            Object handlerServiceObject = activePage.getActiveEditor().getSite().getService(IHandlerService.class);
            IHandlerService handlerService = (IHandlerService) handlerServiceObject;
            Object cmdServiceObject = activePage.getActiveEditor().getSite().getService(ICommandService.class);
            ICommandService cmdService = (ICommandService) cmdServiceObject;
            try {
                HashMap<String, Object> parameters = new HashMap<>();
                Command command = cmdService.getCommand(ExportToTextCommandHandler.COMMAND_ID);
                ParameterizedCommand cmd = ParameterizedCommand.generateCommand(command, parameters);
                IEvaluationContext context = handlerService.getCurrentState();
                List<TmfEventTableColumn> exportColumns = new ArrayList<>();
                for (int i : fTable.getColumnOrder()) {
                    TableColumn column = fTable.getColumns()[i];
                    // Omit the margin column and hidden columns
                    if (isVisibleEventColumn(column)) {
                        exportColumns.add(fColumns.get(i));
                    }
                }
                context.addVariable(ExportToTextCommandHandler.TMF_EVENT_TABLE_COLUMNS_ID, exportColumns);
                handlerService.executeCommandInContext(cmd, null, context);
            } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
                TraceUtils.displayErrorMsg(e);
            }
        }
    };
    final IAction addAsFilterAction = new Action(Messages.TmfEventsTable_AddAsFilterText) {

        @Override
        public void run() {
            applySearchAsFilter();
        }
    };
    final IAction clearFiltersAction = new Action(Messages.TmfEventsTable_ClearFiltersActionText) {

        @Override
        public void run() {
            clearFilters();
        }
    };
    final IAction collapseAction = new Action(Messages.TmfEventsTable_CollapseFilterMenuName) {

        @Override
        public void run() {
            applyFilter(new TmfCollapseFilter());
        }
    };
    final IAction synchronizeAction = new Action(Messages.TmfEventsTable_SynchronizeActionText, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            TmfTraceManager.getInstance().updateTraceContext(NonNullUtils.checkNotNull(fTrace), builder -> builder.setSynchronized(isChecked()));
        }
    };
    class ToggleBookmarkAction extends Action {

        Long fRank;

        public ToggleBookmarkAction(final String text, final Long rank) {
            super(text);
            fRank = rank;
        }

        @Override
        public void run() {
            toggleBookmark(fRank);
        }
    }
    fHeaderPopupMenuManager = new MenuManager();
    fHeaderPopupMenuManager.setRemoveAllWhenShown(true);
    fHeaderPopupMenuManager.addMenuListener(manager -> {
        final Point point = fTable.toControl(fLastMenuCursorLocation);
        TableColumn selectedColumn = fTable.getColumn(point);
        if (selectedColumn != null && selectedColumn.getResizable()) {
            fHeaderPopupMenuManager.add(createAutoFitAction(selectedColumn));
            fHeaderPopupMenuManager.add(new Separator());
        }
        for (int index : fTable.getColumnOrder()) {
            TableColumn column = fTable.getColumns()[index];
            if (column.getData(Key.WIDTH) != null) {
                fHeaderPopupMenuManager.add(createShowColumnAction(column));
            }
        }
        fHeaderPopupMenuManager.add(new Separator());
        fHeaderPopupMenuManager.add(createShowAllAction());
        fHeaderPopupMenuManager.add(createResetAllAction());
    });
    fTablePopupMenuManager = new MenuManager();
    fTablePopupMenuManager.setRemoveAllWhenShown(true);
    fTablePopupMenuManager.addMenuListener(manager -> {
        if (fTable.getSelectionIndices().length == 1 && fTable.getSelectionIndices()[0] == 0) {
            // Right-click on header row
            if (fHeaderState == HeaderState.SEARCH) {
                fTablePopupMenuManager.add(addAsFilterAction);
            }
            return;
        }
        final Point point = fTable.toControl(fLastMenuCursorLocation);
        final TableItem item = fTable.getSelection().length > 0 ? fTable.getSelection()[0] : null;
        if (item != null) {
            final Rectangle imageBounds = item.getImageBounds(0);
            imageBounds.width = BOOKMARK_IMAGE.getBounds().width;
            if (point.x <= (imageBounds.x + imageBounds.width)) {
                // Right-click on left margin
                final Long rank = (Long) item.getData(Key.RANK);
                if ((rank != null) && (fBookmarksFile != null)) {
                    if (fBookmarksMap.containsKey(rank)) {
                        fTablePopupMenuManager.add(new ToggleBookmarkAction(Messages.TmfEventsTable_RemoveBookmarkActionText, rank));
                    } else {
                        fTablePopupMenuManager.add(new ToggleBookmarkAction(Messages.TmfEventsTable_AddBookmarkActionText, rank));
                    }
                }
                return;
            }
        }
        // Right-click on table
        if (fSelectedRank != -1 && fSelectedBeginRank != -1) {
            fTablePopupMenuManager.add(copyAction);
            fTablePopupMenuManager.add(new Separator());
        }
        if (fTable.isVisible() && fRawViewer.isVisible()) {
            fTablePopupMenuManager.add(hideTableAction);
            fTablePopupMenuManager.add(hideRawAction);
        } else if (!fTable.isVisible()) {
            fTablePopupMenuManager.add(showTableAction);
        } else if (!fRawViewer.isVisible()) {
            fTablePopupMenuManager.add(showRawAction);
        }
        fTablePopupMenuManager.add(exportToTextAction);
        fTablePopupMenuManager.add(new Separator());
        if (item != null) {
            final Object data = item.getData();
            Separator separator = null;
            if (data instanceof ITmfSourceLookup) {
                IContributionItem action = OpenSourceCodeAction.create(Messages.TmfSourceLookup_OpenSourceCodeActionText, (ITmfSourceLookup) data, fTable.getShell());
                if (action != null) {
                    fTablePopupMenuManager.add(action);
                    separator = new Separator();
                }
            }
            if (data instanceof ITmfModelLookup) {
                ITmfModelLookup event2 = (ITmfModelLookup) data;
                if (event2.getModelUri() != null) {
                    fTablePopupMenuManager.add(openModelAction);
                    separator = new Separator();
                }
                if (separator != null) {
                    fTablePopupMenuManager.add(separator);
                }
            }
        }
        /*
             * Only show collapse filter if at least one trace can be
             * collapsed.
             */
        boolean isCollapsible = false;
        if (fTrace != null) {
            for (ITmfTrace trace1 : TmfTraceManager.getTraceSet(fTrace)) {
                Class<? extends ITmfEvent> eventClass = trace1.getEventType();
                isCollapsible = ITmfCollapsibleEvent.class.isAssignableFrom(eventClass);
                if (isCollapsible) {
                    break;
                }
            }
        }
        if (isCollapsible && !fCollapseFilterEnabled) {
            fTablePopupMenuManager.add(collapseAction);
            fTablePopupMenuManager.add(new Separator());
        }
        fTablePopupMenuManager.add(clearFiltersAction);
        final ITmfFilterTreeNode[] savedFilters = FilterManager.getSavedFilters();
        if (savedFilters.length > 0) {
            final MenuManager subMenu = new MenuManager(Messages.TmfEventsTable_ApplyPresetFilterMenuName);
            for (final ITmfFilterTreeNode node : savedFilters) {
                if (node instanceof TmfFilterNode) {
                    final TmfFilterNode filter = (TmfFilterNode) node;
                    subMenu.add(new Action(filter.getFilterName()) {

                        @Override
                        public void run() {
                            applyFilter(filter);
                        }
                    });
                }
            }
            fTablePopupMenuManager.add(subMenu);
        }
        fTablePopupMenuManager.add(new Separator());
        ITmfTrace trace2 = fTrace;
        if (trace2 != null) {
            synchronizeAction.setChecked(TmfTraceManager.getInstance().getTraceContext(trace2).isSynchronized());
            fTablePopupMenuManager.add(synchronizeAction);
        }
        appendToTablePopupMenu(fTablePopupMenuManager, item);
    });
    fRawViewerPopupMenuManager = new MenuManager();
    fRawViewerPopupMenuManager.setRemoveAllWhenShown(true);
    fRawViewerPopupMenuManager.addMenuListener(manager -> {
        if (fTable.isVisible() && fRawViewer.isVisible()) {
            fRawViewerPopupMenuManager.add(hideTableAction);
            fRawViewerPopupMenuManager.add(hideRawAction);
        } else if (!fTable.isVisible()) {
            fRawViewerPopupMenuManager.add(showTableAction);
        } else if (!fRawViewer.isVisible()) {
            fRawViewerPopupMenuManager.add(showRawAction);
        }
        appendToRawPopupMenu(fRawViewerPopupMenuManager);
    });
    fHeaderMenu = fHeaderPopupMenuManager.createContextMenu(fTable);
    fTablePopup = fTablePopupMenuManager.createContextMenu(fTable);
    fTable.setMenu(fTablePopup);
    fRawTablePopup = fRawViewerPopupMenuManager.createContextMenu(fRawViewer);
    fRawViewer.setMenu(fRawTablePopup);
}
Also used : HashMap(java.util.HashMap) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Rectangle(org.eclipse.swt.graphics.Rectangle) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ICommandService(org.eclipse.ui.commands.ICommandService) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) NotHandledException(org.eclipse.core.commands.NotHandledException) IPath(org.eclipse.core.runtime.IPath) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) TmfEventTableColumn(org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn) TmfEventTableColumn(org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn) TableColumn(org.eclipse.swt.widgets.TableColumn) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) IHandlerService(org.eclipse.ui.handlers.IHandlerService) MenuManager(org.eclipse.jface.action.MenuManager) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) OpenSourceCodeAction(org.eclipse.tracecompass.tmf.ui.actions.OpenSourceCodeAction) IFile(org.eclipse.core.resources.IFile) URI(org.eclipse.emf.common.util.URI) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ExecutionException(org.eclipse.core.commands.ExecutionException) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ITmfModelLookup(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup) IAction(org.eclipse.jface.action.IAction) IContributionItem(org.eclipse.jface.action.IContributionItem) ITmfSourceLookup(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup) Point(org.eclipse.swt.graphics.Point) NotEnabledException(org.eclipse.core.commands.NotEnabledException) Point(org.eclipse.swt.graphics.Point) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ExecutionException(org.eclipse.core.commands.ExecutionException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) NotHandledException(org.eclipse.core.commands.NotHandledException) TmfCollapseFilter(org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) ITmfCollapsibleEvent(org.eclipse.tracecompass.tmf.core.event.collapse.ITmfCollapsibleEvent) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) CopyToClipboardOperation(org.eclipse.tracecompass.internal.tmf.ui.commands.CopyToClipboardOperation) IMarker(org.eclipse.core.resources.IMarker) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Separator(org.eclipse.jface.action.Separator)

Example 3 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class FilterTreeLabelProvider method getText.

@Override
public String getText(Object element) {
    StringBuilder label = new StringBuilder();
    if (element instanceof TmfFilterNode) {
        TmfFilterNode node = (TmfFilterNode) element;
        label.append(node.getNodeName()).append(' ').append(node.getFilterName() != null && !node.getFilterName().isEmpty() ? node.getFilterName() : Messages.FilterTreeLabelProvider_FilterNameHint);
    } else if (element instanceof TmfFilterTraceTypeNode) {
        TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) element;
        // $NON-NLS-1$
        label.append(node.isNot() ? NOT : EMPTY_STRING).append("WITH ").append(node.getNodeName()).append(' ').append((node.getName() != null ? node.getName() : Messages.FilterTreeLabelProvider_TraceTypeHint));
    } else if (element instanceof TmfFilterAndNode) {
        TmfFilterAndNode node = (TmfFilterAndNode) element;
        label.append((node.isNot() ? NOT : EMPTY_STRING)).append(node.getNodeName());
    } else if (element instanceof TmfFilterOrNode) {
        TmfFilterOrNode node = (TmfFilterOrNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getNodeName());
    } else if (element instanceof TmfFilterContainsNode) {
        TmfFilterContainsNode node = (TmfFilterContainsNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getValue() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getValue()).append(QUOTE).toString() : EMPTY_STRING);
    } else if (element instanceof TmfFilterEqualsNode) {
        TmfFilterEqualsNode node = (TmfFilterEqualsNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getValue() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getValue()).append(QUOTE).toString() : EMPTY_STRING);
    } else if (element instanceof TmfFilterMatchesNode) {
        TmfFilterMatchesNode node = (TmfFilterMatchesNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getRegex() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getRegex()).append(QUOTE).toString() : EMPTY_STRING);
    } else if (element instanceof TmfFilterCompareNode) {
        TmfFilterCompareNode node = (TmfFilterCompareNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        node.getResult() < 0 ? " <" : (node.getResult() > 0 ? " >" : " =")).append(// $NON-NLS-1$
        node.getType() == Type.ALPHA ? SPACE_QUOTE : node.getType() == Type.TIMESTAMP ? " [" : ' ').append(node.hasValidValue() ? node.getValue() : Messages.FilterTreeLabelProvider_ValueHint).append(node.getType() == Type.ALPHA ? '\"' : node.getType() == Type.TIMESTAMP ? ']' : EMPTY_STRING);
    }
    return label.toString();
}
Also used : TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)

Example 4 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class FilterViewer method fillContextMenuForNode.

/**
 * Fill the context menu with the valid children of the provided node
 *
 * @param node
 *            The target node
 * @param manager
 *            The menu manager
 */
protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) {
    for (final String child : node.getValidChildren()) {
        final Action action = new Action() {

            @Override
            public void run() {
                ITmfFilterTreeNode newNode = null;
                if (TmfFilterNode.NODE_NAME.equals(child)) {
                    // $NON-NLS-1$
                    newNode = new TmfFilterNode(node, "");
                } else if (TmfFilterTraceTypeNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterTraceTypeNode(node);
                } else if (TmfFilterAndNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterAndNode(node);
                } else if (TmfFilterOrNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterOrNode(node);
                } else if (TmfFilterContainsNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterContainsNode(node);
                } else if (TmfFilterEqualsNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterEqualsNode(node);
                } else if (TmfFilterMatchesNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterMatchesNode(node);
                } else if (TmfFilterCompareNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterCompareNode(node);
                }
                if (newNode != null) {
                    fViewer.refresh();
                    fViewer.setSelection(new StructuredSelection(newNode), true);
                }
            }
        };
        if (TmfFilterNode.NODE_NAME.equals(child)) {
            // $NON-NLS-1$
            action.setText(Messages.FilterViewer_NewPrefix + " " + child);
        } else {
            action.setText(child);
        }
        manager.add(action);
    }
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) Action(org.eclipse.jface.action.Action) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)

Example 5 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class TmfFilterNodeTest method createFilter.

// ------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------
@Before
public void createFilter() {
    fFilter = new TmfFilterNode(null, FILTER);
    fFilterNode = fFilter;
}
Also used : TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) Before(org.junit.Before)

Aggregations

TmfFilterNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)9 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)5 TmfFilterContainsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode)5 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)5 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)4 TmfFilterCompareNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)4 TmfFilterEqualsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode)4 TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)4 TmfFilterTraceTypeNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode)4 HashMap (java.util.HashMap)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Action (org.eclipse.jface.action.Action)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1