use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class WidgetTreeContainerEditPolicy method getMoveChildrenCommand.
@Override
protected Command getMoveChildrenCommand(ChangeBoundsRequest request) {
CompoundCommand command = new CompoundCommand();
@SuppressWarnings("rawtypes") List editparts = request.getEditParts();
@SuppressWarnings("rawtypes") List children = getHost().getChildren();
int newIndex = findIndexOfTreeItemAt(request.getLocation());
int tempIndex = newIndex;
for (int i = 0; i < editparts.size(); i++) {
EditPart child = (EditPart) editparts.get(editparts.size() - 1 - i);
int oldIndex = children.indexOf(child);
if (oldIndex == tempIndex || oldIndex + 1 == tempIndex) {
command.add(UnexecutableCommand.INSTANCE);
return command;
} else if (oldIndex <= tempIndex) {
tempIndex--;
}
command.add(new ChangeOrderCommand(tempIndex, (AbstractContainerModel) getHost().getModel(), (AbstractWidgetModel) child.getModel()));
}
return command;
}
use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class WidgetTreeContainerEditPolicy method getAddCommand.
@Override
protected Command getAddCommand(ChangeBoundsRequest request) {
CompoundCommand cmd = new CompoundCommand();
@SuppressWarnings("rawtypes") List editparts = request.getEditParts();
int index = findIndexOfTreeItemAt(request.getLocation());
for (int i = 0; i < editparts.size(); i++) {
EditPart child = (EditPart) editparts.get(index >= 0 ? editparts.size() - 1 - i : i);
if (isAncestor(child, getHost())) {
cmd.add(UnexecutableCommand.INSTANCE);
} else {
AbstractWidgetModel childModel = (AbstractWidgetModel) child.getModel();
cmd.add(createCreateCommand(childModel, new Rectangle(new Point(), childModel.getSize()), index, "Reparent Widgets"));
}
}
return cmd;
}
use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method getResizeChildrenCommand.
// This has been overriden to fix a bug when handle bounds does not equal with bounds. For example, polyline figue.
/* (non-Javadoc)
* @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#getResizeChildrenCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
*/
@Override
protected Command getResizeChildrenCommand(ChangeBoundsRequest request) {
CompoundCommand resize = new CompoundCommand();
Command c;
GraphicalEditPart child;
List<?> children = request.getEditParts();
for (int i = 0; i < children.size(); i++) {
child = (GraphicalEditPart) children.get(i);
c = createChangeConstraintCommand(request, child, translateToModelConstraint(getConstraintForResize(request, child)));
resize.add(c);
}
return resize.unwrap();
}
use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method createChangeConstraintCommand.
@Override
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
return super.createChangeConstraintCommand(request, child, constraint);
AbstractBaseEditPart part = (AbstractBaseEditPart) child;
AbstractWidgetModel widgetModel = part.getWidgetModel();
IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(widgetModel.getTypeID());
Command cmd = null;
if (feedbackFactory != null)
cmd = feedbackFactory.createChangeBoundsCommand(widgetModel, request, (Rectangle) constraint);
if (cmd == null)
cmd = new WidgetSetConstraintCommand(widgetModel, request, (Rectangle) constraint);
List<ConnectionModel> allConnections = new ArrayList<ConnectionModel>(part.getWidgetModel().getSourceConnections());
allConnections.addAll(part.getWidgetModel().getTargetConnections());
if (part.getWidgetModel() instanceof AbstractContainerModel) {
for (AbstractWidgetModel d : ((AbstractContainerModel) part.getWidgetModel()).getAllDescendants()) {
allConnections.addAll(d.getSourceConnections());
allConnections.addAll(d.getTargetConnections());
}
}
if (allConnections.size() > 0) {
CompoundCommand reRouteCmd = new CompoundCommand();
for (ConnectionModel srcConn : allConnections) {
reRouteCmd.add(new SetWidgetPropertyCommand(srcConn, ConnectionModel.PROP_POINTS, new PointList()));
}
cmd = cmd.chain(reRouteCmd);
}
if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
if (guidePos != null) {
cmd = chainGuideAttachmentCommand(request, part, cmd, true);
} else if (GuideUtil.getInstance().getGuide(widgetModel, true) != null) {
// SnapToGuides didn't provide a horizontal guide, but
// this part is attached
// to a horizontal guide. Now we check to see if the
// part is attached to
// the guide along the edge being resized. If that is
// the case, we need to
// detach the part from the guide; otherwise, we leave
// it alone.
int alignment = GuideUtil.getInstance().getGuide(widgetModel, true).getAlignment(widgetModel);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
cmd = cmd.chain(new ChangeGuideCommand(widgetModel, true));
}
}
}
if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
if (guidePos != null) {
cmd = chainGuideAttachmentCommand(request, part, cmd, false);
} else if (GuideUtil.getInstance().getGuide(widgetModel, false) != null) {
int alignment = GuideUtil.getInstance().getGuide(widgetModel, false).getAlignment(widgetModel);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.WEST) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
cmd = cmd.chain(new ChangeGuideCommand(widgetModel, false));
}
}
}
if (request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_ALIGN_CHILDREN)) {
cmd = chainGuideAttachmentCommand(request, part, cmd, true);
cmd = chainGuideAttachmentCommand(request, part, cmd, false);
cmd = chainGuideDetachmentCommand(request, part, cmd, true);
cmd = chainGuideDetachmentCommand(request, part, cmd, false);
}
return cmd;
}
use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method getCreateCommand.
@Override
protected Command getCreateCommand(CreateRequest request) {
String typeId = determineTypeIdFromRequest(request);
IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(typeId);
Command widgetCreateCommand = createWidgetCreateCommand(request);
if (widgetCreateCommand == null)
return null;
if (feedbackFactory != null) {
CompoundCommand compoundCommand = new CompoundCommand();
compoundCommand.add(widgetCreateCommand);
Command initialBoundsCommand = feedbackFactory.createInitialBoundsCommand((AbstractWidgetModel) request.getNewObject(), request, (Rectangle) getConstraintFor(request));
if (initialBoundsCommand != null)
compoundCommand.add(initialBoundsCommand);
return compoundCommand;
} else
return widgetCreateCommand;
}
Aggregations