Search in sources :

Example 6 with Repository

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

the class JcrNewNodeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getCurrentSelection(event);
    JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
    if (node == null) {
        return null;
    }
    Shell shell = HandlerUtil.getActiveShell(event);
    if (!node.canCreateChild()) {
        MessageDialog.openInformation(shell, "Cannot create node", "Node is not covered by the workspace filter as defined in filter.xml");
        return null;
    }
    Repository repository = ServerUtil.getDefaultRepository(node.getProject());
    NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
    if (ntManager == null) {
        if (!doNotAskAgain) {
            MessageDialog dialog = new MessageDialog(null, "Unable to validate node type", null, "Unable to validate node types since project " + node.getProject().getName() + " is not associated with a server or the server is not started.", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "Continue (do not ask again)", "Continue" }, 1) {

                @Override
                protected void configureShell(Shell shell) {
                    super.configureShell(shell);
                    setShellStyle(getShellStyle() | SWT.SHEET);
                }
            };
            int choice = dialog.open();
            if (choice <= 0) {
                return null;
            }
            if (choice == 1) {
                doNotAskAgain = true;
            }
        }
    }
    final NodeType nodeType = node.getNodeType();
    if (nodeType != null && nodeType.getName() != null && nodeType.getName().equals("nt:file")) {
        MessageDialog.openInformation(shell, "Cannot create node", "Node of type nt:file cannot have children");
        return null;
    }
    try {
        final NewNodeDialog nnd = new NewNodeDialog(shell, node, ntManager);
        if (nnd.open() == IStatus.OK) {
            node.createChild(nnd.getValue(), nnd.getChosenNodeType());
            return null;
        }
    } catch (RepositoryException e1) {
        Activator.getDefault().getPluginLogger().warn("Could not open NewNodeDialog due to " + e1, e1);
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Repository(org.apache.sling.ide.transport.Repository) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) NodeType(javax.jcr.nodetype.NodeType) ISelection(org.eclipse.jface.viewers.ISelection) NodeTypeRegistry(org.apache.sling.ide.transport.NodeTypeRegistry) RepositoryException(org.apache.sling.ide.transport.RepositoryException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 7 with Repository

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

the class SlingLaunchpadBehaviour method start.

public void start(IProgressMonitor monitor) throws CoreException {
    boolean success = false;
    Result<ResourceProxy> result = null;
    monitor = SubMonitor.convert(monitor, "Starting server", 10).setWorkRemaining(50);
    Repository repository;
    RepositoryInfo repositoryInfo;
    OsgiClient client;
    try {
        repository = ServerUtil.connectRepository(getServer(), monitor);
        repositoryInfo = ServerUtil.getRepositoryInfo(getServer(), monitor);
        client = Activator.getDefault().getOsgiClientFactory().createOsgiClient(repositoryInfo);
    } catch (CoreException e) {
        setServerState(IServer.STATE_STOPPED);
        throw e;
    } catch (URISyntaxException e) {
        setServerState(IServer.STATE_STOPPED);
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
    }
    // 10/50 done
    monitor.worked(10);
    try {
        EmbeddedArtifactLocator artifactLocator = Activator.getDefault().getArtifactLocator();
        // 15/50 done
        installBundle(monitor, client, artifactLocator.loadSourceSupportBundle(), SUPPORT_SOURCE_BUNDLE_SYMBOLIC_NAME);
        // 20/50 done
        installBundle(monitor, client, artifactLocator.loadToolingSupportBundle(), SUPPORT_BUNDLE_SYMBOLIC_NAME);
    } catch (IOException | OsgiClientException e) {
        Activator.getDefault().getPluginLogger().warn("Failed reading the installation support bundle", e);
    }
    try {
        if (getServer().getMode().equals(ILaunchManager.DEBUG_MODE)) {
            debuggerConnection = new JVMDebuggerConnection(client);
            success = debuggerConnection.connectInDebugMode(launch, getServer(), SubMonitor.convert(monitor, 30));
        // 50/50 done
        } else {
            Command<ResourceProxy> command = repository.newListChildrenNodeCommand("/");
            result = command.execute();
            success = result.isSuccess();
            // 50/50 done
            monitor.worked(30);
        }
        if (success) {
            setServerState(IServer.STATE_STARTED);
        } else {
            setServerState(IServer.STATE_STOPPED);
            String message = "Unable to connect to the Server. Please make sure a server instance is running ";
            if (result != null) {
                message += " (" + result.toString() + ")";
            }
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message));
        }
    } catch (CoreException | RuntimeException e) {
        setServerState(IServer.STATE_STOPPED);
        throw e;
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) RepositoryInfo(org.apache.sling.ide.transport.RepositoryInfo) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Repository(org.apache.sling.ide.transport.Repository) CoreException(org.eclipse.core.runtime.CoreException) OsgiClient(org.apache.sling.ide.osgi.OsgiClient) EmbeddedArtifactLocator(org.apache.sling.ide.artifacts.EmbeddedArtifactLocator) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException)

Example 8 with Repository

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

the class JcrNode method getNodeType.

public NodeType getNodeType() {
    Repository repository = ServerUtil.getDefaultRepository(getProject());
    NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
    if (ntManager == null) {
        return null;
    }
    return ntManager.getNodeType(getPrimaryType());
}
Also used : Repository(org.apache.sling.ide.transport.Repository) NodeTypeRegistry(org.apache.sling.ide.transport.NodeTypeRegistry)

Example 9 with Repository

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

the class JcrNode method getSerializationKind.

private SerializationKind getSerializationKind(String nodeType) {
    final SerializationKindManager skm = new SerializationKindManager();
    final Repository repo = ServerUtil.getDefaultRepository(getProject());
    if (repo == null) {
        return getFallbackSerializationKind(nodeType);
    }
    try {
        skm.init(repo);
        //TODO: mixins not yet supported
        return skm.getSerializationKind(nodeType, new ArrayList<String>());
    } catch (RepositoryException e) {
        e.printStackTrace();
        return getFallbackSerializationKind(nodeType);
    }
}
Also used : Repository(org.apache.sling.ide.transport.Repository) RepositoryException(org.apache.sling.ide.transport.RepositoryException) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager)

Example 10 with Repository

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

Repository (org.apache.sling.ide.transport.Repository)10 NodeTypeRegistry (org.apache.sling.ide.transport.NodeTypeRegistry)7 RepositoryException (org.apache.sling.ide.transport.RepositoryException)5 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Logger (org.apache.sling.ide.log.Logger)2 IResource (org.eclipse.core.resources.IResource)2 Attribute (de.pdark.decentxml.Attribute)1 Document (de.pdark.decentxml.Document)1 Element (de.pdark.decentxml.Element)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NodeType (javax.jcr.nodetype.NodeType)1 EmbeddedArtifactLocator (org.apache.sling.ide.artifacts.EmbeddedArtifactLocator)1