Search in sources :

Example 1 with TransmissionConstraintInfo

use of org.yamcs.protobuf.Mdb.TransmissionConstraintInfo in project yamcs-studio by yamcs.

the class CommandStackTableViewer method addFixedColumns.

private void addFixedColumns(TableColumnLayout tcl) {
    Image level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level1s.png"));
    Image level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level2s.png"));
    Image level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level3s.png"));
    Image level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level4s.png"));
    Image level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level5s.png"));
    TableViewerColumn 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));
    TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.NONE);
    nameColumn.getColumn().setText(COL_COMMAND);
    nameColumn.setLabelProvider(new CommandSourceColumnLabelProvider(styleProvider));
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(300));
    TableViewerColumn 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) {
            StackedCommand 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 null;
            }
        }

        @Override
        public String getToolTipText(Object element) {
            StackedCommand 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));
    TableViewerColumn constraintsColumn = new TableViewerColumn(this, SWT.LEFT);
    constraintsColumn.getColumn().setText(COL_CONSTRAINTS);
    constraintsColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            StackedCommand cmd = (StackedCommand) element;
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < cmd.getMetaCommand().getConstraintCount(); i++) {
                if (i != 0)
                    buf.append(" and ");
                TransmissionConstraintInfo constraint = cmd.getMetaCommand().getConstraint(i);
                for (int j = 0; j < constraint.getComparisonCount(); j++) {
                    if (j != 0)
                        buf.append(", ");
                    appendConstraint(constraint.getComparison(j), buf);
                }
            }
            return buf.length() != 0 ? buf.toString() : "-";
        }
    });
    tcl.setColumnData(constraintsColumn.getColumn(), new ColumnPixelData(250));
    TableViewerColumn 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) {
            StackedCommand cmd = (StackedCommand) element;
            long timeout = -1;
            for (TransmissionConstraintInfo constraint : cmd.getMetaCommand().getConstraintList()) timeout = Math.max(timeout, constraint.getTimeout());
            return (timeout >= 0) ? Long.toString(timeout) + " ms" : "-";
        }
    });
    tcl.setColumnData(constraintsTimeOutColumn.getColumn(), new ColumnPixelData(50));
    TableViewerColumn 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));
    TableViewerColumn ptvColumn = new TableViewerColumn(this, SWT.CENTER);
    ptvColumn.getColumn().setText(COL_PTV);
    ptvColumn.getColumn().setToolTipText("Pre-Transmission Verification");
    ptvColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            StackedCommand cmd = (StackedCommand) element;
            switch(cmd.getPTVInfo().getState()) {
                case UNDEF:
                    return grayBubble;
                case NA:
                case OK:
                    return greenBubble;
                case PENDING:
                    return waitingImage;
                case NOK:
                    return redBubble;
                default:
                    log.warning("Unexpected PTV state " + cmd.getPTVInfo().getState());
                    return grayBubble;
            }
        }

        @Override
        public String getToolTipText(Object element) {
            StackedCommand cmd = (StackedCommand) element;
            if (cmd.getPTVInfo().getFailureMessage() != null)
                return cmd.getPTVInfo().getFailureMessage();
            else
                return super.getToolTipText(element);
        }
    });
    tcl.setColumnData(ptvColumn.getColumn(), new ColumnPixelData(50));
    TableViewerColumn 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) {
            StackedCommand cmd = (StackedCommand) element;
            return cmd.getStackedState().getText();
        }

        @Override
        public Color getBackground(Object element) {
            StackedCommand 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) {
            StackedCommand 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));
    // column comment
    TableViewerColumn 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
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(rowIdColumn);
    columns.add(nameColumn);
    columns.add(significanceColumn);
    columns.add(constraintsColumn);
    columns.add(constraintsTimeOutColumn);
    columns.add(releaseColumn);
    columns.add(ptvColumn);
    columns.add(stateColumn);
    columns.add(commentColumn);
    for (TableViewerColumn 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 : 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.ui.utils.CenteredImageLabelProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TransmissionConstraintInfo(org.yamcs.protobuf.Mdb.TransmissionConstraintInfo) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ArrayList (java.util.ArrayList)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ControlListener (org.eclipse.swt.events.ControlListener)1 Color (org.eclipse.swt.graphics.Color)1 Image (org.eclipse.swt.graphics.Image)1 TransmissionConstraintInfo (org.yamcs.protobuf.Mdb.TransmissionConstraintInfo)1 CenteredImageLabelProvider (org.yamcs.studio.core.ui.utils.CenteredImageLabelProvider)1