use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class LayoutWidgetsImp method run.
public static void run(AbstractLayoutEditpart layoutWidget, CommandStack commandStack) {
AbstractContainerModel container = layoutWidget.getWidgetModel().getParent();
List<AbstractWidgetModel> modelChildren = new ArrayList<AbstractWidgetModel>();
modelChildren.addAll(container.getChildren());
modelChildren.remove(layoutWidget.getWidgetModel());
if (modelChildren.size() == 0)
return;
List<Rectangle> newBounds = layoutWidget.getNewBounds(modelChildren, container.getBounds());
CompoundCommand compoundCommand = new CompoundCommand("Layout Widgets");
int i = 0;
for (AbstractWidgetModel model : modelChildren) {
compoundCommand.add(new SetBoundsCommand(model, newBounds.get(i)));
i++;
}
commandStack.execute(compoundCommand);
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class ReplaceWidgetCommand method getAllConnections.
private List<ConnectionModel> getAllConnections(AbstractWidgetModel widget, boolean source) {
List<ConnectionModel> result = new ArrayList<ConnectionModel>();
result.addAll(source ? widget.getSourceConnections() : widget.getTargetConnections());
if (widget instanceof AbstractContainerModel) {
for (AbstractWidgetModel child : ((AbstractContainerModel) widget).getAllDescendants()) {
result.addAll(source ? child.getSourceConnections() : child.getTargetConnections());
}
}
return result;
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class WidgetCreateCommand method redo.
@Override
public void redo() {
if (newWidget instanceof AbstractLayoutModel && container.getLayoutWidget() != null) {
MessageDialog.openError(null, "Creating widget failed", "There is already a layout widget in the container. " + "Please delete it before you can add a new layout widget.");
return;
}
if (bounds != null) {
newWidget.setLocation(bounds.x, bounds.y);
if (bounds.width > 0 && bounds.height > 0)
newWidget.setSize(bounds.width, bounds.height);
}
boolean autoName = false;
for (AbstractWidgetModel child : container.getChildren()) {
if (child.getName().equals(newWidget.getName()))
autoName = true;
}
if (autoName) {
Map<String, Integer> nameMap = new HashMap<String, Integer>();
for (AbstractWidgetModel child : container.getChildren()) {
String key = child.getName();
int tailNo = 0;
if (key.matches(".*_\\d+")) {
// $NON-NLS-1$
// $NON-NLS-1$
int i = key.lastIndexOf('_');
tailNo = Integer.parseInt(key.substring(i + 1));
key = key.substring(0, i);
}
if (nameMap.containsKey(key))
nameMap.put(key, Math.max(nameMap.get(key) + 1, tailNo));
else
nameMap.put(key, 0);
}
String nameHead = newWidget.getName();
if (nameHead.matches(".*_\\d+")) {
// $NON-NLS-1$
// $NON-NLS-1$
nameHead = nameHead.substring(0, nameHead.lastIndexOf('_'));
}
newWidget.setName(nameHead + // $NON-NLS-1$
"_" + (nameMap.get(nameHead) == null ? 0 : nameMap.get(nameHead) + 1));
}
container.addChild(index, newWidget);
container.selectWidget(newWidget, append);
if (newWidget instanceof AbstractContainerModel) {
try {
XMLUtil.fillLinkingContainers((AbstractContainerModel) newWidget);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class PerformAutoSizeAction method run.
@Override
public void run(IAction action) {
if (getContainerEditpart().getChildren().size() <= 0) {
return;
}
CompoundCommand compoundCommand = new CompoundCommand("Perform AutoSize");
AbstractContainerEditpart containerEditpart = getContainerEditpart();
AbstractContainerModel containerModel = containerEditpart.getWidgetModel();
// temporary unlock children so children will not be resized.
if (containerEditpart instanceof GroupingContainerEditPart) {
compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, false));
}
IFigure figure = getContainerFigure();
Rectangle childrenRange = GeometryUtil.getChildrenRange(containerEditpart);
Point tranlateSize = new Point(childrenRange.x, childrenRange.y);
compoundCommand.add(new SetBoundsCommand(containerModel, new Rectangle(containerModel.getLocation().translate(tranlateSize), new Dimension(childrenRange.width + figure.getInsets().left + figure.getInsets().right, childrenRange.height + figure.getInsets().top + figure.getInsets().bottom))));
for (Object editpart : containerEditpart.getChildren()) {
AbstractWidgetModel widget = ((AbstractBaseEditPart) editpart).getWidgetModel();
compoundCommand.add(new SetBoundsCommand(widget, new Rectangle(widget.getLocation().translate(tranlateSize.getNegated()), widget.getSize())));
}
// recover lock
if (containerEditpart instanceof GroupingContainerEditPart) {
Object oldvalue = containerEditpart.getWidgetModel().getPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN);
compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, oldvalue));
}
execute(compoundCommand);
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class ActionButtonEditPart method registerPropertyChangeHandlers.
/**
* {@inheritDoc}
*/
@Override
protected void registerPropertyChangeHandlers() {
PropertyChangeListener styleListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
AbstractWidgetModel model = getWidgetModel();
WidgetDescriptor descriptor = WidgetsService.getInstance().getWidgetDescriptor(model.getTypeID());
String type = descriptor == null ? model.getTypeID().substring(model.getTypeID().lastIndexOf(".") + 1) : descriptor.getName();
model.setPropertyValue(AbstractWidgetModel.PROP_WIDGET_TYPE, type);
AbstractContainerModel parent = model.getParent();
parent.removeChild(model);
parent.addChild(model);
parent.selectWidget(model, true);
}
};
getWidgetModel().getProperty(ActionButtonModel.PROP_STYLE).addPropertyChangeListener(styleListener);
updatePropSheet();
delegate.registerPropertyChangeHandlers();
}
Aggregations