Search in sources :

Example 1 with TableHierarchyRenderer

use of de.jaret.util.ui.table.renderer.TableHierarchyRenderer in project translationstudio8 by heartsome.

the class TableHierarchicalExample method createControls.

/**
     * Create the controls that compose the console test.
     * 
     */
protected void createControls(IHierarchicalJaretTableModel hierarchicalModel) {
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    _shell.setLayout(gl);
    GridData gd = new GridData(GridData.FILL_BOTH);
    _jt = new JaretTable(_shell, SWT.V_SCROLL | SWT.H_SCROLL);
    _jt.setLayoutData(gd);
    IHierarchicalJaretTableModel hmodel = hierarchicalModel;
    if (hierarchicalModel == null) {
        ITableNode root = new DummyTableNode("tn1", "tn1", "Root", "This the root node");
        ITableNode r1 = new DummyTableNode("tn11", "tn12", "1", "Child 1 of the root");
        ITableNode r2 = new DummyTableNode("tn12", "tn12", "2", "Child 2 of the root");
        ITableNode r3 = new DummyTableNode("tn13", "tn13", "3", "Child 3 of the root");
        root.addNode(r1);
        root.addNode(r2);
        root.addNode(r3);
        r1.addNode(new DummyTableNode("tn111", "tn111", "1", "A second level child"));
        r1.addNode(new DummyTableNode("tn112", "tn112", "2", "Another second level child"));
        ITableNode n1 = new DummyTableNode("tn131", "tn131", "1", "A second level child");
        r3.addNode(n1);
        ITableNode n2 = new DummyTableNode("tn132", "tn132", "2", "Another second level child");
        r3.addNode(n2);
        n1.addNode(new DummyTableNode("tn1311", "tn1311", "1", "A third level child"));
        n1.addNode(new DummyTableNode("tn1312", "tn1312", "2", "Another third level child"));
        DefaultHierarchicalTableModel dhmodel = new DefaultHierarchicalTableModel(root);
        hmodel = dhmodel;
        if (SUPPORT_DND) {
            // init the simple drag and drop handling
            initDND(_jt, _shell);
        }
    }
    _jt.setTableModel(hmodel);
    StdHierarchicalTableModel model = (StdHierarchicalTableModel) _jt.getTableModel();
    IColumn hcol = new HierarchyColumn();
    // create and setup hierarchy renderer
    final TableHierarchyRenderer hierarchyRenderer = new TableHierarchyRenderer();
    hierarchyRenderer.setLabelProvider(new LabelProvider());
    hierarchyRenderer.setDrawIcons(true);
    hierarchyRenderer.setDrawLabels(true);
    _jt.registerCellRenderer(hcol, hierarchyRenderer);
    model.addColumn(hcol);
    model.addColumn(new PropCol("b1", "column 1", "B1"));
    model.addColumn(new PropCol("t1", "column 2", "T1"));
    model.addColumn(new PropCol("t2", "column 3", "T2"));
    model.addColumn(new PropCol("t3", "column 4", "T3"));
    JaretTableActionFactory af = new JaretTableActionFactory();
    MenuManager mm = new MenuManager();
    mm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_CONFIGURECOLUMNS));
    _jt.setHeaderContextMenu(mm.createContextMenu(_jt));
    MenuManager rm = new MenuManager();
    rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTROWHEIGHT));
    rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTALLROWHEIGHTS));
    _jt.setRowContextMenu(rm.createContextMenu(_jt));
    TableControlPanel ctrlPanel = new TableControlPanel(_shell, SWT.NULL, _jt);
    Label l = new Label(_shell, SWT.NONE);
    l.setText("Level width:");
    final Scale levelWidthScale = new Scale(_shell, SWT.HORIZONTAL);
    levelWidthScale.setMaximum(40);
    levelWidthScale.setMinimum(0);
    levelWidthScale.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent ev) {
            int val = levelWidthScale.getSelection();
            hierarchyRenderer.setLevelWidth(val);
            _jt.redraw();
        }
    });
}
Also used : JaretTable(de.jaret.util.ui.table.JaretTable) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) JaretTableActionFactory(de.jaret.util.ui.table.util.action.JaretTableActionFactory) Scale(org.eclipse.swt.widgets.Scale) DefaultHierarchicalTableModel(de.jaret.util.ui.table.model.DefaultHierarchicalTableModel) TableHierarchyRenderer(de.jaret.util.ui.table.renderer.TableHierarchyRenderer) GridLayout(org.eclipse.swt.layout.GridLayout) IColumn(de.jaret.util.ui.table.model.IColumn) HierarchyColumn(de.jaret.util.ui.table.model.HierarchyColumn) PropCol(de.jaret.util.ui.table.model.PropCol) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IHierarchicalJaretTableModel(de.jaret.util.ui.table.model.IHierarchicalJaretTableModel) StdHierarchicalTableModel(de.jaret.util.ui.table.model.StdHierarchicalTableModel) ITableNode(de.jaret.util.ui.table.model.ITableNode) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Aggregations

JaretTable (de.jaret.util.ui.table.JaretTable)1 DefaultHierarchicalTableModel (de.jaret.util.ui.table.model.DefaultHierarchicalTableModel)1 HierarchyColumn (de.jaret.util.ui.table.model.HierarchyColumn)1 IColumn (de.jaret.util.ui.table.model.IColumn)1 IHierarchicalJaretTableModel (de.jaret.util.ui.table.model.IHierarchicalJaretTableModel)1 ITableNode (de.jaret.util.ui.table.model.ITableNode)1 PropCol (de.jaret.util.ui.table.model.PropCol)1 StdHierarchicalTableModel (de.jaret.util.ui.table.model.StdHierarchicalTableModel)1 TableHierarchyRenderer (de.jaret.util.ui.table.renderer.TableHierarchyRenderer)1 JaretTableActionFactory (de.jaret.util.ui.table.util.action.JaretTableActionFactory)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Label (org.eclipse.swt.widgets.Label)1 Scale (org.eclipse.swt.widgets.Scale)1