use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class CloneCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
Clipboard clipboard = new Clipboard(Display.getCurrent());
DisplayModel tempModel = new DisplayModel();
for (AbstractWidgetModel widget : _models) {
tempModel.addChild(widget, false);
}
String xml = XMLUtil.widgetToXMLString(tempModel, false);
clipboard.setContents(new Object[] { xml }, new Transfer[] { OPIWidgetsTransfer.getInstance() });
_clonedWidgets = getWidgetsFromClipboard();
_compoundCommand = new CompoundCommand();
int i = 0;
for (AbstractWidgetModel widgetModel : _clonedWidgets) {
if (_difference != null) {
widgetModel.setLocation((widgetModel.getLocation().x + _difference.width), (widgetModel.getLocation().y + _difference.height));
} else {
widgetModel.setLocation((widgetModel.getLocation().x + 10), (widgetModel.getLocation().y + 10));
}
_compoundCommand.add(new WidgetCreateCommand(widgetModel, _parent, new Rectangle(widgetModel.getLocation(), widgetModel.getSize()), (i++ == 0 ? false : true)));
if (_hGuide != null) {
ChangeGuideCommand hGuideCommand = new ChangeGuideCommand(widgetModel, true);
hGuideCommand.setNewGuide(_hGuide, _hAlignment);
_compoundCommand.add(hGuideCommand);
}
if (_vGuide != null) {
ChangeGuideCommand vGuideCommand = new ChangeGuideCommand(widgetModel, false);
vGuideCommand.setNewGuide(_vGuide, _vAlignment);
_compoundCommand.add(vGuideCommand);
}
}
_compoundCommand.execute();
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class ReplaceWidgetCommand method redo.
@Override
public void redo() {
index = container.getIndexOf(srcWidget);
container.removeChild(srcWidget);
container.addChild(index, targetWidget);
for (ConnectionModel conn : sourceConnections) {
if (conn.getSource() == srcWidget)
conn.setSource(targetWidget);
}
for (ConnectionModel conn : targetConnections) {
if (conn.getTarget() == srcWidget)
conn.setTarget(targetWidget);
}
removeConnections(sourceConnections);
removeConnections(targetConnections);
List<AbstractWidgetModel> allDescendants = container.getAllDescendants();
for (ConnectionModel conn : sourceConnections) {
if (allDescendants.contains(conn.getSource()))
conn.reconnect();
}
for (ConnectionModel conn : targetConnections) {
if (allDescendants.contains(conn.getTarget()))
conn.reconnect();
}
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class WidgetDeleteCommand 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.AbstractWidgetModel in project yamcs-studio by yamcs.
the class DropPVtoContainerEditPolicy method getCommand.
@Override
public Command getCommand(Request request) {
if (request.getType() == DropPVRequest.REQ_DROP_PV && request instanceof DropPVRequest) {
DropPVRequest dropPVRequest = (DropPVRequest) request;
if (dropPVRequest.getTargetWidget() != null && dropPVRequest.getTargetWidget() instanceof AbstractContainerEditpart) {
WidgetsSelectDialog dialog = new WidgetsSelectDialog(getHost().getViewer().getControl().getShell(), dropPVRequest.getPvNames().length, true);
if (dialog.open() == Window.OK) {
String typeID = dialog.getOutput();
CompoundCommand command = new CompoundCommand("Create Widget");
// $NON-NLS-1$
String[] pvNames = dropPVRequest.getPvNames();
Point location = dropPVRequest.getLocation().getCopy();
AbstractContainerModel container = ((AbstractContainerEditpart) dropPVRequest.getTargetWidget()).getWidgetModel();
AbstractContainerModel parent = container.getParent();
AbstractContainerModel temp = container;
while (parent != null) {
location.translate(temp.getLocation().getNegated());
temp = parent;
parent = parent.getParent();
}
int i = 1;
int lastWidth = 0, lastHeight = 0;
for (String pvName : pvNames) {
AbstractWidgetModel widgetModel = WidgetsService.getInstance().getWidgetDescriptor(typeID).getWidgetModel();
command.add(new WidgetCreateCommand(widgetModel, container, new Rectangle(location.getCopy().translate(lastWidth, lastHeight), new Dimension(-1, -1)), i != 1, true));
command.add(new SetWidgetPropertyCommand(widgetModel, AbstractPVWidgetModel.PROP_PVNAME, pvName.trim()));
if (i % WIDGETS_ACCOUNT_ON_A_ROW == 0) {
lastWidth = 0;
lastHeight += widgetModel.getHeight();
} else
lastWidth += widgetModel.getWidth();
i++;
}
return command;
}
}
}
return null;
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class AbstractBaseEditPart method doRefreshVisuals.
/**
* Resizes the figure. Use {@link AbstractBaseEditPart} to implement more complex refreshing behavior.
*
* @param refreshableFigure
* the figure
*/
protected synchronized void doRefreshVisuals(final IFigure refreshableFigure) {
super.refreshVisuals();
AbstractWidgetModel model = getWidgetModel();
GraphicalEditPart parent = (GraphicalEditPart) getParent();
if (parent != null) {
parent.setLayoutConstraint(this, refreshableFigure, new Rectangle(model.getLocation(), model.getSize()));
}
}
Aggregations