use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class PasteWidgetsAction method createPasteCommand.
/**
* Creates the paste command.
*
* @return Command The paste command
*/
public Command createPasteCommand() {
AbstractContainerModel targetModel = getTargetContainerModel();
List<AbstractWidgetModel> widgets = getWidgetsFromClipboard();
if (widgets != null) {
if (_cursorLocation == null) {
this.fetchCurrentCursorLocation();
}
Control cursorControl = Display.getCurrent().getCursorControl();
Point pastePoint;
if (isCursorAboveTargetContainer(cursorControl, targetModel)) {
pastePoint = getCursorRelativePositionToTargetContainer(getCursorLocationOnDisplay(cursorControl), targetModel);
// move the cursor location so that the user could know he has pasted how many widgets.
Display.getCurrent().setCursorLocation(_cursorLocation.x + 10, _cursorLocation.y + 10);
} else {
Random rand = new Random();
pastePoint = new Point(rand.nextInt(20), rand.nextInt(20));
}
List<Point> intrinsicLocations = getWidgetsIntrinsicRelativePositions(widgets);
CompoundCommand cmd = new CompoundCommand("Paste " + widgets.size() + " Widget" + (widgets.size() > 0 ? "s" : ""));
int i = 0;
for (AbstractWidgetModel widgetModel : widgets) {
// create command
cmd.add(new WidgetCreateCommand(widgetModel, targetModel, new Rectangle(intrinsicLocations.get(i).translate(pastePoint), widgetModel.getSize()), (i == 0 ? false : true)));
i++;
}
_cursorLocation = null;
return cmd;
}
return null;
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class PasteWidgetsAction method getAbsolutePosition.
/**
* @param widgetModel
* @return the absolute position of a widget relative to display.
*/
private Point getAbsolutePosition(AbstractWidgetModel widgetModel) {
if (widgetModel instanceof DisplayModel)
return new Point(0, 0);
Point result = widgetModel.getLocation();
AbstractContainerModel parent = widgetModel.getParent();
while (!(parent instanceof DisplayModel)) {
result.translate(parent.getLocation());
parent = parent.getParent();
}
return result;
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class CreateGroupAction method getSelectedWidgetModels.
// /**
// * Gets the widget models of all currently selected EditParts.
// *
// * @return a list with all widget models that are currently selected
// */
// protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
//
// List<AbstractWidgetModel> selectedWidgetModels = new ArrayList<AbstractWidgetModel>();
//
// for (Object o : selection.toList()) {
// if (o instanceof AbstractBaseEditPart) {
// selectedWidgetModels.add(((AbstractBaseEditPart) o)
// .getWidgetModel());
// }
// }
// return selectedWidgetModels;
// }
//
/**
* Gets the widget models of all currently selected EditParts.
*
* @return a list with all widget models that are currently selected.
* The order of the selected widgets was kept.
*/
protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
// List selection = getSelectedObjects();
List<AbstractWidgetModel> sameParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> differentParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> result = new ArrayList<AbstractWidgetModel>();
AbstractContainerModel parent = null;
for (Object o : selection.toList()) {
if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
AbstractWidgetModel widgetModel = ((AbstractBaseEditPart) o).getWidgetModel();
if (parent == null)
parent = widgetModel.getParent();
if (widgetModel.getParent() == parent)
sameParentModels.add(widgetModel);
else
differentParentModels.add(widgetModel);
}
}
// sort widgets to its original order
if (sameParentModels.size() > 1) {
AbstractWidgetModel[] modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {
@Override
public int compare(AbstractWidgetModel o1, AbstractWidgetModel o2) {
if (o1.getParent().getChildren().indexOf(o1) > o2.getParent().getChildren().indexOf(o2))
return 1;
else
return -1;
}
});
result.addAll(Arrays.asList(modelArray));
if (differentParentModels.size() > 0)
result.addAll(differentParentModels);
return result;
}
if (differentParentModels.size() > 0)
sameParentModels.addAll(differentParentModels);
return sameParentModels;
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class CreateGroupAction method run.
@Override
public void run(IAction action) {
List<AbstractWidgetModel> originalSelectedWidgets = getSelectedWidgetModels();
CompoundCommand compoundCommand = new CompoundCommand("Create Group");
List<AbstractWidgetModel> selectedWidgets = new ArrayList<AbstractWidgetModel>();
selectedWidgets.addAll(originalSelectedWidgets);
// remove the selected widgets which are children of another selected widget.
for (AbstractWidgetModel widget : originalSelectedWidgets) {
if (widget instanceof DisplayModel) {
selectedWidgets.remove(widget);
continue;
}
if (widget instanceof AbstractContainerModel) {
for (AbstractWidgetModel child : originalSelectedWidgets) {
if (((AbstractContainerModel) widget).getChildren().contains(child))
selectedWidgets.remove(child);
}
}
}
int minDepth = Integer.MAX_VALUE;
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
AbstractWidgetModel minDepthWidget = selectedWidgets.get(0);
for (AbstractWidgetModel widget : selectedWidgets) {
int leftX = widget.getLocation().x;
int upY = widget.getLocation().y;
int rightX = widget.getLocation().x + widget.getSize().width;
int bottomY = widget.getLocation().y + widget.getSize().height;
int depth = widget.getNestedDepth();
if (leftX < minX)
minX = leftX;
if (upY < minY)
minY = upY;
if (rightX > maxX)
maxX = rightX;
if (bottomY > maxY)
maxY = bottomY;
if (minDepth > depth) {
minDepth = depth;
minDepthWidget = widget;
}
}
// Orphan order should be reversed so that undo operation has the correct order.
AbstractWidgetModel[] widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
for (int i = widgetsArray.length - 1; i >= 0; i--) {
compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
}
GroupingContainerModel groupingContainerModel = new GroupingContainerModel();
SchemaService.getInstance().applySchema(groupingContainerModel);
// the parent should be the widget with minimum nested depth
AbstractContainerModel parent = minDepthWidget.getParent();
int borderWidth = 0;
if (groupingContainerModel.getBorderStyle() == BorderStyle.GROUP_BOX)
borderWidth = 30;
groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN, true);
groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_SHOW_SCROLLBAR, false);
compoundCommand.add(new WidgetCreateCommand(groupingContainerModel, parent, new Rectangle(minX, minY, maxX - minX + borderWidth, maxY - minY + borderWidth), false));
for (AbstractWidgetModel widget : selectedWidgets) {
compoundCommand.add(new AddWidgetCommand(groupingContainerModel, widget, new Rectangle(widget.getLocation().translate(-minX, -minY), widget.getSize())));
}
execute(compoundCommand);
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class ChangeOrderAction method fillWidgetMap.
/**
* @param widgetMap
*/
private void fillWidgetMap(Map<AbstractContainerModel, List<IndexedWidget>> widgetMap) {
for (Object selection : getSelectedObjects()) {
if (selection instanceof AbstractBaseEditPart) {
AbstractBaseEditPart widgetEditpart = (AbstractBaseEditPart) selection;
AbstractWidgetModel widgetModel = (AbstractWidgetModel) widgetEditpart.getModel();
if (widgetEditpart.getParent() != null && widgetModel.getParent() != null) {
AbstractContainerModel containerModel = (AbstractContainerModel) widgetEditpart.getParent().getModel();
if (!widgetMap.containsKey(containerModel)) {
widgetMap.put(containerModel, new LinkedList<IndexedWidget>());
}
widgetMap.get(containerModel).add(new IndexedWidget(containerModel.getIndexOf(widgetModel), widgetModel));
}
}
}
}
Aggregations