use of org.csstudio.opibuilder.model.AbstractWidgetModel 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.AbstractWidgetModel in project yamcs-studio by yamcs.
the class ArrayEditPart method createChild.
@Override
protected EditPart createChild(Object model) {
final AbstractWidgetModel child = (AbstractWidgetModel) model;
for (String propId : child.getAllPropertyIDs()) child.getProperty(propId).addPropertyChangeListener(syncPropertiesListener);
final EditPart result = super.createChild(model);
UIBundlingThread.getInstance().addRunnable(getViewer().getControl().getDisplay(), new Runnable() {
@Override
public void run() {
hookChild(result, getChildren().indexOf(result), true);
}
});
return result;
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class ArrayEditPart method removeChild.
@Override
protected void removeChild(EditPart child) {
super.removeChild(child);
AbstractWidgetModel childModel = ((AbstractBaseEditPart) child).getWidgetModel();
// recover property visibility
if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
for (String propId : INVISIBLE_CHILD_PROPIDS) try {
childModel.setPropertyVisibleAndSavable(propId, true, true);
} catch (NonExistPropertyException e) {
}
}
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class ArrayLayoutEditPolicy method createWidgetCreateCommand.
@Override
protected Command createWidgetCreateCommand(CreateRequest request) {
AbstractContainerModel container = (AbstractContainerModel) getHost().getModel();
if (!container.getChildren().isEmpty())
return null;
CompoundCommand result = new CompoundCommand("Create widget in array");
Dimension size = ((Rectangle) getConstraintFor(request)).getSize();
AbstractWidgetModel widget = (AbstractWidgetModel) request.getNewObject();
if (size == null || size.width < 1 || size.height < 1)
size = widget.getSize();
addUpdateContainerCommands(container, size, result);
WidgetCreateCommand widgetCreateCommand = new WidgetCreateCommand(widget, container, (Rectangle) getConstraintFor(request), false, true);
result.add(widgetCreateCommand);
return result;
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class LinkingContainerEditpart method layout.
@Override
public void layout() {
AbstractLayoutEditpart layoutter = getLayoutWidget();
if (layoutter != null && layoutter.getWidgetModel().isEnabled()) {
List<AbstractWidgetModel> modelChildren = new ArrayList<AbstractWidgetModel>();
for (Object child : getChildren()) {
if (child instanceof AbstractBaseEditPart && !(child instanceof AbstractLayoutEditpart)) {
modelChildren.add(((AbstractBaseEditPart) child).getWidgetModel());
}
}
layoutter.layout(modelChildren, getFigure().getClientArea());
}
}
Aggregations