]>
git.argeo.org Git - gpl/argeo-suite.git/blob - core/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultLeadPane.java
1 package org
.argeo
.suite
.ui
;
3 import java
.util
.Arrays
;
4 import java
.util
.Collections
;
6 import java
.util
.TreeMap
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.api
.NodeConstants
;
14 import org
.argeo
.cms
.Localized
;
15 import org
.argeo
.cms
.auth
.CurrentUser
;
16 import org
.argeo
.cms
.ui
.CmsUiProvider
;
17 import org
.argeo
.cms
.ui
.CmsView
;
18 import org
.argeo
.suite
.RankedObject
;
19 import org
.eclipse
.swt
.layout
.GridLayout
;
20 import org
.eclipse
.swt
.widgets
.Button
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Control
;
23 import org
.osgi
.framework
.Constants
;
25 /** Side pane listing various perspectives. */
26 public class DefaultLeadPane
implements CmsUiProvider
{
27 private final static Log log
= LogFactory
.getLog(DefaultLeadPane
.class);
29 public static enum Property
{
30 defaultLayers
, adminLayers
;
33 private Map
<String
, RankedObject
<SuiteLayer
>> layers
= Collections
.synchronizedSortedMap(new TreeMap
<>());
34 private String
[] defaultLayers
;
35 private String
[] adminLayers
;
38 public Control
createUi(Composite parent
, Node node
) throws RepositoryException
{
39 CmsView cmsView
= CmsView
.getCmsView(parent
);
40 GridLayout layout
= new GridLayout();
41 layout
.verticalSpacing
= 10;
42 layout
.marginTop
= 10;
43 layout
.marginLeft
= 10;
44 layout
.marginRight
= 10;
45 parent
.setLayout(layout
);
48 for (String layerId
: defaultLayers
) {
49 if (layers
.containsKey(layerId
)) {
50 RankedObject
<SuiteLayer
> layerObj
= layers
.get(layerId
);
52 // TODO deal with i10n
53 String titleStr
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.title
.name());
54 Localized title
= null;
56 title
= new Localized
.Untranslated(titleStr
);
58 String iconName
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.icon
.name());
59 SuiteIcon icon
= null;
61 icon
= SuiteIcon
.valueOf(iconName
);
63 Button b
= SuiteUiUtils
.createLayerButton(parent
, layerId
, title
, icon
);
70 boolean isAdmin
= cmsView
.doAs(() -> CurrentUser
.isInRole(NodeConstants
.ROLE_USER_ADMIN
));
71 if (isAdmin
&& adminLayers
!= null)
72 for (String layerId
: adminLayers
) {
73 if (layers
.containsKey(layerId
)) {
74 RankedObject
<SuiteLayer
> layerObj
= layers
.get(layerId
);
76 // TODO deal with i10n
77 String titleStr
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.title
.name());
78 Localized title
= null;
80 title
= new Localized
.Untranslated(titleStr
);
82 String iconName
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.icon
.name());
83 SuiteIcon icon
= null;
85 icon
= SuiteIcon
.valueOf(iconName
);
87 Button b
= SuiteUiUtils
.createLayerButton(parent
, layerId
, title
, icon
);
93 // Button dashboardB = createButton(parent, SuiteMsg.dashboard.name(), SuiteMsg.dashboard, SuiteIcon.dashboard);
94 if (!cmsView
.isAnonymous()) {
95 // createButton(parent, SuiteMsg.documents.name(), SuiteMsg.documents, SuiteIcon.documents);
96 // createButton(parent, SuiteMsg.people.name(), SuiteMsg.people, SuiteIcon.people);
97 // createButton(parent, SuiteMsg.locations.name(), SuiteMsg.locations, SuiteIcon.location);
102 public void init(Map
<String
, Object
> properties
) {
103 defaultLayers
= (String
[]) properties
.get(Property
.defaultLayers
.toString());
104 if (defaultLayers
== null)
105 throw new IllegalArgumentException("Default layers must be set.");
106 if (log
.isDebugEnabled())
107 log
.debug("Default layers: " + Arrays
.asList(defaultLayers
));
108 adminLayers
= (String
[]) properties
.get(Property
.adminLayers
.toString());
109 if (log
.isDebugEnabled() && adminLayers
!= null)
110 log
.debug("Admin layers: " + Arrays
.asList(adminLayers
));
113 public void addLayer(SuiteLayer layer
, Map
<String
, Object
> properties
) {
114 if (properties
.containsKey(Constants
.SERVICE_PID
)) {
115 String pid
= (String
) properties
.get(Constants
.SERVICE_PID
);
116 RankedObject
.putIfHigherRank(layers
, pid
, layer
, properties
);
120 public void removeLayer(SuiteLayer layer
, Map
<String
, Object
> properties
) {
121 if (properties
.containsKey(Constants
.SERVICE_PID
)) {
122 String pid
= (String
) properties
.get(Constants
.SERVICE_PID
);
123 if (layers
.containsKey(pid
)) {
124 if (layers
.get(pid
).equals(new RankedObject
<SuiteLayer
>(layer
, properties
))) {