Search in sources :

Example 6 with SimpleContentProposalProvider

use of org.eclipse.jface.fieldassist.SimpleContentProposalProvider 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)

Aggregations

SimpleContentProposalProvider (org.eclipse.jface.fieldassist.SimpleContentProposalProvider)6 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Composite (org.eclipse.swt.widgets.Composite)2 NodeTypeRegistry (org.apache.sling.ide.transport.NodeTypeRegistry)1 Repository (org.apache.sling.ide.transport.Repository)1 RepositoryException (org.apache.sling.ide.transport.RepositoryException)1 ComboContentAdapter (org.eclipse.jface.fieldassist.ComboContentAdapter)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 CCombo (org.eclipse.swt.custom.CCombo)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 GridLayout (org.eclipse.swt.layout.GridLayout)1