Search in sources :

Example 1 with TracePattern

use of org.erlide.tracing.core.mvc.model.TracePattern in project erlide_eclipse by erlang.

the class CreateTracePatternWithNoArityHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
    if (selection instanceof ITreeSelection) {
        final Object firstElement = ((ITreeSelection) selection).getFirstElement();
        if (firstElement instanceof IErlFunction) {
            final IErlFunction function = (IErlFunction) firstElement;
            final TracePattern tracePattern = new TracePattern(true);
            tracePattern.setFunctionName(function.getFunctionName());
            tracePattern.setModuleName(ErlangEngine.getInstance().getModelUtilService().getModule(function).getModuleName());
            tracePattern.setLocal(true);
            tracePattern.setEnabled(true);
            TraceBackend.getInstance().addTracePattern(tracePattern);
        }
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ISelection(org.eclipse.jface.viewers.ISelection) TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Example 2 with TracePattern

use of org.erlide.tracing.core.mvc.model.TracePattern in project erlide_eclipse by erlang.

the class RemoveTracePatternWithNoArityHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
    if (selection instanceof ITreeSelection) {
        final Object firstElement = ((ITreeSelection) selection).getFirstElement();
        if (firstElement instanceof IErlFunction) {
            final IErlFunction function = (IErlFunction) firstElement;
            final TracePattern tracePattern = new TracePattern(true);
            tracePattern.setFunctionName(function.getFunctionName());
            tracePattern.setModuleName(ErlangEngine.getInstance().getModelUtilService().getModule(function).getModuleName());
            TraceBackend.getInstance().removeTracePattern(tracePattern);
        }
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ISelection(org.eclipse.jface.viewers.ISelection) TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Example 3 with TracePattern

use of org.erlide.tracing.core.mvc.model.TracePattern in project erlide_eclipse by erlang.

the class TracePatternCellModifier method modify.

@Override
public void modify(final Object element, final String property, final Object value) {
    final TracePattern pattern = (TracePattern) ((TableItem) element).getData();
    switch(TracePatternColumn.valueOf(property)) {
        case ENABLED:
            pattern.setEnabled((Boolean) value);
            break;
        case MODULE_NAME:
            pattern.setModuleName((String) value);
            break;
        case FUNCTION_NAME:
            pattern.setFunctionName((String) value);
            break;
        case LOCAL:
            pattern.setLocal((Boolean) value);
            break;
        case ARITY:
            if (value == null || "".equals(value)) {
                pattern.setArity(-1);
            } else {
                try {
                    final Integer arity = Integer.valueOf((String) value);
                    if (arity >= 0) {
                        pattern.setArity(arity);
                    }
                } catch (final NumberFormatException e) {
                }
            }
            break;
        case MATCH_SPEC:
            pattern.setMatchSpec((MatchSpec) value);
            break;
        default:
    }
    tableViewer.refresh();
}
Also used : TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Example 4 with TracePattern

use of org.erlide.tracing.core.mvc.model.TracePattern in project erlide_eclipse by erlang.

the class ControlPanelView method createPatternButtonsPanel.

private void createPatternButtonsPanel(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new RowLayout());
    // "Add" button
    Button button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("New pattern");
    button.setToolTipText("Add new trace pattern");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            TraceBackend.getInstance().addTracePattern(new TracePattern(true));
        }
    });
    // "Remove" button
    button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("Remove pattern");
    button.setToolTipText("Remove selected trace pattern");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TracePattern tracePattern = (TracePattern) ((IStructuredSelection) functionsTableViewer.getSelection()).getFirstElement();
            if (tracePattern != null) {
                TraceBackend.getInstance().removeTracePattern(tracePattern);
            }
        }
    });
    // Pattern config buttons
    final Button loadConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button deleteConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveAsConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Label configNameLabel = new Label(container, SWT.NULL);
    configNameLabel.setLayoutData(new RowData(120, SWT.DEFAULT));
    // "Load patterns" button
    loadConfigButton.setToolTipText("Load pattern set...");
    loadConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
    loadConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final ElementListSelectionDialog dialog = new SelectConfigurationDialog(parent.getShell(), new LabelProvider());
            dialog.setElements(ConfigurationManager.getTPConfigs());
            dialog.open();
            final String result = (String) dialog.getFirstResult();
            if (result != null) {
                patternsConfigName = result;
                configNameLabel.setText(patternsConfigName);
                TraceBackend.getInstance().loadTracePatterns(ConfigurationManager.loadTPConfig(patternsConfigName));
            }
        }
    });
    // "Delete patterns" button
    deleteConfigButton.setToolTipText("Delete current pattern set...");
    deleteConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_REMOVE));
    deleteConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (patternsConfigName != null) {
                final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                messageBox.setMessage("Delete \"" + patternsConfigName + "\"?");
                messageBox.setText("Delete configuration");
                if (messageBox.open() == SWT.YES) {
                    ConfigurationManager.removeTPConfig(patternsConfigName);
                    patternsConfigName = null;
                    configNameLabel.setText("");
                }
            }
        }
    });
    // "Save patterns" button
    saveConfigButton.setToolTipText("Save current pattern set");
    saveConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVE_EDIT));
    saveConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (patternsConfigName != null) {
                if (!ConfigurationManager.saveTPConfig(patternsConfigName)) {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + patternsConfigName);
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
    // "Save patterns as..." button
    saveAsConfigButton.setToolTipText("Save current pattern set as...");
    saveAsConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVEAS_EDIT));
    saveAsConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final String[] configurations = ConfigurationManager.getTPConfigs();
            final Set<String> existingNames = new HashSet<>(Arrays.asList(configurations));
            final InputDialog dialog = new ConfigurationSaveAsDialog(parent.getShell(), "Save trace pattern configuration", "Enter name for configuration:", patternsConfigName, existingNames);
            if (dialog.open() == Window.OK) {
                if (ConfigurationManager.saveTPConfig(dialog.getValue())) {
                    patternsConfigName = dialog.getValue();
                    configNameLabel.setText(patternsConfigName);
                } else {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + dialog.getValue());
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectConfigurationDialog(org.erlide.tracing.core.ui.dialogs.SelectConfigurationDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ConfigurationSaveAsDialog(org.erlide.tracing.core.ui.dialogs.ConfigurationSaveAsDialog) NodeLabelProvider(org.erlide.tracing.core.mvc.view.NodeLabelProvider) TracePatternLabelProvider(org.erlide.tracing.core.mvc.view.TracePatternLabelProvider) ProcessLabelProvider(org.erlide.tracing.core.mvc.view.ProcessLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Example 5 with TracePattern

use of org.erlide.tracing.core.mvc.model.TracePattern in project erlide_eclipse by erlang.

the class CreateTracePatternHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
    if (selection instanceof ITreeSelection) {
        final Object firstElement = ((ITreeSelection) selection).getFirstElement();
        if (firstElement instanceof IErlFunction) {
            final IErlFunction function = (IErlFunction) firstElement;
            final TracePattern tracePattern = new TracePattern(true);
            tracePattern.setFunctionName(function.getFunctionName());
            tracePattern.setModuleName(ErlangEngine.getInstance().getModelUtilService().getModule(function).getModuleName());
            tracePattern.setArity(function.getArity());
            tracePattern.setLocal(true);
            tracePattern.setEnabled(true);
            TraceBackend.getInstance().addTracePattern(tracePattern);
        }
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ISelection(org.eclipse.jface.viewers.ISelection) TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Aggregations

TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)6 ISelection (org.eclipse.jface.viewers.ISelection)4 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)4 HashSet (java.util.HashSet)1 Set (java.util.Set)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 ElementListSelectionDialog (org.eclipse.ui.dialogs.ElementListSelectionDialog)1 NodeLabelProvider (org.erlide.tracing.core.mvc.view.NodeLabelProvider)1 ProcessLabelProvider (org.erlide.tracing.core.mvc.view.ProcessLabelProvider)1