Finalize UI lifecycle.
[gpl/argeo-suite.git] / core / org.argeo.suite.ui / src / org / argeo / suite / ui / DefaultHeader.java
index d3b474000e1ed57b13b65940b867163e5b597817..080bac2cfa121b92817a22a95aecabfb700c6641 100644 (file)
@@ -23,6 +23,8 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 
@@ -38,26 +40,6 @@ public class DefaultHeader implements CmsUiProvider, ManagedService {
                CmsView cmsView = CmsView.getCmsView(parent);
                CmsTheme theme = CmsTheme.getCmsTheme(parent);
 
-               String titleStr = (String) properties.get(TITLE_PROPERTY);
-               if (titleStr != null) {
-                       if (titleStr.startsWith("%")) {
-                               title = new Localized() {
-
-                                       @Override
-                                       public String name() {
-                                               return titleStr;
-                                       }
-
-                                       @Override
-                                       public ClassLoader getL10nClassLoader() {
-                                               return getClass().getClassLoader();
-                                       }
-                               };
-                       } else {
-                               title = new Localized.Untranslated(titleStr);
-                       }
-               }
-
                parent.setLayout(CmsUiUtils.noSpaceGridLayout(new GridLayout(3, true)));
 
                // TODO right to left
@@ -109,8 +91,33 @@ public class DefaultHeader implements CmsUiProvider, ManagedService {
                return lbl;
        }
 
-       public void init(Map<String, String> properties) {
+       public void init(BundleContext bundleContext, Map<String, String> properties) {
                this.properties = new TreeMap<>(properties);
+               String titleStr = (String) properties.get(TITLE_PROPERTY);
+               if (titleStr != null) {
+                       if (titleStr.startsWith("%")) {
+                               title = new Localized() {
+
+                                       @Override
+                                       public String name() {
+                                               return titleStr;
+                                       }
+
+                                       @Override
+                                       public ClassLoader getL10nClassLoader() {
+                                               return bundleContext != null
+                                                               ? bundleContext.getBundle().adapt(BundleWiring.class).getClassLoader()
+                                                               : getClass().getClassLoader();
+                                       }
+                               };
+                       } else {
+                               title = new Localized.Untranslated(titleStr);
+                       }
+               }
+       }
+
+       public void destroy() {
+
        }
 
        @Override
@@ -119,4 +126,8 @@ public class DefaultHeader implements CmsUiProvider, ManagedService {
                        this.properties.putAll(LangUtils.dictToStringMap(properties));
        }
 
+       public Localized getTitle() {
+               return title;
+       }
+
 }