Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2015-02-12 08:13:19 -0500
committerGabriel Pascual2015-02-13 08:01:37 -0500
commit8d669e43dfda285d328ba6324cd601eb99ae91eb (patch)
treef617aad8e4104a5fe4ddca60de92c5a7205ee5e2
parent88586d4986afc80be8ec4cec06e51dd3f69263b9 (diff)
downloadorg.eclipse.papyrus-8d669e43dfda285d328ba6324cd601eb99ae91eb.tar.gz
org.eclipse.papyrus-8d669e43dfda285d328ba6324cd601eb99ae91eb.tar.xz
org.eclipse.papyrus-8d669e43dfda285d328ba6324cd601eb99ae91eb.zip
Bug 459702: [Control Mode] Do not create private/local user info in
imported models/submodels https://bugs.eclipse.org/bugs/show_bug.cgi?id=459702 - Fix Di Model participant for Control Mode - Complete tests Change-Id: Ib171a4e4a353afb80bda1e9995b0103e8d73f3ae Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml2
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/CleanSashCommand.java90
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java272
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/DiControlParticipant.java (renamed from plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/SashControlParticipant.java)287
-rw-r--r--tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/META-INF/MANIFEST.MF51
-rw-r--r--tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.di20
-rw-r--r--tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.notation105
-rw-r--r--tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.uml7
-rw-r--r--tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/AllTests.java58
-rw-r--r--tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlLegacyModelTest.java158
-rw-r--r--tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlModelTest.java37
11 files changed, 789 insertions, 298 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
index 0526c9d6e5c..6fd05206917 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
@@ -15,7 +15,7 @@
<extension
point="org.eclipse.papyrus.infra.services.controlmode.participant">
<participant
- class="org.eclipse.papyrus.infra.services.controlmode.participants.SashControlParticipant">
+ class="org.eclipse.papyrus.infra.services.controlmode.participants.DiControlParticipant">
</participant>
</extension>
<extension
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/CleanSashCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/CleanSashCommand.java
new file mode 100644
index 00000000000..39ad1a425a6
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/CleanSashCommand.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * 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
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4te.net - Bug 459702
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.controlmode.commands;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.core.sashwindows.di.util.DiUtils;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
+
+/**
+ * Command to clean all traces of Sash model.
+ */
+public class CleanSashCommand extends AbstractControlCommand {
+
+ /** The Constant SASH_CLEAN_COMMAND_LABEL. */
+ static final String SASH_CLEAN_COMMAND_LABEL = "Clear di command";
+
+ /** The Constant MODEL_SET_ERROR_MESSAGE. */
+ static final String MODEL_SET_ERROR_MESSAGE = "Unable to retrieve resource set";
+
+ /** The Constant OLD_DI_MESSAGE_ERROR. */
+ static final String OLD_DI_MESSAGE_ERROR = "Unable to retrieve old di resource";
+
+ /**
+ * Instantiates a new clean sash command.
+ *
+ * @param affectedFiles
+ * the affected files
+ * @param request
+ * the request
+ */
+ public CleanSashCommand(@SuppressWarnings("rawtypes") List affectedFiles, ControlModeRequest request) {
+ super(SASH_CLEAN_COMMAND_LABEL, affectedFiles, request);
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ ModelSet modelSet = getRequest().getModelSet();
+ if (modelSet == null) {
+ return CommandResult.newErrorCommandResult(MODEL_SET_ERROR_MESSAGE);
+ }
+
+ // This is the Sash model which determines the model file extension cause of different possible mode (Legacy or standard)
+ Resource oldDiresource = modelSet.getAssociatedResource(getRequest().getTargetObject(), DiModel.DI_FILE_EXTENSION, true);
+ if (oldDiresource == null) {
+ return CommandResult.newErrorCommandResult(OLD_DI_MESSAGE_ERROR);
+ }
+
+ if (DiUtils.lookupSashWindowsMngr(oldDiresource) != null) {
+ // Case : legacy
+ oldDiresource.getContents().clear();
+ } else {
+ // Case : Standard
+ SashModel sashModel = SashModelUtils.getSashModel(modelSet);
+ sashModel.loadModel(oldDiresource.getURI().trimFileExtension());
+ modelSet.getResourcesToDeleteOnSave().add(SashModelUtils.getSashModel(modelSet).getResourceURI());
+ }
+
+ return CommandResult.newOKCommandResult();
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java
index ba30173a2c6..f814a95731b 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java
@@ -1,111 +1,161 @@
-/*****************************************************************************
- * Copyright (c) 2012 Atos.
- *
- *
- * 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:
- * Tristan FAURE (Atos) tristan.faure@atos.net- Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.controlmode.commands;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
-import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
-import org.eclipse.papyrus.infra.core.sashwindows.di.SashModel;
-import org.eclipse.papyrus.infra.core.sashwindows.di.SashWindowsMngr;
-import org.eclipse.papyrus.infra.core.sashwindows.di.exception.SashEditorException;
-import org.eclipse.papyrus.infra.core.sashwindows.di.util.DiUtils;
-import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
-import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequestParameters;
-
-/**
- * Initialize the di resource with all necessary informations
- * ex : Page Ref
- *
- * @author adaussy
- *
- */
-public class InitializeSashCommand extends AbstractControlCommand {
-
- /**
- * @param request
- */
- public InitializeSashCommand(ControlModeRequest request) {
- super("Initialize sash model", null, request);
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- /*
- * Get from the request tab and diagrams being moved
- */
- Collection<EObject> openables = getMovedOpenablesFromRequest();
- try {
- SashWindowsMngr sashMng = createSashWindowsMngr(openables);
- Resource diResource = getDiResource();
- if (diResource == null) {
- return CommandResult.newErrorCommandResult("Unable to find DI resource");
- }
- diResource.getContents().add(sashMng);
- } catch (SashEditorException e) {
- e.printStackTrace();
- return CommandResult.newErrorCommandResult(e);
- }
- return CommandResult.newOKCommandResult();
- }
-
- /**
- * @return tables being moved from the request
- */
- @SuppressWarnings("unchecked")
- protected Collection<EObject> getMovedOpenablesFromRequest() {
- Collection<EObject> tabs = (Collection<EObject>) getRequest().getParameter(ControlModeRequestParameters.MOVED_OPENABLES);
- if (tabs == null) {
- return new ArrayList<EObject>();
- }
- return tabs;
- }
-
- /**
- * @return retrieve the di resource from the request
- */
- protected Resource getDiResource() {
- return getRequest().getTargetResource(org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel.MODEL_FILE_EXTENSION);
- }
-
- /**
- * Create a new {@link SashModel} and add page ref for each diagrams and tables being controlled
- *
- * @param openables
- * @return
- * @throws SashEditorException
- */
- protected SashWindowsMngr createSashWindowsMngr(Collection<EObject> openables) throws SashEditorException {
- // Create a new SashWindowManager
- SashWindowsMngr windowsMngr = DiUtils.createDefaultSashWindowsMngr();
- Resource diResource = SashModelUtils.getSashModel(getRequest().getModelSet()).getResource();
- // add pages to the page list
- for (EObject openable : openables) {
- PageRef pageRef = DiUtils.getPageRef(diResource, openable);
- if (pageRef != null) {
- // windowsMngr.getPageList().addPage(pageRef.getPageIdentifier()); //The page list is not used anymore
- DiUtils.addPageToTabFolder(windowsMngr, pageRef);
- }
- }
- return windowsMngr;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013,2015 Atos, 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:
+ * Arthur Daussy (Atos) arthur.daussy@atos.net- Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 459702
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.controlmode.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashModel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashWindowsMngr;
+import org.eclipse.papyrus.infra.core.sashwindows.di.exception.SashEditorException;
+import org.eclipse.papyrus.infra.core.sashwindows.di.util.DiUtils;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModePlugin;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequestParameters;
+
+/**
+ * Initialise a correct Sash Model in the right location. Two case:
+ * <dl>
+ * <dt>Legacy</dt>
+ * <dd>The sash model must written in Di file.</dd>
+ * <dt>Standard</dt>
+ * <dd>Since Luna, the Sash Model must be inserted in its own workspace's resource.</dd>
+ * </dl>
+ *
+ * @author adaussy
+ *
+ */
+public class InitializeSashCommand extends AbstractControlCommand {
+
+ /** The Constant SASH_RESOURCE_ERROR. */
+ private static final String SASH_RESOURCE_ERROR = "Unable to find Sash resource";
+
+ /** The Constant SASH_COMMAND_TITLE. */
+ private static final String SASH_COMMAND_TITLE = "Initialize Sash model";
+
+ /**
+ * Instantiates a new initialize sash command.
+ *
+ * @param request
+ * the request
+ */
+ public InitializeSashCommand(ControlModeRequest request) {
+ super(SASH_COMMAND_TITLE, null, request);
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ /*
+ * Get from the request tab and diagrams being moved
+ */
+ Collection<EObject> openables = getMovedOpenablesFromRequest();
+ try {
+ SashWindowsMngr sashMng = createSashWindowsMngr(openables);
+ Resource sashResourceResource = getSashResource();
+
+
+ if (sashResourceResource == null) {
+ return CommandResult.newErrorCommandResult(SASH_RESOURCE_ERROR);
+ }
+ sashResourceResource.getContents().add(sashMng);
+ } catch (SashEditorException e) {
+ ControlModePlugin.log.error(e);
+ return CommandResult.newErrorCommandResult(e);
+ } catch (ServiceException e) {
+ ControlModePlugin.log.error(e);
+ return CommandResult.newErrorCommandResult(e);
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ * Gets the moved openables from request.
+ *
+ * @return tables being moved from the request
+ */
+ @SuppressWarnings("unchecked")
+ protected Collection<EObject> getMovedOpenablesFromRequest() {
+ Collection<EObject> tabs = (Collection<EObject>) getRequest().getParameter(ControlModeRequestParameters.MOVED_OPENABLES);
+ if (tabs == null) {
+ return new ArrayList<EObject>();
+ }
+ return tabs;
+ }
+
+ /**
+ * Gets the sash resource.
+ *
+ * @return retrieve the di resource from the request
+ * @throws ServiceException
+ */
+ protected Resource getSashResource() throws ServiceException {
+
+ org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel sashModel = SashModelUtils.getSashModel(request.getModelSet());
+ Resource sashResource = request.getTargetResource(DiModel.MODEL_FILE_EXTENSION);
+
+ // Check if the Sash resource is not Legacy format
+ if (org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel.SASH_MODEL_FILE_EXTENSION.equals(sashModel.getResourceURI().fileExtension())) {
+
+ // Load Sash resource
+ URI targetUri = sashResource.getURI().trimFileExtension();
+ sashModel.loadModel(targetUri);
+ sashResource = SashModelUtils.getSashModel(request.getModelSet()).getResource();
+ }
+
+ return sashResource;
+ }
+
+ /**
+ * Create a new {@link SashModel} and add page ref for each diagrams and tables being controlled
+ *
+ * @param openables
+ * @return
+ * @throws SashEditorException
+ * @throws ServiceException
+ */
+ protected SashWindowsMngr createSashWindowsMngr(Collection<EObject> openables) throws SashEditorException, ServiceException {
+
+ // Create a new SashWindowManager
+ SashWindowsMngr windowsMngr = DiUtils.createDefaultSashWindowsMngr();
+ IPageManager pageManager = ServiceUtilsForResourceSet.getInstance().getIPageManager(request.getModelSet());
+
+ // Complete SashWindow Manager filling the default TabFolder with opened diagram
+ for (EObject openable : openables) {
+ if (pageManager.isOpen(openable)) {
+ windowsMngr.getSashModel().addPage(windowsMngr.getSashModel().getCurrentSelection(), openable);
+ }
+ }
+
+ return windowsMngr;
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/SashControlParticipant.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/DiControlParticipant.java
index bd76fb24aba..a831269363f 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/SashControlParticipant.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/DiControlParticipant.java
@@ -1,129 +1,158 @@
-/*******************************************************************************
- * Copyright (c) 2013 Atos.
- * 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:
- * Arthur Daussy <a href="mailto:arthur.daussy@atos.net"> - initial API and implementation
- ******************************************************************************/
-package org.eclipse.papyrus.infra.services.controlmode.participants;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
-import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
-import org.eclipse.papyrus.infra.services.controlmode.commands.AbstractControlCommand;
-import org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource;
-import org.eclipse.papyrus.infra.services.controlmode.commands.InitializeSashCommand;
-import org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand;
-
-
-/**
- * Control participant in charge of controling the di resources.
- * It move page ref to control resources
- *
- * @author adaussy
- *
- */
-public class SashControlParticipant implements IControlCommandParticipant, IUncontrolCommandParticipant {
-
- public String getID() {
- return "org.eclipse.papyrus.infra.services.controlmode.participants.SashControlParticipant";//
- }
-
- public int getPriority() {
- return 80;
- }
-
- public boolean provideControlCommand(ControlModeRequest request) {
- EObject objectBeingControl = request.getTargetObject();
- return objectBeingControl != null;
- }
-
- public ICommand getPreControlCommand(ControlModeRequest request) {
- return new CreateControlResource(request, SashModel.MODEL_FILE_EXTENSION);
- }
-
- public ICommand getPostControlCommand(ControlModeRequest request) {
- return new InitializeSashCommand(request);
- }
-
- public boolean provideUnControlCommand(ControlModeRequest request) {
- EObject objectBeingControl = request.getTargetObject();
- return objectBeingControl != null;
- }
-
- public ICommand getPreUncontrolCommand(ControlModeRequest request) {
- boolean result = setDiTargetRequest(request);
- if (result) {
- return getClearDiCommand(request);
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- protected ICommand getClearDiCommand(final ControlModeRequest request) {
- ModelSet modelSet = request.getModelSet();
- IFile affectedFiles = WorkspaceSynchronizer.getFile(modelSet.getAssociatedResource(request.getTargetObject(), SashModel.MODEL_FILE_EXTENSION, true));
- return new ClearDiCommand(Collections.singletonList(affectedFiles), request);
- }
-
- public class ClearDiCommand extends AbstractControlCommand {
-
- public ClearDiCommand(@SuppressWarnings("rawtypes") List affectedFiles, ControlModeRequest request) {
- super("Clear di command", affectedFiles, request);
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- ModelSet modelSet = getRequest().getModelSet();
- if (modelSet == null) {
- return CommandResult.newErrorCommandResult("Unable to retrieve resource set");
- }
- Resource oldDiresource = modelSet.getAssociatedResource(getRequest().getTargetObject(), SashModel.MODEL_FILE_EXTENSION, true);
- if (oldDiresource == null) {
- return CommandResult.newErrorCommandResult("Unable to retrieve old di resource");
- }
- oldDiresource.getContents().clear();
- return CommandResult.newOKCommandResult();
- }
- }
-
- protected boolean setDiTargetRequest(ControlModeRequest request) {
- URI diURI = request.getNewURI().trimFileExtension().appendFileExtension(SashModel.MODEL_FILE_EXTENSION);
- ModelSet modelSet = request.getModelSet();
- if (modelSet != null) {
- Resource diResource = null;
- try {
- diResource = modelSet.getResource(diURI, true);
- } catch (Exception e) {
- diResource = null;
- }
- if (diResource == null) {
- return false;
- }
- request.setTargetResource(diResource, SashModel.MODEL_FILE_EXTENSION);
- // Nothing to do but everything is ok
- return true;
- }
- return false;
- }
-
- public ICommand getPostUncontrolCommand(ControlModeRequest request) {
- return new RemoveControlResourceCommand(request, SashModel.MODEL_FILE_EXTENSION);
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Atos, 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:
+ * Arthur Daussy <a href="mailto:arthur.daussy@atos.net"> - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 459702
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.services.controlmode.participants;
+
+import java.util.Collections;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
+import org.eclipse.papyrus.infra.services.controlmode.commands.CleanSashCommand;
+import org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource;
+import org.eclipse.papyrus.infra.services.controlmode.commands.InitializeSashCommand;
+import org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand;
+
+
+/**
+ * Control participant in charge of controling the di resources.
+ * It move page ref to control resources
+ *
+ * @author adaussy
+ *
+ */
+public class DiControlParticipant implements IControlCommandParticipant, IUncontrolCommandParticipant {
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getID()
+ *
+ * @return
+ */
+ public String getID() {
+ return "org.eclipse.papyrus.infra.services.controlmode.participants.SashControlParticipant"; //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getPriority()
+ *
+ * @return
+ */
+ public int getPriority() {
+ return 80;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#provideControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest)
+ *
+ * @param request
+ * @return
+ */
+ public boolean provideControlCommand(ControlModeRequest request) {
+ EObject objectBeingControl = request.getTargetObject();
+ return objectBeingControl != null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#getPreControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest)
+ *
+ * @param request
+ * @return
+ */
+ public ICommand getPreControlCommand(ControlModeRequest request) {
+ return new CreateControlResource(request, DiModel.DI_FILE_EXTENSION);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#getPostControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest)
+ *
+ * @param request
+ * @return
+ */
+ public ICommand getPostControlCommand(ControlModeRequest request) {
+ return new InitializeSashCommand(request);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#provideUnControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest)
+ *
+ * @param request
+ * @return
+ */
+ public boolean provideUnControlCommand(ControlModeRequest request) {
+ EObject objectBeingControl = request.getTargetObject();
+ return objectBeingControl != null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#getPreUncontrolCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest)
+ *
+ * @param request
+ * @return
+ */
+ public ICommand getPreUncontrolCommand(ControlModeRequest request) {
+ boolean result = setDiTargetRequest(request);
+ if (result) {
+ return getClearDiCommand(request);
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ protected ICommand getClearDiCommand(final ControlModeRequest request) {
+ ModelSet modelSet = request.getModelSet();
+ IFile affectedFiles = WorkspaceSynchronizer.getFile(modelSet.getAssociatedResource(request.getTargetObject(), DiModel.DI_FILE_EXTENSION, true));
+ return new CleanSashCommand(Collections.singletonList(affectedFiles), request);
+ }
+
+ /**
+ * Sets the Di target request.
+ *
+ * @param request
+ * the request
+ * @return true, if successful
+ */
+ protected boolean setDiTargetRequest(ControlModeRequest request) {
+ boolean sucessful = false;
+
+ // Retrieve target Di resource URI
+ URI diURI = request.getNewURI().trimFileExtension().appendFileExtension(DiModel.DI_FILE_EXTENSION);
+ ModelSet modelSet = request.getModelSet();
+
+ if (modelSet != null) {
+
+ // Try to load target Di resource with Model Set
+ Resource diResource = null;
+ try {
+ diResource = modelSet.getResource(diURI, true);
+ } catch (Exception e) {
+ diResource = null;
+ }
+
+ sucessful = diResource != null;
+ if (sucessful) {
+ request.setTargetResource(diResource, DiModel.DI_FILE_EXTENSION);
+ }
+ }
+
+ return sucessful;
+ }
+
+ public ICommand getPostUncontrolCommand(ControlModeRequest request) {
+ return new RemoveControlResourceCommand(request, DiModel.DI_FILE_EXTENSION);
+ }
+}
diff --git a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/META-INF/MANIFEST.MF
index 378243688b8..1998ee2295e 100644
--- a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/META-INF/MANIFEST.MF
@@ -1,25 +1,26 @@
-Manifest-Version: 1.0
-Require-Bundle: org.eclipse.ui;bundle-version="3.106.0",
- org.junit;bundle-version="4.11.0",
- org.eclipse.papyrus.junit.framework;bundle-version="1.0.2",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.2",
- org.eclipse.papyrus.infra.services.controlmode;bundle-version="1.0.2",
- org.eclipse.papyrus.infra.core;bundle-version="1.0.2",
- org.eclipse.papyrus.views.modelexplorer;bundle-version="1.0.2",
- org.eclipse.uml2.uml;bundle-version="5.0.0",
- org.eclipse.swtbot.eclipse.finder;bundle-version="2.2.1",
- org.eclipse.swtbot.junit4_x;bundle-version="2.2.1",
- org.eclipse.emf.transaction,
- org.eclipse.papyrus.infra.services.resourceloading.preferences;bundle-version="1.0.2",
- org.eclipse.papyrus.junit.utils;bundle-version="1.0.2"
-Export-Package: org.eclipse.papyrus.infra.services.controlmode.tests,
- org.eclipse.papyrus.infra.services.controlmode.tests.control,
- org.eclipse.papyrus.infra.services.controlmode.tests.uncontrol
-Bundle-Vendor: %Bundle-Vendor
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.0.2.qualifier
-Bundle-Name: %Bundle-Name
-Bundle-ManifestVersion: 2
-Bundle-Activator: org.eclipse.papyrus.infra.services.controlmode.tests.control.Activator
-Bundle-SymbolicName: org.eclipse.papyrus.infra.services.controlmode.tests
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui;bundle-version="3.106.0",
+ org.junit;bundle-version="4.11.0",
+ org.eclipse.papyrus.junit.framework;bundle-version="1.0.2",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.2",
+ org.eclipse.papyrus.infra.services.controlmode;bundle-version="1.0.2",
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.2",
+ org.eclipse.papyrus.views.modelexplorer;bundle-version="1.0.2",
+ org.eclipse.uml2.uml;bundle-version="5.0.0",
+ org.eclipse.swtbot.eclipse.finder;bundle-version="2.2.1",
+ org.eclipse.swtbot.junit4_x;bundle-version="2.2.1",
+ org.eclipse.emf.transaction,
+ org.eclipse.papyrus.infra.services.resourceloading.preferences;bundle-version="1.0.2",
+ org.eclipse.papyrus.junit.utils;bundle-version="1.0.2",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.2"
+Export-Package: org.eclipse.papyrus.infra.services.controlmode.tests,
+ org.eclipse.papyrus.infra.services.controlmode.tests.control,
+ org.eclipse.papyrus.infra.services.controlmode.tests.uncontrol
+Bundle-Vendor: %Bundle-Vendor
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.0.2.qualifier
+Bundle-Name: %Bundle-Name
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.infra.services.controlmode.tests.control.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.infra.services.controlmode.tests
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.di b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.di
new file mode 100644
index 00000000000..46f21577901
--- /dev/null
+++ b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.di
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<di:SashWindowsMngr xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.eclipse.org/papyrus/0.7.0/sashdi">
+ <pageList>
+ <availablePage>
+ <emfPageIdentifier href="model.notation#_ld92QLLMEeSdSv3eJr1O_w"/>
+ </availablePage>
+ </pageList>
+ <sashModel currentSelection="//@sashModel/@windows.0/@children.0">
+ <windows>
+ <children xsi:type="di:TabFolder">
+ <children>
+ <emfPageIdentifier href="model.notation#_ld92QLLMEeSdSv3eJr1O_w"/>
+ </children>
+ <children>
+ <emfPageIdentifier href="model.notation#_k8kVMLLTEeSrOcSd47uy1Q"/>
+ </children>
+ </children>
+ </windows>
+ </sashModel>
+</di:SashWindowsMngr>
diff --git a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.notation b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.notation
new file mode 100644
index 00000000000..7c4d9ae272a
--- /dev/null
+++ b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.notation
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/papyrus/infra/viewpoints/policy/style" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML">
+ <notation:Diagram xmi:id="_ld92QLLMEeSdSv3eJr1O_w" type="PapyrusUMLClassDiagram" name="NewDiagram" measurementUnit="Pixel">
+ <children xmi:type="notation:Shape" xmi:id="_oaq38LLMEeSdSv3eJr1O_w" type="2007">
+ <children xmi:type="notation:DecorationNode" xmi:id="_oa3FMLLMEeSdSv3eJr1O_w" type="5026"/>
+ <children xmi:type="notation:DecorationNode" xmi:id="_oa3sQLLMEeSdSv3eJr1O_w" type="7016">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_obzgYLLMEeSdSv3eJr1O_w" source="PapyrusCSSForceValue">
+ <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_ob0HcLLMEeSdSv3eJr1O_w" key="showTitle" value="true"/>
+ </eAnnotations>
+ <children xmi:type="notation:Shape" xmi:id="_us_KkLLMEeSdSv3eJr1O_w" type="3010">
+ <children xmi:type="notation:DecorationNode" xmi:id="_us_xoLLMEeSdSv3eJr1O_w" type="5014"/>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_utQ3YLLMEeSdSv3eJr1O_w" type="7011">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_utaBULLMEeSdSv3eJr1O_w" source="PapyrusCSSForceValue">
+ <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_utaBUbLMEeSdSv3eJr1O_w" key="showTitle" value="true"/>
+ </eAnnotations>
+ <styles xmi:type="notation:TitleStyle" xmi:id="_utQ3YbLMEeSdSv3eJr1O_w"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_utQ3YrLMEeSdSv3eJr1O_w"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_utQ3Y7LMEeSdSv3eJr1O_w"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_utQ3ZLLMEeSdSv3eJr1O_w"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_utQ3ZbLMEeSdSv3eJr1O_w" type="7012">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_utaoYLLMEeSdSv3eJr1O_w" source="PapyrusCSSForceValue">
+ <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_utaoYbLMEeSdSv3eJr1O_w" key="showTitle" value="true"/>
+ </eAnnotations>
+ <styles xmi:type="notation:TitleStyle" xmi:id="_utQ3ZrLMEeSdSv3eJr1O_w"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_utQ3Z7LMEeSdSv3eJr1O_w"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_utQ3aLLMEeSdSv3eJr1O_w"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_utQ3abLMEeSdSv3eJr1O_w"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_utRecLLMEeSdSv3eJr1O_w" type="7013">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_utbPcLLMEeSdSv3eJr1O_w" source="PapyrusCSSForceValue">
+ <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_utbPcbLMEeSdSv3eJr1O_w" key="showTitle" value="true"/>
+ </eAnnotations>
+ <styles xmi:type="notation:TitleStyle" xmi:id="_utRecbLMEeSdSv3eJr1O_w"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_utRecrLMEeSdSv3eJr1O_w"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_utRec7LMEeSdSv3eJr1O_w"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_utRedLLMEeSdSv3eJr1O_w"/>
+ </children>
+ <element xmi:type="uml:Class" href="model.uml#_usuE0LLMEeSdSv3eJr1O_w"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_us_KkbLMEeSdSv3eJr1O_w" x="80" y="17" width="76" height="56"/>
+ </children>
+ <styles xmi:type="notation:TitleStyle" xmi:id="_oa3sQbLMEeSdSv3eJr1O_w"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_oa3sQrLMEeSdSv3eJr1O_w"/>
+ </children>
+ <element xmi:type="uml:Package" href="model.uml#_oZE8gLLMEeSdSv3eJr1O_w"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_oaq38bLMEeSdSv3eJr1O_w" x="120" y="65" width="246" height="121"/>
+ </children>
+ <styles xmi:type="notation:DiagramStyle" xmi:id="_ld-dULLMEeSdSv3eJr1O_w"/>
+ <element xmi:type="uml:Model" href="model.uml#_la-MoLLMEeSdSv3eJr1O_w"/>
+ </notation:Diagram>
+ <notation:Diagram xmi:id="_k8kVMLLTEeSrOcSd47uy1Q" type="PapyrusUMLClassDiagram" name="ClassDiagram" measurementUnit="Pixel">
+ <children xmi:type="notation:Shape" xmi:id="_lzwb4LLTEeSrOcSd47uy1Q" type="2008">
+ <children xmi:type="notation:DecorationNode" xmi:id="_lz_scLLTEeSrOcSd47uy1Q" type="5029"/>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_lz_scbLTEeSrOcSd47uy1Q" type="7017">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_lz_scrLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_lz_sc7LTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_lz_sdLLTEeSrOcSd47uy1Q"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_lz_sdbLTEeSrOcSd47uy1Q"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_lz_sdrLTEeSrOcSd47uy1Q" type="7018">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_lz_sd7LTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_lz_seLLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_lz_sebLTEeSrOcSd47uy1Q"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_lz_serLTEeSrOcSd47uy1Q"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_lz_se7LTEeSrOcSd47uy1Q" type="7019">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_lz_sfLLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_lz_sfbLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_lz_sfrLTEeSrOcSd47uy1Q"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_lz_sf7LTEeSrOcSd47uy1Q"/>
+ </children>
+ <element xmi:type="uml:Class" href="model.uml#_usuE0LLMEeSdSv3eJr1O_w"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_lzwb4bLTEeSrOcSd47uy1Q" x="257" y="256"/>
+ </children>
+ <children xmi:type="notation:Shape" xmi:id="_mWZ18LLTEeSrOcSd47uy1Q" type="2008">
+ <children xmi:type="notation:DecorationNode" xmi:id="_mWadALLTEeSrOcSd47uy1Q" type="5029"/>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_mWadAbLTEeSrOcSd47uy1Q" type="7017">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_mWadArLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_mWadA7LTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_mWadBLLTEeSrOcSd47uy1Q"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_mWadBbLTEeSrOcSd47uy1Q"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_mWadBrLTEeSrOcSd47uy1Q" type="7018">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_mWadB7LTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_mWadCLLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_mWadCbLTEeSrOcSd47uy1Q"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_mWadCrLTEeSrOcSd47uy1Q"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_mWadC7LTEeSrOcSd47uy1Q" type="7019">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_mWadDLLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_mWadDbLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_mWadDrLTEeSrOcSd47uy1Q"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_mWadD7LTEeSrOcSd47uy1Q"/>
+ </children>
+ <element xmi:type="uml:Class" href="model.uml#_mV5foLLTEeSrOcSd47uy1Q"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_mWZ18bLTEeSrOcSd47uy1Q" x="539" y="253" width="111" height="108"/>
+ </children>
+ <styles xmi:type="notation:StringValueStyle" xmi:id="_k8kVMbLTEeSrOcSd47uy1Q" name="diagram_compatibility_version" stringValue="1.0.0"/>
+ <styles xmi:type="notation:DiagramStyle" xmi:id="_k8kVMrLTEeSrOcSd47uy1Q"/>
+ <styles xmi:type="style:PapyrusViewStyle" xmi:id="_k8kVM7LTEeSrOcSd47uy1Q">
+ <owner xmi:type="uml:Package" href="model.uml#_oZE8gLLMEeSdSv3eJr1O_w"/>
+ </styles>
+ <element xmi:type="uml:Package" href="model.uml#_oZE8gLLMEeSdSv3eJr1O_w"/>
+ </notation:Diagram>
+</xmi:XMI>
diff --git a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.uml b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.uml
new file mode 100644
index 00000000000..b413309dfcf
--- /dev/null
+++ b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/model/ControlModeLegacyModelTest/model.uml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_la-MoLLMEeSdSv3eJr1O_w" name="model">
+ <packagedElement xmi:type="uml:Package" xmi:id="_oZE8gLLMEeSdSv3eJr1O_w" name="Package1">
+ <packagedElement xmi:type="uml:Class" xmi:id="_usuE0LLMEeSdSv3eJr1O_w" name="Class1"/>
+ <packagedElement xmi:type="uml:Class" xmi:id="_mV5foLLTEeSrOcSd47uy1Q" name="Class2"/>
+ </packagedElement>
+</uml:Model>
diff --git a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/AllTests.java b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/AllTests.java
index 0d0cf4c88b6..ea125b3f640 100644
--- a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/AllTests.java
+++ b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/AllTests.java
@@ -1,28 +1,30 @@
-/*******************************************************************************
- * 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:
- * Juan Cadavid <juan.cadavid@cea.fr> implementation
- ******************************************************************************/
-package org.eclipse.papyrus.infra.services.controlmode.tests;
-
-import org.eclipse.papyrus.infra.services.controlmode.tests.control.ControlModelTest;
-import org.eclipse.papyrus.infra.services.controlmode.tests.control.ControlModelWithProfileTest;
-import org.eclipse.papyrus.infra.services.controlmode.tests.uncontrol.UncontrolModelTest;
-import org.eclipse.papyrus.infra.services.controlmode.tests.uncontrol.UncontrolModelWithProfileTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-@RunWith(Suite.class)
-@SuiteClasses({ ControlModelWithProfileTest.class,
- UncontrolModelTest.class,
- ControlModelTest.class,
- UncontrolModelWithProfileTest.class })
-public class AllTests {
-
-}
+/*******************************************************************************
+ * 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:
+ * Juan Cadavid <juan.cadavid@cea.fr> implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.services.controlmode.tests;
+
+import org.eclipse.papyrus.infra.services.controlmode.tests.control.ControlLegacyModelTest;
+import org.eclipse.papyrus.infra.services.controlmode.tests.control.ControlModelTest;
+import org.eclipse.papyrus.infra.services.controlmode.tests.control.ControlModelWithProfileTest;
+import org.eclipse.papyrus.infra.services.controlmode.tests.uncontrol.UncontrolModelTest;
+import org.eclipse.papyrus.infra.services.controlmode.tests.uncontrol.UncontrolModelWithProfileTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({ ControlModelWithProfileTest.class,
+ UncontrolModelTest.class,
+ ControlModelTest.class,
+ UncontrolModelWithProfileTest.class,
+ ControlLegacyModelTest.class })
+public class AllTests {
+
+}
diff --git a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlLegacyModelTest.java b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlLegacyModelTest.java
new file mode 100644
index 00000000000..c90b253cefc
--- /dev/null
+++ b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlLegacyModelTest.java
@@ -0,0 +1,158 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.controlmode.tests.control;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.ParameterValuesException;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.util.DiUtils;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.controlmode.commands.ControlModeCommandParameterValues;
+import org.eclipse.papyrus.infra.services.controlmode.handler.ControlCommandHandler;
+import org.eclipse.papyrus.infra.services.controlmode.tests.Messages;
+import org.eclipse.papyrus.junit.utils.HandlerUtils;
+import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
+import org.eclipse.papyrus.junit.utils.ProjectUtils;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * Test of Control feature with Legacy model.
+ *
+ * @author Gabriel Pascual
+ *
+ */
+public class ControlLegacyModelTest extends AbstractControlModeTest {
+
+ private static final String PROJECT_NAME = "ControlModeTestProject"; //$NON-NLS-1$
+
+ private static final String SOURCE_PATH = "/model/ControlModeLegacyModelTest/"; //$NON-NLS-1$
+
+ private static final String FILE_ROOT_NAME = "model"; //$NON-NLS-1$
+
+ @Override
+ protected void initTests(final Bundle bundle) throws CoreException, IOException {
+ bot = new SWTWorkbenchBot();
+ ProjectUtils.removeAllProjectFromTheWorkspace();
+ IProject testProject = ProjectUtils.createProject(PROJECT_NAME);
+ modelFile = PapyrusProjectUtils.copyPapyrusModel(testProject, bundle, SOURCE_PATH, FILE_ROOT_NAME);
+ AbstractControlModeTest.bundle = bundle;
+ }
+
+ @After
+ public void cleanUp() throws NotDefinedException, ParameterValuesException {
+
+ // Set value to default
+ IParameter dialogParameter = HandlerUtils.getCommand(this.COMMAND_ID).getParameter(ControlCommandHandler.CONTROLMODE_USE_DIALOG_PARAMETER);
+ ControlModeCommandParameterValues controlModePlatformValues = (ControlModeCommandParameterValues) dialogParameter.getValues();
+ controlModePlatformValues.put("showDialog", true);
+ }
+
+ @Test
+ public void testControlLegacyModel() {
+ RunnableWithResult<?> runnableWithResult = new RunnableWithResult.Impl<Object>() {
+
+ @Override
+ public void run() {
+ List<PackageableElement> elements = selectElementToControl();
+ Assert.assertTrue(Messages.ControlModelTest_4, HandlerUtils.getActiveHandlerFor(COMMAND_ID).isEnabled());
+ // Click "ok" with SWTBot
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ fail(e.getLocalizedMessage());
+ }
+
+
+ bot.button("OK").click(); //$NON-NLS-1$
+
+ }
+ });
+ controlAndSave(editor, model, elements, HandlerUtils.getCommand(COMMAND_ID));
+ assertSashControl(elements);
+ }
+
+
+ };
+ Display.getDefault().syncExec(runnableWithResult);
+
+
+ }
+
+ @Test
+ public void testControlModelWithoutDialog() throws NotDefinedException, ParameterValuesException {
+ IParameter dialogParameter = HandlerUtils.getCommand(this.COMMAND_ID).getParameter(ControlCommandHandler.CONTROLMODE_USE_DIALOG_PARAMETER);
+ ControlModeCommandParameterValues controlModePlatformValues = (ControlModeCommandParameterValues) dialogParameter.getValues();
+ controlModePlatformValues.put("showDialog", false);
+ RunnableWithResult<?> runnableWithResult = new RunnableWithResult.Impl<Object>() {
+
+ @Override
+ public void run() {
+ List<PackageableElement> elements = selectElementToControl();
+ Assert.assertTrue(Messages.ControlModelTest_4, HandlerUtils.getActiveHandlerFor(COMMAND_ID).isEnabled());
+
+ controlAndSave(editor, model, elements, HandlerUtils.getCommand(COMMAND_ID));
+ assertSashControl(elements);
+ }
+
+ };
+ Display.getDefault().syncExec(runnableWithResult);
+ }
+
+ /**
+ * Assert sash control.
+ *
+ * @param elements
+ * the elements
+ */
+ private void assertSashControl(List<PackageableElement> elements) {
+ ModelSet modelSet = null;
+ PackageableElement controledElement = elements.get(0);
+ try {
+ modelSet = ServiceUtilsForEObject.getInstance().getModelSet(controledElement);
+ } catch (ServiceException e) {
+ fail(e.getMessage());
+ }
+ Resource resource = modelSet.getAssociatedResource(controledElement, DiModel.DI_FILE_EXTENSION, true);
+ assertFalse(resource.getContents().isEmpty());
+ assertNotNull(DiUtils.lookupSashWindowsMngr(resource));
+
+
+
+ }
+
+}
diff --git a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlModelTest.java b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlModelTest.java
index dda74c974df..ed6bdf8bd22 100644
--- a/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlModelTest.java
+++ b/tests/junit/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.tests/src/org/eclipse/papyrus/infra/services/controlmode/tests/control/ControlModelTest.java
@@ -10,6 +10,7 @@
******************************************************************************/
package org.eclipse.papyrus.infra.services.controlmode.tests.control;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
@@ -20,7 +21,12 @@ import org.eclipse.core.commands.ParameterValuesException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.services.controlmode.commands.ControlModeCommandParameterValues;
import org.eclipse.papyrus.infra.services.controlmode.handler.ControlCommandHandler;
import org.eclipse.papyrus.infra.services.controlmode.tests.Messages;
@@ -43,6 +49,7 @@ public class ControlModelTest extends AbstractControlModeTest {
private static final String FILE_ROOT_NAME = "ControlModeTestModel"; //$NON-NLS-1$
+ @Override
protected void initTests(final Bundle bundle) throws CoreException, IOException {
bot = new SWTWorkbenchBot();
ProjectUtils.removeAllProjectFromTheWorkspace();
@@ -51,7 +58,8 @@ public class ControlModelTest extends AbstractControlModeTest {
AbstractControlModeTest.bundle = bundle;
}
- @Ignore @Test
+ @Ignore
+ @Test
public void controlModelTest() {
RunnableWithResult<?> runnableWithResult = new RunnableWithResult.Impl<Object>() {
@@ -81,11 +89,11 @@ public class ControlModelTest extends AbstractControlModeTest {
};
Display.getDefault().syncExec(runnableWithResult);
}
-
+
@Test
public void controlModelTestWithoutDialog() throws NotDefinedException, ParameterValuesException {
IParameter dialogParameter = HandlerUtils.getCommand(this.COMMAND_ID).getParameter(ControlCommandHandler.CONTROLMODE_USE_DIALOG_PARAMETER);
- ControlModeCommandParameterValues controlModePlatformValues = (ControlModeCommandParameterValues)dialogParameter.getValues();
+ ControlModeCommandParameterValues controlModePlatformValues = (ControlModeCommandParameterValues) dialogParameter.getValues();
controlModePlatformValues.put("showDialog", false);
RunnableWithResult<?> runnableWithResult = new RunnableWithResult.Impl<Object>() {
@@ -93,7 +101,7 @@ public class ControlModelTest extends AbstractControlModeTest {
public void run() {
List<PackageableElement> elements = selectElementToControl();
Assert.assertTrue(Messages.ControlModelTest_4, HandlerUtils.getActiveHandlerFor(COMMAND_ID).isEnabled());
-
+
controlAndSave(editor, model, elements, HandlerUtils.getCommand(COMMAND_ID));
}
@@ -101,4 +109,25 @@ public class ControlModelTest extends AbstractControlModeTest {
Display.getDefault().syncExec(runnableWithResult);
}
+
+ /**
+ * Assert sash control.
+ *
+ * @param elements
+ * the elements
+ */
+ protected void assertSashControl(List<PackageableElement> elements) {
+ ModelSet modelSet = null;
+ PackageableElement controlElement = elements.get(0);
+ try {
+ modelSet = ServiceUtilsForEObject.getInstance().getModelSet(controlElement);
+ } catch (ServiceException e) {
+ fail(e.getMessage());
+ }
+ Resource resource = modelSet.getAssociatedResource(controlElement, DiModel.DI_FILE_EXTENSION, true);
+ assertTrue(resource.getContents().isEmpty());
+
+ }
+
+
}

Back to the top