From 1d4aaa9d22fb35ec031b01a8e5cd66fef00c0f30 Mon Sep 17 00:00:00 2001 From: bblajer Date: Fri, 4 May 2007 14:08:42 +0000 Subject: 1. Links to links; 2. Exception from TreeEditPartViewer (in the outline) while closing the diagram editor (because unregister is not called, only deactivate) fixed; 3. instead of rerouting a link to an end that does not support it, remove the link --- .../lite/edit/parts/tree/BaseTreeEditPart.java | 7 +++-- .../OwnedLinksNotationModelRefresher.java | 30 ++++++++++++++++--- .../lite/figures/ConnectionConnectionAnchor.java | 34 ++++++++++++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/figures/ConnectionConnectionAnchor.java (limited to 'plugins/org.eclipse.gmf.runtime.lite/src/org') diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/tree/BaseTreeEditPart.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/tree/BaseTreeEditPart.java index df4db0f5f..2db5736db 100644 --- a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/tree/BaseTreeEditPart.java +++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/tree/BaseTreeEditPart.java @@ -96,8 +96,11 @@ public class BaseTreeEditPart extends AbstractTreeEditPart implements IUpdatable super.deactivate(); } - protected final TransactionalUpdateManager getTransactionalUpdateManager() { - return (TransactionalUpdateManager) getViewer().getProperty(TransactionalUpdateManager.class.getName()); + protected TransactionalUpdateManager getTransactionalUpdateManager() { + if (getParent() instanceof BaseTreeEditPart) { + return ((BaseTreeEditPart) getParent()).getTransactionalUpdateManager(); + } + return null; } protected List getModelChildren() { diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/update/canonical/OwnedLinksNotationModelRefresher.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/update/canonical/OwnedLinksNotationModelRefresher.java index 5b47a6213..73df6995d 100644 --- a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/update/canonical/OwnedLinksNotationModelRefresher.java +++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/edit/parts/update/canonical/OwnedLinksNotationModelRefresher.java @@ -99,12 +99,20 @@ public abstract class OwnedLinksNotationModelRefresher extends AbstractNotationM command.appendIfCanExecute(getCreateNotationalElementCommand(next)); } else { View newSourceView = myViewService.findView(next.getSource()); - if (changedSource && newSourceView != null) { - command.appendIfCanExecute(new ReconnectNotationalEdgeSourceCommand(currentEdge, newSourceView)); + if (changedSource) { + if (newSourceView != null && isValidLinkSource(newSourceView, next)) { + command.appendIfCanExecute(new ReconnectNotationalEdgeSourceCommand(currentEdge, newSourceView)); + } else { + command.appendIfCanExecute(new RemoveNotationalEdgeCommand(currentEdge.getDiagram(), currentEdge)); + } } View newTargetView = myViewService.findView(next.getDestination()); - if (changedTarget && newTargetView != null) { - command.appendIfCanExecute(new ReconnectNotationalEdgeTargetCommand(currentEdge, newTargetView)); + if (changedTarget) { + if (newTargetView != null && isValidLinkTarget(newTargetView, next)) { + command.appendIfCanExecute(new ReconnectNotationalEdgeTargetCommand(currentEdge, newTargetView)); + } else { + command.appendIfCanExecute(new RemoveNotationalEdgeCommand(currentEdge.getDiagram(), currentEdge)); + } } } } @@ -126,4 +134,18 @@ public abstract class OwnedLinksNotationModelRefresher extends AbstractNotationM protected abstract List/**/ getSemanticChildLinks(); protected abstract List/**/ getNotationalChildLinks(); + + /** + * Returns whether the given view can be source of the given link. + */ + protected boolean isValidLinkSource(View sourceCandidate, LinkDescriptor linkDescriptor) { + return true; + } + + /** + * Returns whether the given view can be source of the given link. + */ + protected boolean isValidLinkTarget(View targetCandidate, LinkDescriptor linkDescriptor) { + return true; + } } diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/figures/ConnectionConnectionAnchor.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/figures/ConnectionConnectionAnchor.java new file mode 100644 index 000000000..e37df34ae --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/figures/ConnectionConnectionAnchor.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2007 Borland Software Corporation + * + * 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: + * bblajer - initial API and implementation + */ +package org.eclipse.gmf.runtime.lite.figures; + +import org.eclipse.draw2d.ChopboxAnchor; +import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.Rectangle; + + +public class ConnectionConnectionAnchor extends ChopboxAnchor { + public ConnectionConnectionAnchor(Connection figure) { + super(figure); + } + + @Override + protected Rectangle getBox() { + PointList points = ((Connection) getOwner()).getPoints(); + if (points == null || points.size() == 0) { + return super.getBox(); + } + return new Rectangle(points.getMidpoint(), new Dimension(1,1)); + } +} -- cgit v1.2.1