1 package org
.argeo
.app
.ui
;
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
;
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;
29 public Control
createUiPart(Composite parent
, Content context
) {
30 CmsView cmsView
= CmsSwtUtils
.getCmsView(parent
);
31 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
33 parent
.setLayout(CmsSwtUtils
.noSpaceGridLayout(new GridLayout(3, true)));
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()
45 lbl
.setText(title
.lead());
46 CmsSwtUtils
.style(lbl
, SuiteStyle
.headerTitle
);
47 lbl
.setLayoutData(CmsSwtUtils
.fillWidth());
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());
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));
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;
69 // public void widgetSelected(SelectionEvent e) {
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;
80 public void mouseDown(MouseEvent e
) {
86 end
.setLayout(new GridLayout(1, false));
87 // required in order to avoid wrong height after logout
88 new Label(end
, SWT
.NONE
).setText("");
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() {
101 public String
name() {
106 public ClassLoader
getL10nClassLoader() {
107 return bundleContext
!= null
108 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
109 : getClass().getClassLoader();
113 title
= new Localized
.Untranslated(titleStr
);
118 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
122 public Localized
getTitle() {