Search in sources :

Example 56 with ControlListener

use of org.eclipse.swt.events.ControlListener 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 57 with ControlListener

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

the class CommandQueuedTableViewer method addFixedColumns.

private void addFixedColumns(TableColumnLayout tcl) {
    TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.NONE);
    nameColumn.getColumn().setText(COL_QUEUE);
    nameColumn.getColumn().setToolTipText("The queue which contains the command");
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(200));
    TableViewerColumn userColumn = new TableViewerColumn(this, SWT.NONE);
    userColumn.getColumn().setText(COL_USER);
    userColumn.getColumn().setToolTipText("The user who submitted the command");
    tcl.setColumnData(userColumn.getColumn(), new ColumnWeightData(200));
    TableViewerColumn stringColumn = new TableViewerColumn(this, SWT.CENTER);
    stringColumn.getColumn().setText(COL_STRING);
    stringColumn.getColumn().setToolTipText("Command source code");
    tcl.setColumnData(stringColumn.getColumn(), new ColumnWeightData(200));
    TableViewerColumn timeColumn = new TableViewerColumn(this, SWT.LEFT);
    timeColumn.getColumn().setText(COL_TIME);
    timeColumn.getColumn().setToolTipText("Time");
    tcl.setColumnData(timeColumn.getColumn(), new ColumnWeightData(200));
    // Common properties to all columns
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(nameColumn);
    columns.add(userColumn);
    columns.add(stringColumn);
    columns.add(timeColumn);
    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 58 with ControlListener

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

the class EventLogTableViewer method addFixedColumns.

private void addFixedColumns() {
    // sort listener common for all columns
    Listener sortListener = event -> {
        TableColumn column = (TableColumn) event.widget;
        // TODO should this sort logic not move up into this class? Why are columns passed?
        EventLogContentProvider contentProvider = (EventLogContentProvider) getContentProvider();
        contentProvider.sort(column);
    };
    TableViewerColumn messageColumn = new TableViewerColumn(this, SWT.NONE);
    messageColumn.getColumn().setText(COL_MESSAGE);
    messageColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(300));
    TableViewerColumn sourceColumn = new TableViewerColumn(this, SWT.NONE);
    sourceColumn.getColumn().setText(COL_SOURCE);
    sourceColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(150));
    TableViewerColumn generationColumn = new TableViewerColumn(this, SWT.NONE);
    generationColumn.getColumn().setText(COL_GENERATION);
    generationColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(150));
    TableViewerColumn receptionColumn = new TableViewerColumn(this, SWT.NONE);
    receptionColumn.getColumn().setText(COL_RECEPTION);
    receptionColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(150));
    TableViewerColumn seqNumColum = new TableViewerColumn(this, SWT.RIGHT);
    seqNumColum.getColumn().setText(COL_SEQNUM);
    seqNumColum.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(80));
    if (!EventLogPreferences.isShowSequenceNumberColumn()) {
        tableLayout.addColumnData(new ColumnPixelData(0));
        seqNumColum.getColumn().setResizable(false);
    }
    if (!EventLogPreferences.isShowGenerationColumn()) {
        tableLayout.addColumnData(new ColumnPixelData(0));
        generationColumn.getColumn().setResizable(false);
    }
    if (!EventLogPreferences.isShowReceptionColumn()) {
        tableLayout.addColumnData(new ColumnPixelData(0));
        receptionColumn.getColumn().setResizable(false);
    }
    for (TableColumn tableColumn : getTable().getColumns()) {
        tableColumn.setMoveable(true);
        // prevent resize to 0
        tableColumn.addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                if (tableColumn.getWidth() < 5)
                    tableColumn.setWidth(5);
            }
        });
    }
    // TODO use IMemento or something
    // !! Keep these values in sync with EventLogViewerComparator constructor
    getTable().setSortColumn(receptionColumn.getColumn());
    getTable().setSortDirection(SWT.UP);
}
Also used : TableLayout(org.eclipse.jface.viewers.TableLayout) TableViewer(org.eclipse.jface.viewers.TableViewer) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) SWT(org.eclipse.swt.SWT) TableColumn(org.eclipse.swt.widgets.TableColumn) ControlListener(org.eclipse.swt.events.ControlListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ControlEvent(org.eclipse.swt.events.ControlEvent) Listener(org.eclipse.swt.widgets.Listener) ControlListener(org.eclipse.swt.events.ControlListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 59 with ControlListener

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

the class DataLinkTableViewer 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(18));
    TableViewerColumn typeColumn = new TableViewerColumn(this, SWT.LEFT);
    typeColumn.getColumn().setText(COL_TYPE);
    tcl.setColumnData(typeColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn specColumn = new TableViewerColumn(this, SWT.LEFT);
    specColumn.getColumn().setText(COL_SPEC);
    tcl.setColumnData(specColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn streamColumn = new TableViewerColumn(this, SWT.LEFT);
    streamColumn.getColumn().setText(COL_STREAM);
    tcl.setColumnData(streamColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn statusColumn = new TableViewerColumn(this, SWT.CENTER);
    statusColumn.getColumn().setText(COL_STATUS);
    tcl.setColumnData(statusColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn datacount = new TableViewerColumn(this, SWT.RIGHT);
    datacount.getColumn().setText(COL_DATACOUNT);
    tcl.setColumnData(datacount.getColumn(), new ColumnWeightData(10));
    // Common properties to all columns
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(nameColumn);
    columns.add(typeColumn);
    columns.add(specColumn);
    columns.add(streamColumn);
    columns.add(statusColumn);
    columns.add(datacount);
    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 60 with ControlListener

use of org.eclipse.swt.events.ControlListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Control method test_addControlListenerLorg_eclipse_swt_events_ControlListener.

@Test
public void test_addControlListenerLorg_eclipse_swt_events_ControlListener() {
    ControlListener listener = new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
            eventOccurred = true;
        }

        @Override
        public void controlResized(ControlEvent e) {
            eventOccurred = true;
        }
    };
    control.addControlListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.Move, new Event());
    assertTrue(eventOccurred);
    eventOccurred = false;
    control.notifyListeners(SWT.Resize, new Event());
    assertTrue(eventOccurred);
    control.removeControlListener(listener);
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Aggregations

ControlListener (org.eclipse.swt.events.ControlListener)87 ControlEvent (org.eclipse.swt.events.ControlEvent)82 GridData (org.eclipse.swt.layout.GridData)31 FocusEvent (org.eclipse.swt.events.FocusEvent)19 Composite (org.eclipse.swt.widgets.Composite)19 Test (org.junit.Test)19 MouseEvent (org.eclipse.swt.events.MouseEvent)18 Point (org.eclipse.swt.graphics.Point)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 KeyEvent (org.eclipse.swt.events.KeyEvent)16 ArrayList (java.util.ArrayList)14 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 DisposeEvent (org.eclipse.swt.events.DisposeEvent)13 Control (org.eclipse.swt.widgets.Control)13 Event (org.eclipse.swt.widgets.Event)13 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)11 DisposeListener (org.eclipse.swt.events.DisposeListener)11 FocusListener (org.eclipse.swt.events.FocusListener)11 Listener (org.eclipse.swt.widgets.Listener)10 ModifyEvent (org.eclipse.swt.events.ModifyEvent)9