Search in sources :

Example 96 with IStatus

use of org.eclipse.core.runtime.IStatus in project sling by apache.

the class JcrDropAdapterAssistant method validateDrop.

@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
    if (target instanceof JcrNode) {
        JcrNode jcrNode = (JcrNode) target;
        IStatus result = jcrNode.validateDrop(operation, transferType);
        if (!result.isOK()) {
            // check for details to be shown in the status bar
            final String message = result.getMessage();
            if (message != null && message.trim().length() > 0) {
                StatusLineUtils.setErrorMessage(2000, message);
            } else {
                StatusLineUtils.resetErrorMessage();
            }
        } else {
            StatusLineUtils.resetErrorMessage();
        }
        return result;
    }
    return Status.CANCEL_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode)

Example 97 with IStatus

use of org.eclipse.core.runtime.IStatus in project sling by apache.

the class JcrNode method validateDrop.

public IStatus validateDrop(int operation, TransferData transferType) {
    Repository repository = ServerUtil.getDefaultRepository(getProject());
    NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
    if (ntManager == null) {
        return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop element here because corresponding server is not started! (Needed to determine node types)", null);
    }
    // let's support plain files first
    try {
        if (getPrimaryType().equals("nt:file")) {
            // hard-code the most prominent case: cannot drop onto a file
            return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop element onto nt:file", null);
        }
        if (ntManager.isAllowedPrimaryChildNodeType(getPrimaryType(), "nt:file")) {
            return Status.OK_STATUS;
        } else {
            return Status.CANCEL_STATUS;
        }
    } catch (RepositoryException e) {
        Activator.getDefault().getPluginLogger().error("validateDrop: Got Exception while " + "verifying nodeType: " + e, e);
        return Status.CANCEL_STATUS;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Repository(org.apache.sling.ide.transport.Repository) NodeTypeRegistry(org.apache.sling.ide.transport.NodeTypeRegistry) RepositoryException(org.apache.sling.ide.transport.RepositoryException)

Example 98 with IStatus

use of org.eclipse.core.runtime.IStatus in project sling by apache.

the class JcrNode method handleDropResource.

private IStatus handleDropResource(IFolder targetFolder, IResource droppedResourceRoot, int detail) throws CoreException {
    if (targetFolder == null) {
        return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop on this type of element (yet)", null);
    }
    if (droppedResourceRoot == null) {
        throw new IllegalArgumentException("droppedResourceRoot must not be null");
    }
    IFile copyToFile = targetFolder.getFile(droppedResourceRoot.getName());
    IPath copyToPath = copyToFile.getFullPath();
    switch(detail) {
        case DND.DROP_COPY:
            {
                droppedResourceRoot.copy(copyToPath, true, new NullProgressMonitor());
                break;
            }
        case DND.DROP_MOVE:
            {
                droppedResourceRoot.move(copyToPath, true, new NullProgressMonitor());
                break;
            }
        default:
            {
                throw new IllegalStateException("Unknown drop action (detail: " + detail + ")");
            }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath)

Example 99 with IStatus

use of org.eclipse.core.runtime.IStatus in project sling by apache.

the class JcrNode method handleDrop.

public IStatus handleDrop(Object data, int detail) throws CoreException {
    IFolder folder = (IFolder) this.resource;
    if (data instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) data;
        Object firstElem = sel.getFirstElement();
        if (firstElem instanceof IResource) {
            IResource resource = (IResource) firstElem;
            return handleDropResource(folder, resource, detail);
        } else if (firstElem instanceof JcrNode) {
            JcrNode node = (JcrNode) firstElem;
            return handleDropNode(folder, node, detail);
        } else {
            return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop on this type of element (yet) [1]", null);
        }
    } else {
        return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop this type of selection", null);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 100 with IStatus

use of org.eclipse.core.runtime.IStatus in project sling by apache.

the class SlingWstServer method waitForServerToStart.

public void waitForServerToStart(long duration, TimeUnit timeUnit) throws InterruptedException {
    final CountDownLatch startLatch = new CountDownLatch(1);
    final IStatus[] statusHolder = new IStatus[1];
    server.start(ILaunchManager.RUN_MODE, new IOperationListener() {

        @Override
        public void done(IStatus result) {
            statusHolder[0] = result;
            startLatch.countDown();
        }
    });
    boolean success = startLatch.await(duration, timeUnit);
    assertThat("Server did not start in " + duration + " " + timeUnit, success, equalTo(true));
    assertThat("Unexpected IStatus when starting server", statusHolder[0], IStatusIsOk.isOk());
}
Also used : IOperationListener(org.eclipse.wst.server.core.IServer.IOperationListener) IStatus(org.eclipse.core.runtime.IStatus) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)1423 Status (org.eclipse.core.runtime.Status)500 CoreException (org.eclipse.core.runtime.CoreException)369 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)270 File (java.io.File)169 IOException (java.io.IOException)154 ArrayList (java.util.ArrayList)141 IPath (org.eclipse.core.runtime.IPath)138 IFile (org.eclipse.core.resources.IFile)130 Job (org.eclipse.core.runtime.jobs.Job)123 MultiStatus (org.eclipse.core.runtime.MultiStatus)113 InvocationTargetException (java.lang.reflect.InvocationTargetException)106 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)85 IProject (org.eclipse.core.resources.IProject)84 List (java.util.List)83 Path (org.eclipse.core.runtime.Path)52 Test (org.junit.Test)52 IResource (org.eclipse.core.resources.IResource)51 SubMonitor (org.eclipse.core.runtime.SubMonitor)51 Composite (org.eclipse.swt.widgets.Composite)44