summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Aubry2012-07-27 09:43:20 (EDT)
committer Kevin KIN-FOO2012-08-07 05:17:29 (EDT)
commitd5672ec66b2434782ba9ba2ec52bf117c7df5ca5 (patch)
treee5557af73dc90eea22ac4cc906d7f82fee9761a3
parentfe3a2a7dad6281a08e7ecf3f9b3cb9ac6357b4af (diff)
downloadorg.eclipse.koneki.ldt-d5672ec66b2434782ba9ba2ec52bf117c7df5ca5.zip
org.eclipse.koneki.ldt-d5672ec66b2434782ba9ba2ec52bf117c7df5ca5.tar.gz
org.eclipse.koneki.ldt-d5672ec66b2434782ba9ba2ec52bf117c7df5ca5.tar.bz2
Bug 386107 - Custom DLTK UI interpreter preference page
-rw-r--r--plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/AddLuaInterpreterDialog.java70
-rw-r--r--plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterEnvironmentVariablesBlock.java22
-rw-r--r--plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterPreferencePage.java138
-rw-r--r--plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpretersBlock.java19
4 files changed, 245 insertions, 4 deletions
diff --git a/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/AddLuaInterpreterDialog.java b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/AddLuaInterpreterDialog.java
index e614d70..5d2d93d 100644
--- a/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/AddLuaInterpreterDialog.java
+++ b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/AddLuaInterpreterDialog.java
@@ -11,12 +11,17 @@
package org.eclipse.koneki.ldt.debug.ui.internal.interpreters;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterEnvironmentVariablesBlock;
import org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterLibraryBlock;
import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog;
import org.eclipse.dltk.internal.debug.ui.interpreters.IAddInterpreterDialogRequestor;
+import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersMessages;
import org.eclipse.dltk.launching.IInterpreterInstall;
import org.eclipse.dltk.launching.IInterpreterInstallType;
import org.eclipse.dltk.ui.dialogs.StatusInfo;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
public class AddLuaInterpreterDialog extends AddScriptInterpreterDialog {
@@ -32,8 +37,69 @@ public class AddLuaInterpreterDialog extends AddScriptInterpreterDialog {
}
@Override
+ protected AbstractInterpreterEnvironmentVariablesBlock createEnvironmentVariablesBlock() {
+ return new LuaInterpreterEnvironmentVariablesBlock(this);
+ }
+
+ @Override
+ protected Composite createEnvironmentVariablesBlockParent(Composite parent, int numColumns) {
+ return super.createEnvironmentVariablesBlockParent(parent, numColumns);
+ }
+
+ @Override
protected IStatus validateInterpreterLocation() {
- // TODO reactivate validation
- return new StatusInfo();
+ // just validate the field is not empty
+ final IStatus s;
+ final Path location = new Path(getInterpreterPath());
+ if (location.isEmpty()) {
+ s = new StatusInfo(IStatus.INFO, InterpretersMessages.addInterpreterDialog_enterLocation);
+ } else {
+ s = new StatusInfo();
+ }
+ return s;
+ }
+
+ protected void createDialogBlocks(Composite parent, int numColumns) {
+ // removing library block by stubing it
+ fLibraryBlock = new LibraryBlockStub();
+
+ // create environment variable block instead
+ fEnvironmentVariablesBlock = createEnvironmentVariablesBlock();
+ if (fEnvironmentVariablesBlock != null) {
+ Composite envParent = createEnvironmentVariablesBlockParent(parent, numColumns);
+
+ fEnvironmentVariablesBlock.createControlsIn(envParent);
+ }
+
+ }
+
+ /**
+ * Stub to avoid library block
+ */
+ private class LibraryBlockStub extends AbstractInterpreterLibraryBlock {
+
+ protected LibraryBlockStub() {
+ super(null);
+ }
+
+ @Override
+ protected IBaseLabelProvider getLabelProvider() {
+ return null;
+ }
+
+ @Override
+ public void initializeFrom(IInterpreterInstall interpreter, IInterpreterInstallType type) {
+ }
+
+ @Override
+ public void restoreDefaultLibraries() {
+ }
+
+ @Override
+ protected boolean isDefaultLocations() {
+ return true;
+ }
+
}
+
}
diff --git a/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterEnvironmentVariablesBlock.java b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterEnvironmentVariablesBlock.java
new file mode 100644
index 0000000..4f0a598
--- /dev/null
+++ b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterEnvironmentVariablesBlock.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Sierra Wireless and others.
+ * 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:
+ * Sierra Wireless - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.koneki.ldt.debug.ui.internal.interpreters;
+
+import org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterEnvironmentVariablesBlock;
+import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog;
+
+public class LuaInterpreterEnvironmentVariablesBlock extends AbstractInterpreterEnvironmentVariablesBlock {
+
+ protected LuaInterpreterEnvironmentVariablesBlock(AddScriptInterpreterDialog dialog) {
+ super(dialog);
+ }
+
+}
diff --git a/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterPreferencePage.java b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterPreferencePage.java
index 9cc9119..1bcd7af 100644
--- a/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterPreferencePage.java
+++ b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpreterPreferencePage.java
@@ -10,13 +10,151 @@
*******************************************************************************/
package org.eclipse.koneki.ldt.debug.ui.internal.interpreters;
+import org.eclipse.dltk.core.environment.EnvironmentManager;
+import org.eclipse.dltk.core.environment.IEnvironment;
+import org.eclipse.dltk.debug.ui.DLTKDebugUIPlugin;
+import org.eclipse.dltk.debug.ui.interpreters.InterpretersUpdater;
+import org.eclipse.dltk.internal.debug.ui.IScriptDebugHelpContextIds;
import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersBlock;
+import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersMessages;
import org.eclipse.dltk.internal.debug.ui.interpreters.ScriptInterpreterPreferencePage;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.ScriptRuntime;
+import org.eclipse.dltk.launching.ScriptRuntime.DefaultInterpreterEntry;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.custom.BusyIndicator;
+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.ui.PlatformUI;
public class LuaInterpreterPreferencePage extends ScriptInterpreterPreferencePage {
+ private LuaInterpretersBlock fInterpretersBlock;
+
@Override
public InterpretersBlock createInterpretersBlock() {
return new LuaInterpretersBlock();
}
+
+ /**
+ * Copy of the super method without the initialization of the default interpreter and customizing interpreter list validation
+ */
+ @Override
+ protected Control createContents(Composite ancestor) {
+ initializeDialogUnits(ancestor);
+
+ noDefaultAndApplyButton();
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ ancestor.setLayout(layout);
+
+ fInterpretersBlock = (LuaInterpretersBlock) createInterpretersBlock();
+ fInterpretersBlock.createControl(ancestor);
+ Control control = fInterpretersBlock.getControl();
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.horizontalSpan = 1;
+ control.setLayoutData(data);
+
+ fInterpretersBlock.restoreColumnSettings(getDialogSettings(false), IScriptDebugHelpContextIds.INTERPRETER_PREFERENCE_PAGE);
+
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(ancestor, IScriptDebugHelpContextIds.INTERPRETER_PREFERENCE_PAGE);
+ checkDefaultInterpreter();
+ fInterpretersBlock.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+
+ validateInterpreterList();
+ }
+ });
+ applyDialogFont(ancestor);
+ validateInterpreterList();
+ return ancestor;
+ }
+
+ /**
+ * Retrieve default interpreter in preference and check it is the UI
+ */
+ private void checkDefaultInterpreter() {
+ IEnvironment[] environments = EnvironmentManager.getEnvironments();
+ for (IEnvironment environment : environments) {
+ // Retrieve default
+ IInterpreterInstall defaultInterpreter = ScriptRuntime.getDefaultInterpreterInstall(new DefaultInterpreterEntry(fInterpretersBlock
+ .getCurrentNature(), environment.getId()));
+ if (defaultInterpreter != null) {
+ // Find the interpreter in the list
+ for (IInterpreterInstall interpreter : fInterpretersBlock.getInterpreters()) {
+ if (defaultInterpreter.equals(interpreter)) {
+ //check it
+ fInterpretersBlock.setCheckedInterpreter(interpreter);
+ }
+ }
+ }
+ }
+ }
+
+ private void validateInterpreterList() {
+ // remove old messages
+ setErrorMessage(null);
+
+ // check if no default interpreter
+ if (fInterpretersBlock.getInterpreters().length > 0 && fInterpretersBlock.getSelection().isEmpty()) {
+ setErrorMessage(InterpretersMessages.InterpreterPreferencePage_pleaseSetDefaultInterpreter);
+
+ // Check if no interpreter
+ } else if (fInterpretersBlock.getInterpreters().length == 0) {
+ setErrorMessage(InterpretersMessages.InterpreterPreferencePage_addInterpreter);
+ }
+ }
+
+ /**
+ * Copy of the super method but using the current class's fInterpretersBlock private attribute
+ */
+ @Override
+ public boolean performOk() {
+ final boolean[] canceled = new boolean[] { false };
+ BusyIndicator.showWhile(null, new Runnable() {
+ public void run() {
+ IInterpreterInstall[] defaultInterpreter = fInterpretersBlock.getCheckedInterpreters();
+ IInterpreterInstall[] interpreters = fInterpretersBlock.getInterpreters();
+
+ InterpretersUpdater updater = new InterpretersUpdater();
+ if (!updater.updateInterpreterSettings(fInterpretersBlock.getCurrentNature(), interpreters, defaultInterpreter)) {
+ canceled[0] = true;
+ }
+ }
+ });
+
+ if (canceled[0]) {
+ return false;
+ }
+
+ // save column widths
+ fInterpretersBlock.saveColumnSettings(getDialogSettings(true), IScriptDebugHelpContextIds.INTERPRETER_PREFERENCE_PAGE);
+
+ return true;
+ }
+
+ /**
+ * Copy of the super method but using the current class's fInterpretersBlock private attribute
+ */
+ protected IDialogSettings getDialogSettings(boolean isSaving) {
+ final IDialogSettings settings = DLTKDebugUIPlugin.getDefault().getDialogSettings();
+ final String nature = fInterpretersBlock.getCurrentNature();
+ IDialogSettings section = settings.getSection(nature);
+ if (section == null) {
+ if (isSaving) {
+ section = settings.addNewSection(nature);
+ } else {
+ section = settings;
+ }
+ }
+ return section;
+ }
+
}
diff --git a/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpretersBlock.java b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpretersBlock.java
index 5d79d92..598b538 100644
--- a/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpretersBlock.java
+++ b/plugins/org.eclipse.koneki.ldt.debug.ui/src/org/eclipse/koneki/ldt/debug/ui/internal/interpreters/LuaInterpretersBlock.java
@@ -12,9 +12,12 @@ package org.eclipse.koneki.ldt.debug.ui.internal.interpreters;
import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog;
import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersBlock;
+import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersMessages;
import org.eclipse.dltk.launching.IInterpreterInstall;
import org.eclipse.dltk.launching.ScriptRuntime;
import org.eclipse.koneki.ldt.core.LuaNature;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
public class LuaInterpretersBlock extends InterpretersBlock {
@@ -23,9 +26,21 @@ public class LuaInterpretersBlock extends InterpretersBlock {
return LuaNature.ID;
}
+ @Override
protected AddScriptInterpreterDialog createInterpreterDialog(IInterpreterInstall standin) {
- AddLuaInterpreterDialog dialog = new AddLuaInterpreterDialog(this, getShell(), ScriptRuntime.getInterpreterInstallTypes(getCurrentNature()),
+ return new AddLuaInterpreterDialog(this, getShell(), ScriptRuntime.getInterpreterInstallTypes(getCurrentNature()),
standin);
- return dialog;
+ }
+
+ @Override
+ protected Button createPushButton(Composite parent, String label) {
+ Button button = super.createPushButton(parent, label);
+
+ // Hide Search button
+ if (InterpretersMessages.InstalledInterpretersBlock_6.equals(label)) {
+ button.setVisible(false);
+ }
+
+ return button;
}
}