001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.soa.mapper.common.palette;
021:
022: import java.awt.event.ActionListener;
023: import javax.swing.JPopupMenu;
024:
025: import org.openide.ErrorManager;
026: import org.openide.nodes.Index;
027:
028: /**
029: * Popup menu for the functoid palette.
030: *
031: * @author Tientien Li
032: */
033: class PalettePopupMenu extends JPopupMenu {
034:
035: /**
036: * the palette root node
037: */
038: private PaletteNode mPalNode;
039:
040: /**
041: * Constructor to create a Palette Popup Menu
042: *
043: *
044: * @param palNode the root palette node
045: *
046: */
047: public PalettePopupMenu(PaletteNode palNode) {
048:
049: mPalNode = palNode;
050:
051: javax.swing.JMenuItem menuItem;
052: java.util.ResourceBundle bundle = PaletteManager.getBundle();
053:
054: menuItem = new javax.swing.JMenuItem(bundle
055: .getString("CTL_CreateCategory")); // NOI18N
056:
057: menuItem.addActionListener(new ActionListener() {
058:
059: public void actionPerformed(java.awt.event.ActionEvent evt) {
060: createCategory();
061: }
062: });
063: add(menuItem);
064: addSeparator();
065:
066: menuItem = new javax.swing.JMenuItem(bundle
067: .getString("CTL_OrderCategories")); // NOI18N
068:
069: menuItem.setEnabled(mPalNode.getCookie(Index.class) != null);
070: menuItem.addActionListener(new ActionListener() {
071:
072: public void actionPerformed(java.awt.event.ActionEvent evt) {
073: reorderCategories();
074: }
075: });
076: add(menuItem);
077: }
078:
079: /**
080: * reorder palette Categories on the list
081: *
082: *
083: */
084: private void reorderCategories() {
085:
086: Index order = (Index) mPalNode.getCookie(Index.class);
087:
088: if (order != null) {
089: order.reorder();
090: }
091: }
092:
093: /**
094: * create a new palette Category
095: *
096: *
097: */
098: private void createCategory() {
099:
100: try {
101: mPalNode.createNewCategory();
102: } catch (java.io.IOException e) {
103: if (Boolean.getBoolean("netbeans.debug.exceptions")) { // NOI18N
104: e.printStackTrace(System.err);
105: }
106:
107: ErrorManager.getDefault().notify(e);
108: }
109: }
110: }
|