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
.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
;
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;
30 public Control
createUiPart(Composite parent
, Content context
) {
31 CmsView cmsView
= CmsSwtUtils
.getCmsView(parent
);
32 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
34 parent
.setLayout(CmsSwtUtils
.noSpaceGridLayout(new GridLayout(3, true)));
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()
46 lbl
.setText(title
.lead());
47 CmsSwtUtils
.style(lbl
, SuiteStyle
.headerTitle
);
48 lbl
.setLayoutData(CmsSwtUtils
.fillWidth());
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());
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));
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;
71 public void widgetSelected(SelectionEvent e
) {
77 end
.setLayout(new GridLayout(1, false));
78 // required in order to avoid wrong height after logout
79 new Label(end
, SWT
.NONE
).setText("");
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() {
92 public String
name() {
97 public ClassLoader
getL10nClassLoader() {
98 return bundleContext
!= null
99 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
100 : getClass().getClassLoader();
104 title
= new Localized
.Untranslated(titleStr
);
109 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
113 public Localized
getTitle() {