Bug 575117 - Missing migration command for existing table from uml

Change-Id: Ic42dafcd78ba5f7342d52a4efe557a1fd8bcb27f
Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
diff --git a/plugins/gui/org.eclipse.papyrus.sysml16.architecture/src/org/eclipse/papyrus/sysml16/architecture/internal/UMLtoSyML16ModelConversionCommand.java b/plugins/gui/org.eclipse.papyrus.sysml16.architecture/src/org/eclipse/papyrus/sysml16/architecture/internal/UMLtoSyML16ModelConversionCommand.java
index d00c79a..068b6d4 100644
--- a/plugins/gui/org.eclipse.papyrus.sysml16.architecture/src/org/eclipse/papyrus/sysml16/architecture/internal/UMLtoSyML16ModelConversionCommand.java
+++ b/plugins/gui/org.eclipse.papyrus.sysml16.architecture/src/org/eclipse/papyrus/sysml16/architecture/internal/UMLtoSyML16ModelConversionCommand.java
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (c) 2019 CEA LIST, and others.
+ * Copyright (c) 2019, 2021 CEA LIST, and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
  *
  * Contributors:
  *   Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *   Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 575117
  *
  *****************************************************************************/
 
@@ -18,8 +19,11 @@
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
 import org.eclipse.emf.transaction.RollbackException;
 import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
 import org.eclipse.gmf.runtime.common.core.command.CommandResult;
@@ -29,9 +33,12 @@
 import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.papyrus.infra.architecture.commands.IModelConversionCommand;
 import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper;
 import org.eclipse.papyrus.infra.emf.gmf.util.GMFUnsafe;
 import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
 import org.eclipse.papyrus.infra.gmfdiag.style.PapyrusDiagramStyle;
+import org.eclipse.papyrus.infra.nattable.model.nattable.NattablePackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
 import org.eclipse.papyrus.sysml16.architecture.util.SysML16chitectureUtil;
 
 /**
@@ -41,19 +48,23 @@
 
 	/**
 	 * {@inheritDoc}
-	 * 
+	 *
 	 * @see org.eclipse.papyrus.infra.architecture.commands.IModelConversionCommand#convertModel(org.eclipse.papyrus.infra.core.resource.ModelSet)
 	 */
 	@Override
 	public void convertModel(final ModelSet modelSet) {
 		NotationModel model = (NotationModel) modelSet.getModel(NotationModel.MODEL_ID);
-		CompositeCommand compositeCommand = new CompositeCommand("Conversion to SysML 1.6 context");
+		CompositeCommand compositeCommand = new CompositeCommand("Conversion to SysML 1.6 context"); //$NON-NLS-1$
 		for (Resource current : model.getResources()) {
 			for (EObject element : current.getContents()) {
 				if (element instanceof Diagram) {
 					ICommand convertDiagram = convertDiagram((Diagram) element);
 					compositeCommand.add(convertDiagram);
 				}
+				if (element instanceof Table) {
+					ICommand convertDiagram = convertTable((Table) element, modelSet.getTransactionalEditingDomain());
+					compositeCommand.add(convertDiagram);
+				}
 			}
 		}
 
@@ -65,7 +76,39 @@
 	}
 
 	/**
-	 * Provide an ICommand for each diagram that need a conversion
+	 * Provide an ICommand for each table that needs a conversion
+	 *
+	 * @param element
+	 * @param domain
+	 * @return
+	 */
+	private ICommand convertTable(final Table element, final EditingDomain domain) {
+		Command command = null;
+		switch (element.getTableKindId()) {
+		case "org.eclipse.papyrus.uml.table.genericTree": //$NON-NLS-1$
+			command = SetCommand.create(domain, element, NattablePackage.eINSTANCE.getTable_TableKindId(), "org.eclipse.papyrus.sysml16.table.genericTree"); //$NON-NLS-1$
+			break;
+		case "org.eclipse.papyrus.uml.table.classTree": //$NON-NLS-1$
+			command = SetCommand.create(domain, element, NattablePackage.eINSTANCE.getTable_TableKindId(), "org.eclipse.papyrus.sysml16.table.classTree"); //$NON-NLS-1$
+			break;
+		case "org.eclipse.papyrus.uml.table.generic": //$NON-NLS-1$
+			command = SetCommand.create(domain, element, NattablePackage.eINSTANCE.getTable_TableKindId(), "org.eclipse.papyrus.sysml16.table.generic"); //$NON-NLS-1$
+			break;
+		case "org.eclipse.papyrus.uml.table.view": //$NON-NLS-1$
+			command = SetCommand.create(domain, element, NattablePackage.eINSTANCE.getTable_TableKindId(), "org.eclipse.papyrus.sysml16.table.view"); //$NON-NLS-1$
+			break;
+		case "org.eclipse.papyrus.uml.table.matrix": //$NON-NLS-1$
+			command = SetCommand.create(domain, element, NattablePackage.eINSTANCE.getTable_TableKindId(), "org.eclipse.papyrus.sysml16.table.matrix"); //$NON-NLS-1$
+			break;
+		default:
+			break;
+		}
+		return command != null ? EMFtoGMFCommandWrapper.wrap(command) : IdentityCommand.INSTANCE;
+	}
+
+	/**
+	 * Provide an ICommand for each diagram that needs a conversion
+	 *
 	 * @param diagram
 	 * @return
 	 */
@@ -74,13 +117,13 @@
 			if (object instanceof PapyrusDiagramStyle) {
 				switch (((PapyrusDiagramStyle) object).getDiagramKindId()) {
 				// FIXME: UML Representation kind ids should be provided by API core
-				case "org.eclipse.papyrus.uml.diagram.package":
+				case "org.eclipse.papyrus.uml.diagram.package": //$NON-NLS-1$
 					return new SetPapyrusDiagramStyleCommand(diagram, SysML16chitectureUtil.DIAGRAM_PACKAGE_ID);
-				case "org.eclipse.papyrus.uml.diagram.activity":
+				case "org.eclipse.papyrus.uml.diagram.activity": //$NON-NLS-1$
 					return new SetPapyrusDiagramStyleCommand(diagram, SysML16chitectureUtil.DIAGRAM_ACTIVITY_ID);
-				case "org.eclipse.papyrus.uml.diagram.stateMachine":
+				case "org.eclipse.papyrus.uml.diagram.stateMachine": //$NON-NLS-1$
 					return new SetPapyrusDiagramStyleCommand(diagram, SysML16chitectureUtil.DIAGRAM_STATE_MACHINE_ID);
-				case "org.eclipse.papyrus.uml.diagram.useCase":
+				case "org.eclipse.papyrus.uml.diagram.useCase": //$NON-NLS-1$
 					return new SetPapyrusDiagramStyleCommand(diagram, SysML16chitectureUtil.DIAGRAM_USE_CASE_ID);
 				default:// not conversion available
 					break;
@@ -92,7 +135,7 @@
 
 	///////////////////////////////////////////////////////////////////////////////
 	/**
-	 * FIXME: Should be provided as API by the core 
+	 * FIXME: Should be provided as API by the core
 	 * TODO: should be undoable
 	 * A command to set the diagram kind to a diagram
 	 */
@@ -102,7 +145,7 @@
 		private String diagramKind;
 
 		public SetPapyrusDiagramStyleCommand(Diagram diagram, String newStyle) {
-			super("Set new diagram kind for Papyrus Style");
+			super("Set new diagram kind for Papyrus Style"); //$NON-NLS-1$
 			this.diagram = diagram;
 			this.diagramKind = newStyle;
 		}