Commit 8c9bc65e authored by Johannes Eder's avatar Johannes Eder
Browse files

removed unused code

Issue-Ref: 3972
Issue-Url: https://af3-developer.fortiss.org/issues/3972

Signed-off-by: Johannes Eder's avatarJohannes Eder <eder@fortiss.org>
parent 9ebbe2e6
ComponentConnectionCompositor.java 1e0f1142c9ea412ecfbdabd769e688930225ad08 GREEN
ComponentConnectionCompositor.java 69769699e75a7bb7e8e5f6d15563564d52e52a81 YELLOW
......@@ -17,39 +17,20 @@ package org.fortiss.af3.component.ui.compose;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createChannel;
import java.awt.MouseInfo;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.component.utils.ComponentModelElementFactory;
import org.fortiss.af3.component.utils.ComponentUtils;
import org.fortiss.tooling.base.compose.ConnectionCompositorBase;
import org.fortiss.tooling.base.dnd.ConnectionDragContext;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.utils.LayoutDataUtils;
import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
/**
* Connection compositor for directly connecting components.
......@@ -70,47 +51,26 @@ public class ComponentConnectionCompositor
Component parentComp = getConnectionContainer((Port)source, (Port)target);
return canConnect((Port)source, (Port)target, parentComp);
}
return true;
return false;
}
/** Check the classes for the given end of the connection. */
private boolean isOfValidClass(EObject end) {
return end instanceof Component || end instanceof ComponentArchitecture ||
end instanceof Port;
return end instanceof Port;
}
/** {@inheritDoc} */
@Override
public boolean connect(EObject source, EObject target, IHierarchicElement uselessParent,
IConnectionCompositionContext context) {
// Both targetPos and srcPos *have to be computed before the first call to
// handleConnectionEnd because they depend on the mouse cursor when the compositor is called
// (and handleConnectionEnd can change this cursor).
Point targetPos = null;
Point srcPos = null;
if(context instanceof ConnectionDragContext) {
targetPos = getTargetPopupPos();
srcPos = getSourcePopupPos((ConnectionDragContext)context);
}
Port sourceConnector = handleConnectionEnd(source, srcPos, context, false);
if(sourceConnector == null) {
// A little bit ugly to throw an exception there, we would rather just return false.
// However since the connection runs inside a transaction that would entail that the
// model is dirty even though we did not do anything.
throw new OperationCanceledException();
}
Port targetConnector = handleConnectionEnd(target, targetPos, context, true);
if(targetConnector == null) {
throw new OperationCanceledException();
}
Component parentComp = getConnectionContainer(sourceConnector, targetConnector);
Component parentComp = getConnectionContainer((Port)source, (Port)target);
ITopLevelElement topElement =
IPersistencyService.getInstance().getTopLevelElementFor(source);
if(topElement != null) {
topElement.prepareIDs(sourceConnector);
topElement.prepareIDs(targetConnector);
topElement.prepareIDs(source);
topElement.prepareIDs(target);
}
createConnection(sourceConnector, targetConnector, parentComp, topElement);
createConnection((Port)source, (Port)target, parentComp, topElement);
return true;
}
......@@ -170,176 +130,12 @@ public class ComponentConnectionCompositor
return gParent1.equals(parent2) ? gParent1 : parent2.getParentComponent();
}
/**
* Returns the port corresponding to the given end.
* - If end is a port it is obvious.
* - If it is a component then we should add a port to the component and return this component.
* - If we are in a drag and drop context where the end corresponds to the background of the
* editor, then we raise a pop-up menu asking whether we should create a component or a port,
* and then create and return the objects accordingly.
*/
private Port handleConnectionEnd(EObject end, Point popupPos,
IConnectionCompositionContext context, boolean isTarget) {
Port targetConnector = null;
if(end instanceof Port) {
targetConnector = (Port)end;
} else {
if(!(context instanceof ConnectionDragContext)) {
return null;
}
ConnectionDragContext ctx = (ConnectionDragContext)context;
if(isTarget ? ctx.isTargetRoot() : ctx.isSourceRoot()) {
EndSelectionPopup popup = new EndSelectionPopup(popupPos, isTarget);
popup.open();
Display d = Display.getCurrent();
while(!(popup.getShell() == null || popup.getShell().isDisposed())) {
if(!d.readAndDispatch()) {
d.sleep();
}
}
EObject elt = popup.getSelectedItem();
if(elt == null) {
return null;
}
if(elt instanceof Component) {
composeWithDropContext((IHierarchicElement)end, elt, ctx, isTarget);
targetConnector = createPort(!isTarget);
composeWithDropContext((Component)elt, targetConnector, ctx, isTarget);
} else if(elt instanceof Port) {
targetConnector = (Port)elt;
IElementCompositionContext dropCtx =
isTarget ? ctx.getTargetDropContext() : ctx.getSourceDropContext();
LayoutDataUtils.layoutModelElement(elt, dropCtx);
IElementCompositorService.getInstance().compose(end, elt, null);
}
} else {
targetConnector = createPort(!isTarget);
composeWithDropContext((IHierarchicElement)end, targetConnector, ctx, isTarget);
}
}
return targetConnector;
}
/**
* Composes <code>contained</code> into <code>container</code> with the relevant drop context
* depending whether it we are considering the source or the target of the connection.
*/
private void composeWithDropContext(IHierarchicElement container, EObject contained,
IConnectionCompositionContext context, boolean isTarget) {
if(isTarget) {
createNewTargetDropContext(container, context, contained);
} else {
createNewSourceDropContext(container, context, contained);
}
}
/** {@inheritDoc} */
@Override
protected IConnection createConnection() {
return createChannel();
}
/** Creates an output port if we are considering a target or an input port otherwise. */
private Port createPort(boolean isTarget) {
if(isTarget) {
return ComponentModelElementFactory.createOutputPort("Output", "");
}
return ComponentModelElementFactory.createInputPort("Input", "");
}
/** Returns the position to use for the pop up letting the user select a target. */
private Point getTargetPopupPos() {
java.awt.Point pos = MouseInfo.getPointerInfo().getLocation();
return new Point(pos.x, pos.y);
}
/** Returns the position to use for the pop up letting the user select a source. */
private Point getSourcePopupPos(ConnectionDragContext context) {
org.fortiss.tooling.base.model.layout.Point targetPos = context.getTargetPosition();
// Big hack to get the absolute position of the source and target cursor:
// since when the command is triggered the mouse should be at the same position as the
// target we can compute the difference and apply it to the source as well to retrieve
// the absolute coordinate of the source. Disgusting but works.
java.awt.Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
int relX = mouseLocation.x - targetPos.getX();
int relY = mouseLocation.y - targetPos.getY();
org.fortiss.tooling.base.model.layout.Point sourcePos = context.getSourcePosition();
return new Point(sourcePos.getX() + relX, sourcePos.getY() + relY);
}
/** Pop-up to use to let the user select the object they want to create. */
private class EndSelectionPopup extends org.eclipse.jface.dialogs.PopupDialog {
/** The item selected by the user. */
private EObject selectedItem;
/**
* Are we focusing on the source or the target of the connection ?
* Allows to create the relevant object (input or output port?).
*/
private boolean isTarget;
/** Position where to display the pop-up. Depends on the drag-and-drop gesture. */
private Point position;
/** Returns selectedItem. */
public EObject getSelectedItem() {
return selectedItem;
}
/** Constructor. */
public EndSelectionPopup(Point popupPosition, boolean isTarget) {
super(Display.getCurrent().getActiveShell(), PopupDialog.INFOPOPUP_SHELLSTYLE, true,
false, true, false, false, "Add", null);
this.isTarget = isTarget;
this.position = popupPosition;
}
/** {@inheritDoc} */
@Override
protected Point getDefaultLocation(Point initialSize) {
return this.position;
}
/** Fake class to get a cancel button. */
private class Cancel {
// Nothing to do.
}
/** {@inheritDoc} */
@Override
protected Control createDialogArea(Composite parent) {
TableViewer viewer;
viewer = new TableViewer(parent);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ModelElementLabelProvider() {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
return element instanceof Cancel ? "Cancel" : super.getText(element);
}
});
Component comp = ComponentModelElementFactory.createComponent("Component", "");
Port port;
port = createPort(isTarget);
Object[] prototypes = {comp, port, new Cancel()};
viewer.setInput(prototypes);
viewer.getTable().addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
StructuredSelection selection = (StructuredSelection)viewer.getSelection();
Object sel = selection.getFirstElement();
selectedItem = sel instanceof Cancel ? null : (EObject)sel;
close();
}
});
return parent;
}
}
/** {@inheritDoc} */
@Override
public boolean canDisconnect(EObject connection) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment