Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2014-03-26 12:42:36 +0000
committerVincent Lorenzo2014-03-26 12:42:36 +0000
commit71479301ef39716f092474d684c910077400f1a6 (patch)
tree99d890a1ade60c0b9d6d3a181ae9f79fb509446d
parenta22245ed7b0d110dfd8d30da010b13ecdff6c878 (diff)
downloadorg.eclipse.papyrus-71479301ef39716f092474d684c910077400f1a6.tar.gz
org.eclipse.papyrus-71479301ef39716f092474d684c910077400f1a6.tar.xz
org.eclipse.papyrus-71479301ef39716f092474d684c910077400f1a6.zip
430702: [Diagram] Moving source of a link moves the target too.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=430702 Fix anchors after DnD from ModelExplorer + improve code
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java26
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java135
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java96
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java86
4 files changed, 248 insertions, 95 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java
index 3652277ed79..3229f7b00ba 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java
@@ -17,13 +17,17 @@ package org.eclipse.papyrus.infra.gmfdiag.common.commands;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.emf.transaction.RunnableWithResult;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.gef.EditPart;
@@ -33,6 +37,7 @@ import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.FixAnchorHelper;
@@ -86,25 +91,6 @@ public abstract class AbstractFixEdgeAnchorDeferredCommand extends AbstractTrans
*
* @param connectionToRefresh
* the connection edit part to refresh
- */
- protected void refreshConnection(final AbstractConnectionEditPart connectionToRefresh) {
- connectionToRefresh.refresh();
- final EditPart sourceEp = connectionToRefresh.getSource();
- if(sourceEp != null) {
- sourceEp.refresh();
- }
- final EditPart targetEP = connectionToRefresh.getTarget();
- if(targetEP != null) {
- targetEP.refresh();
- }
- //to force the call to the router, to update the figure
- connectionToRefresh.getFigure().validate();
- }
-
- /**
- *
- * @param connectionToRefresh
- * the connection edit part to refresh
* @param commandToContribute
* the command to contribute (as parameter to avoid to create several compound command
*/
@@ -171,4 +157,6 @@ public abstract class AbstractFixEdgeAnchorDeferredCommand extends AbstractTrans
public boolean canExecute() {
return super.canExecute() && this.helper != null && this.containerEP != null;
}
+
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java
new file mode 100644
index 00000000000..0c7b2d62c31
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java
@@ -0,0 +1,135 @@
+/*****************************************************************************
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+
+
+/**
+ *
+ * abstract runnable used to refresh the connection, source and target editparts
+ *
+ */
+public abstract class AbstractRefreshConnectionElementsRunnable<T> implements RunnableWithResult<T> {
+
+ /**
+ * the status of the runnable
+ */
+ private IStatus status;
+
+ /**
+ * the result of the runnable
+ */
+ private T result;
+
+ /**
+ * the container editpart of the refreshed connection
+ */
+ private final IGraphicalEditPart containerEP;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param containerEP
+ * the editpart owning the connection
+ */
+ public AbstractRefreshConnectionElementsRunnable(final IGraphicalEditPart containerEP) {
+ this.containerEP = containerEP;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.transaction.RunnableWithResult#getResult()
+ *
+ * @return
+ */
+ public final T getResult() {
+ return result;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.transaction.RunnableWithResult#setStatus(org.eclipse.core.runtime.IStatus)
+ *
+ * @param status
+ * set the new status for the runnable
+ */
+ public final void setStatus(IStatus status) {
+ this.status = status;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.transaction.RunnableWithResult#getStatus()
+ *
+ * @return
+ * the status of the runnable
+ */
+ public final IStatus getStatus() {
+ return status;
+ }
+
+ /**
+ *
+ * @return
+ * the container edit part
+ */
+ protected final IGraphicalEditPart getContainerEditPart() {
+ return this.containerEP;
+ }
+ /**
+ *
+ * @param connectionToRefresh
+ * the connection edit part to refresh
+ */
+ protected final void refreshConnection(final AbstractConnectionEditPart connectionToRefresh) {
+ connectionToRefresh.refresh();
+ final EditPart sourceEp = connectionToRefresh.getSource();
+ if(sourceEp != null) {
+ sourceEp.refresh();
+ }
+ final EditPart targetEP = connectionToRefresh.getTarget();
+ if(targetEP != null) {
+ targetEP.refresh();
+ }
+ //to force the call to the router, to update the figure
+ connectionToRefresh.getFigure().validate();
+ }
+
+ /**
+ *
+ * @return
+ * the figure for the container edit part
+ */
+ protected final IFigure getContainerFigure() {
+ return this.containerEP.getFigure();
+ }
+
+ /**
+ *
+ * @param result
+ * set the result of the runnable
+ */
+ protected final void setResult(T result) {
+ this.result = result;
+ }
+
+}; \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java
index 77dae8137ee..ac8f3bc8826 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java
@@ -15,6 +15,7 @@
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+import java.io.ObjectInputStream.GetField;
import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
@@ -22,6 +23,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.transaction.RunnableWithResult;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.commands.CompoundCommand;
@@ -32,6 +34,7 @@ import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.swt.widgets.Display;
/**
@@ -73,44 +76,14 @@ public class FixEdgeAnchorAfterCreationDeferredCommand extends AbstractFixEdgeAn
*/
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- final RunnableWithResult<AbstractConnectionEditPart> refreshRunnable = new RunnableWithResult<AbstractConnectionEditPart>() {
-
- private IStatus status;
-
- private AbstractConnectionEditPart result;
-
- public AbstractConnectionEditPart getResult() {
- return result;
- }
-
- public void setStatus(IStatus status) {
- this.status = status;
- }
-
- public IStatus getStatus() {
- return status;
- }
-
- public void run() {
- getContainerEP().refresh();
-
- // We update the figure world
- getContainerFigure().invalidate();
- getContainerFigure().validate();
- final View view = (View)request.getConnectionViewDescriptor().getAdapter(View.class);
- if(view != null) {
- final Map<?, ?> epRegistry = getContainerEP().getRoot().getViewer().getEditPartRegistry();
- Object editPart = epRegistry.get(view);
- if(editPart instanceof AbstractConnectionEditPart) {
- this.result = (AbstractConnectionEditPart)editPart;
- refreshConnection(this.result);
- }
- }
- setStatus(Status.OK_STATUS);
- }
- };
+ //we execute all ui thread
+ while(Display.getDefault().readAndDispatch());
+ //we refresh the editparts
+ RefreshConnectionElementsRunnable refreshRunnable = new RefreshConnectionElementsRunnable(this.request, getContainerEP());
EditPartUtil.synchronizeRunnableToMainThread(getContainerEP(), refreshRunnable);
+
+ //we do the work
final AbstractConnectionEditPart connectionEP = refreshRunnable.getResult();
if(connectionEP != null) {
final CompoundCommand cc = new CompoundCommand("Fix connections anchors"); //$NON-NLS-1$
@@ -145,4 +118,55 @@ public class FixEdgeAnchorAfterCreationDeferredCommand extends AbstractFixEdgeAn
public boolean canExecute() {
return super.canExecute() && this.request != null;
}
+
+ /**
+ *
+ * The runnable used to refresh the views
+ *
+ */
+ private static class RefreshConnectionElementsRunnable extends AbstractRefreshConnectionElementsRunnable<AbstractConnectionEditPart> {
+
+ /**
+ * the connection request
+ */
+ final CreateConnectionViewRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param request
+ * the request used to create the connection view
+ * @param containerEP
+ * the edit part owning the new connection editpart
+ * @param containerFigure
+ */
+ public RefreshConnectionElementsRunnable(final CreateConnectionViewRequest request, final IGraphicalEditPart containerEP) {
+ super(containerEP);
+ this.request = request;
+ }
+
+ /**
+ *
+ * @see java.lang.Runnable#run()
+ *
+ */
+ public void run() {
+ getContainerEditPart().refresh();
+ // We update the figure world
+ getContainerFigure().invalidate();
+ getContainerFigure().validate();
+ final View view = (View)this.request.getConnectionViewDescriptor().getAdapter(View.class);
+ if(view != null) {
+ final Map<?, ?> epRegistry = getContainerEditPart().getRoot().getViewer().getEditPartRegistry();
+ Object editPart = epRegistry.get(view);
+ if(editPart instanceof AbstractConnectionEditPart) {
+ setResult((AbstractConnectionEditPart)editPart);
+ refreshConnection(getResult());
+ }
+ }
+ setStatus(Status.OK_STATUS);
+ }
+ };
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java
index 41b83cab5c1..a5cd2e2e346 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java
@@ -72,44 +72,8 @@ public class FixEdgeAnchorsDeferredCommand extends AbstractFixEdgeAnchorDeferred
*/
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- final RunnableWithResult<Collection<AbstractConnectionEditPart>> refreshRunnable = new RunnableWithResult<Collection<AbstractConnectionEditPart>>() {
-
- private IStatus status;
-
- private Collection<AbstractConnectionEditPart> result;
-
- public Collection<AbstractConnectionEditPart> getResult() {
- return result;
- }
-
- public void setStatus(IStatus status) {
- this.status = status;
- }
-
- public IStatus getStatus() {
- return status;
- }
-
- public void run() {
- getContainerEP().refresh();
-
- // We update the figure world
- getContainerFigure().invalidate();
- getContainerFigure().validate();
- final Iterator<?> iter = connectionsEditPartToRefresh.iterator();
- final Collection<AbstractConnectionEditPart> connectionsEP = new HashSet<AbstractConnectionEditPart>();
- this.result = connectionsEP;
- while(iter.hasNext()) {
- final Object object = iter.next();
- if(object instanceof AbstractConnectionEditPart) {
- connectionsEP.add((AbstractConnectionEditPart)object);
- refreshConnection((AbstractConnectionEditPart)object);
- }
- }
- setStatus(Status.OK_STATUS);
- }
- };
-
+ final RefreshConnectionElementsRunnable refreshRunnable = new RefreshConnectionElementsRunnable(this.connectionsEditPartToRefresh, getContainerEP());
+
EditPartUtil.synchronizeRunnableToMainThread(getContainerEP(), refreshRunnable);
final Collection<AbstractConnectionEditPart> toRefresh = refreshRunnable.getResult();
final Iterator<AbstractConnectionEditPart> iter = toRefresh.iterator();
@@ -119,7 +83,7 @@ public class FixEdgeAnchorsDeferredCommand extends AbstractFixEdgeAnchorDeferred
addFixAnchorCommand(current, cc);
if(cc.canExecute()) {
cc.execute();
- }else{
+ } else {
Activator.log.warn("Command to fix the anchors is null"); //$NON-NLS-1$
}
}
@@ -136,6 +100,48 @@ public class FixEdgeAnchorsDeferredCommand extends AbstractFixEdgeAnchorDeferred
this.connectionsEditPartToRefresh.clear();
}
+ private static class RefreshConnectionElementsRunnable extends AbstractRefreshConnectionElementsRunnable<Collection<AbstractConnectionEditPart>> {
+
+ /**
+ * the list of the connections to refresh
+ */
+ private Collection<?> connectionsEditPartToRefresh;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param connectionsEditPartToRefresh
+ * the list of the connection edit part to refresh
+ * @param containerEP
+ */
+ public RefreshConnectionElementsRunnable(final Collection<?> connectionsEditPartToRefresh, final IGraphicalEditPart containerEP) {
+ super(containerEP);
+ this.connectionsEditPartToRefresh = connectionsEditPartToRefresh;
+ }
-
+ /**
+ *
+ * @see java.lang.Runnable#run()
+ *
+ */
+ public void run() {
+ getContainerEditPart().refresh();
+
+ // We update the figure world
+ getContainerFigure().invalidate();
+ getContainerFigure().validate();
+ final Iterator<?> iter = connectionsEditPartToRefresh.iterator();
+ final Collection<AbstractConnectionEditPart> connectionsEP = new HashSet<AbstractConnectionEditPart>();
+ setResult(connectionsEP);
+ while(iter.hasNext()) {
+ final Object object = iter.next();
+ if(object instanceof AbstractConnectionEditPart) {
+ connectionsEP.add((AbstractConnectionEditPart)object);
+ refreshConnection((AbstractConnectionEditPart)object);
+ }
+ }
+ setStatus(Status.OK_STATUS);
+ }
+ }
}

Back to the top