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


Java EditorCookie.saveDocument方法代码示例

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


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

示例1: testNationalCharactersSaved

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public void testNationalCharactersSaved() throws Exception {
    DataObject d = DataObject.find(testFileObject);
    
    encodingName = "ISO-8859-2"; // NOI18N
    
    EditorCookie o = d.getLookup().lookup(EditorCookie.class);
    StyledDocument doc = o.openDocument();
    doc.insertString(0, CZECH_STRING_UTF, null);
    
    o.saveDocument();

    // try to open the file
    InputStream istm = testFileObject.getInputStream();
    try {
        BufferedReader r = new BufferedReader(new InputStreamReader(istm, "ISO-8859-2")); // NOI18N
        String line = r.readLine();

        assertEquals("Text differs", CZECH_STRING_UTF, line); // NOI18N
    } finally {
        istm.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:DataEditorSupportEncodingTest.java

示例2: testSaveOpenConcurrent

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/** Tests that charset of saving document is not removed from cache by
 * concurrent openDocument() call (see #160784). */
public void testSaveOpenConcurrent() throws Exception {
    obj = DataObject.find(fileObject);
    DES sup = support();
    assertFalse("It is closed now", sup.isDocumentLoaded());
    assertNotNull("DataObject found", obj);

    Document doc = sup.openDocument();
    assertTrue("It is open now", support().isDocumentLoaded());
    doc.insertString(0, "Ahoj", null);
    EditorCookie s = (EditorCookie) sup;
    assertNotNull("Modified, so it has cookie", s);
    assertEquals(sup, s);

    Logger.getLogger(DataEditorSupport.class.getName()).setLevel(Level.FINEST);
    Logger.getLogger(DataEditorSupport.class.getName()).addHandler(new OpeningHandler(sup));
    s.saveDocument();
    
    assertLockFree(obj.getPrimaryFile());
    s.close();
    CloseCookie c = (CloseCookie) sup;
    assertNotNull("Has close", c);
    assertTrue("Close ok", c.close());
    assertLockFree(obj.getPrimaryFile());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:DataEditorSupportTest.java

示例3: saveButtonActionPerformed

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
    final HintMetadata selectedHint = getSelectedHint();
    final String selectedHintId = selectedHint.id;
    DataObject dob = getDataObject(selectedHint);
    EditorCookie ec = dob.getCookie(EditorCookie.class);
    try {
        ec.saveDocument();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    RulesManager.getInstance().reload();
    cpBased.reset();
    errorTreeModel = constructTM(Utilities.getBatchSupportedHints(cpBased).keySet(), false);
    setModel(errorTreeModel);
    if (logic != null) {
        logic.errorTreeModel = errorTreeModel;
    }
    select(getHintByName(selectedHintId));
    customHintCodeBeforeEditing = null;
    cancelEditActionPerformed(evt);
    hasNewHints = true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:HintsPanel.java

示例4: testLineSeparator

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public void testLineSeparator() throws Exception {
    File file = File.createTempFile("lineSeparator", ".txt", getWorkDir());
    file.deleteOnExit();
    FileObject fileObject = FileUtil.toFileObject(file);
    fileObject.setAttribute(FileObject.DEFAULT_LINE_SEPARATOR_ATTR, "\r");
    DataObject dataObject = DataObject.find(fileObject);
    EditorCookie editor = dataObject.getLookup().lookup(org.openide.cookies.EditorCookie.class);
    final StyledDocument doc = editor.openDocument();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            try {
                doc.insertString(doc.getLength(), ".\n", null);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });
    
    editor.saveDocument();
    InputStream inputStream = fileObject.getInputStream();
    assertEquals('.',inputStream.read());
    assertEquals('\r',inputStream.read());
    inputStream.close();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:LineSeparatorDataEditorSupportTest.java

示例5: save

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
 * Saves the document.
 * @see EditorCookie#saveDocument
 */
public void save(){
    EditorCookie edit = (EditorCookie) getLookup().lookup(EditorCookie.class);
    if (edit != null){
        try {
            edit.saveDocument();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:PUDataObject.java

示例6: saveByDocumentEditorCookie

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
void saveByDocumentEditorCookie(){
    try {
        DataObject dobj = DataObject.find(backendCatalogFileObj);
        EditorCookie thisDocumentEditorCookie = (EditorCookie)dobj.getCookie(EditorCookie.class);
        thisDocumentEditorCookie.saveDocument();
    } catch (IOException ex) {
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:CatalogFileWrapperDOMImpl.java

示例7: testIncompatibleCharacter

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public void testIncompatibleCharacter() throws Exception {
    DataObject d = DataObject.find(testFileObject);
    
    encodingName = "ISO-8859-1"; // NOI18N
    
    EditorCookie o = d.getLookup().lookup(EditorCookie.class);
    StyledDocument doc = o.openDocument();
    doc.insertString(0, CZECH_STRING_UTF, null);
    
    try {
        o.saveDocument();
        
        // try to open the file
        InputStream istm = testFileObject.getInputStream();
        try {
            BufferedReader r = new BufferedReader(new InputStreamReader(istm, "ISO-8859-2")); // NOI18N
            String line = r.readLine();
            
            int questionMarkPos = line.indexOf('?'); // NOI18N
            
            assertTrue("Should save question marks", questionMarkPos != -1); // NOI18N
        } finally {
            istm.close();
        }
        //fail("Exception expected");
    } catch (UnmappableCharacterException ex) {
        // expected exceptiom
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:DataEditorSupportEncodingTest.java

示例8: save

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
 * Saves the document.
 * @see EditorCookie#saveDocument
 */
public void save() {
    EditorCookie edit = (EditorCookie) getLookup().lookup(EditorCookie.class);
    if (edit != null) {
        try {
            edit.saveDocument();
        } catch (IOException ex) {
            ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:HibernateCfgDataObject.java

示例9: save

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
 * Saves the document.
 * @see EditorCookie#saveDocument
 */
public void save() {
    EditorCookie edit = (EditorCookie) getCookie(EditorCookie.class);
    if (edit != null) {
        try {
            edit.saveDocument();
        } catch (IOException ex) {
            ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:HibernateMappingDataObject.java

示例10: testCommentPrinted195048

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public void testCommentPrinted195048() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile,
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "}\n");
    String golden =
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n\n" +
        "    /**test*/\n" +
        "    private String t() {\n" +
        "        String s;\n" +
        "    }\n" +
        "}\n";

    JavaSource src = getJavaSource(testFile);
    Task task = new Task<WorkingCopy>() {
        public void run(final WorkingCopy wc) throws IOException {
            wc.toPhase(JavaSource.Phase.RESOLVED);
            final TreeMaker tm = wc.getTreeMaker();
            MethodTree nue = tm.Method(tm.Modifiers(EnumSet.of(Modifier.PRIVATE)),
                                       "t",
                                       tm.MemberSelect(tm.MemberSelect(tm.Identifier("java"), "lang"), "String"),
                                       Collections.<TypeParameterTree>emptyList(),
                                       Collections.<VariableTree>emptyList(),
                                       Collections.<ExpressionTree>emptyList(),
                                       "{java.lang.String s;}",
                                       null);
            GeneratorUtilities gu = GeneratorUtilities.get(wc);

            tm.addComment(nue, Comment.create(Style.JAVADOC, -2, -2, -2, "/**test*/"), true);
            nue = gu.importFQNs(nue);

            ClassTree clazz = (ClassTree) wc.getCompilationUnit().getTypeDecls().get(0);

            wc.rewrite(clazz, gu.insertClassMember(clazz, nue));
        }

    };
    src.runModificationTask(task).commit();
    //GeneratorUtilities.insertClassMember opens the Document:
    DataObject d = DataObject.find(FileUtil.toFileObject(testFile));
    EditorCookie ec = d.getLookup().lookup(EditorCookie.class);
    ec.saveDocument();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:51,代码来源:CommentsTest.java

示例11: testInsertMethodBeforeVariablesBug177824

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
 * #177824: Guarded Exception
 */
public void testInsertMethodBeforeVariablesBug177824() throws Exception {

    String source =
        "package test;\n" +
        "\n" +
        "import java.awt.event.ActionEvent;\n" +
        "import java.awt.event.ActionListener;\n" +
        "\n" +
        "public class Guarded1 implements ActionListener {\n" +
        "    \n" +
        "    private void fooActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fooActionPerformed\n" +
        "    }//GEN-LAST:event_fooActionPerformed\n" +
        "\n" +
        "    // Variables declaration - do not modify//GEN-BEGIN:variables\n" +
        "    private javax.swing.JButton jButton1;\n" +
        "    // End of variables declaration//GEN-END:variables\n" +
        "}\n";

    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, source);
    DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
    EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
    Document doc = editorCookie.openDocument();
    String golden =
        "package test;\n" +
        "\n" +
        "import java.awt.event.ActionEvent;\n" +
        "import java.awt.event.ActionListener;\n" +
        "\n" +
        "public class Guarded1 implements ActionListener {\n" +
        "    \n" +
        "    private void fooActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fooActionPerformed\n" +
        "    }//GEN-LAST:event_fooActionPerformed\n" +
        "\n" +
        "    public String toString() {\n" +
        "    }\n" +
        "\n" +
        "    // Variables declaration - do not modify//GEN-BEGIN:variables\n" +
        "    private javax.swing.JButton jButton1;\n" +
        "    // End of variables declaration//GEN-END:variables\n" +
        "}\n";

    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree newMethod = make.Method(
                    make.Modifiers(Collections.<Modifier>singleton(Modifier.PUBLIC)),
                    "toString",
                    make.Type("java.lang.String"),
                    Collections.<TypeParameterTree>emptyList(),
                    Collections.<VariableTree>emptyList(),
                    Collections.<ExpressionTree>emptyList(),
                    make.Block(Collections.<StatementTree>emptyList(), false),
                    null // default value - not applicable
            );
            ClassTree copy = make.insertClassMember(clazz, 2, newMethod);
            workingCopy.rewrite(clazz, copy);
        }
    };
    src.runModificationTask(task).commit();
    editorCookie.saveDocument();
    String res = TestUtilities.copyFileToString(testFile);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:73,代码来源:GuardedBlockTest.java

示例12: testAddMethodAfterVariables

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
 * #90424: Guarded Exception
 */
public void testAddMethodAfterVariables() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package javaapplication5;\n" +
        "\n" +
        "import java.awt.event.ActionEvent;\n" +
        "import java.awt.event.ActionListener;\n" +
        "\n" +
        "public class Guarded1 implements ActionListener {\n" +
        "    \n" +
        "    public Guarded1() {\n" +
        "    }\n" +
        "    \n" +
        "    // Variables declaration - do not modify//GEN-BEGIN:variables\n" +
        "    private javax.swing.JButton jButton1;\n" +
        "    // End of variables declaration//GEN-END:variables\n" +
        "}\n"
    );
    DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
    EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
    Document doc = editorCookie.openDocument();
    String golden = 
        "package javaapplication5;\n" +
        "\n" +
        "import java.awt.event.ActionEvent;\n" +
        "import java.awt.event.ActionListener;\n" +
        "\n" +
        "public class Guarded1 implements ActionListener {\n" +
        "    \n" +
        "    public Guarded1() {\n" +
        "    }\n" +
        "    \n" +
        "    // Variables declaration - do not modify//GEN-BEGIN:variables\n" +
        "    private javax.swing.JButton jButton1;\n" +
        "    // End of variables declaration//GEN-END:variables\n" +
        "\n" +
        "    public void actionPerformed(ActionEvent e) {\n" +
        "    }\n" +
        "}\n";
    
    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree newMethod = make.Method(
                    make.Modifiers(Collections.<Modifier>singleton(Modifier.PUBLIC)),
                    "actionPerformed",
                    make.PrimitiveType(TypeKind.VOID),
                    Collections.<TypeParameterTree>emptyList(),
                    Collections.<VariableTree>singletonList(
                        make.Variable(
                            make.Modifiers(Collections.<Modifier>emptySet()),
                            "e", 
                            make.Identifier("ActionEvent"), 
                        null)
                    ),
                    Collections.<ExpressionTree>emptyList(),
                    make.Block(Collections.<StatementTree>emptyList(), false),
                    null // default value - not applicable
            ); 
            ClassTree copy = make.addClassMember(clazz, newMethod);
            workingCopy.rewrite(clazz, copy);
        }
    };
    src.runModificationTask(task).commit();
    editorCookie.saveDocument();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:78,代码来源:GuardedBlockTest.java

示例13: test119048

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
 * #119048: Guarded Exception
 */
public void test119048() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package javaapplication5;\n" +
        "\n" +
        "public class NewJFrame extends javax.swing.JFrame {\n" +
        "\n" +
        "    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed\n" +
        "        // TODO add your handling code here:\n" +
        "        a = 3;\n" +
        "    }//GEN-LAST:event_jButton1ActionPerformed\n" +
        "\n" +
        "}"
    );
    DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
    EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
    Document doc = editorCookie.openDocument();
    String golden = 
        "package javaapplication5;\n" +
        "\n" +
        "public class NewJFrame extends javax.swing.JFrame {\n" +
        "\n" +
        "    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed\n" +
        "        int a;\n" +
        "        // TODO add your handling code here:\n" +
        "        a = 3;\n" +
        "    }//GEN-LAST:event_jButton1ActionPerformed\n" +
        "\n" +
        "}";
    
    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree method = (MethodTree) clazz.getMembers().get(1);
            VariableTree var = make.Variable(
                    make.Modifiers(Collections.<Modifier>emptySet()),
                    "a",
                    make.PrimitiveType(TypeKind.INT),
                    null
                );
            BlockTree copy = make.insertBlockStatement(method.getBody(), 0, var);
            workingCopy.rewrite(method.getBody(), copy);
        }
    };
    src.runModificationTask(task).commit();
    editorCookie.saveDocument();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:GuardedBlockTest.java

示例14: switchModule

import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
     * Enbles <code>enable = true</code>  or disables <code>enable = false</code> the module.
     */
    public static void switchModule(String codeName, boolean enable) throws Exception {
        String statusFile = "Modules/" + codeName.replace('.', '-') + ".xml";
        ModuleInfo mi = getModuleInfo(codeName);
/*
        FileObject fo = findFileObject(statusFile);
        Document document = XMLUtil.parse(new InputSource(fo.getInputStream()), false, false, null, EntityCatalog.getDefault());
        //Document document = XMLUtil.parse(new InputSource(data.getPrimaryFile().getInputStream()), false, false, null, EntityCatalog.getDefault());
        NodeList list = document.getElementsByTagName("param");
 
        for (int i = 0; i < list.getLength(); i++) {
            Element ele = (Element) list.item(i);
            if (ele.getAttribute("name").equals("enabled")) {
                ele.getFirstChild().setNodeValue(enable ? "true" : "false");
                break;
            }
        }
 
        FileLock lock = fo.lock();
        OutputStream os = fo.getOutputStream(lock);
        XMLUtil.write(document, os, "UTF-8");
        lock.releaseLock();
        os.close();
 */
        
        // module is switched
        if (mi.isEnabled() == enable) {
            return;
        }
        
        DataObject data = findDataObject(statusFile);
        EditorCookie ec = (EditorCookie) data.getCookie(EditorCookie.class);
        StyledDocument doc = ec.openDocument();
        
        // Change parametr enabled
        String stag = "<param name=\"enabled\">";
        String etag = "</param>";
        String enabled = enable ? "true" : "false";
        String result;
        
        String str = doc.getText(0,doc.getLength());
        int sindex = str.indexOf(stag);
        int eindex = str.indexOf(etag, sindex);
        if (sindex > -1 && eindex > sindex) {
            result = str.substring(0, sindex + stag.length()) + enabled + str.substring(eindex);
            //System.err.println(result);
        } else {
            //throw new IllegalStateException("Invalid format of: " + statusFile + ", missing parametr 'enabled'");
            // Probably autoload module
            return;
        }
        
        // prepare synchronization and register listener
        final Waiter waiter = new Waiter();
        final PropertyChangeListener pcl = new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("enabled")) {
                    waiter.notifyFinished();
                }
            }
        };
        mi.addPropertyChangeListener(pcl);
        
        // save document
        doc.remove(0,doc.getLength());
        doc.insertString(0,result,null);
        ec.saveDocument();
        
        // wait for enabled propety change and remove listener
        waiter.waitFinished();
        mi.removePropertyChangeListener(pcl);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:75,代码来源:AbstractTestUtil.java


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