]>
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
.Collections
;
5 import java
.util
.TreeMap
;
8 import javax
.jcr
.RepositoryException
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.cms
.Localized
;
13 import org
.argeo
.cms
.ui
.CmsTheme
;
14 import org
.argeo
.cms
.ui
.CmsUiProvider
;
15 import org
.argeo
.cms
.ui
.CmsView
;
16 import org
.argeo
.cms
.ui
.util
.CmsIcon
;
17 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
18 import org
.argeo
.suite
.RankedObject
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Button
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Control
;
25 import org
.eclipse
.swt
.widgets
.Label
;
26 import org
.osgi
.framework
.Constants
;
28 /** Side pane listing various perspectives. */
29 public class DefaultLeadPane
implements CmsUiProvider
{
30 private final static Log log
= LogFactory
.getLog(DefaultLeadPane
.class);
32 public static enum Property
{
36 private Map
<String
, RankedObject
<SuiteLayer
>> layers
= Collections
.synchronizedSortedMap(new TreeMap
<>());
37 private String
[] defaultLayers
;
40 public Control
createUi(Composite parent
, Node node
) throws RepositoryException
{
41 CmsView cmsView
= CmsView
.getCmsView(parent
);
42 GridLayout layout
= new GridLayout();
43 layout
.verticalSpacing
= 10;
44 layout
.marginTop
= 10;
45 layout
.marginLeft
= 10;
46 layout
.marginRight
= 10;
47 parent
.setLayout(layout
);
50 for (String layerId
: defaultLayers
) {
51 if (layers
.containsKey(layerId
)) {
52 RankedObject
<SuiteLayer
> layerObj
= layers
.get(layerId
);
54 // TODO deal with i10n
55 String titleStr
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.title
.name());
56 Localized title
= null;
58 title
= new Localized
.Untranslated(titleStr
);
60 String iconName
= (String
) layerObj
.getProperties().get(SuiteLayer
.Property
.icon
.name());
61 SuiteIcon icon
= null;
63 icon
= SuiteIcon
.valueOf(iconName
);
65 Button b
= createButton(parent
, layerId
, title
, icon
);
71 // Button dashboardB = createButton(parent, SuiteMsg.dashboard.name(), SuiteMsg.dashboard, SuiteIcon.dashboard);
72 if (!cmsView
.isAnonymous()) {
73 // createButton(parent, SuiteMsg.documents.name(), SuiteMsg.documents, SuiteIcon.documents);
74 // createButton(parent, SuiteMsg.people.name(), SuiteMsg.people, SuiteIcon.people);
75 // createButton(parent, SuiteMsg.locations.name(), SuiteMsg.locations, SuiteIcon.location);
80 protected Button
createButton(Composite parent
, String layer
, Localized msg
, CmsIcon icon
) {
81 CmsTheme theme
= CmsTheme
.getCmsTheme(parent
);
82 Button button
= new Button(parent
, SWT
.PUSH
);
83 CmsUiUtils
.style(button
, SuiteStyle
.leadPane
);
85 button
.setImage(icon
.getBigIcon(theme
));
86 button
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.BOTTOM
, true, false));
87 // button.setToolTipText(msg.lead());
89 Label lbl
= new Label(parent
, SWT
.NONE
);
90 CmsUiUtils
.style(lbl
, SuiteStyle
.leadPane
);
91 lbl
.setText(msg
.lead());
92 lbl
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, true, false));
94 CmsUiUtils
.sendEventOnSelect(button
, SuiteEvent
.switchLayer
.topic(), SuiteEvent
.LAYER
, layer
);
98 public void init(Map
<String
, Object
> properties
) {
99 defaultLayers
= (String
[]) properties
.get(Property
.defaultLayers
.toString());
100 if (defaultLayers
== null)
101 throw new IllegalArgumentException("Default layers must be set.");
102 if (log
.isDebugEnabled())
103 log
.debug("Default layers: " + defaultLayers
);
106 public void addLayer(SuiteLayer layer
, Map
<String
, Object
> properties
) {
107 if (properties
.containsKey(Constants
.SERVICE_PID
)) {
108 String pid
= (String
) properties
.get(Constants
.SERVICE_PID
);
109 RankedObject
.putIfHigherRank(layers
, pid
, layer
, properties
);