当前位置: 首页>>代码示例>>Java>>正文


Java EditorCookie.openDocument方法代码示例

本文整理汇总了Java中org.openide.cookies.EditorCookie.openDocument方法的典型用法代码示例。如果您正苦于以下问题:Java EditorCookie.openDocument方法的具体用法?Java EditorCookie.openDocument怎么用?Java EditorCookie.openDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.cookies.EditorCookie的用法示例。


在下文中一共展示了EditorCookie.openDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject fo = fs.getRoot().createData("JFrame.java");
    
    source = convertStreamToString(getClass().getResourceAsStream("resources/JFrame.txt"));
    
    writeFile(source, fo);
    DataObject sourceDataObject = DataObject.find(fo);
    
    EditorCookie editorCookie = sourceDataObject.getCookie(EditorCookie.class);        
    if (editorCookie == null) {
        throw new IllegalArgumentException("I18N: Illegal data object type"+ sourceDataObject); // NOI18N
    }        
    StyledDocument document = editorCookie.getDocument();
    while(document == null) {
        document = editorCookie.openDocument();
    }        
                    
    instance = new JavaI18nFinder(document);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavaI18nFinderTest.java

示例2: openFileAtOffset

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
private static boolean openFileAtOffset(DataObject dataObject, int offset) throws IOException {
    EditorCookie ec = dataObject.getCookie(EditorCookie.class);
    LineCookie lc = dataObject.getCookie(LineCookie.class);
    if (ec != null && lc != null) {
        StyledDocument doc = ec.openDocument();
        if (doc != null) {
            int lineNumber = NbDocument.findLineNumber(doc, offset);
            if (lineNumber != -1) {
                Line line = lc.getLineSet().getCurrent(lineNumber);
                if (line != null) {
                    int lineOffset = NbDocument.findLineOffset(doc, lineNumber);
                    int column = offset - lineOffset;
                    line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column);
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:SpringXMLConfigEditorUtils.java

示例3: getDocument

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public static Document getDocument(FileObject modelSourceFileObject){
    Document result = null;
    try {
        DataObject dObject = DataObject.find(modelSourceFileObject);
        EditorCookie ec = (EditorCookie)dObject.getCookie(EditorCookie.class);
        Document doc = ec.openDocument();
        if(doc instanceof BaseDocument)
            return doc;            
        result = new org.netbeans.editor.BaseDocument(true, modelSourceFileObject.getMIMEType());
        String str = doc.getText(0, doc.getLength());
        result.insertString(0,str,null);            
    } catch (Exception dObjEx) {
        return null;
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:Utilities.java

示例4: getSourceDocument

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
private Document getSourceDocument(StreamSource ss) {
    Document sdoc = null;
    FileObject fo = ss.getLookup().lookup(FileObject.class);
    if (fo != null) {
        try {
            DataObject dao = DataObject.find(fo);
            if (dao.getPrimaryFile() == fo) {
                EditorCookie ec = dao.getCookie(EditorCookie.class);
                if (ec != null) {
                    sdoc = ec.openDocument();
                }
            }
        } catch (Exception e) {
            // fallback to other means of obtaining the source
        }
    } else {
        sdoc = ss.getLookup().lookup(Document.class);
    }
    return sdoc;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DiffResultsViewForLine.java

示例5: getDocument

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@Override
protected BaseDocument getDocument(FileObject fo, String mimeType, Language language) {
    // for some reason GsfTestBase is not using DataObjects for BaseDocument construction
    // which means that for example Java formatter which does call EditorCookie to retrieve
    // document will get difference instance of BaseDocument for indentation
    try {
         DataObject dobj = DataObject.find(fo);
         assertNotNull(dobj);

         EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
         assertNotNull(ec);

         return (BaseDocument)ec.openDocument();
    }
    catch (Exception ex){
        fail(ex.toString());
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:HtmlIndenterTest.java

示例6: postOpenEditor

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public static void postOpenEditor(BookmarkInfo bookmark) {
    try {
        final EditorCookie ec = findEditorCookie(bookmark);
        Document doc;
        if (ec != null && (doc = ec.openDocument()) != null) {
            updateCurrentLineIndex(bookmark, doc);
            BookmarkHistory.get().add(bookmark);
            final int lineIndex = bookmark.getCurrentLineIndex();
            // Post opening since otherwise the focus would get returned to an original pane
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    openEditor(ec, lineIndex); // Take url from bookmarkInfo
                }
            });
        }
    } catch (IOException ex) {
        LOG.log(Level.INFO, null, ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:BookmarkUtils.java

示例7: getDocument

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
private Document getDocument(FileObject fo){
    Document result = null;
    try {
        DataObject dObject = DataObject.find(fo);
        EditorCookie ec = (EditorCookie)dObject.getCookie(EditorCookie.class);
        Document doc = ec.openDocument();
        if(doc instanceof BaseDocument)
            return doc;
        result = new org.netbeans.editor.BaseDocument(true, fo.getMIMEType());
        String str = doc.getText(0, doc.getLength());
        result.insertString(0,str,null);
        
    } catch (Exception dObjEx) {
        return null;
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CatalogModelTest.java

示例8: dataObjectToString

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/** Converts DataObject to String.
 */
public static String dataObjectToString(DataObject dataObject) throws IOException, BadLocationException {
    EditorCookie editorCookie = (EditorCookie) dataObject.getCookie(EditorCookie.class);
    
    if (editorCookie != null) {
        StyledDocument document = editorCookie.openDocument();
        if (document != null) {
            return  document.getText(0, document.getLength());
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:AbstractTestUtil.java

示例9: assertOutput

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**Verify the content of the given resulting file.
 *
 * This method will "normalize" whitespaces in the file: generally, all
 * whitespaces are reduced to a single space both in the given code and
 * the code read from the file, before the comparison.
 *
 * @param fileName the name of the file that should be verified
 * @param code expected content of the resulting file.
 * @return the wrapper itself
 * @throws AssertionError if the file does not have the correct content
 */
public AppliedFix assertOutput(String fileName, String code) throws Exception {
    FileObject toCheck = sourceRoot.getFileObject(fileName);

    assertNotNull("Required file: " + fileName + " not found", toCheck);

    DataObject toCheckDO = DataObject.find(toCheck);
    EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
    Document toCheckDocument = ec.openDocument();

    String realCode = toCheckDocument.getText(0, toCheckDocument.getLength());

    assertSameOutput(realCode, code);
    return this;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:HintTest.java

示例10: createDocuments

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
protected Document[] createDocuments(String... fileName) {
    try {
        List<Document> docs = new ArrayList<>();
        FileSystem memFS = FileUtil.createMemoryFileSystem();
        for (String fName : fileName) {

            //we may also create folders
            StringTokenizer items = new StringTokenizer(fName, "/");
            FileObject fo = memFS.getRoot();
            while(items.hasMoreTokens()) {
                String item = items.nextToken();
                if(items.hasMoreTokens()) {
                    //folder
                    fo = fo.createFolder(item);
                } else {
                    //last, create file
                    fo = fo.createData(item);
                }
                assertNotNull(fo);
            }
            
            DataObject dobj = DataObject.find(fo);
            assertNotNull(dobj);

            EditorCookie cookie = dobj.getCookie(EditorCookie.class);
            assertNotNull(cookie);

            Document document = (Document) cookie.openDocument();
            assertEquals(0, document.getLength());

            docs.add(document);

        }
        return docs.toArray(new Document[]{});
    } catch (Exception ex) {
        throw new IllegalStateException("Error setting up tests", ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:TestBase.java

示例11: getDocument

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@Override
public Document getDocument(FileObject file) {
    try {
        final DataObject dobj = DataObject.find(file);
        final EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
        return ec == null ?
            null :
            ec.openDocument();
    } catch (DataObjectNotFoundException e) {
        return null;
    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:DocumentFactoryImpl.java

示例12: testDoNotAutocompleteQuteInHtmlAttribute

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public void testDoNotAutocompleteQuteInHtmlAttribute() throws DataObjectNotFoundException, IOException, BadLocationException {
    FileObject fo = getTestFile("testfiles/test.html");
    assertEquals("text/html", fo.getMIMEType());

    DataObject dobj = DataObject.find(fo);
    EditorCookie ec = dobj.getCookie(EditorCookie.class);
    Document document = ec.openDocument();
    ec.open();
    JEditorPane jep = ec.getOpenedPanes()[0];
    BaseAction type = (BaseAction) jep.getActionMap().get(NbEditorKit.defaultKeyTypedAction);
    //find the pipe
    String text = document.getText(0, document.getLength());

    int pipeIdx = text.indexOf('|');
    assertTrue(pipeIdx != -1);

    //delete the pipe
    document.remove(pipeIdx, 1);

    jep.setCaretPosition(pipeIdx);
    
    //type "
    ActionEvent ae = new ActionEvent(doc, 0, "\"");
    type.actionPerformed(ae, jep);

    //check the document content
    String beforeCaret = document.getText(pipeIdx, 2);
    assertEquals("\" ", beforeCaret);

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:CssBracketCompleterTest.java

示例13: getOutput

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**Return code after the fix has been applied.
 *
 * @param fileName file for which the code should be returned
 * @return the code after the fix has been applied
 */
public String getOutput(String fileName) throws Exception {
    FileObject toCheck = sourceRoot.getFileObject(fileName);

    assertNotNull(toCheck);

    DataObject toCheckDO = DataObject.find(toCheck);
    EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
    Document toCheckDocument = ec.openDocument();

    return toCheckDocument.getText(0, toCheckDocument.getLength());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:HintTest.java

示例14: prepareTest

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
protected void prepareTest(String code) throws Exception {
    clearWorkDir();

    FileObject workFO = FileUtil
            .toFileObject(getWorkDir());

    assertNotNull(workFO);

    FileObject sourceRoot = workFO
            .createFolder("src");
    FileObject buildRoot = workFO
            .createFolder("build");
    FileObject cache = workFO
            .createFolder("cache");

    FileObject data = FileUtil
            .createData(sourceRoot, "test/Test.java");

    org.netbeans.api.java.source.TestUtilities
            .copyStringToFile(FileUtil
            .toFile(data), code);

    data
            .refresh();

    SourceUtilsTestUtil
            .prepareTest(sourceRoot, buildRoot, cache);
    
    if (sourceLevel != null)
        SourceUtilsTestUtil.setSourceLevel(data, sourceLevel);

    DataObject od = DataObject
            .find(data);
    EditorCookie ec = od
            .getCookie(EditorCookie.class);

    assertNotNull(ec);

    doc = ec
            .openDocument();

    doc
            .putProperty(Language.class, JavaTokenId
            .language());
    doc
            .putProperty("mimeType", "text/x-java");

    JavaSource js = JavaSource
            .forFileObject(data);

    assertNotNull(js);

    info = SourceUtilsTestUtil
            .getCompilationInfo(js, Phase.RESOLVED);

    assertNotNull(info);
    assertTrue(info
            .getDiagnostics()
            .toString(), info
            .getDiagnostics()
            .isEmpty());
    
    if (getName().equals("testCommentVariable")) {
        info.getTreeUtilities().getComments(info.getCompilationUnit(), true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:IntroduceHintTest.java

示例15: testEmbeddingIndexerQueryOnOuterAndInner

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public void testEmbeddingIndexerQueryOnOuterAndInner() throws Exception {
    RepositoryUpdater ru = RepositoryUpdater.getDefault();
    assertEquals(0, ru.getScannedBinaries().size());
    assertEquals(0, ru.getScannedBinaries().size());
    assertEquals(0, ru.getScannedUnknowns().size());

    final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);

    srcCp = ClassPath.getClassPath(srcRoot, PATH_TOP_SOURCES);
    assertNotNull(srcCp);
    assertEquals(1, srcCp.getRoots().length);
    assertEquals(srcRoot, srcCp.getRoots()[0]);
    globalPathRegistry_register(PATH_TOP_SOURCES, srcCp);
    assertTrue (handler.await());
    assertEquals(0, handler.getBinaries().size());
    assertEquals(1, handler.getSources().size());
    assertEquals(srcRoot.toURL(), handler.getSources().get(0));

    //Symulate EditorRegistry
    final Source src = Source.create(srcFile);
    ParserManager.parse(Collections.<Source>singleton(src), new UserTask() {
        @Override
        public void run(ResultIterator resultIterator) throws Exception {
        }
    });
    final DataObject dobj = DataObject.find(srcFile);
    final EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
    final StyledDocument doc = ec.openDocument();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            final JEditorPane jp = new JEditorPane() {
                @Override
                public boolean isFocusOwner() {
                    return true;
                }
            };
            jp.setDocument(doc);
            EditorApiPackageAccessor.get().register(jp);
        }
    });

    //Do modification
    NbDocument.runAtomic(doc, new Runnable() {
        @Override
        public void run() {
            try {                    
                doc.insertString(doc.getLength(), "<C>", null); //NOI18N
            } catch (Exception e) {
                Exceptions.printStackTrace(e);
            }
        }
    });

    //Query should be updated
    QuerySupport sup = QuerySupport.forRoots(TopIndexer.NAME, TopIndexer.VERSION, srcRoot);
    Collection<? extends IndexResult> res = sup.query("_sn", srcFile.getNameExt(), QuerySupport.Kind.EXACT, (String[]) null);
    assertEquals(1,res.size());
    assertEquals(Boolean.TRUE.toString(), res.iterator().next().getValue("valid")); //NOI18N

    sup = QuerySupport.forRoots(InnerIndexer.NAME, InnerIndexer.VERSION, srcRoot);
    res = sup.query("_sn", srcFile.getNameExt(), QuerySupport.Kind.EXACT, (String[]) null);
    assertEquals(5,res.size());
    Map<? extends Integer,? extends Integer> count = countModes(res);
    assertEquals(Integer.valueOf(1), count.get(0));
    assertEquals(Integer.valueOf(2), count.get(1));
    assertEquals(Integer.valueOf(1), count.get(2));
    assertEquals(Integer.valueOf(1), count.get(3));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:73,代码来源:EmbeddedIndexerTest.java


注:本文中的org.openide.cookies.EditorCookie.openDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。