Search in sources :

Example 6 with MacrosInput

use of org.csstudio.opibuilder.util.MacrosInput in project yamcs-studio by yamcs.

the class OPIRuntimeDelegate method init.

public void init(final IWorkbenchPartSite site, final IEditorInput input) throws PartInitException {
    this.site = site;
    setEditorInput(input);
    if (viewer != null) {
        viewer.getControl().removePaintListener(errorMessagePaintListener);
    }
    displayModel = new DisplayModel(getOPIFilePath());
    displayModel.setOpiRuntime(opiRuntime);
    displayModelFilled = false;
    InputStream inputStream = null;
    try {
        if (input instanceof IRunnerInput) {
            final IRunnerInput run_input = (IRunnerInput) input;
            if (ResourceUtil.isURL(run_input.getPath().toString())) {
                // TODO Part of
                // https://github.com/ControlSystemStudio/cs-studio/issues/735:
                // One *.opi was loaded in a job, other *.opi
                // in UI thread, merging both..
                final Display display = site.getShell().getDisplay();
                fillDisplayModelInJob(input, display, site);
            } else
                inputStream = run_input.getInputStream();
            displayOpenManager = run_input.getDisplayOpenManager();
        } else {
            inputStream = ResourceUtil.getInputStreamFromEditorInput(input);
        }
        if (inputStream != null) {
            MacrosInput macrosInput = null;
            if (input instanceof IRunnerInput) {
                macrosInput = ((IRunnerInput) input).getMacrosInput();
            }
            XMLUtil.fillDisplayModelFromInputStream(inputStream, displayModel, null, macrosInput);
            displayModelFilled = true;
            if (input instanceof IRunnerInput)
                addRunnerInputMacros(input);
        }
    } catch (Exception e) {
        ErrorHandlerUtil.handleError("Failed to open opi file: " + input, e, true, true);
        throw new PartInitException("Failed to run OPI file: " + input, e);
    }
    // if it was an opened editor
    if (viewer != null && displayModelFilled) {
        viewer.setContents(displayModel);
        updateEditorTitle();
        displayModel.setViewer(viewer);
        displayModel.setOpiRuntime(opiRuntime);
    }
    getActionRegistry().registerAction(new RefreshOPIAction(opiRuntime));
    getActionRegistry().registerAction(new PrintDisplayAction(opiRuntime));
    // hide close button
    hideCloseButton(site);
}
Also used : MacrosInput(org.csstudio.opibuilder.util.MacrosInput) RefreshOPIAction(org.csstudio.opibuilder.actions.RefreshOPIAction) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) InputStream(java.io.InputStream) PartInitException(org.eclipse.ui.PartInitException) PrintDisplayAction(org.csstudio.opibuilder.actions.PrintDisplayAction) PartInitException(org.eclipse.ui.PartInitException) Display(org.eclipse.swt.widgets.Display)

Example 7 with MacrosInput

use of org.csstudio.opibuilder.util.MacrosInput in project yamcs-studio by yamcs.

the class AbstractContainerEditpart method registerBasePropertyChangeHandlers.

@Override
protected void registerBasePropertyChangeHandlers() {
    super.registerBasePropertyChangeHandlers();
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            MacrosInput macrosInput = (MacrosInput) newValue;
            LinkedHashMap<String, String> macrosMap = new LinkedHashMap<String, String>();
            if (macrosInput.isInclude_parent_macros()) {
                macrosMap.putAll(getWidgetModel().getParentMacroMap());
            }
            macrosMap.putAll(macrosInput.getMacrosMap());
            getWidgetModel().setMacroMap(macrosMap);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractContainerModel.PROP_MACROS, handler);
    layout();
    childrenPropertyChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getOldValue() instanceof Integer) {
                addChild(createChild(evt.getNewValue()), ((Integer) evt.getOldValue()).intValue());
                layout();
            } else if (evt.getOldValue() instanceof AbstractWidgetModel) {
                EditPart child = (EditPart) getViewer().getEditPartRegistry().get(evt.getOldValue());
                if (child != null) {
                    removeChild(child);
                    layout();
                }
            } else
                refreshChildren();
        }
    };
    getWidgetModel().getChildrenProperty().addPropertyChangeListener(childrenPropertyChangeListener);
    if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
        selectionPropertyChangeListener = new PropertyChangeListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                List<AbstractWidgetModel> widgets = (List<AbstractWidgetModel>) evt.getNewValue();
                List<EditPart> widgetEditparts = new ArrayList<EditPart>();
                for (AbstractWidgetModel w : widgets) {
                    EditPart e = (EditPart) getViewer().getEditPartRegistry().get(w);
                    if (e != null)
                        widgetEditparts.add(e);
                }
                if (!(Boolean) evt.getOldValue()) {
                    // append
                    getViewer().deselectAll();
                }
                for (EditPart editpart : widgetEditparts) {
                    if (editpart.isSelectable())
                        getViewer().appendSelection(editpart);
                }
            }
        };
        getWidgetModel().getSelectionProperty().addPropertyChangeListener(selectionPropertyChangeListener);
    }
}
Also used : MacrosInput(org.csstudio.opibuilder.util.MacrosInput) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) EditPart(org.eclipse.gef.EditPart) LinkedHashMap(java.util.LinkedHashMap) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) ArrayList(java.util.ArrayList) List(java.util.List) IFigure(org.eclipse.draw2d.IFigure)

Example 8 with MacrosInput

use of org.csstudio.opibuilder.util.MacrosInput in project yamcs-studio by yamcs.

the class AbstractContainerModel method configureBaseProperties.

@Override
protected void configureBaseProperties() {
    super.configureBaseProperties();
    addProperty(new MacrosProperty(PROP_MACROS, "Macros", WidgetPropertyCategory.Basic, new MacrosInput(new LinkedHashMap<String, String>(), true)));
}
Also used : MacrosInput(org.csstudio.opibuilder.util.MacrosInput) MacrosProperty(org.csstudio.opibuilder.properties.MacrosProperty)

Example 9 with MacrosInput

use of org.csstudio.opibuilder.util.MacrosInput in project yamcs-studio by yamcs.

the class XMLUtil method buildMacroMap.

private static Map<String, String> buildMacroMap(AbstractContainerModel model) {
    Map<String, String> macros = new HashMap<>();
    if (model != null) {
        MacrosInput input = model.getMacrosInput();
        if (input.isInclude_parent_macros()) {
            macros.putAll(buildMacroMap(model.getParent()));
        }
        macros.putAll(input.getMacrosMap());
    }
    return macros;
}
Also used : MacrosInput(org.csstudio.opibuilder.util.MacrosInput) HashMap(java.util.HashMap)

Example 10 with MacrosInput

use of org.csstudio.opibuilder.util.MacrosInput in project yamcs-studio by yamcs.

the class OpenOPIProbeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    ProcessVariable[] pvs = AdapterUtil.convert(selection, ProcessVariable.class);
    IPath probeOPIPath = ResourceUtil.getPathFromString("platform:/plugin/org.csstudio.opibuilder/opi/probe.opi");
    LinkedHashMap<String, String> macros = new LinkedHashMap<>();
    if (pvs.length > 0) {
        macros.put(MACRO_NAME, pvs[0].getName());
    }
    int i = 0;
    for (ProcessVariable pv : pvs) {
        // $NON-NLS-1$
        macros.put(MACRO_NAME + "_" + Integer.toString(i), pv.getName());
        i++;
    }
    MacrosInput macrosInput = new MacrosInput(macros, true);
    // Errors in here will show in dialog and error log
    RunModeService.openDisplay(probeOPIPath, Optional.of(macrosInput), DisplayMode.NEW_TAB_DETACHED, Optional.empty());
    return null;
}
Also used : MacrosInput(org.csstudio.opibuilder.util.MacrosInput) IPath(org.eclipse.core.runtime.IPath) ProcessVariable(org.csstudio.csdata.ProcessVariable) ISelection(org.eclipse.jface.viewers.ISelection) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MacrosInput (org.csstudio.opibuilder.util.MacrosInput)14 LinkedHashMap (java.util.LinkedHashMap)4 IPath (org.eclipse.core.runtime.IPath)4 PartInitException (org.eclipse.ui.PartInitException)3 Element (org.jdom.Element)3 InputStream (java.io.InputStream)2 MacrosProperty (org.csstudio.opibuilder.properties.MacrosProperty)2 Path (org.eclipse.core.runtime.Path)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ProcessVariable (org.csstudio.csdata.ProcessVariable)1 PrintDisplayAction (org.csstudio.opibuilder.actions.PrintDisplayAction)1 RefreshOPIAction (org.csstudio.opibuilder.actions.RefreshOPIAction)1 NotImplementedException (org.csstudio.opibuilder.datadefinition.NotImplementedException)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1