Search in sources :

Example 56 with AbstractWidgetModel

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

the class OPIEditor method getAdapter.

@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class type) {
    if (type == IPropertySheetPage.class)
        return getPropertySheetPage();
    else if (type == ZoomManager.class)
        return ((ScalableFreeformRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager();
    else // return getOverviewOutlinePage();
    if (type == IContentOutlinePage.class) {
        outlinePage = new OutlinePage(new TreeViewer());
        return outlinePage;
    } else if (type.equals(IContextProvider.class)) {
        if (helpContextProvider == null)
            helpContextProvider = new OPIHelpContextProvider(getGraphicalViewer());
        return helpContextProvider;
    } else if (type.equals(IGotoMarker.class)) {
        return new IGotoMarker() {

            @Override
            public void gotoMarker(IMarker marker) {
                try {
                    String wuid = (String) marker.getAttribute(AbstractWidgetModel.PROP_WIDGET_UID);
                    if (wuid == null) {
                        // if wuid is not stored in the marker try to find it based on character
                        Integer charStart = (Integer) marker.getAttribute(IMarker.CHAR_START);
                        if (charStart == null) {
                            return;
                        }
                        // Get the closest widget to charStart position
                        wuid = XMLUtil.findClosestWidgetUid(getInputStream(), charStart);
                        if (wuid == null) {
                            return;
                        }
                    }
                    AbstractWidgetModel widget = getDisplayModel().getWidgetFromWUID(wuid);
                    if (widget == null) {
                        return;
                    }
                    // Get the widget editPart
                    Object obj = getGraphicalViewer().getEditPartRegistry().get(widget);
                    if (obj != null && obj instanceof AbstractBaseEditPart) {
                        EditPart widgetEditPart = (AbstractBaseEditPart) obj;
                        // Reveal the widget
                        getGraphicalViewer().reveal(widgetEditPart);
                        // Find the closest selectable part
                        while (widgetEditPart != null && !widgetEditPart.isSelectable()) {
                            widgetEditPart = widgetEditPart.getParent();
                        }
                        if (widgetEditPart != null) {
                            // Select the widget in OPI
                            SelectionManager selectionManager = getGraphicalViewer().getSelectionManager();
                            selectionManager.deselectAll();
                            selectionManager.appendSelection(widgetEditPart);
                        }
                    }
                } catch (IOException e) {
                    MessageDialog.openError(getSite().getShell(), "IO Error", e.getMessage());
                    OPIBuilderPlugin.getLogger().log(Level.WARNING, "File open error", // $NON-NLS-1$
                    e);
                } catch (CoreException e) {
                    MessageDialog.openError(getSite().getShell(), "Core Error", e.getMessage());
                    OPIBuilderPlugin.getLogger().log(Level.WARNING, "File open error", // $NON-NLS-1$
                    e);
                }
            }
        };
    }
    return super.getAdapter(type);
}
Also used : SelectionManager(org.eclipse.gef.SelectionManager) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) TreeViewer(org.eclipse.gef.ui.parts.TreeViewer) RootEditPart(org.eclipse.gef.RootEditPart) EditPart(org.eclipse.gef.EditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) IGotoMarker(org.eclipse.ui.ide.IGotoMarker) IOException(java.io.IOException) IContentOutlinePage(org.eclipse.ui.views.contentoutline.IContentOutlinePage) ContentOutlinePage(org.eclipse.gef.ui.parts.ContentOutlinePage) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IContextProvider(org.eclipse.help.IContextProvider) CoreException(org.eclipse.core.runtime.CoreException) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) EventObject(java.util.EventObject) IMarker(org.eclipse.core.resources.IMarker)

Example 57 with AbstractWidgetModel

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

the class CopyPropertiesAction method run.

@Override
public void run() {
    PropertiesSelectDialog dialog = new PropertiesSelectDialog(null, getSelectedWidgetModels().get(0));
    if (dialog.open() == Window.OK) {
        List<String> propList = dialog.getOutput();
        if (!propList.isEmpty()) {
            AbstractWidgetModel widget = getSelectedWidgetModels().get(0);
            Element widgetElement = XMLUtil.widgetToXMLElement(widget);
            Element propertisElement = new Element(PROPID_ELEMENT);
            for (String propID : propList) {
                propertisElement.addContent(new Element(propID));
            }
            Element rootElement = new Element(ROOT_ELEMENT);
            rootElement.addContent(widgetElement);
            rootElement.addContent(propertisElement);
            XMLOutputter xmlOutputter = new XMLOutputter(Format.getRawFormat());
            String xmlString = xmlOutputter.outputString(rootElement);
            ((OPIEditor) getWorkbenchPart()).getClipboard().setContents(new Object[] { xmlString }, new Transfer[] { PropertiesCopyDataTransfer.getInstance() });
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) Element(org.jdom.Element) PropertiesSelectDialog(org.csstudio.opibuilder.visualparts.PropertiesSelectDialog)

Example 58 with AbstractWidgetModel

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

the class RemoveGroupAction method run.

@Override
public void run(IAction action) {
    CompoundCommand compoundCommand = new CompoundCommand("Remove Group");
    GroupingContainerModel containerModel = getSelectedContainer();
    // Orphan order should be reversed so that undo operation has the correct order.
    AbstractWidgetModel[] widgetsArray = containerModel.getChildren().toArray(new AbstractWidgetModel[containerModel.getChildren().size()]);
    for (int i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(containerModel, widgetsArray[i]));
    }
    Point leftCorner = containerModel.getLocation();
    for (AbstractWidgetModel widget : containerModel.getChildren()) {
        compoundCommand.add(new AddWidgetCommand(containerModel.getParent(), widget, new Rectangle(widget.getLocation(), widget.getSize()).translate(leftCorner)));
    }
    compoundCommand.add(new WidgetDeleteCommand(containerModel.getParent(), containerModel));
    execute(compoundCommand);
}
Also used : GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) WidgetDeleteCommand(org.csstudio.opibuilder.commands.WidgetDeleteCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 59 with AbstractWidgetModel

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

the class ArrayEditPart method hookChild.

/**
 *Hook child with array index
 * @param editPart
 */
protected void hookChild(final EditPart editPart, final int indexOfArrayChild, boolean directChild) {
    if (editPart instanceof AbstractContainerEditpart) {
        for (Object grandChild : ((AbstractContainerEditpart) editPart).getChildren()) hookChild((EditPart) grandChild, indexOfArrayChild, false);
    }
    AbstractWidgetModel childModel = ((AbstractBaseEditPart) editPart).getWidgetModel();
    if (directChild) {
        if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
            for (String propId : INVISIBLE_CHILD_PROPIDS) try {
                childModel.setPropertyVisibleAndSavable(propId, false, true);
            } catch (NonExistPropertyException e) {
            }
        }
        try {
            childModel.setScaleOptions(false, false, false);
            // $NON-NLS-1$
            childModel.setPropertyValue(IPVWidgetModel.PROP_PVNAME, "");
            childModel.setPropertyValue(IPVWidgetModel.PROP_BORDER_ALARMSENSITIVE, false);
        } catch (NonExistPropertyException e) {
        }
    }
    if (getExecutionMode() == ExecutionMode.RUN_MODE && editPart instanceof IPVWidgetEditpart) {
        ((IPVWidgetEditpart) editPart).addSetPVValueListener(new ISetPVValueListener() {

            // Capture set PV value event on children and write to the PV on
            // the array widget
            @Override
            public void beforeSetPVValue(String pvPropId, Object value) {
                int index = getArrayFigure().getIndex() + indexOfArrayChild;
                try {
                    ArrayDataType dataType = getWidgetModel().getDataType();
                    switch(dataType) {
                        case OBJECT_ARRAY:
                            ((Object[]) valueArray)[index] = value;
                            break;
                        case DOUBLE_ARRAY:
                            double doubleValue;
                            if (value instanceof Number)
                                doubleValue = ((Number) value).doubleValue();
                            else {
                                doubleValue = Double.valueOf(value.toString());
                            }
                            ((double[]) valueArray)[index] = doubleValue;
                            break;
                        case BYTE_ARRAY:
                            byte byteValue;
                            if (value instanceof Number)
                                byteValue = ((Number) value).byteValue();
                            else {
                                byteValue = Byte.valueOf(value.toString());
                            }
                            ((byte[]) valueArray)[index] = byteValue;
                            break;
                        case INT_ARRAY:
                            int intValue;
                            if (value instanceof Number)
                                intValue = ((Number) value).intValue();
                            else {
                                intValue = Byte.valueOf(value.toString());
                            }
                            ((int[]) valueArray)[index] = intValue;
                            break;
                        case SHORT_ARRAY:
                            short shortValue;
                            if (value instanceof Number)
                                shortValue = ((Number) value).shortValue();
                            else {
                                shortValue = Short.valueOf(value.toString());
                            }
                            ((short[]) valueArray)[index] = shortValue;
                            break;
                        case FLOAT_ARRAY:
                            float floatValue;
                            if (value instanceof Number)
                                floatValue = ((Number) value).floatValue();
                            else {
                                floatValue = Float.valueOf(value.toString());
                            }
                            ((float[]) valueArray)[index] = floatValue;
                            break;
                        case LONG_ARRAY:
                            long longValue;
                            if (value instanceof Number)
                                longValue = ((Number) value).longValue();
                            else {
                                longValue = Long.valueOf(value.toString());
                            }
                            ((long[]) valueArray)[index] = longValue;
                            break;
                        case STRING_ARRAY:
                            ((String[]) valueArray)[index] = value.toString();
                            break;
                        default:
                            break;
                    }
                    if (getPV() != null)
                        // but EPICS PV doesn't support write long[]. should be removed after switched to pv manager
                        if (valueArray instanceof long[]) {
                            int[] temp = new int[((long[]) valueArray).length];
                            for (int i = 0; i < ((long[]) valueArray).length; i++) temp[i] = (int) ((long[]) valueArray)[i];
                            setPVValue(ArrayModel.PROP_PVNAME, temp);
                        } else
                            setPVValue(ArrayModel.PROP_PVNAME, valueArray);
                } catch (NumberFormatException e) {
                    String msg = NLS.bind("Writing failed: The input data {0} is not compatible with array data type.", value.toString());
                    // recover the original data in children widgets.
                    setValue(getValue());
                    ErrorHandlerUtil.handleError(msg, e);
                }
            }
        });
    }
}
Also used : NonExistPropertyException(org.csstudio.opibuilder.model.NonExistPropertyException) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) VString(org.diirt.vtype.VString) IPVWidgetEditpart(org.csstudio.opibuilder.editparts.IPVWidgetEditpart) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) ArrayDataType(org.csstudio.opibuilder.widgets.model.ArrayModel.ArrayDataType)

Example 60 with AbstractWidgetModel

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

the class ArrayLayoutEditPolicy method createAddCommand.

@Override
protected Command createAddCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
    if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
        return super.createAddCommand(request, child, constraint);
    AbstractContainerModel container = (AbstractContainerModel) getHost().getModel();
    if (!container.getChildren().isEmpty())
        return null;
    AbstractWidgetModel widget = (AbstractWidgetModel) child.getModel();
    CompoundCommand result = new CompoundCommand("Add widget to array");
    addUpdateContainerCommands(container, widget.getSize(), result);
    result.add(new AddWidgetCommand(container, widget, (Rectangle) constraint));
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

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