Browser navigation
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 14 May 2018 11:11:26 +0000 (13:11 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 14 May 2018 11:11:26 +0000 (13:11 +0200)
org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoOfficeRapE4App.java
org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java [new file with mode: 0644]
org.argeo.suite.e4/OSGI-INF/systemE4Service.xml
org.argeo.suite.e4/src/org/argeo/suite/e4/parts/AbstractSuiteDashboard.java
org.argeo.suite.e4/src/org/argeo/suite/e4/parts/DefaultDashboardEditor.java

index 473406fa6a1aa941c6eb0f805b24b2ba27483511..92fcfa377f069fbb6d7bfb900f63db4b27606100 100644 (file)
@@ -8,6 +8,7 @@ public class ArgeoOfficeRapE4App extends AbstractRapE4App {
                setPageTitle("Argeo Office");
                setE4Xmi("org.argeo.suite.e4/e4xmi/argeo-office.e4xmi");
                setPath("/office");
+               setLifeCycleUri("bundleclass://org.argeo.suite.e4.rap/org.argeo.suite.e4.rap.ArgeoSuiteLoginLifecycle");
        }
 
 }
diff --git a/org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java b/org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java
new file mode 100644 (file)
index 0000000..3262311
--- /dev/null
@@ -0,0 +1,66 @@
+package org.argeo.suite.e4.rap;
+
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import javax.inject.Inject;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.cms.e4.rap.CmsLoginLifecycle;
+import org.argeo.connect.ui.SystemWorkbenchService;
+import org.argeo.jcr.JcrUtils;
+
+public class ArgeoSuiteLoginLifecycle extends CmsLoginLifecycle {
+       private final static Log log = LogFactory.getLog(ArgeoSuiteLoginLifecycle.class);
+       @Inject
+       SystemWorkbenchService systemWorkbenchService;
+
+       @Inject
+       Repository repository;
+
+       @Override
+       protected void startupComplete() {
+               loadState();
+       }
+
+       @Override
+       protected void stateChanged() {
+               loadState();
+       }
+
+       private void loadState() {
+               String state = getState();
+               if (state != null && state.startsWith("/")) {
+                       Session session = null;
+                       try {
+                               Subject subject = getSubject();
+                               session = Subject.doAs(subject, new PrivilegedExceptionAction<Session>() {
+
+                                       @Override
+                                       public Session run() throws PrivilegedActionException {
+                                               try {
+                                                       return repository.login();
+                                               } catch (RepositoryException e) {
+                                                       throw new PrivilegedActionException(e);
+                                               }
+                                       }
+
+                               });
+                               if (state.startsWith("/")) {
+                                       Node node = session.getNode(state);
+                                       systemWorkbenchService.openEntityEditor(node);
+                               }
+                       } catch (RepositoryException | PrivilegedActionException e) {
+                               log.error("Cannot load state " + state, e);
+                       } finally {
+                               JcrUtils.logoutQuietly(session);
+                       }
+               }
+       }
+}
index 1d758e28726b47cc7e8cb2b3ae120dc9796f4f7f..c5be2deda11b34c2f1941870cfbd7c4a7b7f444d 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="System E4 Service">
-   <implementation class="org.argeo.connect.e4.SystemE4Service"/>
+   <implementation class="org.argeo.connect.e4.SystemE4ServiceFunction"/>
    <service>
       <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
    </service>
index 88067aab7f7cd0dd0f7b457c21a26a3ab8646167..521c1fca8741f107ceeb57a2e3255ab72ceb3288 100644 (file)
@@ -5,8 +5,11 @@ import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.jcr.Node;
 import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.ui.eclipse.forms.FormToolkit;
 import org.argeo.cms.util.CmsUtils;
 import org.argeo.connect.SystemAppService;
@@ -17,6 +20,9 @@ import org.argeo.connect.ui.SystemWorkbenchService;
 import org.argeo.connect.util.ConnectJcrUtils;
 import org.argeo.eclipse.ui.EclipseUiUtils;
 import org.argeo.jcr.JcrUtils;
+import org.eclipse.e4.ui.di.Focus;
+import org.eclipse.rap.rwt.RWT;
+import org.eclipse.rap.rwt.client.service.BrowserNavigation;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -29,6 +35,7 @@ import org.eclipse.swt.widgets.Link;
 
 /** Generic dashboard for Argeo Suite applications */
 public abstract class AbstractSuiteDashboard {
+       private final static Log log = LogFactory.getLog(AbstractSuiteDashboard.class);
 
        // DEPENDENCY INJECTION
        @Inject
@@ -45,17 +52,20 @@ public abstract class AbstractSuiteDashboard {
        // UI Objects
        private FormToolkit toolkit;
 
-       public void init()  {
+       // RAP specific
+       private BrowserNavigation browserNavigation;
+
+       public void init() {
                session = ConnectJcrUtils.login(repository);
-//             updateTooltip(input);
+               // updateTooltip(input);
        }
 
-//     private void updateTooltip(IEditorInput input) {
-//             if (input instanceof EntityEditorInput) {
-//                     EntityEditorInput sei = (EntityEditorInput) input;
-//                     sei.setTooltipText("My Dashboard");
-//             }
-//     }
+       // private void updateTooltip(IEditorInput input) {
+       // if (input instanceof EntityEditorInput) {
+       // EntityEditorInput sei = (EntityEditorInput) input;
+       // sei.setTooltipText("My Dashboard");
+       // }
+       // }
 
        /**
         * Implementing classes must call super in order to create the correct form
@@ -65,6 +75,7 @@ public abstract class AbstractSuiteDashboard {
        public void createPartControl(Composite parent) {
                toolkit = new FormToolkit(Display.getCurrent());
                init();
+               browserNavigation = RWT.getClient().getService(BrowserNavigation.class);
        }
 
        // UTILS
@@ -125,6 +136,10 @@ public abstract class AbstractSuiteDashboard {
                JcrUtils.logoutQuietly(session);
        }
 
+       @Focus
+       public void setFocus() {
+               browserNavigation.pushState("~", "Dashboard");
+       }
 
        // Expose to implementing classes
        protected Session getSession() {
index 1e2be9a690fc5dc5edb7149af1bc58e9f3423cfd..abf77adace75d7a0cecce8c1995f9d9676c2b7ac 100644 (file)
@@ -363,11 +363,6 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                }
        }
 
-       @Focus
-       public void setFocus() {
-               // refreshDocListGadget();
-       }
-
        public void setActivitiesService(ActivitiesService activitiesService) {
                this.activitiesService = activitiesService;
        }