diff --git a/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java b/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java index c4ce5b1cb..c029a426d 100644 --- a/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java +++ b/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java @@ -10,7 +10,6 @@ *******************************************************************************/ package com.googlecode.goclipse.core; -import melnorme.lang.ide.core.LangCore; import melnorme.lang.ide.core.operations.ToolchainPreferences; import melnorme.lang.ide.core.utils.prefs.BooleanPreference; import melnorme.lang.ide.core.utils.prefs.IProjectPreference; @@ -18,10 +17,10 @@ public interface GoEnvironmentPrefs { - IProjectPreference GO_PATH = new OptionalStringPreference(LangCore.PLUGIN_ID, + IProjectPreference GO_PATH = new OptionalStringPreference( "com.googlecode.goclipse.gopath", ToolchainPreferences.USE_PROJECT_SETTINGS).getProjectPreference(); - IProjectPreference APPEND_PROJECT_LOC_TO_GOPATH = new BooleanPreference(LangCore.PLUGIN_ID, + IProjectPreference APPEND_PROJECT_LOC_TO_GOPATH = new BooleanPreference( "append_projloc_gopath", true, ToolchainPreferences.USE_PROJECT_SETTINGS).getProjectPreference(); } \ No newline at end of file diff --git a/plugin_ide.core/src/com/googlecode/goclipse/core/GoToolPreferences.java b/plugin_ide.core/src/com/googlecode/goclipse/core/GoToolPreferences.java index ac69d9714..57f67f78d 100644 --- a/plugin_ide.core/src/com/googlecode/goclipse/core/GoToolPreferences.java +++ b/plugin_ide.core/src/com/googlecode/goclipse/core/GoToolPreferences.java @@ -12,23 +12,64 @@ import java.nio.file.Path; -import melnorme.lang.ide.core.LangCore; +import melnorme.lang.ide.core.LangCore_Actual; import melnorme.lang.ide.core.utils.prefs.DerivedValuePreference; import melnorme.lang.ide.core.utils.prefs.OptionalStringPreference; import melnorme.lang.utils.validators.LocationOrSinglePathValidator; +import melnorme.lang.utils.validators.PathValidator; +import melnorme.utilbox.fields.validation.ValidationException; +import melnorme.utilbox.status.Severity; public interface GoToolPreferences { - DerivedValuePreference GO_GURU_Path = new DerivedValuePreference(LangCore.PLUGIN_ID, - "GoToolPreferences.GO_GURU_Path", "", null, - (new LocationOrSinglePathValidator("guru path:")).setFileOnly(true)); + public class GoToolValidator extends LocationOrSinglePathValidator { + public GoToolValidator(String fieldNamePrefix) { + // TODO: refactor to fieldName + super(fieldNamePrefix); + } + + @Override + protected String getFullMessage(String simpleMessage) { + return super.getFullMessage(simpleMessage); + } + + @Override + protected ValidationException createIsEmptyException() { + String baseMsg = fieldNamePrefix + " is not configured."; + String detailsMsg = + "The " + fieldNamePrefix + " setting needs to be configured in the " + + linkGoPreferences() + ".\n" + "See the " + linkUserGuide() + " for more information."; + return new ValidationException(Severity.WARNING, baseMsg, detailsMsg); + } + + protected String linkGoPreferences() { + return linkReference("Go preferences", "pref:" + LangCore_Actual.TOOLS_PREF_PAGE_ID); + } + + protected String linkUserGuide() { + return linkReference("UserGuide", LangCore_Actual.USER_GUIDE_LINK); + } + + public static String linkReference(String text, String target) { + return "" + text + ""; + } + } - DerivedValuePreference GODEF_Path = new DerivedValuePreference(LangCore.PLUGIN_ID, + PathValidator GURU_PATH_validator = new GoToolValidator("guru path"); + PathValidator GODEF_PATH_validator = new GoToolValidator("godef path"); + PathValidator GOFMT_PATH_validator = new GoToolValidator("gofmt path"); + + + DerivedValuePreference GO_GURU_Path = new DerivedValuePreference( + "GoToolPreferences.GO_GURU_Path", "", null, + GURU_PATH_validator); + + DerivedValuePreference GODEF_Path = new DerivedValuePreference( "GoToolPreferences.godef.Path", "", null, - (new LocationOrSinglePathValidator("godef path:")).setFileOnly(true)); + GODEF_PATH_validator); DerivedValuePreference GOFMT_Path = new DerivedValuePreference( - new OptionalStringPreference(LangCore.PLUGIN_ID, "GoToolPreferences.GOFMT_Path", null), - (new LocationOrSinglePathValidator("gofmt path:")).setFileOnly(true)); + new OptionalStringPreference("GoToolPreferences.GOFMT_Path", null), + GOFMT_PATH_validator); } \ No newline at end of file diff --git a/plugin_ide.core/src/melnorme/lang/ide/core/LangCore_Actual.java b/plugin_ide.core/src/melnorme/lang/ide/core/LangCore_Actual.java index 8346cf33e..166db1534 100644 --- a/plugin_ide.core/src/melnorme/lang/ide/core/LangCore_Actual.java +++ b/plugin_ide.core/src/melnorme/lang/ide/core/LangCore_Actual.java @@ -28,6 +28,15 @@ public class LangCore_Actual extends AbstractLangCore { public static final String VAR_NAME_SdkToolPath = "GO_TOOL_PATH"; public static final String VAR_NAME_SdkToolPath_DESCRIPTION = "The path of the Go tool"; + /* ----------------- ----------------- */ + + public static final String USER_GUIDE_LINK = + "https://github.com/GoClipse/goclipse/blob/latest/documentation/UserGuide.md#user-guide"; + public static final String TOOLS_PREF_PAGE_ID = + "com.googlecode.goclipse.ui.PreferencePages.GocodePreferencePage"; + + /* ----------------- ----------------- */ + public LangCore_Actual(ILogHandler logHandler) { super(logHandler); } diff --git a/plugin_ide.ui/src/com/googlecode/goclipse/ui/GoUIPlugin.java b/plugin_ide.ui/src/com/googlecode/goclipse/ui/GoUIPlugin.java index b2c0f6a24..2e739b97c 100644 --- a/plugin_ide.ui/src/com/googlecode/goclipse/ui/GoUIPlugin.java +++ b/plugin_ide.ui/src/com/googlecode/goclipse/ui/GoUIPlugin.java @@ -10,13 +10,24 @@ *******************************************************************************/ package com.googlecode.goclipse.ui; +import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail; +import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; + +import org.eclipse.jface.preference.IPreferenceNode; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.PreferencesUtil; import org.osgi.framework.BundleContext; import com.googlecode.goclipse.core.tools.GocodeServerManager; import com.googlecode.goclipse.ui.actions.StartGocodeServerOperation; import melnorme.lang.ide.core.LangCore; +import melnorme.lang.ide.core.LangCore_Actual; import melnorme.lang.ide.ui.LangUIPlugin; +import melnorme.lang.ide.ui.utils.WorkbenchUtils; import melnorme.lang.tooling.common.ops.IOperationMonitor; import melnorme.utilbox.concurrency.OperationCancellation; import melnorme.utilbox.core.CommonException; @@ -30,6 +41,24 @@ protected GoOperationsConsoleUIHandler createOperationsConsoleListener() { @Override protected void doInitializeAfterLoad(IOperationMonitor om) throws CommonException { + checkPrefPageIdIsValid(LangCore_Actual.TOOLS_PREF_PAGE_ID); + } + + protected void checkPrefPageIdIsValid(String prefId) { + Shell shell = WorkbenchUtils.getActiveWorkbenchShell(); + PreferenceDialog prefDialog = PreferencesUtil.createPreferenceDialogOn(shell, prefId, null, null); + assertNotNull(prefDialog); // Don't create, just eagerly check that it exits, that the ID is correct + ISelection selection = prefDialog.getTreeViewer().getSelection(); + if(selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + if(ss.getFirstElement() instanceof IPreferenceNode) { + IPreferenceNode prefNode = (IPreferenceNode) ss.getFirstElement(); + if(prefNode.getId().equals(prefId)) { + return; // Id exists + } + } + } + assertFail(); } public static GocodeServerManager prepareGocodeManager_inUI()