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
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.cms
.CmsException
;
13 import org
.argeo
.cms
.ui
.widgets
.auth
.DefaultLoginDialog
;
14 import org
.eclipse
.core
.runtime
.ILogListener
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Platform
;
17 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
18 import org
.eclipse
.swt
.widgets
.Display
;
19 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
20 import org
.osgi
.framework
.BundleContext
;
21 import org
.osgi
.framework
.ServiceRegistration
;
23 /** The activator class controls the plug-in life cycle */
24 public class WorkbenchUiPlugin
extends AbstractUIPlugin
implements ILogListener
{
25 private final static Log log
= LogFactory
.getLog(WorkbenchUiPlugin
.class);
28 public final static String PLUGIN_ID
= "org.argeo.cms.ui.workbench"; //$NON-NLS-1$
29 public final static String THEME_PLUGIN_ID
= "org.argeo.cms.ui.theme"; //$NON-NLS-1$
31 private ResourceBundle messages
;
32 private static BundleContext bundleContext
;
34 public static InheritableThreadLocal
<Display
> display
= new InheritableThreadLocal
<Display
>() {
37 protected Display
initialValue() {
38 return Display
.getCurrent();
42 final static String CONTEXT_KEYRING
= "KEYRING";
44 private CallbackHandler defaultCallbackHandler
;
45 private ServiceRegistration
<CallbackHandler
> defaultCallbackHandlerReg
;
47 // The shared instance
48 private static WorkbenchUiPlugin plugin
;
50 public void start(BundleContext context
) throws Exception
{
52 bundleContext
= context
;
53 defaultCallbackHandler
= new DefaultCallbackHandler();
54 defaultCallbackHandlerReg
= context
.registerService(CallbackHandler
.class, defaultCallbackHandler
, null);
57 messages
= ResourceBundle
.getBundle(PLUGIN_ID
+ ".messages");
58 Platform
.addLogListener(this);
59 if (log
.isTraceEnabled())
60 log
.trace("Eclipse logging now directed to standard logging");
63 public void stop(BundleContext context
) throws Exception
{
65 defaultCallbackHandlerReg
.unregister();
68 public static BundleContext
getBundleContext() {
73 * Returns the shared instance
75 * @return the shared instance
77 public static WorkbenchUiPlugin
getDefault() {
81 protected class DefaultCallbackHandler
implements CallbackHandler
{
82 public void handle(final Callback
[] callbacks
) throws IOException
, UnsupportedCallbackException
{
84 // if (display != null) // RCP
85 Display displayToUse
= display
.get();
86 if (displayToUse
== null)// RCP
87 displayToUse
= Display
.getDefault();
88 displayToUse
.syncExec(new Runnable() {
90 DefaultLoginDialog dialog
= new DefaultLoginDialog(display
.get().getActiveShell());
92 dialog
.handle(callbacks
);
93 } catch (IOException e
) {
94 throw new CmsException("Cannot open dialog", e
);
99 // DefaultLoginDialog dialog = new DefaultLoginDialog();
100 // dialog.handle(callbacks);
106 public static ImageDescriptor
getImageDescriptor(String path
) {
107 return imageDescriptorFromPlugin(THEME_PLUGIN_ID
, path
);
110 /** Returns the internationalized label for the given key */
111 public static String
getMessage(String key
) {
113 return getDefault().messages
.getString(key
);
114 } catch (NullPointerException npe
) {
115 log
.warn(key
+ " not found.");
121 * Gives access to the internationalization message bundle. Returns null in case
122 * this UiPlugin is not started (for JUnit tests, by instance)
124 public static ResourceBundle
getMessagesBundle() {
125 if (getDefault() != null)
127 return getDefault().messages
;
132 public void logging(IStatus status
, String plugin
) {
133 Log pluginLog
= LogFactory
.getLog(plugin
);
134 Integer severity
= status
.getSeverity();
135 if (severity
== IStatus
.ERROR
)
136 pluginLog
.error(status
.getMessage(), status
.getException());
137 else if (severity
== IStatus
.WARNING
)
138 pluginLog
.warn(status
.getMessage(), status
.getException());
139 else if (severity
== IStatus
.INFO
)
140 pluginLog
.info(status
.getMessage(), status
.getException());
141 else if (severity
== IStatus
.CANCEL
)
142 if (pluginLog
.isDebugEnabled())
143 pluginLog
.debug(status
.getMessage(), status
.getException());