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