use of org.csstudio.opibuilder.commands.ChangeGuideCommand 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.csstudio.opibuilder.commands.ChangeGuideCommand in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method chainGuideDetachmentCommand.
/**
* Adds a ChangeGuideCommand to the given Command.
*
* @param request
* The request
* @param part
* The AbstractWidgetEditPart, which model should be detached
* from a guide
* @param cmd
* The Command
* @param horizontal
* A boolean, true if the guide is horizontal, false otherwise
* @return Command The given command
*/
private Command chainGuideDetachmentCommand(final Request request, final AbstractBaseEditPart part, final Command cmd, final boolean horizontal) {
Command result = cmd;
// Detach from guide, if none is given
Integer guidePos = (Integer) request.getExtendedData().get(horizontal ? SnapToGuides.KEY_HORIZONTAL_GUIDE : SnapToGuides.KEY_VERTICAL_GUIDE);
if (guidePos == null) {
result = result.chain(new ChangeGuideCommand(part.getWidgetModel(), horizontal));
}
return result;
}
use of org.csstudio.opibuilder.commands.ChangeGuideCommand in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method chainGuideAttachmentCommand.
/**
* Adds a ChangeGuideCommand to the given Command.
*
* @param request
* The Request
* @param part
* The AbstractWidgetEditPart, which model should be detached
* from a guide
* @param cmd
* The Command
* @param horizontal
* A boolean, true if the guide is horizontal, false otherwise
* @return Command The given command
*/
private Command chainGuideAttachmentCommand(final Request request, final AbstractBaseEditPart part, final Command cmd, final boolean horizontal) {
Command result = cmd;
// Attach to guide, if one is given
Integer guidePos = (Integer) request.getExtendedData().get(horizontal ? SnapToGuides.KEY_HORIZONTAL_GUIDE : SnapToGuides.KEY_VERTICAL_GUIDE);
if (guidePos != null) {
int alignment = ((Integer) request.getExtendedData().get(horizontal ? SnapToGuides.KEY_HORIZONTAL_ANCHOR : SnapToGuides.KEY_VERTICAL_ANCHOR)).intValue();
ChangeGuideCommand cgm = new ChangeGuideCommand(part.getWidgetModel(), horizontal);
cgm.setNewGuide(findGuideAt(guidePos.intValue(), horizontal), alignment);
result = result.chain(cgm);
}
return result;
}
Aggregations