Search in sources :

Example 1 with ModelListenerAdapter

use of org.csstudio.trends.databrowser3.model.ModelListenerAdapter 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)

Aggregations

InputStream (java.io.InputStream)1 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)1 Model (org.csstudio.trends.databrowser3.model.Model)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 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)1 PartInitException (org.eclipse.ui.PartInitException)1