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.attredit;
22
import java.util.Vector;
24
import javax.swing.event.DocumentEvent;
25
import javax.swing.event.DocumentListener;
26
import javax.swing.border.*;
27
import com.netscape.admin.dirserv.panel.UIFactory;
28
import com.netscape.management.client.util.Debug;
30
import com.netscape.admin.dirserv.propedit.DSEntryPanel;
31
import javax.swing.text.BadLocationException;
32
import com.netscape.admin.dirserv.AttributeAlias;
34
* StringAttributeEditor<BR>
35
* Attribute editor for string-valued attributes. A single label may
36
* be visible, and have 0 or more text fields (one for each value). If
37
* the editor is single-valued, at most one text field is allowed.
42
public class StringAttributeEditor extends AttributeEditor
43
implements DocumentListener {
45
* Construct an empty one.
48
public StringAttributeEditor() {
53
* Gets a default (blank) value.
55
* @return A single value.
57
public Object getDefaultValue() {
58
return new String( "" );
61
protected JComponent fetchField( Object value ) {
63
if ( _blankField != null ) {
64
field = (JTextField)_blankField;
65
field.setText( (String)value );
68
field = makeTextField( (String)value );
70
field.setOpaque( true );
71
field.setBorder( _textBorder );
72
field.setEnabled( true );
73
field.addFocusListener( this );
74
field.addMouseListener( this );
75
if ( _textFont != null )
76
field.setFont( _textFont );
77
field.setBackground( _textBackground );
78
field.setForeground( _textColor );
82
protected JComponent makeField() {
83
return makeTextField( "" );
86
protected JTextField makeTextField( String value ) {
87
return UIFactory.makeJTextField( this, value );
93
* @return A vector of all values.
95
public Vector getValues() {
96
_values = new Vector();
97
for( int i = 0; i < _fields.size(); i++ )
99
((JTextField)_fields.elementAt(i)).getText() );
100
return super.getValues();
106
* @param index Index of the value to be retrieved.
107
* @return A single value.
109
public Object getValue( int index ) {
111
return super.getValue( index );
115
* Get the last component that can have focus, for chaining.
117
* @return The last component internally that can have focus.
119
public JComponent getLastFocusableComponent() {
120
int i = getValueCount();
122
return (JComponent)_fields.elementAt( i - 1 );
126
public boolean isBinary() {
130
public void changedUpdate(DocumentEvent e) {
131
Debug.println("StringAttributeEditor.changedUpdate()");
134
/* We see if we have to notify the parent that the dn changed*/
135
Container parent = getEditorParent();
137
String[] namingAttributes = ((DSEntryPanel)parent).getNamingAttributes();
138
boolean isNamingAttribute = false;
139
String name = getName();
140
if (namingAttributes != null) {
141
for (int i=0; i < namingAttributes.length; i++) {
142
if (name.equals(getName())) {
143
isNamingAttribute = true;
148
if (isNamingAttribute) {
149
((DSEntryPanel)parent).updateNamingValue(name);
151
} catch (ClassCastException classException) {
152
Debug.println("StringAttributeEditor.changedUpdate(). Exception"+ classException);
156
public void removeUpdate(DocumentEvent e) {
159
public void insertUpdate(DocumentEvent e) {