use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart in project knime-core by knime.
the class WorkflowSelectionDragEditPartsTracker method getCommand.
/**
* Asks each edit part in the
* {@link org.eclipse.gef.tools.AbstractTool#getOperationSet() operation set}
* to contribute to a {@link CompoundCommand} after first setting the
* request type to either {@link org.eclipse.gef.RequestConstants#REQ_MOVE}
* or {@link org.eclipse.gef.RequestConstants#REQ_ORPHAN}, depending on the
* result of {@link #isMove()}.
*
* Additionally the method creates a command to adapt connections where both
* node container are include in the drag operation.
*
* {@inheritDoc}
*/
@Override
protected Command getCommand() {
CompoundCommand command = new CompoundCommand();
command.setDebugLabel("Drag Object Tracker");
Iterator iter = getOperationSet().iterator();
Request request = getTargetRequest();
if (isCloneActive()) {
request.setType(REQ_CLONE);
} else if (isMove()) {
request.setType(REQ_MOVE);
} else {
request.setType(REQ_ORPHAN);
}
if (!isCloneActive()) {
while (iter.hasNext()) {
EditPart editPart = (EditPart) iter.next();
command.add(editPart.getCommand(request));
}
}
// now add the commands for the node-embraced connections
ConnectionContainerEditPart[] connectionsToAdapt = getEmbracedConnections(getOperationSet());
for (ConnectionContainerEditPart connectionPart : connectionsToAdapt) {
command.add(connectionPart.getBendpointAdaptionCommand(request));
}
if (!isMove() || isCloneActive()) {
if (!isCloneActive()) {
request.setType(REQ_ADD);
}
if (getTargetEditPart() == null) {
command.add(UnexecutableCommand.INSTANCE);
} else {
command.add(getTargetEditPart().getCommand(getTargetRequest()));
}
}
return command;
}
use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart in project knime-core by knime.
the class WorkflowMarqueeSelectionTool method calculateNewSelection.
private void calculateNewSelection(final Collection<GraphicalEditPart> newSelections, final Collection<GraphicalEditPart> deselections) {
Rectangle marqueeRect = getMarqueeSelectionRectangle();
for (Iterator<GraphicalEditPart> itr = getAllChildren().iterator(); itr.hasNext(); ) {
GraphicalEditPart child = itr.next();
IFigure figure = child.getFigure();
if (!child.isSelectable() || child.getTargetEditPart(MARQUEE_REQUEST) != child || !isFigureVisible(figure) || !figure.isShowing()) {
continue;
}
if (!(child instanceof NodeContainerEditPart || child instanceof ConnectionContainerEditPart || child instanceof AbstractWorkflowPortBarEditPart || child instanceof AnnotationEditPart)) {
continue;
}
Rectangle r = figure.getBounds().getCopy();
figure.translateToAbsolute(r);
boolean included = false;
if (child instanceof ConnectionEditPart && marqueeRect.intersects(r)) {
Rectangle relMarqueeRect = Rectangle.SINGLETON;
figure.translateToRelative(relMarqueeRect.setBounds(marqueeRect));
included = ((PolylineConnection) figure).getPoints().intersects(relMarqueeRect);
} else if (child instanceof AnnotationEditPart) {
// select WorkflowAnnotations only if they are fully included in the selection
if (figure instanceof WorkflowAnnotationFigure) {
included = marqueeRect.contains(r);
}
} else if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
included = marqueeRect.intersects(r);
} else {
included = marqueeRect.contains(r);
}
if (included) {
if (isToggle()) {
if (wasSelected(child)) {
deselections.add(child);
} else {
newSelections.add(child);
}
} else {
newSelections.add(child);
}
} else if (isToggle()) {
// readded if it was in the selection before
if (wasSelected(child)) {
newSelections.add(child);
} else {
deselections.add(child);
}
}
}
if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
calculateConnections(newSelections, deselections);
}
}
use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart in project knime-core by knime.
the class AbstractClipboardAction method getSelectedConnectionParts.
/**
* @return The selected <code>ConnectionContainerEditParts</code>, may be
* empty
*/
protected ConnectionContainerEditPart[] getSelectedConnectionParts() {
ArrayList<ConnectionContainerEditPart> objects = new ArrayList<ConnectionContainerEditPart>(getSelectedObjects());
// parts for a ConnectionContainer
for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
Object element = iter.next();
if (!(element instanceof ConnectionContainerEditPart)) {
iter.remove();
continue;
}
}
final ConnectionContainerEditPart[] parts = objects.toArray(new ConnectionContainerEditPart[objects.size()]);
return parts;
}
use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart in project knime-core by knime.
the class ConnectionBendpointEditPolicy method getDeleteBendpointCommand.
/**
* {@inheritDoc}
*/
protected Command getDeleteBendpointCommand(final BendpointRequest req) {
// get the index of the bendpoint to delete
int index = req.getIndex();
ConnectionContainerEditPart editPart = (ConnectionContainerEditPart) getHost();
WorkflowManager wfm = getWorkflowManager();
return new NewBendpointDeleteCommand(editPart, wfm, index);
}
use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart in project knime-core by knime.
the class SnapToPortGeometry method populateRowsAndCols.
/**
* Updates the cached row and column Entries using the provided parts.
* Columns are only the center of a node figure while rows are all ports of
* a node.
*
* @param parts a List of EditParts
*/
protected void populateRowsAndCols(final List parts, final List dragedParts) {
// add the port edit parts to a list
List<AbstractPortEditPart> portList = getPorts(parts);
// create all row relevant points fromt the port list
List<Entry> rowVector = new ArrayList<Entry>();
for (int i = 0; i < portList.size(); i++) {
GraphicalEditPart child = portList.get(i);
Rectangle bounds = getFigureBounds(child);
// get information is this is an inport
boolean inport = false;
if (portList.get(i) instanceof NodeInPortEditPart || portList.get(i) instanceof WorkflowInPortEditPart) {
inport = true;
}
// get information is this is a model port
rowVector.add(new Entry(0, bounds.y + (bounds.height - 1) / 2, inport, portList.get(i).getType()));
}
// add the port edit parts to a list
List<AbstractPortEditPart> dargedPortList = getPorts(dragedParts);
for (int i = 0; i < dargedPortList.size(); i++) {
// for each port get a possible connection (if connected)
AbstractPortEditPart portPart = dargedPortList.get(i);
List sourceConnections = portPart.getSourceConnections();
for (int j = 0; j < sourceConnections.size(); j++) {
ConnectionContainerEditPart conPart = (ConnectionContainerEditPart) sourceConnections.get(j);
Point p = ((Connection) conPart.getFigure()).getPoints().getPoint(2);
rowVector.add(new Entry(0, p.y, true, portPart.getType()));
}
List targetConnections = portPart.getTargetConnections();
for (int j = 0; j < targetConnections.size(); j++) {
ConnectionContainerEditPart conPart = (ConnectionContainerEditPart) targetConnections.get(j);
PointList pList = ((Connection) conPart.getFigure()).getPoints();
Point p = pList.getPoint(pList.size() - 3);
rowVector.add(new Entry(0, p.y, false, portPart.getType()));
}
}
List<Entry> colVector = new ArrayList<Entry>();
for (int i = 0; i < parts.size(); i++) {
GraphicalEditPart child = (GraphicalEditPart) parts.get(i);
Rectangle bounds = getFigureBounds(child);
colVector.add(new Entry(0, bounds.x + (bounds.width - 1) / 2));
}
m_rows = rowVector.toArray(new Entry[rowVector.size()]);
m_cols = colVector.toArray(new Entry[colVector.size()]);
}
Aggregations