Search in sources :

Example 46 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project ACS by ACS-Community.

the class EventListPart method postConstruct.

/**
	 */
@PostConstruct
public void postConstruct(Composite parent, final IEclipseContext context, IEventBroker eventBroker, EMenuService menuService) {
    try {
        em = EventModel.getInstance();
    } catch (Throwable thr) {
        thr.printStackTrace();
        IStatus someStatus = statusReporter.newStatus(IStatus.ERROR, "Connection with NCs failed.", thr);
        statusReporter.report(someStatus, StatusReporter.SHOW);
        throw new RuntimeException(thr);
    }
    logger = em.getLogger();
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    gridLayout.verticalSpacing = 0;
    parent.setLayout(gridLayout);
    // TODO: We currently have the filter text control in the regular view toolbar.
    //       The e3 eventGUI had a "custom tool bar" inserted here.
    //       We should decide which way it's better.
    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    /*
		 * "Time "+timeStamp+" "+m_channelName+" "+component+" "+count+"
		 * "+channelEventCount+" " +" "+evtTypeName+"
		 * "+evtCounter.get(evtTypeName)
		 */
    TableViewerColumn tvcol = new TableViewerColumn(viewer, SWT.NONE, 0);
    tvcol.setLabelProvider(new TimeStampLabelProvider());
    TableColumn col = tvcol.getColumn();
    col.setText("Timestamp");
    col.setWidth(180);
    col.setAlignment(SWT.LEFT);
    tvcol = new TableViewerColumn(viewer, SWT.NONE, 1);
    tvcol.setLabelProvider(new EventSourceLabelProvider());
    col = tvcol.getColumn();
    col.setText("Event source");
    col.setWidth(150);
    col.setAlignment(SWT.LEFT);
    tvcol = new TableViewerColumn(viewer, SWT.NONE, 2);
    tvcol.setLabelProvider(new CountLabelProvider());
    col = tvcol.getColumn();
    col.setText("# Events in channel");
    col.setWidth(50);
    col.setAlignment(SWT.LEFT);
    tvcol = new TableViewerColumn(viewer, SWT.NONE, 3);
    tvcol.setLabelProvider(new EventTypeLabelProvider());
    col = tvcol.getColumn();
    col.setText("Event type");
    col.setWidth(150);
    col.setAlignment(SWT.LEFT);
    tvcol = new TableViewerColumn(viewer, SWT.NONE, 4);
    tvcol.setLabelProvider(new EventTypeCountLabelProvider());
    col = tvcol.getColumn();
    col.setText("# Events this type");
    col.setWidth(50);
    col.setAlignment(SWT.LEFT);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTable());
    viewer.setContentProvider(new EventListViewContentProvider(em));
    // Attach a selection listener to our event list that will post the selected event for the event details list
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.size() == 1) {
                selectionService.setSelection(selection.getFirstElement());
            }
        }
    });
    viewer.setInput(new Object());
    hookContextMenu(menuService);
    pel = new PopulateEventList(logger, viewer, new StatusLineWriter(eventBroker), em.getEventQueue(), "NC Events");
    eventListThread = pel.getThreadForEventList();
    eventListThread.start();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Table(org.eclipse.swt.widgets.Table) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) StatusLineWriter(alma.acs.eventbrowser.status.StatusLineWriter) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PostConstruct(javax.annotation.PostConstruct)

Example 47 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project ACS by ACS-Community.

the class TableViewBase method createPartControl.

@Override
public void createPartControl(Composite parent) {
    tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    // Set the column
    for (int t = 0; t < colNames.length; t++) {
        int style = t == 0 ? SWT.LEFT : SWT.CENTER;
        final TableViewerColumn viewerColumn = new TableViewerColumn(tableViewer, style);
        final TableColumn column = viewerColumn.getColumn();
        column.setText(colNames[t]);
        final int index = t;
        // Setting the right sorter
        column.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                sorter.setColumn(index);
                int dir = tableViewer.getTable().getSortDirection();
                if (tableViewer.getTable().getSortColumn() == column) {
                    dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
                } else {
                    dir = SWT.DOWN;
                }
                tableViewer.getTable().setSortDirection(dir);
                tableViewer.getTable().setSortColumn(column);
                tableViewer.refresh();
            }
        });
        column.pack();
        column.setWidth(colWidths[t]);
    }
    tableViewer.setContentProvider(new ViewContentProvider());
}
Also used : Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 48 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project cubrid-manager by CUBRID.

the class PstmtSQLDialog method removeColumn.

protected void removeColumn() {
    if (parameterTypeTable.getItemCount() > 0) {
        parameterTypeTable.remove(0);
    }
    int oldCount = parameterTypeTable.getColumnCount();
    for (int i = 0; i < oldCount; i++) {
        parameterTypeTable.getColumn(0).dispose();
        parameterTable.getTable().getColumn(0).dispose();
    }
    TableColumn columnNO = new TableColumn(parameterTypeTable, SWT.NONE);
    columnNO.setWidth(40);
    columnNO.setText("");
    final TableViewerColumn columnNO2 = new TableViewerColumn(parameterTable, SWT.CENTER);
    columnNO2.getColumn().setWidth(40);
    columnNO2.getColumn().setText("");
    /*For bug TOOLS-3115*/
    parameterTable.setLabelProvider(new ParamValueLabelProvider(parameterTable.getTable()));
    valueList.clear();
    parameterTable.refresh();
}
Also used : TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 49 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project cubrid-manager by CUBRID.

the class PstmtSQLDialog method createEmptyTable.

/**
	 * Create the empty parameter table
	 *
	 * @param parent Composite
	 * @param isMulti boolean
	 */
protected void createEmptyTable(Composite parent) {
    Group typeGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
    GridData groupGd = new GridData(GridData.FILL_HORIZONTAL);
    groupGd.heightHint = 70;
    typeGroup.setLayoutData(groupGd);
    typeGroup.setLayout(new GridLayout());
    typeGroup.setText(Messages.colParaType);
    parameterTypeTable = new Table(typeGroup, SWT.BORDER | SWT.H_SCROLL);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 45;
    parameterTypeTable.setLayoutData(gd);
    parameterTypeTable.setHeaderVisible(true);
    parameterTypeTable.setLinesVisible(false);
    parameterTypeTable.setDragDetect(false);
    TableColumn columnNO = new TableColumn(parameterTypeTable, SWT.CENTER);
    columnNO.setWidth(40);
    columnNO.setText("");
    tableEditor = new TableEditor(parameterTypeTable);
    tableEditor.horizontalAlignment = SWT.LEFT;
    tableEditor.grabHorizontal = true;
    parameterTypeTable.addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(Event event) {
            if (event.button != 1) {
                return;
            }
            if (isChanging) {
                return;
            }
            Point pt = new Point(event.x, event.y);
            final TableItem item = parameterTypeTable.getItem(0);
            for (int i = 1; i < parameterTypeTable.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    handleType(item, i);
                }
            }
        }
    });
    Group parameterGroup = new Group(parent, SWT.SHADOW_IN);
    parameterGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    parameterGroup.setLayout(new GridLayout(2, false));
    parameterGroup.setText(Messages.colParaValue);
    ToolBar toolBar = new ToolBar(parameterGroup, SWT.FLAT);
    ToolItem addRecordItem = new ToolItem(toolBar, SWT.PUSH);
    addRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_insert.png"));
    addRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addData();
        }
    });
    ToolItem delRecordItem = new ToolItem(toolBar, SWT.PUSH);
    delRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_delete.png"));
    delRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (parameterTable.getTable().getSelectionIndices().length == 0) {
                setErrorMessage(Messages.errDeleteMsg);
                return;
            }
            List<Integer> deleteIndex = new ArrayList<Integer>();
            for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                deleteIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
            }
            int lastSelectedIndex = 0;
            for (int i = 0; i < deleteIndex.size(); i++) {
                int seletectIndex = deleteIndex.get(i);
                int newIndex = seletectIndex - i;
                valueList.remove(newIndex);
                lastSelectedIndex = newIndex;
            }
            //reset the index in data
            for (int i = 0; i < valueList.size(); i++) {
                ParamValueObject paramValueObject = valueList.get(i);
                paramValueObject.getValue().set(0, String.valueOf(i + 1));
            }
            parameterTable.setInput(valueList);
            parameterTable.refresh();
            if (parameterTable.getTable().getItemCount() > 0) {
                parameterTable.getTable().setSelection(lastSelectedIndex < 1 ? 0 : lastSelectedIndex - 1);
                parameterTable.getTable().setFocus();
            }
            validate();
        }
    });
    parameterTable = new TableViewer(parameterGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    // press the tab key, it is moved next input area
    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(parameterTable, new FocusCellOwnerDrawHighlighter(parameterTable));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(parameterTable) {

        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION && ((MouseEvent) event.sourceEvent).button == 1) || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
        //				|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    TableViewerEditor.create(parameterTable, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    //		new Table(parameterGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    parameterTable.getTable().setLayoutData(gridData);
    parameterTable.getTable().setHeaderVisible(true);
    parameterTable.getTable().setLinesVisible(true);
    parameterTable.setUseHashlookup(true);
    final TableViewerColumn columnNO2 = new TableViewerColumn(parameterTable, SWT.CENTER);
    columnNO2.getColumn().setWidth(40);
    columnNO2.getColumn().setText("");
    parameterTable.setContentProvider(new ParamValueContentProvider());
    parameterTable.setLabelProvider(new ParamValueLabelProvider(parameterTable.getTable()));
    parameterTable.getTable().addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'c') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                StringBuffer clipboardDataString = new StringBuffer();
                List<Integer> replaceIndex = new ArrayList<Integer>();
                for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                    replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
                }
                for (int i = 0; i < replaceIndex.size(); i++) {
                    if (i != 0) {
                        clipboardDataString.append(EXCELDATASEPRATOR);
                    }
                    ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
                    for (int j = 1; j < parameterTypeTable.getColumnCount(); j++) {
                        if (j != 1) {
                            clipboardDataString.append(EXCELCOLUMNSEPRATOR);
                        }
                        String value = paramValueObject.getValue().get(j);
                        clipboardDataString.append(value);
                    }
                }
                TextTransfer textTransfer = TextTransfer.getInstance();
                Transfer[] transfers = new Transfer[] { textTransfer };
                Object[] data = new Object[] { clipboardDataString.toString() };
                cb.setContents(data, transfers);
                cb.dispose();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'v') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                //					boolean supportFlag = false;
                //					TransferData[] transferDatas = cb.getAvailableTypes();
                //					for(int i=0; i<transferDatas.length; i++) {
                //						// Checks whether RTF format is available.
                //						if(RTFTransfer.getInstance().isSupportedType(transferDatas[i])) {
                //							supportFlag = true;
                //							break;
                //						}
                //					}
                //					if (!supportFlag) {
                //						setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
                //						return;
                //					}
                String plainText = (String) cb.getContents(TextTransfer.getInstance());
                List<ParamValueObject> list = generateParamValueObjectListFromClipboardString(plainText);
                if (list.size() == 0 || list.get(0).getValue().size() != parameterTypeTable.getColumnCount()) {
                    setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
                    return;
                }
                //					String rtfText = (String)cb.getContents(RTFTransfer.getInstance());
                int startIndex = parameterTable.getTable().getSelectionIndex();
                //if the copy line bigger than the value list, add new ParamValueObject to the end
                if (parameterTable.getTable().getSelectionCount() <= 1) {
                    if (startIndex < 0 || startIndex > valueList.size()) {
                        for (ParamValueObject copyParamValueObject : list) {
                            valueList.add(copyParamValueObject);
                        }
                    } else {
                        for (ParamValueObject copyParamValueObject : list) {
                            if (startIndex > valueList.size() - 1) {
                                valueList.add(copyParamValueObject);
                            } else {
                                ParamValueObject paramValueObject = valueList.get(startIndex);
                                List<String> oldValue = paramValueObject.getValue();
                                for (int i = 1; i < oldValue.size(); i++) {
                                    List<String> newValue = copyParamValueObject.getValue();
                                    if (i > newValue.size() - 1) {
                                        break;
                                    }
                                    oldValue.set(i, newValue.get(i));
                                }
                            }
                            startIndex++;
                        }
                    }
                } else {
                    // replay the select line
                    List<Integer> replaceIndex = new ArrayList<Integer>();
                    for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                        replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
                    }
                    for (int i = 0; i < replaceIndex.size(); i++) {
                        ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
                        List<String> oldValue = paramValueObject.getValue();
                        if (i > list.size()) {
                            break;
                        }
                        List<String> newValue = list.get(i).getValue();
                        for (int j = 1; j < oldValue.size(); j++) {
                            if (j > newValue.size()) {
                                break;
                            }
                            oldValue.set(j, newValue.get(j));
                        }
                    }
                }
                cb.dispose();
                refreshValueListIndex();
                parameterTable.refresh();
                validate();
            }
        }
    });
    // use to mark click point, the right click menu use this point
    parameterTable.getTable().addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event event) {
            clickPoint = new Point(event.x, event.y);
        }
    });
    registerContextMenu();
    parameterTable.setInput(valueList);
}
Also used : Group(org.eclipse.swt.widgets.Group) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) TraverseListener(org.eclipse.swt.events.TraverseListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) TableItem(org.eclipse.swt.widgets.TableItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ToolItem(org.eclipse.swt.widgets.ToolItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableEditor(org.eclipse.swt.custom.TableEditor) Point(org.eclipse.swt.graphics.Point) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Clipboard(org.eclipse.swt.dnd.Clipboard) TableViewer(org.eclipse.jface.viewers.TableViewer) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 50 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project cubrid-manager by CUBRID.

the class PstmtSQLDialog method createColumn.

/**
	 * Create the empty parameter table
	 *
	 * @param parent Composite
	 * @param isMulti boolean
	 */
protected void createColumn(int columnCount) {
    TableItem item = new TableItem(parameterTypeTable, SWT.NONE);
    item.setText(0, Messages.msgPstmtType);
    for (int i = 0; i < columnCount; i++) {
        TableColumn typeColumn = new TableColumn(parameterTypeTable, SWT.NONE);
        typeColumn.setWidth(90);
        typeColumn.setText(String.valueOf(i + 1));
        final TableViewerColumn paraColumn = new TableViewerColumn(parameterTable, SWT.LEFT);
        paraColumn.getColumn().setWidth(90);
        paraColumn.getColumn().setText(String.valueOf(i + 1));
        paraColumn.setEditingSupport(new ParamValueEditingSupport(parameterTable, i + 1));
    }
    parameterTable.setLabelProvider(new ParamValueLabelProvider(parameterTable.getTable()));
    //add one data to parameterTable
    ParamValueObject paramValueObject = new ParamValueObject();
    //index
    paramValueObject.getValue().add("1");
    for (int i = 0; i < columnCount; i++) {
        paramValueObject.getValue().add("");
    }
    valueList.add(paramValueObject);
    parameterTable.setInput(valueList);
    parameterTable.refresh();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

TableColumn (org.eclipse.swt.widgets.TableColumn)305 Table (org.eclipse.swt.widgets.Table)151 GridData (org.eclipse.swt.layout.GridData)105 TableViewer (org.eclipse.jface.viewers.TableViewer)94 Composite (org.eclipse.swt.widgets.Composite)92 SelectionEvent (org.eclipse.swt.events.SelectionEvent)87 GridLayout (org.eclipse.swt.layout.GridLayout)76 TableItem (org.eclipse.swt.widgets.TableItem)76 Point (org.eclipse.swt.graphics.Point)57 Label (org.eclipse.swt.widgets.Label)55 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)52 Button (org.eclipse.swt.widgets.Button)48 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)41 FillLayout (org.eclipse.swt.layout.FillLayout)37 Listener (org.eclipse.swt.widgets.Listener)37 Event (org.eclipse.swt.widgets.Event)35 Shell (org.eclipse.swt.widgets.Shell)35 Test (org.junit.Test)33 SelectionListener (org.eclipse.swt.events.SelectionListener)32 Text (org.eclipse.swt.widgets.Text)30