diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/EclipseUtils.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/EclipseUtils.java index 70ac95899..3a7f1d509 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/EclipseUtils.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/EclipseUtils.java @@ -32,9 +32,9 @@ import melnorme.lang.ide.core.EclipseCore; import melnorme.lang.ide.core.LangCore; -import melnorme.lang.tooling.common.ops.Operation; import melnorme.lang.tooling.common.ops.IOperationMonitor; import melnorme.lang.tooling.common.ops.IOperationMonitor.BasicOperationMonitor; +import melnorme.lang.tooling.common.ops.Operation; import melnorme.utilbox.concurrency.ICancelMonitor; import melnorme.utilbox.concurrency.OperationCancellation; import melnorme.utilbox.core.CommonException; @@ -112,7 +112,7 @@ public static void removeNature(IProject project, String natureID) throws CoreEx } public static T getAdapter(Object adaptable, Class adapterType) { - return (T) Platform.getAdapterManager().getAdapter(adaptable, adapterType); + return Platform.getAdapterManager().getAdapter(adaptable, adapterType); } /* ----------------- status ----------------- */ diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/BooleanPreference.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/BooleanPreference.java index 4e4d0b6da..c6446de9b 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/BooleanPreference.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/BooleanPreference.java @@ -21,6 +21,10 @@ public class BooleanPreference extends PreferenceHelper { public BooleanPreference(String key, boolean defaultValue) { super(key, defaultValue); } + public BooleanPreference(String key, boolean defaultValue, IProjectPreference useProjectSettings) { + super(key, defaultValue, useProjectSettings); + } + public BooleanPreference(String pluginId, String key, boolean defaultValue) { super(pluginId, key, defaultValue); } diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/DerivedValuePreference.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/DerivedValuePreference.java index e0e52e452..cfc0325d8 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/DerivedValuePreference.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/DerivedValuePreference.java @@ -24,10 +24,10 @@ public class DerivedValuePreference { protected final StringPreference preference; protected final Validator validator; - public DerivedValuePreference(String pluginId, String key, String defaultValue, + public DerivedValuePreference(String key, String defaultValue, IProjectPreference useProjectPref /* can be null*/, Validator validator) { - this(new StringPreference(pluginId, key, defaultValue, useProjectPref), validator); + this(new StringPreference(key, defaultValue, useProjectPref), validator); } public DerivedValuePreference(StringPreference preference, Validator validator) { diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/OptionalStringPreference.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/OptionalStringPreference.java index 19d7f537e..f5d333cfa 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/OptionalStringPreference.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/OptionalStringPreference.java @@ -17,9 +17,8 @@ */ public class OptionalStringPreference extends StringPreference { - public OptionalStringPreference(String pluginId, String key, - IProjectPreference useProjectSettings) { - super(pluginId, key, null, useProjectSettings); + public OptionalStringPreference(String key, IProjectPreference useProjectSettings) { + super(key, null, useProjectSettings); } @Override diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/PreferenceHelper.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/PreferenceHelper.java index f68033208..f60d1fd81 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/PreferenceHelper.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/PreferenceHelper.java @@ -62,11 +62,14 @@ public PreferenceHelper(String pluginId, String key, T defaultValue) { this(pluginId, key, defaultValue, true, null); } - public PreferenceHelper(String pluginId, String key, T defaultValue, - IProjectPreference useProjectPref) { + public PreferenceHelper(String pluginId, String key, T defaultValue, IProjectPreference useProjectPref) { this(pluginId, key, defaultValue, true, useProjectPref); } + public PreferenceHelper(String key, T defaultValue, IProjectPreference useProjectPref) { + this(LangCore.PLUGIN_ID, key, defaultValue, true, useProjectPref); + } + public PreferenceHelper(String pluginId, String key, T defaultValue, boolean ensureUniqueKey, IProjectPreference useProjectPreference) { this.key = assertNotNull(PreferencesOverride.getKeyIdentifer(key, this)); diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/StringPreference.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/StringPreference.java index cb1c3cf29..c89a7bde6 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/StringPreference.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/utils/prefs/StringPreference.java @@ -18,6 +18,9 @@ public class StringPreference extends PreferenceHelper { public StringPreference(String key, String defaultValue) { super(key, defaultValue); } + public StringPreference(String key, String defaultValue, IProjectPreference useProjectPref) { + super(key, defaultValue, useProjectPref); + } public StringPreference(String pluginId, String key, String defaultValue) { super(pluginId, key, defaultValue); } diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/dialogs/LangProjectWizardFirstPage.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/dialogs/LangProjectWizardFirstPage.java index bc3defe27..f785f7966 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/dialogs/LangProjectWizardFirstPage.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/dialogs/LangProjectWizardFirstPage.java @@ -20,7 +20,6 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -29,7 +28,6 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.dialogs.PreferencesUtil; import melnorme.lang.ide.core.LangCore; import melnorme.lang.ide.core.LangCore_Actual; @@ -37,6 +35,7 @@ import melnorme.lang.ide.core.utils.ProjectValidator; import melnorme.lang.ide.core.utils.ResourceUtils; import melnorme.lang.ide.ui.LangUIPlugin_Actual; +import melnorme.lang.ide.ui.utils.WorkbenchUtils; import melnorme.util.swt.SWTFactory; import melnorme.util.swt.SWTFactoryUtil; import melnorme.util.swt.SWTUtil; @@ -310,13 +309,8 @@ public void widgetSelected(SelectionEvent e) { } protected void openPreferencePage() { - PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(getShell(), - LangUIPlugin_Actual.ROOT_PREF_PAGE_ID, null, null); - - if (pref != null) { - pref.open(); - updateWidgetFromInput(); - } + WorkbenchUtils.openPreferencePage(getShell(), LangUIPlugin_Actual.ROOT_PREF_PAGE_ID); + updateWidgetFromInput(); } @Override diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog.java index daa0ffcbb..5e4c4af1a 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog.java @@ -19,7 +19,6 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import melnorme.util.swt.SWTFactory; @@ -56,7 +55,7 @@ protected void configureShell(Shell newShell) { @Override protected Image getImage() { - return Display.getCurrent().getSystemImage(SWTUtil.getSystemImageCode(statusLevel)); + return SWTUtil.getSWTImageForStatusLevel(statusLevel); } @Override diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog2.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog2.java new file mode 100644 index 000000000..24e90ee73 --- /dev/null +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog2.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2016 Bruno Medeiros and other Contributors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bruno Medeiros - initial API and implementation + *******************************************************************************/ +package melnorme.lang.ide.ui.utils; + + +import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +import melnorme.util.swt.SWTFactoryUtil; +import melnorme.util.swt.SWTUtil; +import melnorme.util.swt.components.AbstractWidget; +import melnorme.utilbox.status.StatusException; + +public class StatusMessageDialog2 extends Dialog { + + protected final String title; + + protected final IconAndMessageWidget iconAndMessageWidget; + + public StatusMessageDialog2(Shell shell, String title, StatusException statusMessage) { + super(shell); + assertNotNull(statusMessage); + this.title = title; + this.iconAndMessageWidget = createIconAndMessageWidget(); + this.iconAndMessageWidget.setStatusMessage(statusMessage); + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(title); + } + + @Override + protected Control createContents(Composite parent) { + return super.createContents(parent); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite topControl = (Composite) super.createDialogArea(parent); + GridLayout gridLayout = (GridLayout) topControl.getLayout(); + gridLayout.numColumns = 2; + iconAndMessageWidget.createComponentInlined(topControl); + iconAndMessageWidget.messageControlLayoutData().widthHint = + convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); + + return topControl; + } + + protected IconAndMessageWidget createIconAndMessageWidget() { + return new IconAndMessageWidget(); + } + + public static class IconAndMessageWidget extends AbstractWidget { + + protected StatusException statusMessage; + + protected Label imageControl; + protected Label messageControl; + + public IconAndMessageWidget() { + } + + @Override + public int getPreferredLayoutColumns() { + return 2; + } + + public void setStatusMessage(StatusException statusMessage) { + this.statusMessage = assertNotNull(statusMessage); + } + + @Override + protected void createContents(Composite topControl) { + imageControl = createImageControl(topControl); + createMessageControl(topControl); + } + + protected Label createImageControl(Composite topControl) { + return SWTFactoryUtil.createIconLabel(topControl, getImage(), + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING).create() + ); + } + + protected Image getImage() { + return SWTUtil.getImageForSeverity(statusMessage.getSeverity()); + } + + protected void createMessageControl(Composite topControl) { + String message = statusMessage.getMultiLineRender(); + messageControl = SWTFactoryUtil.createLabel(topControl, SWT.WRAP, message, gdGrabAll()); + } + + public GridData messageControlLayoutData() { + assertNotNull(messageControl); + return (GridData) messageControl.getLayoutData(); + } + + @Override + protected void updateWidgetFromInput() { + // immutable widget + } + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + } + +} \ No newline at end of file diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialogExt.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialogExt.java new file mode 100644 index 000000000..966c040fb --- /dev/null +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialogExt.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2016 Bruno Medeiros and other Contributors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bruno Medeiros - initial API and implementation + *******************************************************************************/ +package melnorme.lang.ide.ui.utils; + + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.program.Program; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Shell; + +import melnorme.util.swt.SWTFactoryUtil; +import melnorme.utilbox.fields.validation.IDetailsMessage; +import melnorme.utilbox.misc.StringUtil; +import melnorme.utilbox.status.StatusException; + +public class StatusMessageDialogExt extends StatusMessageDialog2 { + + public StatusMessageDialogExt(Shell shell, String title, StatusException statusMessage) { + super(shell, title, statusMessage); + } + + @Override + protected IconAndMessageWidget createIconAndMessageWidget() { + return new IconAndMessageWidgetExt(); + } + + /** + * Extension to {@link IconAndMessageWidget}, allows displaying additional info from {@link IDetailsMessage} + * in a control with links in texts. + */ + public static class IconAndMessageWidgetExt extends IconAndMessageWidget { + + protected Link helpControl; + + @Override + protected void createMessageControl(Composite topControl) { + super.createMessageControl(topControl); + + if(statusMessage instanceof IDetailsMessage) { + IDetailsMessage detailsMessage = (IDetailsMessage) statusMessage; + createDetailsMessage(topControl, detailsMessage); + } + } + + protected void createDetailsMessage(Composite topControl, IDetailsMessage detailsMessage) { + String additionalMessage = "\n" + detailsMessage.getDetailsMessage(); + + helpControl = SWTFactoryUtil.createLink(topControl, SWT.WRAP, additionalMessage, + gdfFillDefaults().grab(true, true).span(2, 1).create() + ); + + helpControl.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String uri = e.text; + if(uri.startsWith("http")) { + Program.launch(uri); + } else if(uri.startsWith("pref:")) { + String prefId = StringUtil.removeStart("pref:", uri); + WorkbenchUtils.openPreferencePage(helpControl.getShell(), prefId); + } else { + UIOperationsStatusHandler.handleInternalError("Unknown link URI:\n" + uri, null); + } + } + }); + } + + public Link getHelpControl() { + return helpControl; + } + } + +} \ No newline at end of file diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationErrorHandlerImpl.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationErrorHandlerImpl.java index 00ca40838..924d13731 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationErrorHandlerImpl.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationErrorHandlerImpl.java @@ -13,16 +13,9 @@ import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; -import melnorme.lang.ide.core.EclipseCore; import melnorme.lang.ide.core.LangCore; -import melnorme.lang.ide.core.utils.EclipseUtils; import melnorme.utilbox.status.Severity; import melnorme.utilbox.status.StatusException; @@ -51,21 +44,11 @@ public void handleStatus(boolean logError, Shell shell, String title, StatusExce } assertNotNull(shell); - if(status.getCause() == null) { - // No point in using ErrorDialog, use simpler dialog - openMessageDialog(MessageDialog.ERROR, shell, title, status.getMessage()); - return; - } - - openErrorDialog(shell, title, status); - } - - protected void openMessageDialog(int kind, Shell shell, String title, String message) { - MessageDialog.open(kind, shell, title, message, SWT.SHEET); + openMessageDialog(shell, title, status); } - protected void openErrorDialog(Shell shell, String title, StatusException status) { - new ErrorDialogExt(shell, title, status).open(); + protected void openMessageDialog(Shell shell, String title, StatusException status) { + new StatusMessageDialogExt(shell, title, status).open(); } /* ----------------- ----------------- */ @@ -82,25 +65,6 @@ public void displayStatusMessage(String title, Severity severity, String message /* ----------------- ----------------- */ - public static class ErrorDialogExt extends ErrorDialog { - - public ErrorDialogExt(Shell parentShell, String dialogTitle, StatusException se) { - super(parentShell, dialogTitle, "XXX", createDialogStatus(se), - IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR); - - this.message = se.getMessage(); - } - - protected static Status createDialogStatus(StatusException se) { - return EclipseCore.createStatus( - EclipseUtils.toEclipseSeverity(se), - null, - new Exception(getExceptionText(se.getCause())) - ); - } - - } - protected static String getExceptionText(Throwable exception) { if(exception == null) return null; diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationsStatusHandler.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationsStatusHandler.java index ac6310c7e..ceaa791d7 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationsStatusHandler.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/UIOperationsStatusHandler.java @@ -94,13 +94,8 @@ public static void handleOperationStatus(String opName, CommonException ce) { public static class Null_UIOperationErrorHandlerImpl extends UIOperationErrorHandlerImpl { @Override - protected void openMessageDialog(int kind, Shell shell, String title, String message) { - //super.openMessageDialog(kind, shell, title, message); - } - - @Override - protected void openErrorDialog(Shell shell, String title, StatusException status) { - //super.openErrorDialog(shell, title, status); + protected void openMessageDialog(Shell shell, String title, StatusException status) { + // Do nothing } } diff --git a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/WorkbenchUtils.java b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/WorkbenchUtils.java index d956dbd25..d227db799 100644 --- a/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/WorkbenchUtils.java +++ b/plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/WorkbenchUtils.java @@ -11,6 +11,7 @@ package melnorme.lang.ide.ui.utils; import org.eclipse.core.resources.IResource; +import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; @@ -23,6 +24,7 @@ import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.ide.ResourceUtil; public class WorkbenchUtils { @@ -99,4 +101,17 @@ public static IWorkbenchPart getActivePart(IWorkbenchPartSite site) { return service.getActivePart(); } + /* ----------------- ----------------- */ + + public static void openPreferencePage(Shell shell, String prefPageId) { + PreferenceDialog prefDialog = PreferencesUtil.createPreferenceDialogOn(shell, prefPageId, null, null); + + if(prefDialog != null) { + prefDialog.open(); + } else { + String message = "Preference page not found: `" + prefPageId + "`."; + UIOperationsStatusHandler.handleInternalError(shell, message, null); + } + } + } \ No newline at end of file diff --git a/plugin_ide.ui/src-lang/melnorme/util/swt/SWTUtil.java b/plugin_ide.ui/src-lang/melnorme/util/swt/SWTUtil.java index 1d081991b..6ba506c13 100644 --- a/plugin_ide.ui/src-lang/melnorme/util/swt/SWTUtil.java +++ b/plugin_ide.ui/src-lang/melnorme/util/swt/SWTUtil.java @@ -14,6 +14,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Resource; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -22,6 +23,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import melnorme.utilbox.status.Severity; import melnorme.utilbox.status.StatusLevel; /** @@ -127,6 +129,10 @@ public static int statusLevelToMessageDialogKing(StatusLevel statusLevel) { throw assertFail(); } + public static Image getSWTImageForStatusLevel(StatusLevel statusLevel2) { + return getSystemImage(getSystemImageCode(statusLevel2)); + } + public static int getSystemImageCode(StatusLevel statusLevel) { switch (statusLevel) { case ERROR: return SWT.ICON_ERROR; @@ -137,4 +143,17 @@ public static int getSystemImageCode(StatusLevel statusLevel) { throw assertFail(); } + public static Image getImageForSeverity(Severity severity) { + switch (severity) { + case ERROR: return getSystemImage(SWT.ICON_ERROR); + case WARNING: return getSystemImage(SWT.ICON_WARNING); + case INFO: return getSystemImage(SWT.ICON_INFORMATION); + } + throw assertFail(); + } + + public static Image getSystemImage(final int imageID) { + return Display.getCurrent().getSystemImage(imageID); + } + } \ No newline at end of file diff --git a/plugin_tooling/src-lang/melnorme/lang/utils/validators/AbstractValidatorExt.java b/plugin_tooling/src-lang/melnorme/lang/utils/validators/AbstractValidatorExt.java index a54de8b8b..b533c3898 100644 --- a/plugin_tooling/src-lang/melnorme/lang/utils/validators/AbstractValidatorExt.java +++ b/plugin_tooling/src-lang/melnorme/lang/utils/validators/AbstractValidatorExt.java @@ -22,7 +22,7 @@ public AbstractValidatorExt() { protected ValidationException createException(Severity severity, String message) { assertNotNull(severity); - return new ValidationException(severity, getFullMessage(message), message, null); + return new ValidationException(severity, getFullMessage(message)); } protected String getFullMessage(String simpleMessage) { diff --git a/plugin_tooling/src-lang/melnorme/lang/utils/validators/PathValidator.java b/plugin_tooling/src-lang/melnorme/lang/utils/validators/PathValidator.java index 221c8c114..7fed22331 100644 --- a/plugin_tooling/src-lang/melnorme/lang/utils/validators/PathValidator.java +++ b/plugin_tooling/src-lang/melnorme/lang/utils/validators/PathValidator.java @@ -80,7 +80,7 @@ protected Path createPath(String pathString) throws ValidationException { if(canBeEmpty) { return null; } - throw createException(Severity.WARNING, ValidationMessages.Path_EmptyPath()); + throw createIsEmptyException(); } Path path = PathUtil.createPathOrNull(pathString); @@ -90,6 +90,10 @@ protected Path createPath(String pathString) throws ValidationException { return path; } + protected ValidationException createIsEmptyException() { + return createException(Severity.WARNING, ValidationMessages.Path_EmptyPath()); + } + protected Path validatePath(Path path) throws ValidationException { if(path.isAbsolute()) { return PathUtil.toPath(getValidatedLocation(path)); diff --git a/plugin_tooling/src-util/melnorme/utilbox/fields/validation/IDetailsMessage.java b/plugin_tooling/src-util/melnorme/utilbox/fields/validation/IDetailsMessage.java new file mode 100644 index 000000000..39b72b865 --- /dev/null +++ b/plugin_tooling/src-util/melnorme/utilbox/fields/validation/IDetailsMessage.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2016 Bruno Medeiros and other Contributors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bruno Medeiros - initial API and implementation + *******************************************************************************/ +package melnorme.utilbox.fields.validation; + + +public interface IDetailsMessage { + + String getDetailsMessage(); + +} \ No newline at end of file diff --git a/plugin_tooling/src-util/melnorme/utilbox/fields/validation/ValidationException.java b/plugin_tooling/src-util/melnorme/utilbox/fields/validation/ValidationException.java index fc7376b42..ddc23e7e5 100644 --- a/plugin_tooling/src-util/melnorme/utilbox/fields/validation/ValidationException.java +++ b/plugin_tooling/src-util/melnorme/utilbox/fields/validation/ValidationException.java @@ -10,8 +10,6 @@ *******************************************************************************/ package melnorme.utilbox.fields.validation; -import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; - import melnorme.utilbox.status.Severity; import melnorme.utilbox.status.StatusException; @@ -20,21 +18,22 @@ * as well as contain the simple message (a message strictly about what is went wrong in the validation). */ @SuppressWarnings("serial") -public class ValidationException extends StatusException { +public class ValidationException extends StatusException implements IDetailsMessage { - protected final String simpleMessage; + protected final String detailsMessage; - public ValidationException(Severity severity, String message, String simpleMessage, Throwable cause) { - super(severity, message, cause); - this.simpleMessage = assertNotNull(simpleMessage); + public ValidationException(Severity severity, String message) { + this(severity, message, null); } - public String getSimpleMessage() { - return simpleMessage; + public ValidationException(Severity severity, String message, String detailsMessage) { + super(severity, message, null); + this.detailsMessage = detailsMessage; } - public String getContextualizedMessage() { - return getMessage(); + @Override + public String getDetailsMessage() { + return detailsMessage; } } \ No newline at end of file diff --git a/plugin_tooling/src-util/melnorme/utilbox/misc/StringUtil.java b/plugin_tooling/src-util/melnorme/utilbox/misc/StringUtil.java index 2c4513367..3abf3e9f0 100644 --- a/plugin_tooling/src-util/melnorme/utilbox/misc/StringUtil.java +++ b/plugin_tooling/src-util/melnorme/utilbox/misc/StringUtil.java @@ -269,9 +269,13 @@ public static String substringFromMatch(String match, String string) { return indexOf == -1 ? "" : string.substring(indexOf); } - /** If given string starts with given startMatch, trim that from string. - * @return the result. */ public static String trimStart(String string, String startMatch) { + return removeStart(startMatch, string); + } + + /** If given string starts with given startMatch, remove that from string. + * @return the result. */ + public static String removeStart(String startMatch, String string) { if(string.startsWith(startMatch)) { return string.substring(startMatch.length()); }