summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/CMSBaseMenuInfo.java
blob: cb1909f22e43ae06e08d70dfe60cdde5a07dd947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.admin.certsrv;

import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import com.netscape.management.client.*;
import com.netscape.management.client.util.*;
import java.util.*;

/**
 * This class represents the menu item selection and associated
 * call back function.
 *
 * @author Jack Pan-Chen
 * @version $Revision$, $Date$
 * @see com.netscape.admin.certsrv
 */
public class CMSBaseMenuInfo implements IMenuInfo {

    /*==========================================================
     * variables
     *==========================================================*/
    //framework level menu catagory ids
    public static String MENU_FILE = Framework.MENU_FILE;
    public static String MENU_VIEW = Framework.MENU_VIEW;
    public static String MENU_OBJECT = ResourcePage.MENU_OBJECT;

    //menu bar menu items
    public static String MENU_KEYCERT = CMSAdminResources.MENU_KEYCERT;
    public static String MENU_REFRESH = CMSAdminResources.MENU_REFRESH;
    public static String MENU_KEYCERT_MANAGEMENT = CMSAdminResources.MENU_KEYCERT_MANAGEMENT;
    public static String MENU_PKCS11 = CMSAdminResources.MENU_PKCS11;
    public static String MENU_NEWCERT = CMSAdminResources.MENU_NEWCERT;

    //context menu items


    protected Vector mMenuCategoryIDs;      //stores the ids
    protected Vector mCategoryIDMenuItems;  //stores the menu items associated
                                            //with the specified id
    protected Vector mMenuItemsIDs;         //stores the item ids
    protected Vector mActionListeners;      //stores the action listeners

    protected ResourceBundle mResource;

	/*==========================================================
     * constructors
     *==========================================================*/
    public CMSBaseMenuInfo() {
        mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName());
        mMenuCategoryIDs = new Vector();
        mCategoryIDMenuItems = new Vector();
        mMenuItemsIDs = new Vector();
        mActionListeners = new Vector();
    }

    /*==========================================================
	 * public methods
     *==========================================================*/

    /**
     * Register menu items and associated action obejct
     * @param id menu catagory ID
     * @param item menu item
     * @param action IMenuAction object
     */
    public void registerMenuItem(String id, String keyword, IMenuAction action) {
        IMenuItem item = getMenuItemText(keyword);

        //register menu item and action pair
        int i = mMenuItemsIDs.indexOf(item.getID());
        if (i == -1) {
            mMenuItemsIDs.addElement(item.getID());
            mActionListeners.addElement(action);
        } else {
            mActionListeners.setElementAt(action,i);
        }

        //register catgory id and associated menu items
        i = mMenuCategoryIDs.indexOf(id);
        if (i == -1) {
            mMenuCategoryIDs.addElement(id);
            mCategoryIDMenuItems.addElement(new Vector());
        }
        i = mMenuCategoryIDs.indexOf(id);
        Vector items = (Vector) mCategoryIDMenuItems.elementAt(i);
        items.addElement(item);     //XXX check exist already ??
    }
    
    /**
     * Add menu item separator
     */
    public void addMenuItemSeparator(String id) {
        int i = mMenuCategoryIDs.indexOf(id);
        if (i < 0 ) {
            mMenuCategoryIDs.addElement(id);
            Vector items = new Vector();
            items.addElement(new MenuItemSeparator());
            mCategoryIDMenuItems.addElement(items);
        } else {
            Vector items = (Vector) mCategoryIDMenuItems.elementAt(i);
            items.addElement(new MenuItemSeparator());
        }
    }

    /**
      * Returns supported menu categories.
      */
	public String[] getMenuCategoryIDs() {
	    if (mMenuCategoryIDs.size() == 0) {
	        return null;
	    }
        String[] id = new String[mMenuCategoryIDs.size()];
        mMenuCategoryIDs.copyInto(id);
        //for(int i=0; i< id.length; i++)
        //    System.out.println("ID: "+id[i]);
        return id;
    }

    /**
      * Returns menu items for a particular menu category.
      */
	public IMenuItem[] getMenuItems(String category) {
        int i = mMenuCategoryIDs.indexOf(category);
        if (i != -1) {
            Vector v = (Vector) mCategoryIDMenuItems.elementAt(i);
            IMenuItem[] items = new IMenuItem[v.size()];
            v.copyInto(items);
            //for(int j=0; j< items.length; j++)
            //    System.out.println("ITEM: "+items[j].getID());
            return items;
        }
        return null;
	}

    /**
      * Notification that a menu item has been selected.
      */
	public void actionMenuSelected(IPage viewInstance, IMenuItem item) {
        int i = mMenuItemsIDs.indexOf(item.getID());
        if (i == -1)
            return;
        IMenuAction act = (IMenuAction) mActionListeners.elementAt(i);
        act.perform(viewInstance);
	}

    /*==========================================================
	 * priotected methods
     *==========================================================*/

    protected MenuItemText getMenuItemText(String keyword) {
        String name = mResource.getString("GENERAL_MENU_"+keyword+"_LABEL");
        if (name == null)
            name = "Missing Label";
        String desc = mResource.getString("GENERAL_MENU_"+keyword+"_DESC");
        if (desc == null)
            desc = " ";
        return new MenuItemText( keyword, name, desc);
    }

}