~ubuntu-branches/ubuntu/wily/389-ds-console/wily-proposed

« back to all changes in this revision

Viewing changes to src/com/netscape/admin/dirserv/DSStatusResourceModel.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-03-15 19:58:37 UTC
  • Revision ID: package-import@ubuntu.com-20120315195837-296zyft51thld8q7
Tags: upstream-1.2.6
ImportĀ upstreamĀ versionĀ 1.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** BEGIN COPYRIGHT BLOCK
 
2
 * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
 
3
 * Copyright (C) 2005 Red Hat, Inc.
 
4
 * All rights reserved.
 
5
 * 
 
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.
 
9
 * 
 
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.
 
14
 * 
 
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 **/
 
19
 
 
20
package com.netscape.admin.dirserv;
 
21
 
 
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.*;
 
31
 
 
32
/**
 
33
 *      Netscape Directory Server 4.0 resource model.
 
34
 *
 
35
 * @author  rweltman
 
36
 * @version %I%, %G%
 
37
 * @date                11/1/97
 
38
 */
 
39
 
 
40
public class DSStatusResourceModel extends DSBaseModel implements IDSContentListener {
 
41
 
 
42
    /**
 
43
     * Constructor - create all panels.
 
44
     *
 
45
     * @param info      Global console connection information
 
46
     * @param serverInfo Server instance connection information
 
47
     */
 
48
    public DSStatusResourceModel( ConsoleInfo info,
 
49
                                  ConsoleInfo serverInfo ) {
 
50
        super( info, serverInfo );
 
51
        ResourceObject root = new StatusResourceObject( this );
 
52
        setRoot( root );
 
53
    }
 
54
 
 
55
    /**
 
56
     * Returns supported menu categories
 
57
     */
 
58
    public String[] getMenuCategoryIDs() {
 
59
                if (_categoryID == null) {
 
60
                        _categoryID = new String[] {
 
61
                                Framework.MENU_FILE,
 
62
                                        Framework.MENU_VIEW,
 
63
                                        ResourcePage.MENU_CONTEXT,                      
 
64
                                        ResourcePage.MENU_OBJECT,       
 
65
                                        };
 
66
                }
 
67
                return _categoryID;
 
68
    }
 
69
        
 
70
    /**
 
71
     * add menu items for this page.
 
72
     */
 
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(),
 
82
                                                };
 
83
                        }
 
84
                        return _menuFile;
 
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"))
 
93
                                                };
 
94
                        }
 
95
                        return _menuView;
 
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"))
 
103
                                                };
 
104
                        }
 
105
                        return _menuContext;
 
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"))
 
113
                                                };
 
114
                        }
 
115
                        return _menuObject;
 
116
                }
 
117
                return null;
 
118
    }
 
119
        
 
120
    /**
 
121
     * Notification that a menu item has been selected.
 
122
     */
 
123
    public void actionMenuSelected(IPage viewInstance, IMenuItem item)
 
124
    {
 
125
                setWaitCursor(true);
 
126
                super.actionMenuSelected(viewInstance, item);
 
127
                if (item.getID().equals(OPEN)) {
 
128
                        actionObjectRun(viewInstance, _selection);
 
129
                        
 
130
                } else if(item.getID().equals(AUTHENTICATE)) {
 
131
                        boolean result = getNewAuthentication();
 
132
                        
 
133
                } else if(item.getID().equals(REFRESH_ALL)) {
 
134
                        setSelectedNode((IResourceObject)getRoot());
 
135
                        refreshObject();
 
136
                } else if (item.getID().equals(REFRESH)) {
 
137
                refreshObject();
 
138
                }
 
139
                setWaitCursor(false);
 
140
                
 
141
    }
 
142
 
 
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 );
 
158
            }
 
159
            selected.addElement( c );
 
160
        }
 
161
 
 
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();
 
167
                if ( (c != null) &&
 
168
                     _selectionListeners.contains( c ) &&
 
169
                     !selected.contains( c ) ) {
 
170
                    try {
 
171
                        IDSResourceSelectionListener l = 
 
172
                            (IDSResourceSelectionListener)c;
 
173
                        l.unselect( sel, viewInstance );
 
174
                    } catch ( Exception e ) {
 
175
                        Debug.println(
 
176
                                      "DSResourceModel.actionObjectSelected: " +
 
177
                                      "c = " + c + ", " + e.toString() );
 
178
                    }
 
179
                }
 
180
            }
 
181
        }
 
182
 
 
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 );
 
190
        }
 
191
    }
 
192
 
 
193
 
 
194
    /**
 
195
     * Notification that the framework window is closing.
 
196
     * Called by ResourcePage
 
197
     */
 
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();
 
206
            }
 
207
        }
 
208
    }
 
209
 
 
210
    public void refreshView() {
 
211
        refreshObject();
 
212
    }
 
213
 
 
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 */
 
219
                }
 
220
            Component panel = sel.getCustomPanel();
 
221
            if ( sel instanceof ActionListener )
 
222
                ((ActionListener)sel).actionPerformed(
 
223
                                                      new ActionEvent( this,
 
224
                                                                       ActionEvent.ACTION_PERFORMED,
 
225
                                                                       REFRESH ) );
 
226
            if ( (panel != null) && (panel instanceof ActionListener) )
 
227
                ((ActionListener)panel).actionPerformed(
 
228
                                                        new ActionEvent( this,
 
229
                                                                         ActionEvent.ACTION_PERFORMED,
 
230
                                                                         REFRESH ) );
 
231
        }
 
232
    }
 
233
 
 
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";
 
242
}