Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2012-02-24 07:56:51 -0500
committerptessier2012-02-24 07:56:51 -0500
commit172b7f98096d78ead0df1420d68cf617de1f6866 (patch)
treeb5f07ea7144f8d512964a739dbb04e584219e671 /plugins
parent495a681ff98bffcd5df92f0ecb8b914a84dc23b0 (diff)
downloadorg.eclipse.papyrus-172b7f98096d78ead0df1420d68cf617de1f6866.tar.gz
org.eclipse.papyrus-172b7f98096d78ead0df1420d68cf617de1f6866.tar.xz
org.eclipse.papyrus-172b7f98096d78ead0df1420d68cf617de1f6866.zip
372474: [DirectEditor] possibility to add priority for direct editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=372474
Diffstat (limited to 'plugins')
-rw-r--r--plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorExtensionPoint.java104
-rw-r--r--plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorRegistry.java126
-rw-r--r--plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/IDirectEditorConfigurationIds.java24
-rw-r--r--plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/preferences/PapyrusEmbeddedEditorsPreferencePage.java1
4 files changed, 253 insertions, 2 deletions
diff --git a/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorExtensionPoint.java b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorExtensionPoint.java
index fde94ea291f..1faa76b9835 100644
--- a/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorExtensionPoint.java
+++ b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorExtensionPoint.java
@@ -24,12 +24,15 @@ import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditor
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
+import org.eclipse.papyrus.infra.constraints.constraints.JavaQuery;
import org.eclipse.swt.graphics.Image;
public class DirectEditorExtensionPoint {
/** Array that stores registered transformations */
private static DirectEditorExtensionPoint[] configurations;
+
+ private static DirectEditorRegistry directEditorProvider;
/** value of the language attribute */
private String language;
@@ -42,6 +45,12 @@ public class DirectEditorExtensionPoint {
private Class objectClassToEdit;
+ /**the current priority of the direct editor, can be null**/
+ private Integer priority;
+
+
+
+
/**
* Returns the set of transformations registered in the platform
*
@@ -71,8 +80,22 @@ public class DirectEditorExtensionPoint {
} // end of configElements loop
configurations = directEditorExtensionPoints.toArray(new DirectEditorExtensionPoint[directEditorExtensionPoints.size()]);
+ directEditorProvider= new DirectEditorRegistry();
+ directEditorProvider.init(configurations);
+
return configurations;
}
+
+ public static DirectEditorRegistry getDirectEditorProvider(){
+ if(directEditorProvider!=null){
+ return directEditorProvider;
+ }
+ else{
+ directEditorProvider= new DirectEditorRegistry();
+ directEditorProvider.init(getDirectEditorConfigurations());
+ return directEditorProvider;
+ }
+ }
/**
* Retrieves the preferred editor configuration for the specified type
@@ -164,6 +187,9 @@ public class DirectEditorExtensionPoint {
// string
objectToEdit = getAttribute(configElt, IDirectEditorConfigurationIds.ATT_OBJECT_TO_EDIT, "java.lang.Object", true); // should already be a string
directEditorConfiguration = getDirectEditorConfigurationClass(configElt);
+ //the constraint maybe null!
+
+ priority= getPriority(configElt);
if(directEditorConfiguration == null) {
directEditorConfiguration = getAdvancedDirectEditorConfigurationClass(configElt);
}
@@ -200,6 +226,56 @@ public class DirectEditorExtensionPoint {
return configuration;
}
+
+
+ /**
+ * Try to load a javaQuery defined in the extension point
+ *
+ * @param configElement the config element see {@link IConfigurationElement}
+ * @return the java query class see {@link JavaQuery}, can return null because this attribute is optional
+ */
+ protected static JavaQuery getJavaQueryClass(IConfigurationElement configElement) {
+ JavaQuery javaQuery = null;
+ try {
+ if(configElement.getAttribute(IDirectEditorConfigurationIds.ATT_CONSTRAINT)==null){return null;}
+ Object config = configElement.createExecutableExtension(IDirectEditorConfigurationIds.ATT_CONSTRAINT);
+ if(config instanceof JavaQuery) {
+ javaQuery = (JavaQuery)config;
+ }
+ } catch (CoreException e) {
+ Activator.log(e);
+ }
+ return javaQuery;
+ }
+
+
+ protected static Integer getPriority(IConfigurationElement configElement) {
+ IAdvancedEditorConfiguration configuration = null;
+ try {
+ for(IConfigurationElement childConfigElement : configElement.getChildren(IDirectEditorConfigurationIds.ATT_PRIORITY)) {
+
+ String config = getAttribute(childConfigElement, IDirectEditorConfigurationIds.ATT_PRIORITY_NAME, null, true);
+ if(config.equals(IDirectEditorConfigurationIds.PRIORITY_HIGHEST)){
+ return new Integer(0);}
+ if(config.equals(IDirectEditorConfigurationIds.PRIORITY_HIGH)){
+ return new Integer(1);}
+ if(config.equals(IDirectEditorConfigurationIds.PRIORITY_MEDIUM)){
+ return new Integer(2);}
+ if(config.equals(IDirectEditorConfigurationIds.PRIORITY_LOW)){
+ return new Integer(3);}
+ if(config.equals(IDirectEditorConfigurationIds.PRIORITY_LOWEST)){
+ return new Integer(4);}
+ System.out.println(config);
+ }
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ configuration = null;
+ }
+ return new Integer(5);
+ }
+
+
protected static IAdvancedEditorConfiguration getAdvancedDirectEditorConfigurationClass(IConfigurationElement configElement) {
IAdvancedEditorConfiguration configuration = null;
try {
@@ -221,7 +297,7 @@ public class DirectEditorExtensionPoint {
return configuration;
}
-///////////////////////////////// TODO:(done) Method added for the case of popup editors
+ ///////////////////////////////// TODO:(done) Method added for the case of popup editors
protected static IPopupEditorConfiguration getPopupDirectEditorConfigurationClass(IConfigurationElement configElement) {
IPopupEditorConfiguration configuration = null;
try {
@@ -242,7 +318,7 @@ public class DirectEditorExtensionPoint {
}
return configuration;
}
-/////////////////////////////////////
+ /////////////////////////////////////
/**
* Returns the value of the attribute that has the given name, for the given configuration
@@ -365,4 +441,28 @@ public class DirectEditorExtensionPoint {
this.directEditorConfiguration = directEditorConfiguration;
}
+ /**
+ * Gets the priority.
+ *
+ * @return the priority
+ */
+ public Integer getPriority() {
+ return priority;
+ }
+
+
+ /**
+ * Sets the priority.
+ *
+ * @param priority the new priority
+ */
+ public void setPriority(Integer priority) {
+ this.priority = priority;
+ }
+
+
+
+
+
+
}
diff --git a/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorRegistry.java b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorRegistry.java
new file mode 100644
index 00000000000..7c96f7b5793
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/DirectEditorRegistry.java
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Patrick Tesseir (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.extensionpoints.editors.definition;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.TreeMap;
+
+import org.eclipse.papyrus.extensionpoints.editors.Activator;
+import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
+
+/**
+ * the goal of this class is to store all direct editors and to provides them by taking account
+ * object to edit, constraint, and priority
+ *
+ */
+public class DirectEditorRegistry {
+
+ // map of direct editor indexed by priorities
+ protected TreeMap<Integer, ArrayList<DirectEditorExtensionPoint>> editorMap=new TreeMap<Integer, ArrayList<DirectEditorExtensionPoint>>();
+ //list of objects that can be edited
+ protected ArrayList<String> objectToEdits= new ArrayList<String>();
+
+ /**
+ * add a direct editor
+ * if this direct editor is already used as default in preferences, its priority becomes 0
+ * @param directEditor a direct editor, cannot be null
+ */
+ public void add(DirectEditorExtensionPoint directEditor){
+ assert(directEditor!=null);
+ objectToEdits.add(directEditor.getObjectToEdit());
+ Integer priority=directEditor.getPriority();
+
+ //take in account priority of preferences
+ String preferedLanguage = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + directEditor.getObjectToEdit());
+
+ //if the language equals is store in preferences this is the default direct editor
+ if(preferedLanguage.equals(directEditor.getLanguage())) {
+ priority=new Integer(0);
+ }
+ ArrayList<DirectEditorExtensionPoint> currentValue=editorMap.get(priority);
+ if( currentValue==null){
+ currentValue= new ArrayList<DirectEditorExtensionPoint>();
+ }
+
+ currentValue.add(directEditor);
+ editorMap.put(priority, currentValue);
+ }
+
+ /**
+ * put in preferences the editor with the more important priority
+ */
+ protected void adaptPreferences(){
+ Iterator<String> iter= objectToEdits.iterator();
+ DirectEditorExtensionPoint defaultDirectEditor=null;
+ while(iter.hasNext()) {
+ String objectToEdit = (String)iter.next();
+ defaultDirectEditor= getDefaultDirectEditor(objectToEdit);
+
+ String id= IDirectEditorsIds.EDITOR_FOR_ELEMENT + defaultDirectEditor.getObjectToEdit();
+ String language= defaultDirectEditor.getLanguage();
+ Activator.getDefault().getPreferenceStore().setValue(id, language);
+ }
+ }
+ @Override
+ public String toString() {
+ String out="";
+ Iterator<Integer> keyIterator=editorMap.keySet().iterator();
+
+ while(keyIterator.hasNext()) {
+ Integer index = (Integer)keyIterator.next();
+ out=out+"\n["+index+"]"+ "=["+editorMap.get(index)+"]";
+
+ }
+ return out;
+ }
+
+ /**
+ * used to fill the registry with an array of direct editors
+ * @param directEditors cannot be null
+ */
+ public void init(DirectEditorExtensionPoint[] directEditors){
+ editorMap= new TreeMap<Integer, ArrayList<DirectEditorExtensionPoint>>();
+ objectToEdits= new ArrayList<String>();
+ for(int i = 0; i < directEditors.length; i++) {
+ add(directEditors[i]);
+
+ }
+ adaptPreferences();
+
+ }
+ /**
+ * get the direct editor with the higher priority for a given object to edit.
+ * @param ObjectToEdit the string that represents the element to edit
+ * @return a direct editor, it can be null
+ */
+ public DirectEditorExtensionPoint getDefaultDirectEditor (String ObjectToEdit){
+ Iterator<Integer> keyIterator=editorMap.keySet().iterator();
+
+ while(keyIterator.hasNext()) {
+ Integer index = (Integer)keyIterator.next();
+ Iterator<DirectEditorExtensionPoint> iter=editorMap.get(index).iterator();
+ while(iter.hasNext()) {
+ DirectEditorExtensionPoint directEditorExtensionPoint = (DirectEditorExtensionPoint)iter.next();
+ if( directEditorExtensionPoint.getObjectToEdit().equals(ObjectToEdit)){
+ return directEditorExtensionPoint;
+ }
+
+ }
+ }
+
+ return null;
+ }
+
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/IDirectEditorConfigurationIds.java b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/IDirectEditorConfigurationIds.java
index 57b027f3111..cbf480aa0ad 100644
--- a/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/IDirectEditorConfigurationIds.java
+++ b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/definition/IDirectEditorConfigurationIds.java
@@ -41,4 +41,28 @@ public interface IDirectEditorConfigurationIds {
/** id of the direct editor popup configuration tag */
public static final String TAG_POPUP_EDITOR = "popupeditor";
+
+ /** id of the constraint associated to a directEditor */
+ public static final String ATT_CONSTRAINT= "constraint";
+
+ /** id of the priority associated to a directEditor */
+ public static final String ATT_PRIORITY="Priority";
+
+ /** id of the priority name associated to a directEditor */
+ public static final String ATT_PRIORITY_NAME="name";
+
+ /** string that represents the lowest priority**/
+ public static final String PRIORITY_LOWEST = "Lowest";
+
+ /** string that represents a Low priority**/
+ public static final String PRIORITY_LOW = "Low";
+
+ /** string that represents a Medium priority**/
+ public static final String PRIORITY_MEDIUM = "Medium";
+
+ /** string that represents a High priority**/
+ public static final String PRIORITY_HIGH = "High";
+
+ /** string that represents the Highest priority**/
+ public static final String PRIORITY_HIGHEST = "Highest";
}
diff --git a/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/preferences/PapyrusEmbeddedEditorsPreferencePage.java b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/preferences/PapyrusEmbeddedEditorsPreferencePage.java
index c6aecbcc47d..d488a40a74e 100644
--- a/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/preferences/PapyrusEmbeddedEditorsPreferencePage.java
+++ b/plugins/core/org.eclipse.papyrus.extensionpoints.editors/src/org/eclipse/papyrus/extensionpoints/editors/preferences/PapyrusEmbeddedEditorsPreferencePage.java
@@ -234,6 +234,7 @@ public class PapyrusEmbeddedEditorsPreferencePage extends PreferencePage impleme
item.setData(DATA_EDITOR, null);
item.setText(simpleEditorPrefered ? getEditorItemName(null) + DEFAULT_EDITOR_LABEL : getEditorItemName(null));
}
+
/**
* Retrieves the {@link TableItem} name

Back to the top