X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=org.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2FSuiteUi.java;h=ae278157f85f63de84ea03a110bfe20174fd9043;hp=8320f7618e1ee5180fe85d48c0120ef6138ea235;hb=9cfd54a608937b5373c6ac880a9874aa542bb2a1;hpb=f21589b7f2a19a79edcc213b867c47130faa76cd diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUi.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUi.java index 8320f76..ae27815 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUi.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUi.java @@ -8,8 +8,9 @@ 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.api.NodeConstants; -import org.argeo.api.NodeUtils; import org.argeo.cms.ui.CmsView; import org.argeo.cms.ui.util.CmsUiUtils; import org.argeo.jcr.Jcr; @@ -17,18 +18,18 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; -/** The {@link CmsView} for the work ergonomics of Argeo Suite. */ +/** The view for the default ergonomics of Argeo Suite. */ class SuiteUi extends Composite { private static final long serialVersionUID = 6207018859086689108L; - + private final static Log log = LogFactory.getLog(SuiteUi.class); private Composite header; private Composite belowHeader; private Composite leadPane; private Composite dynamicArea; private Session sysSession; - private Session homeSession; - private Node userHome; +// private Session homeSession; + private Node userDir; private Map layers = new HashMap<>(); private Map workAreas = new HashMap<>(); @@ -42,6 +43,7 @@ class SuiteUi extends Composite { this.setLayout(CmsUiUtils.noSpaceGridLayout()); header = new Composite(this, SWT.NONE); + header.setLayout(CmsUiUtils.noSpaceGridLayout()); CmsUiUtils.style(header, SuiteStyle.header); header.setLayoutData(CmsUiUtils.fillWidth()); @@ -63,9 +65,10 @@ class SuiteUi extends Composite { dynamicArea = new Composite(belowHeader, SWT.NONE); } leadPane.setLayoutData(CmsUiUtils.fillHeight()); + leadPane.setLayout(CmsUiUtils.noSpaceGridLayout()); CmsUiUtils.style(leadPane, SuiteStyle.leadPane); - dynamicArea.setLayoutData(CmsUiUtils.fillAll()); + dynamicArea.setLayoutData(CmsUiUtils.fillAll()); dynamicArea.setLayout(new FormLayout()); } else { @@ -89,29 +92,53 @@ class SuiteUi extends Composite { private Composite getLayer(String id, Node context) { if (!layers.containsKey(id)) - throw new IllegalArgumentException("No layer " + id + " is available."); + return null; if (!workAreas.containsKey(id)) initLayer(id, layers.get(id), context); return workAreas.get(id); } - Composite switchToLayer(String layer, Node context) { + Composite switchToLayer(String layerId, Node context) { + Composite current = null; if (currentLayerId != null) { - Composite current = getCurrentWorkArea(); - if (currentLayerId.equals(layer)) + current = getCurrentWorkArea(); + if (currentLayerId.equals(layerId)) return current; } if (context == null) { if (!cmsView.isAnonymous()) - context = userHome; + context = userDir; + } + Composite toShow = getLayer(layerId, context); + if (toShow != null) { + currentLayerId = layerId; + if (!isDisposed()) { +// getDisplay().syncExec(() -> { + if (!toShow.isDisposed()) { + toShow.moveAbove(null); + } else { + log.warn("Cannot show work area because it is disposed."); + toShow = initLayer(layerId, layers.get(layerId), context); + toShow.moveAbove(null); + } + dynamicArea.layout(true, true); +// }); + } + return toShow; + } else { + return current; } - Composite toShow = getLayer(layer, context); - getDisplay().syncExec(() -> { - toShow.moveAbove(null); - dynamicArea.layout(true, true); - }); - currentLayerId = layer; - return toShow; + } + + Composite switchToLayer(SuiteLayer layer, Node context) { + // TODO make it more robust + for (String layerId : layers.keySet()) { + SuiteLayer l = layers.get(layerId); + if (layer == l) { + return switchToLayer(layerId, context); + } + } + throw new IllegalArgumentException("Layer is not registered."); } void addLayer(String id, SuiteLayer layer) { @@ -134,6 +161,14 @@ class SuiteUi extends Composite { return workArea; } + synchronized void logout() { + userDir = null; + Jcr.logout(sysSession); +// Jcr.logout(homeSession); + currentLayerId = null; + workAreas.clear(); + } + /* * GETTERS / SETTERS */ @@ -154,18 +189,18 @@ class SuiteUi extends Composite { // return sysSession; // } // - void initSessions(Repository repository) throws RepositoryException { + synchronized void initSessions(Repository repository, String userDirPath) throws RepositoryException { this.sysSession = repository.login(); - this.homeSession = repository.login(NodeConstants.HOME_WORKSPACE); - userHome = NodeUtils.getUserHome(homeSession); +// this.homeSession = repository.login(NodeConstants.HOME_WORKSPACE); + userDir = sysSession.getNode(userDirPath); addDisposeListener((e) -> { Jcr.logout(sysSession); - Jcr.logout(homeSession); +// Jcr.logout(homeSession); }); } - Node getUserHome() { - return userHome; + Node getUserDir() { + return userDir; } Session getSysSession() { @@ -177,10 +212,14 @@ class SuiteUi extends Composite { return sysSession; if (NodeConstants.SYS_WORKSPACE.equals(workspaceName)) return sysSession; - else if (NodeConstants.HOME_WORKSPACE.equals(workspaceName)) - return homeSession; +// else if (NodeConstants.HOME_WORKSPACE.equals(workspaceName)) +// return homeSession; else throw new IllegalArgumentException("Unknown workspace " + workspaceName); } + public CmsView getCmsView() { + return cmsView; + } + }