1 package org
.argeo
.cms
.ui
.workbench
;
3 import java
.io
.IOException
;
4 import java
.util
.ResourceBundle
;
6 import javax
.security
.auth
.callback
.Callback
;
7 import javax
.security
.auth
.callback
.CallbackHandler
;
8 import javax
.security
.auth
.callback
.UnsupportedCallbackException
;
10 import org
.argeo
.api
.cms
.CmsLog
;
11 import org
.argeo
.cms
.CmsException
;
12 import org
.eclipse
.core
.runtime
.ILogListener
;
13 import org
.eclipse
.core
.runtime
.IStatus
;
14 import org
.eclipse
.core
.runtime
.Platform
;
15 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
16 import org
.eclipse
.swt
.widgets
.Display
;
17 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
18 import org
.osgi
.framework
.BundleContext
;
19 import org
.osgi
.framework
.ServiceRegistration
;
21 /** The activator class controls the plug-in life cycle */
22 public class WorkbenchUiPlugin
extends AbstractUIPlugin
implements ILogListener
{
23 private final static CmsLog log
= CmsLog
.getLog(WorkbenchUiPlugin
.class);
26 public final static String PLUGIN_ID
= "org.argeo.cms.ui.workbench"; //$NON-NLS-1$
27 public final static String THEME_PLUGIN_ID
= "org.argeo.cms.ui.theme"; //$NON-NLS-1$
29 private ResourceBundle messages
;
30 private static BundleContext bundleContext
;
32 public static InheritableThreadLocal
<Display
> display
= new InheritableThreadLocal
<Display
>() {
35 protected Display
initialValue() {
36 return Display
.getCurrent();
40 final static String CONTEXT_KEYRING
= "KEYRING";
42 private CallbackHandler defaultCallbackHandler
;
43 private ServiceRegistration
<CallbackHandler
> defaultCallbackHandlerReg
;
45 // The shared instance
46 private static WorkbenchUiPlugin plugin
;
48 public void start(BundleContext context
) throws Exception
{
50 bundleContext
= context
;
51 defaultCallbackHandler
= new DefaultCallbackHandler();
52 defaultCallbackHandlerReg
= context
.registerService(CallbackHandler
.class, defaultCallbackHandler
, null);
55 messages
= ResourceBundle
.getBundle(PLUGIN_ID
+ ".messages");
56 Platform
.addLogListener(this);
57 if (log
.isTraceEnabled())
58 log
.trace("Eclipse logging now directed to standard logging");
61 public void stop(BundleContext context
) throws Exception
{
63 defaultCallbackHandlerReg
.unregister();
66 public static BundleContext
getBundleContext() {
71 * Returns the shared instance
73 * @return the shared instance
75 public static WorkbenchUiPlugin
getDefault() {
79 protected class DefaultCallbackHandler
implements CallbackHandler
{
80 public void handle(final Callback
[] callbacks
) throws IOException
, UnsupportedCallbackException
{
82 // if (display != null) // RCP
83 Display displayToUse
= display
.get();
84 if (displayToUse
== null)// RCP
85 displayToUse
= Display
.getDefault();
86 displayToUse
.syncExec(new Runnable() {
88 DefaultLoginDialog dialog
= new DefaultLoginDialog(display
.get().getActiveShell());
90 dialog
.handle(callbacks
);
91 } catch (IOException e
) {
92 throw new CmsException("Cannot open dialog", e
);
97 // DefaultLoginDialog dialog = new DefaultLoginDialog();
98 // dialog.handle(callbacks);
104 public static ImageDescriptor
getImageDescriptor(String path
) {
105 return imageDescriptorFromPlugin(THEME_PLUGIN_ID
, path
);
108 /** Returns the internationalized label for the given key */
109 public static String
getMessage(String key
) {
111 return getDefault().messages
.getString(key
);
112 } catch (NullPointerException npe
) {
113 log
.warn(key
+ " not found.");
119 * Gives access to the internationalization message bundle. Returns null in case
120 * this UiPlugin is not started (for JUnit tests, by instance)
122 public static ResourceBundle
getMessagesBundle() {
123 if (getDefault() != null)
125 return getDefault().messages
;
130 public void logging(IStatus status
, String plugin
) {
131 CmsLog pluginLog
= CmsLog
.getLog(plugin
);
132 Integer severity
= status
.getSeverity();
133 if (severity
== IStatus
.ERROR
)
134 pluginLog
.error(status
.getMessage(), status
.getException());
135 else if (severity
== IStatus
.WARNING
)
136 pluginLog
.warn(status
.getMessage(), status
.getException());
137 else if (severity
== IStatus
.INFO
)
138 pluginLog
.info(status
.getMessage(), status
.getException());
139 else if (severity
== IStatus
.CANCEL
)
140 if (pluginLog
.isDebugEnabled())
141 pluginLog
.debug(status
.getMessage(), status
.getException());