From be4f78978faba3d3ceb88df02a7f93a2e09ff1e0 Mon Sep 17 00:00:00 2001 From: Kenji Hosokawa Date: Tue, 3 Aug 2021 18:42:39 +0900 Subject: Initial commit Bug-AGL: SPEC-4033 Signed-off-by: Kenji Hosokawa --- .../src/rba/tool/core/console/ConsoleManager.java | 96 ++++++++++++++++++++++ .../src/rba/tool/core/console/IConsoleHook.java | 8 ++ .../src/rba/tool/core/console/IConsoleManager.java | 14 ++++ 3 files changed, 118 insertions(+) create mode 100644 rba.tool.core/src/rba/tool/core/console/ConsoleManager.java create mode 100644 rba.tool.core/src/rba/tool/core/console/IConsoleHook.java create mode 100644 rba.tool.core/src/rba/tool/core/console/IConsoleManager.java (limited to 'rba.tool.core/src/rba/tool/core/console') 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> hook_notifierIdMap = new HashMap>(); + + 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 hookList = hook_notifierIdMap.get(targetNotifierId); + if (hookList == null) { + hookList = new ArrayList(); + hook_notifierIdMap.put(targetNotifierId, hookList); + } + hookList.add(hook); + } + + @Override + public void removeHook(IConsoleHook hook, String targetNotifierId) { + List hookList = hook_notifierIdMap.get(targetNotifierId); + if (hookList == null) { + return; + } + hookList.remove(hook); + } + + public void preNotify(String message, String notifierId) { + List 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 hookList = hook_notifierIdMap.get(notifierId); + if (hookList != null && !hookList.isEmpty()) { + hookList.forEach(hook -> hook.postNotify(message, notifierId)); + } + } +} diff --git a/rba.tool.core/src/rba/tool/core/console/IConsoleHook.java b/rba.tool.core/src/rba/tool/core/console/IConsoleHook.java new file mode 100644 index 0000000..8fbbd12 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/console/IConsoleHook.java @@ -0,0 +1,8 @@ +package rba.tool.core.console; + +public interface IConsoleHook { + + void preNotify(String message, String notifierId); + + void postNotify(String message, String notifierId); +} diff --git a/rba.tool.core/src/rba/tool/core/console/IConsoleManager.java b/rba.tool.core/src/rba/tool/core/console/IConsoleManager.java new file mode 100644 index 0000000..821e6f9 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/console/IConsoleManager.java @@ -0,0 +1,14 @@ +package rba.tool.core.console; + +public interface IConsoleManager { + + void output(String message, String notifierId); + + void clearConsole(); + + void warning(String message, String notifierId); + + void addHook(IConsoleHook hook, String targetNotifierId); + + void removeHook(IConsoleHook hook, String targetNotifierId); +} -- cgit 1.2.3-korg