Search in sources :

Example 36 with ColumnLabelProvider

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

the class CommandHistoryView method processCommandHistoryEntry.

public void processCommandHistoryEntry(CommandHistoryEntry cmdhistEntry) {
    // Maybe we need to update structure
    for (CommandHistoryAttribute attr : cmdhistEntry.getAttrList()) {
        if (IGNORED_ATTRIBUTES.contains(attr.getName()))
            continue;
        String shortName = CommandHistoryRecordContentProvider.toHumanReadableName(attr);
        if (!dynamicColumns.contains(shortName)) {
            TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.LEFT);
            column.getColumn().setText(shortName);
            column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn()));
            column.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    return ((CommandHistoryRecord) element).getTextForColumn(shortName, showRelativeTime);
                }

                @Override
                public String getToolTipText(Object element) {
                    return ((CommandHistoryRecord) element).getTooltipForColumn(shortName);
                }

                @Override
                public Image getImage(Object element) {
                    String imgLoc = ((CommandHistoryRecord) element).getImageForColumn(shortName);
                    if (CommandHistoryRecordContentProvider.GREEN.equals(imgLoc))
                        return greenBubble;
                    else if (CommandHistoryRecordContentProvider.RED.equals(imgLoc))
                        return redBubble;
                    else
                        return null;
                }
            });
            dynamicColumns.add(shortName);
            tableLayout.addColumnData(new ColumnPixelData(90));
            column.getColumn().setWidth(90);
            column.getColumn().addControlListener(new ControlListener() {

                @Override
                public void controlMoved(ControlEvent e) {
                }

                @Override
                public void controlResized(ControlEvent e) {
                    checkMinWidth(column.getColumn());
                }
            });
        }
    }
    // Now add content
    tableContentProvider.processCommandHistoryEntry(cmdhistEntry);
    updateSummaryLine();
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ControlListener(org.eclipse.swt.events.ControlListener) Image(org.eclipse.swt.graphics.Image) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CommandHistoryAttribute(org.yamcs.protobuf.Commanding.CommandHistoryAttribute)

Example 37 with ColumnLabelProvider

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

the class ArgumentTableViewer method addFixedColumns.

private void addFixedColumns(TableColumnLayout tcl) {
    TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.NONE);
    nameColumn.getColumn().setText(COL_NAME);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TelecommandArgument argument = (TelecommandArgument) element;
            return argument.getName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(200));
    TableViewerColumn valueColumn = new TableViewerColumn(this, SWT.NONE);
    valueColumn.getColumn().setText(COL_VALUE);
    valueColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TelecommandArgument argument = (TelecommandArgument) element;
            return argument.getValue();
        }
    });
    tcl.setColumnData(valueColumn.getColumn(), new ColumnWeightData(200));
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 38 with ColumnLabelProvider

use of org.eclipse.jface.viewers.ColumnLabelProvider 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)

Example 39 with ColumnLabelProvider

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

the class ConnectionsDialog method createServerPanel.

private Composite createServerPanel(Composite parent, ResourceManager resourceManager) {
    Composite serverPanel = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    serverPanel.setLayoutData(gd);
    TableColumnLayout tcl = new TableColumnLayout();
    serverPanel.setLayout(tcl);
    Image serverImage = resourceManager.createImage(RCPUtils.getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server.gif"));
    connViewer = new TableViewer(serverPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    connViewer.getTable().setHeaderVisible(true);
    connViewer.getTable().setLinesVisible(false);
    TableViewerColumn nameColumn = new TableViewerColumn(connViewer, SWT.NONE);
    nameColumn.getColumn().setText("Connection Name");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return serverImage;
        }

        @Override
        public String getText(Object element) {
            YamcsConfiguration conf = (YamcsConfiguration) element;
            return conf.getName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(400));
    connViewer.setContentProvider(new ArrayContentProvider());
    connViewer.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            YamcsConfiguration conf = (YamcsConfiguration) sel.getFirstElement();
            yamcsInstanceText.setText(forceString(conf.getInstance()));
            yamcsUserText.setText(forceString(conf.getUser()));
            yamcsPasswordText.setText(forceString(conf.getPassword()));
            savePasswordButton.setSelection(conf.isSavePassword());
            yamcsPrimaryHostText.setText(forceString(conf.getPrimaryHost()));
            yamcsPrimaryPortText.setText(forceString(conf.getPrimaryPort()));
            yamcsFailoverHostText.setText(forceString(conf.getFailoverHost()));
            yamcsFailoverPortText.setText(forceString(conf.getFailoverPort()));
            nameText.setText(forceString(conf.getName()));
            updateState();
        }
    });
    connViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            YamcsConfiguration c1 = (YamcsConfiguration) o1;
            YamcsConfiguration c2 = (YamcsConfiguration) o2;
            if (c1.getName() != null && c2.getName() != null)
                return c1.getName().compareTo(c2.getName());
            else
                return 0;
        }
    });
    return serverPanel;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TextUtils.forceString(org.yamcs.studio.core.ui.utils.TextUtils.forceString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 40 with ColumnLabelProvider

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

the class SwitchProcessorDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(area, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new GridLayout());
    Composite tableWrapper = new Composite(composite, SWT.NONE);
    TableColumnLayout tcl = new TableColumnLayout();
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper.setLayout(tcl);
    processorsTable = new TableViewer(tableWrapper, SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    processorsTable.getTable().setHeaderVisible(true);
    processorsTable.getTable().setLinesVisible(true);
    TableViewerColumn instanceColumn = new TableViewerColumn(processorsTable, SWT.NONE);
    instanceColumn.getColumn().setText("Instance");
    instanceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ProcessorInfo info = (ProcessorInfo) element;
            return info.getInstance();
        }
    });
    tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(100));
    TableViewerColumn nameColumn = new TableViewerColumn(processorsTable, SWT.NONE);
    nameColumn.getColumn().setText("Processor");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ProcessorInfo info = (ProcessorInfo) element;
            return info.getName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100));
    TableViewerColumn typeColumn = new TableViewerColumn(processorsTable, SWT.NONE);
    typeColumn.getColumn().setText("Type");
    typeColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ProcessorInfo info = (ProcessorInfo) element;
            return info.getType();
        }
    });
    tcl.setColumnData(typeColumn.getColumn(), new ColumnPixelData(100));
    processorsTable.setContentProvider(ArrayContentProvider.getInstance());
    processorsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    processorsTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 == null || e2 == null)
                return 0;
            ProcessorInfo p1 = (ProcessorInfo) e1;
            ProcessorInfo p2 = (ProcessorInfo) e2;
            int c = p1.getInstance().compareTo(p2.getInstance());
            return (c != 0) ? c : p1.getName().compareTo(p2.getName());
        }
    });
    ManagementCatalogue catalogue = ManagementCatalogue.getInstance();
    processorsTable.setInput(catalogue.getProcessors());
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ProcessorInfo(org.yamcs.protobuf.YamcsManagement.ProcessorInfo) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) ManagementCatalogue(org.yamcs.studio.core.model.ManagementCatalogue) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)41 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)28 Composite (org.eclipse.swt.widgets.Composite)16 Image (org.eclipse.swt.graphics.Image)13 TableViewer (org.eclipse.jface.viewers.TableViewer)11 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)10 GridData (org.eclipse.swt.layout.GridData)10 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)9 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)8 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Table (org.eclipse.swt.widgets.Table)7 Text (org.eclipse.swt.widgets.Text)6 ControlEvent (org.eclipse.swt.events.ControlEvent)5 ControlListener (org.eclipse.swt.events.ControlListener)5 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)4 Viewer (org.eclipse.jface.viewers.Viewer)4