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

Commit

Permalink
Added more helpful error dialog for Go language tools empty prefs.
Browse files Browse the repository at this point in the history
Fixes #209
  • Loading branch information
bruno-medeiros committed Jul 6, 2016
1 parent 3292780 commit c793657
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
*******************************************************************************/
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;
import melnorme.lang.ide.core.utils.prefs.OptionalStringPreference;

public interface GoEnvironmentPrefs {

IProjectPreference<String> GO_PATH = new OptionalStringPreference(LangCore.PLUGIN_ID,
IProjectPreference<String> GO_PATH = new OptionalStringPreference(
"com.googlecode.goclipse.gopath", ToolchainPreferences.USE_PROJECT_SETTINGS).getProjectPreference();

IProjectPreference<Boolean> APPEND_PROJECT_LOC_TO_GOPATH = new BooleanPreference(LangCore.PLUGIN_ID,
IProjectPreference<Boolean> APPEND_PROJECT_LOC_TO_GOPATH = new BooleanPreference(
"append_projloc_gopath", true, ToolchainPreferences.USE_PROJECT_SETTINGS).getProjectPreference();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> GO_GURU_Path = new DerivedValuePreference<Path>(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 "<a href=\"" + target + "\">" + text + "</a>";
}
}

DerivedValuePreference<Path> GODEF_Path = new DerivedValuePreference<Path>(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<Path> GO_GURU_Path = new DerivedValuePreference<Path>(
"GoToolPreferences.GO_GURU_Path", "", null,
GURU_PATH_validator);

DerivedValuePreference<Path> GODEF_Path = new DerivedValuePreference<Path>(
"GoToolPreferences.godef.Path", "", null,
(new LocationOrSinglePathValidator("godef path:")).setFileOnly(true));
GODEF_PATH_validator);

DerivedValuePreference<Path> GOFMT_Path = new DerivedValuePreference<Path>(
new OptionalStringPreference(LangCore.PLUGIN_ID, "GoToolPreferences.GOFMT_Path", null),
(new LocationOrSinglePathValidator("gofmt path:")).setFileOnly(true));
new OptionalStringPreference("GoToolPreferences.GOFMT_Path", null),
GOFMT_PATH_validator);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
29 changes: 29 additions & 0 deletions plugin_ide.ui/src/com/googlecode/goclipse/ui/GoUIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit c793657

Please sign in to comment.