summaryrefslogtreecommitdiffstats
path: root/rba.tool.core/src/rba/tool/core/console/ConsoleManager.java
diff options
context:
space:
mode:
authorKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-03 18:42:39 +0900
committerKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-06 19:32:38 +0900
commitbe4f78978faba3d3ceb88df02a7f93a2e09ff1e0 (patch)
tree1f3f1a96251ac4f655c8a96fc33d5d4ee779cd06 /rba.tool.core/src/rba/tool/core/console/ConsoleManager.java
parent71ca7c6cab863767ef30c8bd05b2bbfda8731cb5 (diff)
Initial commit
Bug-AGL: SPEC-4033 Signed-off-by: Kenji Hosokawa <khosokawa@jp.adit-jv.com>
Diffstat (limited to 'rba.tool.core/src/rba/tool/core/console/ConsoleManager.java')
-rw-r--r--rba.tool.core/src/rba/tool/core/console/ConsoleManager.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/rba.tool.core/src/rba/tool/core/console/ConsoleManager.java b/rba.tool.core/src/rba/tool/core/console/ConsoleManager.java
new file mode 100644
index 0000000..823d3dd
--- /dev/null
+++ b/rba.tool.core/src/rba/tool/core/console/ConsoleManager.java
@@ -0,0 +1,96 @@
+package rba.tool.core.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
+
+public class ConsoleManager implements IConsoleManager {
+
+ public static ConsoleManager INSTANCE = new ConsoleManager();
+
+ org.eclipse.ui.console.IConsoleManager consoleManager;
+
+ MessageConsole console;
+
+ MessageConsoleStream consoleStream;
+
+ MessageConsoleStream consoleWarnStream;
+
+ String title = "RBA Tool Console";
+
+ Map<String, List<IConsoleHook>> hook_notifierIdMap = new HashMap<String, List<IConsoleHook>>();
+
+ private ConsoleManager() {
+ consoleManager = ConsolePlugin.getDefault().getConsoleManager();
+ console = new MessageConsole(title, null);
+ consoleManager.addConsoles(new MessageConsole[] { console });
+
+ consoleStream = console.newMessageStream();
+
+ consoleWarnStream = console.newMessageStream();
+ consoleWarnStream.setColor(new Color(null, 255, 0, 0)); // red
+ consoleWarnStream.setFontStyle(SWT.BOLD);
+ }
+
+ public void clearConsole() {
+ console.clearConsole();
+ }
+
+ @Override
+ public void output(String message, String notifierId) {
+ preNotify(message, notifierId);
+ // original output message
+ consoleManager.showConsoleView(console);
+ consoleStream.println(message);
+ postNotify(message, notifierId);
+ }
+
+ @Override
+ public void warning(String message, String notifierId) {
+ preNotify(message, notifierId);
+ // original warning message
+ consoleManager.showConsoleView(console);
+ consoleWarnStream.println(message);
+ postNotify(message, notifierId);
+ }
+
+ @Override
+ public void addHook(IConsoleHook hook, String targetNotifierId) {
+ List<IConsoleHook> hookList = hook_notifierIdMap.get(targetNotifierId);
+ if (hookList == null) {
+ hookList = new ArrayList<IConsoleHook>();
+ hook_notifierIdMap.put(targetNotifierId, hookList);
+ }
+ hookList.add(hook);
+ }
+
+ @Override
+ public void removeHook(IConsoleHook hook, String targetNotifierId) {
+ List<IConsoleHook> hookList = hook_notifierIdMap.get(targetNotifierId);
+ if (hookList == null) {
+ return;
+ }
+ hookList.remove(hook);
+ }
+
+ public void preNotify(String message, String notifierId) {
+ List<IConsoleHook> hookList = hook_notifierIdMap.get(notifierId);
+ if (hookList != null && !hookList.isEmpty()) {
+ hookList.forEach(hook -> hook.preNotify(message, notifierId));
+ }
+ }
+
+ public void postNotify(String message, String notifierId) {
+ List<IConsoleHook> hookList = hook_notifierIdMap.get(notifierId);
+ if (hookList != null && !hookList.isEmpty()) {
+ hookList.forEach(hook -> hook.postNotify(message, notifierId));
+ }
+ }
+}