Search in sources :

Example 16 with ControlListener

use of org.eclipse.swt.events.ControlListener in project yamcs-studio by yamcs.

the class ParameterTableViewer method addFixedColumns.

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

        @Override
        public String getText(Object element) {
            ParameterInfo cnt = (ParameterInfo) element;
            return cnt.getQualifiedName();
        }
    });
    TableViewerColumn engValueColumn = new TableViewerColumn(this, SWT.RIGHT);
    engValueColumn.getColumn().setText(COL_ENG);
    tcl.setColumnData(engValueColumn.getColumn(), new ColumnWeightData(10));
    engValueColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ParameterReader reader = readers.get(element);
            if (reader == null || reader.getValue() == null)
                return "-";
            ParameterValue value = reader.getValue();
            return String.valueOf(getValue(value.getEngValue()));
        }
    });
    TableViewerColumn rawValueColumn = new TableViewerColumn(this, SWT.RIGHT);
    rawValueColumn.getColumn().setText(COL_RAW);
    tcl.setColumnData(rawValueColumn.getColumn(), new ColumnWeightData(10));
    rawValueColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ParameterReader reader = readers.get(element);
            if (reader == null || reader.getValue() == null)
                return "-";
            ParameterValue value = reader.getValue();
            return String.valueOf(getValue(value.getRawValue()));
        }
    });
    TableViewerColumn gentimeValueColumn = new TableViewerColumn(this, SWT.LEFT);
    gentimeValueColumn.getColumn().setText(COL_TIME);
    tcl.setColumnData(gentimeValueColumn.getColumn(), new ColumnWeightData(20));
    gentimeValueColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ParameterReader reader = readers.get(element);
            if (reader == null || reader.getValue() == null)
                return "-";
            ParameterValue value = reader.getValue();
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            Date time = new Date(value.getGenerationTime());
            String strDate = sdfDate.format(time);
            return strDate;
        }
    });
    TableViewerColumn aqutimeValueColumn = new TableViewerColumn(this, SWT.LEFT);
    aqutimeValueColumn.getColumn().setText(COL_AQU_TIME);
    tcl.setColumnData(aqutimeValueColumn.getColumn(), new ColumnWeightData(20));
    aqutimeValueColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ParameterReader reader = readers.get(element);
            if (reader == null || reader.getValue() == null)
                return "-";
            ParameterValue value = reader.getValue();
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            Date time = new Date(value.getAcquisitionTime());
            String strDate = sdfDate.format(time);
            return strDate;
        }
    });
    // Common properties to all columns
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(nameColumn);
    columns.add(engValueColumn);
    columns.add(rawValueColumn);
    columns.add(gentimeValueColumn);
    columns.add(aqutimeValueColumn);
    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 : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ParameterValue(org.yamcs.protobuf.Pvalue.ParameterValue) ArrayList(java.util.ArrayList) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) Date(java.util.Date) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) SimpleDateFormat(java.text.SimpleDateFormat) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 17 with ControlListener

use of org.eclipse.swt.events.ControlListener in project yamcs-studio by yamcs.

the class CommandHistoryView method addFixedColumns.

private void addFixedColumns() {
    TableViewerColumn stateColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    stateColumn.getColumn().setImage(headerCompleteImage);
    stateColumn.getColumn().addSelectionListener(getSelectionAdapter(stateColumn.getColumn()));
    stateColumn.getColumn().setToolTipText("Completion");
    stateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            switch(((CommandHistoryRecord) element).getCommandState()) {
                case COMPLETED:
                    return checkmarkImage;
                case FAILED:
                    return errorImage;
                default:
                    return null;
            }
        }

        @Override
        public String getText(Object element) {
            CommandHistoryRecord rec = (CommandHistoryRecord) element;
            switch(((CommandHistoryRecord) element).getCommandState()) {
                case COMPLETED:
                    return "Completed";
                case FAILED:
                    return rec.getPTVInfo().getFailureMessage();
                default:
                    return null;
            }
        }
    });
    tableLayout.addColumnData(new ColumnPixelData(90));
    TableViewerColumn gentimeColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    gentimeColumn.getColumn().setText(COL_T);
    gentimeColumn.getColumn().addSelectionListener(getSelectionAdapter(gentimeColumn.getColumn()));
    gentimeColumn.getColumn().setToolTipText("Generation Time");
    gentimeColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((CommandHistoryRecord) element).getGenerationTime();
        }
    });
    tableLayout.addColumnData(new ColumnPixelData(150));
    TableViewerColumn nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    nameColumn.getColumn().setText(COL_COMMAND);
    nameColumn.getColumn().setToolTipText("Command String");
    nameColumn.getColumn().addSelectionListener(getSelectionAdapter(nameColumn.getColumn()));
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandHistoryRecord rec = (CommandHistoryRecord) element;
            return rec.getCommandString();
        }
    });
    tableLayout.addColumnData(new ColumnPixelData(500));
    TableViewerColumn originColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    originColumn.getColumn().setText(COL_SRC);
    originColumn.getColumn().setToolTipText("Source (user@origin)");
    originColumn.getColumn().addSelectionListener(getSelectionAdapter(originColumn.getColumn()));
    originColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandHistoryRecord rec = (CommandHistoryRecord) element;
            return rec.getUsername() + "@" + rec.getOrigin();
        }
    });
    tableLayout.addColumnData(new ColumnPixelData(200));
    TableViewerColumn seqIdColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
    seqIdColumn.getColumn().setText(COL_SRC_ID);
    seqIdColumn.getColumn().addSelectionListener(getSelectionAdapter(seqIdColumn.getColumn()));
    seqIdColumn.getColumn().setToolTipText("Client ID");
    seqIdColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return String.valueOf(((CommandHistoryRecord) element).getSequenceNumber());
        }
    });
    tableLayout.addColumnData(new ColumnPixelData(50));
    TableViewerColumn ptvColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
    ptvColumn.getColumn().setText(COL_PTV);
    ptvColumn.getColumn().addSelectionListener(getSelectionAdapter(ptvColumn.getColumn()));
    ptvColumn.getColumn().setToolTipText("Pre-Transmission Verification");
    ptvColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            CommandHistoryRecord rec = (CommandHistoryRecord) element;
            switch(rec.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 " + rec.getPTVInfo().getState());
                    return grayBubble;
            }
        }

        @Override
        public String getToolTipText(Object element) {
            CommandHistoryRecord rec = (CommandHistoryRecord) element;
            if (rec.getPTVInfo().getFailureMessage() != null) {
                return rec.getPTVInfo().getFailureMessage();
            } else {
                return super.getToolTipText(element);
            }
        }
    });
    tableLayout.addColumnData(new ColumnPixelData(50));
    TableViewerColumn finalSeqColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
    finalSeqColumn.getColumn().setText(COL_SEQ_ID);
    finalSeqColumn.getColumn().addSelectionListener(getSelectionAdapter(finalSeqColumn.getColumn()));
    finalSeqColumn.getColumn().setToolTipText("Final Sequence Count");
    finalSeqColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandHistoryRecord rec = (CommandHistoryRecord) element;
            return (rec.getFinalSequenceCount() != null) ? String.valueOf(rec.getFinalSequenceCount()) : "-";
        }
    });
    tableLayout.addColumnData(new ColumnPixelData(50));
    // Common properties to all columns
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(gentimeColumn);
    columns.add(nameColumn);
    columns.add(originColumn);
    columns.add(seqIdColumn);
    columns.add(ptvColumn);
    columns.add(finalSeqColumn);
    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) {
                checkMinWidth(column.getColumn());
            }
        });
    }
    // TODO use IMemento or something
    tableViewer.getTable().setSortColumn(gentimeColumn.getColumn());
    tableViewer.getTable().setSortDirection(SWT.DOWN);
    getViewSite().setSelectionProvider(tableViewer);
}
Also used : 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) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 18 with ControlListener

use of org.eclipse.swt.events.ControlListener in project yamcs-studio by yamcs.

the class CommandQueuesTableViewer method addFixedColumns.

private void addFixedColumns(TableColumnLayout tcl) {
    TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.NONE);
    nameColumn.getColumn().setText(COL_QUEUE);
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(40));
    TableViewerColumn stateColumn = new TableViewerColumn(this, SWT.CENTER);
    stateColumn.getColumn().setText(COL_STATE);
    stateColumn.getColumn().setWidth(250);
    stateColumn.setEditingSupport(new StateEditingSupport(stateColumn.getViewer()));
    tcl.setColumnData(stateColumn.getColumn(), new ColumnWeightData(30));
    TableViewerColumn commandsColumn = new TableViewerColumn(this, SWT.CENTER);
    commandsColumn.getColumn().setText(COL_COMMANDS);
    tcl.setColumnData(commandsColumn.getColumn(), new ColumnWeightData(10));
    TableViewerColumn sentColumn = new TableViewerColumn(this, SWT.CENTER);
    sentColumn.getColumn().setText(COL_SENT);
    tcl.setColumnData(sentColumn.getColumn(), new ColumnWeightData(10));
    TableViewerColumn rejectedColumn = new TableViewerColumn(this, SWT.CENTER);
    rejectedColumn.getColumn().setText(COL_REJECTED);
    tcl.setColumnData(rejectedColumn.getColumn(), new ColumnWeightData(10));
    // Common properties to all columns
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(nameColumn);
    columns.add(stateColumn);
    columns.add(commandsColumn);
    columns.add(sentColumn);
    columns.add(rejectedColumn);
    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 : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ArrayList(java.util.ArrayList) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 19 with ControlListener

use of org.eclipse.swt.events.ControlListener in project tmdm-studio-se by Talend.

the class XObjectEditor method createToolbar.

protected void createToolbar(final Composite parent) {
    toolBar = new TdEditorToolBar(parent);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    toolBar.getToolbarControl().setLayoutData(data);
    toolBar.addResizeListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            parent.getParent().layout(true);
            parent.layout(true);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 20 with ControlListener

use of org.eclipse.swt.events.ControlListener in project nebula.widgets.nattable by eclipse.

the class NatCombo method createTextControl.

/**
 * Creates the Text control of this NatCombo, adding styles, look&amp;feel
 * and needed listeners for the control only.
 *
 * @param style
 *            The style for the Text Control to construct. Uses this style
 *            adding internal styles via ConfigRegistry.
 */
protected void createTextControl(int style) {
    int widgetStyle = style | HorizontalAlignmentEnum.getSWTStyle(this.cellStyle);
    this.text = new Text(this, widgetStyle);
    this.text.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    this.text.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    this.text.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    this.text.setLayoutData(gridData);
    this.text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
                showDropdownControl();
                int selectionIndex = getDropdownTable().getSelectionIndex();
                if (selectionIndex < 0) {
                    select(0);
                } else {
                    // only visualize the selection in the dropdown, do not
                    // perform a selection
                    getDropdownTable().select(selectionIndex);
                }
                // ensure the arrow key events do not have any further
                // effect
                event.doit = false;
            } else if (!LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character)) {
                if (NatCombo.this.freeEdit) {
                    // free value in text control will be used
                    if (!getDropdownTable().isDisposed()) {
                        getDropdownTable().deselectAll();
                        for (Map.Entry<String, Boolean> entry : NatCombo.this.selectionStateMap.entrySet()) {
                            entry.setValue(Boolean.FALSE);
                        }
                    }
                } else {
                    showDropdownControl();
                }
            }
        }
    });
    this.text.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            if (!NatCombo.this.freeEdit) {
                if (getDropdownTable().isDisposed() || !getDropdownTable().isVisible()) {
                    showDropdownControl();
                } else {
                    // if there is no free edit enabled, set the focus back
                    // to the dropdownlist so it handles key strokes itself
                    getDropdownTable().forceFocus();
                }
            }
        }
    });
    this.text.addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            calculateBounds();
        }

        @Override
        public void controlMoved(ControlEvent e) {
            calculateBounds();
        }
    });
    this.text.addFocusListener(new FocusListenerWrapper());
    final Canvas iconCanvas = new Canvas(this, SWT.NONE) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle iconImageBounds = NatCombo.this.iconImage.getBounds();
            return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
        }
    };
    gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
    iconCanvas.setLayoutData(gridData);
    iconCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent event) {
            GC gc = event.gc;
            Rectangle iconCanvasBounds = iconCanvas.getBounds();
            Rectangle iconImageBounds = NatCombo.this.iconImage.getBounds();
            int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
            int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
            gc.drawImage(NatCombo.this.iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
            Color originalFg = gc.getForeground();
            gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
            gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
            gc.setForeground(originalFg);
        }
    });
    iconCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            if (NatCombo.this.dropdownShell != null && !NatCombo.this.dropdownShell.isDisposed()) {
                if (NatCombo.this.dropdownShell.isVisible()) {
                    NatCombo.this.text.forceFocus();
                    hideDropdownControl();
                } else {
                    showDropdownControl();
                }
            } else {
                showDropdownControl();
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) GC(org.eclipse.swt.graphics.GC) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)54 ControlListener (org.eclipse.swt.events.ControlListener)54 GridData (org.eclipse.swt.layout.GridData)21 FocusEvent (org.eclipse.swt.events.FocusEvent)14 Control (org.eclipse.swt.widgets.Control)12 FocusListener (org.eclipse.swt.events.FocusListener)11 MouseEvent (org.eclipse.swt.events.MouseEvent)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 Composite (org.eclipse.swt.widgets.Composite)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 ArrayList (java.util.ArrayList)9 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)9 DisposeEvent (org.eclipse.swt.events.DisposeEvent)9 DisposeListener (org.eclipse.swt.events.DisposeListener)9 KeyEvent (org.eclipse.swt.events.KeyEvent)9 Point (org.eclipse.swt.graphics.Point)9 Event (org.eclipse.swt.widgets.Event)8 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)6 Listener (org.eclipse.swt.widgets.Listener)6 Table (org.eclipse.swt.widgets.Table)6