Search in sources :

Example 66 with CellEditor

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

the class AssignmentPropertySection method createControls.

@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
    super.createControls(parent, aTabbedPropertySheetPage);
    composite = getWidgetFactory().createFlatFormComposite(parent);
    // PTODO mhelleboid externalize tableviewer creation
    adapterFactory = new BusinessItemProviderAdapterFactory();
    tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
    tableViewer.setLabelProvider(new RepositoryFactoryProxyLabelProvider(adapterFactory));
    Table table = tableViewer.getTable();
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final String[] columnProperties = new String[] { Messages.getString("AssignmentPropertySection.Type"), Messages.getString("AssignmentPropertySection.Name"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Messages.getString("AssignmentPropertySection.Comment") };
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column1.setText(columnProperties[0]);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column2.setText(columnProperties[1]);
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnWeightData(1, 150, true));
    column3.setText(columnProperties[2]);
    tableViewer.setColumnProperties(columnProperties);
    final IItemPropertyDescriptor itemPropertyDescriptor = getItemPropertyDescriptor();
    tableViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return property.equals(columnProperties[2]);
        }

        public Object getValue(Object element, String property) {
            return EmfPropertyHelper.getValue(itemPropertyDescriptor, element);
        }

        public void modify(Object element, String property, Object value) {
            if (element instanceof TableItem) {
                TableItem tableItem = (TableItem) element;
                itemPropertyDescriptor.setPropertyValue(tableItem.getData(), value);
            }
        }
    });
    CellEditor[] cellEditors = new CellEditor[3];
    cellEditors[2] = new TextCellEditor(table);
    tableViewer.setCellEditors(cellEditors);
    createKeyListener(table);
    createSelectionListener();
    createPopupMenu();
    createDoubleClickListener();
    handleLayout(parent, table, column1, column2, column3);
    aTabbedPropertySheetPage.getSite().setSelectionProvider(this);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableItem(org.eclipse.swt.widgets.TableItem) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) BusinessItemProviderAdapterFactory(org.talend.designer.business.model.business.provider.BusinessItemProviderAdapterFactory) ICellModifier(org.eclipse.jface.viewers.ICellModifier) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IItemPropertyDescriptor(org.eclipse.emf.edit.provider.IItemPropertyDescriptor) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 67 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)

Example 68 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 69 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project Palladio-Editors-Sirius by PalladioSimulator.

the class InfrastructureSignaturesEditorSection method createViewerCellEditors.

/* (non-Javadoc)
	 * @see org.palladiosimulator.editors.commons.tabs.generic.EditorSection#createViewerCellEditors(org.eclipse.swt.widgets.Table)
	 */
@Override
protected CellEditor[] createViewerCellEditors(Table table) {
    CellEditor[] editors = new CellEditor[columnNames.length];
    editors[SIGNATURENAME_COLUMN_INDEX] = new TextCellEditor(table);
    // create 'DeleteCellValueListener' and as SelectionListener to the 'TableVewer'
    InfrastructureSignatureDeleteCellValueListener cellValueListener = new InfrastructureSignatureDeleteCellValueListener(viewer);
    viewer.addSelectionChangedListener(cellValueListener);
    editors[PARAMETER_COLUMN_INDEX] = new DialogCellEditor(table) {

        @Override
        protected Object openDialogBox(Control cellEditorWindow) {
            ParametersDialog dialog = new ParametersDialog(cellEditorWindow.getShell(), getSelectedSignature());
            if (dialog.open() == Dialog.OK)
                viewer.refresh();
            return null;
        }
    };
    return editors;
}
Also used : Control(org.eclipse.swt.widgets.Control) InfrastructureSignatureDeleteCellValueListener(org.palladiosimulator.editors.commons.tabs.operations.InfrastructureSignatureDeleteCellValueListener) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) DialogCellEditor(org.eclipse.jface.viewers.DialogCellEditor) DialogCellEditor(org.eclipse.jface.viewers.DialogCellEditor) EObject(org.eclipse.emf.ecore.EObject) ParametersDialog(org.palladiosimulator.editors.commons.dialogs.parameters.ParametersDialog) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 70 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project Palladio-Editors-Sirius by PalladioSimulator.

the class OperationsEditorSection method createViewerCellEditors.

/* (non-Javadoc)
	 * @see org.palladiosimulator.editors.commons.tabs.generic.EditorSection#createViewerCellEditors(org.eclipse.swt.widgets.Table)
	 */
@Override
protected CellEditor[] createViewerCellEditors(Table table) {
    CellEditor[] editors = new CellEditor[columnNames.length];
    editors[SIGNATURENAME_COLUMN_INDEX] = new TextCellEditor(table);
    // create 'DeleteCellValueListener' and as SelectionListener to the 'TableVewer'
    OperationDeleteCellValueListener cellValueListener = new OperationDeleteCellValueListener(viewer);
    viewer.addSelectionChangedListener(cellValueListener);
    editors[RETURNTYPE_COLUMN_INDEX] = new TypeDialogCellEditor(table, cellValueListener) {

        /* (non-Javadoc)
			 * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control)
			 */
        @Override
        protected Object openDialogBox(Control cellEditorWindow) {
            TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(getSelectedSignature());
            ArrayList<Object> filterList = new ArrayList<Object>();
            filterList.add(DataType.class);
            filterList.add(Repository.class);
            ArrayList<EReference> additionalReferences = new ArrayList<EReference>();
            CallDataTypeDialog dialog = new CallDataTypeDialog(cellEditorWindow.getShell(), filterList, additionalReferences, editingDomain.getResourceSet());
            dialog.setProvidedService(DataType.class);
            dialog.open();
            if (!(dialog.getResult() instanceof DataType))
                return null;
            return dialog.getResult();
        }
    };
    editors[PARAMETER_COLUMN_INDEX] = new DialogCellEditor(table) {

        @Override
        protected Object openDialogBox(Control cellEditorWindow) {
            ParametersDialog dialog = new ParametersDialog(cellEditorWindow.getShell(), getSelectedSignature());
            if (dialog.open() == Dialog.OK)
                viewer.refresh();
            return null;
        }
    };
    return editors;
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) TypeDialogCellEditor(org.palladiosimulator.editors.commons.tabs.operations.TypeDialogCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) DialogCellEditor(org.eclipse.jface.viewers.DialogCellEditor) ArrayList(java.util.ArrayList) TypeDialogCellEditor(org.palladiosimulator.editors.commons.tabs.operations.TypeDialogCellEditor) ParametersDialog(org.palladiosimulator.editors.commons.dialogs.parameters.ParametersDialog) CallDataTypeDialog(org.palladiosimulator.editors.commons.dialogs.datatype.CallDataTypeDialog) Control(org.eclipse.swt.widgets.Control) Repository(org.palladiosimulator.pcm.repository.Repository) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) TypeDialogCellEditor(org.palladiosimulator.editors.commons.tabs.operations.TypeDialogCellEditor) DialogCellEditor(org.eclipse.jface.viewers.DialogCellEditor) DataType(org.palladiosimulator.pcm.repository.DataType) OperationDeleteCellValueListener(org.palladiosimulator.editors.commons.tabs.operations.OperationDeleteCellValueListener) EObject(org.eclipse.emf.ecore.EObject) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

CellEditor (org.eclipse.jface.viewers.CellEditor)72 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)47 ICellModifier (org.eclipse.jface.viewers.ICellModifier)21 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 GridData (org.eclipse.swt.layout.GridData)21 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 TableViewer (org.eclipse.jface.viewers.TableViewer)14 Label (org.eclipse.swt.widgets.Label)14 Item (org.eclipse.swt.widgets.Item)12 Button (org.eclipse.swt.widgets.Button)11 TableItem (org.eclipse.swt.widgets.TableItem)11 Text (org.eclipse.swt.widgets.Text)9 ArrayList (java.util.ArrayList)8 SelectionListener (org.eclipse.swt.events.SelectionListener)8 Group (org.eclipse.swt.widgets.Group)8