use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class OpenDisplayAction method getMacrosInput.
protected MacrosInput getMacrosInput() {
MacrosInput result = new MacrosInput(new LinkedHashMap<String, String>(), true);
MacrosInput macrosInput = ((MacrosInput) getPropertyValue(PROP_MACROS)).getCopy();
if (macrosInput.isInclude_parent_macros()) {
Map<String, String> macrosMap = getWidgetModel() instanceof AbstractContainerModel ? ((AbstractContainerModel) getWidgetModel()).getParentMacroMap() : getWidgetModel().getParent().getMacroMap();
result.getMacrosMap().putAll(macrosMap);
}
result.getMacrosMap().putAll(macrosInput.getMacrosMap());
return result;
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class WidgetComponentEditPolicy method createDeleteCommand.
@Override
protected Command createDeleteCommand(GroupRequest deleteRequest) {
Object containerModel = getHost().getParent().getModel();
Object widget = getHost().getModel();
if (containerModel instanceof AbstractContainerModel && widget instanceof AbstractWidgetModel)
return new WidgetDeleteCommand((AbstractContainerModel) containerModel, (AbstractWidgetModel) widget);
return super.createDeleteCommand(deleteRequest);
}
use of org.csstudio.opibuilder.model.AbstractContainerModel 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.csstudio.opibuilder.model.AbstractContainerModel 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.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method sortSelectedWidgets.
/**
* Sort the selected widget as they were in their parents
*
* @return a list with all widget editpart that are currently selected
*/
private final List<AbstractBaseEditPart> sortSelectedWidgets(List<?> selection) {
List<AbstractBaseEditPart> sameParentWidgets = new ArrayList<AbstractBaseEditPart>();
List<AbstractBaseEditPart> differentParentWidgets = new ArrayList<AbstractBaseEditPart>();
List<AbstractBaseEditPart> result = new ArrayList<AbstractBaseEditPart>();
AbstractContainerModel parent = null;
for (Object o : selection) {
if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
AbstractWidgetModel widgetModel = ((AbstractBaseEditPart) o).getWidgetModel();
if (parent == null)
parent = widgetModel.getParent();
if (widgetModel.getParent() == parent)
sameParentWidgets.add((AbstractBaseEditPart) o);
else
differentParentWidgets.add((AbstractBaseEditPart) o);
}
}
// sort widgets to its original order
if (sameParentWidgets.size() > 1) {
AbstractBaseEditPart[] modelArray = sameParentWidgets.toArray(new AbstractBaseEditPart[0]);
Arrays.sort(modelArray, new Comparator<AbstractBaseEditPart>() {
@Override
public int compare(AbstractBaseEditPart o1, AbstractBaseEditPart o2) {
if (o1.getWidgetModel().getParent().getChildren().indexOf(o1.getWidgetModel()) > o2.getWidgetModel().getParent().getChildren().indexOf(o2.getWidgetModel()))
return 1;
else
return -1;
}
});
result.addAll(Arrays.asList(modelArray));
if (differentParentWidgets.size() > 0)
result.addAll(differentParentWidgets);
return result;
}
if (differentParentWidgets.size() > 0)
sameParentWidgets.addAll(differentParentWidgets);
return sameParentWidgets;
}
Aggregations