Search in sources :

Example 1 with IEditingModel

use of com.liferay.ide.core.model.IEditingModel in project liferay-ide by liferay.

the class InputContext method flushModel.

protected void flushModel(IDocument doc) {
    boolean flushed = true;
    if (fEditOperations.size() > 0) {
        try {
            MultiTextEdit edit = new MultiTextEdit();
            if (isNewlineNeeded(doc)) {
                insert(edit, new InsertEdit(doc.getLength(), TextUtilities.getDefaultLineDelimiter(doc)));
            }
            for (int i = 0; i < fEditOperations.size(); i++) {
                insert(edit, (TextEdit) fEditOperations.get(i));
            }
            if (_fModel instanceof IEditingModel) {
                ((IEditingModel) _fModel).setStale(true);
            }
            edit.apply(doc);
            fEditOperations.clear();
        } catch (MalformedTreeException mte) {
            LiferayUIPlugin.logError(mte);
            flushed = false;
        } catch (BadLocationException ble) {
            LiferayUIPlugin.logError(ble);
            flushed = false;
        }
    }
    if (flushed && (_fModel instanceof IEditable)) {
        ((IEditable) _fModel).setDirty(false);
    }
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) IEditingModel(com.liferay.ide.core.model.IEditingModel) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) IEditable(com.liferay.ide.core.model.IEditable) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with IEditingModel

use of com.liferay.ide.core.model.IEditingModel in project liferay-ide by liferay.

the class InputContext method create.

protected void create() {
    _fDocumentProvider = createDocumentProvider(_fEditorInput);
    try {
        _fDocumentProvider.connect(_fEditorInput);
        _fModel = createModel(_fEditorInput);
        if (_fModel instanceof IModelChangeProvider) {
            _fModelListener = new IModelChangedListener() {

                public void modelChanged(IModelChangedEvent e) {
                    if (e.getChangeType() != IModelChangedEvent.WORLD_CHANGED) {
                        if (!_fEditor.getLastDirtyState()) {
                            _fEditor.fireSaveNeeded(_fEditorInput, true);
                        }
                        IModelChangeProvider provider = e.getChangeProvider();
                        if (provider instanceof IEditingModel) {
                            if (((IEditingModel) provider).isDirty()) {
                                addTextEditOperation(fEditOperations, e);
                            }
                        }
                    }
                }
            };
            ((IModelChangeProvider) _fModel).addModelChangedListener(_fModelListener);
        }
        IAnnotationModel amodel = _fDocumentProvider.getAnnotationModel(_fEditorInput);
        if (amodel != null) {
            amodel.connect(_fDocumentProvider.getDocument(_fEditorInput));
        }
        _fElementListener = new ElementListener();
        _fDocumentProvider.addElementStateListener(_fElementListener);
    } catch (CoreException ce) {
        LiferayUIPlugin.logError(ce);
    }
}
Also used : IModelChangedEvent(com.liferay.ide.core.model.IModelChangedEvent) CoreException(org.eclipse.core.runtime.CoreException) IModelChangeProvider(com.liferay.ide.core.model.IModelChangeProvider) IEditingModel(com.liferay.ide.core.model.IEditingModel) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IModelChangedListener(com.liferay.ide.core.model.IModelChangedListener)

Aggregations

IEditingModel (com.liferay.ide.core.model.IEditingModel)2 IEditable (com.liferay.ide.core.model.IEditable)1 IModelChangeProvider (com.liferay.ide.core.model.IModelChangeProvider)1 IModelChangedEvent (com.liferay.ide.core.model.IModelChangedEvent)1 IModelChangedListener (com.liferay.ide.core.model.IModelChangedListener)1 CoreException (org.eclipse.core.runtime.CoreException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 InsertEdit (org.eclipse.text.edits.InsertEdit)1 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1