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

The following examples show how to use org.openide.loaders.DataObject#move() . 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: AnnotationProviderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails
public void testContextLookupIsConsistentAfterMove() throws Exception {              
    ConsistencyCheckProvider.setCalled(0);
    // Prepare the data object (to initialize the lookup)
    FileObject fo = fs.getRoot().createData("test2", "txt");
    DataObject data = DataObject.find(fo);
    EditorCookie ec = data.getCookie(EditorCookie.class);

    // now move it (the lookup should update itself)
    FileObject fld = fs.getRoot().createFolder("folder1");
    DataFolder df = DataFolder.findFolder(fld);
    data.move(df);

    // now open the editor (invoke AnnotationProviders)
    // and check the lookup
    ec.open();
    assertEquals("Consistent lookup content", data.getPrimaryFile(),ConsistencyCheckProvider.getInLkp());
}
 
Example 2
Source File: AnnotationProviderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails
public void testContextLookupFiresDuringMove() throws Exception {              
    // Prepare the data object (to initialize the lookup)
    FileObject fo = fs.getRoot().createData("test3", "txt");
    DataObject data = DataObject.find(fo);
    EditorCookie ec = data.getCookie(EditorCookie.class);

    // open the editor and check the lookup before move
    ec.open();
    assertEquals("Lookup content consistent before move", data.getPrimaryFile(),ConsistencyCheckProvider.getInLkp());

    forceGC ();
    
    // now move the file
    ConsistencyCheckProvider.setCalled(0);
    FileObject fld = fs.getRoot().createFolder("folder1");
    DataFolder df = DataFolder.findFolder(fld);
    data.move(df);

    forceGC ();
    
    // check the result
    assertEquals("Lookup fires one change during move", 1, ConsistencyCheckProvider.changes);
    assertEquals("Lookup content consistent after move", data.getPrimaryFile(),ConsistencyCheckProvider.getInLkp());
}
 
Example 3
Source File: DocumentTitlePropertyTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Test updating document property Document.TitleProperty when dataobject is moved */
public void testMove () throws IOException {
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj");
    FileUtil.createFolder(FileUtil.getConfigRoot(), "newFolder");

    DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj"));
    DataFolder dFolder = (DataFolder) DataObject.find(FileUtil.getConfigFile("newFolder"));

    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );

    EditorCookie ec = obj.getCookie(EditorCookie.class);

    StyledDocument doc = ec.openDocument();

    String val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("someFolder/someFile.obj"));

    obj.move(dFolder);

    val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("newFolder/someFile.obj"));
}
 
Example 4
Source File: ActionPasteType.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Transferable paste() throws IOException {
    if (targetFolder != null) {
        for (Iterator iterator = sourceDataObjects.iterator(); iterator.hasNext();) {
            DataObject dataObject = (DataObject) iterator.next();
            boolean isValid = dataObject != null && dataObject.isValid();
            
            if (isValid && pasteOperation == LoaderTransfer.CLIPBOARD_COPY) {
                dataObject.createShadow(targetFolder);
            } 
            
            if (isValid && pasteOperation == LoaderTransfer.CLIPBOARD_CUT) {
                dataObject.move(targetFolder);
            }
                                
        }                
    }
    return null;
}
 
Example 5
Source File: SourceTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testDOMove154813() throws IOException {
    FileObject file = createFileObject("test1/empty.txt", "", "\n");
    DataObject dfile = DataObject.find(file);
    Document doc = createDocument("text/x-testtesttest", "");
    doc.putProperty(Document.StreamDescriptionProperty, dfile);
    Source source = Source.create(doc);
    assertNotNull("No Source for " + doc, source);
    FileObject wd = file.getParent().getParent();
    FileObject nueParent = wd.getFileObject("test2");

    if (nueParent == null) {
        nueParent = wd.createFolder("test2");
    }

    dfile.move(DataFolder.findFolder(nueParent));
    source = Source.create(doc);
    assertNotNull("No Source for " + doc, source);
    assertEquals("Correct FileObject", dfile.getPrimaryFile(), source.getFileObject());
}
 
Example 6
Source File: DataEditorSupportMoveTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testModifiedMove() throws Exception {
    FileObject root = FileUtil.toFileObject(getWorkDir());
    FileObject data = FileUtil.createData(root, "someFolder/someFile.obj");
    
    DataObject obj = DataObject.find(data);
    assertEquals( MyDataObject.class, obj.getClass());
    assertEquals(MyLoader.class, obj.getLoader().getClass());
    
    EditorCookie ec = obj.getLookup().lookup(EditorCookie.class);
    assertNotNull("Editor cookie found", ec);
    ec.open();
    JEditorPane[] arr = openedPanes(ec);
    assertEquals("One pane is opened", 1, arr.length);
            
    StyledDocument doc = ec.openDocument();
    doc.insertString(0, "Ahoj", null);
    assertTrue("Modified", obj.isModified());
    Thread.sleep(100);
    
    FileObject newFolder = FileUtil.createFolder(root, "otherFolder");
    DataFolder df = DataFolder.findFolder(newFolder);
    
    obj.move(df);
    
    assertEquals(newFolder, obj.getPrimaryFile().getParent());
    
    assertEquals("Still one editor", 1, openedPanes(ec).length);
    DD.assertNoCalls();
}
 
Example 7
Source File: DnDSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Move toolbar button to a new position.
 */
private boolean moveButton( DataObject ob, int dropIndex, boolean dropBefore ) throws IOException {
    //find out which button is currently under the drag cursor
    DataObject objUnderCursor = getDataObjectUnderDropCursor( dropIndex-1, dropBefore );

    if( sourceToolbar != currentToolbar ) {
        //move button to the new toolbar
        ob.move(getBackingFolder(currentToolbar));
    }

    reorderButtons( ob, objUnderCursor );
    //else we're dragging a button to an empty toolbar
    return true;
}
 
Example 8
Source File: FilesystemInterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void moveDO(File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));
    DataObject daoTarget = DataObject.find(FileUtil.toFileObject(to.getParentFile()));
    daoFrom.move((DataFolder) daoTarget);
}
 
Example 9
Source File: InteceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void moveDO(File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));    
    DataObject daoTarget = DataObject.find(FileUtil.toFileObject(to.getParentFile()));    
    daoFrom.move((DataFolder) daoTarget);    
}
 
Example 10
Source File: InterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void moveDO (File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));
    DataObject daoTarget = DataObject.find(FileUtil.toFileObject(to.getParentFile()));
    daoFrom.move((DataFolder) daoTarget);
}