use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class NativeTextEditpart method registerPropertyChangeHandlers.
@Override
protected void registerPropertyChangeHandlers() {
super.registerPropertyChangeHandlers();
removeAllPropertyChangeHandlers(NativeTextModel.PROP_ALIGN_H);
PropertyChangeListener updatePropSheetListener = evt -> updatePropSheet();
getWidgetModel().getProperty(NativeTextModel.PROP_MULTILINE_INPUT).addPropertyChangeListener(updatePropSheetListener);
IWidgetPropertyChangeHandler handler = (oldValue, newValue, figure) -> {
AbstractWidgetModel model = getWidgetModel();
var parent = model.getParent();
parent.removeChild(model);
parent.addChild(model);
parent.selectWidget(model, true);
return false;
};
setPropertyChangeHandler(NativeTextModel.PROP_SHOW_NATIVE_BORDER, handler);
setPropertyChangeHandler(NativeTextModel.PROP_MULTILINE_INPUT, handler);
setPropertyChangeHandler(NativeTextModel.PROP_WRAP_WORDS, handler);
setPropertyChangeHandler(NativeTextModel.PROP_SHOW_H_SCROLL, handler);
setPropertyChangeHandler(NativeTextModel.PROP_SHOW_V_SCROLL, handler);
setPropertyChangeHandler(NativeTextModel.PROP_PASSWORD_INPUT, handler);
setPropertyChangeHandler(NativeTextModel.PROP_ALIGN_H, handler);
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class AbstractContainerEditpart method registerBasePropertyChangeHandlers.
@Override
protected void registerBasePropertyChangeHandlers() {
super.registerBasePropertyChangeHandlers();
setPropertyChangeHandler(PROP_MACROS, (oldValue, newValue, figure) -> {
var macrosInput = (MacrosInput) newValue;
var macrosMap = new LinkedHashMap<String, String>();
if (macrosInput.isInclude_parent_macros()) {
macrosMap.putAll(getWidgetModel().getParentMacroMap());
}
macrosMap.putAll(macrosInput.getMacrosMap());
getWidgetModel().setMacroMap(macrosMap);
return false;
});
layout();
childrenPropertyChangeListener = evt -> {
if (evt.getOldValue() instanceof Integer) {
addChild(createChild(evt.getNewValue()), ((Integer) evt.getOldValue()).intValue());
layout();
} else if (evt.getOldValue() instanceof AbstractWidgetModel) {
var child = (EditPart) getViewer().getEditPartRegistry().get(evt.getOldValue());
if (child != null) {
removeChild(child);
layout();
}
} else {
refreshChildren();
}
};
getWidgetModel().getChildrenProperty().addPropertyChangeListener(childrenPropertyChangeListener);
if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
selectionPropertyChangeListener = new PropertyChangeListener() {
@SuppressWarnings("unchecked")
@Override
public void propertyChange(PropertyChangeEvent evt) {
var widgets = (List<AbstractWidgetModel>) evt.getNewValue();
var widgetEditparts = new ArrayList<EditPart>();
for (var w : widgets) {
var e = (EditPart) getViewer().getEditPartRegistry().get(w);
if (e != null) {
widgetEditparts.add(e);
}
}
if (!(Boolean) evt.getOldValue()) {
// append
getViewer().deselectAll();
}
for (var editpart : widgetEditparts) {
if (editpart.isSelectable()) {
getViewer().appendSelection(editpart);
}
}
}
};
getWidgetModel().getSelectionProperty().addPropertyChangeListener(selectionPropertyChangeListener);
}
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class LayoutWidgetsImp method run.
public static void run(AbstractLayoutEditpart layoutWidget, CommandStack commandStack) {
var container = layoutWidget.getWidgetModel().getParent();
List<AbstractWidgetModel> modelChildren = new ArrayList<>();
modelChildren.addAll(container.getChildren());
modelChildren.remove(layoutWidget.getWidgetModel());
if (modelChildren.size() == 0) {
return;
}
var newBounds = layoutWidget.getNewBounds(modelChildren, container.getBounds());
var compoundCommand = new CompoundCommand("Layout Widgets");
var i = 0;
for (var model : modelChildren) {
compoundCommand.add(new SetBoundsCommand(model, newBounds.get(i)));
i++;
}
commandStack.execute(compoundCommand);
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class CreateGroupAction method run.
@Override
public void run(IAction action) {
var originalSelectedWidgets = getSelectedWidgetModels();
var compoundCommand = new CompoundCommand("Create Group");
List<AbstractWidgetModel> selectedWidgets = new ArrayList<>();
selectedWidgets.addAll(originalSelectedWidgets);
// remove the selected widgets which are children of another selected widget.
for (var widget : originalSelectedWidgets) {
if (widget instanceof DisplayModel) {
selectedWidgets.remove(widget);
continue;
}
if (widget instanceof AbstractContainerModel) {
for (var child : originalSelectedWidgets) {
if (((AbstractContainerModel) widget).getChildren().contains(child)) {
selectedWidgets.remove(child);
}
}
}
}
var minDepth = Integer.MAX_VALUE;
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
var minDepthWidget = selectedWidgets.get(0);
for (var widget : selectedWidgets) {
var leftX = widget.getLocation().x;
var upY = widget.getLocation().y;
var rightX = widget.getLocation().x + widget.getSize().width;
var bottomY = widget.getLocation().y + widget.getSize().height;
var 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.
var widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
for (var i = widgetsArray.length - 1; i >= 0; i--) {
compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
}
var groupingContainerModel = new GroupingContainerModel();
SchemaService.getInstance().applySchema(groupingContainerModel);
// the parent should be the widget with minimum nested depth
var parent = minDepthWidget.getParent();
var 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 (var 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.AbstractWidgetModel 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 (var 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<>();
List<AbstractWidgetModel> differentParentModels = new ArrayList<>();
List<AbstractWidgetModel> result = new ArrayList<>();
AbstractContainerModel parent = null;
for (var o : selection.toList()) {
if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
var 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) {
var modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
Arrays.sort(modelArray, (o1, 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;
}
Aggregations