X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=org.argeo.suite.workbench.rap%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fworkbench%2Fcommands%2FOpenDashboardEditor.java;fp=org.argeo.suite.workbench.rap%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fworkbench%2Fcommands%2FOpenDashboardEditor.java;h=6f335cc4475dcaea6e8606571156e45192aa9b2d;hp=0000000000000000000000000000000000000000;hb=1fb1ccc2edbf7cfbdd37efc618c52b8eebe4e6be;hpb=89c40e3a8444034d5a11954b5ca77d207f82ce69 diff --git a/org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/commands/OpenDashboardEditor.java b/org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/commands/OpenDashboardEditor.java new file mode 100644 index 0000000..6f335cc --- /dev/null +++ b/org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/commands/OpenDashboardEditor.java @@ -0,0 +1,52 @@ +package org.argeo.suite.workbench.commands; + +import javax.jcr.Node; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.argeo.connect.people.workbench.rap.editors.util.EntityEditorInput; +import org.argeo.jcr.JcrUtils; +import org.argeo.node.NodeUtils; +import org.argeo.suite.SuiteException; +import org.argeo.suite.workbench.AsUiPlugin; +import org.argeo.suite.workbench.parts.DefaultDashboardEditor; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Workaround to enable opening of a default editor */ +public class OpenDashboardEditor extends AbstractHandler { + public final static String ID = AsUiPlugin.PLUGIN_ID + ".openDashboardEditor"; + + private Repository repository; + + public Object execute(ExecutionEvent event) throws ExecutionException { + Session session = null; + try { + // TODO check roles + session = repository.login(); + IWorkbenchPage iwPage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); + Node homeNode = NodeUtils.getUserHome(session); + EntityEditorInput eei = new EntityEditorInput(homeNode.getIdentifier()); + IEditorPart iep = iwPage.findEditor(eei); + if (iep == null) { + iwPage.openEditor(eei, DefaultDashboardEditor.ID); + } else + iwPage.activate(iep); + } catch (RepositoryException | PartInitException re) { + throw new SuiteException("Unable to open dashboard", re); + } finally { + JcrUtils.logoutQuietly(session); + } + return null; + } + + public void setRepository(Repository repository) { + this.repository = repository; + } +}