Search in sources :

Example 1 with ILeafNode

use of org.eclipse.xtext.nodemodel.ILeafNode in project mechanoid by robotoworks.

the class NewMechanoidDBFileWizard method onNewResourceEditorOpened.

@Override
protected void onNewResourceEditorOpened(IEditorPart editor) {
    final XtextEditor xeditor = (XtextEditor) editor;
    final IXtextDocument document = xeditor.getDocument();
    xeditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {

        @Override
        public void process(XtextResource state) throws Exception {
            Model model = (Model) state.getContents().get(0);
            MigrationBlock migrationBlock = model.getDatabase().getMigrations().get(0);
            //$NON-NLS-1$
            ILeafNode node = findFirstLeafNodeForKeyword(migrationBlock, "{");
            int position = node.getOffset() + 1;
            //$NON-NLS-1$
            document.replace(position, 0, "\n\t\t");
            xeditor.selectAndReveal(position + 3, 0);
        }
    });
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) Model(com.robotoworks.mechanoid.db.sqliteModel.Model) XtextResource(org.eclipse.xtext.resource.XtextResource) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

MigrationBlock (com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)1 Model (com.robotoworks.mechanoid.db.sqliteModel.Model)1 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1