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
.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
.MouseAdapter
;
14 import org
.eclipse
.swt
.events
.MouseEvent
;
15 import org
.eclipse
.swt
.events
.SelectionAdapter
;
16 import org
.eclipse
.swt
.events
.SelectionEvent
;
17 import org
.eclipse
.swt
.layout
.GridData
;
18 import org
.eclipse
.swt
.layout
.GridLayout
;
19 import org
.eclipse
.swt
.widgets
.Button
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.swt
.widgets
.Label
;
23 import org
.osgi
.framework
.BundleContext
;
24 import org
.osgi
.framework
.wiring
.BundleWiring
;
26 /** Header of a standard Argeo Suite application. */
27 public class DefaultHeader
implements CmsUiProvider
{
28 public final static String TITLE_PROPERTY
= "argeo.suite.ui.header.title";
29 private Localized title
= null;
32 public Control
createUiPart(Composite parent
, Content context
) {
33 CmsView cmsView
= CmsSwtUtils
.getCmsView(parent
);
34 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
36 parent
.setLayout(CmsSwtUtils
.noSpaceGridLayout(new GridLayout(3, true)));
39 Composite lead
= new Composite(parent
, SWT
.NONE
);
40 CmsSwtUtils
.style(lead
, SuiteStyle
.header
);
41 lead
.setLayoutData(new GridData(SWT
.LEAD
, SWT
.CENTER
, true, false));
42 lead
.setLayout(new GridLayout());
43 Label lbl
= new Label(lead
, SWT
.NONE
);
44 // String title = properties.get(TITLE_PROPERTY);
45 // // TODO expose the localized
46 // lbl.setText(LocaleUtils.isLocaleKey(title) ? LocaleUtils.local(title, getClass().getClassLoader()).toString()
48 lbl
.setText(title
.lead());
49 CmsSwtUtils
.style(lbl
, SuiteStyle
.headerTitle
);
50 lbl
.setLayoutData(CmsSwtUtils
.fillWidth());
52 Composite middle
= new Composite(parent
, SWT
.NONE
);
53 CmsSwtUtils
.style(middle
, SuiteStyle
.header
);
54 middle
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, true, false));
55 middle
.setLayout(new GridLayout());
57 Composite end
= new Composite(parent
, SWT
.NONE
);
58 CmsSwtUtils
.style(end
, SuiteStyle
.header
);
59 end
.setLayoutData(new GridData(SWT
.END
, SWT
.CENTER
, true, false));
61 if (!cmsView
.isAnonymous()) {
62 end
.setLayout(new GridLayout(2, false));
63 Label userL
= new Label(end
, SWT
.NONE
);
64 CmsSwtUtils
.style(userL
, SuiteStyle
.header
);
65 userL
.setText(CurrentUser
.getDisplayName());
66 // Button logoutB = new Button(end, SWT.FLAT);
67 // logoutB.setImage(theme.getSmallIcon(SuiteIcon.logout));
68 // logoutB.addSelectionListener(new SelectionAdapter() {
69 // private static final long serialVersionUID = 7116760083964201233L;
72 // public void widgetSelected(SelectionEvent e) {
77 Label logOutL
= new Label(end
, 0);
78 logOutL
.setImage(theme
.getSmallIcon(SuiteIcon
.openUserMenu
));
79 logOutL
.addMouseListener(new MouseAdapter() {
80 private static final long serialVersionUID
= 6908266850511460799L;
83 public void mouseDown(MouseEvent e
) {
89 end
.setLayout(new GridLayout(1, false));
90 // required in order to avoid wrong height after logout
91 new Label(end
, SWT
.NONE
).setText("");
97 public void init(BundleContext bundleContext
, Map
<String
, String
> properties
) {
98 String titleStr
= (String
) properties
.get(TITLE_PROPERTY
);
99 if (titleStr
!= null) {
100 if (titleStr
.startsWith("%")) {
101 title
= new Localized() {
104 public String
name() {
109 public ClassLoader
getL10nClassLoader() {
110 return bundleContext
!= null
111 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
112 : getClass().getClassLoader();
116 title
= new Localized
.Untranslated(titleStr
);
121 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
125 public Localized
getTitle() {