Bug 454697 - Images and actions extensible
Change-Id: I378325b242ba70bcac088b3400717c958cd218d9
Signed-off-by: Joy Bhattacharjee <joy.bhattacharjee@sap.com>
diff --git a/org.eclipse.ogee.designer/plugin.xml b/org.eclipse.ogee.designer/plugin.xml
index 1604985..5dba655 100644
--- a/org.eclipse.ogee.designer/plugin.xml
+++ b/org.eclipse.ogee.designer/plugin.xml
@@ -23,6 +23,7 @@
schema="schema/org.eclipse.ogee.designer.layout.exsd"/>
<extension-point id="org.eclipse.ogee.designer.contextmenu" name="Context Menu" schema="schema/org.eclipse.ogee.designer.contextmenu.exsd"/>
<extension-point id="org.eclipse.ogee.designer.bindingcontextmenu" name="BindingContextMenu" schema="schema/org.eclipse.ogee.designer.bindingcontextmenu.exsd"/>
+ <extension-point id="org.eclipse.ogee.designer.artifactselection" name="ArtifactSelection" schema="schema/org.eclipse.ogee.designer.artifactselection.exsd"/>
<extension
point="org.eclipse.graphiti.ui.diagramTypes">
diff --git a/org.eclipse.ogee.designer/schema/org.eclipse.ogee.designer.artifactselection.exsd b/org.eclipse.ogee.designer/schema/org.eclipse.ogee.designer.artifactselection.exsd
new file mode 100644
index 0000000..7eeea0d
--- /dev/null
+++ b/org.eclipse.ogee.designer/schema/org.eclipse.ogee.designer.artifactselection.exsd
@@ -0,0 +1,114 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.ogee.designer" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.ogee.designer" id="org.eclipse.ogee.designer.artifactselection" name="ArtifactSelection"/>
+ </appinfo>
+ <documentation>
+ This extention point provides an handle to the eobject selected in the editor
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element ref="artifactselection"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="artifactselection">
+ <annotation>
+ <documentation>
+ This extention will allow to get handle to the PictogramElement and EObject resouce which are selected or deleted from the graphical editor
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.ogee.designer.contextmenu.IArtifactSelection"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ The id of the extention point
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/ODataEditor.java b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/ODataEditor.java
index 3438fcf..b7eacfc 100644
--- a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/ODataEditor.java
+++ b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/ODataEditor.java
@@ -55,6 +55,7 @@
import org.eclipse.ogee.designer.messages.Messages;
import org.eclipse.ogee.designer.utils.ArtifactUtil;
import org.eclipse.ogee.designer.utils.IODataEditorConstants;
+import org.eclipse.ogee.designer.utils.ODataArtifactSelectionUtil;
import org.eclipse.ogee.designer.utils.ODataLayoutUtil;
import org.eclipse.ogee.designer.utils.PropertyUtil;
import org.eclipse.ogee.designer.visualizer.ODataModelVisualizer;
@@ -719,6 +720,10 @@
// Do the selection in the diagram.
selectPictogramElements(pes);
}
+ //below code is enable the artifact selection extention
+ PictogramElement[] selectedPictogramElements = getSelectedPictogramElements();
+ EObject businessObject = (EObject) getDiagramTypeProvider().getFeatureProvider().getBusinessObjectForPictogramElement(selectedPictogramElements[0]);
+ ODataArtifactSelectionUtil.notifyRegisteredSubscribers(selectedPictogramElements[0], businessObject , ODataArtifactSelectionUtil.SelectionStatus.SELECTED);
}
}
}
diff --git a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/contextmenu/IArtifactSelection.java b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/contextmenu/IArtifactSelection.java
new file mode 100644
index 0000000..114d123
--- /dev/null
+++ b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/contextmenu/IArtifactSelection.java
@@ -0,0 +1,37 @@
+package org.eclipse.ogee.designer.contextmenu;
+
+import java.util.EnumSet;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+public interface IArtifactSelection {
+
+ /**
+ * Set the handle to the PictogramElement selected
+ *
+ */
+ void setSelectedPictogramElement(PictogramElement pe);
+ /**
+ * Set the handle to the EObject selected
+ *
+ */
+ void setSelectedEObjectElement(EObject eo);
+ /**
+ * Set the handle to the PictogramElement deleted
+ *
+ */
+ void setDeletedPictogramElement(PictogramElement pe);
+ /**
+ * Set the handle to the EObject deleted
+ *
+ */
+ void setDeletedEObjectElement(EObject eo);
+ /**
+ * Return a list of objects to which the menu item can be added
+ *
+ * @return EnumSet Applicable UIElementType/s
+ */
+ public EnumSet<UIElementType> getApplicableElements();
+
+}
diff --git a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/features/ODataDeleteFeature.java b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/features/ODataDeleteFeature.java
index 0855da4..774e16d 100644
--- a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/features/ODataDeleteFeature.java
+++ b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/features/ODataDeleteFeature.java
@@ -39,6 +39,7 @@
import org.eclipse.ogee.designer.providers.ODataFeatureProvider;
import org.eclipse.ogee.designer.utils.ArtifactUtil;
import org.eclipse.ogee.designer.utils.IODataEditorConstants;
+import org.eclipse.ogee.designer.utils.ODataArtifactSelectionUtil;
import org.eclipse.ogee.designer.utils.ODataLayoutUtil;
import org.eclipse.ogee.designer.utils.ODataShapeUtil;
import org.eclipse.ogee.designer.utils.PropertyUtil;
@@ -187,6 +188,10 @@
// this is to update referred PictogramElements.
ODataShapeUtil.updateReferedShapes((EObject) currentObject,
getFeatureProvider(), true);
+ // this is to update referred PictogramElements.
+ EObject businessObject = (EObject) currentObject;
+ ODataArtifactSelectionUtil.notifyRegisteredSubscribers(context
+ .getPictogramElement(), businessObject , ODataArtifactSelectionUtil.SelectionStatus.DELETED);
}
}
diff --git a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/utils/IODataEditorConstants.java b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/utils/IODataEditorConstants.java
index 4f43b1d..1d57577 100644
--- a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/utils/IODataEditorConstants.java
+++ b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/utils/IODataEditorConstants.java
@@ -404,5 +404,22 @@
* The OData Perspective Id
*/
public static final String ODATA_PERSPECTIVE_ID = "org.eclipse.ogee.utils.perspective"; //$NON-NLS-1$
+
+
+ /**
+ * String Constant for Selection Extension Attribute "name"
+ */
+ public static final String ODATA_ARTIFACT_SELECTION_ATTRIBUTE_NAME = Activator.PLUGIN_ID
+ + ".artifactselection"; //$NON-NLS-1$
+
+ /**
+ * String Constant for artifact selection Extension Attribute "id"
+ */
+ public static final String ARTIFACT_SELECTION_ATTRIBUTE_ID = "id"; //$NON-NLS-1$
+
+ /**
+ * String Constant for artifact selection Extension Attribute "class"
+ */
+ public static final String ARTIFACT_SELECTION_ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$
}
diff --git a/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/utils/ODataArtifactSelectionUtil.java b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/utils/ODataArtifactSelectionUtil.java
new file mode 100644
index 0000000..81d90d7
--- /dev/null
+++ b/org.eclipse.ogee.designer/src/org/eclipse/ogee/designer/utils/ODataArtifactSelectionUtil.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2014 SAP SE.
+ * 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:
+ * SAP SE - initial API and implementation and/or initial documentation
+ *
+ *******************************************************************************/
+package org.eclipse.ogee.designer.utils;
+
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.ogee.designer.Activator;
+import org.eclipse.ogee.designer.contextmenu.IArtifactSelection;
+import org.eclipse.ogee.designer.contextmenu.UIElementType;
+import org.eclipse.ogee.model.odata.Association;
+import org.eclipse.ogee.model.odata.ComplexType;
+import org.eclipse.ogee.model.odata.EntitySet;
+import org.eclipse.ogee.model.odata.EntityType;
+import org.eclipse.ogee.model.odata.FunctionImport;
+import org.eclipse.ogee.utils.logger.Logger;
+
+/**
+ * This class will be used for to retrieve all
+ * implementations of artifact selection extension point.
+ *
+ *
+ */
+public class ODataArtifactSelectionUtil {
+ private static String[][] artifactSelectionOption = null;
+
+ public enum SelectionStatus {
+ SELECTED , DELETED;
+
+ }
+
+ public static IConfigurationElement[] getArtifactSelectionExtensions() {
+
+ IConfigurationElement[] extensionMenuConfigElems = Platform
+ .getExtensionRegistry().getConfigurationElementsFor(
+ IODataEditorConstants.ODATA_ARTIFACT_SELECTION_ATTRIBUTE_NAME );
+
+ return extensionMenuConfigElems;
+ }
+
+ /**
+ * Returns Current current selection.
+ *
+ * @param artifactSelectionId
+ *
+ * @return IArtifactSelection Instance.
+ */
+ public static IArtifactSelection getCurrentSelection(String artifactSelectionId) {
+ IArtifactSelection currentSelection = null;
+ String id = null;
+ String currentSelectionID = artifactSelectionId;
+
+ try {
+ IConfigurationElement[] contextMenuConfigElems = getArtifactSelectionExtensions();
+ for (IConfigurationElement iConfigurationElement : contextMenuConfigElems) {
+ id = iConfigurationElement
+ .getAttribute(IODataEditorConstants.ARTIFACT_SELECTION_ATTRIBUTE_ID );
+ if (id.equals(currentSelectionID)) {
+ currentSelection = (IArtifactSelection) iConfigurationElement
+ .createExecutableExtension(IODataEditorConstants.ARTIFACT_SELECTION_ATTRIBUTE_CLASS);
+ break;
+ }
+
+ }
+ } catch (CoreException e) {
+ Logger.getLogger(Activator.PLUGIN_ID).logError(e);
+ }
+
+ return currentSelection;
+ }
+
+ /**
+ * This method is used in creating UI in Editor Context Menu. Creates a
+ * String Array with name,id,parent_name,icon & key_binding with all
+ * available context menus
+ *
+ *
+ * @return String Array.
+ */
+ public static String[][] getCurrentSelectionOption() {
+ String id = null;
+ String className = null;
+ String plugin_id = null;
+ IArtifactSelection currentSelection = null;
+
+ if (artifactSelectionOption == null) {
+ IConfigurationElement[] contextMenuExtensions = getArtifactSelectionExtensions();
+ Map<String, IConfigurationElement> filteredExtensions = new LinkedHashMap<String, IConfigurationElement>();
+ for (IConfigurationElement iConfigurationElement : contextMenuExtensions) {
+ id = iConfigurationElement
+ .getAttribute(IODataEditorConstants.ARTIFACT_SELECTION_ATTRIBUTE_ID);
+ className = iConfigurationElement
+ .getAttribute(IODataEditorConstants.ARTIFACT_SELECTION_ATTRIBUTE_CLASS);
+ if (id != null && !id.isEmpty() && className != null
+ && !className.isEmpty()) {
+ try {
+ currentSelection = (IArtifactSelection) iConfigurationElement
+ .createExecutableExtension(IODataEditorConstants.ARTIFACT_SELECTION_ATTRIBUTE_CLASS);
+ if (currentSelection != null) {
+ filteredExtensions.put(id, iConfigurationElement);
+ }
+
+ } catch (CoreException e) {
+ Logger.getLogger(Activator.PLUGIN_ID).logError(e);
+ }
+
+ }
+ }
+ int counter = 0;
+ Collection<String> filteredKeys = filteredExtensions.keySet();
+ artifactSelectionOption = new String[filteredKeys.size()][2];
+ IConfigurationElement iConfigurationElement = null;
+ for (String key : filteredKeys) {
+ iConfigurationElement = filteredExtensions.get(key);
+ id = iConfigurationElement
+ .getAttribute(IODataEditorConstants.ARTIFACT_SELECTION_ATTRIBUTE_ID);
+ artifactSelectionOption[counter][0] = id;
+ plugin_id = iConfigurationElement.getContributor().getName();
+ artifactSelectionOption[counter++][1] = plugin_id;
+ }
+ }
+ return artifactSelectionOption;
+ }
+
+ public static void notifyRegisteredSubscribers( PictogramElement pe, EObject eo , SelectionStatus status){
+ String[][] selectionOptions = ODataArtifactSelectionUtil.getCurrentSelectionOption();
+ String contextMenuId = null;
+ if (selectionOptions .length > 0){
+ for (int i = 0; i < selectionOptions.length; i++) {
+ contextMenuId = selectionOptions[i][0];
+ IArtifactSelection artifactSelectionFeature = ODataArtifactSelectionUtil.getCurrentSelection(contextMenuId);
+ EnumSet<UIElementType> uiElementTypeSet = artifactSelectionFeature
+ .getApplicableElements();
+ if(uiElementTypeSet != null){
+ for (UIElementType uiElementType : uiElementTypeSet) {
+ if(isArtifactSelectedApplicable(uiElementType,eo) && status == SelectionStatus.SELECTED){
+ artifactSelectionFeature.setSelectedEObjectElement(eo);
+ artifactSelectionFeature.setSelectedPictogramElement(pe);
+ }
+ if(!isArtifactSelectedApplicable(uiElementType,eo) && status == SelectionStatus.SELECTED){
+ artifactSelectionFeature.setSelectedEObjectElement(null);
+ artifactSelectionFeature.setSelectedPictogramElement(null);
+ }
+ if(isArtifactSelectedApplicable(uiElementType,eo) && status == SelectionStatus.DELETED){
+ artifactSelectionFeature.setDeletedEObjectElement(eo);
+ artifactSelectionFeature.setDeletedPictogramElement(pe);
+ }
+ }
+ }
+
+
+ }
+ }
+
+ }
+
+ public static boolean isArtifactSelectedApplicable(UIElementType elementType , EObject elementEObject){
+ boolean isRequiredElement = false;
+ switch(elementType){
+ case ENTITY_TYPE:
+ isRequiredElement = (elementEObject instanceof EntityType) ? true : false;
+ break;
+ case ASSOCIATION:
+ isRequiredElement = (elementEObject instanceof Association) ? true : false;
+ break;
+ case COMPLEX_TYPE:
+ isRequiredElement = (elementEObject instanceof ComplexType) ? true : false;
+ break;
+ case FUNCTION_IMPORT:
+ isRequiredElement = (elementEObject instanceof FunctionImport) ? true : false;
+ break;
+ case ENTITY_SET:
+ isRequiredElement = (elementEObject instanceof EntitySet) ? true : false;
+ break;
+ default:
+ isRequiredElement = false;
+ }
+ return isRequiredElement ;
+
+ }
+
+}