Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2016-05-19 12:21:40 -0400
committerGerrit Code Review @ Eclipse.org2016-08-04 07:45:27 -0400
commit1de8a09c355ba2a4ef37f547c9f33692a2e21ebc (patch)
treeb85b7d7c89d384b9fe79688cde3dd1f09479195a /plugins/developer/org.eclipse.papyrus.dev.types
parent4dff83585552fbbed4fb1433e694a3006fd8cca1 (diff)
downloadorg.eclipse.papyrus-1de8a09c355ba2a4ef37f547c9f33692a2e21ebc.tar.gz
org.eclipse.papyrus-1de8a09c355ba2a4ef37f547c9f33692a2e21ebc.tar.xz
org.eclipse.papyrus-1de8a09c355ba2a4ef37f547c9f33692a2e21ebc.zip
Bug 491783 - Change the ElementTypeConfiguration metamodel to make the
before and after reference directly AdviceConfigurations. Change the interpretation accordingly. Bug 497481 - Change the ElementTypeConfiguration metamodel to replace string-based references to specialization by Ereferences in SpecializationTypeConfiguration. Change the interpretation accordingly. Update oep.infra.types.doc accordingly. Change-Id: I13284a6a74fe3d86427b19424a9b8c4caed01d89
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.dev.types')
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.types/META-INF/MANIFEST.MF2
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.types/plugin.xml29
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/handlers/MigrateSpecializations.java266
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java2
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java62
5 files changed, 359 insertions, 2 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/META-INF/MANIFEST.MF b/plugins/developer/org.eclipse.papyrus.dev.types/META-INF/MANIFEST.MF
index 5ee30eec196..073c7e32dcc 100644
--- a/plugins/developer/org.eclipse.papyrus.dev.types/META-INF/MANIFEST.MF
+++ b/plugins/developer/org.eclipse.papyrus.dev.types/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Require-Bundle: org.eclipse.ui;bundle-version="[3.107.0,4.0.0)",
org.eclipse.uml2.uml;bundle-version="[5.2.0,6.0.0)",
- org.eclipse.papyrus.infra.types.core;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.infra.types.core;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.services.edit;bundle-version="[2.0.0,3.0.0)",
org.eclipse.gmf.codegen;bundle-version="[2.11.0,3.0.0)",
org.eclipse.xtend.lib;bundle-version="[2.10.0,3.0.0)",
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/plugin.xml b/plugins/developer/org.eclipse.papyrus.dev.types/plugin.xml
index a591e0bb35c..72f6f9d8c22 100644
--- a/plugins/developer/org.eclipse.papyrus.dev.types/plugin.xml
+++ b/plugins/developer/org.eclipse.papyrus.dev.types/plugin.xml
@@ -55,6 +55,30 @@
</visibleWhen>
</command>
</menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <command
+ commandId="org.eclipse.papyrus.infra.dev.types.commands.migrateSpecializations"
+ id="org.eclipse.papyrus.infra.dev.types.menus.migrateSpecializations"
+ label="Migrate Specializations"
+ mnemonic="S"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <adapt
+ type="org.eclipse.core.resources.IFile">
+ </adapt>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
</extension>
<extension
@@ -69,6 +93,11 @@
id="org.eclipse.papyrus.infra.dev.types.commands.generateElementTypesRegistry"
name="Generate ElementTypes Registry">
</command>
+ <command
+ defaultHandler="org.eclipse.papyrus.dev.types.handlers.MigrateSpecializations"
+ id="org.eclipse.papyrus.infra.dev.types.commands.migrateSpecializations"
+ name="Migrate Specializations">
+ </command>
</extension>
<extension
point="org.eclipse.ui.views">
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/handlers/MigrateSpecializations.java b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/handlers/MigrateSpecializations.java
new file mode 100644
index 00000000000..9ebedb73a51
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/handlers/MigrateSpecializations.java
@@ -0,0 +1,266 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.dev.types.handlers;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class MigrateSpecializations extends AbstractHandler {
+ final String FILE_EXTENSION = "elementtypesconfigurations";
+
+ final String TYPE_ATTRIBUTE = "xsi:type";
+ final String NAME_ATTRIBUTE = "name";
+ final String IDENTIFIER_ATTRIBUTE = "identifier";
+ final String ELEMENTTYPECONFIGURATION_NAMESPACE_ATTRIBUTE = "xmlns:elementtypesconfigurations";
+ final String ELEMENTTYPECONFIGURATION_NAMESPACE_OLD = "http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.1";
+ final String ELEMENTTYPECONFIGURATION_NAMESPACE_NEW = "http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2";
+
+ final String ELEMENTTYPECONFIGURATIONS = "elementTypeConfigurations";
+ final String ELEMENTTYPESCONFIGURATIONS_SPECIALIZATIONTYPECONFIGURATION = "elementtypesconfigurations:SpecializationTypeConfiguration";
+ final String SPECIALIZEDTYPESID_ATTRIBUTE = "specializedTypesID";
+ final String SPECIALIZEDTYPES_ATTRIBUTE = "specializedTypes";
+ final String HREF_ATTRIBUTE = "href";
+
+ final String ELEMENTTYPESCONFIGURATIONS_METAMODELTYPECONFIGURATION = "elementtypesconfigurations:MetamodelTypeConfiguration";
+
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+
+
+
+ Map<String, String> mapSpecializationMigration = new HashMap<>();
+ Map<String, String> mapMetamodelMigration = new HashMap<>();
+
+
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+ if (!(currentSelection instanceof IStructuredSelection) || currentSelection.isEmpty()) {
+ return null;
+ }
+
+ final IStructuredSelection selection = (IStructuredSelection) currentSelection;
+
+ Iterator<?> it = selection.iterator();
+
+ while (it.hasNext()) {
+ Object selectedElement = (Object) it.next();
+
+ if (selectedElement instanceof IFile) {
+ if (FILE_EXTENSION.equals(((IFile) selectedElement).getFileExtension())) {
+ IFile selectedFile = ((IFile) selectedElement);
+ URI uri = selectedFile.getLocationURI();
+
+
+ if (selectedFile.isLinked()) {
+ uri = selectedFile.getRawLocationURI();
+ }
+
+ try {
+ File file = EFS.getStore(uri).toLocalFile(0, new NullProgressMonitor());
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(file);
+ Element root = doc.getDocumentElement();
+
+ NodeList elementTypeConfigurations = root.getElementsByTagName(ELEMENTTYPECONFIGURATIONS);
+
+ for (int i = 0; i < elementTypeConfigurations.getLength(); i++) {
+ Element elementTypeConfiguration = (Element) elementTypeConfigurations.item(i);
+
+ Node identifierAttrib = elementTypeConfiguration.getAttributes().getNamedItem(IDENTIFIER_ATTRIBUTE);
+
+ Node xmiid = elementTypeConfiguration.getAttributes().getNamedItem("xmi:id");
+
+ Node type = elementTypeConfiguration.getAttributes().getNamedItem(TYPE_ATTRIBUTE);
+
+ if (type.getNodeValue().equals(ELEMENTTYPESCONFIGURATIONS_SPECIALIZATIONTYPECONFIGURATION)) {
+ mapSpecializationMigration.put(identifierAttrib.getNodeValue(), "platform:/plugin" + selectedFile.getFullPath().toString() + "#" + xmiid.getNodeValue());
+ } else {
+ mapMetamodelMigration.put(identifierAttrib.getNodeValue(), "platform:/plugin" + selectedFile.getFullPath().toString() + "#" + xmiid.getNodeValue());
+ }
+
+ }
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+ }
+
+ it = selection.iterator();
+
+ while (it.hasNext()) {
+ Object selectedElement = (Object) it.next();
+
+ if (selectedElement instanceof IFile) {
+ if (FILE_EXTENSION.equals(((IFile) selectedElement).getFileExtension())) {
+ IFile selectedFile = ((IFile) selectedElement);
+ URI uri = selectedFile.getLocationURI();
+
+ if (selectedFile.isLinked()) {
+ uri = selectedFile.getRawLocationURI();
+ }
+
+ try {
+ File file = EFS.getStore(uri).toLocalFile(0, new NullProgressMonitor());
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(file);
+ Element root = doc.getDocumentElement();
+
+ // Update namespaces
+ root.setAttribute(ELEMENTTYPECONFIGURATION_NAMESPACE_ATTRIBUTE, ELEMENTTYPECONFIGURATION_NAMESPACE_NEW);
+
+ NodeList elementTypeConfigurations = root.getElementsByTagName(ELEMENTTYPECONFIGURATIONS);
+
+ for (int i = 0; i < elementTypeConfigurations.getLength(); i++) {
+ Element elementTypeConfiguration = (Element) elementTypeConfigurations.item(i);
+
+ // Node type = elementTypeConfiguration.getAttributes().getNamedItem(TYPE_ATTRIBUTE);
+
+ // if (type.getNodeValue().equals(ELEMENTTYPESCONFIGURATIONS_SPECIALIZATIONTYPECONFIGURATION)) {
+ NodeList children = elementTypeConfiguration.getChildNodes();
+
+ ArrayList<String> specializedIDs = new ArrayList<String>();
+ ArrayList<Node> childToRemove = new ArrayList<Node>();
+ for (int j = 0; j < children.getLength(); j++) {
+
+ Node child = children.item(j);
+ if (child instanceof Element) {
+ if (child.getNodeName().equals(SPECIALIZEDTYPESID_ATTRIBUTE)) {
+ String specialized = ((Element) child).getFirstChild().getNodeValue();
+ specializedIDs.add(specialized);
+ childToRemove.add(child);
+ }
+ }
+ }
+
+ for (Node node : childToRemove) {
+ elementTypeConfiguration.removeChild(node);
+ }
+
+ for (String specialized : specializedIDs) {
+ Element specializedTypes = doc.createElement(SPECIALIZEDTYPES_ATTRIBUTE);
+
+ if (mapMetamodelMigration.containsKey(specialized)) {
+ specializedTypes.setAttribute(TYPE_ATTRIBUTE, ELEMENTTYPESCONFIGURATIONS_METAMODELTYPECONFIGURATION);
+ specializedTypes.setAttribute(HREF_ATTRIBUTE, mapMetamodelMigration.get(specialized));
+ elementTypeConfiguration.appendChild(specializedTypes);
+ } else if (mapSpecializationMigration.containsKey(specialized)) {
+ specializedTypes.setAttribute(TYPE_ATTRIBUTE, ELEMENTTYPESCONFIGURATIONS_SPECIALIZATIONTYPECONFIGURATION);
+ specializedTypes.setAttribute(HREF_ATTRIBUTE, mapSpecializationMigration.get(specialized));
+ elementTypeConfiguration.appendChild(specializedTypes);
+ } else {
+ System.err.println("Couldn't find : " + specialized);
+ }
+
+
+ }
+ // }
+ }
+
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+ Result output = new StreamResult(file);
+ Source input = new DOMSource(doc);
+
+ transformer.transform(input, output);
+
+
+ selectedFile.touch(new NullProgressMonitor());
+
+
+
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (TransformerConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (TransformerFactoryConfigurationError e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (TransformerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ return null;
+ }
+
+
+
+
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java
index 18829a02018..29c7ab425aa 100644
--- a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java
+++ b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java
@@ -136,7 +136,7 @@ public class ElementTypesDetailsContentProvider implements ITreeContentProvider
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof List<?>) {
- Collections.sort((List<IEditHelperAdvice>) parentElement, new AdviceComparator(contextID));
+ Collections.sort((List<IEditHelperAdvice>) parentElement, new AdviceComparator(ElementTypeRegistry.getInstance().getType(typeID), contextID));
return ((List<?>) parentElement).toArray();
}
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java
index 627b3b86471..da3a26356ae 100644
--- a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java
+++ b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java
@@ -12,13 +12,20 @@
*****************************************************************************/
package org.eclipse.papyrus.dev.types.view;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.eclipse.gmf.runtime.emf.type.core.ClientContextManager;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -26,14 +33,20 @@ import org.eclipse.papyrus.dev.types.providers.ElementTypesContentProvider;
import org.eclipse.papyrus.dev.types.providers.ElementTypesDetailsContentProvider;
import org.eclipse.papyrus.dev.types.providers.ElementTypesDetailsLabelProvider;
import org.eclipse.papyrus.dev.types.providers.ElementTypesLabelProvider;
+import org.eclipse.papyrus.infra.types.core.utils.AdviceComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.eclipse.ui.part.ViewPart;
@@ -96,6 +109,55 @@ public class RegistredElementTypesView extends ViewPart {
}
});
+ Button exportButton = new Button(parent, SWT.NONE);
+ exportButton.setText("Export registry");
+ exportButton.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
+ String dest = dialog.open();
+ if (dest != null) {
+ File file = new File(dest);
+ if (file != null) {
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(file));
+
+ for (String clientContexId : itemsList) {
+ writer.write(clientContexId + "\n");
+ IElementType[] elementTypes = ElementTypeRegistry.getInstance().getElementTypes(ClientContextManager.getInstance().getClientContext(clientContexId));
+ for (int j = 0; j < elementTypes.length; j++) {
+ IElementType elementType = elementTypes[j];
+ writer.write("\t" + elementType.getId() + "\n");
+
+
+ IEditHelperAdvice[] advices = ElementTypeRegistry.getInstance().getEditHelperAdvice(elementType);
+ List<IEditHelperAdvice> advicesList = Arrays.asList(advices);
+ Collections.sort(advicesList, new AdviceComparator(elementType, clientContexId));
+ for (IEditHelperAdvice advice : advicesList) {
+ writer.write("\t\t" + advice.getClass().getName() + "\n");
+ }
+ }
+ }
+
+ writer.flush();
+
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ } finally {
+ try {
+ writer.close();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ }
+ }
+ }
+ });
+
sash = new SashForm(parent, SWT.HORIZONTAL);
sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Back to the top