Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-08-09 09:15:06 +0000
committerUwe Stieber2012-08-09 09:15:06 +0000
commitec531d22c43aa3ecae948aa20b4defdfe4877ace (patch)
tree62b34c1a929c62d3553ac9ce27520b4b686fe0d9 /target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src
parent2c9db2f4f297f92647e3c36d8d46d5d9f7b26ae9 (diff)
downloadorg.eclipse.tcf-ec531d22c43aa3ecae948aa20b4defdfe4877ace.tar.gz
org.eclipse.tcf-ec531d22c43aa3ecae948aa20b4defdfe4877ace.tar.xz
org.eclipse.tcf-ec531d22c43aa3ecae948aa20b4defdfe4877ace.zip
Target Explorer: Unify properties editor page save handling and provide StatusHandlerUtil
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java
new file mode 100644
index 000000000..dfec3d827
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.statushandler/src/org/eclipse/tcf/te/runtime/statushandler/StatusHandlerUtil.java
@@ -0,0 +1,98 @@
+/**
+ * StatusHandlerUtil.java
+ * Created on May 21, 2012
+ *
+ * Copyright (c) 2012 Wind River Systems, Inc.
+ *
+ * The right to copy, distribute, modify, or otherwise make use
+ * of this software may be licensed only pursuant to the terms
+ * of an applicable Wind River license agreement.
+ */
+package org.eclipse.tcf.te.runtime.statushandler;
+
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+import org.eclipse.tcf.te.runtime.statushandler.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandler;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandlerConstants;
+
+/**
+ * Status handler utility implementations.
+ */
+public final class StatusHandlerUtil {
+
+ /**
+ * Handle the given status for the given context.
+ *
+ * @param status The status. Must not be <code>null</code>.
+ * @param context The context. Must not be <code>null</code>.
+ * @param template The message template or <code>null</code>.
+ * @param title The dialog title or <code>null</code>.
+ * @param contextHelpId The context help id or <code>null</code>.
+ * @param caller The caller or <code>null</code>.
+ * @param done The callback or <code>null</code>.
+ */
+ public static void handleStatus(IStatus status, Object context, String template, String title, String contextHelpId, Object caller, ICallback done) {
+ Assert.isNotNull(status);
+ Assert.isNotNull(context);
+
+ IStatusHandler[] handlers = StatusHandlerManager.getInstance().getHandler(context);
+ if (handlers.length > 0) {
+ IPropertiesContainer data = new PropertiesContainer();
+
+ if (title != null) data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, title);
+ if (contextHelpId != null) data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, contextHelpId);
+ if (caller != null) data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, caller);
+
+ updateMessage(status, template);
+
+ handlers[0].handleStatus(status, data, null);
+ } else {
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+
+ private static void updateMessage(IStatus status, String template) {
+ Assert.isNotNull(status);
+
+ StringBuilder message = new StringBuilder();
+ String msg = status.getMessage();
+
+ if (msg != null && msg.contains("Error text:")) { //$NON-NLS-1$
+ StringTokenizer tokenizer = new StringTokenizer(msg, ","); //$NON-NLS-1$
+ while (tokenizer.hasMoreElements()) {
+ String token = tokenizer.nextToken();
+ if (token.trim().startsWith("Error text:")) { //$NON-NLS-1$
+ token = token.replaceAll("Error text:", " "); //$NON-NLS-1$ //$NON-NLS-2$
+ message.append(template != null ? NLS.bind(template, token.trim()) : token.trim());
+ break;
+ }
+ }
+ }
+
+ if (message.length() > 0) {
+ try {
+ final Field f = status.getClass().getDeclaredField("message"); //$NON-NLS-1$
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ f.setAccessible(true);
+ return null;
+ }
+ });
+ f.set(status, message.toString());
+ }
+ catch (Exception e) {}
+ }
+ }
+}

Back to the top