Skip to content

Commit

Permalink
Auto-detect Dart SDK in preference page does not work for existing
Browse files Browse the repository at this point in the history
workspace eclipse#83

Signed-off-by: Lakshminarayana Nekkanti <[email protected]>
  • Loading branch information
lak-proddev committed Jul 9, 2019
1 parent 9cb40fd commit 00a495e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.dartboard.Constants;
import org.eclipse.dartboard.Messages;
import org.eclipse.dartboard.util.StringUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
Expand Down Expand Up @@ -104,6 +105,9 @@ public boolean performOk() {
* @return
*/
private Path getPath(String location) {
if (StringUtil.isNullOrEmpty(location)) {
return null;
}
Path path = Paths.get(location);
if (Files.exists(path)) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.eclipse.dartboard.preference;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.eclipse.dartboard.Messages;
import org.eclipse.dartboard.util.StringUtil;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Composite;
Expand All @@ -18,15 +18,16 @@ public DartSDKLocationFieldEditor(String preferencesKey, String label, Composite

@Override
protected boolean doCheckState() {
boolean isValid = true;
String location = getTextControl().getText();
Path path = Paths.get(location);
if (Files.exists(path)) {
return true;
} else {
if (StringUtil.isNullOrEmpty(location) || !Files.exists(Paths.get(location))) {
isValid = false;
}
if (!isValid) {
setErrorMessage(Messages.Preference_SDKNotFound_Message);
showErrorMessage();
return false;
}
return isValid;
}

protected void addModifyListener(ModifyListener listener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2019 vogella GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Lakshminarayana Nekkanti
*******************************************************************************/
package org.eclipse.dartboard.util;

public class StringUtil {

public static boolean isNullOrEmpty(String string) {
return string == null || string.isEmpty();
}
}

0 comments on commit 00a495e

Please sign in to comment.