|
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-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.vcscore.versioning.impl;
import java.beans.BeanInfo;
import java.awt.Image;
import org.openide.nodes.Sheet;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.util.actions.SystemAction;
import org.openide.DialogDisplayer;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileUtil;
/**
* Special node for filesystem (root folder). Takes icon from the
* filsystem. This class was copied from the core.
* It adds actions, cookies, icon and display name based on background file.
* Property sheet and customizer is based on background filesystem.
* It does not support any clipboard operations.
*
* @author Jaroslav Tulach, Martin Entlicher
*/
final class FileSystemNode extends AbstractNode implements java.beans.PropertyChangeListener {
/** generated Serialized Version UID */
static final long serialVersionUID = 1742510847721720990L;
/** message that gives name to the root */
private static java.text.MessageFormat formatRoot;
private final FileObject root;
/**
* @param root folder to work on
*/
public FileSystemNode(FileObject root) {
// TODO I'm hiding here a bug in FS, it wrongly works over deleted roots and shows random files!
// visible after deserialization of old setting that used already deleted folders
super(FileUtil.toFile(root).exists() ? new FolderChildren(root) : Children.LEAF);
this.root = root;
init();
}
public Cookie getCookie(Class type) {
// mimics DataNode because some actions heavily depends on DataObject cookie existence
if (type.isAssignableFrom(DataObject.class) || type.isAssignableFrom(DataFolder.class)) {
try {
return DataObject.find(root);
} catch (DataObjectNotFoundException e) {
// ignore, call super later on
}
}
return super.getCookie(type);
}
public org.openide.util.HelpCtx getHelpCtx() {
return null;
}
/** Adds properties from customize sheet and for sorting.
* @return the property sheet
*/
protected Sheet createSheet () {
Sheet s = super.createSheet ();
s.remove(Sheet.PROPERTIES);
try {
BeanInfo bi = java.beans.Introspector.getBeanInfo (fileSystem().getClass ());
org.openide.nodes.BeanNode.Descriptor d = org.openide.nodes.BeanNode.computeProperties (fileSystem(), bi);
Sheet.Set set = Sheet.createPropertiesSet ();
set.put (d.property);
s.put (set);
if (d.expert != null) {
set = Sheet.createExpertSet ();
set.put (d.expert);
s.put (set);
}
} catch (java.beans.IntrospectionException ex) {
org.openide.ErrorManager.getDefault ().notify (
org.openide.ErrorManager.INFORMATIONAL, ex
);
}
return s;
}
/** Name of the node.
*/
public String getName () {
return fileSystem() == null ? "" : fileSystem().getSystemName (); // NOI18N
}
public String getShortDescription() {
return fileSystem() == null ? "" : fileSystem().getDisplayName(); // NOI18N
}
/** initiates node */
void init() {
fileSystem().addPropertyChangeListener(org.openide.util.WeakListeners.propertyChange(this, fileSystem()));
setIconBase ("org/netbeans/modules/vcscore/versioning/impl/defaultFS"); // NOI18N
formatRoot = new java.text.MessageFormat ("{0}"); // NOI18N
initDisplayName ();
}
/** Initializes display name.
*/
void initDisplayName () {
String s = formatRoot.format (
new Object[] {fileSystem().getDisplayName (), fileSystem().getSystemName ()}
);
// TODO distinquish invalid FSs after external deletion
setDisplayName (s);
}
/** 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.