Search in sources :

Example 46 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class Generator method exposeForm.

/**
   * @param rootContainer output parameter; should be LwRootContainer[1]
   */
public static FormProperty[] exposeForm(final Project project, final VirtualFile formFile, final LwRootContainer[] rootContainer) throws MyException {
    final Module module = ModuleUtil.findModuleForFile(formFile, project);
    LOG.assertTrue(module != null);
    final PsiPropertiesProvider propertiesProvider = new PsiPropertiesProvider(module);
    final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
    final LwRootContainer _rootContainer;
    try {
        _rootContainer = Utils.getRootContainer(doc.getText(), propertiesProvider);
    } catch (AlienFormFileException e) {
        throw new MyException(e.getMessage());
    } catch (Exception e) {
        throw new MyException(UIDesignerBundle.message("error.cannot.process.form.file", e));
    }
    rootContainer[0] = _rootContainer;
    final String classToBind = _rootContainer.getClassToBind();
    if (classToBind == null) {
        throw new MyException(UIDesignerBundle.message("error.form.is.not.bound.to.a.class"));
    }
    final PsiClass boundClass = FormEditingUtil.findClassToBind(module, classToBind);
    if (boundClass == null) {
        throw new MyException(UIDesignerBundle.message("error.bound.class.does.not.exist", classToBind));
    }
    final ArrayList<FormProperty> result = new ArrayList<>();
    final MyException[] exception = new MyException[1];
    FormEditingUtil.iterate(_rootContainer, new FormEditingUtil.ComponentVisitor<LwComponent>() {

        public boolean visit(final LwComponent component) {
            final String binding = component.getBinding();
            if (binding == null) {
                return true;
            }
            final PsiField[] fields = boundClass.getFields();
            PsiField field = null;
            for (int i = fields.length - 1; i >= 0; i--) {
                if (binding.equals(fields[i].getName())) {
                    field = fields[i];
                    break;
                }
            }
            if (field == null) {
                exception[0] = new MyException(UIDesignerBundle.message("error.field.not.found.in.class", binding, classToBind));
                return false;
            }
            final PsiClass fieldClass = getClassByType(field.getType());
            if (fieldClass == null) {
                exception[0] = new MyException(UIDesignerBundle.message("error.invalid.binding.field.type", binding, classToBind));
                return false;
            }
            if (instanceOf(fieldClass, JTextComponent.class.getName())) {
                result.add(new FormProperty(component, "getText", "setText", String.class.getName()));
            } else if (instanceOf(fieldClass, JCheckBox.class.getName())) {
                result.add(new FormProperty(component, "isSelected", "setSelected", boolean.class.getName()));
            }
            return true;
        }
    });
    if (exception[0] != null) {
        throw exception[0];
    }
    return result.toArray(new FormProperty[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) AlienFormFileException(com.intellij.uiDesigner.compiler.AlienFormFileException) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer) Document(com.intellij.openapi.editor.Document) IncorrectOperationException(com.intellij.util.IncorrectOperationException) AlienFormFileException(com.intellij.uiDesigner.compiler.AlienFormFileException) LwComponent(com.intellij.uiDesigner.lw.LwComponent) Module(com.intellij.openapi.module.Module) PsiPropertiesProvider(com.intellij.uiDesigner.PsiPropertiesProvider) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil)

Example 47 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class IpnbEditorUtil method createPlainCodeEditor.

public static Editor createPlainCodeEditor(@NotNull final Project project, @NotNull final String text) {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    assert editorFactory != null;
    final Document document = editorFactory.createDocument(text);
    EditorEx editor = (EditorEx) editorFactory.createEditor(document, project);
    setupEditor(editor);
    return editor;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document)

Example 48 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class StudyToolWindow method enterEditingMode.

public void enterEditingMode(VirtualFile taskFile, Project project) {
    final EditorFactory factory = EditorFactory.getInstance();
    Document document = FileDocumentManager.getInstance().getDocument(taskFile);
    if (document == null) {
        return;
    }
    WebBrowserManager.getInstance().setShowBrowserHover(false);
    final EditorEx createdEditor = (EditorEx) factory.createEditor(document, project, taskFile, false);
    Disposer.register(project, new Disposable() {

        public void dispose() {
            factory.releaseEditor(createdEditor);
        }
    });
    JComponent editorComponent = createdEditor.getComponent();
    editorComponent.setBorder(new EmptyBorder(10, 20, 0, 10));
    editorComponent.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
    EditorSettings editorSettings = createdEditor.getSettings();
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    mySplitPane.setFirstComponent(editorComponent);
    mySplitPane.repaint();
    StudyTaskManager.getInstance(project).setToolWindowMode(StudyToolWindowMode.EDITING);
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorSettings(com.intellij.openapi.editor.EditorSettings) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document) EmptyBorder(javax.swing.border.EmptyBorder)

Example 49 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class IpnbFileEditor method getState.

@NotNull
@Override
public FileEditorState getState(@NotNull FileEditorStateLevel level) {
    final int index = getIpnbFilePanel().getSelectedIndex();
    final Document document = FileDocumentManager.getInstance().getCachedDocument(myFile);
    long modificationStamp = document != null ? document.getModificationStamp() : myFile.getModificationStamp();
    return new IpnbEditorState(modificationStamp, index);
}
Also used : Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class PyStubsTest method testStubIndexMismatch.

public void testStubIndexMismatch() {
    VirtualFile vFile = myFixture.getTempDirFixture().createFile("foo.py");
    final Project project = myFixture.getProject();
    PsiFileImpl fooPyFile = (PsiFileImpl) PsiManager.getInstance(project).findFile(vFile);
    assertNotNull(fooPyFile);
    final Document fooDocument = fooPyFile.getViewProvider().getDocument();
    assertNotNull(fooDocument);
    final Collection<PyClass> classes = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
    assertEquals(0, classes.size());
    new WriteCommandAction.Simple(project, fooPyFile) {

        public void run() {
            fooDocument.setText("class Foo: pass");
        }
    }.execute();
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    documentManager.commitDocument(fooDocument);
    documentManager.performForCommittedDocument(fooDocument, () -> {
        fooPyFile.setTreeElementPointer(null);
        //classes = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
        //fooPyFile.unloadContent();
        DumbServiceImpl.getInstance(project).setDumb(true);
        try {
            assertEquals(1, ((PyFile) fooPyFile).getTopLevelClasses().size());
            assertFalse(fooPyFile.isContentsLoaded());
        } finally {
            DumbServiceImpl.getInstance(project).setDumb(false);
        }
        final Collection<PyClass> committedClasses = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
        assertEquals(1, committedClasses.size());
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document)

Aggregations

Document (com.intellij.openapi.editor.Document)1075 VirtualFile (com.intellij.openapi.vfs.VirtualFile)246 PsiFile (com.intellij.psi.PsiFile)191 Project (com.intellij.openapi.project.Project)164 NotNull (org.jetbrains.annotations.NotNull)138 Nullable (org.jetbrains.annotations.Nullable)129 TextRange (com.intellij.openapi.util.TextRange)122 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)117 PsiElement (com.intellij.psi.PsiElement)107 Editor (com.intellij.openapi.editor.Editor)104 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)56 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)45 IncorrectOperationException (com.intellij.util.IncorrectOperationException)43 IOException (java.io.IOException)42 RangeMarker (com.intellij.openapi.editor.RangeMarker)35 MockVirtualFile (com.intellij.mock.MockVirtualFile)33 File (java.io.File)32 ArrayList (java.util.ArrayList)32 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)30 List (java.util.List)29