Search in sources :

Example 1 with ResourceManager

use of org.eclipse.jface.resource.ResourceManager in project egit by eclipse.

the class CommitSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(1, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    final ResourceManager resources = new LocalResourceManager(JFaceResources.getResources());
    UIUtils.hookDisposal(main, resources);
    // Table never shows e-mail addresses because it might get rather wide.
    table = new CommitGraphTable(main, null, resources, false);
    table.getTableView().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            commitId = null;
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.size() == 1)
                commitId = ((SWTCommit) sel.getFirstElement()).getId();
            getButton(OK).setEnabled(commitId != null);
        }
    });
    table.getTableView().addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            if (getButton(OK).isEnabled())
                buttonPressed(OK);
        }
    });
    // allow for some room here
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 400).applyTo(table.getControl());
    allCommits = new SWTCommitList(table.getControl(), resources);
    return main;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) IOpenListener(org.eclipse.jface.viewers.IOpenListener) Composite(org.eclipse.swt.widgets.Composite) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 2 with ResourceManager

use of org.eclipse.jface.resource.ResourceManager in project yamcs-studio by yamcs.

the class AddToStackWizardPage1 method createControl.

@Override
public void createControl(Composite parent) {
    var composite = new Composite(parent, SWT.NONE);
    setControl(composite);
    var gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    // grid for expand+filter box
    var gl2 = new GridLayout(3, false);
    gl2.marginHeight = 0;
    gl2.marginWidth = 0;
    var row = new Composite(composite, SWT.NONE);
    row.setLayout(gl2);
    row.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // add expand all / collapse all button
    var expandAll = new Button(row, SWT.ARROW | SWT.DOWN);
    var expandAllData = new GridData(SWT.NONE);
    expandAll.setLayoutData(expandAllData);
    expandAll.setText("Expand All");
    expandAll.setToolTipText("Expand All");
    expandAll.setVisible(false);
    expandAllData.exclude = true;
    var collapseAll = new Button(row, SWT.ARROW | SWT.RIGHT);
    var collapseAllData = new GridData(SWT.NONE);
    collapseAll.setLayoutData(collapseAllData);
    collapseAll.setText("Collapse All");
    collapseAll.setToolTipText("Collapse All");
    collapseAll.setVisible(true);
    // add filter box
    var searchbox = new Text(row, SWT.SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    searchbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    expandAll.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commandsTreeTable.expandAll();
            expandAll.setVisible(false);
            collapseAll.setVisible(true);
            expandAllData.exclude = true;
            collapseAllData.exclude = false;
            expandAll.pack();
            collapseAll.pack();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            commandsTreeTable.expandAll();
            expandAll.setVisible(false);
            collapseAll.setVisible(true);
            expandAllData.exclude = true;
            collapseAllData.exclude = false;
            expandAll.pack();
            collapseAll.pack();
        }
    });
    collapseAll.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commandsTreeTable.collapseAll();
            expandAll.setVisible(true);
            collapseAll.setVisible(false);
            expandAllData.exclude = false;
            collapseAllData.exclude = true;
            expandAll.pack();
            collapseAll.pack();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            commandsTreeTable.collapseAll();
            expandAll.setVisible(true);
            collapseAll.setVisible(false);
            expandAllData.exclude = false;
            collapseAllData.exclude = true;
            expandAll.pack();
            collapseAll.pack();
        }
    });
    // build tree table
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), composite);
    level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level0s.png"));
    level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level1s.png"));
    level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level2s.png"));
    level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level3s.png"));
    level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level4s.png"));
    level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level5s.png"));
    var treeWrapper = new Composite(composite, SWT.NONE);
    tcl = new TreeColumnLayout();
    var gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 800;
    gd.heightHint = 500;
    treeWrapper.setLayoutData(gd);
    treeWrapper.setLayout(tcl);
    commandsTreeTable = new TreeViewer(treeWrapper, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    commandsTreeTable.getTree().setHeaderVisible(true);
    commandsTreeTable.getTree().setLinesVisible(true);
    // column xtce path
    var pathColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    pathColumn.getColumn().setText(COL_PATH);
    pathColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof XtceSubSystemNode) {
                var node = (XtceSubSystemNode) element;
                return node.getName();
            } else {
                var node = (XtceCommandNode) element;
                return node.getCommandInfo().getName();
            }
        }
    });
    tcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(300));
    // column significance
    var significanceColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    significanceColumn.getColumn().setText(COL_SIGN);
    significanceColumn.getColumn().setToolTipText("Significance Level");
    significanceColumn.getColumn().setAlignment(SWT.CENTER);
    significanceColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            if (element instanceof XtceCommandNode) {
                var node = (XtceCommandNode) element;
                var cmd = node.getCommandInfo();
                if (cmd.getSignificance() == null) {
                    return level0Image;
                }
                switch(cmd.getSignificance().getConsequenceLevel()) {
                    case NONE:
                        return level0Image;
                    case WATCH:
                        return level1Image;
                    case WARNING:
                        return level2Image;
                    case DISTRESS:
                        return level3Image;
                    case CRITICAL:
                        return level4Image;
                    case SEVERE:
                        return level5Image;
                    default:
                        return null;
                }
            }
            return null;
        }
    });
    tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(50));
    // on item selection update significance message and page completion status
    commandsTreeTable.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            setMessage(null);
            return;
        }
        var selectedElement = sel.getFirstElement();
        if (selectedElement instanceof XtceCommandNode) {
            var cmd = ((XtceCommandNode) sel.getFirstElement()).getCommandInfo();
            // setMessage(getMessage(cmd));
            command.setMetaCommand(cmd);
            setPageComplete(true);
        } else {
            setPageComplete(false);
        }
    });
    var commandTreeContentProvider = new CommandTreeContentProvider();
    commandsTreeTable.setContentProvider(commandTreeContentProvider);
    commandsTreeTable.setInput(commandTreeContentProvider);
    YamcsPlugin.getMissionDatabase().getCommands().forEach(cmd -> {
        if (!cmd.hasAbstract() || !cmd.getAbstract()) {
            // add aliases columns
            for (var alias : cmd.getAliasList()) {
                var namespace = alias.getNamespace();
                if (!namespaces.contains(namespace) && !namespace.startsWith("/")) {
                    namespaces.add(namespace);
                    addAliasColumn(namespace);
                }
            }
            commandTreeContentProvider.addElement(cmd.getQualifiedName(), cmd);
        }
    });
    commandsTreeTable.expandAll();
    var filter = new CommandTreeViewerFilter(commandTreeContentProvider);
    commandsTreeTable.addFilter(filter);
    searchbox.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent ke) {
            if (ke.keyCode == SWT.ARROW_DOWN) {
                var items = commandsTreeTable.getTree().getItems();
                if (items.length > 0) {
                    IStructuredSelection sel = new StructuredSelection(items[0].getData());
                    commandsTreeTable.setSelection(sel);
                    commandsTreeTable.getTree().setFocus();
                }
            } else {
                filter.setSearchTerm(searchbox.getText());
                commandsTreeTable.refresh();
                commandsTreeTable.expandAll();
            }
        }
    });
    commandsTreeTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            String n1;
            String n2;
            if (o1 instanceof XtceSubSystemNode) {
                n1 = ((XtceSubSystemNode) o1).getName();
            } else {
                n1 = ((XtceCommandNode) o1).getCommandInfo().getQualifiedName();
            }
            if (o2 instanceof XtceSubSystemNode) {
                n2 = ((XtceSubSystemNode) o2).getName();
            } else {
                n2 = ((XtceCommandNode) o2).getCommandInfo().getQualifiedName();
            }
            return n1.compareTo(n2);
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) XtceSubSystemNode(org.yamcs.studio.core.ui.XtceSubSystemNode) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Text(org.eclipse.swt.widgets.Text) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CenteredImageLabelProvider(org.yamcs.studio.core.utils.CenteredImageLabelProvider) GridData(org.eclipse.swt.layout.GridData) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with ResourceManager

use of org.eclipse.jface.resource.ResourceManager 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)

Example 4 with ResourceManager

use of org.eclipse.jface.resource.ResourceManager in project yamcs-studio by yamcs.

the class ConnectionsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText("Yamcs Server Connections");
    Composite contentArea = new Composite(parent, SWT.NONE);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.verticalSpacing = 0;
    contentArea.setLayout(gl);
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), contentArea);
    ToolBar editBar = new ToolBar(contentArea, SWT.NO_FOCUS);
    addServerButton = new ToolItem(editBar, SWT.NONE);
    addServerButton.setImage(resourceManager.createImage(RCPUtils.getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server_add.png")));
    addServerButton.setToolTipText("Add Connection");
    addServerButton.addListener(SWT.Selection, evt -> {
        addServer();
        updateState();
    });
    removeServerButton = new ToolItem(editBar, SWT.NONE);
    removeServerButton.setImage(resourceManager.createImage(RCPUtils.getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server_remove.png")));
    removeServerButton.setToolTipText("Delete Connection");
    removeServerButton.addListener(SWT.Selection, evt -> {
        removeSelectedServer();
        updateState();
    });
    editBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    SashForm sash = new SashForm(contentArea, SWT.HORIZONTAL);
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    sash.setLayout(new FillLayout());
    createServerPanel(sash, resourceManager);
    // Create right side, but wrap it in another composite to force
    // dimensions even when invisible
    Composite detailPanelWrapper = new Composite(sash, SWT.NONE);
    gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    detailPanelWrapper.setLayout(gl);
    createDetailPanel(detailPanelWrapper, resourceManager);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 250;
    detailPanel.setLayoutData(gd);
    sash.setWeights(new int[] { 55, 45 });
    ConnectionPreferences.getConfigurations().forEach(conf -> {
        connViewer.add(conf);
    });
    YamcsConfiguration lastConf = ConnectionPreferences.getLastUsedConfiguration();
    if (lastConf != null)
        selectServer(lastConf);
    else
        selectFirstServer();
    updateState();
    return contentArea;
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) FillLayout(org.eclipse.swt.layout.FillLayout) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 5 with ResourceManager

use of org.eclipse.jface.resource.ResourceManager in project yamcs-studio by yamcs.

the class LoginDialog method create.

@Override
public void create() {
    super.create();
    setTitle("Connect to " + nvl(conf.getName(), conf.getPrimaryConnectionString()));
    setMessage("Please provide your credentials");
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), getShell());
    Image titleImage = resourceManager.createImage(RCPUtils.getImageDescriptor(LoginDialog.class, "icons/yamcs_banner.png"));
    setTitleImage(titleImage);
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Image(org.eclipse.swt.graphics.Image)

Aggregations

ResourceManager (org.eclipse.jface.resource.ResourceManager)9 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)8 GridLayout (org.eclipse.swt.layout.GridLayout)7 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 Image (org.eclipse.swt.graphics.Image)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 ToolBar (org.eclipse.swt.widgets.ToolBar)3 ToolItem (org.eclipse.swt.widgets.ToolItem)3 IOException (java.io.IOException)2 UIText (org.eclipse.egit.ui.internal.UIText)2 SashForm (org.eclipse.swt.custom.SashForm)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Button (org.eclipse.swt.widgets.Button)2 HashMap (java.util.HashMap)1 List (java.util.List)1