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);
}
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);
}
}
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)));
}
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;
}
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;
}
Aggregations