Search in sources :

Example 1 with IModelStateListener

use of org.eclipse.wst.sse.core.internal.provisional.IModelStateListener in project liferay-ide by liferay.

the class LayoutTplEditor method initSourceModel.

protected void initSourceModel() {
    if (_sourceModel == null) {
        if ((_sourcePage != null) && (_sourcePage.getDocumentProvider() != null)) {
            IDocumentProvider documentProvider = _sourcePage.getDocumentProvider();
            IDocument doc = documentProvider.getDocument(getEditorInput());
            _sourceModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForEdit(doc);
            _sourceModel.addModelStateListener(new IModelStateListener() {

                public void modelAboutToBeChanged(IStructuredModel model) {
                }

                public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
                }

                public void modelChanged(IStructuredModel model) {
                    setSourceModelChanged(true);
                }

                public void modelDirtyStateChanged(IStructuredModel model, boolean dirty) {
                }

                public void modelReinitialized(IStructuredModel structuredModel) {
                }

                public void modelResourceDeleted(IStructuredModel model) {
                }

                public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
                }
            });
        }
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument) IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Example 2 with IModelStateListener

use of org.eclipse.wst.sse.core.internal.provisional.IModelStateListener in project webtools.sourceediting by eclipse.

the class AbstractStructuredModel method fireModelAboutToBeReinitialized.

protected void fireModelAboutToBeReinitialized() {
    // another thread
    if (fModelStateListeners != null) {
        if (Logger.DEBUG_MODELSTATE) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Logger.log(Logger.INFO, "IModelStateListener event for " + getId() + " : modelAboutToBeReinitialized");
        }
        Object[] holdListeners = fModelStateListeners;
        for (int i = 0; i < holdListeners.length; i++) {
            // NOTE: trick for transition. We actual use the same
            // listeners
            // as modelState, but only send this to those that have
            // implemented ModelStateExtended.
            IModelStateListener listener = (IModelStateListener) holdListeners[i];
            listener.modelAboutToBeReinitialized(this);
        }
    }
}
Also used : IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Example 3 with IModelStateListener

use of org.eclipse.wst.sse.core.internal.provisional.IModelStateListener in project webtools.sourceediting by eclipse.

the class TestStructuredModel method testAddRemoveModelStateListener.

public void testAddRemoveModelStateListener() throws IOException, CoreException {
    IStructuredModel model = getTestModel();
    try {
        IModelStateListener listener = new IModelStateListener() {

            public void modelAboutToBeChanged(IStructuredModel model) {
            // 
            }

            public void modelChanged(IStructuredModel model) {
            // 
            }

            public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
            // 
            }

            public void modelResourceDeleted(IStructuredModel model) {
            // 
            }

            public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
            // 
            }

            public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
            // 
            }

            public void modelReinitialized(IStructuredModel structuredModel) {
            // 
            }
        };
        model.aboutToChangeModel();
        model.removeModelStateListener(listener);
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Example 4 with IModelStateListener

use of org.eclipse.wst.sse.core.internal.provisional.IModelStateListener in project webtools.sourceediting by eclipse.

the class AbstractStructuredModel method fireModelReinitialized.

protected void fireModelReinitialized() {
    // another thread
    if (fModelStateListeners != null) {
        if (Logger.DEBUG_MODELSTATE) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Logger.log(Logger.INFO, "IModelStateListener event for " + getId() + " : modelReinitialized");
        }
        Object[] holdListeners = fModelStateListeners;
        for (int i = 0; i < holdListeners.length; i++) {
            IModelStateListener listener = (IModelStateListener) holdListeners[i];
            listener.modelReinitialized(this);
        }
    }
}
Also used : IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Example 5 with IModelStateListener

use of org.eclipse.wst.sse.core.internal.provisional.IModelStateListener in project liferay-ide by liferay.

the class PortletsNode method _getPortletAppModelElement.

private PortletApp _getPortletAppModelElement() {
    if (_modelElement == null) {
        IFile portletXmlFile = ProjectUtil.getPortletXmlFile(this._parent.getProject());
        if ((portletXmlFile != null) && portletXmlFile.exists()) {
            try {
                IStructuredModel portletXmlModel = StructuredModelManager.getModelManager().getModelForRead(portletXmlFile);
                IModelStateListener listener = new IModelStateListener() {

                    public void modelAboutToBeChanged(IStructuredModel model) {
                    }

                    public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
                    }

                    public void modelChanged(IStructuredModel model) {
                        _refresh();
                    }

                    public void modelDirtyStateChanged(IStructuredModel model, boolean dirty) {
                        _refresh();
                    }

                    public void modelReinitialized(IStructuredModel structuredModel) {
                        _refresh();
                    }

                    public void modelResourceDeleted(IStructuredModel model) {
                        _refresh();
                    }

                    public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
                        _refresh();
                    }

                    private void _refresh() {
                        portletXmlModel.removeModelStateListener(this);
                        if (!PortletsNode.this._modelElement.disposed()) {
                            PortletsNode.this._modelElement.dispose();
                        }
                        PortletsNode.this._modelElement = null;
                        PortletsNode.this._parent.refresh();
                    }
                };
                portletXmlModel.addModelStateListener(listener);
                _modelElement = PortletApp.TYPE.instantiate(new RootXmlResource(new XmlResourceStore(portletXmlFile.getContents())));
            } catch (Exception e) {
                PortletUIPlugin.logError(e);
            }
        }
    }
    return _modelElement;
}
Also used : IFile(org.eclipse.core.resources.IFile) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Aggregations

IModelStateListener (org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)3 IFile (org.eclipse.core.resources.IFile)1 IDocument (org.eclipse.jface.text.IDocument)1 RootXmlResource (org.eclipse.sapphire.modeling.xml.RootXmlResource)1 XmlResourceStore (org.eclipse.sapphire.modeling.xml.XmlResourceStore)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1