Search in sources :

Example 21 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class JcrNodeRenameHandler 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);
    InputDialog id = new InputDialog(shell, "Change Node Name", "Enter new name for node '" + node.getDescription() + "':", node.getLabel(), NodeNameValidator.INSTANCE);
    if (id.open() == IStatus.OK) {
        node.rename(id.getValue());
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) InputDialog(org.eclipse.jface.dialogs.InputDialog) ISelection(org.eclipse.jface.viewers.ISelection)

Example 22 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class AbstractOpenInBrowserHandler 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);
    IModule module = ServerUtil.getModule(node.getProject());
    if (module == null) {
        MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
        return null;
    }
    IServer[] servers = ServerUtil.getServersByModule(module, new NullProgressMonitor());
    if (servers == null || servers.length == 0) {
        MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
        return null;
    }
    IServer server = servers[0];
    URL url;
    try {
        url = getUrlToOpen(node, server);
    } catch (MalformedURLException e) {
        StatusManager.getManager().handle(new Status(Status.WARNING, Activator.PLUGIN_ID, "Url is invalid", e), StatusManager.SHOW);
        return null;
    }
    try {
        IWorkbenchBrowserSupport browserSupport = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getBrowserSupport();
        browserSupport.createBrowser("org.apache.sling.ide.openOnServer").openURL(url);
    } catch (PartInitException e) {
        StatusManager.getManager().handle(new Status(Status.WARNING, Activator.PLUGIN_ID, "Failed creating browser instance", e), StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) IModule(org.eclipse.wst.server.core.IModule) IServer(org.eclipse.wst.server.core.IServer) MalformedURLException(java.net.MalformedURLException) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Example 23 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class SightlyNatureTesterTest method testOnProject.

private void testOnProject(boolean hasSightlyNature) throws CoreException {
    if (hasSightlyNature) {
        projectAdapter.installFacet("sightly", "1.1");
    }
    final IPath sightlyTemplatePath = Path.fromPortableString("/jcr_root/libs/my/component/html.html");
    projectAdapter.createOrUpdateFile(sightlyTemplatePath, new ByteArrayInputStream(("<html />").getBytes()));
    // test on resources directly
    assertEquals("Test on project", hasSightlyNature, tester.test(projectRule.getProject(), "sightlyNature", new Object[0], null));
    assertEquals("Test on folder", hasSightlyNature, tester.test(projectRule.getProject().getFolder("jcr_root"), "sightlyNature", new Object[0], null));
    assertEquals("Test on file", hasSightlyNature, tester.test(projectRule.getProject().getFile(sightlyTemplatePath), "sightlyNature", new Object[0], null));
    // directly create the root node
    SyncDir syncDirNode = new SyncDir((IFolder) projectRule.getProject().findMember("jcr_root"));
    assertEquals("Test on sync dir node", hasSightlyNature, tester.test(syncDirNode, "sightlyNature", new Object[0], null));
    // test on jcr nodes
    JcrContentContentProvider contentProvider = new JcrContentContentProvider();
    JcrNode firstChild = (JcrNode) contentProvider.getChildren(syncDirNode)[0];
    assertEquals("Test on jcr node", hasSightlyNature, tester.test(firstChild, "sightlyNature", new Object[0], null));
}
Also used : JcrContentContentProvider(org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) SyncDir(org.apache.sling.ide.eclipse.ui.nav.model.SyncDir)

Example 24 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class AbstractClipboardHandler 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;
    }
    execute0(node);
    return null;
}
Also used : JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) ISelection(org.eclipse.jface.viewers.ISelection)

Example 25 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class JcrNodeDeleteHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    JcrNode node = SelectionUtils.getFirst(selection, JcrNode.class);
    if (node == null) {
        return null;
    }
    Shell shell = HandlerUtil.getActiveShellChecked(event);
    if (!MessageDialog.openConfirm(shell, "Delete Node", "Do you really want to delete '" + node.getLabel() + "'?")) {
        return null;
    }
    node.delete();
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) ISelection(org.eclipse.jface.viewers.ISelection)

Aggregations

JcrNode (org.apache.sling.ide.eclipse.ui.nav.model.JcrNode)27 ISelection (org.eclipse.jface.viewers.ISelection)10 Test (org.junit.Test)8 SyncDir (org.apache.sling.ide.eclipse.ui.nav.model.SyncDir)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 JcrContentContentProvider (org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider)3 Shell (org.eclipse.swt.widgets.Shell)3 PartInitException (org.eclipse.ui.PartInitException)3 IPropertyDescriptor (org.eclipse.ui.views.properties.IPropertyDescriptor)3 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 Point (org.eclipse.swt.graphics.Point)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NodeType (javax.jcr.nodetype.NodeType)1 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)1 JcrProperty (org.apache.sling.ide.eclipse.ui.nav.model.JcrProperty)1