1
/** BEGIN COPYRIGHT BLOCK
2
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
3
* Copyright (C) 2005 Red Hat, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* END COPYRIGHT BLOCK **/
20
package com.netscape.admin.dirserv;
22
import java.awt.Component;
23
import java.awt.event.*;
24
import java.util.Enumeration;
25
import java.util.Vector;
26
import com.netscape.management.client.*;
27
import com.netscape.management.client.util.ResourceSet;
28
import com.netscape.management.client.util.Debug;
29
import com.netscape.management.client.console.ConsoleInfo;
30
import com.netscape.admin.dirserv.node.*;
33
* Netscape Directory Server 4.0 resource model.
40
public class DSStatusResourceModel extends DSBaseModel implements IDSContentListener {
43
* Constructor - create all panels.
45
* @param info Global console connection information
46
* @param serverInfo Server instance connection information
48
public DSStatusResourceModel( ConsoleInfo info,
49
ConsoleInfo serverInfo ) {
50
super( info, serverInfo );
51
ResourceObject root = new StatusResourceObject( this );
56
* Returns supported menu categories
58
public String[] getMenuCategoryIDs() {
59
if (_categoryID == null) {
60
_categoryID = new String[] {
63
ResourcePage.MENU_CONTEXT,
64
ResourcePage.MENU_OBJECT,
71
* add menu items for this page.
73
public IMenuItem[] getMenuItems(String category) {
74
if(category.equals(Framework.MENU_FILE)) {
75
if (_menuFile == null) {
76
_menuFile = new IMenuItem[] {
77
new MenuItemText( AUTHENTICATE,
78
_resource.getString("menu", "authenticate"),
79
_resource.getString("menu",
80
"authenticate-description")),
81
new MenuItemSeparator(),
85
} else if(category.equals(Framework.MENU_VIEW)) {
86
if (_menuView == null) {
87
_menuView = new IMenuItem[] {
88
new MenuItemSeparator(),
89
new MenuItemText( REFRESH_ALL,
90
_resource.getString("menu", "refresh-all"),
91
_resource.getString("menu",
92
"refresh-all-description"))
96
} else if (category.equals(ResourcePage.MENU_CONTEXT)) {
97
if (_menuContext == null) {
98
_menuContext = new IMenuItem[] {
99
new MenuItemText( REFRESH,
100
_resource.getString("menu", "refresh"),
101
_resource.getString("menu",
102
"refresh-description"))
106
} else if (category.equals(ResourcePage.MENU_OBJECT)) {
107
if (_menuObject == null) {
108
_menuObject = new IMenuItem[] {
109
new MenuItemText( REFRESH,
110
_resource.getString("menu", "refresh"),
111
_resource.getString("menu",
112
"refresh-description"))
121
* Notification that a menu item has been selected.
123
public void actionMenuSelected(IPage viewInstance, IMenuItem item)
126
super.actionMenuSelected(viewInstance, item);
127
if (item.getID().equals(OPEN)) {
128
actionObjectRun(viewInstance, _selection);
130
} else if(item.getID().equals(AUTHENTICATE)) {
131
boolean result = getNewAuthentication();
133
} else if(item.getID().equals(REFRESH_ALL)) {
134
setSelectedNode((IResourceObject)getRoot());
136
} else if (item.getID().equals(REFRESH)) {
139
setWaitCursor(false);
143
public void actionObjectSelected( IPage viewInstance,
144
IResourceObject[] selection,
145
IResourceObject[] previousSelection) {
146
super.actionObjectSelected(viewInstance, selection, previousSelection);
147
_selection = selection;
148
if ( _selection == null )
149
_selection = new IResourceObject[0];
150
Vector selected = new Vector();
151
Vector toNotify = new Vector();
152
/* Signal all selected objects, keep track of which ones */
153
for( int i = 0; i < _selection.length; i++ ) {
154
IResourceObject sel = _selection[i];
155
Component c = sel.getCustomPanel();
156
if ( (c != null) && _selectionListeners.contains( c ) ) {
157
toNotify.addElement( sel );
159
selected.addElement( c );
162
/* All other listeners must be unselected */
163
if ( previousSelection != null ) {
164
for( int i = 0; i < previousSelection.length; i++ ) {
165
IResourceObject sel = previousSelection[i];
166
Component c = sel.getCustomPanel();
168
_selectionListeners.contains( c ) &&
169
!selected.contains( c ) ) {
171
IDSResourceSelectionListener l =
172
(IDSResourceSelectionListener)c;
173
l.unselect( sel, viewInstance );
174
} catch ( Exception e ) {
176
"DSResourceModel.actionObjectSelected: " +
177
"c = " + c + ", " + e.toString() );
183
for( int i = 0; i < toNotify.size(); i++ ) {
184
IResourceObject sel =
185
(IResourceObject)toNotify.elementAt( i );
186
Component c = sel.getCustomPanel();
187
IDSResourceSelectionListener l =
188
(IDSResourceSelectionListener)c;
189
l.select( sel, viewInstance );
195
* Notification that the framework window is closing.
196
* Called by ResourcePage
198
public void actionViewClosing(IPage viewInstance)
199
throws CloseVetoException {
200
/* Check if any clients have unsaved changes */
201
Enumeration e = _changeClients.elements();
202
while( e.hasMoreElements() ) {
203
if ( ((IChangeClient)e.nextElement()).isDirty() ) {
204
/* Yes, notify the framework */
205
throw new CloseVetoException();
210
public void refreshView() {
214
private void refreshObject() {
215
if ( (_selection != null) && (_selection.length > 0) ) {
216
IResourceObject sel = _selection[0];
217
if (sel.equals(getRoot())) {
218
setSchema( null ); /* Refresh schema if we are refreshing the root */
220
Component panel = sel.getCustomPanel();
221
if ( sel instanceof ActionListener )
222
((ActionListener)sel).actionPerformed(
223
new ActionEvent( this,
224
ActionEvent.ACTION_PERFORMED,
226
if ( (panel != null) && (panel instanceof ActionListener) )
227
((ActionListener)panel).actionPerformed(
228
new ActionEvent( this,
229
ActionEvent.ACTION_PERFORMED,
234
private String[] _categoryID = null;
235
private IMenuItem[] _menuFile = null;
236
private IMenuItem[] _menuContext = null;
237
private IMenuItem[] _menuView = null;
238
private IMenuItem[] _menuEdit = null;
239
private IMenuItem[] _menuObject = null;
240
static public final String REFRESH = "refresh";
241
static final String REFRESH_ALL = "refresh all";