Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmallet2017-08-01 15:48:18 +0000
committerPierre Guilet2017-08-04 14:09:50 +0000
commit50406c3364b0227aee3c013dda14726c2f56e238 (patch)
treebc028a41914b17e1cbbb7844c4eb4256284c5cac
parentf96ddec3d9ed4c59a3954efdf5b06a916d1328e4 (diff)
downloadorg.eclipse.sirius-50406c3364b0227aee3c013dda14726c2f56e238.tar.gz
org.eclipse.sirius-50406c3364b0227aee3c013dda14726c2f56e238.tar.xz
org.eclipse.sirius-50406c3364b0227aee3c013dda14726c2f56e238.zip
[517532] Add drag&drop of semantic model on aird editor.
* addition of dropAdapterAssistant to add new semantic model to a session by simply drag'n'dropping the model file from the workspace into the "Models" block of the aird editor * addition of unitary test Bug:517532 Change-Id: I6d521fd41484986bf1aacdc1ef7a001cb63354f4 Signed-off-by: jmallet <jessy.mallet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.html3
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.textile2
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DndWorkspaceToAirdEditorTest.java144
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java4
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/plugin.xml9
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/ModelCommonDropAdapterAssistant.java113
7 files changed, 276 insertions, 2 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.html b/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.html
index 2fc6e2f446..2bd0a5cc53 100644
--- a/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.html
+++ b/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.html
@@ -240,6 +240,9 @@
</ul>
</li>
</ul>
+ <p>Note that you can also add a new semantic model to a session by simply drag and dropping the model file from the workpace (from any Eclipse view) into the
+ <em>Models</em> block on the left side of the editor.
+ </p>
<h3 id="model_creation_wizard">Creating New Models</h3>
<p>The aird editor features a generic model creation wizard that can be used to create new models files of any kind supported in the environement (i.e. instances of any installed meta-model). To create a new model, select the
<i>New...</i> button. It opens a creation wizard:
diff --git a/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.textile b/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.textile
index 8f7f1c649e..0045daa726 100644
--- a/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/user/general/Aird_Editor.textile
@@ -104,6 +104,8 @@ To be able to edit a semantic model with a Sirius modeler, you must first tell t
* A manual one were you have two different buttons in the editor:
** The *__New...__* button, which opens a wizard allowing to create a new model from any registered package and in any project you want (see the next section for more details on the wizard). The newly created model will be loaded automatically in the aird file.
** The *__Add__* button, which allows to load into the aird file an already existing model either from the same project or from another one.
+Note that you can also add a new semantic model to a session by simply drag and dropping the model file from the workpace (from any Eclipse view) into the _Models_ block on the left side of the editor.
+
h3(#model_creation_wizard). Creating New Models
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF
index 25f644ce1a..52bb314414 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF
@@ -53,7 +53,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.platform,
org.eclipse.sirius.tests.sample.migration,
org.eclipse.emf.edit.ui,
- org.eclipse.gmf.runtime.diagram.ui.render
+ org.eclipse.gmf.runtime.diagram.ui.render,
+ org.eclipse.sirius.ui.editor
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Eclipse-RegisterBuddy: org.apache.log4j
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DndWorkspaceToAirdEditorTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DndWorkspaceToAirdEditorTest.java
new file mode 100644
index 0000000000..f69f634478
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DndWorkspaceToAirdEditorTest.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Obeo
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.tests.swtbot;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase;
+import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource;
+import org.eclipse.sirius.tests.swtbot.support.utils.dnd.DndUtil;
+import org.eclipse.sirius.ui.editor.SessionEditor;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.junit.Assume;
+import org.junit.runner.RunWith;
+
+/**
+ * Class test for the new feature "drag and drop on aird editor". see bug #517532
+ *
+ * @author jmallet
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class DndWorkspaceToAirdEditorTest extends AbstractSiriusSwtBotGefTestCase {
+
+ private static final String MODEL = "436.ecore";
+
+ private static final String SESSION_FILE = "436.aird";
+
+ private static final String VSM_FILE = "436.odesign";
+
+ private static final String SAMPLE_MODEL_FILE = "file.ecore";
+
+ private static final String DATA_UNIT_DIR = "data/unit/dragAndDrop/tc-436/";
+
+ private static final String FILE_DIR = "/";
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onSetUpBeforeClosingWelcomePage() throws Exception {
+ copyFileToTestProject(Activator.PLUGIN_ID, DATA_UNIT_DIR, MODEL, VSM_FILE, SESSION_FILE, SAMPLE_MODEL_FILE);
+ }
+
+ /**
+ * Validate drag&drop of a model from the explorer view to the models block of the aird editor.
+ *
+ * @throws Exception
+ * if an error occurs.
+ */
+ public void testDragAndDropModelFile() throws Exception {
+ Assume.assumeFalse("Drag and drop from View does not work with Xvnc", DndUtil.isUsingXvnc());
+ // open aird editor
+ final UIResource sessionAirdResource = new UIResource(designerProject, FILE_DIR, SESSION_FILE);
+ RunnableWithResult<IEditorPart> result = new RunnableWithResult<IEditorPart>() {
+ private IEditorPart resultEditor;
+
+ @Override
+ public void run() {
+ URI uri = URI.createPlatformResourceURI(sessionAirdResource.getFullPath().toString(), true);
+ try {
+ resultEditor = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(ResourcesPlugin
+ .getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)))),
+ SessionEditor.EDITOR_ID);
+ } catch (PartInitException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public IEditorPart getResult() {
+ return resultEditor;
+ }
+
+ @Override
+ public void setStatus(IStatus status) {
+
+ }
+
+ @Override
+ public IStatus getStatus() {
+ return null;
+ }
+ };
+ PlatformUI.getWorkbench().getDisplay().syncExec(result);
+ // Get back trees
+ SWTBotTree semanticAirdTree = bot.editorById(SessionEditor.EDITOR_ID).bot().tree(0);
+
+ SWTBotTree modelExplorerTree = bot.viewByTitle("Model Explorer").bot().tree();
+ SWTBotTreeItem sampleFile = modelExplorerTree.expandNode(designerProject.getName())
+ .expandNode(SAMPLE_MODEL_FILE);
+ int modelNumber = semanticAirdTree.getAllItems().length;
+
+ bot.getDisplay().asyncExec(() -> {
+ // compute drop point
+ Rectangle bounds = semanticAirdTree.widget.getBounds();
+ Point dropPoint = new Point(modelExplorerTree.widget.getBounds().width + bounds.width / 2, bounds.height);
+ // drag and drop
+ sampleFile.select();
+ DndUtil util = new DndUtil(bot.getDisplay());
+ util.dragAndDrop(sampleFile, dropPoint);
+ });
+ bot.waitUntil(new DefaultCondition() {
+
+ public boolean test() throws Exception {
+ return semanticAirdTree.getAllItems().length > modelNumber;
+ }
+
+ public String getFailureMessage() {
+ return "No model was added after the drag and drop.";
+ }
+ });
+ // check item of the semantic aird tree
+ boolean isDragAndDropOk = false;
+ for (SWTBotTreeItem swtBotTreeItem : semanticAirdTree.getAllItems()) {
+ String text = swtBotTreeItem.getText();
+ if (text.contains(SAMPLE_MODEL_FILE)) {
+ isDragAndDropOk = true;
+ }
+ }
+
+ assertTrue("Model file file.ecore must be added to semantic model tree.", isDragAndDropOk);
+
+ }
+}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
index 5f5fe24656..f350356137 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
@@ -271,6 +271,7 @@ public class AllTestSuite extends TestCase {
suite.addTestSuite(OpenMultipleRepresentationsTest.class);
suite.addTestSuite(ShapeResizingEdgePositionStabilityTests.class);
suite.addTestSuite(PortsOnNodePositionStabilityTest.class);
+ suite.addTest(new JUnit4TestAdapter(DndWorkspaceToAirdEditorTest.class));
suite.addTest(new JUnit4TestAdapter(PortLocationAfterDragAndDropTest.class));
suite.addTestSuite(PortLocationAfterDragAndDropOnDiagramTest.class);
suite.addTestSuite(CopyPasteLayoutOfPortsWithConflictWithNotPastedPortsTest.class);
@@ -360,7 +361,8 @@ public class AllTestSuite extends TestCase {
// This test is KO if the cdonative plugins are active (VP-4101), so
// launch it only when cdonative plugins are not active.
try {
- Resource resource = new ResourceSetImpl().getResource(URI.createPlatformPluginURI("org.eclipse.sirius.cdonative/model/viewpoint.genmodel", true), true);
+ Resource resource = new ResourceSetImpl().getResource(
+ URI.createPlatformPluginURI("org.eclipse.sirius.cdonative/model/viewpoint.genmodel", true), true);
if (resource == null) {
suite.addTestSuite(DisabledSiriusClipboardSupportTest.class);
}
diff --git a/plugins/org.eclipse.sirius.ui.editor/plugin.xml b/plugins/org.eclipse.sirius.ui.editor/plugin.xml
index aeae98e3c5..4369c2cd74 100644
--- a/plugins/org.eclipse.sirius.ui.editor/plugin.xml
+++ b/plugins/org.eclipse.sirius.ui.editor/plugin.xml
@@ -72,6 +72,15 @@
priority="high">
<triggerPoints>
</triggerPoints>
+ <dropAssistant
+ class="org.eclipse.sirius.ui.editor.ModelCommonDropAdapterAssistant"
+ id="org.eclipse.sirius.ui.editor.modelDropAssistant">
+ <possibleDropTargets>
+ <adapt
+ type="java.lang.Object">
+ </adapt>
+ </possibleDropTargets>
+ </dropAssistant>
</navigatorContent>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/ModelCommonDropAdapterAssistant.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/ModelCommonDropAdapterAssistant.java
new file mode 100644
index 0000000000..dbd879d66b
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/ModelCommonDropAdapterAssistant.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.ui.editor;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.internal.resources.File;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonDropAdapter;
+import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
+
+/**
+ * A {@link CommonDropAdapterAssistant} to support drop of model elements into
+ * semantic tree viewer.
+ *
+ * @author jmallet
+ */
+@SuppressWarnings("restriction")
+public class ModelCommonDropAdapterAssistant extends CommonDropAdapterAssistant {
+
+ @Override
+ public IStatus validateDrop(Object target, int operation, TransferData transferType) {
+ IStatus status = Status.CANCEL_STATUS;
+ if (DND.DROP_MOVE == operation) {
+ Collection<File> extractDragSource = extractDragSource(LocalSelectionTransfer.getTransfer().getSelection());
+ if (!extractDragSource.isEmpty()) {
+ status = Status.OK_STATUS;
+ }
+ }
+ return status;
+ }
+
+ @Override
+ public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
+ IStatus status = Status.CANCEL_STATUS;
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ final IWorkbenchPage activePage = window.getActivePage();
+ final IEditorPart activeEditor = activePage.getActiveEditor();
+ if (activeEditor instanceof SessionEditor) {
+ Session session = ((SessionEditor) activeEditor).getSession();
+ Collection<File> droppedEObjects = extractDragSource(aDropTargetEvent.data);
+ if (!droppedEObjects.isEmpty()) {
+ try {
+ new ProgressMonitorDialog(window.getShell()).run(false, false, monitor -> {
+ session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
+ @Override
+ protected void doExecute() {
+ for (Iterator<File> iterator = droppedEObjects.iterator(); iterator.hasNext(); ) {
+ File file = iterator.next();
+ session.addSemanticResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true), monitor);
+ }
+ }
+ });
+ });
+ status = Status.OK_STATUS;
+ } catch (InvocationTargetException | InterruptedException e) {
+ SessionEditorPlugin.getPlugin().error(e.getMessage(), e);
+ }
+ }
+ }
+ return status;
+ }
+
+ /**
+ * This extracts a collection of dragged source file from the given object
+ * retrieved from the transfer agent. This default implementation converts a
+ * structured selection into a collection of elements.
+ *
+ * @param object
+ * the object representing the selection in drag
+ * @return the drag selection in form of collection
+ */
+ protected Collection<File> extractDragSource(Object object) {
+ Collection<File> droppedEObjects = new ArrayList<File>();
+ if (object instanceof IStructuredSelection) {
+ List<?> list = ((IStructuredSelection) object).toList();
+ for (Object obj : list) {
+ if (obj instanceof File) {
+ File file = (File) obj;
+ droppedEObjects.add(file);
+ }
+ }
+ }
+ return droppedEObjects;
+ }
+
+}

Back to the top