Search in sources :

Example 1 with ProcessInstanceSort

use of com.centurylink.mdw.plugin.designer.model.ProcessInstanceSort in project mdw-designer by CenturyLinkCloud.

the class ProcessInstanceListView method createTable.

private void createTable(Composite parent) {
    int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION;
    processInstanceTable = new Table(parent, style);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 10;
    processInstanceTable.setLayoutData(gridData);
    processInstanceTable.setLinesVisible(true);
    processInstanceTable.setHeaderVisible(true);
    for (int i = 0; i < columnSpecs.size(); i++) {
        ColumnSpec colSpec = columnSpecs.get(i);
        int styles = SWT.LEFT;
        if (colSpec.readOnly)
            style = style | SWT.READ_ONLY;
        TableColumn column = new TableColumn(processInstanceTable, styles, i);
        column.setText(colSpec.label);
        column.setWidth(colSpec.width);
        column.setResizable(colSpec.resizable);
        column.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                TableColumn sortColumn = tableViewer.getTable().getSortColumn();
                TableColumn currentColumn = (TableColumn) e.widget;
                int direction = tableViewer.getTable().getSortDirection();
                if (sortColumn == currentColumn) {
                    direction = direction == SWT.UP ? SWT.DOWN : SWT.UP;
                } else {
                    tableViewer.getTable().setSortColumn(currentColumn);
                    direction = SWT.DOWN;
                }
                tableViewer.getTable().setSortDirection(direction);
                ProcessInstanceSort sort = contentProvider.getSort();
                sort.setSort(currentColumn.getText());
                sort.setAscending(direction == SWT.UP);
                refreshTable();
            }
        });
    }
    // double-click
    processInstanceTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            ProcessInstanceVO processInstanceInfo = (ProcessInstanceVO) e.item.getData();
            handleOpen(processInstanceInfo);
        }
    });
    // right-click menu
    processInstanceTable.addListener(SWT.MenuDetect, new Listener() {

        public void handleEvent(Event event) {
            processInstanceTable.setMenu(createContextMenu(processInstanceTable.getShell()));
        }
    });
    // auto-adjust column width
    processInstanceTable.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            int tableWidth = processInstanceTable.getBounds().width;
            int cumulative = 0;
            TableColumn[] tableColumns = processInstanceTable.getColumns();
            for (int i = 0; i < tableColumns.length; i++) {
                if (i == tableColumns.length - 1)
                    tableColumns[i].setWidth(tableWidth - cumulative - 25);
                cumulative += tableColumns[i].getWidth();
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) ColumnSpec(com.centurylink.mdw.plugin.designer.properties.editor.ColumnSpec) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ProcessInstanceSort(com.centurylink.mdw.plugin.designer.model.ProcessInstanceSort) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableColumn(org.eclipse.swt.widgets.TableColumn) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Aggregations

ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)1 ProcessInstanceSort (com.centurylink.mdw.plugin.designer.model.ProcessInstanceSort)1 ColumnSpec (com.centurylink.mdw.plugin.designer.properties.editor.ColumnSpec)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Table (org.eclipse.swt.widgets.Table)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1