Search in sources :

Example 26 with AbstractContainerModel

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

the class TextUpdateEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            setFigureText((String) newValue);
            if (isAutoSize) {
                Display.getCurrent().timerExec(10, new Runnable() {

                    @Override
                    public void run() {
                        performAutoSize();
                    }
                });
            }
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_TEXT, handler);
    IWidgetPropertyChangeHandler fontHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setFont(CustomMediaFactory.getInstance().getFont(((OPIFont) newValue).getFontData()));
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_FONT, fontHandler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            Display.getCurrent().timerExec(10, new Runnable() {

                @Override
                public void run() {
                    if (getWidgetModel().isAutoSize()) {
                        performAutoSize();
                        figure.revalidate();
                    }
                }
            });
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_FONT, handler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_STYLE, handler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_WIDTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setOpaque(!(Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_TRANSPARENT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            isAutoSize = (Boolean) newValue;
            if ((Boolean) newValue) {
                performAutoSize();
                figure.revalidate();
            }
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_AUTOSIZE, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (figure instanceof TextFigure)
                ((TextFigure) figure).setHorizontalAlignment(H_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_H, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (figure instanceof TextFigure)
                ((TextFigure) figure).setVerticalAlignment(V_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_V, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            if (newValue == null)
                return false;
            formatValue(newValue, AbstractPVWidgetModel.PROP_PVVALUE);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVVALUE, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            format = FormatEnum.values()[(Integer) newValue];
            formatValue(newValue, TextUpdateModel.PROP_FORMAT_TYPE);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_FORMAT_TYPE, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            precision = (Integer) newValue;
            formatValue(newValue, TextUpdateModel.PROP_PRECISION);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_PRECISION, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            isPrecisionFromDB = (Boolean) newValue;
            formatValue(newValue, TextUpdateModel.PROP_PRECISION_FROM_DB);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_PRECISION_FROM_DB, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            isShowUnits = (Boolean) newValue;
            formatValue(newValue, TextUpdateModel.PROP_SHOW_UNITS);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_SHOW_UNITS, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            if (figure instanceof TextFigure)
                ((TextFigure) figure).setRotate((Double) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_ROTATION, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            AbstractWidgetModel model = getWidgetModel();
            AbstractContainerModel parent = model.getParent();
            parent.removeChild(model);
            parent.addChild(model);
            parent.selectWidget(model, true);
            return false;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_WRAP_WORDS, handler);
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) NativeTextFigure(org.csstudio.opibuilder.widgets.figures.NativeTextFigure) TextFigure(org.csstudio.swt.widgets.figures.TextFigure) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 27 with AbstractContainerModel

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

the class ChangeOrderAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().size() == 0 || getSelectedObjects().size() == 1 && getSelectedObjects().get(0) instanceof EditPart && ((EditPart) getSelectedObjects().get(0)).getModel() instanceof DisplayModel)
        return false;
    Map<AbstractContainerModel, List<IndexedWidget>> widgetMap = new HashMap<AbstractContainerModel, List<IndexedWidget>>();
    fillWidgetMap(widgetMap);
    // create compound command
    for (final Map.Entry<AbstractContainerModel, List<IndexedWidget>> entry : widgetMap.entrySet()) {
        // sort the list in map by the widget's original order in its container
        AbstractContainerModel container = entry.getKey();
        List<IndexedWidget> widgetList = entry.getValue();
        Collections.sort(widgetList);
        int newIndex;
        switch(orderType) {
            case TO_FRONT:
                newIndex = container.getChildren().size() - 1;
                break;
            case STEP_FRONT:
                newIndex = widgetList.get(widgetList.size() - 1).getIndex() + 1;
                break;
            case STEP_BACK:
                newIndex = widgetList.get(0).getIndex() - 1;
                break;
            case TO_BACK:
            default:
                newIndex = 0;
                break;
        }
        if (newIndex > container.getChildren().size() - 1 || newIndex < 0)
            return false;
        for (IndexedWidget indexedWidget : widgetList) {
            if (container.getIndexOf(indexedWidget.getWidget()) != newIndex)
                return true;
        }
    }
    return false;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) HashMap(java.util.HashMap) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) EditPart(org.eclipse.gef.EditPart) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with AbstractContainerModel

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

the class ChangeOrderAction method run.

@Override
public void run() {
    Map<AbstractContainerModel, List<IndexedWidget>> widgetMap = new HashMap<AbstractContainerModel, List<IndexedWidget>>();
    fillWidgetMap(widgetMap);
    CompoundCommand compoundCommand = new CompoundCommand(orderType.getLabel());
    // create compound command
    for (final Map.Entry<AbstractContainerModel, List<IndexedWidget>> entry : widgetMap.entrySet()) {
        // sort the list in map by the widget's original order in its container
        AbstractContainerModel container = entry.getKey();
        List<IndexedWidget> widgetList = entry.getValue();
        Collections.sort(widgetList);
        int newIndex;
        switch(orderType) {
            case TO_FRONT:
                newIndex = container.getChildren().size() - 1;
                break;
            case STEP_FRONT:
                newIndex = widgetList.get(widgetList.size() - 1).getIndex() + 1;
                break;
            case STEP_BACK:
                newIndex = widgetList.get(0).getIndex() - 1;
                break;
            case TO_BACK:
            default:
                newIndex = 0;
                break;
        }
        // reorder
        switch(orderType) {
            case TO_FRONT:
            case STEP_FRONT:
                for (IndexedWidget indexedWidget : widgetList) {
                    compoundCommand.add(new ChangeOrderCommand(newIndex, container, indexedWidget.getWidget()));
                }
                break;
            case STEP_BACK:
            case TO_BACK:
                for (int i = widgetList.size() - 1; i >= 0; i--) {
                    compoundCommand.add(new ChangeOrderCommand(newIndex, container, widgetList.get(i).getWidget()));
                }
                break;
            default:
                break;
        }
    }
    execute(compoundCommand);
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) HashMap(java.util.HashMap) ChangeOrderCommand(org.csstudio.opibuilder.commands.ChangeOrderCommand) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 29 with AbstractContainerModel

use of org.csstudio.opibuilder.model.AbstractContainerModel 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 30 with AbstractContainerModel

use of org.csstudio.opibuilder.model.AbstractContainerModel 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)

Aggregations

AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)34 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)27 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)11 ArrayList (java.util.ArrayList)10 Rectangle (org.eclipse.draw2d.geometry.Rectangle)10 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)9 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)7 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)6 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)5 IFigure (org.eclipse.draw2d.IFigure)5 Point (org.eclipse.draw2d.geometry.Point)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeListener (java.beans.PropertyChangeListener)4 List (java.util.List)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)4 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4 HashMap (java.util.HashMap)3 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)3