summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/CMSBaseResourceModel.java
blob: b7ec04e3a78dad2ed48aba04cfe03d49ea0ef366 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// --- 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 java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import com.netscape.management.client.*;
import com.netscape.management.client.util.*;
import com.netscape.management.client.console.*;
import com.netscape.admin.certsrv.config.*;
import com.netscape.admin.certsrv.menu.*;

/**
 *	Netscape Certificate Server 4.0 BASE resource model.<br>
 *
 *  This class represtents the tree node objects displayed
 *  in the right tree-view.<p>
 *
 *  Menu Event are now handled by extenal IMenuInfo object.
 *
 * @author Jack Pan-Chen
 * @author Thomas Kwan
 * @version $Revision$, $Date$
 * @see com.netscape.admin.certsrv
 */
public class CMSBaseResourceModel extends ResourceModel {

    /*==========================================================
     * variables
     *==========================================================*/

    private CMSResourcePage mPage;          // physical page representation
	protected ConsoleInfo mConsoleInfo;     // console info 
	protected CMSServerInfo mServerInfo;    // server info
	protected IResourceObject[] mSelection; // selected objects
	protected Vector mSelectionListeners;   // listener list
	protected ResourceBundle mResource;     // resource boundle
	protected Hashtable mNickNameRegistry;  // storing the obejct nickname pair
    protected RefreshTabPane mRefreshPane;

	/*==========================================================
	 * constructors
	 *==========================================================*/

	/**
	 * Constructor - create all panels.
	 *
	 * @param info	Global console connection information
	 * @param serverInfo Server instance connection information
	 */
	public CMSBaseResourceModel( ConsoleInfo info, CMSServerInfo serverInfo ) {
		mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName());
		mConsoleInfo = info;
		mServerInfo = serverInfo;
		mNickNameRegistry = new Hashtable();
		mSelectionListeners = new Vector();
		init();
	}

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

    /**
     * Set the physical page associated with this model
     * @param page CMSResourcePage instance
     */
    public void setResourcePage(CMSResourcePage page) {
        mPage = page;    
    }
    
    public CMSResourcePage getResourcePage() {
        return mPage;
    }

    /**
     * Return the global console information reference.
     *
     * @return The global console information reference.
     **/
    public ConsoleInfo getConsoleInfo() {
		return mConsoleInfo;
    }

    /**
     * Return the Server information reference.
     *
     * @return The server information reference.
     **/
    public CMSServerInfo getServerInfo() {
		return mServerInfo;
    }


    /**
     * Get Parent Frame
     * @return frame to be usd in dialogs
     */
    public JFrame getFrame() {
        return UtilConsoleGlobals.getActivatedFrame();
    }

    /**
     * Tree Nodes selected call back
     */
	public void actionObjectSelected( IPage viewInstance,
									  IResourceObject[] selection,
									  IResourceObject[] previousSelection) {

		//Debug.println("CMSResourceModel: actionObjectSelected()");
		mSelection = selection;
		if ( mSelection == null )
			mSelection = new IResourceObject[0];
		Vector selected = new Vector();
		Vector toNotify = new Vector();
		/* Signal all selected objects, keep track of which ones */
		for( int i = 0; i < mSelection.length; i++ ) {
		    IResourceObject sel = mSelection[i];
		    Component c = sel.getCustomPanel();
            if (mRefreshPane != null) {
                mRefreshPane.select(c);
            }
		    if ( (c != null) && (mSelectionListeners.indexOf( c ) >= 0) ) {
				toNotify.addElement( sel );
    		}
   			selected.addElement( c );
		}

		/* All other listeners must be unselected */
		boolean canMove = true;
		if ( previousSelection != null ) {
    		for( int i = 0; i < previousSelection.length; i++ ) {
	    	    IResourceObject sel = previousSelection[i];
    		    Component c = sel.getCustomPanel();
    		    if ( (mSelectionListeners.indexOf( c ) >= 0) &&
		             (selected.indexOf( c ) < 0) ) {
		            try {
            			IResourceSelectionListener l =
               			    (IResourceSelectionListener)c;
        	    		if (!l.unselect( sel, viewInstance ))
        	    		    canMove = false;
        	    	} catch ( Exception e ) {
        	    	    //System.err.println( e );
        	    	    Debug.println( e.toString() );
        	    	}
        		}
    		}
    	}

        if (!canMove)
            return;

		for( int i = 0; i < toNotify.size(); i++ ) {
		    IResourceObject sel =
				(IResourceObject)toNotify.elementAt( i );
		    Component c = sel.getCustomPanel();
			IResourceSelectionListener l =
				(IResourceSelectionListener)c;
			l.select( sel, viewInstance );
		}

		//change menu
		super.actionObjectSelected(viewInstance, selection, previousSelection);
	}

    public void setRefreshCallback(RefreshTabPane pane) {
        mRefreshPane = pane;
    }

    /**
      * Adds a listener that is interested in receiving selection events.
	  * Called by panels
      */
	public void addIResourceSelectionListener(IResourceSelectionListener l) {
		mSelectionListeners.addElement(l);
	}

    /**
      * Removes previously added IDSResourceSelectionListener.
	  * Called by panels
      */
	public void removeIResourceSelectionListener(IResourceSelectionListener l) {
		mSelectionListeners.removeElement(l);
    }

	/**
     *   Returns list of listeners for this model.
	 */
	public Enumeration getSelectionListeners() {
		return mSelectionListeners.elements();
	}

    /**
     * The SubSystemUILoader should use this function to add
     * subsystem node into the root node. SubSystemLoader is responsible
     * for setting up the subtrees.
     */
    public void addSubSystemNode(CMSResourceObject node) {
        ((CMSResourceObject)getRoot()).add(node);    
    }
    
    /**
     * Register the nick name of the resource object, so other sub system
     * can look up and retrieve the corresponding resource object.
     */
    public void registerNickName(String nickName, CMSResourceObject node) {
        mNickNameRegistry.put(nickName, node);    
    }
    
    /**
     * Retrieve the resource obejct associated with this nickname
     */
    public CMSResourceObject getByNickName(String nickName) {
        return (CMSResourceObject) mNickNameRegistry.get(nickName);
    }
    
	/**
	 * Start the zipping status bar
	 */
    public void progressStart() {
        mPage.progressStart();
    }

    /**
     * Stop the zipping status bar
     */
    public void progressStop() {
        mPage.progressStop();
    }	    
    
    /*==========================================================
	 * priotected methods
     *==========================================================*/
    
    protected void init() {
        CMSResourceObject root = new CMSResourceObject();
		root.setName(mResource.getString(CMSAdminResources.CERT_SERVER_NAME)+":" + mServerInfo.getPort());
		root.setCustomPanel( new CMSBlankPanel(this));
		root.setIcon( CMSAdminUtil.getImage(CMSAdminResources.IMAGE_CERTICON_SMALL));
		root.setAllowsChildren(true);
		super.setRoot( root );
    }

}