|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.vcscore.ui.fsmanager;
import java.awt.Image;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.util.Collection;
import java.util.ResourceBundle;
import org.netbeans.modules.vcscore.registry.FSInfo;
import org.netbeans.modules.vcscore.registry.FSRegistry;
import org.netbeans.modules.vcscore.registry.FSRegistryEvent;
import org.netbeans.modules.vcscore.registry.FSRegistryListener;
import org.openide.nodes.Children;
import org.openide.nodes.*;
import org.openide.cookies.FilterCookie;
import org.openide.filesystems.*;
import org.openide.util.NbBundle;
import org.openide.util.WeakListener;
/** Implements children. Nodes representing registered filesystems.
*
* @author Richard Gregor
*/
public class VcsChildren extends Children.Keys implements FSRegistryListener, Runnable {
private FSRegistry registry;
/** Create pattern children. The children are initilay unfiltered.
* @param elemrent the atteached class. For this class we recognize the patterns
*/
public VcsChildren() {
super();
debug("VcsChildren Init");
registry = FSRegistry.getDefault();
// Add registry listener
registry.addFSRegistryListener((FSRegistryListener) WeakListener.create(FSRegistryListener.class, this, registry));
}
/** Called when the preparation of nodes is needed
*/
protected void addNotify() {
setKeys (getVcsFileSystems());
}
/** Called when all children are garbage collected */
protected void removeNotify() {
setKeys( java.util.Collections.EMPTY_SET );
}
/** Creates nodes for given key.
*/
protected Node[] createNodes( final Object key ) {
debug("create nodes");
FSInfo info = (FSInfo)key;
FSInfoBeanNode node = null;
try{
node = new FSInfoBeanNode(info);
}catch(Exception e){
}
return new Node[] { node };
}
private Object[] getVcsFileSystems() {
debug("getVcsFileSystems");
FSInfo info[] = registry.getRegistered();
return info;
}
/** Called when a new filesystem information is added.
*
*/
public void fsAdded(FSRegistryEvent ev) {
resetKeys();
}
/** Called when a filesystem information is removed.
*
*/
public void fsRemoved(FSRegistryEvent ev) {
resetKeys();
}
/**
* Dispatch the refresh of children keys into AWT thread to avoid deadlock.
*/
private final void resetKeys() {
javax.swing.SwingUtilities.invokeLater(this);
}
/**
* Refresh the children keys. This is implemented as runnable, for
* convenient dispatch into AWT.
*/
public void run() {
setKeys(getVcsFileSystems());
}
static class FSInfoBeanNode extends AbstractNode implements PropertyChangeListener {
private FSInfo info;
public FSInfoBeanNode(FSInfo info) throws IntrospectionException{
super(Children.LEAF);
this.info = info;
setName(info.getFSRoot().toString());
setDisplayName(info.getFSRoot().toString());
info.addPropertyChangeListener(WeakListener.propertyChange(this, info));
}
/** Finds an icon for this node. The filesystem's icon is returned.
* @see java.bean.BeanInfo
* @see org.openide.filesystems.FileSystem#getIcon
* @param type constants from
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.