Search in sources :

Example 51 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class ArrayModel method addChild.

@Override
public synchronized void addChild(AbstractWidgetModel child, boolean changeParent) {
    if (!getChildren().isEmpty())
        return;
    // child should not be scalable because their size are layoutted by the array figure.
    child.setScaleOptions(false, false, false);
    super.addChild(child, changeParent);
    for (int i = 1; i < getVisibleElementsCount(); i++) {
        try {
            AbstractWidgetModel clone = XMLUtil.XMLElementToWidget(XMLUtil.widgetToXMLElement(child));
            super.addChild(clone, changeParent);
        } catch (Exception e) {
            ErrorHandlerUtil.handleError("Failed to generate copy of the element widget in array widget.", e);
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel)

Example 52 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class GroupingContainerModel method rotate90.

@Override
public void rotate90(boolean clockwise) {
    boolean oldLock = isLocked();
    setPropertyValue(PROP_LOCK_CHILDREN, false);
    Point center = new Point(getWidth() / 2, getHeight() / 2);
    for (AbstractWidgetModel abstractWidgetModel : getChildren()) {
        abstractWidgetModel.rotate90(clockwise, center);
    }
    Point oldLoc = getLocation();
    super.rotate90(clockwise);
    Point newLoc = getLocation();
    int dx = newLoc.x - oldLoc.x;
    int dy = newLoc.y - oldLoc.y;
    // move back
    for (AbstractWidgetModel abstractWidgetModel : getChildren()) {
        abstractWidgetModel.setLocation(abstractWidgetModel.getLocation().translate(-dx, -dy));
    }
    setPropertyValue(PROP_LOCK_CHILDREN, oldLock);
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 53 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class PastePropertiesAction method createPasteCommand.

public Command createPasteCommand() {
    PropertiesCopyData propData = getPropetiesCopyDataFromClipboard();
    CompoundCommand cmd = new CompoundCommand("Paste Properties");
    for (AbstractWidgetModel targetWidget : getSelectedWidgetModels()) {
        for (String prop_id : propData.getPropIDList()) {
            if (targetWidget.getAllPropertyIDs().contains(prop_id)) {
                cmd.add(new SetWidgetPropertyCommand(targetWidget, prop_id, propData.getWidgetModel().getPropertyValue(prop_id)));
            }
        }
    }
    return cmd;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) PropertiesCopyData(org.csstudio.opibuilder.datadefinition.PropertiesCopyData) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 54 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class PasteWidgetsAction method getWidgetsIntrinsicRelativePositions.

private List<Point> getWidgetsIntrinsicRelativePositions(List<AbstractWidgetModel> widgets) {
    PointList pointList = new PointList(widgets.size());
    for (AbstractWidgetModel widgetModel : widgets) {
        pointList.addPoint(widgetModel.getLocation());
    }
    Point upperLeftCorner = pointList.getBounds().getLocation();
    List<Point> result = new ArrayList<Point>(widgets.size());
    for (int i = 0; i < widgets.size(); i++) {
        result.add(pointList.getPoint(i).translate(-upperLeftCorner.x, -upperLeftCorner.y));
    }
    return result;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 55 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class PropertiesCopyDataTransfer method nativeToJava.

@Override
protected Object nativeToJava(TransferData transferData) {
    if (!isSupportedType(transferData))
        return null;
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    if (bytes == null)
        return null;
    try {
        SAXBuilder saxBuilder = new SAXBuilder();
        // $NON-NLS-1$
        Document doc = saxBuilder.build(new ByteArrayInputStream(bytes));
        Element root = doc.getRootElement();
        List<String> propIDList = new ArrayList<String>();
        AbstractWidgetModel widgetModel = null;
        for (Object o : root.getChildren()) {
            if (o instanceof Element) {
                Element e = (Element) o;
                if (e.getName().equals(CopyPropertiesAction.PROPID_ELEMENT))
                    for (Object po : e.getChildren()) {
                        Element pe = (Element) po;
                        propIDList.add(pe.getName());
                    }
                else
                    widgetModel = XMLUtil.XMLElementToWidget(e);
            }
        }
        return new PropertiesCopyData(widgetModel, propIDList);
    } catch (Exception e) {
        // $NON-NLS-1$
        OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to transfer XML to widget", e);
    }
    return null;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertiesCopyData(org.csstudio.opibuilder.datadefinition.PropertiesCopyData) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Document(org.jdom.Document) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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