KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > properties > RoleMapElementEditor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * RoleMapElementEditor.java
26  *
27  * Created on March 19, 2002, 11:18 AM
28  */

29
30 package com.sun.enterprise.tools.common.properties;
31
32 import java.awt.Component JavaDoc;
33 import java.awt.Graphics JavaDoc;
34 import java.awt.Rectangle JavaDoc;
35
36 import javax.swing.JTable JavaDoc;
37 import javax.swing.JScrollPane JavaDoc;
38 import javax.swing.table.TableCellEditor JavaDoc;
39 import java.beans.*;
40 import javax.swing.*;
41 import java.awt.*;
42
43 import java.util.ResourceBundle JavaDoc;
44 import com.sun.enterprise.tools.common.util.diagnostics.Reporter;
45 /**
46  *
47  * @author vkraemer
48  * @version
49  */

50 public class RoleMapElementEditor extends PropertyEditorSupport {
51
52     private RoleMapElement roleMap;
53     private JTable JavaDoc table = null;
54     private JTextField desc = null;
55     private static ResourceBundle JavaDoc bundle =
56         ResourceBundle.getBundle("com.sun.enterprise.tools.common.properties.Bundle"); //NOI18N
57
static final java.util.ResourceBundle JavaDoc helpBundle = java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.HelpIDBundle"); // NOI18N
58

59     /** Creates new RoleMapElementEditor */
60     public RoleMapElementEditor() {
61     }
62
63     /** The String is not editable in the sheet.
64      */

65     public String JavaDoc getAsText() {
66         return null;
67     }
68     
69     /** Does this editor use painting to illuminate the property state in the
70      * property sheet
71      */

72     public boolean isPaintable() {
73         return true;
74     }
75     
76     /** return the UI components to edit this object */
77     public Component JavaDoc getCustomEditor() {
78         table = new JTable JavaDoc(new RoleMapElementTableModel(roleMap));
79         table.setDefaultEditor(Object JavaDoc.class, c023cell);
80         if (table.getModel().getRowCount() > 0)
81             table.editCellAt(0,0);
82         javax.swing.table.TableColumnModel JavaDoc tcm = table.getColumnModel();
83         //
84
// make the password field editor 'secret'...
85
//
86
javax.swing.table.TableColumn JavaDoc tc = tcm.getColumn(1);
87         //PasswordRenderEdit pre1 = new PasswordRenderEdit();
88
PasswordRender pre2 = new PasswordRender();
89         tc.setCellEditor(c1cell);
90         tc.setCellRenderer(pre2);
91         
92         //set principal editor
93
javax.swing.table.TableColumn JavaDoc principalColumn = tcm.getColumn(3);
94         principalColumn.setCellEditor(new PrincipalsEditor(null));
95         principalColumn.setCellRenderer(new PrincipalsRenderer());
96         JScrollPane JavaDoc sp = new JScrollPane JavaDoc(table);
97         
98         JPanel pane = new JPanel();
99         GridBagLayout gridbag = new GridBagLayout();
100         pane.setLayout(gridbag);
101         GridBagConstraints c = new GridBagConstraints();
102         c.weightx = 0.5;
103         c.weighty = 0.5;
104         c.gridx = 0;
105         c.gridy = 0;
106         c.gridwidth = 1;
107         c.gridheight = 1;
108         c.insets = new Insets(5, 5, 5, 5);
109         c.fill = GridBagConstraints.BOTH;
110         pane.add(sp, c);
111
112         c.weightx = 0.5;
113         c.weighty = 0.5;
114         c.gridx = 0;
115         c.gridy = 1;
116         c.gridwidth = 1;
117         c.gridheight = 1;
118         c.insets = new Insets(5, 5, 5, 5);
119         c.fill = GridBagConstraints.BOTH;
120         JLabel descLabel = new JLabel(bundle.getString("LBL_DESCRIPTION")); //NOI18N
121
/* pane.add(descLabel, c);
122
123         c.weightx = 0.5;
124         c.weighty = 0.5;
125         c.gridx = 0;
126         c.gridy = 2;
127         c.gridwidth = 1;
128         c.gridheight = 1;
129         c.insets = new Insets(5, 5, 5, 5);
130         c.fill = GridBagConstraints.BOTH;
131  */

132         desc = new JTextField(68);
133         desc.setText(roleMap.getRoleMapDescription());
134         JPanel descPane = new JPanel();
135         descLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
136         descPane.add(descLabel);
137         descPane.add(desc);
138         pane.add(descPane, c);
139         org.openide.util.HelpCtx.setHelpIDString(pane, helpBundle.getString("role_map_editor")); //NOI18N
140
return pane;
141     }
142     
143     public Object JavaDoc getValue() {
144         if (roleMap != null && desc != null)
145             roleMap.setRoleMapDescription(desc.getText());
146         return new RoleMapElement(roleMap);
147     }
148     
149     public void paintValue(Graphics JavaDoc gfx, Rectangle JavaDoc box) {
150         int num = roleMap.getLength();
151         String JavaDoc s = "" + num + " "; //NOI18N
152

153         String JavaDoc format = null; //bundle.getString
154
if(num == 1)
155             format = bundle.getString("PROP_TEXT_ONE_MAP_ELEMNT");//NOI18N
156
else
157             format = bundle.getString("PROP_TEXT_N_MAP_ELEMNT");//NOI18N
158

159         s = java.text.MessageFormat.format(format, new Object JavaDoc[] { s });
160         
161         java.awt.FontMetrics JavaDoc fm = gfx.getFontMetrics();
162         
163         //PropertySheetSettings pss = (PropertySheetSettings) PropertySheetSettings.findObject(PropertySheetSettings.class, true);
164
//gfx.setColor(pss.getValueColor());
165
gfx.drawString(s, 4, (box.height - fm.getHeight()) / 2 + 1 + fm.getMaxAscent());
166     }
167     
168     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
169         throw new IllegalArgumentException JavaDoc(bundle.getString("ERR_SET_AS_TEXT_ILLEGAL")); //NOI18N
170
}
171     
172     TableCellEditor JavaDoc c023cell = new javax.swing.DefaultCellEditor JavaDoc(new javax.swing.JTextField JavaDoc());
173     TableCellEditor JavaDoc c1cell = new javax.swing.DefaultCellEditor JavaDoc(new javax.swing.JPasswordField JavaDoc());
174     
175     public void setValue(Object JavaDoc value) {
176         Reporter.info(""); //NOI18N
177
if (table != null) {
178             TableCellEditor JavaDoc cell = table.getCellEditor();
179             if (null != cell) {
180                 Reporter.info("There is a cell: " + cell);//NOI18N
181
Reporter.info(" this is the value of the cell: " + cell.getCellEditorValue());//NOI18N
182
int r = table.getEditingRow();
183                 int c = table.getEditingColumn();
184                 if (r > -1 && c > -1) {
185                     table.setValueAt(cell.getCellEditorValue(), r, c);
186                 }
187             }
188         }
189         if (value instanceof RoleMapElement) {
190             roleMap = (RoleMapElement) value; //new RoleMapElement((RoleMapElement) value);
191
}
192     }
193     
194     public boolean supportsCustomEditor() {
195         return true;
196     }
197     
198 }
199
Popular Tags