1 package org
.argeo
.app
.swt
.ux
;
5 import org
.argeo
.api
.acr
.Content
;
6 import org
.argeo
.api
.cms
.ux
.CmsView
;
7 import org
.argeo
.app
.ux
.SuiteIcon
;
8 import org
.argeo
.app
.ux
.SuiteStyle
;
9 import org
.argeo
.cms
.CurrentUser
;
10 import org
.argeo
.cms
.Localized
;
11 import org
.argeo
.cms
.swt
.CmsSwtTheme
;
12 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
13 import org
.argeo
.cms
.swt
.acr
.SwtUiProvider
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.MouseAdapter
;
16 import org
.eclipse
.swt
.events
.MouseEvent
;
17 import org
.eclipse
.swt
.layout
.GridData
;
18 import org
.eclipse
.swt
.layout
.GridLayout
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Control
;
21 import org
.eclipse
.swt
.widgets
.Label
;
22 import org
.osgi
.framework
.BundleContext
;
23 import org
.osgi
.framework
.wiring
.BundleWiring
;
25 /** Header of a standard Argeo Suite application. */
26 public class DefaultHeader
implements SwtUiProvider
{
27 public final static String TITLE_PROPERTY
= "argeo.suite.ui.header.title";
28 private Localized title
= null;
31 public Control
createUiPart(Composite parent
, Content context
) {
32 CmsView cmsView
= CmsSwtUtils
.getCmsView(parent
);
33 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
35 parent
.setLayout(CmsSwtUtils
.noSpaceGridLayout(new GridLayout(3, true)));
38 Composite lead
= new Composite(parent
, SWT
.NONE
);
39 CmsSwtUtils
.style(lead
, SuiteStyle
.header
);
40 lead
.setLayoutData(new GridData(SWT
.LEAD
, SWT
.CENTER
, true, false));
41 lead
.setLayout(new GridLayout());
42 Label lbl
= new Label(lead
, SWT
.NONE
);
43 // String title = properties.get(TITLE_PROPERTY);
44 // // TODO expose the localized
45 // lbl.setText(LocaleUtils.isLocaleKey(title) ? LocaleUtils.local(title, getClass().getClassLoader()).toString()
47 lbl
.setText(title
.lead());
48 CmsSwtUtils
.style(lbl
, SuiteStyle
.headerTitle
);
49 lbl
.setLayoutData(CmsSwtUtils
.fillWidth());
51 Composite middle
= new Composite(parent
, SWT
.NONE
);
52 CmsSwtUtils
.style(middle
, SuiteStyle
.header
);
53 middle
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, true, false));
54 middle
.setLayout(new GridLayout());
56 Composite end
= new Composite(parent
, SWT
.NONE
);
57 CmsSwtUtils
.style(end
, SuiteStyle
.header
);
58 end
.setLayoutData(new GridData(SWT
.END
, SWT
.CENTER
, true, false));
60 if (!cmsView
.isAnonymous()) {
61 end
.setLayout(new GridLayout(2, false));
62 Label userL
= new Label(end
, SWT
.NONE
);
63 CmsSwtUtils
.style(userL
, SuiteStyle
.header
);
64 userL
.setText(CurrentUser
.getDisplayName());
65 // Button logoutB = new Button(end, SWT.FLAT);
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) {
76 Label logOutL
= new Label(end
, 0);
77 logOutL
.setImage(theme
.getSmallIcon(SuiteIcon
.openUserMenu
));
78 logOutL
.addMouseListener(new MouseAdapter() {
79 private static final long serialVersionUID
= 6908266850511460799L;
82 public void mouseDown(MouseEvent e
) {
88 end
.setLayout(new GridLayout(1, false));
89 // required in order to avoid wrong height after logout
90 new Label(end
, SWT
.NONE
).setText("");
96 public void init(BundleContext bundleContext
, Map
<String
, String
> properties
) {
97 String titleStr
= (String
) properties
.get(TITLE_PROPERTY
);
98 if (titleStr
!= null) {
99 if (titleStr
.startsWith("%")) {
100 title
= new Localized() {
103 public String
name() {
108 public ClassLoader
getL10nClassLoader() {
109 return bundleContext
!= null
110 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
111 : getClass().getClassLoader();
115 title
= new Localized
.Untranslated(titleStr
);
120 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
124 public Localized
getTitle() {