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%2FDefaultLeadPane.java;h=7f2fe9fb53d6a6f5019d87817783d94601b8af15;hp=48e6149d6af6aba132523a1b28e4cacf0356f890;hb=c813f6f1fdff65e43bdf56a49f9a93ddc8808d73;hpb=ff73a753e98016467d44c3a0beac79d590874520 diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultLeadPane.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultLeadPane.java index 48e6149..7f2fe9f 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultLeadPane.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultLeadPane.java @@ -1,32 +1,44 @@ package org.argeo.suite.ui; -import java.util.HashMap; +import java.util.Arrays; +import java.util.Collections; import java.util.Map; +import java.util.TreeMap; import javax.jcr.Node; import javax.jcr.RepositoryException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.api.NodeConstants; import org.argeo.cms.Localized; +import org.argeo.cms.auth.CurrentUser; import org.argeo.cms.ui.CmsTheme; import org.argeo.cms.ui.CmsUiProvider; import org.argeo.cms.ui.CmsView; import org.argeo.cms.ui.util.CmsIcon; import org.argeo.cms.ui.util.CmsUiUtils; -import org.argeo.eclipse.ui.Selected; +import org.argeo.suite.RankedObject; import org.eclipse.swt.SWT; +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.osgi.service.event.Event; -import org.osgi.service.event.EventAdmin; +import org.eclipse.swt.widgets.Label; +import org.osgi.framework.Constants; /** Side pane listing various perspectives. */ public class DefaultLeadPane implements CmsUiProvider { private final static Log log = LogFactory.getLog(DefaultLeadPane.class); - private EventAdmin eventAdmin; + + public static enum Property { + defaultLayers, adminLayers; + } + + private Map> layers = Collections.synchronizedSortedMap(new TreeMap<>()); + private String[] defaultLayers; + private String[] adminLayers; @Override public Control createUi(Composite parent, Node node) throws RepositoryException { @@ -38,31 +50,105 @@ public class DefaultLeadPane implements CmsUiProvider { layout.marginRight = 10; parent.setLayout(layout); - Button dashboardB = createButton(parent, SuiteMsg.dashboard.name(), SuiteMsg.dashboard, SuiteIcon.dashboard); + Button first = null; + for (String layerId : defaultLayers) { + if (layers.containsKey(layerId)) { + RankedObject layerObj = layers.get(layerId); + + // TODO deal with i10n + String titleStr = (String) layerObj.getProperties().get(SuiteLayer.Property.title.name()); + Localized title = null; + if (titleStr != null) + title = new Localized.Untranslated(titleStr); + + String iconName = (String) layerObj.getProperties().get(SuiteLayer.Property.icon.name()); + SuiteIcon icon = null; + if (iconName != null) + icon = SuiteIcon.valueOf(iconName); + + Button b = createButton(parent, layerId, title, icon); + if (first == null) + first = b; + } + } + + // TODO factorise + boolean isAdmin = cmsView.doAs(() -> CurrentUser.isInRole(NodeConstants.ROLE_USER_ADMIN)); + if (isAdmin && adminLayers != null) + for (String layerId : adminLayers) { + if (layers.containsKey(layerId)) { + RankedObject layerObj = layers.get(layerId); + + // TODO deal with i10n + String titleStr = (String) layerObj.getProperties().get(SuiteLayer.Property.title.name()); + Localized title = null; + if (titleStr != null) + title = new Localized.Untranslated(titleStr); + + String iconName = (String) layerObj.getProperties().get(SuiteLayer.Property.icon.name()); + SuiteIcon icon = null; + if (iconName != null) + icon = SuiteIcon.valueOf(iconName); + + Button b = createButton(parent, layerId, title, icon); + if (first == null) + first = b; + } + } + +// Button dashboardB = createButton(parent, SuiteMsg.dashboard.name(), SuiteMsg.dashboard, SuiteIcon.dashboard); if (!cmsView.isAnonymous()) { - createButton(parent, SuiteMsg.documents.name(), SuiteMsg.documents, SuiteIcon.documents); - createButton(parent, SuiteMsg.people.name(), SuiteMsg.people, SuiteIcon.people); - createButton(parent, SuiteMsg.locations.name(), SuiteMsg.locations, SuiteIcon.location); +// createButton(parent, SuiteMsg.documents.name(), SuiteMsg.documents, SuiteIcon.documents); +// createButton(parent, SuiteMsg.people.name(), SuiteMsg.people, SuiteIcon.people); +// createButton(parent, SuiteMsg.locations.name(), SuiteMsg.locations, SuiteIcon.location); } - return dashboardB; + return first; } protected Button createButton(Composite parent, String layer, Localized msg, CmsIcon icon) { CmsTheme theme = CmsTheme.getCmsTheme(parent); Button button = new Button(parent, SWT.PUSH); CmsUiUtils.style(button, SuiteStyle.leadPane); - button.setToolTipText(msg.lead()); - button.setImage(icon.getBigIcon(theme)); - CmsUiUtils.sendEventOnSelect(button, SuiteEvent.switchLayer.topic(), SuiteEvent.LAYER_PARAM, layer); + if (icon != null) + button.setImage(icon.getBigIcon(theme)); + button.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, false)); + // button.setToolTipText(msg.lead()); + if (msg != null) { + Label lbl = new Label(parent, SWT.NONE); + CmsUiUtils.style(lbl, SuiteStyle.leadPane); + lbl.setText(msg.lead()); + lbl.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false)); + } + CmsUiUtils.sendEventOnSelect(button, SuiteEvent.switchLayer.topic(), SuiteEvent.LAYER, layer); return button; } - public void init(Map properties) { - + public void init(Map properties) { + defaultLayers = (String[]) properties.get(Property.defaultLayers.toString()); + if (defaultLayers == null) + throw new IllegalArgumentException("Default layers must be set."); + if (log.isDebugEnabled()) + log.debug("Default layers: " + Arrays.asList(defaultLayers)); + adminLayers = (String[]) properties.get(Property.adminLayers.toString()); + if (log.isDebugEnabled() && adminLayers != null) + log.debug("Admin layers: " + Arrays.asList(adminLayers)); } - public void setEventAdmin(EventAdmin eventAdmin) { - this.eventAdmin = eventAdmin; + public void addLayer(SuiteLayer layer, Map properties) { + if (properties.containsKey(Constants.SERVICE_PID)) { + String pid = (String) properties.get(Constants.SERVICE_PID); + RankedObject.putIfHigherRank(layers, pid, layer, properties); + } } + public void removeLayer(SuiteLayer layer, Map properties) { + if (properties.containsKey(Constants.SERVICE_PID)) { + String pid = (String) properties.get(Constants.SERVICE_PID); + if (layers.containsKey(pid)) { + if (layers.get(pid).equals(new RankedObject(layer, properties))) { + layers.remove(pid); + } + } + } + } }