|
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.url;
import java.lang.reflect.InvocationTargetException;
import java.io.IOException;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.JSeparator;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
import org.openide.actions.*;
import org.openide.awt.Actions;
import org.openide.cookies.InstanceCookie;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.InstanceDataObject;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Index;
import org.openide.nodes.Node;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.NotifyDescriptor;
import org.openide.filesystems.Repository;
import org.openide.util.actions.SystemAction;
import org.openide.util.datatransfer.NewType;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
/** The node for the bookmarks folder representation.
* Delegates most of its functionality to the original data folder node.
* Final only for better performance, can be unfinaled.
*
* @author Ian Formanek
* @see org.openide.Places.Folders#bookmarks
*/
public final class BookmarksNode extends DataFolder.FolderNode {
/** Empty array of properties sets. This node has no proeprties. */ // PENDING
private static final Node.PropertySet[] NO_PROPERTIES = new Node.PropertySet[0];
/** Resource bundle used for i18n-zing strings in this source. */
private static ResourceBundle bundle;
/** Constructs node for default bookmark folder.
* @see org.openide.Places.Folders#bookmarks */
public BookmarksNode() {
this(DataFolder.findFolder(Repository.getDefault()
.getDefaultFileSystem()
.findResource("Bookmarks"))); //NOI18N
}
/** Constructs this node with given folder as enclosing instance.
* @param folder folder which to filter for bookmarks */
private BookmarksNode(DataFolder folder) {
folder.super(new BookmarksFolderChildren(folder));
setIconBase("org/netbeans/modules/url/bookmarks"); // NOI18N
// Trick: To have a node name localized but remain the object name
// the same until renamed explictly. -> due to be able show
// node names without ampersands for shortcuts and be able to show
// shortcuts in bookmarks menu.
// Note: see getDisplayName method bellow.
setName(super.getDisplayName(), false);
}
/** Gets display name. Overrides superclass method.
* Cuts ampersand from the original display name. */
public String getDisplayName() {
return Actions.cutAmpersand(super.getDisplayName());
}
/** Overrides superclass method. */
protected Sheet createSheet() {
Sheet sheet = new Sheet();
Sheet.Set sheetSet = Sheet.createPropertiesSet();
sheetSet.put(createNameProperty());
sheet.put(sheetSet);
return sheet;
}
/** Creates a name property. */
private Node.Property createNameProperty() {
return new PropertySupport.ReadWrite (
DataObject.PROP_NAME,
String.class,
NbBundle.getBundle(BookmarksNode.class).getString("PROP_Name"),
NbBundle.getBundle(BookmarksNode.class).getString("PROP_NameShortDescription")) {
public Object getValue () {
return BookmarksNode.this.getName();
}
public void setValue(Object val) throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
if (!canWrite())
throw new IllegalAccessException();
if (!(val instanceof String))
throw new IllegalArgumentException();
try {
getDataObject().rename ((String)val);
} catch (IOException ex) {
throw new InvocationTargetException (ex);
}
}
public boolean canWrite () {
return canRename();
}
};
}
/** Indicates whether the node can be renamed.
* Forbids renaming if this node represents places.folders.bookmarks.
* Overrides superclass method.
* @see org.openide.Places.Folders#bookmarks */
public boolean canRename() {
if (getDataObject() == DataFolder.findFolder(Repository.getDefault()
.getDefaultFileSystem()
.findResource("Bookmarks"))) { //NOI18N
return false;
}
return super.canRename();
}
/** Gets short description. Overrides superclass method. */
public String getShortDescription() {
return getBundle().getString("CTL_Bookmarks_hint");
}
/** Gets help context. Overrides superclass method. */
public HelpCtx getHelpCtx () {
return new HelpCtx(BookmarksNode.class);
}
/** Gets new types. Overrides superclass method.
* @return array of new type for bookmark and bookmark folder
*/
public NewType[] getNewTypes() {
return new NewType[] {
new NewBookmarkType(),
new NewFolderType(),
new NewSeparatorType()
};
}
/** Creates actions for this node. Overrides superclass method. */
protected SystemAction[] createActions () {
ArrayList list = new ArrayList();
list.add(SystemAction.get(FileSystemAction.class));
list.add(null);
list.add(SystemAction.get(PasteAction.class));
list.add(null);
list.add(SystemAction.get(ReorderAction.class));
list.add(null);
list.add(SystemAction.get(NewAction.class));
Node parent = getParentNode();
// For top level node no delete action.
if(parent != null && parent instanceof BookmarksNode) {
list.add(SystemAction.get(DeleteAction.class));
}
list.add(null);
list.add(SystemAction.get(PropertiesAction.class));
return (SystemAction[])list.toArray(new SystemAction[list.size()]);
}
/** Indicates if this node can be remnoved. Overrides superclass method.
* @return true if this node has parent which is instance of
*
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.