]>
git.argeo.org Git - gpl/argeo-suite.git/blob - 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
.CmsTheme
;
17 import org
.argeo
.cms
.ui
.CmsUiProvider
;
18 import org
.argeo
.cms
.ui
.CmsView
;
19 import org
.argeo
.cms
.ui
.util
.CmsIcon
;
20 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
21 import org
.argeo
.suite
.RankedObject
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.osgi
.framework
.Constants
;
31 /** Side pane listing various perspectives. */
32 public class DefaultLeadPane
implements CmsUiProvider
{
33 private final static Log log
= LogFactory
.getLog(DefaultLeadPane
.class);
35 public static enum Property
{
36 defaultLayers
, adminLayers
;
39 private Map
<String
, RankedObject
<SuiteLayer
>> layers
= Collections
.synchronizedSortedMap(new TreeMap
<>());
40 private String
[] defaultLayers
;
41 private String
[] adminLayers
;
44 public Control
createUi(Composite parent
, Node node
) throws RepositoryException
{
45 CmsView cmsView
= CmsView
.getCmsView(parent
);
46 GridLayout layout
= new GridLayout();
47 layout
.verticalSpacing
= 10;
48 layout
.marginTop
= 10;
49 layout
.marginLeft
= 10;
50 layout
.marginRight
= 10;
51 parent
.setLayout(layout
);
54 for (String layerId
: defaultLayers
) {
55 if (layers
.containsKey(layerId
)) {
56 RankedObject
<SuiteLayer
> layerObj
= layers
.get(layerId
);
58 // TODO deal with i10n
59 String titleStr
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.title
.name());
60 Localized title
= null;
62 title
= new Localized
.Untranslated(titleStr
);
64 String iconName
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.icon
.name());
65 SuiteIcon icon
= null;
67 icon
= SuiteIcon
.valueOf(iconName
);
69 Button b
= createButton(parent
, layerId
, title
, icon
);
76 boolean isAdmin
= cmsView
.doAs(() -> CurrentUser
.isInRole(NodeConstants
.ROLE_USER_ADMIN
));
78 for (String layerId
: adminLayers
) {
79 if (layers
.containsKey(layerId
)) {
80 RankedObject
<SuiteLayer
> layerObj
= layers
.get(layerId
);
82 // TODO deal with i10n
83 String titleStr
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.title
.name());
84 Localized title
= null;
86 title
= new Localized
.Untranslated(titleStr
);
88 String iconName
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.icon
.name());
89 SuiteIcon icon
= null;
91 icon
= SuiteIcon
.valueOf(iconName
);
93 Button b
= createButton(parent
, layerId
, title
, icon
);
99 // Button dashboardB = createButton(parent, SuiteMsg.dashboard.name(), SuiteMsg.dashboard, SuiteIcon.dashboard);
100 if (!cmsView
.isAnonymous()) {
101 // createButton(parent, SuiteMsg.documents.name(), SuiteMsg.documents, SuiteIcon.documents);
102 // createButton(parent, SuiteMsg.people.name(), SuiteMsg.people, SuiteIcon.people);
103 // createButton(parent, SuiteMsg.locations.name(), SuiteMsg.locations, SuiteIcon.location);
108 protected Button
createButton(Composite parent
, String layer
, Localized msg
, CmsIcon icon
) {
109 CmsTheme theme
= CmsTheme
.getCmsTheme(parent
);
110 Button button
= new Button(parent
, SWT
.PUSH
);
111 CmsUiUtils
.style(button
, SuiteStyle
.leadPane
);
113 button
.setImage(icon
.getBigIcon(theme
));
114 button
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.BOTTOM
, true, false));
115 // button.setToolTipText(msg.lead());
117 Label lbl
= new Label(parent
, SWT
.NONE
);
118 CmsUiUtils
.style(lbl
, SuiteStyle
.leadPane
);
119 lbl
.setText(msg
.lead());
120 lbl
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, true, false));
122 CmsUiUtils
.sendEventOnSelect(button
, SuiteEvent
.switchLayer
.topic(), SuiteEvent
.LAYER
, layer
);
126 public void init(Map
<String
, Object
> properties
) {
127 defaultLayers
= (String
[]) properties
.get(Property
.defaultLayers
.toString());
128 if (defaultLayers
== null)
129 throw new IllegalArgumentException("Default layers must be set.");
130 if (log
.isDebugEnabled())
131 log
.debug("Default layers: " + Arrays
.asList(defaultLayers
));
132 adminLayers
= (String
[]) properties
.get(Property
.adminLayers
.toString());
133 if (log
.isDebugEnabled() && adminLayers
!= null)
134 log
.debug("Admin layers: " + Arrays
.asList(adminLayers
));
137 public void addLayer(SuiteLayer layer
, Map
<String
, Object
> properties
) {
138 if (properties
.containsKey(Constants
.SERVICE_PID
)) {
139 String pid
= (String
) properties
.get(Constants
.SERVICE_PID
);
140 RankedObject
.putIfHigherRank(layers
, pid
, layer
, properties
);