Search in sources :

Example 41 with Model

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;
}
Also used : FormulaDialog(org.csstudio.apputil.ui.formula.FormulaDialog) InputItem(org.csstudio.apputil.ui.formula.InputItem) Model(org.csstudio.trends.databrowser3.model.Model) ArrayList(java.util.ArrayList) FormulaInput(org.csstudio.trends.databrowser3.model.FormulaInput) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem)

Example 42 with Model

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Model(org.csstudio.trends.databrowser3.model.Model) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence)

Example 43 with Model

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();
}
Also used : Control(org.eclipse.swt.widgets.Control) MenuManager(org.eclipse.jface.action.MenuManager) Menu(org.eclipse.swt.widgets.Menu) ControllerSWT(org.csstudio.trends.databrowser3.ui.ControllerSWT) ModelBasedPlot(org.csstudio.trends.databrowser3.ui.ModelBasedPlot)

Example 44 with Model

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;
}
Also used : XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) StringProperty(org.csstudio.opibuilder.properties.StringProperty) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) Level(java.util.logging.Level) MacroUtil(org.csstudio.apputil.macros.MacroUtil) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) IPath(org.eclipse.core.runtime.IPath) BooleanProperty(org.csstudio.opibuilder.properties.BooleanProperty) Map(java.util.Map) Model(org.csstudio.trends.databrowser3.model.Model) IMacroTableProvider(org.csstudio.apputil.macros.IMacroTableProvider) Logger(java.util.logging.Logger) InfiniteLoopException(org.csstudio.apputil.macros.InfiniteLoopException) MacroTable(org.csstudio.apputil.macros.MacroTable) WidgetPropertyCategory(org.csstudio.opibuilder.properties.WidgetPropertyCategory) SingleSourcePlugin(org.csstudio.utility.singlesource.SingleSourcePlugin) List(java.util.List) MacrosInput(org.csstudio.opibuilder.util.MacrosInput) Path(org.eclipse.core.runtime.Path) MacroValueProvider(org.csstudio.display.builder.model.macros.MacroValueProvider) BorderStyle(org.csstudio.opibuilder.visualparts.BorderStyle) FilePathProperty(org.csstudio.opibuilder.properties.FilePathProperty) Collections(java.util.Collections) InputStream(java.io.InputStream) MacroValueProvider(org.csstudio.display.builder.model.macros.MacroValueProvider) InputStream(java.io.InputStream) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) Model(org.csstudio.trends.databrowser3.model.Model) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) IMacroTableProvider(org.csstudio.apputil.macros.IMacroTableProvider)

Example 45 with 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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) DataBrowserModelEditorInput(org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) PathEditorInput(org.csstudio.utility.singlesource.PathEditorInput)

Aggregations

ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)16 Model (org.csstudio.trends.databrowser3.model.Model)15 ArrayList (java.util.ArrayList)10 PVItem (org.csstudio.trends.databrowser3.model.PVItem)10 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)9 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)7 Instant (java.time.Instant)6 InputStream (java.io.InputStream)5 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)5 FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)4 Shell (org.eclipse.swt.widgets.Shell)4 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)3 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)3 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)3 MinSizeTableColumnLayout (org.csstudio.ui.util.MinSizeTableColumnLayout)3 IPath (org.eclipse.core.runtime.IPath)3 Separator (org.eclipse.jface.action.Separator)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 PartInitException (org.eclipse.ui.PartInitException)3