use of org.csstudio.opibuilder.commands.WidgetSetConstraintCommand 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.WidgetSetConstraintCommand in project yamcs-studio by yamcs.
the class ArrayLayoutEditPolicy method addUpdateContainerCommands.
protected void addUpdateContainerCommands(AbstractContainerModel container, Dimension widgetSize, CompoundCommand result) {
int elementsCount = getHostArrayEditPart().getArrayFigure().calcVisibleElementsCount(widgetSize);
Dimension proposedContainerSize = getHostArrayEditPart().getArrayFigure().calcWidgetSizeForElements(elementsCount, widgetSize);
result.add(new WidgetSetConstraintCommand(container, null, new Rectangle(container.getLocation(), proposedContainerSize)));
result.add(new SetWidgetPropertyCommand(container, ArrayModel.PROP_VISIBLE_ELEMENTS_COUNT, elementsCount));
}
Aggregations