From 1de8a09c355ba2a4ef37f547c9f33692a2e21ebc Mon Sep 17 00:00:00 2001 From: Florian Noyrit Date: Thu, 19 May 2016 18:21:40 +0200 Subject: 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 --- .../META-INF/MANIFEST.MF | 2 +- .../org.eclipse.papyrus.dev.types/plugin.xml | 29 +++ .../dev/types/handlers/MigrateSpecializations.java | 266 +++++++++++++++++++++ .../ElementTypesDetailsContentProvider.java | 2 +- .../dev/types/view/RegistredElementTypesView.java | 62 +++++ 5 files changed, 359 insertions(+), 2 deletions(-) create mode 100644 plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/handlers/MigrateSpecializations.java (limited to 'plugins/developer/org.eclipse.papyrus.dev.types') 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 @@ -54,6 +54,30 @@ + + + + + + + + + + + + @@ -68,6 +92,11 @@ defaultHandler="org.eclipse.papyrus.dev.types.handlers.GenerateElementTypesRegistry" id="org.eclipse.papyrus.infra.dev.types.commands.generateElementTypesRegistry" name="Generate ElementTypes Registry"> + + mapSpecializationMigration = new HashMap<>(); + Map 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 specializedIDs = new ArrayList(); + ArrayList childToRemove = new ArrayList(); + 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) parentElement, new AdviceComparator(contextID)); + Collections.sort((List) 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 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)); -- cgit v1.2.3