]> git.argeo.org Git - gpl/argeo-suite.git/blob - argeo/suite/ui/DefaultHeader.java
Prepare next development cycle
[gpl/argeo-suite.git] / argeo / suite / ui / DefaultHeader.java
1 package org.argeo.suite.ui;
2
3 import java.util.Dictionary;
4 import java.util.Map;
5 import java.util.TreeMap;
6
7 import javax.jcr.Node;
8 import javax.jcr.RepositoryException;
9
10 import org.argeo.cms.LocaleUtils;
11 import org.argeo.cms.auth.CurrentUser;
12 import org.argeo.cms.ui.CmsTheme;
13 import org.argeo.cms.ui.CmsUiProvider;
14 import org.argeo.cms.ui.CmsView;
15 import org.argeo.cms.ui.util.CmsUiUtils;
16 import org.argeo.util.LangUtils;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
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.service.cm.ConfigurationException;
27 import org.osgi.service.cm.ManagedService;
28
29 public class DefaultHeader implements CmsUiProvider, ManagedService {
30 public final static String TITLE_PROPERTY = "argeo.suite.ui.header.title";
31 private Map<String, String> properties;
32
33 @Override
34 public Control createUi(Composite parent, Node context) throws RepositoryException {
35 CmsView cmsView = CmsView.getCmsView(parent);
36 CmsTheme theme = CmsTheme.getCmsTheme(parent);
37
38 parent.setLayout(CmsUiUtils.noSpaceGridLayout(new GridLayout(3, true)));
39
40 // TODO right to left
41 Composite lead = new Composite(parent, SWT.NONE);
42 CmsUiUtils.style(lead, SuiteStyle.header);
43 lead.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, false));
44 lead.setLayout(new GridLayout());
45 Label lbl = new Label(lead, SWT.NONE);
46 String title = properties.get(TITLE_PROPERTY);
47 lbl.setText(LocaleUtils.isLocaleKey(title) ? LocaleUtils.local(title, getClass().getClassLoader()).toString()
48 : title);
49 CmsUiUtils.style(lbl, SuiteStyle.headerTitle);
50 lbl.setLayoutData(CmsUiUtils.fillWidth());
51
52 Composite middle = new Composite(parent, SWT.NONE);
53 CmsUiUtils.style(middle, SuiteStyle.header);
54 middle.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
55 middle.setLayout(new GridLayout());
56
57 Composite end = new Composite(parent, SWT.NONE);
58 CmsUiUtils.style(end, SuiteStyle.header);
59 end.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
60
61 if (!cmsView.isAnonymous()) {
62 end.setLayout(new GridLayout(2, false));
63 Label userL = new Label(end, SWT.NONE);
64 CmsUiUtils.style(userL, SuiteStyle.header);
65 userL.setText(CurrentUser.getDisplayName());
66 Button logoutB = new Button(end, SWT.FLAT);
67 // CmsUiUtils.style(logoutB, SuiteStyle.header);
68 logoutB.setImage(SuiteIcon.logout.getSmallIcon(theme));
69 logoutB.addSelectionListener(new SelectionAdapter() {
70 private static final long serialVersionUID = 7116760083964201233L;
71
72 @Override
73 public void widgetSelected(SelectionEvent e) {
74 cmsView.logout();
75 }
76
77 });
78 } else {
79 end.setLayout(new GridLayout(1, false));
80 // required in order to avoid wrong height after logout
81 new Label(end, SWT.NONE).setText("");
82
83 }
84 return lbl;
85 }
86
87 public void init(Map<String, String> properties) {
88 this.properties = new TreeMap<>(properties);
89 }
90
91 @Override
92 public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
93 if (properties != null)
94 this.properties.putAll(LangUtils.dictToStringMap(properties));
95 }
96
97 }