Search in sources :

Example 16 with AbstractWidgetModel

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

Example 17 with AbstractWidgetModel

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;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) VString(org.diirt.vtype.VString)

Example 18 with AbstractWidgetModel

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) {
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) NonExistPropertyException(org.csstudio.opibuilder.model.NonExistPropertyException) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) VString(org.diirt.vtype.VString)

Example 19 with AbstractWidgetModel

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

Example 20 with AbstractWidgetModel

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

Aggregations

AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)50 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)15 ArrayList (java.util.ArrayList)11 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)10 Point (org.eclipse.draw2d.geometry.Point)7 Rectangle (org.eclipse.draw2d.geometry.Rectangle)7 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)7 EditPart (org.eclipse.gef.EditPart)6 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)5 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)5 IFigure (org.eclipse.draw2d.IFigure)5 PropertyChangeListener (java.beans.PropertyChangeListener)4 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)3 ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)3 EditPolicy (org.eclipse.gef.EditPolicy)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 List (java.util.List)2 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)2