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

« back to all changes in this revision

Viewing changes to src/com/netscape/admin/dirserv/attredit/StringAttributeEditor.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.attredit;
 
21
 
 
22
import java.util.Vector;
 
23
import javax.swing.*;
 
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;
 
29
import java.awt.*;
 
30
import com.netscape.admin.dirserv.propedit.DSEntryPanel;
 
31
import javax.swing.text.BadLocationException;
 
32
import com.netscape.admin.dirserv.AttributeAlias;
 
33
/**
 
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.
 
38
 *
 
39
 * @version 1.0
 
40
 * @author rweltman
 
41
 **/
 
42
public class StringAttributeEditor extends AttributeEditor
 
43
                                   implements DocumentListener {
 
44
    /**
 
45
     * Construct an empty one.
 
46
     *
 
47
     **/
 
48
    public StringAttributeEditor() {
 
49
                super();
 
50
    }
 
51
 
 
52
    /**
 
53
     * Gets a default (blank) value.
 
54
     *
 
55
         * @return A single value.
 
56
     */
 
57
    public Object getDefaultValue() {
 
58
                return new String( "" );
 
59
        }
 
60
 
 
61
    protected JComponent fetchField( Object value ) {
 
62
                JTextField field;
 
63
                if ( _blankField != null ) {
 
64
                        field = (JTextField)_blankField;
 
65
                        field.setText( (String)value );
 
66
                        _blankField = null;
 
67
                } else {
 
68
                        field = makeTextField( (String)value );
 
69
                }
 
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 );
 
79
                return field;
 
80
        }
 
81
 
 
82
    protected JComponent makeField() {
 
83
                return makeTextField( "" );
 
84
        }
 
85
 
 
86
    protected JTextField makeTextField( String value ) {
 
87
                return UIFactory.makeJTextField( this, value );
 
88
        }
 
89
 
 
90
    /**
 
91
     * Gets all values.
 
92
     *
 
93
         * @return A vector of all values.
 
94
     **/
 
95
    public Vector getValues() {
 
96
                _values = new Vector();
 
97
                for( int i = 0; i < _fields.size(); i++ )
 
98
                        _values.addElement(
 
99
                                ((JTextField)_fields.elementAt(i)).getText() );
 
100
                return super.getValues();
 
101
        }
 
102
                
 
103
    /**
 
104
     * Gets a value.
 
105
     *
 
106
     * @param index Index of the value to be retrieved.
 
107
         * @return A single value.
 
108
     **/
 
109
    public Object getValue( int index ) {
 
110
                getValues();
 
111
                return super.getValue( index );
 
112
        }
 
113
 
 
114
    /**
 
115
         * Get the last component that can have focus, for chaining.
 
116
         *
 
117
         * @return The last component internally that can have focus.
 
118
         */
 
119
    public JComponent getLastFocusableComponent() {
 
120
                int i = getValueCount();
 
121
                if ( i > 1 )
 
122
                        return (JComponent)_fields.elementAt( i - 1 );
 
123
                return this;
 
124
        }
 
125
 
 
126
    public boolean isBinary() {
 
127
                return false;
 
128
        }
 
129
 
 
130
    public void changedUpdate(DocumentEvent e) {
 
131
                Debug.println("StringAttributeEditor.changedUpdate()");
 
132
        setDirty();
 
133
 
 
134
                /* We see if we have to notify the parent that the dn changed*/
 
135
                Container parent = getEditorParent();
 
136
                try {   
 
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;
 
144
                                                break;
 
145
                                        }
 
146
                                }
 
147
                        }
 
148
                        if (isNamingAttribute) {                                
 
149
                                ((DSEntryPanel)parent).updateNamingValue(name);
 
150
                        }
 
151
                } catch (ClassCastException classException) {
 
152
                        Debug.println("StringAttributeEditor.changedUpdate(). Exception"+ classException);
 
153
                }       
 
154
    }
 
155
 
 
156
    public void removeUpdate(DocumentEvent e) {
 
157
        changedUpdate(e);
 
158
    }
 
159
    public void insertUpdate(DocumentEvent e) {
 
160
        changedUpdate(e);
 
161
    }
 
162
}