Search in sources :

Example 1 with CenteredImageLabelProvider

use of org.yamcs.studio.core.utils.CenteredImageLabelProvider 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 2 with CenteredImageLabelProvider

use of org.yamcs.studio.core.utils.CenteredImageLabelProvider in project yamcs-studio by yamcs.

the class CommandHistoryView method createColumns.

private void createColumns() {
    var table = tableViewer.getTable();
    var layout = new TableLayout();
    var currentColumns = tableViewer.getTable().getColumns();
    for (var currentColumn : currentColumns) {
        currentColumn.dispose();
    }
    for (var def : columnData.getVisibleColumns()) {
        if (def.name.equals(COL_COMPLETION)) {
            var completionColumn = new TableViewerColumn(tableViewer, SWT.NONE);
            completionColumn.getColumn().addControlListener(columnResizeListener);
            completionColumn.getColumn().addSelectionListener(getSelectionAdapter(completionColumn.getColumn()));
            completionColumn.getColumn().setImage(headerCompleteImage);
            completionColumn.getColumn().setToolTipText("Completion");
            completionColumn.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public Image getImage(Object element) {
                    var command = ((CommandHistoryRecord) element).getCommand();
                    if (command.isSuccess()) {
                        return checkmarkImage;
                    } else if (command.isFailure()) {
                        return errorImage;
                    } else {
                        return null;
                    }
                }

                @Override
                public String getText(Object element) {
                    var command = ((CommandHistoryRecord) element).getCommand();
                    if (command.isSuccess()) {
                        return "Completed";
                    } else if (command.isFailure()) {
                        return command.getError();
                    } else {
                        return null;
                    }
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_T)) {
            var gentimeColumn = new TableViewerColumn(tableViewer, SWT.NONE);
            gentimeColumn.getColumn().addControlListener(columnResizeListener);
            gentimeColumn.getColumn().addSelectionListener(getSelectionAdapter(gentimeColumn.getColumn()));
            gentimeColumn.getColumn().setText(COL_T);
            gentimeColumn.getColumn().setToolTipText("Generation Time");
            gentimeColumn.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    var generationTime = ((CommandHistoryRecord) element).getCommand().getGenerationTime();
                    return YamcsPlugin.getDefault().formatInstant(generationTime);
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
            // Add chevron
            table.setSortColumn(gentimeColumn.getColumn());
            table.setSortDirection(SWT.UP);
        } else if (def.name.equals(COL_COMMAND)) {
            var nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
            nameColumn.getColumn().addSelectionListener(getSelectionAdapter(nameColumn.getColumn()));
            nameColumn.getColumn().setText(COL_COMMAND);
            nameColumn.getColumn().setToolTipText("Command String");
            nameColumn.getColumn().addControlListener(columnResizeListener);
            nameColumn.getColumn().addSelectionListener(getSelectionAdapter(nameColumn.getColumn()));
            nameColumn.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    return rec.getCommand().getSource();
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_USER)) {
            var userColumn = new TableViewerColumn(tableViewer, SWT.NONE);
            userColumn.getColumn().addSelectionListener(getSelectionAdapter(userColumn.getColumn()));
            userColumn.getColumn().setText(COL_USER);
            userColumn.getColumn().setToolTipText("User that issued the command");
            userColumn.getColumn().addControlListener(columnResizeListener);
            userColumn.getColumn().addSelectionListener(getSelectionAdapter(userColumn.getColumn()));
            userColumn.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    return rec.getCommand().getUsername();
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_ORIGIN)) {
            var originColumn = new TableViewerColumn(tableViewer, SWT.NONE);
            originColumn.getColumn().addSelectionListener(getSelectionAdapter(originColumn.getColumn()));
            originColumn.getColumn().setText(COL_ORIGIN);
            originColumn.getColumn().setToolTipText("Origin");
            originColumn.getColumn().addControlListener(columnResizeListener);
            originColumn.getColumn().addSelectionListener(getSelectionAdapter(originColumn.getColumn()));
            originColumn.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    return rec.getCommand().getOrigin();
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_ORIGIN_ID)) {
            var seqIdColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
            seqIdColumn.getColumn().addSelectionListener(getSelectionAdapter(seqIdColumn.getColumn()));
            seqIdColumn.getColumn().setText(COL_ORIGIN_ID);
            seqIdColumn.getColumn().addControlListener(columnResizeListener);
            seqIdColumn.getColumn().addSelectionListener(getSelectionAdapter(seqIdColumn.getColumn()));
            seqIdColumn.getColumn().setToolTipText("Client ID at origin");
            seqIdColumn.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    return String.valueOf(rec.getCommand().getSequenceNumber());
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_PTV)) {
            var ptvColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
            ptvColumn.getColumn().setText(COL_PTV);
            ptvColumn.getColumn().addControlListener(columnResizeListener);
            ptvColumn.getColumn().addSelectionListener(getSelectionAdapter(ptvColumn.getColumn()));
            ptvColumn.getColumn().setToolTipText("Pre-Transmission Verification");
            ptvColumn.setLabelProvider(new CenteredImageLabelProvider() {

                @Override
                public Image getImage(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var command = rec.getCommand();
                    if (command.isSuccess()) {
                        return greenBubble;
                    } else if (command.isFailure()) {
                        return redBubble;
                    } else {
                        return grayBubble;
                    }
                }

                @Override
                public String getToolTipText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var command = rec.getCommand();
                    if (command.getError() != null) {
                        return command.getError();
                    } else {
                        return super.getToolTipText(element);
                    }
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_QUEUED)) {
            var queuedColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
            queuedColumn.getColumn().setText(COL_QUEUED);
            queuedColumn.getColumn().addControlListener(columnResizeListener);
            queuedColumn.getColumn().addSelectionListener(getSelectionAdapter(queuedColumn.getColumn()));
            queuedColumn.getColumn().setToolTipText("Queued acknowledgment");
            queuedColumn.setLabelProvider(new CenteredImageLabelProvider() {

                @Override
                public Image getImage(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var ack = rec.getCommand().getQueuedAcknowledgment();
                    if (ack == null) {
                        return grayBubble;
                    } else {
                        switch(ack.getStatus()) {
                            case "NEW":
                                return grayBubble;
                            case "OK":
                                return greenBubble;
                            case "PENDING":
                                return waitingImage;
                            case "NOK":
                                return redBubble;
                            default:
                                log.warning("Unexpected ack state " + ack.getStatus());
                                return grayBubble;
                        }
                    }
                }

                @Override
                public String getToolTipText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var ack = rec.getCommand().getQueuedAcknowledgment();
                    return (ack != null) ? ack.getMessage() : null;
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_RELEASED)) {
            var releasedColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
            releasedColumn.getColumn().setText(COL_RELEASED);
            releasedColumn.getColumn().addControlListener(columnResizeListener);
            releasedColumn.getColumn().addSelectionListener(getSelectionAdapter(releasedColumn.getColumn()));
            releasedColumn.getColumn().setToolTipText("Released acknowledgment");
            releasedColumn.setLabelProvider(new CenteredImageLabelProvider() {

                @Override
                public Image getImage(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var ack = rec.getCommand().getReleasedAcknowledgment();
                    if (ack == null) {
                        return grayBubble;
                    } else {
                        switch(ack.getStatus()) {
                            case "NEW":
                                return grayBubble;
                            case "OK":
                                return greenBubble;
                            case "PENDING":
                                return waitingImage;
                            case "NOK":
                                return redBubble;
                            default:
                                log.warning("Unexpected ack state " + ack.getStatus());
                                return grayBubble;
                        }
                    }
                }

                @Override
                public String getToolTipText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var ack = rec.getCommand().getReleasedAcknowledgment();
                    return (ack != null) ? ack.getMessage() : null;
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (def.name.equals(COL_SENT)) {
            var sentColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
            sentColumn.getColumn().setText(COL_SENT);
            sentColumn.getColumn().addControlListener(columnResizeListener);
            sentColumn.getColumn().addSelectionListener(getSelectionAdapter(sentColumn.getColumn()));
            sentColumn.getColumn().setToolTipText("Sent acknowledgment");
            sentColumn.setLabelProvider(new CenteredImageLabelProvider() {

                @Override
                public Image getImage(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var ack = rec.getCommand().getSentAcknowledgment();
                    if (ack == null) {
                        return grayBubble;
                    } else {
                        switch(ack.getStatus()) {
                            case "NEW":
                                return grayBubble;
                            case "OK":
                                return greenBubble;
                            case "PENDING":
                                return waitingImage;
                            case "NOK":
                                return redBubble;
                            default:
                                log.warning("Unexpected ack state " + ack.getStatus());
                                return grayBubble;
                        }
                    }
                }

                @Override
                public String getToolTipText(Object element) {
                    var rec = (CommandHistoryRecord) element;
                    var ack = rec.getCommand().getSentAcknowledgment();
                    return (ack != null) ? ack.getMessage() : null;
                }
            });
            layout.addColumnData(new ColumnPixelData(def.width));
        } else if (dynamicColumns.contains(def.name)) {
            var column = new TableViewerColumn(tableViewer, SWT.LEFT);
            column.getColumn().setText(def.name);
            column.getColumn().addControlListener(columnResizeListener);
            column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn()));
            if (def.name.startsWith("Verifier_") || def.name.startsWith("Acknowledge_")) {
                column.setLabelProvider(new CenteredImageLabelProvider() {

                    @Override
                    public Image getImage(Object element) {
                        var rec = (CommandHistoryRecord) element;
                        var command = rec.getCommand();
                        if (command.isSuccess()) {
                            return greenBubble;
                        } else if (command.isFailure()) {
                            return redBubble;
                        } else {
                            return grayBubble;
                        }
                    }

                    @Override
                    public String getToolTipText(Object element) {
                        var rec = (CommandHistoryRecord) element;
                        var ack = rec.getCommand().getAcknowledgment(def.name);
                        return (ack != null) ? ack.getMessage() : null;
                    }
                });
                layout.addColumnData(new ColumnPixelData(def.width));
            } else {
                column.setLabelProvider(new ColumnLabelProvider() {

                    @Override
                    public String getText(Object element) {
                        var rec = (CommandHistoryRecord) element;
                        var value = rec.getCommand().getAttribute(def.name);
                        if (value == null) {
                            return null;
                        } else if (value instanceof byte[]) {
                            return StringConverter.arrayToHexString((byte[]) value);
                        } else {
                            return String.valueOf(value);
                        }
                    }
                });
            }
            layout.addColumnData(new ColumnPixelData(def.width));
        }
    }
    table.setLayout(layout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // !! Ensures column widths are applied when recreating columns
    table.layout(true);
    // !! Ensures table renders correctly for old data when adding a new column
    tableViewer.refresh();
    saveColumnState();
}
Also used : CenteredImageLabelProvider(org.yamcs.studio.core.utils.CenteredImageLabelProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Image(org.eclipse.swt.graphics.Image) TableLayout(org.eclipse.jface.viewers.TableLayout) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 3 with CenteredImageLabelProvider

use of org.yamcs.studio.core.utils.CenteredImageLabelProvider in project yamcs-studio by yamcs.

the class CommandStackTableViewer method addFixedColumns.

private void addFixedColumns(TableColumnLayout tcl) {
    var level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level0s.png"));
    var level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level1s.png"));
    var level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level2s.png"));
    var level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level3s.png"));
    var level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level4s.png"));
    var level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level5s.png"));
    var rowIdColumn = new TableViewerColumn(this, SWT.CENTER);
    rowIdColumn.getColumn().setText(COL_ROW_ID);
    rowIdColumn.getColumn().setToolTipText("Sequence Number within Stack");
    rowIdColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return String.valueOf(contentProvider.indexOf(element) + 1);
        }
    });
    rowIdColumn.getColumn().setWidth(50);
    tcl.setColumnData(rowIdColumn.getColumn(), new ColumnPixelData(50));
    delayColumn = new TableViewerColumn(this, SWT.NONE);
    delayColumn.getColumn().setText(COL_DELAY);
    delayColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var cmd = (StackedCommand) element;
            var delayMs = cmd.getDelayMs();
            var decimalFormat = new DecimalFormat("#,##0");
            var numberAsString = decimalFormat.format(delayMs);
            return (delayMs > 0) ? numberAsString + " ms" : "-";
        }
    });
    // the delay column is shown when the command stack is in automatic mode with
    // stack delays.
    tcl.setColumnData(delayColumn.getColumn(), new ColumnPixelData(0));
    // this.hideDelayColumn();
    var nameColumn = new TableViewerColumn(this, SWT.NONE);
    nameColumn.getColumn().setText(COL_COMMAND);
    nameColumn.setLabelProvider(new CommandSourceColumnLabelProvider(styleProvider));
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(300));
    var significanceColumn = new TableViewerColumn(this, SWT.CENTER);
    significanceColumn.getColumn().setText(COL_SIGNIFICANCE);
    significanceColumn.getColumn().setToolTipText("Significance Level");
    significanceColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            var cmd = (StackedCommand) element;
            if (cmd.getMetaCommand().getSignificance() == null) {
                return null;
            }
            switch(cmd.getMetaCommand().getSignificance().getConsequenceLevel()) {
                case WATCH:
                    return level1Image;
                case WARNING:
                    return level2Image;
                case DISTRESS:
                    return level3Image;
                case CRITICAL:
                    return level4Image;
                case SEVERE:
                    return level5Image;
                default:
                    return level0Image;
            }
        }

        @Override
        public String getToolTipText(Object element) {
            var cmd = (StackedCommand) element;
            if (cmd.getMetaCommand().getSignificance() == null) {
                return super.getToolTipText(element);
            }
            return cmd.getMetaCommand().getSignificance().getReasonForWarning();
        }
    });
    significanceColumn.getColumn().setWidth(50);
    tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(50));
    var constraintsColumn = new TableViewerColumn(this, SWT.LEFT);
    constraintsColumn.getColumn().setText(COL_CONSTRAINTS);
    constraintsColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var cmd = (StackedCommand) element;
            var buf = new StringBuilder();
            for (var i = 0; i < cmd.getMetaCommand().getConstraintCount(); i++) {
                if (i != 0) {
                    buf.append(" and ");
                }
                var constraint = cmd.getMetaCommand().getConstraint(i);
                buf.append(constraint.getExpression());
            }
            return buf.length() != 0 ? buf.toString() : "-";
        }
    });
    tcl.setColumnData(constraintsColumn.getColumn(), new ColumnPixelData(250));
    var constraintsTimeOutColumn = new TableViewerColumn(this, SWT.CENTER);
    constraintsTimeOutColumn.getColumn().setText(COL_CONSTRAINTS_TIMEOUT);
    constraintsTimeOutColumn.getColumn().setToolTipText("Constraints Timeout");
    constraintsTimeOutColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var cmd = (StackedCommand) element;
            var timeout = -1L;
            for (var constraint : cmd.getMetaCommand().getConstraintList()) {
                timeout = Math.max(timeout, constraint.getTimeout());
            }
            return (timeout >= 0) ? Long.toString(timeout) + " ms" : "-";
        }
    });
    tcl.setColumnData(constraintsTimeOutColumn.getColumn(), new ColumnPixelData(50));
    var releaseColumn = new TableViewerColumn(this, SWT.CENTER);
    releaseColumn.getColumn().setText(COL_RELEASE);
    releaseColumn.getColumn().setToolTipText("Release Time");
    releaseColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return "ASAP";
        }
    });
    tcl.setColumnData(releaseColumn.getColumn(), new ColumnPixelData(80));
    var stateColumn = new TableViewerColumn(this, SWT.CENTER);
    stateColumn.getColumn().setText(COL_STATE);
    stateColumn.getColumn().setToolTipText("Stack State");
    stateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var cmd = (StackedCommand) element;
            return cmd.getStackedState().getText();
        }

        @Override
        public Color getBackground(Object element) {
            var cmd = (StackedCommand) element;
            if (cmd.isArmed()) {
                return getTable().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
            } else if (cmd.getStackedState() == StackedState.ISSUED) {
                return getTable().getDisplay().getSystemColor(SWT.COLOR_GREEN);
            } else if (cmd.getStackedState() == StackedState.REJECTED) {
                return styleProvider.getErrorBackgroundColor();
            }
            return super.getBackground(element);
        }

        @Override
        public Color getForeground(Object element) {
            var cmd = (StackedCommand) element;
            if (cmd.getStackedState() == StackedState.REJECTED) {
                return getTable().getDisplay().getSystemColor(SWT.COLOR_RED);
            }
            return super.getForeground(element);
        }
    });
    tcl.setColumnData(stateColumn.getColumn(), new ColumnPixelData(80));
    var qColumn = new TableViewerColumn(this, SWT.CENTER);
    qColumn.getColumn().setText(COL_QUEUED);
    qColumn.getColumn().setToolTipText("Queued");
    qColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            var cmd = (StackedCommand) element;
            if (cmd.getQueuedState() == null) {
                return grayBubble;
            }
            switch(cmd.getQueuedState().getStatus()) {
                case "NA":
                case "OK":
                    return greenBubble;
                case "PENDING":
                    return waitingImage;
                case "NOK":
                    return redBubble;
                default:
                    log.warning("Unexpected state " + cmd.getQueuedState());
                    return grayBubble;
            }
        }
    });
    tcl.setColumnData(qColumn.getColumn(), new ColumnPixelData(50));
    var rColumn = new TableViewerColumn(this, SWT.CENTER);
    rColumn.getColumn().setText(COL_RELEASED);
    rColumn.getColumn().setToolTipText("Released");
    rColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            var cmd = (StackedCommand) element;
            if (cmd.getReleasedState() == null) {
                return grayBubble;
            }
            switch(cmd.getReleasedState().getStatus()) {
                case "NA":
                case "OK":
                    return greenBubble;
                case "PENDING":
                    return waitingImage;
                case "NOK":
                    return redBubble;
                default:
                    log.warning("Unexpected state " + cmd.getReleasedState());
                    return grayBubble;
            }
        }
    });
    tcl.setColumnData(rColumn.getColumn(), new ColumnPixelData(50));
    var sColumn = new TableViewerColumn(this, SWT.CENTER);
    sColumn.getColumn().setText(COL_SENT);
    sColumn.getColumn().setToolTipText("Sent");
    sColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            var cmd = (StackedCommand) element;
            if (cmd.getSentState() == null) {
                return grayBubble;
            }
            switch(cmd.getSentState().getStatus()) {
                case "NA":
                case "OK":
                    return greenBubble;
                case "PENDING":
                    return waitingImage;
                case "NOK":
                    return redBubble;
                default:
                    log.warning("Unexpected state " + cmd.getSentState());
                    return grayBubble;
            }
        }
    });
    tcl.setColumnData(sColumn.getColumn(), new ColumnPixelData(50));
    // column comment
    var commentColumn = new TableViewerColumn(this, SWT.LEFT);
    commentColumn.getColumn().setText(COL_COMMENT);
    commentColumn.getColumn().setToolTipText("Free Text Comment");
    commentColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((StackedCommand) element).getComment();
        }
    });
    tcl.setColumnData(commentColumn.getColumn(), new ColumnPixelData(80));
    // Common properties to all columns
    var columns = new ArrayList<TableViewerColumn>();
    columns.add(rowIdColumn);
    columns.add(nameColumn);
    columns.add(significanceColumn);
    columns.add(constraintsColumn);
    columns.add(constraintsTimeOutColumn);
    columns.add(releaseColumn);
    columns.add(qColumn);
    columns.add(rColumn);
    columns.add(sColumn);
    columns.add(stateColumn);
    columns.add(commentColumn);
    for (var column : columns) {
        // prevent resize to 0
        column.getColumn().addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                if (column.getColumn().getWidth() < 5) {
                    column.getColumn().setWidth(5);
                }
            }
        });
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) Color(org.eclipse.swt.graphics.Color) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) CenteredImageLabelProvider(org.yamcs.studio.core.utils.CenteredImageLabelProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)3 Image (org.eclipse.swt.graphics.Image)3 CenteredImageLabelProvider (org.yamcs.studio.core.utils.CenteredImageLabelProvider)3 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 ResourceManager (org.eclipse.jface.resource.ResourceManager)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableLayout (org.eclipse.jface.viewers.TableLayout)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ControlListener (org.eclipse.swt.events.ControlListener)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1