Search in sources :

Example 1 with ConnectionStateProvider

use of org.yamcs.studio.core.ui.connections.ConnectionStateProvider 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

HashMap (java.util.HashMap)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 ResourceManager (org.eclipse.jface.resource.ResourceManager)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Styler (org.eclipse.jface.viewers.StyledString.Styler)1 RGB (org.eclipse.swt.graphics.RGB)1 TextStyle (org.eclipse.swt.graphics.TextStyle)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Spinner (org.eclipse.swt.widgets.Spinner)1 ConnectionStateProvider (org.yamcs.studio.core.ui.connections.ConnectionStateProvider)1