Search in sources :

Example 1 with ITableCellEditorRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellEditorRenderer in project janrufmonitor by tbrandt77.

the class AbstractTableApplication method buildTableColumns.

private void buildTableColumns() {
    Table t = ((TableViewer) viewer).getTable();
    int columnCount = this.getTableColumnCount();
    String[] columnHeader = new String[columnCount];
    CellEditor[] editors = new CellEditor[columnCount];
    ITableCellRenderer r = null;
    for (int i = 0; i < columnCount; i++) {
        columnHeader[i] = this.getColumnID(i);
        // check renderer type
        r = RendererRegistry.getInstance().getRenderer(columnHeader[i]);
        if (r instanceof ITableCellEditorRenderer) {
            switch(((ITableCellEditorRenderer) r).getType()) {
                case 1:
                    editors[i] = new ComboBoxCellEditor(t, ((ITableCellEditorRenderer) r).getValues(), SWT.READ_ONLY);
                    break;
                case 2:
                    editors[i] = new CheckboxCellEditor(t);
                    break;
                default:
                    // editors[i] = new TextCellEditor(t);
                    editors[i] = new TextCellEditor(t);
            }
        } else {
            // editors[i] = new TextCellEditor(t);
            editors[i] = new TextCellEditor(t, SWT.WRAP);
        }
    }
    ((TableViewer) this.viewer).setColumnProperties(columnHeader);
    ((TableViewer) this.viewer).setCellEditors(editors);
    ((TableViewer) this.viewer).setCellModifier(new TableCellModifier(((TableViewer) viewer), this));
    TableColumn[] cols = t.getColumns();
    for (int i = 0; i < cols.length; i++) {
        cols[i].dispose();
    }
    int columns = this.getTableColumnCount();
    String id = "";
    for (int i = 0; i < columns; i++) {
        TableViewerColumn tc = new TableViewerColumn(((TableViewer) this.viewer), SWT.LEFT);
        id = getColumnID(i);
        ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer(id);
        tc.getColumn().setText((tr != null ? tr.getHeader() : ""));
        tc.getColumn().setData(id);
        if (tr != null && tr.isRenderImage())
            tc.setLabelProvider(this.getImageCellLabelProvider(id));
        else
            tc.setLabelProvider(this.getTextCellLabelProvider(id));
        tc.getColumn().addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                de.janrufmonitor.ui.jface.application.action.IAction action = getOrderAction();
                if (action != null && action instanceof org.eclipse.jface.action.IAction) {
                    Event ev = new Event();
                    ev.widget = e.widget;
                    ((org.eclipse.jface.action.IAction) action).runWithEvent(ev);
                }
            }
        });
        int width = Integer.parseInt(getConfiguration().getProperty(CFG_COLUMN_SIZE + id, "50"));
        if (width > -1) {
            tc.getColumn().setWidth(width);
        }
        tc.getColumn().addControlListener(new ControlAdapter() {

            public void controlResized(ControlEvent e) {
                if (e.widget instanceof TableColumn) {
                    TableColumn tc = (TableColumn) e.widget;
                    if (tc.getData() != null) {
                        String column = (String) tc.getData();
                        int width = tc.getWidth();
                        getConfiguration().setProperty(CFG_COLUMN_SIZE + column, Integer.toString(width));
                        storeConfiguration();
                        m_logger.info("Set column size to " + width);
                    }
                }
            }
        });
    }
    OwnerDrawLabelProvider.setUpOwnerDraw(((TableViewer) this.viewer));
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) IAction(de.janrufmonitor.ui.jface.application.action.IAction) ITableCellEditorRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellEditorRenderer) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 2 with ITableCellEditorRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellEditorRenderer in project janrufmonitor by tbrandt77.

the class AbstractTreeTableApplication method buildTableColumns.

private void buildTableColumns() {
    Tree t = ((TreeViewer) viewer).getTree();
    int columnCount = this.getTableColumnCount();
    String[] columnHeader = new String[columnCount];
    CellEditor[] editors = new CellEditor[columnCount];
    ITableCellRenderer r = null;
    for (int i = 0; i < columnCount; i++) {
        columnHeader[i] = this.getColumnID(i);
        // check renderer type
        r = RendererRegistry.getInstance().getRenderer(columnHeader[i]);
        if (r instanceof ITableCellEditorRenderer) {
            switch(((ITableCellEditorRenderer) r).getType()) {
                case 1:
                    editors[i] = new ComboBoxCellEditor(t, ((ITableCellEditorRenderer) r).getValues(), SWT.READ_ONLY);
                    break;
                case 2:
                    editors[i] = new CheckboxCellEditor(t);
                    break;
                default:
                    // editors[i] = new TextCellEditor(t);
                    editors[i] = new TextCellEditor(t);
            }
        } else {
            // editors[i] = new TextCellEditor(t);
            editors[i] = new TextCellEditor(t, SWT.WRAP);
        }
    }
    ((TreeViewer) this.viewer).setColumnProperties(columnHeader);
    ((TreeViewer) this.viewer).setCellEditors(editors);
    ((TreeViewer) this.viewer).setCellModifier(new TableCellModifier(((TreeViewer) viewer), this));
    TreeColumn[] cols = t.getColumns();
    for (int i = 0; i < cols.length; i++) {
        cols[i].dispose();
    }
    int columns = this.getTableColumnCount();
    String id = "";
    for (int i = 0; i < columns; i++) {
        TreeViewerColumn tc = new TreeViewerColumn((TreeViewer) viewer, SWT.LEFT);
        id = getColumnID(i);
        ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer(id);
        tc.getColumn().setText((tr != null ? tr.getHeader() : ""));
        tc.getColumn().setData(id);
        tc.getColumn().addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                de.janrufmonitor.ui.jface.application.action.IAction action = getOrderAction();
                if (action != null && action instanceof org.eclipse.jface.action.IAction) {
                    Event ev = new Event();
                    ev.widget = e.widget;
                    ((org.eclipse.jface.action.IAction) action).runWithEvent(ev);
                }
            }
        });
        tc.setLabelProvider(this.getTextCellLabelProvider(id));
        int width = Integer.parseInt(getConfiguration().getProperty(CFG_COLUMN_SIZE + id, "50"));
        if (width > -1) {
            tc.getColumn().setWidth(width);
        }
        tc.getColumn().addControlListener(new ControlAdapter() {

            public void controlResized(ControlEvent e) {
                if (e.widget instanceof TreeColumn) {
                    TreeColumn tc = (TreeColumn) e.widget;
                    if (tc.getData() != null) {
                        String column = (String) tc.getData();
                        int width = tc.getWidth();
                        getConfiguration().setProperty(CFG_COLUMN_SIZE + column, Integer.toString(width));
                        storeConfiguration();
                        m_logger.info("Set column size to " + width);
                    }
                }
            }
        });
    }
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) IAction(de.janrufmonitor.ui.jface.application.action.IAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ITableCellEditorRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellEditorRenderer) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Point(org.eclipse.swt.graphics.Point) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

IAction (de.janrufmonitor.ui.jface.application.action.IAction)2 ITableCellEditorRenderer (de.janrufmonitor.ui.jface.application.rendering.ITableCellEditorRenderer)2 ITableCellRenderer (de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 CheckboxCellEditor (org.eclipse.jface.viewers.CheckboxCellEditor)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)2 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)2 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 TreeEvent (org.eclipse.swt.events.TreeEvent)1 Point (org.eclipse.swt.graphics.Point)1