Search in sources :

Example 61 with CellEditor

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

the class XmlDirectEditPolicy method getDirectEditCommand.

@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
    Command command = null;
    CellEditor editor = request.getCellEditor();
    Object directEditFeature = request.getDirectEditFeature();
    if (directEditFeature instanceof DirectEditType) {
        DirectEditType type = (DirectEditType) directEditFeature;
        if (getHost().getModel() instanceof AbstractNode) {
            AbstractNode model = (AbstractNode) getHost().getModel();
            switch(type) {
                case EXPRESSION:
                case NODE_NAME:
                    command = new DirectEditCommand(getHost(), model, type, request.getCellEditor().getValue());
                    break;
                case VAR_NODE_TYPE:
                    if (editor instanceof ComboBoxCellEditor) {
                        ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
                        int selectIndex = (Integer) combo.getValue();
                        command = new DirectEditCommand(getHost(), model, type, combo.getItems()[selectIndex]);
                    }
                    break;
                case LOOKUP_MODEL:
                case MATCH_MODEL:
                case JOIN_MODEL:
                case PERSISTENT_MODEL:
                case OUTPUT_REJECT:
                case LOOK_UP_INNER_JOIN_REJECT:
                    if (editor instanceof ComboBoxCellEditor) {
                        ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
                        int selectIndex = (Integer) combo.getValue();
                        command = new TreeSettingDirectEditCommand(model, type, combo.getItems()[selectIndex]);
                    }
                    break;
                case EXPRESSION_FILTER:
                    if (editor instanceof TextCellEditor) {
                        command = new TreeSettingDirectEditCommand(model, type, request.getCellEditor().getValue());
                    }
                default:
                    break;
            }
        } else {
            switch(type) {
                case LOOKUP_MODEL:
                case MATCH_MODEL:
                case JOIN_MODEL:
                case PERSISTENT_MODEL:
                case OUTPUT_REJECT:
                case LOOK_UP_INNER_JOIN_REJECT:
                case ALL_IN_ONE:
                case ENABLE_EMPTY_ELEMENT:
                    if ((editor instanceof ComboBoxCellEditor)) {
                        ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
                        int selectIndex = (Integer) combo.getValue();
                        command = new TreeSettingDirectEditCommand(getHost().getModel(), type, combo.getItems()[selectIndex]);
                    }
                    break;
                case EXPRESSION_FILTER:
                    command = new TreeSettingDirectEditCommand(getHost().getModel(), type, request.getCellEditor().getValue());
            }
        }
    }
    return command;
}
Also used : DirectEditType(org.talend.designer.gefabstractmap.part.directedit.DirectEditType) DirectEditCommand(org.talend.designer.xmlmap.commands.DirectEditCommand) Command(org.eclipse.gef.commands.Command) TreeSettingDirectEditCommand(org.talend.designer.xmlmap.commands.TreeSettingDirectEditCommand) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) DirectEditCommand(org.talend.designer.xmlmap.commands.DirectEditCommand) TreeSettingDirectEditCommand(org.talend.designer.xmlmap.commands.TreeSettingDirectEditCommand) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TreeSettingDirectEditCommand(org.talend.designer.xmlmap.commands.TreeSettingDirectEditCommand) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 62 with CellEditor

use of org.eclipse.jface.viewers.CellEditor 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 63 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project sling by apache.

the class JcrEditingSupport method doGetCellEditor.

protected CellEditor doGetCellEditor(Object element) {
    if (!canEdit(element)) {
        return null;
    }
    switch(columnId) {
        case NAME:
            {
                // no validator needed - any string is OK
                return new TextCellEditor(tableViewer.getTable());
            }
        case TYPE:
            {
                // using a dropdown editor
                final ComboBoxCellEditor editor = new ComboBoxCellEditor(tableViewer.getTable(), PropertyTypeSupport.PROPERTY_TYPES, SWT.NONE);
                editor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION);
                return editor;
            }
        case VALUE:
            {
                final Field field = asField(element);
                if (getNode().getProperty(field.getPropertyName()).isMultiple()) {
                    // then launch the MVPEditor instead of returning an editor here
                    return new MVNCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
                }
                if (field.getPropertyType() == PropertyType.DATE) {
                    return new DateTimeCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
                }
                if (field.getPropertyType() == PropertyType.BOOLEAN) {
                    return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
                }
                CellEditor editor;
                if (field.getPropertyName().equals("jcr:primaryType")) {
                    editor = new TextCellEditor(tableViewer.getTable()) {

                        @Override
                        protected Control createControl(Composite parent) {
                            Text text = (Text) super.createControl(parent);
                            Repository repository = ServerUtil.getDefaultRepository(getNode().getProject());
                            NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
                            if (ntManager == null) {
                                return text;
                            }
                            try {
                                Collection<String> types = ntManager.getAllowedPrimaryChildNodeTypes(getNode().getParent().getPrimaryType());
                                SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(types.toArray(new String[0]));
                                proposalProvider.setFiltering(true);
                                ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(), proposalProvider, null, null);
                                adapter.setPropagateKeys(true);
                                adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
                                return text;
                            } catch (RepositoryException e) {
                                return text;
                            }
                        }
                    };
                } else {
                    editor = new TextCellEditor(tableViewer.getTable());
                }
                // value might require a validator depending on the property type
                int propertyType = getNode().getPropertyType(field.getPropertyName());
                switch(propertyType) {
                    case PropertyType.STRING:
                    case PropertyType.NAME:
                        {
                            //TODO: check jcr rules for name
                            break;
                        }
                    case PropertyType.DECIMAL:
                        {
                            editor.setValidator(new DecimalValidator(editor));
                            break;
                        }
                    default:
                        {
                            //TODO
                            break;
                        }
                }
                return editor;
            }
        case MULTIPLE:
            {
                if (element instanceof NewRow) {
                    return null;
                }
                return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
            }
        default:
            {
                throw new IllegalStateException("Unknown columnId: " + columnId);
            }
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Text(org.eclipse.swt.widgets.Text) RepositoryException(org.apache.sling.ide.transport.RepositoryException) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) SimpleContentProposalProvider(org.eclipse.jface.fieldassist.SimpleContentProposalProvider) Repository(org.apache.sling.ide.transport.Repository) NodeTypeRegistry(org.apache.sling.ide.transport.NodeTypeRegistry) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 64 with CellEditor

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

the class TableKeyListener method startSupport.

/**
     * After the cell editors have been set on tableviewer, this method should be called to start giving keyboard
     * support.
     */
public void startSupport() {
    /* add table key listener */
    getTable().addKeyListener(new TableKeyListener(this));
    /* add table traverse listener */
    getTable().addTraverseListener(new TableTraverseListener(this));
    /* add table-textcelleditors key and traverse listeners */
    CellEditor[] cellEditors = fTableViewer.getCellEditors();
    if (cellEditors != null) {
        for (int colIndex = 0; colIndex < cellEditors.length; colIndex++) {
            CellEditor cellEditor = cellEditors[colIndex];
            if (cellEditor != null) {
                // cellEditor.getControl().addKeyListener(new
                // CellEditorKeyListener(this, cellEditor, colIndex));
                cellEditor.getControl().addTraverseListener(new CellEditorTraverseListener(this, cellEditor, colIndex));
            }
        }
    }
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor)

Aggregations

CellEditor (org.eclipse.jface.viewers.CellEditor)64 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)41 ICellModifier (org.eclipse.jface.viewers.ICellModifier)21 GridData (org.eclipse.swt.layout.GridData)20 SelectionEvent (org.eclipse.swt.events.SelectionEvent)19 Composite (org.eclipse.swt.widgets.Composite)19 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Map (java.util.Map)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 HashMap (java.util.HashMap)14 Label (org.eclipse.swt.widgets.Label)14 TableViewer (org.eclipse.jface.viewers.TableViewer)13 Item (org.eclipse.swt.widgets.Item)12 Button (org.eclipse.swt.widgets.Button)11 TableItem (org.eclipse.swt.widgets.TableItem)11 SelectionListener (org.eclipse.swt.events.SelectionListener)8 Group (org.eclipse.swt.widgets.Group)8 TableColumn (org.eclipse.swt.widgets.TableColumn)8 Text (org.eclipse.swt.widgets.Text)8