Search in sources :

Example 16 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project tdi-studio-se by Talend.

the class UIManager method changeSchemasDetailView.

/**
     * 
     * cLi Comment method "refreshSchemasDetailView".
     * 
     * refresh schema details view by different provider.
     */
public void changeSchemasDetailView(final TreeViewer schemaDetailsViewer, boolean model) {
    if (schemaDetailsViewer == null || schemaDetailsViewer.getTree().isDisposed()) {
        return;
    }
    final Tree tree = schemaDetailsViewer.getTree();
    // removed all columns
    final TreeColumn[] columns = tree.getColumns();
    for (TreeColumn col : columns) {
        col.dispose();
    }
    if (columnTreeEditor != null) {
        columnTreeEditor.dispose();
        final Control editor = columnTreeEditor.getEditor();
        if (editor != null && !editor.isDisposed()) {
            editor.setVisible(false);
            editor.dispose();
        }
        columnTreeEditor = null;
    }
    if (columnMouseListener != null) {
        tree.removeMouseListener(columnMouseListener);
        columnMouseListener = null;
    }
    SchemaDetailsProvider provider = null;
    if (model) {
        // is properties model
        provider = new SchemaDetailsPropertiesProvider(this);
        List<String> columnProperties = new ArrayList<String>();
        List<CellEditor> cellEidors = new ArrayList<CellEditor>();
        for (EPropertyName pName : EPropertyName.values()) {
            columnProperties.add(pName.name());
            TreeColumn pColumn = new TreeColumn(tree, SWT.NONE);
            pColumn.setWidth(100);
            pColumn.setText(pName.getName());
            final CellEditor cellEditor;
            switch(pName) {
                case NAME:
                case LENGTH:
                case TAGLEVEL:
                // case CARD:
                case PATTERN:
                    cellEditor = new SchemaDetailsTextCellEditor(schemaDetailsViewer, pName);
                    break;
                case KEY:
                    pColumn.setToolTipText("Only one column can be set as key.");
                    cellEditor = new SchemaDetailsCheckBoxCellEditor(tree);
                    break;
                // break;
                case TYPE:
                    cellEditor = new ComboBoxCellEditor(tree, MultiSchemasUtil.getTalendTypeLabel(), SWT.READ_ONLY);
                    break;
                default:
                    cellEditor = null;
            }
            if (cellEditor != null) {
                cellEidors.add(cellEditor);
            }
        }
        schemaDetailsViewer.setColumnProperties(columnProperties.toArray(new String[0]));
        schemaDetailsViewer.setCellEditors(cellEidors.toArray(new CellEditor[0]));
        schemaDetailsViewer.setCellModifier(new SchemaDetailsPropertiesCellModifier(schemaDetailsViewer, this));
        // set sorter
        TreeColumn sorterColumn = tree.getColumn(0);
        sorterColumn.addListener(SWT.Selection, new SchemaDetailsViewerSorterListener(schemaDetailsViewer));
        tree.setSortColumn(sorterColumn);
        tree.setSortDirection(SWT.UP);
        schemaDetailsViewer.setSorter(new SchemaDetailsViewerSorter(schemaDetailsViewer, sorterColumn, tree.getSortDirection() == SWT.UP));
    } else {
        // is column model
        provider = new SchemaDetailsColumnsProvider(this);
        // first columm is fixed.
        TreeColumn propertyColumn = new TreeColumn(tree, SWT.NONE);
        propertyColumn.setWidth(80);
        propertyColumn.setResizable(false);
        //
        columnTreeEditor = new TreeEditor(tree);
        columnTreeEditor.horizontalAlignment = SWT.LEFT;
        columnTreeEditor.grabHorizontal = true;
        columnMouseListener = new SchemaDetailsColumnMouseAdapter(schemaDetailsViewer, columnTreeEditor, this);
        tree.addMouseListener(columnMouseListener);
    }
    schemaDetailsViewer.setContentProvider(provider);
    schemaDetailsViewer.setLabelProvider(provider);
//
}
Also used : SchemaDetailsTextCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsTextCellEditor) SchemaDetailsPropertiesCellModifier(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsPropertiesCellModifier) SchemaDetailsColumnsProvider(org.talend.designer.filemultischemas.ui.provider.column.SchemaDetailsColumnsProvider) SchemaDetailsPropertiesProvider(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsPropertiesProvider) TreeEditor(org.eclipse.swt.custom.TreeEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SchemaDetailsTextCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsTextCellEditor) SchemaDetailsCheckBoxCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsCheckBoxCellEditor) ArrayList(java.util.ArrayList) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SchemaDetailsViewerSorterListener(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsViewerSorterListener) SchemaDetailsColumnMouseAdapter(org.talend.designer.filemultischemas.ui.provider.column.SchemaDetailsColumnMouseAdapter) SchemaDetailsCheckBoxCellEditor(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsCheckBoxCellEditor) Control(org.eclipse.swt.widgets.Control) SchemaDetailsViewerSorter(org.talend.designer.filemultischemas.ui.provider.property.SchemaDetailsViewerSorter) EPropertyName(org.talend.designer.filemultischemas.data.EPropertyName) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) SchemaDetailsProvider(org.talend.designer.filemultischemas.ui.provider.SchemaDetailsProvider)

Example 17 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project tdi-studio-se by Talend.

the class MultiSchemasUI method createHeaderSashForm.

private void createHeaderSashForm(Composite headerComposite) {
    GridLayout layout;
    headerSashForm = new SashForm(headerComposite, SWT.NONE);
    headerSashForm.setLayout(new FillLayout());
    headerSashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
    headerSashForm.setSashWidth(ExternalMultiSchemasUIProperties.SASHFORM_WIDTH);
    //
    multiSchemasFilePreview = new MultiSchemasShadowProcessPreview(this, headerSashForm);
    multiSchemasFilePreview.newTablePreview();
    Composite struComp = new Composite(headerSashForm, SWT.NONE);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    struComp.setLayout(layout);
    headerSashForm.setWeights(ExternalMultiSchemasUIProperties.getHeaderSashformWeights());
    //
    fetchBtn = new Button(struComp, SWT.PUSH);
    fetchBtn.setText(ExternalMultiSchemasUIProperties.FETCH_LABEL);
    fetchBtn.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    //
    schemaTreeViewer = new TreeViewer(struComp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Tree tree = schemaTreeViewer.getTree();
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    schemaTreeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    // SchemasTreeDnD dnd = new SchemasTreeDnD(schemaTreeViewer);
    // dnd.addDragAndDrop();
    schemaTreeViewer.setContentProvider(new SchemasTreeContentProvider());
    schemaTreeViewer.setLabelProvider(new SchemasTreeLabelProvider());
    // schemaTreeViewer.setSorter(new ViewerSorter() {
    //
    // @SuppressWarnings("unchecked")
    // @Override
    // public int compare(Viewer viewer, Object e1, Object e2) {
    // if (e1 instanceof SchemasKeyData && e2 instanceof SchemasKeyData) {
    // return getComparator().compare(((SchemasKeyData) e1).getKeyName(), ((SchemasKeyData) e2).getKeyName());
    // }
    // return super.compare(viewer, e1, e2);
    // }
    //
    // });
    TreeColumn column = new TreeColumn(tree, SWT.LEFT);
    column.setWidth(55);
    //$NON-NLS-1$
    column.setText("Schema");
    column.setResizable(true);
    column = new TreeColumn(tree, SWT.LEFT);
    column.setWidth(100);
    //$NON-NLS-1$
    column.setText("Record");
    column.setResizable(true);
    column = new TreeColumn(tree, SWT.LEFT);
    column.setWidth(20);
    //$NON-NLS-1$
    column.setText("Separator");
    column.setResizable(true);
    schemaTreeViewer.setColumnProperties(new String[] { ExternalMultiSchemasUIProperties.COLUMN_KEY, ExternalMultiSchemasUIProperties.COLUMN_RECORD, ExternalMultiSchemasUIProperties.COLUMN_SEPARATOR });
    // hywang for 10263
    int columnCount = schemaTreeViewer.getTree().getColumnCount();
    CellEditor[] editors = new CellEditor[columnCount];
    for (int i = 0; i < columnCount; i++) {
        editors[i] = new TextCellEditor(schemaTreeViewer.getTree());
    }
    schemaTreeViewer.setCellEditors(editors);
    schemaTreeViewer.setCellModifier(new ICellModifier() {

        public void modify(Object element, String property, Object value) {
            if (element != null) {
                if (element instanceof TreeItem) {
                    TreeItem item = (TreeItem) element;
                    if (item.getData() != null) {
                        if (item.getData() instanceof SchemasKeyData) {
                            SchemasKeyData key = (SchemasKeyData) item.getData();
                            if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_KEY)) {
                                final boolean flag = checkKeyValue(key.getUniqueRecord(), value.toString());
                                if (flag) {
                                    key.setUniqueRecord(value.toString());
                                }
                            }
                            if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_RECORD)) {
                                key.setRecordType(value.toString());
                            }
                            if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_SEPARATOR)) {
                                key.setSeparator(value.toString());
                            }
                        // Object input = schemaTreeViewer.getInput();
                        // SchemasKeyData in = (SchemasKeyData) input;
                        // if (in.getChildren().contains(key)) {
                        // in.getChildren().remove(in.getChildren().indexOf(key));
                        // List<MultiMetadataColumn> colums = multiSchemaManager.createPropertiesColumns(key);
                        // key.setMetadataColumns(colums);
                        // in.getChildren().add(key);
                        // }
                        }
                        schemaTreeViewer.refresh();
                    }
                }
            }
        }

        public Object getValue(Object element, String property) {
            String record = "";
            if (element != null) {
                if (element instanceof SchemasKeyData) {
                    SchemasKeyData key = (SchemasKeyData) element;
                    if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_KEY)) {
                        record = key.getUniqueRecord();
                    }
                    if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_RECORD)) {
                        record = key.getRecordType();
                    }
                    if (property.equals(ExternalMultiSchemasUIProperties.COLUMN_SEPARATOR)) {
                        record = key.getSeparator();
                    }
                }
            }
            return record;
        }

        public boolean canModify(Object element, String property) {
            return true;
        }
    });
    Composite operateTreeComposite = new Composite(struComp, SWT.NONE);
    operateTreeComposite.setLayout(new GridLayout(3, false));
    operateTreeComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    addRow = new Button(operateTreeComposite, SWT.NONE);
    addRow.setText("Add");
    removeRow = new Button(operateTreeComposite, SWT.NONE);
    removeRow.setText("Remove");
    removeRow.setEnabled(false);
    editSchema = new Button(operateTreeComposite, SWT.NONE);
    editSchema.setText("Edit Columns");
    editSchema.setEnabled(false);
    Composite operation = new Composite(struComp, SWT.NONE);
    operation.setLayout(new GridLayout(2, false));
    operation.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    leftBtn = new Button(operation, SWT.PUSH);
    leftBtn.setToolTipText("Left");
    leftBtn.setImage(ImageProvider.getImage(EImage.LEFT_ICON));
    leftBtn.setEnabled(false);
    rightBtn = new Button(operation, SWT.PUSH);
    rightBtn.setToolTipText("Right");
    rightBtn.setImage(ImageProvider.getImage(EImage.RIGHT_ICON));
    rightBtn.setEnabled(false);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) CommandStackForComposite(org.talend.commons.ui.command.CommandStackForComposite) TreeItem(org.eclipse.swt.widgets.TreeItem) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) FillLayout(org.eclipse.swt.layout.FillLayout) SchemasTreeLabelProvider(org.talend.designer.filemultischemas.ui.provider.SchemasTreeLabelProvider) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SchemasTreeContentProvider(org.talend.designer.filemultischemas.ui.provider.SchemasTreeContentProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) Tree(org.eclipse.swt.widgets.Tree) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) MultiSchemasShadowProcessPreview(org.talend.designer.filemultischemas.ui.preview.MultiSchemasShadowProcessPreview) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 18 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project tdi-studio-se by Talend.

the class TreeTableController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#createControl
     * (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(final Composite parentComposite, final IElementParameter param, final int numInRow, final int nbInRow, int top, final Control lastControlPrm) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    final Composite container = parentComposite;
    final TreeViewer viewer = new TreeViewer(container, SWT.FULL_SELECTION | SWT.BORDER);
    viewer.getTree().setHeaderVisible(true);
    // key column
    TreeColumn column = new TreeColumn(viewer.getTree(), SWT.LEFT);
    column.setText("Key");
    column.setWidth(150);
    // columns for values
    if (param.getValue() != null) {
        List<Map<String, Object>> values = (List<Map<String, Object>>) param.getValue();
        for (int i = 0; i < values.size(); i++) {
            column = new TreeColumn(viewer.getTree(), SWT.LEFT);
            column.setText("Value" + i);
            column.setWidth(100);
        }
    }
    viewer.setContentProvider(new MyTreeContentProvider(param));
    viewer.setLabelProvider(new MyTableLableProvider(param));
    viewer.setInput(param);
    CLabel labelLabel2 = getWidgetFactory().createCLabel(container, param.getDisplayName());
    FormData formData = new FormData();
    if (lastControlPrm != null) {
        formData.left = new FormAttachment(lastControlPrm, 0);
    } else {
        formData.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    formData.top = new FormAttachment(0, top);
    labelLabel2.setLayoutData(formData);
    if (numInRow != 1) {
        labelLabel2.setAlignment(SWT.RIGHT);
    }
    // *********************
    formData = new FormData();
    int currentLabelWidth2 = STANDARD_LABEL_WIDTH;
    GC gc2 = new GC(labelLabel2);
    Point labelSize2 = gc2.stringExtent(param.getDisplayName());
    gc2.dispose();
    boolean needOffset = true;
    if ((labelSize2.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth2) {
        currentLabelWidth2 = labelSize2.x + ITabbedPropertyConstants.HSPACE;
        needOffset = false;
    }
    int tableHorizontalOffset = -5;
    if (numInRow == 1) {
        if (lastControlPrm != null) {
            if (needOffset) {
                formData.left = new FormAttachment(lastControlPrm, currentLabelWidth2 + tableHorizontalOffset);
            } else {
                formData.left = new FormAttachment(lastControlPrm, currentLabelWidth2);
            }
        } else {
            if (needOffset) {
                formData.left = new FormAttachment(0, currentLabelWidth2 + tableHorizontalOffset);
            } else {
                formData.left = new FormAttachment(0, currentLabelWidth2);
            }
        }
    } else {
        formData.left = new FormAttachment(labelLabel2, 0 + tableHorizontalOffset, SWT.RIGHT);
    }
    formData.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, 0);
    formData.top = new FormAttachment(0, top);
    int toolbarSize = 0;
    if (!param.isBasedOnSchema()) {
        Point size = viewer.getTree().computeSize(SWT.DEFAULT, SWT.DEFAULT);
        toolbarSize = size.y - 95;
    }
    int currentHeightEditor = viewer.getTree().getHeaderHeight() + param.getListItemsValue().length * viewer.getTree().getItemHeight() + viewer.getTree().getItemHeight() + toolbarSize;
    int minHeightEditor = viewer.getTree().getHeaderHeight() + getNumberLines(param) * viewer.getTree().getItemHeight() + viewer.getTree().getItemHeight() + toolbarSize;
    int ySize2 = Math.max(currentHeightEditor, minHeightEditor);
    formData.bottom = new FormAttachment(0, top + ySize2);
    viewer.getTree().setLayoutData(formData);
    this.dynamicProperty.setCurRowSize(ySize2 + ITabbedPropertyConstants.VSPACE);
    top += this.dynamicProperty.getCurRowSize();
    return null;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TreeColumn(org.eclipse.swt.widgets.TreeColumn) List(java.util.List) GC(org.eclipse.swt.graphics.GC) Map(java.util.Map) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 19 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project tdi-studio-se by Talend.

the class TnsEditorDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    TnsParser tnsparser = new TnsParser(tnsFile);
    treeViewer = new TreeViewer(parent);
    Tree tree = treeViewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 400;
    layoutData.widthHint = 300;
    tree.setLayoutData(layoutData);
    TreeColumn column1st = new TreeColumn(tree, SWT.NONE);
    //$NON-NLS-1$
    column1st.setText(Messages.getString("TnsEditorDialog.Service"));
    column1st.setWidth(200);
    TreeColumn column2nd = new TreeColumn(tree, SWT.NONE);
    //$NON-NLS-1$
    column2nd.setText(Messages.getString("TnsEditorDialog.Value"));
    column2nd.setWidth(200);
    treeViewer.setContentProvider(new TnsContentProvider());
    treeViewer.setLabelProvider(new TnsTableProvider());
    treeViewer.setInput(tnsparser.getTree());
    treeViewer.expandAll();
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            okPressed();
        }
    });
    return tree;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeColumn(org.eclipse.swt.widgets.TreeColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent)

Example 20 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project tdi-studio-se by Talend.

the class ThreadFilteredTree method configureTree.

/**
     * Configure the tree adding columns.
     */
private void configureTree() {
    for (TreeColumn column : getViewer().getTree().getColumns()) {
        column.dispose();
    }
    getViewer().getTree().setLinesVisible(true);
    getViewer().getTree().setHeaderVisible(true);
    for (Entry<String, Boolean> entry : columns.entrySet()) {
        ThreadColumn column = ThreadColumn.getColumn(entry.getKey());
        if (!columns.get(column.label)) {
            continue;
        }
        TreeColumn treeColumn = new TreeColumn(getViewer().getTree(), SWT.NONE);
        treeColumn.setText(column.label);
        treeColumn.setWidth(column.defalutWidth);
        treeColumn.setAlignment(column.initialAlignment);
        treeColumn.setToolTipText(column.toolTip);
        treeColumn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (e.widget instanceof TreeColumn) {
                    sortColumn((TreeColumn) e.widget);
                }
            }
        });
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

TreeColumn (org.eclipse.swt.widgets.TreeColumn)59 Tree (org.eclipse.swt.widgets.Tree)27 TreeViewer (org.eclipse.jface.viewers.TreeViewer)20 GridData (org.eclipse.swt.layout.GridData)18 TreeItem (org.eclipse.swt.widgets.TreeItem)18 Composite (org.eclipse.swt.widgets.Composite)16 GridLayout (org.eclipse.swt.layout.GridLayout)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 Point (org.eclipse.swt.graphics.Point)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 FillLayout (org.eclipse.swt.layout.FillLayout)7 Menu (org.eclipse.swt.widgets.Menu)7 CellEditor (org.eclipse.jface.viewers.CellEditor)6 Button (org.eclipse.swt.widgets.Button)6 ArrayList (java.util.ArrayList)5 IMenuListener (org.eclipse.jface.action.IMenuListener)5 IMenuManager (org.eclipse.jface.action.IMenuManager)5 ICellModifier (org.eclipse.jface.viewers.ICellModifier)5 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)5 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)4