Search in sources :

Example 26 with TreeItem

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

the class AbstractXMLConfigPage method initialize.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.componentdesigner.ui.wizard.creatcomponent.AbstractComponentPage#initialize()
     */
protected void initialize() {
    availableXmlTree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (availableXmlTree.getMenu() != null) {
                availableXmlTree.getMenu().dispose();
            }
            final TreeItem[] treeItem = ((Tree) event.getSource()).getSelection();
            Menu popMenu = new Menu(availableXmlTree);
            MenuItem itemNew = new MenuItem(popMenu, SWT.CASCADE);
            //$NON-NLS-1$
            itemNew.setText(Messages.getString("AbstractXMLConfigPage.New"));
            MenuItem itemDel = new MenuItem(popMenu, SWT.CASCADE);
            //$NON-NLS-1$
            itemDel.setText(Messages.getString("AbstractXMLConfigPage.Delete"));
            itemDel.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    TreeNodeData currentNodeData = (TreeNodeData) treeItem[0].getParentItem().getData();
                    currentNodeData.getXMLNode().removeChild(((TreeNodeData) treeItem[0].getData()).getXMLNode());
                    treeItem[0].dispose();
                }
            });
            final TreeNodeData treeNodeData = ((TreeNodeData) treeItem[0].getData());
            if (treeNodeData.isHasChildTreeNode()) {
                Menu subNewMenu = new Menu(itemNew);
                itemNew.setMenu(subNewMenu);
                Object[] subNodeNames = treeNodeData.getChildNodeNames();
                for (Object nodeName : subNodeNames) {
                    final MenuItem nodeMenuItem = new MenuItem(subNewMenu, SWT.CASCADE);
                    final String itemName = (String) nodeName;
                    nodeMenuItem.setText(itemName);
                    nodeMenuItem.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            TreeItem newItem = new TreeItem(treeItem[0], 0);
                            newItem.setText(itemName);
                            TreeNodeData newNodeData = null;
                            newNodeData = new TreeNodeData();
                            Node parentNode = treeNodeData.getXMLNode();
                            newNodeData.setXMLNode(parentNode.appendChild(parentNode.getOwnerDocument().createElement(itemName)));
                            //$NON-NLS-1$
                            newNodeData.setTreePath(treeNodeData.getTreePath() + "/" + itemName);
                            newNodeData.setTreeNode(ATreeNodeUtil.getTreeNodeByPath(newNodeData.getTreePath()));
                            newItem.setData(newNodeData);
                        }
                    });
                }
            } else {
                itemNew.setEnabled(false);
            }
            availableXmlTree.setMenu(popMenu);
            if (nodeAttrCompsite != null) {
                nodeAttrCompsite.dispose();
            }
            rebuildAttrComposite(treeNodeData);
            setComponentMinSize(treeNodeData.getTreeNode().getLabel());
            rightComposite.layout();
        }
    });
}
Also used : TreeNodeData(org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Node(org.w3c.dom.Node) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 27 with TreeItem

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

the class UpdateViewerHelper method initViewerState.

/**
     * 
     * init view state.
     */
public void initViewerState() {
    if (getViewer() == null) {
        return;
    }
    Tree tree = getViewer().getTree();
    for (TreeItem item : tree.getItems()) {
        Object data = item.getData();
        if (data != null) {
            if (data instanceof Job) {
                updateJobState((Job) data);
            }
        }
    }
    if (tree.getItems().length == 1) {
        getViewer().expandAll();
    }
    refreshSelectButton();
    checkUpdateStatus();
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Tree(org.eclipse.swt.widgets.Tree)

Example 28 with TreeItem

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

the class UpdateViewerHelper method selectAll.

/**
     * 
     * select all.
     * 
     */
public void selectAll(boolean state) {
    if (getViewer() == null) {
        return;
    }
    getViewer().getTree().setRedraw(false);
    TreeItem[] items = getViewer().getTree().getItems();
    for (TreeItem item : items) {
        Object data = item.getData();
        if (data != null) {
            if (data instanceof Job) {
                updateCheckedState(data, state);
            }
        }
    }
    getViewer().getTree().setRedraw(true);
    refreshSelectButton();
    checkUpdateStatus();
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 29 with TreeItem

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

the class JSONFileOutputStep2Form method initLinker.

private void initLinker(TreeItem node, TableItem[] tableItems) {
    FOXTreeNode treeNode = (FOXTreeNode) node.getData();
    IMetadataColumn column = treeNode.getColumn();
    Properties prop = System.getProperties();
    String os = prop.getProperty("os.name");
    boolean isLastOne = false;
    if (column != null) {
        for (int i = 0; i < tableItems.length; i++) {
            MetadataColumn metadataColumn = (MetadataColumn) tableItems[i].getData();
            if (metadataColumn.getLabel().equals(column.getLabel())) {
                // "isLastOne" directly to false
                if (os.startsWith("Linux")) {
                    isLastOne = true;
                }
                linker.addLoopLink(tableItems[i], tableItems[i].getData(), JSONViewer.getTree(), treeNode, isLastOne);
                break;
            }
        }
    }
    TreeItem[] children = node.getItems();
    for (int i = 0; i < children.length; i++) {
        initLinker(children[i], tableItems);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TreeItem(org.eclipse.swt.widgets.TreeItem) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Properties(java.util.Properties)

Example 30 with TreeItem

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

the class JSONFileOutputStep2Form method addJSONFileViewer.

private void addJSONFileViewer(final Composite mainComposite, final int width, final int height) {
    final Group group = Form.createGroup(mainComposite, 1, "Linker Target", height);
    GridData data = new GridData(GridData.FILL_BOTH);
    Composite composite = new Composite(group, SWT.BORDER);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(data);
    JSONViewer = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    data = new GridData(GridData.FILL_BOTH);
    JSONViewer.getControl().setLayoutData(data);
    JSONViewer.setUseHashlookup(true);
    Tree tree = JSONViewer.getTree();
    if (isReadOnly()) {
        tree.setEnabled(false);
    }
    tree.setLinesVisible(true);
    tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("JSON Tree");
    column1.setWidth(120);
    TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
    column2.setText("Related Column");
    column2.setWidth(100);
    TreeColumn column3 = new TreeColumn(tree, SWT.CENTER);
    column3.setText("Node Status");
    column3.setWidth(100);
    TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
    column4.setText("Default Value");
    column4.setWidth(100);
    tree.setHeaderVisible(true);
    JSONFileTreeViewerProvider provider = new JSONFileTreeViewerProvider();
    JSONViewer.setLabelProvider(provider);
    JSONViewer.setCellModifier(new ICellModifier() {

        public void modify(Object element, String property, Object value) {
            TreeItem treeItem = (TreeItem) element;
            FOXTreeNode node = (FOXTreeNode) treeItem.getData();
            if (property.equals("C1")) {
                node.setLabel((String) value);
            }
            if (property.equals("C4")) {
                node.setDefaultValue((String) value);
            }
            JSONViewer.refresh(node);
        }

        public Object getValue(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                //$NON-NLS-1$
                return node.getLabel();
            }
            if (property.equals("C4")) {
                //$NON-NLS-1$
                return node.getDefaultValue();
            }
            return null;
        }

        public boolean canModify(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                if (node.getLabel() != null && node.getLabel().length() > 0) {
                    return true;
                }
            }
            if (property.equals("C4")) {
                if (node.getDefaultValue() != null && node.getDefaultValue().length() > 0) {
                    return true;
                }
            }
            return false;
        }
    });
    JSONViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
    CellEditor editor = new TextCellEditor(JSONViewer.getTree());
    editor.addListener(new DialogErrorJSONLabelCellEditor(editor, "C1"));
    CellEditor editorDefault = new TextCellEditor(JSONViewer.getTree());
    editorDefault.addListener(new DialogErrorJSONLabelCellEditor(editorDefault, "C4"));
    JSONViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
    JSONViewer.setContentProvider(provider);
    // JSONViewer.setInput(treeData);
    JSONViewer.expandAll();
    createAction();
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(JSONViewer.getControl());
    JSONViewer.getControl().setMenu(menu);
    JSONViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });
    initToolBar(composite);
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) GridLayout(org.eclipse.swt.layout.GridLayout) JSONFileTreeViewerProvider(org.talend.repository.json.ui.wizards.view.JSONFileTreeViewerProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Tree(org.eclipse.swt.widgets.Tree) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

TreeItem (org.eclipse.swt.widgets.TreeItem)150 Tree (org.eclipse.swt.widgets.Tree)36 SelectionEvent (org.eclipse.swt.events.SelectionEvent)23 GridData (org.eclipse.swt.layout.GridData)23 Point (org.eclipse.swt.graphics.Point)21 ArrayList (java.util.ArrayList)20 TreeColumn (org.eclipse.swt.widgets.TreeColumn)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 Composite (org.eclipse.swt.widgets.Composite)14 TableItem (org.eclipse.swt.widgets.TableItem)14 SelectionListener (org.eclipse.swt.events.SelectionListener)13 Group (org.eclipse.swt.widgets.Group)13 Button (org.eclipse.swt.widgets.Button)12 Table (org.eclipse.swt.widgets.Table)12 Event (org.eclipse.swt.widgets.Event)11 List (java.util.List)10 Label (org.eclipse.swt.widgets.Label)10 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)9 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)9