Search in sources :

Example 21 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdi-studio-se by Talend.

the class HL7OutputUI method addXMLViewer.

/**
     * create xml viewer.
     *
     * @param mainComposite
     * @param form
     * @param width
     * @param height
     */
private void addXMLViewer(final Composite mainComposite, final int width, final int height) {
    // Group Schema Viewer
    Group group = Form.createGroup(mainComposite, 1, "Linker Target", height);
    // group.setBackgroundMode(SWT.INHERIT_FORCE);
    xmlViewer = new TreeViewer(group, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    xmlViewer.getControl().setLayoutData(gridData);
    xmlViewer.setUseHashlookup(true);
    Tree tree = xmlViewer.getTree();
    if (canModify || isRespo) {
        tree.setEnabled(false);
    }
    tree.setLinesVisible(true);
    tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("HL7 Structure");
    column1.setWidth(170);
    // Related Column
    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(90);
    TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
    column4.setText("Default Value");
    column4.setWidth(90);
    tree.setHeaderVisible(true);
    // tree.setBackgroundMode(SWT.INHERIT_NONE);
    HL7TargetTreeViewerProvider provider = new HL7TargetTreeViewerProvider();
    xmlViewer.setLabelProvider(provider);
    xmlViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            HL7TreeNode node = (HL7TreeNode) 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;
        }

        @Override
        public Object getValue(Object element, String property) {
            HL7TreeNode node = (HL7TreeNode) element;
            if (property.equals("C1")) {
                return node.getLabel();
            }
            if (property.equals("C4")) {
                return node.getDefaultValue();
            }
            return null;
        }

        @Override
        public void modify(Object element, String property, Object value) {
            TreeItem treeItem = (TreeItem) element;
            HL7TreeNode node = (HL7TreeNode) treeItem.getData();
            if (property.equals("C1")) {
                if (value != null && value.toString().length() == 0) {
                    value = node.getLabel();
                }
                node.setLabel((String) value);
            }
            if (property.equals("C4")) {
                node.setDefaultValue((String) value);
            }
            xmlViewer.refresh(node);
        }
    });
    //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    xmlViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
    CellEditor editor = new TextCellEditor(xmlViewer.getTree());
    editor.addListener(new DialogErrorXMLLabelCellEditor(editor, "C1"));
    // add by wzhang for bug 8572. set Default value column to be edit.
    CellEditor editorDefault = new TextCellEditor(xmlViewer.getTree());
    editorDefault.addListener(new DialogErrorXMLLabelCellEditor(editorDefault, "C4"));
    xmlViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
    xmlViewer.setContentProvider(provider);
    xmlViewer.setInput(this.hl7Manager.getTreeData());
    xmlViewer.expandAll();
    createAction();
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            HL7OutputUI.this.fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(xmlViewer.getControl());
    xmlViewer.getControl().setMenu(menu);
    xmlViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
        // TODO Auto-generated method stub
        }
    });
    refreshXMLViewer(null);
}
Also used : Group(org.eclipse.swt.widgets.Group) 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) 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) HL7TargetTreeViewerProvider(org.talend.designer.hl7.ui.edit.HL7TargetTreeViewerProvider) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 22 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdi-studio-se by Talend.

the class AddListDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Composite baseCom = (Composite) super.createDialogArea(parent);
    Composite createDialogArea = (Composite) super.createDialogArea(parent);
    createDialogArea.setLayout(new FillLayout());
    SashForm baseCom = new SashForm(createDialogArea, SWT.VERTICAL | SWT.BORDER);
    treeViewer = new TreeViewer(baseCom, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
    tree = treeViewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    // Paramater Name Column
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("Parameter Name");
    column1.setWidth(200);
    // Array Index Column
    TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
    column2.setText("Array Index");
    column2.setWidth(100);
    treeViewer.setColumnProperties(new String[] { NAME, INDEX });
    CellEditor editor = new TextCellEditor(treeViewer.getTree());
    // CellEditor nameEditor = new ComboBoxCellEditor(treeViewer.getTree());
    treeViewer.setCellEditors(new CellEditor[] { null, editor });
    treeViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            if (element instanceof ParameterInfo) {
                ParameterInfo para = (ParameterInfo) element;
                if (INDEX.equals(property) && para.getArraySize() != 0) {
                    // if item is array it can edit.
                    return true;
                }
            }
            return false;
        }

        public Object getValue(Object element, String property) {
            if (element instanceof ParameterInfo) {
                ParameterInfo para = (ParameterInfo) element;
                if (INDEX.equals(property)) {
                    return para.getIndex() == null ? "" : para.getIndex();
                } else if (NAME.equals(property)) {
                    return para.getName();
                }
            }
            return null;
        }

        public void modify(Object element, String property, Object value) {
            if (element instanceof TreeItem) {
                ParameterInfo para = (ParameterInfo) ((TreeItem) element).getData();
                if (INDEX.equals(property)) {
                    para.setIndex(value.toString());
                }
            }
            treeViewer.refresh();
        }
    });
    // DrillDownAdapter adapter = new DrillDownAdapter(treeView);
    treeViewer.setContentProvider(new WebServiceTreeContentProvider());
    treeViewer.setLabelProvider(new WebServiceTreeLabelProvider());
    treeViewer.setInput(para);
    treeViewer.addSelectionChangedListener(selectAction);
    // tree.addSelectionListener(new SelectionAdapter() {
    //
    // @Override
    // public void widgetSelected(SelectionEvent e) {
    // TreeItem[] selects = tree.getSelection();
    // ISelection select = (ISelection) treeViewer.getSelection();
    // Object obj = ((IStructuredSelection) select).getFirstElement();
    // if (obj instanceof ParameterInfo) {
    // // if (((ParameterInfo) obj).getParameterInfos().size() > 0) {
    // // // ErrorDialog dialog = new ErrorDialog(parentShell, "", "", null, 0);
    // // // dialog.open();
    // // selectedParaInfo = null;
    // // } else {
    // selectedParaInfo = (ParameterInfo) obj;
    // // }
    // }
    // }
    //
    // });
    treeViewer.getTree().addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            createAllTypeDialog();
        }
    });
    return baseCom;
}
Also used : 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) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) ParameterInfo(org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo) SashForm(org.eclipse.swt.custom.SashForm) WebServiceTreeLabelProvider(org.talend.designer.webservice.ui.tree.WebServiceTreeLabelProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) WebServiceTreeContentProvider(org.talend.designer.webservice.ui.tree.WebServiceTreeContentProvider)

Example 23 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project bndtools by bndtools.

the class NewTypeWizardPage method createSuperInterfacesControls.

/**
     * Creates the controls for the superclass name field. Expects a <code>GridLayout</code> with at least 3 columns.
     *
     * @param composite
     *            the parent composite
     * @param nColumns
     *            number of columns to span
     */
protected void createSuperInterfacesControls(Composite composite, int nColumns) {
    //$NON-NLS-1$
    final String INTERFACE = "interface";
    fSuperInterfacesDialogField.doFillIntoGrid(composite, nColumns);
    final TableViewer tableViewer = fSuperInterfacesDialogField.getTableViewer();
    tableViewer.setColumnProperties(new String[] { INTERFACE });
    TableTextCellEditor cellEditor = new TableTextCellEditor(tableViewer, 0) {

        @Override
        protected void doSetFocus() {
            if (text != null) {
                text.setFocus();
                text.setSelection(text.getText().length());
                checkSelection();
                checkDeleteable();
                checkSelectable();
            }
        }
    };
    JavaTypeCompletionProcessor superInterfaceCompletionProcessor = new JavaTypeCompletionProcessor(false, false, true);
    superInterfaceCompletionProcessor.setCompletionContextRequestor(new CompletionContextRequestor() {

        @Override
        public StubTypeContext getStubTypeContext() {
            return getSuperInterfacesStubTypeContext();
        }
    });
    @SuppressWarnings("deprecation") org.eclipse.jface.contentassist.SubjectControlContentAssistant contentAssistant = ControlContentAssistHelper.createJavaContentAssistant(superInterfaceCompletionProcessor);
    Text cellEditorText = cellEditor.getText();
    @SuppressWarnings({ "deprecation", "unused" }) org.eclipse.ui.contentassist.ContentAssistHandler contentAssistantHandler = org.eclipse.ui.contentassist.ContentAssistHandler.createHandlerForText(cellEditorText, contentAssistant);
    TextFieldNavigationHandler.install(cellEditorText);
    cellEditor.setContentAssistant(contentAssistant);
    tableViewer.setCellEditors(new CellEditor[] { cellEditor });
    tableViewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            Object el = element;
            if (el instanceof Item)
                el = ((Item) el).getData();
            ((InterfaceWrapper) el).interfaceName = (String) value;
            fSuperInterfacesDialogField.elementChanged((InterfaceWrapper) el);
        }

        @Override
        public Object getValue(Object element, String property) {
            return ((InterfaceWrapper) element).interfaceName;
        }

        @Override
        public boolean canModify(Object element, String property) {
            return true;
        }
    });
    tableViewer.getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.F2 && event.stateMask == 0) {
                ISelection selection = tableViewer.getSelection();
                if (!(selection instanceof IStructuredSelection))
                    return;
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                tableViewer.editElement(structuredSelection.getFirstElement(), 0);
            }
        }
    });
    GridData gd = (GridData) fSuperInterfacesDialogField.getListControl(null).getLayoutData();
    if (fTypeKind == CLASS_TYPE) {
        gd.heightHint = convertHeightInCharsToPixels(3);
    } else {
        gd.heightHint = convertHeightInCharsToPixels(6);
    }
    gd.grabExcessVerticalSpace = false;
    gd.widthHint = getMaxFieldWidth();
}
Also used : KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) JavaTypeCompletionProcessor(org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor) KeyEvent(org.eclipse.swt.events.KeyEvent) Item(org.eclipse.swt.widgets.Item) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ISelection(org.eclipse.jface.viewers.ISelection) GridData(org.eclipse.swt.layout.GridData) StubTypeContext(org.eclipse.jdt.internal.corext.refactoring.StubTypeContext) CompletionContextRequestor(org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor) TableViewer(org.eclipse.jface.viewers.TableViewer) TableTextCellEditor(org.eclipse.jdt.internal.ui.dialogs.TableTextCellEditor)

Aggregations

ICellModifier (org.eclipse.jface.viewers.ICellModifier)23 CellEditor (org.eclipse.jface.viewers.CellEditor)21 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)21 Item (org.eclipse.swt.widgets.Item)13 GridData (org.eclipse.swt.layout.GridData)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 Composite (org.eclipse.swt.widgets.Composite)10 TableItem (org.eclipse.swt.widgets.TableItem)10 GridLayout (org.eclipse.swt.layout.GridLayout)8 TableViewer (org.eclipse.jface.viewers.TableViewer)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 Label (org.eclipse.swt.widgets.Label)6 TableColumn (org.eclipse.swt.widgets.TableColumn)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 ToolItem (org.eclipse.swt.widgets.ToolItem)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)4 SelectionListener (org.eclipse.swt.events.SelectionListener)4