|
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.core.windows.services;
import org.netbeans.core.NbPlaces;
import org.openide.ErrorManager;
import org.openide.NotifyDescriptor;
import org.openide.actions.*;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.InstanceDataObject;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.openide.util.datatransfer.NewType;
import java.util.ResourceBundle;
/** The node for the menu folder representation.
* Delegates most of its functionality to the original data folder node.
* Final only for better performance, can be unfinaled.
*
* @author Dafe Simonek
*/
public final class MenuFolderNode extends DataFolder.FolderNode {
/** Actions which this node supports */
static SystemAction[] staticActions;
/** Actions of this node when it is top level menu node */
static SystemAction[] topStaticActions;
private static final Node.PropertySet[] NO_PROPERTIES = new Node.PropertySet[0];
private DataFolder folder;
private static final ResourceBundle bundle = NbBundle.getBundle (MenuFolderNode.class);
public MenuFolderNode () {
this (NbPlaces.getDefault().menus ());
}
/** Constructs this node with given node to filter.
*/
MenuFolderNode (DataFolder folder) {
folder.super(new MenuFolderChildren(folder));
this.folder = folder;
//JST: it displays only Menu as name! super.setDisplayName(NbBundle.getBundle (MenuFolderNode.class).getString("CTL_Menu_name"));
super.setShortDescription(bundle.getString("CTL_Menu_hint"));
super.setIconBase ("org/netbeans/core/resources/menu"); // NOI18N
}
public HelpCtx getHelpCtx () {
return new HelpCtx (MenuFolderNode.class);
}
/** Support for new types that can be created in this node.
* @return array of new type operations that are allowed
*/
public NewType[] getNewTypes () {
NewType newMenu = new NewType() {
public String getName () {
return bundle.getString ("CTL_newMenuName");
}
public void create () throws java.io.IOException {
newMenu();
}
};
if(getParentNode() instanceof MenuFolderNode) {
return new NewType[] {
newMenu,
//Fixed bug #5610 Added support for adding new separator through popup menu
new NewType () {
public String getName () {
return bundle.getString ("CTL_newMenuSeparator");
}
public void create () throws java.io.IOException {
newSeparator();
}
}
};
} else {
// #14415. Just menu for main menu bar.
return new NewType[] {newMenu};
}
}
void newMenu () {
NotifyDescriptor.InputLine il = new NotifyDescriptor.InputLine
(bundle.getString ("CTL_newMenuLabel"),
bundle.getString ("CTL_newMenuDialog"));
il.setInputText (bundle.getString ("CTL_newMenu"));
Object ok = org.openide.DialogDisplayer.getDefault ().notify (il);
if (ok == NotifyDescriptor.OK_OPTION) {
String s = il.getInputText();
if (!s.equals ("")) { // NOI18N
FileObject mnFO = folder.getPrimaryFile();
try {
FileObject newFO = mnFO.getFileObject(s);
if (newFO == null) {
String lastName = getLastName();
newFO = mnFO.createFolder (s);
// #13015. Set new item as last one.
if(lastName != null) {
mnFO.setAttribute(
lastName + "/" + newFO.getNameExt(), // NOI18N
Boolean.TRUE
);
}
}
} catch (java.io.IOException e) {
ErrorManager.getDefault ().notify (e);
}
}
}
}
//Fixed bug #5610 Added support for adding new separator through popup menu
void newSeparator () {
try {
InstanceDataObject instData = InstanceDataObject.find
(folder,null,"javax.swing.JSeparator"); // NOI18N
String lastName = getLastName();
DataObject d;
if (instData == null) {
d = InstanceDataObject.create
(folder,null,"javax.swing.JSeparator"); // NOI18N
} else {
d = instData.copy(folder);
}
// #13015. Set new item as last one.
if(lastName != null) {
folder.getPrimaryFile().setAttribute(
lastName + "/" + d.getPrimaryFile().getNameExt(), // NOI18N
Boolean.TRUE
);
}
} catch (java.io.IOException e) {
ErrorManager.getDefault ().notify (e);
}
}
//End
/** Gets name of last child.
* @return name of last menu or
|
... 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.