Search in sources :

Example 1 with IEditable

use of com.liferay.ide.core.model.IEditable 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 IEditable

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

the class InputContext method flushEditorInput.

public void flushEditorInput() {
    if (fEditOperations.size() > 0) {
        IDocument doc = _fDocumentProvider.getDocument(_fEditorInput);
        _fDocumentProvider.aboutToChange(_fEditorInput);
        flushModel(doc);
        _fDocumentProvider.changed(_fEditorInput);
        _fValidated = false;
    } else if ((_fModel instanceof IEditable) && ((IEditable) _fModel).isDirty()) {
        // When text edit operations are made that cancel each other out,
        // the editor is not undirtied
        // e.g. Extensions page: Move an element up and then move it down
        // back in the same position: Bug # 197831
        ((IEditable) _fModel).setDirty(false);
    }
}
Also used : IEditable(com.liferay.ide.core.model.IEditable) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IEditable (com.liferay.ide.core.model.IEditable)2 IEditingModel (com.liferay.ide.core.model.IEditingModel)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 InsertEdit (org.eclipse.text.edits.InsertEdit)1 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1