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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
|
/** BEGIN COPYRIGHT BLOCK
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version
* 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* END COPYRIGHT BLOCK **/
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.text.*;
import com.netscape.management.nmclf.SuiLookAndFeel;
import com.netscape.management.client.util.*;
import com.netscape.management.client.ug.*;
import netscape.ldap.*;
/**
* SuperMailUserPage is an example customized plugin for the
* ResourceEditor. It is used to edit information specific to
* SuperMail users.
*
* All ResourceEditor plugins must implement IResourceEditorPage and
* Observer interfaces. SuperMailUserPage also implements ChangeListener
* and DocumentListener interfaces to keep track of modifications to the
* page.
*/
public class SuperMailUserPage extends JPanel
implements IResourceEditorPage,
Observer,
ChangeListener,
DocumentListener {
// Specify property file without the trailing ".properties". Property
// file contains externalized strings for i18n.
static final ResourceSet _resource = new ResourceSet("supermailug");
// Constants for the SuperMailUser object class attributes (see SuperMailSchema.conf).
static final String ATTR_EMPLOYEE_NUMBER = "employeeNumber";
static final String ATTR_ENABLE_AUTO_REPLY = "enableAutoReply";
static final String ATTR_AUTO_REPLY_TEXT = "autoReplyText";
static final String AUTO_REPLY_ENABLED = "on";
static final String AUTO_REPLY_DISABLED = "off";
ResourceEditor _parent;
String _id;
JTextField _employeeNumber;
JCheckBox _enableAutoReply;
JLabel _autoReplyTextLabel;
JTextArea _autoReplyText;
String _oldEmployeeNumber;
boolean _oldEnableAutoReply;
String _oldAutoReplyText;
boolean _isModified = false;
boolean _isReadOnly = false;
boolean _isEnabled = true;
/**
* Constructor
*/
public SuperMailUserPage() {
}
/**
* Implements the Observer interface.
* Updates the view for the page. If some other control modifies the
* data displayed on this page, this method can be used to reflect
* those changes on this page.
*
* @param o the observable object
* @param arg the attribute to update
*/
public void update(Observable o,
Object arg) {
}
/**
* Implements the ChangeListener interface.
* Updates the modified flag.
*
* @param e change event
*/
public void stateChanged(ChangeEvent e) {
if (e.getSource() == _enableAutoReply &&
_enableAutoReply.isSelected() != _oldEnableAutoReply) {
_isModified = true;
}
}
/**
* Implements the DocumentListener interface.
* Updates the modified flag.
*
* @param e document update event
*/
public void insertUpdate(DocumentEvent e) {
documentChanged(e);
}
/**
* Implements the DocumentListener interface.
* Updates the modified flag.
*
* @param e document update event
*/
public void removeUpdate(DocumentEvent e) {
documentChanged(e);
}
/**
* Implements the DocumentListener interface.
* Updates the modified flag.
*
* @param e document update event
*/
public void changedUpdate(DocumentEvent e) {
documentChanged(e);
}
/**
* Updates the modified flag.
*
* @param e document update event
*/
private void documentChanged(DocumentEvent e) {
if (e.getDocument() == _employeeNumber &&
_employeeNumber.getText().equals(_oldEmployeeNumber) == false) {
_isModified = true;
}
else if (e.getDocument() == _autoReplyText &&
_autoReplyText.getText().equals(_oldAutoReplyText) == false) {
_isModified = true;
}
}
/**
* Implements the IResourceEditorPage interface.
* Initializes the page with context information. It will be called once
* the page is added to resource editor.
*
* @param observable the observable object
* @param parent the resource editor container
*/
public void initialize(ResourcePageObservable observable,
ResourceEditor parent) {
_parent = parent;
_id = _resource.getString("userPage", "id"); // Retrieve externalized strings from the property file.
JLabel employeeNumberLabel = new JLabel(_resource.getString("userPage", "employeeNumber"), SwingConstants.RIGHT);
_employeeNumber = new JTextField(10);
_employeeNumber.getDocument().addDocumentListener(this);
_enableAutoReply = new JCheckBox(_resource.getString("userPage", "enableAutoReply"));
_enableAutoReply.addChangeListener(this);
_autoReplyTextLabel = new JLabel(_resource.getString("userPage", "autoReplyText"), SwingConstants.RIGHT);
_autoReplyText = new UGTextArea(); // UGTextArea extends JTextArea.
_autoReplyText.getDocument().addDocumentListener(this);
// Used for alignment. Blank label expands to take up the empty space.
JLabel blankLabel = new JLabel("");
// Layout widgets
JPanel p = new JPanel(new GridBagLayout());
GridBagUtil.constrain(p, employeeNumberLabel,
0, 0,
1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
SuiLookAndFeel.VERT_WINDOW_INSET, SuiLookAndFeel.HORIZ_WINDOW_INSET, 0, 0);
GridBagUtil.constrain(p, _employeeNumber,
1, 0,
1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
SuiLookAndFeel.VERT_WINDOW_INSET, SuiLookAndFeel.DIFFERENT_COMPONENT_SPACE,
0, SuiLookAndFeel.HORIZ_WINDOW_INSET);
GridBagUtil.constrain(p, _enableAutoReply,
1, 1,
GridBagConstraints.REMAINDER, 1, 1.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
SuiLookAndFeel.SEPARATED_COMPONENT_SPACE, SuiLookAndFeel.HORIZ_WINDOW_INSET, 0, 0);
GridBagUtil.constrain(p, _autoReplyTextLabel,
0, 2,
1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
SuiLookAndFeel.COMPONENT_SPACE, SuiLookAndFeel.HORIZ_WINDOW_INSET, 0, 0);
GridBagUtil.constrain(p, _autoReplyText,
1, 2,
1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
SuiLookAndFeel.COMPONENT_SPACE, SuiLookAndFeel.DIFFERENT_COMPONENT_SPACE,
0, SuiLookAndFeel.HORIZ_WINDOW_INSET);
GridBagUtil.constrain(p, blankLabel,
0, 3,
GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
SuiLookAndFeel.COMPONENT_SPACE, SuiLookAndFeel.HORIZ_WINDOW_INSET,
SuiLookAndFeel.VERT_WINDOW_INSET, SuiLookAndFeel.HORIZ_WINDOW_INSET);
// Auto reply text area can grow to multiple lines. The scroll pane
// lets the text area grow and provide the means to scroll to view the
// rest of the JPanel.
JScrollPane sp = new JScrollPane(p);
sp.setBorder(null);
setLayout(new BorderLayout());
add("Center", sp);
// Initialize fields
_oldEmployeeNumber = observable.get(ATTR_EMPLOYEE_NUMBER, 0);
_employeeNumber.setText(_oldEmployeeNumber);
String value = observable.get(ATTR_ENABLE_AUTO_REPLY, 0);
if (value.equalsIgnoreCase(AUTO_REPLY_ENABLED)) {
_oldEnableAutoReply = true;
}
else {
_oldEnableAutoReply = false;
}
_enableAutoReply.setSelected(_oldEnableAutoReply);
_oldAutoReplyText = observable.get(ATTR_AUTO_REPLY_TEXT, 0);
_autoReplyText.setText(_oldAutoReplyText);
}
/**
* Implements the IResourceEditorPage interface.
* Returns unique ID string which identifies the page.
*
* @return unique ID for the page
*/
public String getID() {
return _id;
}
/**
* Implements the IResourceEditorPage interface.
* Handle some post save condition. This is called after the
* information is saved and the object has been created in
* the directory server.
*
* @param observable the observable object
* @return true if save succeeded; false otherwise
* @exception Exception
*/
public boolean afterSave(ResourcePageObservable observable) throws Exception {
return true;
}
/**
* Implements the IResourceEditorPage interface.
* Saves all modified information to the observable object
*
* @param observable the observable object
* @return true if save succeeded; false otherwise
* @exception Exception
*/
public boolean save(ResourcePageObservable observable) throws Exception {
// Compare to old value, and if different, save or delete.
// Trim leading and trailing white space characters.
if (_employeeNumber.getText().equals(_oldEmployeeNumber) == false) {
if (_employeeNumber.getText().trim().length() == 0) {
observable.delete(ATTR_EMPLOYEE_NUMBER, _oldEmployeeNumber);
_oldEmployeeNumber = "";
}
else {
String newEmployeeNumber = _employeeNumber.getText().trim();
observable.replace(ATTR_EMPLOYEE_NUMBER, newEmployeeNumber);
_oldEmployeeNumber = newEmployeeNumber;
}
}
if (_enableAutoReply.isSelected() != _oldEnableAutoReply) {
if (_enableAutoReply.isSelected()) {
observable.replace(ATTR_ENABLE_AUTO_REPLY, AUTO_REPLY_ENABLED);
}
else {
observable.replace(ATTR_ENABLE_AUTO_REPLY, AUTO_REPLY_DISABLED);
}
_oldEnableAutoReply = _enableAutoReply.isSelected();
}
if (_autoReplyText.getText().equals(_oldAutoReplyText) == false) {
if (_autoReplyText.getText().trim().length() == 0) {
observable.delete(ATTR_AUTO_REPLY_TEXT, _oldAutoReplyText);
_oldAutoReplyText = "";
}
else {
String newAutoReplyText = _autoReplyText.getText().trim();
observable.replace(ATTR_AUTO_REPLY_TEXT, newAutoReplyText);
_oldAutoReplyText = newAutoReplyText;
}
}
return true;
}
/**
* Implements the IResourceEditorPage interface.
* Clears all information on the page.
*/
public void clear() {
_employeeNumber.setText("");
_enableAutoReply.setSelected(false);
_autoReplyText.setText("");
}
/**
* Implements the IResourceEditorPage interface.
* Resets information on the page.
*/
public void reset() {
_employeeNumber.setText(_oldEmployeeNumber);
_enableAutoReply.setSelected(_oldEnableAutoReply);
_autoReplyText.setText(_oldAutoReplyText);
_isModified = false;
}
/**
* Implements the IResourceEditorPage interface.
* Sets default information on the page.
*/
public void setDefault() {
_employeeNumber.setText("");
_enableAutoReply.setSelected(false);
_autoReplyText.setText("");
}
/**
* Implements the IResourceEditorPage interface.
* Specifies whether any information on the page has been modified.
*
* @return true if some information has been modified; false otherwise
*/
public boolean isModified() {
return _isModified;
}
/**
* Implements the IResourceEditorPage interface.
* Sets the modified flag for the page.
*
* @param value true or false
*/
public void setModified(boolean value) {
_isModified = value;
}
/**
* Implements the IResourceEditorPage interface.
* Specifies whether the information on the page is read only.
*
* @return true if some information has been modified; false otherwise
*/
public boolean isReadOnly() {
return _isReadOnly;
}
/**
* Implements the IResourceEditorPage interface.
* Sets the read only flag for the page.
*
* @param value true or false
*/
public void setReadOnly(boolean value) {
_isReadOnly = value;
}
/**
* Implements the IResourceEditorPage interface.
* Sets the enabled flag for the page.
*
* @param value true or false
*/
public void setEnable(boolean value) {
_isEnabled = value;
}
/**
* Implements the IResourceEditorPage interface.
* Specifies whether all required information has been provided for
* the page.
*
* @return true if all required information has been provided; false otherwise
*/
public boolean isComplete() {
return true; // None of the information on this page required.
}
/**
* Implements the IResourceEditorPage interface.
* Returns a brief name for the page. The name should reflect the
* plugin page.
*/
public String getDisplayName() {
return _id;
}
/**
* Implements the IResourceEditorPage interface.
* Displays help information for the page.
*/
public void help() {
Help help = new Help(_resource);
if (help != null) {
// Start the help page for the resource file help token
help.help("userPage", "help");
}
else {
System.out.println("Help not implemented for SuperMailUserPage");
}
}
}
|