Refactor to use ACR instead of JCR.
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 16 Jun 2022 07:29:18 +0000 (09:29 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 16 Jun 2022 07:29:18 +0000 (09:29 +0200)
org.argeo.app.ui/src/org/argeo/app/ui/DefaultEditionLayer.java
org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java
org.argeo.app.ui/src/org/argeo/app/ui/SuiteEvent.java
org.argeo.app.ui/src/org/argeo/app/ui/SuiteLayer.java
org.argeo.app.ui/src/org/argeo/app/ui/SuiteUi.java
org.argeo.app.ui/src/org/argeo/app/ui/SuiteUiUtils.java
org.argeo.app.ui/src/org/argeo/app/ui/openlayers/OpenLayersMap.java
org.argeo.app.ui/src/org/argeo/app/ui/widgets/TabbedArea.java [deleted file]

index 579157dd90795289e2b46a5482ea49b1302e1153..4bfc3de664286b7623f3ab5c93d27685d377cfe0 100644 (file)
@@ -4,15 +4,13 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
+import org.argeo.api.acr.Content;
 import org.argeo.api.cms.CmsTheme;
-import org.argeo.app.ui.widgets.TabbedArea;
 import org.argeo.cms.Localized;
 import org.argeo.cms.swt.CmsSwtUtils;
+import org.argeo.cms.swt.acr.SwtUiProvider;
+import org.argeo.cms.swt.widgets.SwtTabbedArea;
 import org.argeo.cms.ui.CmsUiProvider;
-import org.argeo.jcr.JcrException;
 import org.argeo.util.LangUtils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.SashForm;
@@ -34,12 +32,12 @@ public class DefaultEditionLayer implements SuiteLayer {
        private Localized title = null;
 
        @Override
-       public Control createUi(Composite parent, Node context) throws RepositoryException {
+       public Control createUiPart(Composite parent, Content context) {
                // TODO Factorize more, or split into more specialised classes?
                if (entryArea != null) {
                        if (fixedEntryArea) {
                                FixedEditionArea editionArea = new FixedEditionArea(parent, parent.getStyle());
-                               Control entryAreaC = entryArea.createUi(editionArea.getEntryArea(), context);
+                               Control entryAreaC = entryArea.createUiPart(editionArea.getEntryArea(), context);
                                CmsSwtUtils.style(entryAreaC, SuiteStyle.entryArea);
                                if (this.defaultView != null) {
                                        editionArea.getTabbedArea().view(defaultView, context);
@@ -47,7 +45,7 @@ public class DefaultEditionLayer implements SuiteLayer {
                                return editionArea;
                        } else {
                                SashFormEditionArea editionArea = new SashFormEditionArea(parent, parent.getStyle());
-                               entryArea.createUi(editionArea.getEntryArea(), context);
+                               entryArea.createUiPart(editionArea.getEntryArea(), context);
                                if (this.defaultView != null) {
                                        editionArea.getTabbedArea().view(defaultView, context);
                                }
@@ -56,30 +54,26 @@ public class DefaultEditionLayer implements SuiteLayer {
                } else {
                        if (this.workArea != null) {
                                Composite area = new Composite(parent, SWT.NONE);
-                               this.workArea.createUi(area, context);
+                               this.workArea.createUiPart(area, context);
                                return area;
                        }
                        CmsTheme theme = CmsSwtUtils.getCmsTheme(parent);
-                       TabbedArea tabbedArea = createTabbedArea(parent, theme);
+                       SwtTabbedArea tabbedArea = createTabbedArea(parent, theme);
                        return tabbedArea;
                }
        }
 
        @Override
-       public void view(CmsUiProvider uiProvider, Composite workAreaC, Node context) {
+       public void view(SwtUiProvider uiProvider, Composite workAreaC, Content context) {
                if (workArea != null) {
-                       try {
-                               CmsSwtUtils.clear(workAreaC);
-                               workArea.createUi(workAreaC, context);
-                               workAreaC.layout(true, true);
-                               return;
-                       } catch (RepositoryException e) {
-                               throw new JcrException("Cannot rebuild work area", e);
-                       }
+                       CmsSwtUtils.clear(workAreaC);
+                       workArea.createUiPart(workAreaC, context);
+                       workAreaC.layout(true, true);
+                       return;
                }
 
                // tabbed area
-               TabbedArea tabbedArea = findTabbedArea(workAreaC);
+               SwtTabbedArea tabbedArea = findTabbedArea(workAreaC);
                if (tabbedArea == null)
                        throw new IllegalArgumentException("Unsupported work area " + workAreaC.getClass().getName());
                if (uiProvider == null) {
@@ -94,28 +88,28 @@ public class DefaultEditionLayer implements SuiteLayer {
        }
 
        @Override
-       public Node getCurrentContext(Composite workArea) {
-               TabbedArea tabbedArea = findTabbedArea(workArea);
+       public Content getCurrentContext(Composite workArea) {
+               SwtTabbedArea tabbedArea = findTabbedArea(workArea);
                if (tabbedArea == null)
                        return null;
                return tabbedArea.getCurrentContext();
        }
 
-       private TabbedArea findTabbedArea(Composite workArea) {
-               TabbedArea tabbedArea = null;
+       private SwtTabbedArea findTabbedArea(Composite workArea) {
+               SwtTabbedArea tabbedArea = null;
                if (workArea instanceof SashFormEditionArea) {
                        tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
                } else if (workArea instanceof FixedEditionArea) {
                        tabbedArea = ((FixedEditionArea) workArea).getTabbedArea();
-               } else if (workArea instanceof TabbedArea) {
-                       tabbedArea = (TabbedArea) workArea;
+               } else if (workArea instanceof SwtTabbedArea) {
+                       tabbedArea = (SwtTabbedArea) workArea;
                }
                return tabbedArea;
        }
 
        @Override
-       public void open(CmsUiProvider uiProvider, Composite workArea, Node context) {
-               TabbedArea tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
+       public void open(SwtUiProvider uiProvider, Composite workArea, Content context) {
+               SwtTabbedArea tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
                tabbedArea.open(uiProvider, context);
        }
 
@@ -176,8 +170,8 @@ public class DefaultEditionLayer implements SuiteLayer {
                this.defaultView = defaultView;
        }
 
-       TabbedArea createTabbedArea(Composite parent, CmsTheme theme) {
-               TabbedArea tabbedArea = new TabbedArea(parent, SWT.NONE);
+       SwtTabbedArea createTabbedArea(Composite parent, CmsTheme theme) {
+               SwtTabbedArea tabbedArea = new SwtTabbedArea(parent, SWT.NONE);
                tabbedArea.setSingleTab(singleTab);
                tabbedArea.setBodyStyle(SuiteStyle.mainTabBody.style());
                tabbedArea.setTabStyle(SuiteStyle.mainTab.style());
@@ -190,7 +184,7 @@ public class DefaultEditionLayer implements SuiteLayer {
 //     /** A work area based on an entry area and and a tabbed area. */
        class SashFormEditionArea extends SashForm {
                private static final long serialVersionUID = 2219125778722702618L;
-               private TabbedArea tabbedArea;
+               private SwtTabbedArea tabbedArea;
                private Composite entryC;
 
                SashFormEditionArea(Composite parent, int style) {
@@ -231,7 +225,7 @@ public class DefaultEditionLayer implements SuiteLayer {
                        tabbedArea = createTabbedArea(editorC, theme);
                }
 
-               TabbedArea getTabbedArea() {
+               SwtTabbedArea getTabbedArea() {
                        return tabbedArea;
                }
 
@@ -243,7 +237,7 @@ public class DefaultEditionLayer implements SuiteLayer {
 
        class FixedEditionArea extends Composite {
                private static final long serialVersionUID = -5525672639277322465L;
-               private TabbedArea tabbedArea;
+               private SwtTabbedArea tabbedArea;
                private Composite entryC;
 
                public FixedEditionArea(Composite parent, int style) {
@@ -274,7 +268,7 @@ public class DefaultEditionLayer implements SuiteLayer {
                        tabbedArea = createTabbedArea(editorC, theme);
                }
 
-               TabbedArea getTabbedArea() {
+               SwtTabbedArea getTabbedArea() {
                        return tabbedArea;
                }
 
index e0a21c6e65b3834a9f3248442e158daba2b90935..9bfec26ba989f5428c13f40689900a8af47c0f70 100644 (file)
@@ -41,6 +41,7 @@ import org.argeo.cms.CmsUserManager;
 import org.argeo.cms.LocaleUtils;
 import org.argeo.cms.Localized;
 import org.argeo.cms.jcr.CmsJcrUtils;
+import org.argeo.cms.jcr.acr.JcrContent;
 import org.argeo.cms.jcr.acr.JcrContentProvider;
 import org.argeo.cms.swt.CmsSwtUtils;
 import org.argeo.cms.swt.dialogs.CmsFeedback;
@@ -183,7 +184,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
        @Override
        public void refreshUi(CmsUi cmsUi, String state) {
                try {
-                       Node context = null;
+                       Content context = null;
                        SuiteUi ui = (SuiteUi) cmsUi;
 
                        String uiName = Objects.toString(ui.getParent().getData(UI_NAME_PROPERTY), null);
@@ -276,7 +277,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
 
        }
 
-       private void refreshPart(CmsUiProvider uiProvider, Composite part, Node context) {
+       private void refreshPart(CmsUiProvider uiProvider, Composite part, Content context) {
                CmsSwtUtils.clear(part);
                uiProvider.createUiPart(part, context);
        }
@@ -293,9 +294,12 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                return layersByPid.get(pid).get();
        }
 
-       private <T> T findByType(Map<String, RankedObject<T>> byType, Node context) {
-               if (context == null)
+       private <T> T findByType(Map<String, RankedObject<T>> byType, Content content) {
+               if (content == null)
                        throw new IllegalArgumentException("A node should be provided");
+               
+               if(content instanceof JcrContent) {
+               Node context = ((JcrContent)content).getJcrNode();
                try {
                        // mixins
                        Set<String> types = new TreeSet<>();
@@ -347,6 +351,10 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                } catch (RepositoryException e) {
                        throw new IllegalStateException(e);
                }
+               
+               }else {
+                       throw new UnsupportedOperationException("Content "+content.getClass().getName()+" is not supported.");
+               }
        }
 
        private static String listTypes(Node context) {
@@ -397,7 +405,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                        return;
                }
                SuiteUi suiteUi = (SuiteUi) cmsUi;
-               Node node = stateToNode(suiteUi, state);
+               Content node = stateToNode(suiteUi, state);
                if (node == null) {
                        suiteUi.getCmsView().navigateTo(HOME_STATE);
                } else {
@@ -407,44 +415,46 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
        }
 
        // TODO move it to an internal package?
-       static String nodeToState(Node node) {
-               return '/' + Jcr.getWorkspaceName(node) + Jcr.getPath(node);
+       static String nodeToState(Content node) {
+               return node.getPath();
        }
 
-       private Node stateToNode(SuiteUi suiteUi, String state) {
+       private Content stateToNode(SuiteUi suiteUi, String state) {
                if (suiteUi == null)
                        return null;
                if (state == null || !state.startsWith("/"))
                        return null;
 
-               String path = state.substring(1);
-               String workspace;
-               if (path.equals("")) {
-                       workspace = null;
-                       path = "/";
-               } else {
-                       int index = path.indexOf('/');
-                       if (index == 0) {
-                               log.error("Cannot interpret " + state);
-//                             cmsView.navigateTo("~");
-                               return null;
-                       } else if (index > 0) {
-                               workspace = path.substring(0, index);
-                               path = path.substring(index);
-                       } else {// index<0, assuming root node
-                               workspace = path;
-                               path = "/";
-                       }
-               }
+               String path=state;
+//             String path = state.substring(1);
+//             String workspace;
+//             if (path.equals("")) {
+//                     workspace = null;
+//                     path = "/";
+//             } else {
+//                     int index = path.indexOf('/');
+//                     if (index == 0) {
+//                             log.error("Cannot interpret " + state);
+////                           cmsView.navigateTo("~");
+//                             return null;
+//                     } else if (index > 0) {
+//                             workspace = path.substring(0, index);
+//                             path = path.substring(index);
+//                     } else {// index<0, assuming root node
+//                             workspace = path;
+//                             path = "/";
+//                     }
+//             }
 
                ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository,
                                suiteUi.getCmsView());
-               Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
-//             Session session = suiteUi.getSession(workspace);
-               if (session == null)
-                       return null;
-               Node node = Jcr.getNode(session, path);
-               return node;
+               return contentSession.get(path);
+//             Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
+////           Session session = suiteUi.getSession(workspace);
+//             if (session == null)
+//                     return null;
+//             Node node = Jcr.getNode(session, path);
+//             return node;
        }
 
        /*
@@ -466,23 +476,23 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
 //                     String currentLayerId = ui.getCurrentLayerId();
 //                     SuiteLayer currentLayer = currentLayerId != null ? layersByPid.get(currentLayerId).get() : null;
                        if (SuiteUiUtils.isTopic(event, SuiteEvent.refreshPart)) {
-                               Node node = getNode(ui, event);
+                               Content node = getNode(ui, event);
                                if (node == null)
                                        return;
                                CmsUiProvider uiProvider = findByType(uiProvidersByType, node);
                                SuiteLayer layer = findByType(layersByType, node);
                                ui.switchToLayer(layer, node);
                                ui.getCmsView().runAs(() -> layer.view(uiProvider, ui.getCurrentWorkArea(), node));
-                               ui.getCmsView().stateChanged(nodeToState(node), appTitle + Jcr.getTitle(node));
+                               ui.getCmsView().stateChanged(nodeToState(node), appTitle + CmsUxUtils.getTitle(node));
                        } else if (SuiteUiUtils.isTopic(event, SuiteEvent.openNewPart)) {
-                               Node node = getNode(ui, event);
+                               Content node = getNode(ui, event);
                                if (node == null)
                                        return;
                                CmsUiProvider uiProvider = findByType(uiProvidersByType, node);
                                SuiteLayer layer = findByType(layersByType, node);
                                ui.switchToLayer(layer, node);
                                ui.getCmsView().runAs(() -> layer.open(uiProvider, ui.getCurrentWorkArea(), node));
-                               ui.getCmsView().stateChanged(nodeToState(node), appTitle + Jcr.getTitle(node));
+                               ui.getCmsView().stateChanged(nodeToState(node), appTitle + CmsUxUtils.getTitle(node));
                        } else if (SuiteUiUtils.isTopic(event, SuiteEvent.switchLayer)) {
                                String layerId = get(event, SuiteEvent.LAYER);
                                if (layerId != null) {
@@ -496,25 +506,25 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                                        String title = null;
                                        if (layerTitle != null)
                                                title = layerTitle.lead();
-                                       Node nodeFromState = getNode(ui, event);
+                                       Content nodeFromState = getNode(ui, event);
                                        if (nodeFromState != null && nodeFromState.getPath().equals(ui.getUserDirNode().getPath())) {
                                                // default layer view is forced
                                                String state = defaultLayerPid.equals(layerId) ? "~" : layerId;
                                                ui.getCmsView().stateChanged(state, appTitle + title);
                                                suiteLayer.view(null, workArea, nodeFromState);
                                        } else {
-                                               Node layerCurrentContext = suiteLayer.getCurrentContext(workArea);
+                                               Content layerCurrentContext = suiteLayer.getCurrentContext(workArea);
                                                if (layerCurrentContext != null) {
                                                        // layer was already showing a context so we set the state to it
                                                        ui.getCmsView().stateChanged(nodeToState(layerCurrentContext),
-                                                                       appTitle + Jcr.getTitle(layerCurrentContext));
+                                                                       appTitle + CmsUxUtils.getTitle(layerCurrentContext));
                                                } else {
                                                        // no context was shown
                                                        ui.getCmsView().stateChanged(layerId, appTitle + title);
                                                }
                                        }
                                } else {
-                                       Node node = getNode(ui, event);
+                                       Content node = getNode(ui, event);
                                        if (node != null) {
                                                SuiteLayer layer = findByType(layersByType, node);
                                                ui.getCmsView().runAs(() -> ui.switchToLayer(layer, node));
@@ -528,19 +538,21 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
 
        }
 
-       private Node getNode(SuiteUi ui, Event event) {
+       private Content getNode(SuiteUi ui, Event event) {
                ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository,
                                ui.getCmsView());
 
-               String nodePath = get(event, SuiteEvent.NODE_PATH);
-               if (nodePath != null && nodePath.equals(HOME_STATE))
-                       return ui.getUserDirNode();
-               String workspace = get(event, SuiteEvent.WORKSPACE);
-
-               Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
-//             Session session = ui.getSession(workspace);
-               Node node;
-               if (nodePath == null) {
+               String path = get(event,SuiteEvent.CONTENT_PATH);
+               
+//             String nodePath = get(event, SuiteEvent.NODE_PATH);
+               if (path != null && path.equals(HOME_STATE))
+                       return ui.getUserDir();
+//             String workspace = get(event, SuiteEvent.WORKSPACE);
+
+//             Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
+////           Session session = ui.getSession(workspace);
+               Content node;
+               if (path == null) {
                        // look for a user
                        String username = get(event, SuiteEvent.USERNAME);
                        if (username == null)
@@ -555,20 +567,22 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                                throw new IllegalArgumentException("Badly formatted username", e);
                        }
                        String userNodePath = SuiteUtils.getUserNodePath(userDn);
-                       if (Jcr.itemExists(session, userNodePath))
-                               node = Jcr.getNode(session, userNodePath);
-                       else {
-                               Session adminSession = null;
-                               try {
-                                       adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), workspace);
-                                       SuiteUtils.getOrCreateUserNode(adminSession, userDn);
-                               } finally {
-                                       Jcr.logout(adminSession);
-                               }
-                               node = Jcr.getNode(session, userNodePath);
-                       }
+                       // FIXME deal with home path
+                       return null;
+//                     if (Jcr.itemExists(session, userNodePath))
+//                             node = Jcr.getNode(session, userNodePath);
+//                     else {
+//                             Session adminSession = null;
+//                             try {
+//                                     adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), workspace);
+//                                     SuiteUtils.getOrCreateUserNode(adminSession, userDn);
+//                             } finally {
+//                                     Jcr.logout(adminSession);
+//                             }
+//                             node = Jcr.getNode(session, userNodePath);
+//                     }
                } else {
-                       node = Jcr.getNode(session, nodePath);
+                       node = contentSession.get(path);
                }
                return node;
        }
@@ -648,7 +662,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler {
                        List<String> types = LangUtils.toStringList(properties.get(EntityConstants.TYPE));
                        for (String type : types) {
                                if (layersByType.containsKey(type)) {
-                                       if (layersByType.get(type).equals(new RankedObject<CmsUiProvider>(layer, properties))) {
+                                       if (layersByType.get(type).equals(new RankedObject<SuiteLayer>(layer, properties))) {
                                                layersByType.remove(type);
                                        }
                                }
index c80be8e877d4dd7a33390a43702e93f676e7be7d..d61d84e3a9db4de986bb7a3aeb6ff0adee9a7d3e 100644 (file)
@@ -21,7 +21,9 @@ public enum SuiteEvent implements CmsEvent {
        public final static String CONTENT_PATH = "contentPath";
 
        // JCR
+       @Deprecated
        public final static String NODE_PATH = "path";
+       @Deprecated
        public final static String WORKSPACE = "workspace";
 
        public String getTopicBase() {
@@ -34,10 +36,13 @@ public enum SuiteEvent implements CmsEvent {
                return properties;
        }
 
+       @Deprecated
        public static Map<String, Object> eventProperties(Node node) {
                Map<String, Object> properties = new HashMap<>();
-               properties.put(NODE_PATH, Jcr.getPath(node));
-               properties.put(WORKSPACE, Jcr.getWorkspaceName(node));
+               String contentPath = '/'+ Jcr.getWorkspaceName(node)+ Jcr.getPath(node);
+               properties.put(CONTENT_PATH, contentPath);
+//             properties.put(NODE_PATH, Jcr.getPath(node));
+//             properties.put(WORKSPACE, Jcr.getWorkspaceName(node));
                return properties;
        }
 
index a92994f9d8407213822b40845b5a9dfb828ca0f0..161856360f44fb9b6953420b2ed4251666dbc96d 100644 (file)
@@ -1,22 +1,21 @@
 package org.argeo.app.ui;
 
-import javax.jcr.Node;
-
+import org.argeo.api.acr.Content;
 import org.argeo.cms.Localized;
-import org.argeo.cms.ui.CmsUiProvider;
+import org.argeo.cms.swt.acr.SwtUiProvider;
 import org.eclipse.swt.widgets.Composite;
 
 /** An UI layer for the main work area. */
-public interface SuiteLayer extends CmsUiProvider {
+public interface SuiteLayer extends SwtUiProvider {
        static enum Property {
                title, icon, weights, startMaximized, singleTab, fixedEntryArea;
        }
 
-       void view(CmsUiProvider uiProvider, Composite workArea, Node context);
+       void view(SwtUiProvider uiProvider, Composite workArea, Content context);
        
-       Node getCurrentContext(Composite workArea);
+       Content getCurrentContext(Composite workArea);
 
-       default void open(CmsUiProvider uiProvider, Composite workArea, Node context) {
+       default void open(SwtUiProvider uiProvider, Composite workArea, Content context) {
                view(uiProvider, workArea, context);
        }
 
index 2e0007bf6fd6746609e5a4fb07cf41bf769a8e76..a19da2164029b95b5f09ce1a75a1f1a5a872ec31 100644 (file)
@@ -3,14 +3,11 @@ package org.argeo.app.ui;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.jcr.Node;
-
 import org.argeo.api.acr.Content;
 import org.argeo.api.cms.CmsLog;
 import org.argeo.api.cms.CmsUi;
 import org.argeo.api.cms.CmsView;
 import org.argeo.cms.Localized;
-import org.argeo.cms.jcr.acr.JcrContent;
 import org.argeo.cms.swt.CmsSwtUtils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.FormLayout;
@@ -103,7 +100,7 @@ class SuiteUi extends Composite implements CmsUi {
                return currentLayerId;
        }
 
-       private Composite getLayer(String id, Node context) {
+       private Composite getLayer(String id, Content context) {
                if (!layers.containsKey(id))
                        return null;
                if (!workAreas.containsKey(id))
@@ -111,7 +108,7 @@ class SuiteUi extends Composite implements CmsUi {
                return workAreas.get(id);
        }
 
-       Composite switchToLayer(String layerId, Node context) {
+       Composite switchToLayer(String layerId, Content context) {
                Composite current = null;
                if (currentLayerId != null) {
                        current = getCurrentWorkArea();
@@ -143,7 +140,7 @@ class SuiteUi extends Composite implements CmsUi {
                }
        }
 
-       Composite switchToLayer(SuiteLayer layer, Node context) {
+       Composite switchToLayer(SuiteLayer layer, Content context) {
                // TODO make it more robust
                for (String layerId : layers.keySet()) {
                        SuiteLayer l = layers.get(layerId);
@@ -167,7 +164,7 @@ class SuiteUi extends Composite implements CmsUi {
                }
        }
 
-       protected Composite initLayer(String id, SuiteLayer layer, Node context) {
+       protected Composite initLayer(String id, SuiteLayer layer, Content context) {
                Composite workArea = cmsView.doAs(() -> (Composite) layer.createUiPart(dynamicArea, context));
                CmsSwtUtils.style(workArea, SuiteStyle.workArea);
                workArea.setLayoutData(CmsSwtUtils.coverAll());
@@ -221,10 +218,15 @@ class SuiteUi extends Composite implements CmsUi {
 //             });
 //     }
 
-       Node getUserDirNode() {
+       @Deprecated
+       Content getUserDirNode() {
                if (userDir == null)
                        return null;
-               return ((JcrContent) userDir).getJcrNode();
+               return userDir;
+       }
+
+       Content getUserDir() {
+               return userDir;
        }
 
        void setUserDir(Content userDir) {
index 504fbd2e3ed72d54d979aa50b822f03e57a0ecd0..7fe00fe9cf912c455c4aca0c46250b6992dcc6e1 100644 (file)
@@ -11,6 +11,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 import org.apache.commons.io.IOUtils;
+import org.argeo.api.acr.Content;
 import org.argeo.api.cms.CmsEditable;
 import org.argeo.api.cms.CmsEvent;
 import org.argeo.api.cms.CmsStyle;
@@ -22,6 +23,7 @@ import org.argeo.app.api.SuiteRole;
 import org.argeo.cms.LocaleUtils;
 import org.argeo.cms.Localized;
 import org.argeo.cms.auth.CurrentUser;
+import org.argeo.cms.jcr.acr.JcrContent;
 import org.argeo.cms.swt.CmsIcon;
 import org.argeo.cms.swt.CmsSwtUtils;
 import org.argeo.cms.swt.dialogs.LightweightDialog;
@@ -358,8 +360,13 @@ public class SuiteUiUtils {
                return img;
        }
 
+       public static String toLink(Content node) {
+               return node != null ? "#" + CmsSwtUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null;
+       }
+
        public static String toLink(Node node) {
-               return node != null ? "#" + CmsUiUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null;
+               return node != null ? "#" + CmsSwtUtils.cleanPathForUrl(SuiteApp.nodeToState(JcrContent.nodeToContent(node)))
+                               : null;
        }
 
        public static Control addLink(Composite parent, String label, Node node, CmsStyle style)
index bf2ac2c6ca166b489e1c0e87d090457069f1610c..76aa403279820be8e7289c528bb613612b59bc62 100644 (file)
@@ -272,8 +272,9 @@ public class OpenLayersMap extends Composite {
                                return null;
                        String path = arguments[0].toString();
                        Map<String, Object> properties = new HashMap<>();
-                       properties.put(SuiteEvent.NODE_PATH, path);
-                       properties.put(SuiteEvent.WORKSPACE, CmsConstants.SYS_WORKSPACE);
+//                     properties.put(SuiteEvent.NODE_PATH, path);
+//                     properties.put(SuiteEvent.WORKSPACE, CmsConstants.SYS_WORKSPACE);
+                       properties.put(SuiteEvent.CONTENT_PATH, '/' + CmsConstants.SYS_WORKSPACE + path);
                        cmsView.sendEvent(SuiteEvent.refreshPart.topic(), properties);
                        return null;
                }
diff --git a/org.argeo.app.ui/src/org/argeo/app/ui/widgets/TabbedArea.java b/org.argeo.app.ui/src/org/argeo/app/ui/widgets/TabbedArea.java
deleted file mode 100644 (file)
index 321a198..0000000
+++ /dev/null
@@ -1,257 +0,0 @@
-package org.argeo.app.ui.widgets;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-
-import org.argeo.cms.swt.CmsSwtUtils;
-import org.argeo.cms.swt.Selected;
-import org.argeo.cms.ui.CmsUiProvider;
-import org.argeo.cms.ui.viewers.Section;
-import org.argeo.jcr.Jcr;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.ToolBar;
-import org.eclipse.swt.widgets.ToolItem;
-
-/** Manages {@link Section} in a tab-like structure. */
-public class TabbedArea extends Composite {
-       private static final long serialVersionUID = 8659669229482033444L;
-
-       private Composite headers;
-       private Composite body;
-
-       private List<Section> sections = new ArrayList<>();
-
-       private Node previousNode;
-       private CmsUiProvider previousUiProvider;
-       private CmsUiProvider currentUiProvider;
-
-       private String tabStyle;
-       private String tabSelectedStyle;
-       private String bodyStyle;
-       private Image closeIcon;
-
-       private StackLayout stackLayout;
-
-       private boolean singleTab = false;
-
-       public TabbedArea(Composite parent, int style) {
-               super(parent, SWT.NONE);
-               CmsSwtUtils.style(parent, bodyStyle);
-
-               setLayout(CmsSwtUtils.noSpaceGridLayout());
-
-               // TODO manage tabs at bottom or sides
-               headers = new Composite(this, SWT.NONE);
-               headers.setLayoutData(CmsSwtUtils.fillWidth());
-               body = new Composite(this, SWT.NONE);
-               body.setLayoutData(CmsSwtUtils.fillAll());
-               // body.setLayout(new FormLayout());
-               stackLayout = new StackLayout();
-               body.setLayout(stackLayout);
-               emptyState();
-       }
-
-       protected void refreshTabHeaders() {
-               int tabCount = sections.size() > 0 ? sections.size() : 1;
-               for (Control tab : headers.getChildren())
-                       tab.dispose();
-
-               headers.setLayout(CmsSwtUtils.noSpaceGridLayout(new GridLayout(tabCount, true)));
-
-               if (sections.size() == 0) {
-                       Composite emptyHeader = new Composite(headers, SWT.NONE);
-                       emptyHeader.setLayoutData(CmsSwtUtils.fillAll());
-                       emptyHeader.setLayout(new GridLayout());
-                       Label lbl = new Label(emptyHeader, SWT.NONE);
-                       lbl.setText("");
-                       lbl.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
-
-               }
-
-               Section currentSection = getCurrentSection();
-               for (Section section : sections) {
-                       boolean selected = section == currentSection;
-                       Composite sectionHeader = section.createHeader(headers);
-                       CmsSwtUtils.style(sectionHeader, selected ? tabSelectedStyle : tabStyle);
-                       int headerColumns = singleTab ? 1 : 2;
-                       sectionHeader.setLayout(new GridLayout(headerColumns, false));
-                       sectionHeader.setLayout(CmsSwtUtils.noSpaceGridLayout(headerColumns));
-                       Button title = new Button(sectionHeader, SWT.FLAT);
-                       CmsSwtUtils.style(title, selected ? tabSelectedStyle : tabStyle);
-                       title.setLayoutData(CmsSwtUtils.fillWidth());
-                       title.addSelectionListener((Selected) (e) -> showTab(tabIndex(section.getNode())));
-                       Node node = section.getNode();
-                       String titleStr = Jcr.getTitle(node);
-                       // TODO internationalize
-                       title.setText(titleStr);
-                       if (!singleTab) {
-                               ToolBar toolBar = new ToolBar(sectionHeader, SWT.NONE);
-                               ToolItem closeItem = new ToolItem(toolBar, SWT.FLAT);
-                               if (closeIcon != null)
-                                       closeItem.setImage(closeIcon);
-                               else
-                                       closeItem.setText("X");
-                               CmsSwtUtils.style(closeItem, selected ? tabSelectedStyle : tabStyle);
-                               closeItem.addSelectionListener((Selected) (e) -> closeTab(section));
-                       }
-               }
-
-       }
-
-       public void view(CmsUiProvider uiProvider, Node context) {
-               if (body.isDisposed())
-                       return;
-               int index = tabIndex(context);
-               if (index >= 0) {
-                       showTab(index);
-                       previousNode = context;
-                       previousUiProvider = uiProvider;
-                       return;
-               }
-               Section section = (Section) body.getChildren()[0];
-               previousNode = section.getNode();
-               if (previousNode == null) {// empty state
-                       previousNode = context;
-                       previousUiProvider = uiProvider;
-               } else {
-                       previousUiProvider = currentUiProvider;
-               }
-               currentUiProvider = uiProvider;
-               section.setNode(context);
-               // section.setLayoutData(CmsUiUtils.coverAll());
-               build(section, uiProvider, context);
-               if (sections.size() == 0)
-                       sections.add(section);
-               refreshTabHeaders();
-               index = tabIndex(context);
-               showTab(index);
-               layout(true, true);
-       }
-
-       public void open(CmsUiProvider uiProvider, Node context) {
-               if (singleTab)
-                       throw new UnsupportedOperationException("Open is not supported in single tab mode.");
-
-               if (previousNode != null && Jcr.getIdentifier(previousNode).equals(Jcr.getIdentifier(context))) {
-                       // does nothing
-                       return;
-               }
-               if (sections.size() == 0)
-                       CmsSwtUtils.clear(body);
-               Section currentSection = getCurrentSection();
-               int currentIndex = sections.indexOf(currentSection);
-               Section previousSection = new Section(body, SWT.NONE, context);
-               build(previousSection, previousUiProvider, previousNode);
-               // previousSection.setLayoutData(CmsUiUtils.coverAll());
-               int newIndex = currentIndex + 1;
-               sections.add(currentIndex, previousSection);
-//             sections.add(newIndex, previousSection);
-               showTab(newIndex);
-               refreshTabHeaders();
-               layout(true, true);
-       }
-
-       public void showTab(int index) {
-               Section sectionToShow = sections.get(index);
-               // sectionToShow.moveAbove(null);
-               stackLayout.topControl = sectionToShow;
-               refreshTabHeaders();
-               layout(true, true);
-       }
-
-       protected void build(Section section, CmsUiProvider uiProvider, Node context) {
-               for (Control child : section.getChildren())
-                       child.dispose();
-               CmsSwtUtils.style(section, bodyStyle);
-               section.setNode(context);
-               uiProvider.createUiPart(section, context);
-
-       }
-
-       private int tabIndex(Node node) {
-               for (int i = 0; i < sections.size(); i++) {
-                       Section section = sections.get(i);
-                       if (Jcr.getIdentifier(section.getNode()).equals(Jcr.getIdentifier(node)))
-                               return i;
-               }
-               return -1;
-       }
-
-       public void closeTab(Section section) {
-               int currentIndex = sections.indexOf(section);
-               int nextIndex = currentIndex == 0 ? 0 : currentIndex - 1;
-               sections.remove(section);
-               section.dispose();
-               if (sections.size() == 0) {
-                       emptyState();
-                       refreshTabHeaders();
-                       layout(true, true);
-                       return;
-               }
-               refreshTabHeaders();
-               showTab(nextIndex);
-       }
-
-       public void closeAllTabs() {
-               for (Section section : sections) {
-                       section.dispose();
-               }
-               sections.clear();
-               emptyState();
-               refreshTabHeaders();
-               layout(true, true);
-       }
-
-       protected void emptyState() {
-               new Section(body, SWT.NONE, null);
-               refreshTabHeaders();
-       }
-
-       public Composite getCurrent() {
-               return getCurrentSection();
-       }
-
-       protected Section getCurrentSection() {
-               return (Section) stackLayout.topControl;
-       }
-
-       public Node getCurrentContext() {
-               Section section = getCurrentSection();
-               if (section != null) {
-                       return section.getNode();
-               } else {
-                       return null;
-               }
-       }
-
-       public void setTabStyle(String tabStyle) {
-               this.tabStyle = tabStyle;
-       }
-
-       public void setTabSelectedStyle(String tabSelectedStyle) {
-               this.tabSelectedStyle = tabSelectedStyle;
-       }
-
-       public void setBodyStyle(String bodyStyle) {
-               this.bodyStyle = bodyStyle;
-       }
-
-       public void setCloseIcon(Image closeIcon) {
-               this.closeIcon = closeIcon;
-       }
-
-       public void setSingleTab(boolean singleTab) {
-               this.singleTab = singleTab;
-       }
-
-}