Source Code Cross Referenced for TransientFieldsPanel.java in  » Net » Terracotta » com » tc » 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 » Net » Terracotta » com.tc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc;
005:
006:        import org.dijon.Button;
007:        import org.dijon.ContainerResource;
008:
009:        import com.tc.admin.common.XContainer;
010:        import com.tc.admin.common.XTable;
011:        import com.terracottatech.config.DsoApplication;
012:        import com.terracottatech.config.TransientFields;
013:
014:        import java.awt.event.ActionEvent;
015:        import java.awt.event.ActionListener;
016:
017:        import javax.swing.JOptionPane;
018:        import javax.swing.event.ListSelectionEvent;
019:        import javax.swing.event.ListSelectionListener;
020:        import javax.swing.event.TableModelEvent;
021:        import javax.swing.event.TableModelListener;
022:        import javax.swing.table.DefaultTableModel;
023:
024:        public class TransientFieldsPanel extends XContainer implements 
025:                TableModelListener {
026:            private DsoApplication m_dsoApp;
027:            private TransientFields m_transientFields;
028:            private XTable m_transientTable;
029:            private TransientTableModel m_transientTableModel;
030:            private Button m_addButton;
031:            private ActionListener m_addListener;
032:            private Button m_removeButton;
033:            private ActionListener m_removeListener;
034:            private ListSelectionListener m_transientsListener;
035:
036:            public TransientFieldsPanel() {
037:                super ();
038:            }
039:
040:            public void load(ContainerResource containerRes) {
041:                super .load(containerRes);
042:
043:                m_transientTable = (XTable) findComponent("TransientFieldTable");
044:                m_transientTable
045:                        .setModel(m_transientTableModel = new TransientTableModel());
046:                m_transientsListener = new ListSelectionListener() {
047:                    public void valueChanged(ListSelectionEvent lse) {
048:                        if (!lse.getValueIsAdjusting()) {
049:                            int[] sel = m_transientTable.getSelectedRows();
050:                            m_removeButton.setEnabled(sel != null
051:                                    && sel.length > 0);
052:                        }
053:                    }
054:                };
055:
056:                m_addButton = (Button) findComponent("AddTransientButton");
057:                m_addListener = new ActionListener() {
058:                    public void actionPerformed(ActionEvent ae) {
059:                        String field = JOptionPane.showInputDialog(
060:                                "Transient field", "");
061:
062:                        if (field != null) {
063:                            field = field.trim();
064:
065:                            if (field != null && field.length() > 0
066:                                    && !isTransient(field)) {
067:                                internalAddTransient(field);
068:                            }
069:                        }
070:                    }
071:                };
072:
073:                m_removeButton = (Button) findComponent("RemoveTransientButton");
074:                m_removeListener = new ActionListener() {
075:                    public void actionPerformed(ActionEvent ae) {
076:                        TransientFields tf = ensureTransientFields();
077:                        int[] selection = m_transientTable.getSelectedRows();
078:
079:                        for (int i = selection.length - 1; i >= 0; i--) {
080:                            tf.removeFieldName(selection[i]);
081:                        }
082:                        m_transientTableModel.removeRows(selection);
083:                    }
084:                };
085:            }
086:
087:            public boolean hasAnySet() {
088:                return m_transientFields != null
089:                        && m_transientFields.sizeOfFieldNameArray() > 0;
090:            }
091:
092:            private TransientFields ensureTransientFields() {
093:                if (m_transientFields == null) {
094:                    ensureXmlObject();
095:                }
096:                return m_transientFields;
097:            }
098:
099:            public void ensureXmlObject() {
100:                if (m_transientFields == null) {
101:                    removeListeners();
102:                    m_transientFields = m_dsoApp.addNewTransientFields();
103:                    updateChildren();
104:                    addListeners();
105:                }
106:            }
107:
108:            private void syncModel() {
109:                if (!hasAnySet() && m_dsoApp.getTransientFields() != null) {
110:                    m_dsoApp.unsetTransientFields();
111:                    m_transientFields = null;
112:                }
113:
114:                SessionIntegratorFrame frame = (SessionIntegratorFrame) getAncestorOfClass(SessionIntegratorFrame.class);
115:                frame.modelChanged();
116:            }
117:
118:            private void addListeners() {
119:                m_transientTableModel.addTableModelListener(this );
120:                m_transientTable.getSelectionModel().addListSelectionListener(
121:                        m_transientsListener);
122:                m_addButton.addActionListener(m_addListener);
123:                m_removeButton.addActionListener(m_removeListener);
124:            }
125:
126:            private void removeListeners() {
127:                m_transientTableModel.removeTableModelListener(this );
128:                m_transientTable.getSelectionModel()
129:                        .removeListSelectionListener(m_transientsListener);
130:                m_addButton.removeActionListener(m_addListener);
131:                m_removeButton.removeActionListener(m_removeListener);
132:            }
133:
134:            private void updateChildren() {
135:                m_transientTableModel.clear();
136:
137:                if (m_transientFields != null) {
138:                    String[] transients = m_transientFields.getFieldNameArray();
139:
140:                    for (int i = 0; i < transients.length; i++) {
141:                        m_transientTableModel.addField(transients[i]);
142:                    }
143:                }
144:            }
145:
146:            public void setup(DsoApplication dsoApp) {
147:                setEnabled(true);
148:                removeListeners();
149:
150:                m_dsoApp = dsoApp;
151:                m_transientFields = m_dsoApp != null ? m_dsoApp
152:                        .getTransientFields() : null;
153:
154:                updateChildren();
155:                addListeners();
156:            }
157:
158:            public void tearDown() {
159:                removeListeners();
160:
161:                m_dsoApp = null;
162:                m_transientFields = null;
163:
164:                m_transientTableModel.clear();
165:
166:                setEnabled(false);
167:            }
168:
169:            class TransientTableModel extends DefaultTableModel {
170:                TransientTableModel() {
171:                    super ();
172:                    setColumnIdentifiers(new String[] { "Transient fields" });
173:                }
174:
175:                void clear() {
176:                    setRowCount(0);
177:                }
178:
179:                void setTransientFields(TransientFields fields) {
180:                    clear();
181:
182:                    if (fields != null) {
183:                        int count = fields.sizeOfFieldNameArray();
184:
185:                        for (int i = 0; i < count; i++) {
186:                            addField(fields.getFieldNameArray(i));
187:                        }
188:                    }
189:                }
190:
191:                void addField(String fieldName) {
192:                    addRow(new Object[] { fieldName });
193:                }
194:
195:                int indexOf(String fieldName) {
196:                    int count = getRowCount();
197:
198:                    for (int i = 0; i < count; i++) {
199:                        if (((String) getValueAt(i, 0)).equals(fieldName)) {
200:                            return i;
201:                        }
202:                    }
203:
204:                    return -1;
205:                }
206:
207:                public void setValueAt(Object value, int row, int col) {
208:                    m_transientFields.setFieldNameArray(row, (String) value);
209:                    super .setValueAt(value, row, col);
210:                }
211:
212:                void removeRows(int[] rows) {
213:                    removeTableModelListener(TransientFieldsPanel.this );
214:                    for (int i = rows.length - 1; i >= 0; i--) {
215:                        removeRow(rows[i]);
216:                    }
217:                    addTableModelListener(TransientFieldsPanel.this );
218:                    syncModel();
219:                }
220:            }
221:
222:            public void tableChanged(TableModelEvent tme) {
223:                syncModel();
224:            }
225:
226:            private void internalAddTransient(String fieldName) {
227:                ensureTransientFields().addFieldName(fieldName);
228:                m_transientTableModel.addField(fieldName);
229:
230:                int row = m_transientTableModel.getRowCount() - 1;
231:                m_transientTable.setRowSelectionInterval(row, row);
232:            }
233:
234:            private void internalRemoveTransient(String fieldName) {
235:                int row = m_transientTableModel.indexOf(fieldName);
236:
237:                if (row >= 0) {
238:                    ensureTransientFields().removeFieldName(row);
239:                    m_transientTableModel.removeRow(row);
240:
241:                    if (row > 0) {
242:                        row = Math.min(m_transientTableModel.getRowCount() - 1,
243:                                row);
244:                        m_transientTable.setRowSelectionInterval(row, row);
245:                    }
246:                }
247:            }
248:
249:            public boolean isTransient(String fieldName) {
250:                TransientFields transients = ensureTransientFields();
251:                int count = transients.sizeOfFieldNameArray();
252:
253:                for (int i = 0; i < count; i++) {
254:                    if (fieldName.equals(transients.getFieldNameArray(i))) {
255:                        return true;
256:                    }
257:                }
258:
259:                return false;
260:            }
261:
262:            public void ensureTransient(String fieldName) {
263:                if (!isTransient(fieldName)) {
264:                    internalAddTransient(fieldName);
265:                }
266:            }
267:
268:            public void ensureNotTransient(String fieldName) {
269:                if (isTransient(fieldName)) {
270:                    internalRemoveTransient(fieldName);
271:                }
272:            }
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.