]> git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.app.ui/src/org/argeo/app/ui/DefaultHeader.java
Adapt to changes in Argeo Commons.
[gpl/argeo-suite.git] / org.argeo.app.ui / src / org / argeo / app / ui / DefaultHeader.java
1 package org.argeo.app.ui;
2
3 import java.util.Map;
4
5 import org.argeo.api.acr.Content;
6 import org.argeo.api.cms.ux.CmsView;
7 import org.argeo.cms.Localized;
8 import org.argeo.cms.auth.CurrentUser;
9 import org.argeo.cms.swt.CmsSwtTheme;
10 import org.argeo.cms.swt.CmsSwtUtils;
11 import org.argeo.cms.ui.CmsUiProvider;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.events.SelectionAdapter;
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Label;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.wiring.BundleWiring;
23
24 /** Header of a standard Argeo Suite application. */
25 public class DefaultHeader implements CmsUiProvider {
26 public final static String TITLE_PROPERTY = "argeo.suite.ui.header.title";
27 private Localized title = null;
28
29 @Override
30 public Control createUiPart(Composite parent, Content context) {
31 CmsView cmsView = CmsSwtUtils.getCmsView(parent);
32 CmsSwtTheme theme = CmsSwtUtils.getCmsTheme(parent);
33
34 parent.setLayout(CmsSwtUtils.noSpaceGridLayout(new GridLayout(3, true)));
35
36 // TODO right to left
37 Composite lead = new Composite(parent, SWT.NONE);
38 CmsSwtUtils.style(lead, SuiteStyle.header);
39 lead.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, false));
40 lead.setLayout(new GridLayout());
41 Label lbl = new Label(lead, SWT.NONE);
42 // String title = properties.get(TITLE_PROPERTY);
43 // // TODO expose the localized
44 // lbl.setText(LocaleUtils.isLocaleKey(title) ? LocaleUtils.local(title, getClass().getClassLoader()).toString()
45 // : title);
46 lbl.setText(title.lead());
47 CmsSwtUtils.style(lbl, SuiteStyle.headerTitle);
48 lbl.setLayoutData(CmsSwtUtils.fillWidth());
49
50 Composite middle = new Composite(parent, SWT.NONE);
51 CmsSwtUtils.style(middle, SuiteStyle.header);
52 middle.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
53 middle.setLayout(new GridLayout());
54
55 Composite end = new Composite(parent, SWT.NONE);
56 CmsSwtUtils.style(end, SuiteStyle.header);
57 end.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
58
59 if (!cmsView.isAnonymous()) {
60 end.setLayout(new GridLayout(2, false));
61 Label userL = new Label(end, SWT.NONE);
62 CmsSwtUtils.style(userL, SuiteStyle.header);
63 userL.setText(CurrentUser.getDisplayName());
64 Button logoutB = new Button(end, SWT.FLAT);
65 // CmsUiUtils.style(logoutB, SuiteStyle.header);
66 logoutB.setImage(theme.getSmallIcon(SuiteIcon.logout));
67 logoutB.addSelectionListener(new SelectionAdapter() {
68 private static final long serialVersionUID = 7116760083964201233L;
69
70 @Override
71 public void widgetSelected(SelectionEvent e) {
72 cmsView.logout();
73 }
74
75 });
76 } else {
77 end.setLayout(new GridLayout(1, false));
78 // required in order to avoid wrong height after logout
79 new Label(end, SWT.NONE).setText("");
80
81 }
82 return lbl;
83 }
84
85 public void init(BundleContext bundleContext, Map<String, String> properties) {
86 String titleStr = (String) properties.get(TITLE_PROPERTY);
87 if (titleStr != null) {
88 if (titleStr.startsWith("%")) {
89 title = new Localized() {
90
91 @Override
92 public String name() {
93 return titleStr;
94 }
95
96 @Override
97 public ClassLoader getL10nClassLoader() {
98 return bundleContext != null
99 ? bundleContext.getBundle().adapt(BundleWiring.class).getClassLoader()
100 : getClass().getClassLoader();
101 }
102 };
103 } else {
104 title = new Localized.Untranslated(titleStr);
105 }
106 }
107 }
108
109 public void destroy(BundleContext bundleContext, Map<String, String> properties) {
110
111 }
112
113 public Localized getTitle() {
114 return title;
115 }
116
117 }