Search in sources :

Example 1 with DataBrowserModelEditorInput

use of org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput in project org.csstudio.display.builder by kasemir.

the class DataBrowserEditor method init.

/**
 * Initialize model from editor input
 *  {@inheritDoc}
 */
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
    setSite(site);
    if (input instanceof DataBrowserModelEditorInput) {
        // Received model with input
        model = ((DataBrowserModelEditorInput) input).getModel();
        setInput(input);
    } else {
        // Create new model
        model = new Model();
        setInput(new DataBrowserModelEditorInput(input, model));
        // Load model content from file
        try (final InputStream stream = SingleSourcePlugin.getResourceHelper().getInputStream(input)) {
            if (stream != null)
                new XMLPersistence().load(model, stream);
        } catch (Exception ex) {
            throw new PartInitException(NLS.bind(Messages.ConfigFileErrorFmt, input.getName()), ex);
        }
    }
    // Update the editor's name from "Data Browser" to title of model or file name
    // See DataBrowserModelEditorInput.getName()
    setPartName(getEditorInput().getName());
    model_listener = new ModelListenerAdapter() {

        @Override
        public void changedSaveChangesBehavior(final boolean save_changes) {
            is_dirty = save_changes;
            firePropertyChange(IEditorPart.PROP_DIRTY);
        }

        @Override
        public void changedTitle() {
            setDirty(true);
        }

        @Override
        public void changedLayout() {
            setDirty(true);
        }

        @Override
        public void changedTiming() {
            setDirty(true);
        }

        @Override
        public void changedArchiveRescale() {
            setDirty(true);
        }

        @Override
        public void changedColorsOrFonts() {
            setDirty(true);
        }

        @Override
        public void changedTimerange() {
            setDirty(true);
        }

        @Override
        public void changeTimeAxisConfig() {
            setDirty(true);
        }

        @Override
        public void changedAxis(final Optional<AxisConfig> axis) {
            setDirty(true);
        }

        @Override
        public void itemAdded(final ModelItem item) {
            setDirty(true);
        }

        @Override
        public void itemRemoved(final ModelItem item) {
            setDirty(true);
        }

        @Override
        public void changedItemVisibility(final ModelItem item) {
            setDirty(true);
        }

        @Override
        public void changedItemLook(final ModelItem item) {
            site.getShell().getDisplay().asyncExec(() -> setDirty(true));
        }

        @Override
        public void changedItemDataConfig(PVItem item) {
            setDirty(true);
        }

        @Override
        public void scrollEnabled(final boolean scroll_enabled) {
            setDirty(true);
        }

        @Override
        public void changedAnnotations() {
            setDirty(true);
        }
    };
    model.addListener(model_listener);
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) InputStream(java.io.InputStream) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) PartInitException(org.eclipse.ui.PartInitException) ModelListenerAdapter(org.csstudio.trends.databrowser3.model.ModelListenerAdapter) Model(org.csstudio.trends.databrowser3.model.Model) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) PartInitException(org.eclipse.ui.PartInitException) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 2 with DataBrowserModelEditorInput

use of org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput in project org.csstudio.display.builder by kasemir.

the class OpenDisplayFile method openDisplay.

/**
 * {@inheritDoc}
 */
@Override
public void openDisplay(final String path, final String data) throws Exception {
    final Model model = new Model();
    // Read file
    final ResourceHelper resources = SingleSourcePlugin.getResourceHelper();
    final IPath ipath = resources.newPath(path);
    try (final InputStream stream = resources.getInputStream(ipath)) {
        new XMLPersistence().load(model, stream);
    }
    final IEditorInput input = new DataBrowserModelEditorInput(new PathEditorInput(ipath), model);
    // Create new editor
    final DataBrowserEditor editor = DataBrowserEditor.createInstance(input);
    if (editor == null)
        throw new Exception("Cannot create Data Browser");
}
Also used : IPath(org.eclipse.core.runtime.IPath) DataBrowserModelEditorInput(org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput) InputStream(java.io.InputStream) Model(org.csstudio.trends.databrowser3.model.Model) ResourceHelper(org.csstudio.utility.singlesource.ResourceHelper) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) IEditorInput(org.eclipse.ui.IEditorInput) DataBrowserEditor(org.csstudio.trends.databrowser3.editor.DataBrowserEditor) PathEditorInput(org.csstudio.utility.singlesource.PathEditorInput)

Example 3 with DataBrowserModelEditorInput

use of org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput in project org.csstudio.display.builder by kasemir.

the class OpenDataBrowserAction method run.

@Override
public void run() {
    IPath filename;
    try {
        filename = SingleSourcePlugin.getResourceHelper().newPath(widget.getExpandedFilename());
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Cannot determine path", ex);
        return;
    }
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        final IEditorInput input = new PathEditorInput(filename);
        final DataBrowserModelEditorInput model_input = new DataBrowserModelEditorInput(input, widget.cloneModel());
        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)

Example 4 with DataBrowserModelEditorInput

use of org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput 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

DataBrowserModelEditorInput (org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput)3 PathEditorInput (org.csstudio.utility.singlesource.PathEditorInput)3 IPath (org.eclipse.core.runtime.IPath)3 IEditorInput (org.eclipse.ui.IEditorInput)3 InputStream (java.io.InputStream)2 Model (org.csstudio.trends.databrowser3.model.Model)2 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 DataBrowserEditor (org.csstudio.trends.databrowser3.editor.DataBrowserEditor)1 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)1 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)1 ModelListenerAdapter (org.csstudio.trends.databrowser3.model.ModelListenerAdapter)1 PVItem (org.csstudio.trends.databrowser3.model.PVItem)1 ResourceHelper (org.csstudio.utility.singlesource.ResourceHelper)1 PartInitException (org.eclipse.ui.PartInitException)1