Search in sources :

Example 71 with AbstractWidgetModel

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();
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Clipboard(org.eclipse.swt.dnd.Clipboard) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 72 with AbstractWidgetModel

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();
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel)

Example 73 with AbstractWidgetModel

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;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ArrayList(java.util.ArrayList) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel)

Example 74 with AbstractWidgetModel

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;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) WidgetsSelectDialog(org.csstudio.opibuilder.visualparts.WidgetsSelectDialog)

Example 75 with AbstractWidgetModel

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()));
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart)

Aggregations

AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)82 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)27 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)22 Rectangle (org.eclipse.draw2d.geometry.Rectangle)18 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)17 ArrayList (java.util.ArrayList)15 Point (org.eclipse.draw2d.geometry.Point)14 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)12 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)10 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)9 IFigure (org.eclipse.draw2d.IFigure)9 PropertyChangeEvent (java.beans.PropertyChangeEvent)8 PropertyChangeListener (java.beans.PropertyChangeListener)8 Dimension (org.eclipse.draw2d.geometry.Dimension)8 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)7 EditPart (org.eclipse.gef.EditPart)7 PointList (org.eclipse.draw2d.geometry.PointList)6 List (java.util.List)5 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)5 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)5