diff options
author | Andrey Loskutov | 2021-12-01 17:29:53 +0000 |
---|---|---|
committer | Andrey Loskutov | 2021-12-14 13:47:14 +0000 |
commit | fce216930e9e87e2f735cc72f7687717aec90e94 (patch) | |
tree | 318b4282a6d1523a78bf58ddd50a82186135f4f8 | |
parent | e81a54a076c159432d2e8b1c661d94a805516849 (diff) | |
download | eclipse.platform.debug-fce216930e9e87e2f735cc72f7687717aec90e94.tar.gz eclipse.platform.debug-fce216930e9e87e2f735cc72f7687717aec90e94.tar.xz eclipse.platform.debug-fce216930e9e87e2f735cc72f7687717aec90e94.zip |
Bug 577564 - add priority attribute to variableValueEditorY20211226-0600Y20211224-0600Y20211223-0600Y20211222-1030Y20211222-0840Y20211222-0830Y20211222-0600Y20211221-0600Y20211220-0600Y20211219-0600Y20211218-0600Y20211217-0600Y20211216-0600Y20211215-1140Y20211215-0600I20211226-1800I20211225-1800I20211224-1800I20211223-1800I20211222-1800I20211221-1800I20211221-0620I20211220-1820I20211219-1800I20211218-1800I20211218-0200I20211218-0140I20211217-1800I20211216-1800I20211215-1800I20211214-1800
New "priority" attribute is optional integer number 0 to 10 describing
priority of this extension, with 0 being the lowest priority. If
multiple contributions have the same priority, an arbitrary contribution
among them will be selected.
Change-Id: Ib787799214f31423adb66ec1c5bd56f555f97dde
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.debug/+/188423
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
9 files changed, 216 insertions, 16 deletions
diff --git a/org.eclipse.debug.tests/META-INF/MANIFEST.MF b/org.eclipse.debug.tests/META-INF/MANIFEST.MF index baca5dc14..856c28e50 100644 --- a/org.eclipse.debug.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.debug.tests/META-INF/MANIFEST.MF @@ -29,6 +29,7 @@ Export-Package: org.eclipse.debug.tests, org.eclipse.debug.tests.sourcelookup, org.eclipse.debug.tests.statushandlers, org.eclipse.debug.tests.stepfilters, + org.eclipse.debug.tests.ui, org.eclipse.debug.tests.view.memory, org.eclipse.debug.tests.viewer.model Eclipse-BundleShape: dir diff --git a/org.eclipse.debug.tests/plugin.xml b/org.eclipse.debug.tests/plugin.xml index a350e91c8..4503162f5 100644 --- a/org.eclipse.debug.tests/plugin.xml +++ b/org.eclipse.debug.tests/plugin.xml @@ -142,4 +142,19 @@ modelIdentifier="org.eclipse.debug.tests"> </logicalStructureType> </extension> + <extension + point="org.eclipse.debug.ui.variableValueEditors"> + <variableValueEditor + modelId="testModel" + priority="x" + class="org.eclipse.debug.tests.ui.TestVariableValueEditor1"/> + <variableValueEditor + modelId="testModel" + priority="10" + class="org.eclipse.debug.tests.ui.TestVariableValueEditor2"/> + <variableValueEditor + modelId="testModel" + priority="-1" + class="org.eclipse.debug.tests.ui.TestVariableValueEditor3"/> + </extension> </plugin> diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java index 369225644..be2dc6124 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java @@ -44,6 +44,7 @@ import org.eclipse.debug.tests.logicalstructure.LogicalStructureCacheTest; import org.eclipse.debug.tests.sourcelookup.SourceLookupFacilityTests; import org.eclipse.debug.tests.statushandlers.StatusHandlerTests; import org.eclipse.debug.tests.stepfilters.StepFiltersTests; +import org.eclipse.debug.tests.ui.VariableValueEditorManagerTests; import org.eclipse.debug.tests.view.memory.MemoryRenderingTests; import org.eclipse.debug.tests.view.memory.TableRenderingTests; import org.eclipse.debug.tests.viewer.model.ChildrenUpdateTests; @@ -89,6 +90,7 @@ import org.junit.runners.Suite; FilterTransformTests.class, ChildrenUpdateTests.class, PresentationContextTests.class, + VariableValueEditorManagerTests.class, // Memory view MemoryRenderingTests.class, diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor1.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor1.java new file mode 100644 index 000000000..eb2a93f82 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor1.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2021 Andrey Loskutov 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: + * Andrey Loskutov (loskutov@gmx.de) - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.ui; + +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.ui.actions.IVariableValueEditor; +import org.eclipse.swt.widgets.Shell; + +public class TestVariableValueEditor1 implements IVariableValueEditor { + + @Override + public boolean editVariable(IVariable variable, Shell shell) { + return false; + } + + @Override + public boolean saveVariable(IVariable variable, String expression, Shell shell) { + return false; + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor2.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor2.java new file mode 100644 index 000000000..658968f53 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor2.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2021 Andrey Loskutov 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: + * Andrey Loskutov (loskutov@gmx.de) - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.ui; + +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.ui.actions.IVariableValueEditor; +import org.eclipse.swt.widgets.Shell; + +public class TestVariableValueEditor2 implements IVariableValueEditor { + + @Override + public boolean editVariable(IVariable variable, Shell shell) { + return false; + } + + @Override + public boolean saveVariable(IVariable variable, String expression, Shell shell) { + return false; + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor3.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor3.java new file mode 100644 index 000000000..09c9cfac6 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/TestVariableValueEditor3.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2021 Andrey Loskutov 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: + * Andrey Loskutov (loskutov@gmx.de) - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.ui; + +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.ui.actions.IVariableValueEditor; +import org.eclipse.swt.widgets.Shell; + +public class TestVariableValueEditor3 implements IVariableValueEditor { + + @Override + public boolean editVariable(IVariable variable, Shell shell) { + return false; + } + + @Override + public boolean saveVariable(IVariable variable, String expression, Shell shell) { + return false; + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/VariableValueEditorManagerTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/VariableValueEditorManagerTests.java new file mode 100644 index 000000000..bbb07de01 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/VariableValueEditorManagerTests.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2021 Andrey Loskutov 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: + * Andrey Loskutov (loskutov@gmx.de) - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.ui; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.debug.internal.ui.VariableValueEditorManager; +import org.eclipse.debug.tests.AbstractDebugTest; +import org.eclipse.debug.ui.actions.IVariableValueEditor; +import org.junit.Test; + +/** + * Tests status handlers + */ +public class VariableValueEditorManagerTests extends AbstractDebugTest { + + @Test + public void testHighestPriorityEditorUsed() { + IVariableValueEditor editor = VariableValueEditorManager.getDefault().getVariableValueEditor("testModel"); + assertEquals("Not the editor with highest priority used by VariableValueEditorManager", TestVariableValueEditor2.class, editor.getClass()); + } + + + +} diff --git a/org.eclipse.debug.ui/schema/variableValueEditors.exsd b/org.eclipse.debug.ui/schema/variableValueEditors.exsd index 76d585467..77d8b014d 100644 --- a/org.eclipse.debug.ui/schema/variableValueEditors.exsd +++ b/org.eclipse.debug.ui/schema/variableValueEditors.exsd @@ -2,18 +2,23 @@ <!-- Schema file written by PDE --> <schema targetNamespace="org.eclipse.debug.ui" xmlns="http://www.w3.org/2001/XMLSchema"> <annotation> - <appinfo> + <appInfo> <meta.schema plugin="org.eclipse.debug.ui" id="variableValueEditors" name="Variable Value Editors"/> - </appinfo> + </appInfo> <documentation> This extension point provides a mechanism for contributing variable value editors for a particular debug model. Variable value editors are used to edit/save variable values. When the user invokes the "Change Value..." or "Assign Value" (details pane) actions on a variable in the Variables view, the contributed <code>org.eclipse.debug.ui.actions.IVariableValueEditor</code> will be invoked to change the value. </documentation> </annotation> <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> <complexType> <sequence> - <element ref="variableValueEditor"/> + <element ref="variableValueEditor" minOccurs="1" maxOccurs="unbounded"/> </sequence> <attribute name="point" type="string" use="required"> <annotation> @@ -46,9 +51,9 @@ <documentation> Implementation of <code>org.eclipse.debug.ui.actions.IVariableValueEditor</code> </documentation> - <appinfo> + <appInfo> <meta.attribute kind="java" basedOn=":org.eclipse.debug.ui.actions.IVariableValueEditor"/> - </appinfo> + </appInfo> </annotation> </attribute> <attribute name="modelId" type="string" use="required"> @@ -58,22 +63,31 @@ </documentation> </annotation> </attribute> + <attribute name="priority" type="string"> + <annotation> + <documentation> + Optional integer number 0 to 10 describing priority of this extension, with 0 being the lowest priority. +If values outside of [0,10] range are specified, they are replaced with appropriate limits, any non integer values are ignored and zero (lowest priority) is used. +If multiple contributions have the same priority, an arbitrary contribution among them will be selected. + </documentation> + </annotation> + </attribute> </complexType> </element> <annotation> - <appinfo> + <appInfo> <meta.section type="since"/> - </appinfo> + </appInfo> <documentation> 3.1 </documentation> </annotation> <annotation> - <appinfo> + <appInfo> <meta.section type="examples"/> - </appinfo> + </appInfo> <documentation> <pre> <extension @@ -87,20 +101,19 @@ </annotation> <annotation> - <appinfo> + <appInfo> <meta.section type="apiInfo"/> - </appinfo> + </appInfo> <documentation> Value of the attribute <b>class</b> must be a fully qualified name of a Java class that implements the interface <b>org.eclipse.debug.ui.actions.IVariableValueEditor</b>. </documentation> </annotation> - <annotation> - <appinfo> + <appInfo> <meta.section type="copyright"/> - </appinfo> + </appInfo> <documentation> Copyright (c) 2004, 2005 IBM Corporation and others.<br> diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/VariableValueEditorManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/VariableValueEditorManager.java index 2608bf0cc..80fa4dd19 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/VariableValueEditorManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/VariableValueEditorManager.java @@ -33,6 +33,14 @@ import org.eclipse.debug.ui.actions.IVariableValueEditor; */ public class VariableValueEditorManager { + private static final int MAX_PRIORITY = 10; + + private static final int DEFAULT_PRIORITY = 0; + + private static final String MODEL_ID = "modelId"; //$NON-NLS-1$ + + private static final String PRIORITY = "priority";//$NON-NLS-1$ + /** * Mapping of debug model identifiers to variable value editors. * The keys in this map are always Strings (model ids). @@ -101,10 +109,39 @@ public class VariableValueEditorManager { IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_VARIABLE_VALUE_EDITORS); IConfigurationElement[] elements = ep.getConfigurationElements(); for (IConfigurationElement element : elements) { - String modelId = element.getAttribute("modelId"); //$NON-NLS-1$ + String modelId = element.getAttribute(MODEL_ID); if (modelId != null) { - fEditorMap.put(modelId, element); + Object original = fEditorMap.put(modelId, element); + // Check if the original contribution had higher priority + if (original instanceof IConfigurationElement) { + int newPrio = getPriority(element); + int oldPrio = getPriority((IConfigurationElement) original); + if (oldPrio > newPrio) { + // restore + fEditorMap.put(modelId, original); + } + } + } + } + } + + private static int getPriority(IConfigurationElement element) { + String attribute = element.getAttribute(PRIORITY); + int priority = DEFAULT_PRIORITY; + if (attribute != null) { + try { + priority = Integer.parseInt(attribute); + } catch (Exception e) { + String error = "Unexpected value: '" + attribute + //$NON-NLS-1$ + "' for '" + PRIORITY + "' attribute " //$NON-NLS-1$//$NON-NLS-2$ + + " in extension point '" + IDebugUIConstants.EXTENSION_POINT_VARIABLE_VALUE_EDITORS //$NON-NLS-1$ + + "' was specified by " + element.getNamespaceIdentifier(); //$NON-NLS-1$ + IllegalArgumentException ie = new IllegalArgumentException(error, e); + DebugUIPlugin.log(ie); } + priority = Math.max(DEFAULT_PRIORITY, priority); + priority = Math.min(MAX_PRIORITY, priority); } + return priority; } } |