Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
LANG: Refactoring to support builder notifyMessage.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Mar 26, 2015
1 parent 34f9177 commit cef3c86
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plugin_ide.core/src-lang/melnorme/lang/ide/core/LangCore.java
Expand Up @@ -101,8 +101,8 @@ public static StatusExt createErrorStatus(String message, Throwable throwable) {
} }


/** Creates a Status with given status code and message. */ /** Creates a Status with given status code and message. */
public static StatusExt createStatus(int statusCode, String message, Throwable throwable) { public static StatusExt createStatus(int severity, String message, Throwable throwable) {
return new StatusExt(statusCode, LangCore.getInstance(), message, throwable); return new StatusExt(severity, LangCore.getInstance(), message, throwable);
} }


public static final class StatusExt extends Status { public static final class StatusExt extends Status {
Expand Down
Expand Up @@ -15,6 +15,7 @@
import melnorme.lang.ide.core.utils.ResourceUtils; import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask; import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask;
import melnorme.lang.ide.core.utils.process.RunExternalProcessTask; import melnorme.lang.ide.core.utils.process.RunExternalProcessTask;
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.utilbox.concurrency.OperationCancellation; import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException; import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.ListenerListHelper; import melnorme.utilbox.misc.ListenerListHelper;
Expand All @@ -31,6 +32,11 @@
*/ */
public abstract class AbstractToolsManager extends ListenerListHelper<ILangOperationsListener_Actual> { public abstract class AbstractToolsManager extends ListenerListHelper<ILangOperationsListener_Actual> {


public void notifyMessage(StatusLevel statusLevel, String title, String message) {
for (ILangOperationsListener listener : getListeners()) {
listener.notifyMessage(statusLevel, title, message);
}
}


public void notifyBuildStarting(IProject project, boolean clearConsole) { public void notifyBuildStarting(IProject project, boolean clearConsole) {
for (ILangOperationsListener listener : getListeners()) { for (ILangOperationsListener listener : getListeners()) {
Expand Down
Expand Up @@ -13,11 +13,15 @@
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;


import melnorme.lang.ide.core.utils.process.IStartProcessListener; import melnorme.lang.ide.core.utils.process.IStartProcessListener;
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.utilbox.core.CommonException; import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.process.ExternalProcessNotifyingHelper; import melnorme.utilbox.process.ExternalProcessNotifyingHelper;


public interface ILangOperationsListener extends IStartProcessListener { public interface ILangOperationsListener extends IStartProcessListener {


/** Report a message to the user. */
void notifyMessage(StatusLevel statusLevel, String title, String message);

void handleBuildStarted(IProject project, boolean clearConsole); void handleBuildStarted(IProject project, boolean clearConsole);
void handleBuildTerminated(IProject project); void handleBuildTerminated(IProject project);


Expand Down
Expand Up @@ -21,6 +21,9 @@
import melnorme.lang.ide.ui.LangImages; import melnorme.lang.ide.ui.LangImages;
import melnorme.lang.ide.ui.LangUIPlugin_Actual; import melnorme.lang.ide.ui.LangUIPlugin_Actual;
import melnorme.lang.ide.ui.utils.ConsoleUtils; import melnorme.lang.ide.ui.utils.ConsoleUtils;
import melnorme.lang.ide.ui.utils.UIOperationExceptionHandler;
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.util.swt.SWTUtil;
import melnorme.utilbox.core.CommonException; import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.StringUtil; import melnorme.utilbox.misc.StringUtil;
import melnorme.utilbox.process.ExternalProcessNotifyingHelper; import melnorme.utilbox.process.ExternalProcessNotifyingHelper;
Expand All @@ -40,6 +43,19 @@ public AbstractToolsConsoleHandler() {
super(); super();
} }


@Override
public void notifyMessage(final StatusLevel statusLevel, final String title, final String message) {
SWTUtil.runInSWTThread(new Runnable() {
@Override
public void run() {
UIOperationExceptionHandler.handleStatusMessage(statusLevel, title, message);
}
});
}


/* ----------------- ----------------- */

public ToolsConsole getOrRecreateMessageConsole(String name, boolean recreateConsole) { public ToolsConsole getOrRecreateMessageConsole(String name, boolean recreateConsole) {
ToolsConsole console = ConsoleUtils.findConsole(name, ToolsConsole.class); ToolsConsole console = ConsoleUtils.findConsole(name, ToolsConsole.class);
if(console != null) { if(console != null) {
Expand Down
Expand Up @@ -13,6 +13,8 @@


import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import melnorme.lang.ide.core.LangCore; import melnorme.lang.ide.core.LangCore;
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.util.swt.SWTUtil;
import melnorme.utilbox.core.CommonException; import melnorme.utilbox.core.CommonException;


import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
Expand All @@ -28,6 +30,19 @@
*/ */
public class UIOperationExceptionHandler { public class UIOperationExceptionHandler {


public static void handleStatusMessage(StatusLevel statusLevel, String title, String message) {
Shell shell = WorkbenchUtils.getActiveWorkbenchShell();
if(shell == null) {
LangCore.logError("Shell not available.");
return;
}

int kind = SWTUtil.statusLevelToMessageDialogKing(statusLevel);
MessageDialog.open(kind, shell, title, message, SWT.SHEET);
}

/* ----------------- ----------------- */

public static void handleError(String message, Throwable exception) { public static void handleError(String message, Throwable exception) {
handleError(true, message, exception); handleError(true, message, exception);
} }
Expand All @@ -42,10 +57,10 @@ public static void handleError(boolean logError, String message, Throwable excep
Shell shell = WorkbenchUtils.getActiveWorkbenchShell(); Shell shell = WorkbenchUtils.getActiveWorkbenchShell();


if(exception == null) { if(exception == null) {
MessageDialog.open(SWT.ERROR, shell, "Error: ", message, SWT.SHEET); MessageDialog.open(MessageDialog.ERROR, shell, "Error: ", message, SWT.SHEET);
} else { } else {
String exceptionText = getExceptionText(exception); String exceptionText = getExceptionText(exception);
MessageDialog.open(SWT.ERROR, shell, "Error: " + message, exceptionText, SWT.SHEET); MessageDialog.open(MessageDialog.ERROR, shell, "Error: " + message, exceptionText, SWT.SHEET);
} }
} }


Expand Down Expand Up @@ -73,7 +88,7 @@ public static void handleWithErrorDialog(boolean logError, String title, String


if(exception == null) { if(exception == null) {
// No point in using ErrorDialog, use simpler dialog // No point in using ErrorDialog, use simpler dialog
MessageDialog.open(SWT.ERROR, shell, title, message, SWT.SHEET); MessageDialog.open(MessageDialog.ERROR, shell, title, message, SWT.SHEET);
return; return;
} }


Expand Down
14 changes: 14 additions & 0 deletions plugin_ide.ui/src-lang/melnorme/util/swt/SWTUtil.java
Expand Up @@ -10,6 +10,10 @@
*******************************************************************************/ *******************************************************************************/
package melnorme.util.swt; package melnorme.util.swt;


import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail;
import melnorme.lang.tooling.data.StatusLevel;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
Expand Down Expand Up @@ -94,4 +98,14 @@ public void run() {
} }
} }


public static int statusLevelToMessageDialogKing(StatusLevel statusLevel) {
switch (statusLevel) {
case ERROR: return MessageDialog.ERROR;
case INFO: return MessageDialog.INFORMATION;
case OK: return MessageDialog.OK;
case WARNING: return MessageDialog.WARNING;
}
throw assertFail();
}

} }

0 comments on commit cef3c86

Please sign in to comment.