Search in sources :

Example 1 with Styler

use of org.eclipse.jface.viewers.StyledString.Styler in project yamcs-studio by yamcs.

the class StackedCommand method toStyledString.

public StyledString toStyledString(CommandStackView styleProvider) {
    Styler identifierStyler = styleProvider != null ? styleProvider.getIdentifierStyler(this) : null;
    Styler bracketStyler = styleProvider != null ? styleProvider.getBracketStyler(this) : null;
    Styler argNameSyler = styleProvider != null ? styleProvider.getArgNameStyler(this) : null;
    Styler errorStyler = styleProvider != null ? styleProvider.getErrorStyler(this) : null;
    Styler numberStyler = styleProvider != null ? styleProvider.getNumberStyler(this) : null;
    StyledString str = new StyledString();
    str.append(getSelectedAlias(), identifierStyler);
    str.append("(", bracketStyler);
    boolean first = true;
    for (ArgumentInfo arg : meta.getArgumentList()) {
        String value = getAssignedStringValue(arg);
        if (value == null && arg.hasInitialValue())
            continue;
        if (!first)
            str.append("\n, ", bracketStyler);
        first = false;
        str.append(arg.getName() + ": ", argNameSyler);
        if (value == null) {
            str.append("  ", errorStyler);
        } else {
            boolean needQuotationMark = ArgumentTableBuilder.STRING.equals(arg.getType().getEngType()) || ArgumentTableBuilder.ENUM.equals(arg.getType().getEngType());
            if (needQuotationMark)
                str.append("\"", isValid(arg) ? numberStyler : errorStyler);
            str.append(value, isValid(arg) ? numberStyler : errorStyler);
            if (needQuotationMark)
                str.append("\"", isValid(arg) ? numberStyler : errorStyler);
        }
    }
    str.append(")", bracketStyler);
    return str;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Styler(org.eclipse.jface.viewers.StyledString.Styler) ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo)

Example 2 with Styler

use of org.eclipse.jface.viewers.StyledString.Styler in project eclipse-integration-commons by spring-projects.

the class Stylers method italicColoured.

public Styler italicColoured(int colorCode) {
    final Color color = getSystemColor(colorCode);
    return new Styler() {

        public void applyStyles(TextStyle textStyle) {
            textStyle.font = getItalicFont();
            textStyle.foreground = color;
        }
    };
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Color(org.eclipse.swt.graphics.Color) Styler(org.eclipse.jface.viewers.StyledString.Styler)

Example 3 with Styler

use of org.eclipse.jface.viewers.StyledString.Styler in project eclipse-integration-commons by spring-projects.

the class SwtConnect method boldMatchedElements.

/**
 * Decorate a basic LabelProvider so that it bolds matched elements based on a text-based filter applied to its labels.
 */
public static StyledCellLabelProvider boldMatchedElements(Stylers stylers, ILabelProvider baseLabels, Filter<String> filter) {
    return new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            // image
            cell.setImage(baseLabels.getImage(element));
            // styled label
            String label = baseLabels.getText(element);
            StyledString styledLabel = new StyledString(label);
            if (filter.accept(label)) {
                Styler bold = stylers.bold();
                for (IRegion r : filter.getHighlights(label)) {
                    styledLabel.setStyle(r.getOffset(), r.getLength(), bold);
                }
            }
            cell.setStyleRanges(styledLabel.getStyleRanges());
            cell.setText(styledLabel.getString());
            cell.getControl().redraw();
        // ^^^ Sigh... Yes, this is needed. It seems SWT/Jface isn't smart enough to itself figure out that if
        // the styleranges change a redraw is needed to make the change visible.
        }
    };
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Styler(org.eclipse.jface.viewers.StyledString.Styler) ViewerCell(org.eclipse.jface.viewers.ViewerCell) IRegion(org.eclipse.jface.text.IRegion)

Example 4 with Styler

use of org.eclipse.jface.viewers.StyledString.Styler in project webtools.sourceediting by eclipse.

the class JFaceNodeAdapterFactory method addStyler.

private void addStyler(String regionType) {
    String colorKey = ColorTypesHelper.getColor(regionType);
    if (getColorPreferences() != null) {
        String prefString = getColorPreferences().getString(colorKey);
        String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
        if (stylePrefs != null) {
            RGB foreground = ColorHelper.toRGB(stylePrefs[0]);
            RGB background = ColorHelper.toRGB(stylePrefs[1]);
            Styler styler = new RGBStyler(foreground, background);
            getStylers().put(regionType, styler);
        }
    }
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) RGB(org.eclipse.swt.graphics.RGB) Styler(org.eclipse.jface.viewers.StyledString.Styler)

Example 5 with Styler

use of org.eclipse.jface.viewers.StyledString.Styler in project yamcs-studio by yamcs.

the class CommandStackView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level0s.png"));
    level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level1s.png"));
    level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level2s.png"));
    level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level3s.png"));
    level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level4s.png"));
    level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level5s.png"));
    var gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.verticalSpacing = 1;
    parent.setLayout(gl);
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    errorBackgroundColor = resourceManager.createColor(new RGB(255, 221, 221));
    bracketStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
        }
    };
    argNameStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
        }
    };
    numberStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
        }
    };
    errorStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getTextFont();
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
            textStyle.underline = true;
            textStyle.underlineColor = Display.getDefault().getSystemColor(SWT.COLOR_RED);
            textStyle.underlineStyle = SWT.UNDERLINE_ERROR;
        }
    };
    issuedStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
        }
    };
    skippedStyler = new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
            textStyle.strikeout = true;
            textStyle.strikeoutColor = textStyle.foreground;
        }
    };
    var tableWrapper = new Composite(parent, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    var tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    commandTableViewer = new CommandStackTableViewer(tableWrapper, tcl, this);
    commandTableViewer.addDoubleClickListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            var cmd = (StackedCommand) sel.getFirstElement();
            if (cmd.getStackedState() != StackedState.ISSUED && cmd.getStackedState() != StackedState.SKIPPED) {
                var dialog = new EditStackedCommandDialog(parent.getShell(), cmd);
                if (dialog.open() == Window.OK) {
                    refreshState();
                }
            }
        }
    });
    var controls = new Composite(parent, SWT.NONE);
    var gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 30;
    controls.setLayoutData(gd);
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    controls.setLayout(gl);
    controls.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    bottomLeft = new Composite(controls, SWT.NONE);
    gd = new GridData(GridData.FILL_BOTH);
    gd.verticalAlignment = SWT.CENTER;
    bottomLeft.setLayoutData(gd);
    gl = new GridLayout(4, false);
    gl.marginWidth = 0;
    gl.marginHeight = 0;
    bottomLeft.setLayout(gl);
    clearanceLabel = new Label(bottomLeft, SWT.NONE);
    clearanceLabel.setVisible(false);
    clearanceImageLabel = new Label(bottomLeft, SWT.NONE);
    clearanceImageLabel.setVisible(false);
    clearanceSeparator = new Label(bottomLeft, SWT.SEPARATOR);
    gd = new GridData();
    gd.heightHint = 15;
    clearanceSeparator.setLayoutData(gd);
    clearanceSeparator.setVisible(false);
    messageLabel = new Label(bottomLeft, SWT.NONE);
    messageLabel.setText("");
    messageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    var bottomRight = new Composite(controls, SWT.NONE);
    gd = new GridData(GridData.FILL_BOTH);
    gd.verticalAlignment = SWT.CENTER;
    gd.horizontalAlignment = SWT.RIGHT;
    bottomRight.setLayoutData(gd);
    gl = new GridLayout(4, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    bottomRight.setLayout(gl);
    // Stack parameters (manual/auto stack)
    var stackParameters = new Composite(bottomRight, SWT.NONE);
    gl = new GridLayout(5, false);
    gl.marginHeight = 0;
    gl.marginWidth = 50;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    stackParameters.setLayout(gl);
    // Group stackTypeGroup = new Group(stackParameters, SWT.NONE);
    // stackTypeGroup.setLayout(new RowLayout(SWT.HORIZONTAL));
    stackModeLabel = new Label(stackParameters, SWT.NONE);
    stackModeLabel.setText("Stack mode: ");
    advanceModeCombo = new Combo(stackParameters, SWT.DROP_DOWN | SWT.READ_ONLY);
    var items = new String[] { "Manual", "Automatic" };
    advanceModeCombo.setItems(items);
    advanceModeCombo.select(0);
    autoOptionsCombo = new Combo(stackParameters, SWT.DROP_DOWN | SWT.READ_ONLY);
    var items2 = new String[] { "AFAP (no delay)", "Fixed Delay", "Stack Delay" };
    autoOptionsCombo.setItems(items2);
    autoOptionsCombo.select(0);
    autoOptionsCombo.setVisible(false);
    fixDelaySpinner = new Spinner(stackParameters, SWT.BORDER);
    fixDelaySpinner.setMinimum(0);
    fixDelaySpinner.setMaximum(Integer.MAX_VALUE);
    fixDelaySpinner.setSelection(200);
    fixDelaySpinner.setIncrement(1);
    fixDelaySpinner.setPageIncrement(100);
    fixDelaySpinner.setVisible(false);
    fixDelaySpinner.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        stack.fixDelayMs = fixDelaySpinner.getSelection();
    });
    var labelUnit = new Label(stackParameters, SWT.NONE);
    labelUnit.setText("ms");
    labelUnit.setVisible(false);
    advanceModeCombo.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        var index = advanceModeCombo.getSelectionIndex();
        if (index == StackMode.MANUAL.index()) {
            // Manual
            stack.stackMode = StackMode.MANUAL;
            autoOptionsCombo.setVisible(false);
            fixDelaySpinner.setVisible(false);
            labelUnit.setVisible(false);
            commandTableViewer.hideDelayColumn();
        } else {
            // Automatic
            stack.stackMode = StackMode.AUTOMATIC;
            autoOptionsCombo.setVisible(true);
            if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
                // fix delay
                fixDelaySpinner.setVisible(true);
                labelUnit.setVisible(true);
                commandTableViewer.hideDelayColumn();
            } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
                // stack delays
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.showDelayColumn();
            } else {
                // afap
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.hideDelayColumn();
            }
        }
        // disarm the stack
        issueButton.setEnabled(false);
        armButton.setSelection(false);
        stack.disarmArmed();
        refreshState();
    });
    autoOptionsCombo.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        if (stack.stackMode == StackMode.AUTOMATIC) {
            if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
                // fix delay
                fixDelaySpinner.setVisible(true);
                labelUnit.setVisible(true);
                commandTableViewer.hideDelayColumn();
            } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
                // stack delay
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.showDelayColumn();
            } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.AFAP.index()) {
                // fix delay
                fixDelaySpinner.setVisible(false);
                labelUnit.setVisible(false);
                commandTableViewer.hideDelayColumn();
            }
        } else {
            // manual mode
            fixDelaySpinner.setVisible(false);
            labelUnit.setVisible(false);
            commandTableViewer.hideDelayColumn();
        }
        if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
            stack.autoMode = AutoMode.FIX_DELAY;
        } else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
            stack.autoMode = AutoMode.STACK_DELAYS;
        } else {
            stack.autoMode = AutoMode.AFAP;
        }
    });
    armButton = new Button(bottomRight, SWT.TOGGLE);
    armButton.setText("1. Arm");
    armButton.setToolTipText("Arm the selected command");
    armButton.setEnabled(false);
    armButton.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        if (armButton.getSelection()) {
            var commandService = getViewSite().getService(ICommandService.class);
            var evaluationService = getViewSite().getService(IEvaluationService.class);
            if (stack.stackMode == StackMode.AUTOMATIC) {
                // automatic stack, arm all commands
                var cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.armAll");
                try {
                    cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
                } catch (Exception e) {
                    log.log(Level.SEVERE, "Could not execute command", e);
                }
            } else {
                // manual stack, individual arm
                var cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.arm");
                try {
                    cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
                } catch (Exception e) {
                    log.log(Level.SEVERE, "Could not execute command", e);
                }
            }
        } else {
            if (stack.getActiveCommand() != null && stack.getActiveCommand().isArmed()) {
                stack.getActiveCommand().setStackedState(StackedState.DISARMED);
                clearArm();
                refreshState();
            }
        }
    });
    issueButton = new Button(bottomRight, SWT.NONE);
    issueButton.setText("2. Issue");
    issueButton.setToolTipText("Issue the selected command");
    issueButton.setEnabled(false);
    issueButton.addListener(SWT.Selection, evt -> {
        var stack = CommandStack.getInstance();
        var commandService = getViewSite().getService(ICommandService.class);
        var evaluationService = getViewSite().getService(IEvaluationService.class);
        org.eclipse.core.commands.Command cmd = null;
        if (stack.stackMode == StackMode.AUTOMATIC) {
            // automatic stack - issue all commands
            cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.issueAll");
        } else {
            // manual stack - issue one command
            cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.issue");
        }
        try {
            cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
        } catch (Exception e) {
            log.log(Level.SEVERE, "Could not execute command", e);
        }
    });
    commandTableViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        updateMessagePanel(sel);
        var stack = CommandStack.getInstance();
        armButton.setSelection(false);
        stack.disarmArmed();
        if (sel.isEmpty() || !stack.isValid() || !sel.getFirstElement().equals(stack.getActiveCommand())) {
            armButton.setEnabled(false);
            issueButton.setEnabled(false);
        } else if (stack.hasRemaining() && YamcsPlugin.hasAnyObjectPrivilege("Command")) {
            armButton.setEnabled(true);
        }
        refreshState();
    });
    getViewSite().setSelectionProvider(commandTableViewer);
    // Set up connection state, and listen to changes
    connectionStateProvider = RCPUtils.findSourceProvider(getViewSite(), ConnectionStateProvider.STATE_KEY_CONNECTED, ConnectionStateProvider.class);
    connectionStateProvider.addSourceProviderListener(sourceProviderListener);
    // Add the popup menu for pasting commands
    addPopupMenu();
    // Set initial state
    refreshState();
    YamcsPlugin.addListener(this);
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) HashMap(java.util.HashMap) ConnectionStateProvider(org.yamcs.studio.core.ui.connections.ConnectionStateProvider) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TextStyle(org.eclipse.swt.graphics.TextStyle) Button(org.eclipse.swt.widgets.Button) Composite(org.eclipse.swt.widgets.Composite) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) RGB(org.eclipse.swt.graphics.RGB) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) GridData(org.eclipse.swt.layout.GridData) Styler(org.eclipse.jface.viewers.StyledString.Styler)

Aggregations

Styler (org.eclipse.jface.viewers.StyledString.Styler)11 StyledString (org.eclipse.jface.viewers.StyledString)8 TextStyle (org.eclipse.swt.graphics.TextStyle)4 Color (org.eclipse.swt.graphics.Color)3 RGB (org.eclipse.swt.graphics.RGB)3 HashMap (java.util.HashMap)1 StrikeoutStyler (org.bndtools.utils.jface.StrikeoutStyler)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 ResourceManager (org.eclipse.jface.resource.ResourceManager)1 IRegion (org.eclipse.jface.text.IRegion)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)1 ViewerCell (org.eclipse.jface.viewers.ViewerCell)1 Image (org.eclipse.swt.graphics.Image)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1