Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[Dltk-dev] Re: fix for resetting debug engine preferences


  attaching the patch helps :)

On Sun, May 11, 2008 at 3:36 PM, Jae Gangemi <jgangemi@xxxxxxxxx> wrote:
hello all -

  it looks like restoring the default values for debugging engines and the likes is currently broken. i have a fix for this, but it required me to add a new method to the DLTKContributionExtensionManager class so i can retrieve a contribution based solely on its configured priority in the plugin.xml. otherwise, if an id based IDLTKContributionSelector is in use, it will continue to use whatever the last saved value is.

  with the 1.0 ramp down policy in effect, i'm guessing that this change is prohibitted by the api freeze, so i wanted to see how to proceed.

  i've attached a patch so others can take a look.

  this patch also included a fix to automatically selected whatever the default global interpreter is, rather then the making the user explicitly pick one, but that is entirely an internal change.

--
-jae



--
-jae
### Eclipse Workspace Patch 1.0
#P org.eclipse.dltk.core
Index: model/org/eclipse/dltk/core/DLTKContributionExtensionManager.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/DLTKContributionExtensionManager.java,v
retrieving revision 1.8
diff -u -r1.8 DLTKContributionExtensionManager.java
--- model/org/eclipse/dltk/core/DLTKContributionExtensionManager.java	17 Apr 2008 09:16:02 -0000	1.8
+++ model/org/eclipse/dltk/core/DLTKContributionExtensionManager.java	11 May 2008 19:34:08 -0000
@@ -59,7 +59,9 @@
 				.toArray(new IDLTKContributedExtension[contributions.size()]);
 	}
 
-	public IDLTKContributedExtension getSelectedContribution(IProject project, String natureId) {
+	public IDLTKContributedExtension getSelectedContribution(IProject project,
+			String natureId) {
+
 		IDLTKContributedExtension[] contributions = getContributions(natureId);
 
 		if (contributions.length > 0) {
@@ -76,6 +78,20 @@
 	}
 
 	/**
+	 * Retrieves a registered contribution based upon its priority.
+	 * 
+	 * @param project
+	 *            project
+	 * @param natureId
+	 *            nature id
+	 */
+	public IDLTKContributedExtension getPriorityContribution(IProject project,
+			String natureId) {
+		IDLTKContributedExtension[] contributions = getContributions(natureId);
+		return defaultSelector.select(contributions, project);
+	}
+
+	/**
 	 * Get the contributions registered for the given nature id
 	 * 
 	 * @param natureId
#P org.eclipse.dltk.ui
Index: src/org/eclipse/dltk/ui/preferences/ContributedExtensionOptionsBlock.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/preferences/ContributedExtensionOptionsBlock.java,v
retrieving revision 1.5
diff -u -r1.5 ContributedExtensionOptionsBlock.java
--- src/org/eclipse/dltk/ui/preferences/ContributedExtensionOptionsBlock.java	2 Apr 2008 01:54:04 -0000	1.5
+++ src/org/eclipse/dltk/ui/preferences/ContributedExtensionOptionsBlock.java	11 May 2008 19:34:09 -0000
@@ -26,7 +26,6 @@
 
 	private ComboViewerBlock viewer;
 
-	// private ComboViewer contributionViewer;
 	private Composite descriptionPlace;
 
 	public ContributedExtensionOptionsBlock(IStatusChangeListener context,
@@ -117,7 +116,15 @@
 			}
 
 			protected Object getDefaultObject() {
-				return getExtensionManager().getSelectedContribution(
+				/*
+				 * no preference value has been set so we want a contribution
+				 * that is returned based upon the 'select by priority' logic
+				 * 
+				 * this is done to handle the case where the plugin implementor
+				 * did not configure a default value via a preference
+				 * initializer
+				 */
+				return getExtensionManager().getPriorityContribution(
 						getProject(), getNatureId());
 			}
 
@@ -166,6 +173,11 @@
 		viewer.initialize(contributions);
 	}
 
+	public void performDefaults() {
+		super.performDefaults();
+		viewer.performDefaults();
+	}
+
 	protected final void updateSelection(IDLTKContributedExtension contrib) {
 		String id = contrib.getId();
 		setValue(getSavedContributionKey(), id);
Index: src/org/eclipse/dltk/ui/preferences/ComboViewerBlock.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/preferences/ComboViewerBlock.java,v
retrieving revision 1.1
diff -u -r1.1 ComboViewerBlock.java
--- src/org/eclipse/dltk/ui/preferences/ComboViewerBlock.java	2 Apr 2008 01:54:04 -0000	1.1
+++ src/org/eclipse/dltk/ui/preferences/ComboViewerBlock.java	11 May 2008 19:34:09 -0000
@@ -38,19 +38,14 @@
 	 */
 	public void initialize(Object[] elements) {
 		viewer.add(elements);
+		setSelectedObject();
+	}
 
-		String id = getSavedObjectId();
-		Object selected = null;
-
-		if (id == null || "".equals(id)) { //$NON-NLS-1$
-			// no entry exists in the preference store for the pref key
-			selected = getDefaultObject();
-		} else {
-			selected = getObjectById(id);
-
-		}
-
-		setSelectedObject(selected);
+	/**
+	 * Reset the combo viewer with its default values.
+	 */
+	public void performDefaults() {
+		setSelectedObject();
 	}
 
 	/**
@@ -61,7 +56,7 @@
 
 	/**
 	 * Returns the name of the object that will be displayed in the drop-down
-	 * seleector.
+	 * selector.
 	 */
 	protected abstract String getObjectName(Object element);
 
@@ -72,7 +67,8 @@
 	 * Subclasses should use this method to store the changed preference value.
 	 * </p>
 	 * 
-	 * @param element newly selected element
+	 * @param element
+	 *            newly selected element
 	 */
 	protected abstract void selectedObjectChanged(Object element);
 
@@ -97,12 +93,6 @@
 	 */
 	protected abstract Object getObjectById(String id);
 
-	private void setSelectedObject(Object element) {
-		if (element != null) {
-			viewer.setSelection(new StructuredSelection(element));
-		}
-	}
-
 	private Object getSelectedObject() {
 		IStructuredSelection selection = (IStructuredSelection) viewer
 				.getSelection();
@@ -112,4 +102,24 @@
 
 		return null;
 	}
+
+	private void setSelectedObject() {
+		String id = getSavedObjectId();
+		Object selected = null;
+
+		if (id == null || "".equals(id)) { //$NON-NLS-1$
+			// no entry exists in the preference store for the pref key
+			selected = getDefaultObject();
+		} else {
+			selected = getObjectById(id);
+			// saved object no longer exists, fall back to the default
+			if (selected == null) {
+				selected = getDefaultObject();
+			}
+		}
+
+		if (selected != null) {
+			viewer.setSelection(new StructuredSelection(selected));
+		}
+	}
 }
#P org.eclipse.dltk.debug.ui
Index: src/org/eclipse/dltk/internal/debug/ui/interpreters/InternalScriptInterpreterPreferenceBlock.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.debug.ui/src/org/eclipse/dltk/internal/debug/ui/interpreters/InternalScriptInterpreterPreferenceBlock.java,v
retrieving revision 1.1
diff -u -r1.1 InternalScriptInterpreterPreferenceBlock.java
--- src/org/eclipse/dltk/internal/debug/ui/interpreters/InternalScriptInterpreterPreferenceBlock.java	2 Apr 2008 01:54:03 -0000	1.1
+++ src/org/eclipse/dltk/internal/debug/ui/interpreters/InternalScriptInterpreterPreferenceBlock.java	11 May 2008 19:34:09 -0000
@@ -3,9 +3,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.dltk.core.internal.environment.LocalEnvironment;
 import org.eclipse.dltk.launching.IInterpreterInstall;
 import org.eclipse.dltk.launching.IInterpreterInstallType;
 import org.eclipse.dltk.launching.ScriptRuntime;
+import org.eclipse.dltk.launching.ScriptRuntime.DefaultInterpreterEntry;
 import org.eclipse.dltk.ui.preferences.ComboViewerBlock;
 import org.eclipse.dltk.ui.preferences.ImprovedAbstractConfigurationBlock;
 import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore;
@@ -98,13 +100,14 @@
 	protected abstract String getSelectorNameLabel();
 
 	/**
-	 * Returns the {@link IInterpreterInstall} that will be auto-selected if 
-	 * an interpreter id is not found in the preference store.
-	 * 
-	 * <p>Subclasses may return <code>null</code> if they do not wish to auto
-	 * select an interpreter or if no interpreters are installed.</p>
+	 * Returns the {@link IInterpreterInstall} that will be auto-selected if an
+	 * interpreter id is not found in the preference store.
 	 */
-	protected abstract Object getDefaultSelectedInterpreter();
+	protected Object getDefaultSelectedInterpreter() {
+		DefaultInterpreterEntry entry = new DefaultInterpreterEntry(
+				getNatureId(), LocalEnvironment.ENVIRONMENT_ID);
+		return ScriptRuntime.getDefaultInterpreterInstall(entry);
+	}
 
 	/*
 	 * @see org.eclipse.dltk.ui.preferences.ImprovedAbstractConfigurationBlock#createOverlayKeys()
@@ -118,6 +121,14 @@
 		return keys;
 	}
 
+	/*
+	 * @see org.eclipse.dltk.ui.preferences.ImprovedAbstractConfigurationBlock#performDefaults()
+	 */
+	public void performDefaults() {
+		super.performDefaults();
+		viewer.performDefaults();
+	}
+
 	private IInterpreterInstall[] getInterpreterInstalls() {
 		List interpreters = new ArrayList();
 		IInterpreterInstallType[] types = ScriptRuntime

Back to the top