Java Code Examples for org.openide.loaders.DataFolder#setOrder()

The following examples show how to use org.openide.loaders.DataFolder#setOrder() . 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: DnDSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void reorderButtons( DataObject objToMove, DataObject objUnderCursor ) throws IOException {
    DataFolder backingFolder = getBackingFolder(currentToolbar);
    List<DataObject> children = new ArrayList<DataObject>( Arrays.asList( backingFolder.getChildren() ) );
    if( null == objUnderCursor ) {
        children.remove( objToMove );
        children.add( objToMove );
    } else {
        int targetIndex = children.indexOf( objUnderCursor );
        int currentIndex = children.indexOf( objToMove );
        if( currentIndex < targetIndex )
            targetIndex--;
        targetIndex = Math.max( 0, targetIndex );
        targetIndex = Math.min( children.size(), targetIndex );
        children.remove( objToMove );
        children.add( targetIndex, objToMove );
    }

    backingFolder.setOrder( children.toArray( new DataObject[children.size()]) );
}
 
Example 2
Source File: DiffPresenter.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void setDefaultDiffService(Object ds, String folder) {
    //System.out.println("setDefaultDiffService("+ds+")");
    FileObject services = FileUtil.getConfigFile(folder);
    DataFolder df = DataFolder.findFolder(services);
    DataObject[] children = df.getChildren();
    //System.out.println("  Got children.");
    for (int i = 0; i < children.length; i++) {
        if (children[i] instanceof InstanceDataObject) {
            InstanceDataObject ido = (InstanceDataObject) children[i];
            if (ido.instanceOf(ds.getClass())) {
                //System.out.println("  Found an instance of my class.");
                try {
                    if (ds.equals(ido.instanceCreate())) {
                        //System.out.println("  Have it, settings the order.");
                        df.setOrder(new DataObject[] { ido });
                        break;
                    }
                } catch (java.io.IOException ioex) {
                } catch (ClassNotFoundException cnfex) {}
            }
        }
    }
}
 
Example 3
Source File: FavoritesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void setName(String name) {
    // #113859 - keep order of children in favorites folder after rename
    final DataFolder favoritesFolder = FavoritesNode.getFolder();
    final DataObject[] children = favoritesFolder.getChildren();
    super.setName(name);
    try {
        favoritesFolder.setOrder(children);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 4
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void reorderAfterAddition(final DataFolder favourities, final DataObject[] children, final List<? extends DataObject> listAdd) {
    List<DataObject> listDest = new ArrayList<DataObject>();
    if (listAdd.size() > 0) {
        //Insert new nodes just before last (root) node
        DataObject root = null;
        //Find root
        for (int i = 0; i < children.length; i++) {
            FileObject fo = children[i].getPrimaryFile();
            if ("Favorites/Root.instance".equals(fo.getPath())) { //NOI18N
                root = children[i];
            }
        }
        if (root != null) {
            for (int i = 0; i < children.length; i++) {
                if (!root.equals(children[i])) {
                    listDest.add(children[i]);
                }
            }
            listDest.addAll(listAdd);
            listDest.add(root);
        } else {
            listDest.addAll(Arrays.asList(children));
            listDest.addAll(listAdd);
        }
        //Set desired order
        DataObject [] newOrder = listDest.toArray(new DataObject[listDest.size()]);
        try {
            favourities.setOrder(newOrder);
        } catch (IOException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
    }
}
 
Example 5
Source File: TextImporter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void reorder( String fileName, FileObject categoryFolder, int dropIndex ) throws IOException {
    if( dropIndex < 0 )
        return;
    FileObject itemFile = categoryFolder.getFileObject(fileName, "xml" ); //NOI18N
    if( null == itemFile )
        return;
    DataFolder catDob = DataFolder.findFolder(categoryFolder);
    DataObject[] children = catDob.getChildren();
    
    DataObject dob = DataObject.find(itemFile);
    if( null == dob )
        return;
    
    int curIndex = -1;
    for( int i=0; i<children.length; i++ ) {
        if( children[i].equals(dob) ) {
            curIndex = i;
            break;
        } 
    }
    if( curIndex < 0 )
        return;
    
    DataObject[] sortedChildren = new DataObject[children.length];
    if( dropIndex >= sortedChildren.length )
        dropIndex = sortedChildren.length-1;
    sortedChildren[dropIndex] = dob;
    int index = 0;
    for( int i=0; i<sortedChildren.length; i++ ) {
        if( sortedChildren[i] != null ) {
            continue;
        }
        DataObject tmp = children[index++];
        if( dob.equals(tmp) ) {
            i--;
            continue;
        }
        sortedChildren[i] = tmp;
    }
    
    catDob.setOrder(sortedChildren);
}