use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class EditFormulaDialog method open.
/**
* Open, i.e. display the dialog.
* @return <code>true</code> when the item was updated,
* <code>false</code> for 'cancel'
*/
public boolean open() {
try {
// Edit
dialog = new FormulaDialog(shell, formula.getExpression(), determineInputs());
if (dialog.open() != Window.OK)
return false;
// Update model item with new formula from dialog
final Model model = formula.getModel().get();
final ArrayList<FormulaInput> new_inputs = new ArrayList<FormulaInput>();
for (final InputItem input : dialog.getInputs()) {
final ModelItem item = model.getItem(input.getInputName());
if (item == null)
// $NON-NLS-1$
throw new Exception("Cannot locate formula input " + input.getInputName());
new_inputs.add(new FormulaInput(item, input.getVariableName()));
}
// Update formula via undo-able command
new ChangeFormulaCommand(shell, operations_manager, formula, dialog.getFormula(), new_inputs.toArray(new FormulaInput[new_inputs.size()]));
} catch (final Exception ex) {
ExceptionDetailsErrorDialog.openError(shell, Messages.Error, ex);
return false;
}
return true;
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidgetJFX method updateChanges.
@Override
public void updateChanges() {
super.updateChanges();
if (dirty_file.checkAndClear()) {
// This is being done here because the load function causes effects that need to happen on the FxUserThread
final InputStream safe_stream = model_file_stream;
model_file_stream = null;
// Clear model that might already contain items
final Model db_model = model_widget.getDataBrowserModel();
db_model.clear();
// Load new model
if (safe_stream != null)
try {
db_model.setMacros(model_widget.getMacrosOrProperties());
new XMLPersistence().load(db_model, safe_stream);
// Override settings in *.plt file with those of widget
db_model.setToolbarVisible(model_widget.propShowToolbar().getValue());
} catch (Exception ex) {
logger.log(Level.WARNING, "Error loading data browser content", ex);
}
}
if (dirty_opts.checkAndClear())
plot.getPlot().showToolbar(model_widget.propShowToolbar().getValue());
if (dirty_size.checkAndClear())
plot.getPlot().setPrefSize(model_widget.propWidth().getValue(), model_widget.propHeight().getValue());
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidgedEditPart method activate.
/**
* {@inheritDoc}}
*/
@Override
public void activate() {
// In run mode, start controller, which will start model
if (getExecutionMode() == ExecutionMode.RUN_MODE) {
try {
// Connect plot to model (created by OPI/GEF)
final ModelBasedPlot plot_widget = gui.getDataBrowserPlot();
controller = new ControllerSWT(null, getWidgetModel().createDataBrowserModel(), plot_widget);
controller.start();
// Have PV for cursor data?
final String pv_name = getWidgetModel().getSelectionValuePv();
if (!pv_name.isEmpty()) {
pv.set(PVManager.write(ExpressionLanguage.channel(pv_name)).async());
plot_widget.getPlot().addListener(plot_listener);
}
// Add context menu to the SWT control
// for opening full data browser
final MenuManager mm = new MenuManager();
mm.add(new OpenDataBrowserAction(this));
mm.add(new ShowToolbarAction(this));
// TODO: legend action
// mm.add(plot_widget.getPlot().getLegendAction());
final Control control = gui.getSWTWidget();
final Menu menu = mm.createContextMenu(control);
control.setMenu(menu);
} catch (Exception ex) {
Logger.getLogger(Activator.ID).log(Level.SEVERE, "Cannot start Data Browser Widget", ex);
}
}
super.activate();
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidgedModel method createDataBrowserModel.
/**
* Create a Data Browser model, loaded with the configuration file
* @return Data Browser Model
* @throws Exception
*/
public Model createDataBrowserModel() throws CoreException, Exception {
final Model model = new Model();
final IMacroTableProvider opi_macros = getAllMacros();
final MacroValueProvider db_macros = name -> opi_macros.getMacroValue(name);
model.setMacros(db_macros);
try (final InputStream input = SingleSourcePlugin.getResourceHelper().getInputStream(getExpandedFilename())) {
new XMLPersistence().load(model, input);
}
return model;
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class OpenDataBrowserAction method run.
@Override
public void run() {
final DataBrowserWidgedModel model = edit_part.getWidgetModel();
IPath filename = model.getExpandedFilename();
if (!filename.isAbsolute())
filename = ResourceUtil.buildAbsolutePath(model, filename);
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
final IEditorInput input = new PathEditorInput(filename);
final DataBrowserModelEditorInput model_input = new DataBrowserModelEditorInput(input, model.createDataBrowserModel());
page.openEditor(model_input, DataBrowserEditor.ID, true);
} catch (Exception ex) {
ExceptionDetailsErrorDialog.openError(page.getActivePart().getSite().getShell(), Messages.Error, NLS.bind(Messages.OpenDataBrowserErrorFmt, filename.toString()), ex);
}
}
Aggregations