Java Code Examples for org.openide.loaders.DataObject#delete()

The following examples show how to use org.openide.loaders.DataObject#delete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientStubsGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected FileObject createDataObjectFromTemplate(final String template, 
         final FileObject dir,final String fileName, final String ext, 
         final boolean overwrite, Map<String,String> parameters ) throws IOException 
{
     FileObject rF0 = dir.getFileObject(fileName, ext);
     if(rF0 != null) {
         if(overwrite) {
             DataObject d = DataObject.find(rF0);
             if(d != null)
                 d.delete();
         } else {
             return rF0;
         }
     }
     DataObject d0 = RestUtils.createDataObjectFromTemplate(template, dir, 
             fileName, parameters);
     return d0.getPrimaryFile();
 }
 
Example 2
Source File: HintsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    HintMetadata hint = this.hint;
    try {
        if (hint==null) {
            hint = getSelectedHint();
        }
        if (hint == null) {
            return;
        }
        DataObject d = getDataObject(hint);
        if (d == null) {
            return;
        }
        if (JOptionPane.YES_OPTION == 
                JOptionPane.showConfirmDialog(errorTree,
                NbBundle.getMessage(HintsPanel.class, "MSG_DeleteConfirmMessage",  hint.displayName ),
                NbBundle.getMessage(HintsPanel.class, "MSG_DeleteConfirmTitle"),
                JOptionPane.YES_NO_OPTION)) {
            d.delete();
            RulesManager.getInstance().reload();
            cpBased.reset();
            //errorTreeModel.removeNodeFromParent(node);
            errorTreeModel = constructTM(Utilities.getBatchSupportedHints(cpBased).keySet(), false);
            setModel(errorTreeModel);
            if (logic != null) {
                logic.errorTreeModel = errorTreeModel;
            }
            hasNewHints = true;
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

}
 
Example 3
Source File: Favorites.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Removes references to nonexistent files.
 * Package-private for tests.
 */
void clearBrokenShadows() throws IOException {
    DataFolder f = FavoritesNode.getFolder();
    DataObject [] arr = f.getChildren();
    for (DataObject obj : arr) {
        if (! (obj instanceof DataShadow)) {
            obj.delete();
        }
    }
}
 
Example 4
Source File: Favorites.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Removes given file objects from Favorites if they are found as roots.
 * Files that are not found are silently ignored.
 * @param toRemove file objects to be removed.
 * @throws IOException When corresponding entry in userdir could not be deleted
 * @throws NullPointerException When any of <code>toRemove</code> parameters
 *         is <code>null</code>. It is undefined whether some of other non-null
 *         parameters were removed or not.
 */
public synchronized void remove(FileObject... toRemove) throws IOException, NullPointerException {
    DataFolder f = FavoritesNode.getFolder();
    DataObject [] arr = f.getChildren();
    for (DataObject obj : arr) {
        if (obj instanceof DataShadow) {
            FileObject root = ((DataShadow) obj).getOriginal().getPrimaryFile();
            for (FileObject rem : toRemove) {
                if (rem.equals(root)) {
                    obj.delete();
                }
            }
        }
    }
}
 
Example 5
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
* Removes the links.
*
* @param arr gives array of actually activated nodes.
*/
@Override
protected void performAction (Node[] arr) {
    for (int i = 0; i < arr.length; i++) {
        DataObject shad = arr[i].getCookie(DataObject.class);

        if (shad != null && shad.getFolder() == FavoritesNode.getFolder()) {
            try {
                shad.delete();
            } catch (IOException ex) {
                LOG.log(Level.WARNING, null, ex);
            }
        }
    }
}
 
Example 6
Source File: AbstractTestUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the DataObject with the given name. The name of a resource is
 * a "/"-separated path name that identifies the resource or Nbfs URL.
 */
public static boolean removeDocument(String name) throws IOException {
    DataObject  dataObject = findDataObject(name);
    if (dataObject != null) {
        dataObject.delete();
        return true;
    } else {
        return false;
    }
}
 
Example 7
Source File: FilesystemInterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void delete(File file) throws IOException {
    DataObject dao = DataObject.find(FileUtil.toFileObject(file));
    dao.delete();
}
 
Example 8
Source File: InteceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void delete(File file) throws IOException {
    DataObject dao = DataObject.find(FileUtil.toFileObject(file));    
    dao.delete();   
}
 
Example 9
Source File: AbstractSvnTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void delete(File file) throws IOException {
    DataObject dao = DataObject.find(FileUtil.toFileObject(file));    
    dao.delete();   
}
 
Example 10
Source File: XTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void deleteData(String path) {
    try {
    DataObject dao = TestUtil.THIS.findData(path);
    if (dao != null) dao.delete();
    } catch (Exception ex) {}
}
 
Example 11
Source File: CompletionJTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Main test method. */
public void test() {
    String folder;
    String name = "Document";
    String ext = "xml";
    XMLOptions options;
    DataObject dao;
    
    try {
        folder = getFilesystemName() + DELIM + getDataPackageName(DELIM);
        
        options = (XMLOptions) SystemOption.findObject(XMLOptions.class, true);
        options.setCompletionAutoPopup(false);
        
        dao = TestUtil.THIS.findData(name + "." + ext);
        if (dao != null) dao.delete();
        // catalog is only real XML template in the module :-(
        NewWizardOperator.create("XML" + DELIM + "OASIS XML Catalog", folder, name);
        editor = new EditorOperator(name);
    } catch (Exception ex) {
        log("Cannot setup test.", ex);
    }
    
    clearText();
    editor.txtEditorPane().setText(""
    + "<?xml version='1.0' encoding='UTF-8'?>\n"
    + "<!DOCTYPE html PUBLIC '-//Test//DTD XHTML 1.0 Subset//EN' 'xhtml.dtd'>\n");

    insert("<h");
    save();
    //tml>
    showCompl(NO_EMPTY);
    enter();
    insert(">\n");
    //<head>
    insertTag("<", ">\n", 1);
    //<title>Test page</title>
    
    /*!!! #36306 hack
    insertTag("<t", "Test page", -1);
     */
    insert("<t");
    showCompl(NO_EMPTY);
    esc();
    insert("Test page");
    //!!! end hack
    
    end();
    insert("\n");
    //</head>
    insertTag("</", "\n", -1);
    //<body>
    insertTag("<", ">\n", 0);
    //<h1 title="test">Test</h1>
    insertTag("<h", " ", 0);
    insertTag("t", "test\">Test", -1);
    insertTag("</", "\n", -1);
    //<table border="1">
    insertTag("<t", " ", 0);
    insertTag("b", "1\">\n", 1);
    //<tr align="center">
    insertTag("<t", " ", 4);
    insertTag("a", "center\">\n", -1);
    //<td>1</td><td>2</td>
    
    /*!!! #36306 hack
    insertTag("<td", "1", -1);
    end();
    insertTag("<td", "2", -1);
     */
    
    insert("<td");
    showCompl(NO_EMPTY);
    esc();
    insert("1");
    end();
    
    insert("<td");
    showCompl(NO_EMPTY);
    esc();
    insert("2");
    //!!! end hack
    
    end();
    insert("\n");
    //</tr>
    insertTag("</", "\n", -1);
    //</table>
    insertTag("</", "\n", -1);
    //</body>
    insertTag("</", "\n", -1);
    //</html>
    insertTag("</", "\n", -1);
    save();
    ref(editor.getText());
    compareReferenceFiles();
}
 
Example 12
Source File: CreateXMLTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testCreateXML() throws Exception {
    String content
    = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"
    + "<root/>\n";
    
    try {
        // delete document if exists
        DataObject dao = TestUtil.THIS.findData(DOCUMENT_NAME + '.' + XML_EXT);
        if (dao != null) dao.delete();
        // create new Data Object
        DataFolder dataFolder = DataFolder.findFolder(TestUtil.THIS.findData("").getPrimaryFile());
        XMLDataObject xmlDataObject = (XMLDataObject) TestUtil.createDataObject(dataFolder, DOCUMENT_NAME, XML_EXT, content);
        TreeEditorCookie cake = (TreeEditorCookie) xmlDataObject.getCookie(TreeEditorCookie.class);
        TreeDocument document = (TreeDocument) cake.openDocumentRoot();
        
        // Create Document Type
        DTDDataObject dtdDataObject = (DTDDataObject) TestUtil.THIS.findData(INTERNAL_DTD);
        cake = (TreeEditorCookie) dtdDataObject.getCookie(TreeEditorCookie.class);
        TreeDTD treeDTD = (TreeDTD) cake.openDocumentRoot();
        TreeDocumentType docType = new TreeDocumentType(DOCUMENT_NAME);
        docType.setSystemId(DTD_SYS_ID);
        TreeChild child = treeDTD.getFirstChild();
        while (child != null) {
            docType.appendChild((TreeChild) child.clone());
            child = child.getNextSibling();
        }
        document.setDocumentType(docType);
        
        // Create document
        TreeElement root = document.getDocumentElement();
        // Create root node
        root.addAttribute(new TreeAttribute("manager", "Tom Jerry"));
        root.addAttribute("id", "a");
        // Create node Product
        TreeElement product = new TreeElement("Product");
        root.appendChild(product);
        root.appendChild(new TreeText("\n"));
        product.addAttribute("isbn", "123456");
        product.addAttribute(new TreeAttribute("id", "b"));
        product.appendChild(new TreeText("\nXML Book\n"));
        // Create node Descript
        TreeElement descript = new TreeElement("Descript");
        product.appendChild(descript);
        product.appendChild(new TreeText("\n"));
        descript.addAttribute("lang", "Eng");
        descript.appendChild(new TreeText("\n"));
        descript.appendChild(new TreeText("The book describe how is using XML in"));
        descript.appendChild(new TreeText("\n"));
        descript.appendChild(new TreeGeneralEntityReference("company"));
        descript.appendChild(new TreeText("from "));
        descript.appendChild(new TreeGeneralEntityReference("cz"));
        descript.appendChild(new TreeText("\n"));
        descript.appendChild(new TreeText("Very important is author\n"));
        descript.appendChild(new TreeGeneralEntityReference("notice"));
        descript.appendChild(new TreeText("\n"));
        
        TestUtil.saveDataObject(xmlDataObject);
        ref(TestUtil.nodeToString(document));
        compareReferenceFiles();
    } catch (Exception ex) {
        log("\nCreating XML fails due:\n", ex);
        ex.printStackTrace();
        fail("\nCreating XML fails due:\n" + ex);
    }
}
 
Example 13
Source File: InterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void deleteDO (File toDelete) throws DataObjectNotFoundException, IOException {
    DataObject dao = DataObject.find(FileUtil.toFileObject(toDelete));
    dao.delete();
}
 
Example 14
Source File: TransformationActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Performs 'XSL Transformation...' action and checks output. */
public void testTransformation() throws Exception {
    
    final String OUT_FILE = "../out/document.html";
    //final String OUT_FILE = "output.html"; //!!!
    final String OUT_NODE = "out" + DELIM + "document";
    //final String OUT_NODE = "sources" + DELIM + "output"; //!!!
    
    // clear output and display Transformation Dialog
    DataObject dao = TestUtil.THIS.findData("out/document.html");
    if (dao != null) /* then */ dao.delete();
    XSLTransformationDialog dialog = transformXML("sources" + DELIM + "document");
    
    // fill in the TransformationDialog and execute transformation
    dialog.cboXSLTScript().clearText();
    dialog.cboXSLTScript().typeText("../styles/doc2html.xsl");
    dialog.cboXSLTScript().pressKey(KeyEvent.VK_TAB);
    
    dialog.cboOutput().clearText();
    dialog.cboOutput().typeText(OUT_FILE);
    dialog.cboJComboBox().selectItem(dialog.ITEM_DONOTHING);
    dialog.oK();
    
    // check the transformation's output
    char[] cbuf = new char[4000];
    Node htmlNode = findDataNode(OUT_NODE);
    new OpenAction().perform(htmlNode);
    // force editor to reload document
    EditorWindowOperator ewo = new EditorWindowOperator();
    EditorOperator eo = ewo.getEditor(htmlNode.getText());
    eo.setCaretPositionToLine(1);
    eo.insert("\n");
    eo.waitModified(true);
    eo.deleteLine(1);
    eo.save();
    
    String substring = "<h1>Testing Document</h1>";
    boolean result = eo.getText().indexOf(substring) != -1;
    assertTrue("Cannot find control substring:\n" + substring, (result));
    //ewo.close(); //!!! on test machines throws JemmyException: Exception in setClosed
}