Source Code Cross Referenced for WrapperAttributeTable.java in  » IDE-Netbeans » jmx » org » netbeans » modules » jmx » mbeanwizard » table » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » jmx » org.netbeans.modules.jmx.mbeanwizard.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 2004-2005 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.jmx.mbeanwizard.table;
043:
044:        import javax.swing.JCheckBox;
045:        import javax.swing.JComboBox;
046:        import javax.swing.JTextField;
047:        import javax.swing.SwingConstants;
048:        import javax.swing.table.AbstractTableModel;
049:        import javax.swing.table.TableCellEditor;
050:        import javax.swing.table.TableCellRenderer;
051:        import org.netbeans.modules.jmx.mbeanwizard.MBeanAttributePanel.AttributesWizardPanel;
052:        import org.netbeans.modules.jmx.mbeanwizard.renderer.CheckBoxRenderer;
053:        import org.netbeans.modules.jmx.mbeanwizard.tablemodel.AbstractJMXTableModel;
054:        import org.netbeans.modules.jmx.mbeanwizard.editor.JCheckBoxCellEditor;
055:        import java.awt.event.ActionListener;
056:        import java.awt.event.ActionEvent;
057:        import javax.swing.DefaultCellEditor;
058:        import javax.swing.table.TableColumn;
059:        import javax.swing.table.TableColumnModel;
060:        import org.netbeans.modules.jmx.FireEvent;
061:        import org.netbeans.modules.jmx.WizardConstants;
062:        import org.netbeans.modules.jmx.WizardHelpers;
063:        import org.netbeans.modules.jmx.mbeanwizard.MBeanWrapperAttribute;
064:        import org.netbeans.modules.jmx.mbeanwizard.listener.AttributeTextFieldKeyListener;
065:        import org.netbeans.modules.jmx.mbeanwizard.tablemodel.MBeanWrapperAttributeTableModel;
066:        import org.netbeans.modules.jmx.mbeanwizard.editor.JComboBoxCellEditor;
067:        import org.netbeans.modules.jmx.mbeanwizard.renderer.TextFieldRenderer;
068:        import org.netbeans.modules.jmx.mbeanwizard.renderer.ComboBoxRenderer;
069:        import org.netbeans.modules.jmx.mbeanwizard.renderer.EmptyRenderer;
070:        import org.netbeans.modules.jmx.mbeanwizard.editor.JTextFieldCellEditor;
071:
072:        /**
073:         *
074:         * @author an156382
075:         */
076:        public class WrapperAttributeTable extends AttributeTable {
077:
078:            private static final int SELWIDTH = 55;
079:
080:            /** Creates a new instance of WrapperAttributeTable */
081:            public WrapperAttributeTable(AbstractTableModel model,
082:                    AttributesWizardPanel wiz) {
083:                super (model, wiz);
084:                ajustSelectionColumnWidth();
085:            }
086:
087:            private void ajustSelectionColumnWidth() {
088:                TableColumnModel colModel = this .getColumnModel();
089:                TableColumn tc = colModel
090:                        .getColumn(MBeanWrapperAttributeTableModel.IDX_ATTR_SELECTION);
091:                tc.setMaxWidth(SELWIDTH);
092:                tc.setMinWidth(SELWIDTH);
093:                tc.setPreferredWidth(SELWIDTH);
094:            }
095:
096:            protected void ajustAccessColumnWidth() {
097:                TableColumnModel colModel = this .getColumnModel();
098:                TableColumn tc = colModel
099:                        .getColumn(MBeanWrapperAttributeTableModel.IDX_ATTR_ACCESS + 1);
100:                tc.setMaxWidth(ACCESSWIDTH);
101:                tc.setMinWidth(ACCESSWIDTH);
102:                tc.setPreferredWidth(ACCESSWIDTH);
103:            }
104:
105:            public MBeanWrapperAttributeTableModel getModel() {
106:                return (MBeanWrapperAttributeTableModel) super .getModel();
107:            }
108:
109:            /**
110:             * Returns the cell editor for the table according to the column
111:             * @param row the row to be considered
112:             * @param column the column to be considered
113:             * @return TableCellEditor the cell editor
114:             */
115:            public TableCellEditor getCellEditor(final int row, final int column) {
116:
117:                if (row >= getRowCount())
118:                    return null;
119:
120:                int editableRow = ((MBeanWrapperAttributeTableModel) getModel())
121:                        .getFirstEditableRow();
122:                boolean selection = (Boolean) getModel().getValueAt(row, 0);
123:
124:                if (column == 0) { //selection
125:                    final JCheckBox selBox = new JCheckBox();
126:                    selBox.setSelected((Boolean) getModel().getValueAt(row,
127:                            column));
128:                    selBox.setHorizontalAlignment(SwingConstants.CENTER);
129:                    selBox.setEnabled(true);
130:                    selBox.addActionListener(new ActionListener() {
131:                        public void actionPerformed(ActionEvent evt) {
132:                            getModel().setValueAt(selBox.isSelected(), row,
133:                                    column);
134:                            ((AbstractJMXTableModel) getModel())
135:                                    .fireTableDataChanged();
136:                            wiz.event();
137:                        }
138:                    });
139:                    selBox.setName("wrapperAttrSelBox");// NOI18N
140:                    //return new DefaultCellEditor(selBox);
141:                    return new JCheckBoxCellEditor(selBox, this );
142:                } else {
143:                    if (column == 1) { //attribute name
144:                        JTextField nameField = new JTextField();
145:                        String o = (String) getModel().getValueAt(row, column);
146:                        nameField.setText(o);
147:                        //nameField.setEditable(false);
148:                        //nameField.setEnabled(false);
149:                        nameField
150:                                .addKeyListener(new AttributeTextFieldKeyListener());
151:                        return new JTextFieldCellEditor(nameField, this );
152:                    } else {
153:                        if (column == 2) { //attribute type
154:                            if (row < editableRow) {
155:                                JTextField typeField = new JTextField();
156:                                String o = (String) getModel().getValueAt(row,
157:                                        column);
158:                                typeField.setText(o);
159:                                //typeField.setEditable(false);
160:                                //typeField.setEnabled(false);
161:                                return new DefaultCellEditor(typeField);
162:                            } else {
163:                                JComboBox jcb = WizardHelpers
164:                                        .instanciateTypeJComboBox();
165:                                return new JComboBoxCellEditor(jcb, this );
166:                            }
167:                        } else {
168:                            if (column == 3) { //access mode
169:
170:                                JComboBox jcb = new JComboBox();
171:                                // fills an MBean Attribute with the information in the model
172:                                MBeanWrapperAttribute mba = ((MBeanWrapperAttributeTableModel) getModel())
173:                                        .getWrapperAttribute(row);
174:                                /** test to fill the access JComboBox **/
175:                                if (row < editableRow) {
176:                                    if (mba.isOriginalReadable())
177:                                        jcb
178:                                                .addItem(WizardConstants.ATTR_ACCESS_READ_ONLY);
179:                                    if (mba.isOriginalWritable())
180:                                        jcb
181:                                                .addItem(WizardConstants.ATTR_ACCESS_WRITE_ONLY);
182:                                    if (mba.isOriginalReadable()
183:                                            && mba.isOriginalWritable())
184:                                        jcb
185:                                                .addItem(WizardConstants.ATTR_ACCESS_READ_WRITE);
186:                                } else {
187:                                    jcb = WizardHelpers
188:                                            .instanciateAccessJComboBox();
189:                                }
190:                                jcb.setEditable(false);
191:                                jcb.setEnabled(true);
192:                                jcb.setName("wrapperAttrAccessBox");// NOI18N
193:                                return new JComboBoxCellEditor(jcb, this );
194:                            } else {
195:                                if (column == 4) { //attribute description
196:                                    JTextField descrField = new JTextField();
197:                                    String o = (String) getModel().getValueAt(
198:                                            row, column);
199:                                    descrField.setText(o);
200:                                    descrField.setEnabled(true);
201:                                    return new JTextFieldCellEditor(descrField,
202:                                            this );
203:                                }
204:                            }
205:                        }
206:                    }
207:                }
208:                return super .getCellEditor(row, column - 1);
209:            }
210:
211:            /**
212:             * Returns the cell renderer for the table according to the column
213:             * @param row the row to be considered
214:             * @param column the column to be considered
215:             * @return TableCellRenderer the cell renderer
216:             */
217:            public TableCellRenderer getCellRenderer(int row, int column) {
218:
219:                if (row >= getRowCount())
220:                    return null;
221:
222:                int editableRow = ((MBeanWrapperAttributeTableModel) getModel())
223:                        .getFirstEditableRow();
224:
225:                if (column == 0) { //selection
226:                    if (row < editableRow) {
227:                        JCheckBox cb = new JCheckBox();
228:                        cb.setEnabled(true);
229:                        return new CheckBoxRenderer(cb);
230:                    } else
231:                        return new EmptyRenderer(new JTextField());
232:                } else {
233:                    if (column == 1) { //attribute Name
234:                        boolean ok = (row < editableRow);
235:                        //if (ok)
236:                        //return new WrapperTextFieldRenderer(new JTextField(),true,false);
237:                        return new TextFieldRenderer(new JTextField(), true,
238:                                !ok);
239:                        //else
240:                        //    return new TextFieldRenderer(new JTextField(),true,true);
241:                    } else {
242:                        if (column == 2) {
243:                            if (row < editableRow)
244:                                //return new WrapperTextFieldRenderer(new JTextField(),true,false);
245:                                return new TextFieldRenderer(new JTextField(),
246:                                        true, false);
247:                            else {
248:                                JComboBox jcb = WizardHelpers
249:                                        .instanciateTypeJComboBox();
250:                                return new ComboBoxRenderer(jcb, true, true);
251:                            }
252:                        } else {
253:                            if (column == 3) { //attribute access
254:                                JComboBox jcb = new JComboBox();
255:                                // fills an MBean Attribute with the information in the model
256:                                MBeanWrapperAttribute mba = ((MBeanWrapperAttributeTableModel) getModel())
257:                                        .getWrapperAttribute(row);
258:                                /** test to fill the access JComboBox **/
259:                                if (mba.isOriginalReadable())
260:                                    jcb
261:                                            .addItem(WizardConstants.ATTR_ACCESS_READ_ONLY);
262:                                if (mba.isOriginalWritable())
263:                                    jcb
264:                                            .addItem(WizardConstants.ATTR_ACCESS_WRITE_ONLY);
265:                                if (mba.isOriginalReadable()
266:                                        && mba.isOriginalWritable())
267:                                    jcb
268:                                            .addItem(WizardConstants.ATTR_ACCESS_READ_WRITE);
269:                                return new ComboBoxRenderer(jcb, true, false);
270:                            } else {
271:                                if (column == 4) { //attribute description
272:                                    JTextField txt = new JTextField();
273:                                    boolean selection = (Boolean) getModel()
274:                                            .getValueAt(row, 0);
275:                                    //return new WrapperDescriptionTextFieldRenderer(
276:                                    return new TextFieldRenderer(txt, true,
277:                                            selection);
278:                                }
279:                            }
280:                        }
281:                    }
282:                }
283:                return super .getCellRenderer(row, column - 1);
284:            }
285:
286:            public boolean isCellEditable(int row, int col) {
287:
288:                int editableRow = ((MBeanWrapperAttributeTableModel) getModel())
289:                        .getFirstEditableRow();
290:                boolean isChecked = (Boolean) getModel().getValueAt(row, 0);
291:
292:                if (row < editableRow) {
293:                    if (isChecked)
294:                        return ((col == 0) || (col == 3) || (col == 4));
295:                    else
296:                        return (col == 0);
297:                } else
298:                    return (col != 0);
299:            }
300:
301:            /**
302:             * Returns the wizard panel of the parent dialog
303:             * @return FireEvent
304:             */
305:            public FireEvent getWiz() {
306:
307:                return this.wiz;
308:            }
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.