Search in sources :

Example 11 with RepositoryException

use of org.apache.sling.ide.transport.RepositoryException 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 12 with RepositoryException

use of org.apache.sling.ide.transport.RepositoryException in project sling by apache.

the class NewNodeDialog method validateInput.

protected void validateInput() {
    final String firstInput = getText().getText();
    final String secondInput = comboSelection;
    try {
        if (secondInput == null || secondInput.length() == 0) {
            setErrorMessage("");
        } else if (ntManager == null) {
            setErrorMessage(null);
        } else if (ntManager.isAllowedPrimaryChildNodeType(parentNodeType, secondInput)) {
            // also check on the name, not only the type
            if (allChildNodeDefs == null) {
                setErrorMessage("No child node definitions found for " + parentNodeType);
            } else {
                boolean success = false;
                for (int i = 0; i < allChildNodeDefs.length; i++) {
                    NodeDefinition aChildNodeDef = allChildNodeDefs[i];
                    if (aChildNodeDef.getName() != null && aChildNodeDef.getName().length() > 0) {
                        if (firstInput.equals(aChildNodeDef.getName())) {
                            setErrorMessage(null);
                            return;
                        }
                    } else {
                        // mark success if there's a child node definition without a name
                        // (ie then it can be any name)
                        success = true;
                    }
                }
                if (success) {
                    setErrorMessage(null);
                    return;
                }
                StringBuffer details = new StringBuffer();
                for (NodeDefinition aChildNodeDef : allChildNodeDefs) {
                    if (details.length() != 0) {
                        details.append(", ");
                    }
                    details.append("(name=" + aChildNodeDef.getName() + ", required primary type(s)=");
                    String[] requiredPrimaryTypeNames = aChildNodeDef.getRequiredPrimaryTypeNames();
                    if (requiredPrimaryTypeNames == null) {
                        details.append("null");
                    } else {
                        for (int j = 0; j < requiredPrimaryTypeNames.length; j++) {
                            String rptn = requiredPrimaryTypeNames[j];
                            if (j > 0) {
                                details.append(",");
                            }
                            details.append(rptn);
                        }
                    }
                    details.append(")");
                }
                setErrorMessage("No matching child node definition found for " + parentNodeType + ". Expected one of: " + details);
            }
        } else {
            setErrorMessage("Error: Invalid child node type of " + parentNodeType);
        }
    } catch (RepositoryException e) {
        setErrorMessage("RepositoryException: " + e);
    }
}
Also used : NodeDefinition(javax.jcr.nodetype.NodeDefinition) RepositoryException(org.apache.sling.ide.transport.RepositoryException) Point(org.eclipse.swt.graphics.Point)

Example 13 with RepositoryException

use of org.apache.sling.ide.transport.RepositoryException in project sling by apache.

the class ImportRepositoryContentAction method run.

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, SerializationException, CoreException {
    // TODO: We should try to make this give 'nice' progress feedback (aka here's what I'm processing)
    monitor.beginTask("Repository import", IProgressMonitor.UNKNOWN);
    this.monitor = monitor;
    repository = ServerUtil.getConnectedRepository(server, monitor);
    this.builder = serializationManager.newBuilder(repository, ProjectUtil.getSyncDirectoryFile(project));
    SerializationKindManager skm;
    try {
        skm = new SerializationKindManager();
        skm.init(repository);
    } catch (RepositoryException e1) {
        throw new InvocationTargetException(e1);
    }
    filter = ProjectUtil.loadFilter(project);
    ProgressUtils.advance(monitor, 1);
    try {
        contentSyncRootDir = ProjectUtil.getSyncDirectory(project);
        repositoryImportRoot = projectRelativePath.makeRelativeTo(contentSyncRootDir.getProjectRelativePath()).makeAbsolute();
        contentSyncRoot = ProjectUtil.getSyncDirectoryFullPath(project).toFile();
        readVltIgnoresNotUnderImportRoot(contentSyncRootDir, repositoryImportRoot);
        ProgressUtils.advance(monitor, 1);
        Activator.getDefault().getPluginLogger().trace("Starting import; repository start point is {0}, workspace start point is {1}", repositoryImportRoot, projectRelativePath);
        recordNotIgnoredResources();
        ProgressUtils.advance(monitor, 1);
        crawlChildrenAndImport(repositoryImportRoot.toPortableString());
        removeNotIgnoredAndNotUpdatedResources(new NullProgressMonitor());
        ProgressUtils.advance(monitor, 1);
    } catch (OperationCanceledException e) {
        throw e;
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    } finally {
        if (builder != null) {
            builder.destroy();
            builder = null;
        }
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RepositoryException(org.apache.sling.ide.transport.RepositoryException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RepositoryException(org.apache.sling.ide.transport.RepositoryException) SerializationException(org.apache.sling.ide.serialization.SerializationException) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager)

Aggregations

RepositoryException (org.apache.sling.ide.transport.RepositoryException)13 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)5 Repository (org.apache.sling.ide.transport.Repository)5 NodeTypeRegistry (org.apache.sling.ide.transport.NodeTypeRegistry)4 Credentials (org.apache.commons.httpclient.Credentials)3 AuthScope (org.apache.commons.httpclient.auth.AuthScope)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 SerializationKindManager (org.apache.sling.ide.serialization.SerializationKindManager)3 ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)3 CoreException (org.eclipse.core.runtime.CoreException)3 JsonReader (com.google.gson.stream.JsonReader)2 JsonToken (com.google.gson.stream.JsonToken)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)2 Part (org.apache.commons.httpclient.methods.multipart.Part)2 StringPart (org.apache.commons.httpclient.methods.multipart.StringPart)2 SerializationKind (org.apache.sling.ide.serialization.SerializationKind)2 IStatus (org.eclipse.core.runtime.IStatus)2