X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=core%2Forg.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2FSuiteApp.java;h=e499463781ac7a59795839abb2a929e49c8f1286;hb=752a7b2614895002a3d184be166ef4162caf0d05;hp=bdcf30c87101e488b6654ac1fec9172843c69374;hpb=c63feb33bc17eb7e4fc6f2b47f31695ab6dfe1f8;p=gpl%2Fargeo-suite.git diff --git a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java index bdcf30c..e499463 100644 --- a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java +++ b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; @@ -57,6 +58,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { public final static String DEFAULT_THEME_ID_PROPERTY = "defaultThemeId"; public final static String DEFAULT_LAYER_PROPERTY = "defaultLayer"; private final static String LOGIN = "login"; + private final static String HOME_STATE = "~"; private String publicBasePath = null; @@ -64,11 +66,13 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { private String headerPid; private String footerPid; private String leadPanePid; + private String adminLeadPanePid; private String loginScreenPid; private String defaultLayerPid = "argeo.suite.ui.dashboardLayer"; private String defaultUiName = "app"; + private String adminUiName = "admin"; private String defaultThemeId = "org.argeo.suite.theme.default"; private Map> uiProvidersByPid = Collections.synchronizedMap(new HashMap<>()); @@ -106,6 +110,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { headerPid = pidPrefix + "header"; footerPid = pidPrefix + "footer"; leadPanePid = pidPrefix + "leadPane"; + adminLeadPanePid = pidPrefix + "adminLeadPane"; loginScreenPid = pidPrefix + "loginScreen"; } @@ -122,6 +127,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { public Set getUiNames() { HashSet uiNames = new HashSet<>(); uiNames.add(defaultUiName); + uiNames.add(adminUiName); return uiNames; } @@ -155,10 +161,19 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { try { Node context = null; SuiteUi ui = (SuiteUi) parent; + + String uiName = Objects.toString(ui.getParent().getData(UI_NAME_PROPERTY), null); + if (uiName == null) + throw new IllegalStateException("UI name should not be null"); CmsView cmsView = CmsView.getCmsView(parent); CmsUiProvider headerUiProvider = findUiProvider(headerPid); CmsUiProvider footerUiProvider = findUiProvider(footerPid); - CmsUiProvider leadPaneUiProvider = findUiProvider(leadPanePid); + CmsUiProvider leadPaneUiProvider; + if (adminUiName.equals(uiName)) { + leadPaneUiProvider = findUiProvider(adminLeadPanePid); + } else { + leadPaneUiProvider = findUiProvider(leadPanePid); + } Localized appTitle = null; if (headerUiProvider instanceof DefaultHeader) { @@ -335,35 +350,33 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { if (!state.startsWith("/")) { if (parent instanceof SuiteUi) { SuiteUi ui = (SuiteUi) parent; - if (LOGIN.equals(state) || state.equals("~")) { + if (LOGIN.equals(state)) { String appTitle = ""; if (ui.getTitle() != null) appTitle = ui.getTitle().lead(); ui.getCmsView().stateChanged(state, appTitle); return; } - String currentLayerId = ui.getCurrentLayerId(); - if (state.equals(currentLayerId)) - return; // does nothing - else { - Map properties = new HashMap<>(); - properties.put(SuiteEvent.LAYER, state); - ui.getCmsView().sendEvent(SuiteEvent.switchLayer.topic(), properties); - } + Map properties = new HashMap<>(); + String layerId = HOME_STATE.equals(state) ? defaultLayerPid : state; + properties.put(SuiteEvent.LAYER, layerId); + properties.put(SuiteEvent.NODE_PATH, HOME_STATE); + ui.getCmsView().sendEvent(SuiteEvent.switchLayer.topic(), properties); } return; } SuiteUi suiteUi = (SuiteUi) parent; Node node = stateToNode(suiteUi, state); if (node == null) { - suiteUi.getCmsView().navigateTo("~"); + suiteUi.getCmsView().navigateTo(HOME_STATE); } else { suiteUi.getCmsView().sendEvent(SuiteEvent.switchLayer.topic(), SuiteEvent.eventProperties(node)); suiteUi.getCmsView().sendEvent(SuiteEvent.refreshPart.topic(), SuiteEvent.eventProperties(node)); } } - private String nodeToState(Node node) { + // TODO move it to an internal package? + static String nodeToState(Node node) { return '/' + Jcr.getWorkspaceName(node) + Jcr.getPath(node); } @@ -440,12 +453,31 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { if (layerId != null) { // ui.switchToLayer(layerId, ui.getUserDir()); SuiteLayer suiteLayer = findLayer(layerId); + if (suiteLayer == null) + throw new IllegalArgumentException("No layer '" + layerId + "' available."); Localized layerTitle = suiteLayer.getTitle(); - ui.getCmsView().runAs(() -> ui.switchToLayer(layerId, ui.getUserDir())); + // FIXME make sure we don't rebuild the work area twice + Composite workArea = ui.getCmsView().doAs(() -> ui.switchToLayer(layerId, ui.getUserDir())); String title = null; if (layerTitle != null) title = layerTitle.lead(); - ui.getCmsView().stateChanged(layerId, appTitle + title); + Node nodeFromState = getNode(ui, event); + if (nodeFromState != null && nodeFromState.getPath().equals(ui.getUserDir().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); + 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)); + } else { + // no context was shown + ui.getCmsView().stateChanged(layerId, appTitle + title); + } + } } else { Node node = getNode(ui, event); if (node != null) { @@ -463,6 +495,8 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { private Node getNode(SuiteUi ui, Event event) { String nodePath = get(event, SuiteEvent.NODE_PATH); + if (nodePath != null && nodePath.equals(HOME_STATE)) + return ui.getUserDir(); String workspaceName = get(event, SuiteEvent.WORKSPACE); Session session = ui.getSession(workspaceName); Node node;