KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PrincipalsEditor.java
26  *
27  * Created on June 28, 2002, 5:25 PM
28  */

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

51 public class PrincipalsEditor implements TableCellEditor {
52     
53     private Vector model;
54     private transient Vector listeners;
55     private transient Vector originalValue;
56     private JTable principalsTable;
57     private JButton button;
58     private JDialog d;
59     private JFrame frame;
60     
61     private static java.util.ResourceBundle JavaDoc bundle =
62         java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.properties.Bundle"); //NOI18N
63
static final java.util.ResourceBundle JavaDoc helpBundle = java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.HelpIDBundle"); // NOI18N
64

65     public PrincipalsEditor(JFrame f) {
66         listeners = new Vector();
67         this.frame = f;
68         
69     // Create button that brings up the editor
70
button = new JButton();
71     button.setBackground(Color.white);
72     button.setBorderPainted(false);
73     button.setMargin(new Insets(0,0,0,0));
74         // Set up the dialog that the button brings up
75
// This will be called when OK button is selected on resulting Dialog
76
button.addActionListener(new ActionListener() {
77                 public void actionPerformed(ActionEvent e) {
78                     if (d == null)
79                         createDialog();
80                     d.setVisible(true);
81                 }
82         });
83     }
84     
85     public Component JavaDoc getTableCellEditorComponent(JTable table, Object JavaDoc value,
86                                                  boolean isSelected,
87                                                  int row, int column) {
88         if (value == null)
89             model = new Vector();
90         else if (value instanceof String JavaDoc && ((String JavaDoc)value).length() == 0)
91             model = new Vector();
92         else if (value instanceof Vector)
93             model = (Vector)value;
94         else
95             Reporter.error(value);
96         if (principalsTable == null)
97             createDialog();
98         principalsTable.setModel(new PrincipalTableModel(model));
99         originalValue = model;
100      
101         table.setRowSelectionInterval(row, row);
102         table.setColumnSelectionInterval(column, column);
103 // return sp;
104
return button;
105     }
106     
107     public void createDialog() {
108         JPanel pane = new JPanel();
109         principalsTable = new JTable();
110         JScrollPane sp = new JScrollPane(principalsTable);
111         d = new JDialog(this.frame, bundle.getString("PRIN_TITLE"), true); //NOI18N
112
d.setSize(500, 300);
113         d.getContentPane().setLayout(new BorderLayout());
114         pane.setLayout(new BorderLayout());
115 // d.getContentPane().add(sp, BorderLayout.CENTER);
116
pane.add(sp, BorderLayout.CENTER);
117         JButton okButton = new JButton(bundle.getString("OK_BUTTON_LABEL")); //NOI18N
118
JButton cancelButton = new JButton(bundle.getString("CANCEL_BUTTON_LABEL")); //NOI18N
119
okButton.addActionListener(new ActionListener() {
120             public void actionPerformed(ActionEvent ev) {
121                 stopCellEditing();
122                 d.setVisible(false);
123                 d.dispose();
124             }
125         });
126         cancelButton.addActionListener(new ActionListener() {
127             public void actionPerformed(ActionEvent ev) {
128                 cancelCellEditing();
129                 d.setVisible(false);
130                 d.dispose();
131             }
132         });
133         JPanel buttonsPane = new JPanel();
134         buttonsPane.add(okButton);
135         buttonsPane.add(cancelButton);
136         org.openide.util.HelpCtx.setHelpIDString(pane, helpBundle.getString("role_map_principal_editor")); //NOI18N
137
// d.getContentPane().add(buttonsPane, BorderLayout.SOUTH);
138
pane.add(buttonsPane, BorderLayout.SOUTH);
139         d.getContentPane().add(pane, BorderLayout.CENTER);
140  // d.setLocationRelativeTo(this.frame);
141
}
142     
143     public void addCellEditorListener(javax.swing.event.CellEditorListener JavaDoc cellEditorListener) {
144         listeners.addElement(cellEditorListener);
145     }
146     
147     public void cancelCellEditing() {
148         fireEditingCanceled();
149     }
150     
151     public Object JavaDoc getCellEditorValue() {
152         return model;
153     }
154     
155     public boolean isCellEditable(java.util.EventObject JavaDoc eventObject) {
156         return true;
157     }
158     
159     public void removeCellEditorListener(javax.swing.event.CellEditorListener JavaDoc cellEditorListener) {
160         listeners.removeElement(cellEditorListener);
161     }
162     
163     public boolean shouldSelectCell(java.util.EventObject JavaDoc eventObject) {
164         return true;
165     }
166     
167     public boolean stopCellEditing() {
168         if (principalsTable != null) {
169             TableCellEditor cell = principalsTable.getCellEditor();
170             if (cell != null)
171                 cell.stopCellEditing();
172         }
173  
174         model = ((PrincipalTableModel)principalsTable.getModel()).getPrincipals();
175         fireEditingStopped();
176         return true;
177     }
178     
179     private void fireEditingCanceled() {
180         ChangeEvent ce = new ChangeEvent(this);
181         for (int i = listeners.size() - 1; i >= 0; i--) {
182             ((CellEditorListener)listeners.elementAt(i)).editingCanceled(ce);
183         }
184     }
185     
186     private void fireEditingStopped() {
187         ChangeEvent ce = new ChangeEvent(this);
188         for (int i = listeners.size() - 1; i >= 0; i--) {
189             ((CellEditorListener)listeners.elementAt(i)).editingStopped(ce);
190         }
191     }
192 }
193
Popular Tags