Source Code Cross Referenced for FreeTableTreeNode.java in  » Ajax » ItsNat » org » itsnat » feashow » features » components » tables » 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 » Ajax » ItsNat » org.itsnat.feashow.features.components.tables 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is not part of the ItsNat framework.
003:         *
004:         * Original source code use and closed source derivatives are authorized
005:         * to third parties with no restriction or fee.
006:         * The original source code is owned by the author.
007:         *
008:         * This program is distributed AS IS in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
011:         *
012:         * Author: Jose Maria Arranz Santamaria
013:         * (C) Innowhere Software Services S.L., Spanish company, year 2007
014:         */
015:
016:        package org.itsnat.feashow.features.components.tables;
017:
018:        import java.util.Collections;
019:        import java.util.Comparator;
020:        import java.util.Vector;
021:        import javax.swing.ListSelectionModel;
022:        import javax.swing.event.ListSelectionEvent;
023:        import javax.swing.event.ListSelectionListener;
024:        import javax.swing.event.TableModelEvent;
025:        import javax.swing.event.TableModelListener;
026:        import javax.swing.table.DefaultTableModel;
027:        import org.itsnat.comp.ItsNatComponentManager;
028:        import org.itsnat.comp.free.ItsNatFreeTable;
029:        import org.itsnat.comp.html.ItsNatHTMLInputButton;
030:        import org.itsnat.comp.html.ItsNatHTMLInputText;
031:        import org.itsnat.core.ItsNatDocument;
032:        import org.itsnat.feashow.FeatureTreeNode;
033:        import org.w3c.dom.events.Event;
034:        import org.w3c.dom.events.EventListener;
035:        import org.w3c.dom.events.EventTarget;
036:
037:        public class FreeTableTreeNode extends FeatureTreeNode implements 
038:                EventListener, TableModelListener, ListSelectionListener {
039:            protected ItsNatFreeTable tableComp;
040:            protected ItsNatHTMLInputButton removeButton;
041:            protected ItsNatHTMLInputText[] newItemComp;
042:            protected ItsNatHTMLInputText posComp;
043:            protected ItsNatHTMLInputButton updateButton;
044:            protected ItsNatHTMLInputButton insertButton;
045:
046:            public FreeTableTreeNode() {
047:            }
048:
049:            public void startExamplePanel() {
050:                ItsNatDocument itsNatDoc = getItsNatDocument();
051:                ItsNatComponentManager componentMgr = itsNatDoc
052:                        .getItsNatComponentManager();
053:
054:                this .tableComp = (ItsNatFreeTable) componentMgr
055:                        .createItsNatComponentById("compId", "freeTable", null);
056:
057:                DefaultTableModel dataModel = (DefaultTableModel) tableComp
058:                        .getTableModel();
059:                dataModel.addColumn("City");
060:                dataModel.addColumn("Public square");
061:                dataModel.addColumn("Monument");
062:                dataModel.addRow(new String[] { "Madrid", "Plaza Mayor",
063:                        "Palacio Real" });
064:                dataModel.addRow(new String[] { "Sevilla", "Plaza de Espaņa",
065:                        "Giralda" });
066:                dataModel.addRow(new String[] { "Segovia",
067:                        "Plaza del Azoguejo", "Acueducto Romano" });
068:
069:                ListSelectionModel rowSelModel = tableComp
070:                        .getRowSelectionModel();
071:                // ListSelectionModel columnSelModel = tableComp.getColumnSelectionModel();
072:
073:                rowSelModel
074:                        .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
075:                // columnSelModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
076:
077:                tableComp.setRowSelectionAllowed(true);
078:                tableComp.setColumnSelectionAllowed(false);
079:
080:                rowSelModel
081:                        .addListSelectionListener(new TableRowSelectionDecoration(
082:                                tableComp));
083:
084:                rowSelModel.setSelectionInterval(1, 1);
085:
086:                dataModel.addTableModelListener(this );
087:                rowSelModel.addListSelectionListener(this );
088:
089:                ListSelectionModel headSelModel = tableComp
090:                        .getItsNatTableHeader().getListSelectionModel();
091:                headSelModel.addListSelectionListener(this );
092:
093:                this .removeButton = (ItsNatHTMLInputButton) componentMgr
094:                        .createItsNatComponentById("removeId");
095:                removeButton.addEventListener("click", this );
096:
097:                this .newItemComp = new ItsNatHTMLInputText[dataModel
098:                        .getColumnCount()];
099:                for (int i = 0; i < newItemComp.length; i++) {
100:                    this .newItemComp[i] = (ItsNatHTMLInputText) componentMgr
101:                            .createItsNatComponentById("itemId" + i);
102:                    newItemComp[i].setText(dataModel.getValueAt(
103:                            rowSelModel.getMinSelectionIndex(), i).toString());
104:                }
105:
106:                this .posComp = (ItsNatHTMLInputText) componentMgr
107:                        .createItsNatComponentById("posId");
108:                posComp.setText(Integer.toString(rowSelModel
109:                        .getMinSelectionIndex()));
110:
111:                this .updateButton = (ItsNatHTMLInputButton) componentMgr
112:                        .createItsNatComponentById("updateId");
113:                updateButton.addEventListener("click", this );
114:
115:                this .insertButton = (ItsNatHTMLInputButton) componentMgr
116:                        .createItsNatComponentById("insertId");
117:                insertButton.addEventListener("click", this );
118:            }
119:
120:            public void endExamplePanel() {
121:                this .tableComp.dispose();
122:                this .tableComp = null;
123:
124:                this .removeButton.dispose();
125:                this .removeButton = null;
126:
127:                for (int i = 0; i < newItemComp.length; i++) {
128:                    this .newItemComp[i].dispose();
129:                    this .newItemComp[i] = null;
130:                }
131:
132:                this .posComp.dispose();
133:                this .posComp = null;
134:
135:                this .updateButton.dispose();
136:                this .updateButton = null;
137:
138:                this .insertButton.dispose();
139:                this .insertButton = null;
140:            }
141:
142:            public void handleEvent(Event evt) {
143:                log(evt.getCurrentTarget() + " " + evt.getType());
144:
145:                EventTarget currentTarget = evt.getCurrentTarget();
146:                if (currentTarget == removeButton.getHTMLInputElement()) {
147:                    DefaultTableModel dataModel = (DefaultTableModel) tableComp
148:                            .getTableModel();
149:                    ListSelectionModel rowSelModel = tableComp
150:                            .getRowSelectionModel();
151:                    if (!rowSelModel.isSelectionEmpty()) {
152:                        // Selection Model is in SINGLE_INTERVAL_SELECTION mode
153:                        int min = rowSelModel.getMinSelectionIndex();
154:                        int max = rowSelModel.getMaxSelectionIndex();
155:                        for (int i = 0; i <= max - min; i++)
156:                            dataModel.removeRow(min);
157:                    }
158:                } else if ((currentTarget == updateButton.getHTMLInputElement())
159:                        || (currentTarget == insertButton.getHTMLInputElement())) {
160:                    String[] newItem = new String[newItemComp.length];
161:                    for (int i = 0; i < newItemComp.length; i++)
162:                        newItem[i] = newItemComp[i].getText();
163:
164:                    int row;
165:                    try {
166:                        row = Integer.parseInt(posComp.getText());
167:                        DefaultTableModel dataModel = (DefaultTableModel) tableComp
168:                                .getTableModel();
169:                        if (currentTarget == updateButton.getHTMLInputElement()) {
170:                            for (int i = 0; i < newItemComp.length; i++)
171:                                dataModel.setValueAt(newItem[i], row, i);
172:                        } else
173:                            dataModel.insertRow(row, newItem);
174:                    } catch (NumberFormatException ex) {
175:                        getItsNatDocument().addCodeToSend(
176:                                "alert('Bad Position')");
177:                    } catch (ArrayIndexOutOfBoundsException ex) {
178:                        getItsNatDocument().addCodeToSend(
179:                                "alert('Bad Position')");
180:                    }
181:                }
182:            }
183:
184:            public void tableChanged(TableModelEvent e) {
185:                int firstRow = e.getFirstRow();
186:                int lastRow = e.getLastRow();
187:
188:                String action = "";
189:                int type = e.getType();
190:                switch (type) {
191:                case TableModelEvent.INSERT:
192:                    action = "added";
193:                    break;
194:                case TableModelEvent.DELETE:
195:                    action = "removed";
196:                    break;
197:                case TableModelEvent.UPDATE:
198:                    action = "changed";
199:                    break;
200:                }
201:
202:                String interval = "";
203:                if (firstRow != -1)
204:                    interval = "interval " + firstRow + "-" + lastRow;
205:
206:                log(e.getClass().toString() + " " + action + " " + interval);
207:            }
208:
209:            public void valueChanged(ListSelectionEvent e) {
210:                if (e.getValueIsAdjusting())
211:                    return;
212:
213:                int first = e.getFirstIndex();
214:                int last = e.getLastIndex();
215:
216:                ListSelectionModel selModel = (ListSelectionModel) e
217:                        .getSource();
218:                if (selModel == tableComp.getRowSelectionModel()) {
219:                    String fact = "";
220:                    for (int i = first; i <= last; i++) {
221:                        boolean selected = selModel.isSelectedIndex(i);
222:                        if (selected)
223:                            fact += ", selected ";
224:                        else
225:                            fact += ", deselected ";
226:                        fact += i;
227:                    }
228:
229:                    log(e.getClass().toString() + " " + fact);
230:
231:                    int row = selModel.getMinSelectionIndex(); // First selected
232:                    if (row != -1) {
233:                        for (int i = 0; i < newItemComp.length; i++) {
234:                            Object value = tableComp.getTableModel()
235:                                    .getValueAt(row, i);
236:                            newItemComp[i].setText(value.toString());
237:                        }
238:                        posComp.setText(Integer.toString(row));
239:                    }
240:                } else if (selModel == tableComp.getItsNatTableHeader()
241:                        .getListSelectionModel()) {
242:                    int selected = -1;
243:                    for (int i = first; i <= last; i++) {
244:                        if (selModel.isSelectedIndex(i))
245:                            selected = i;
246:                    }
247:                    final int selectedCol = selected;
248:                    DefaultTableModel dataModel = (DefaultTableModel) tableComp
249:                            .getTableModel();
250:                    Vector vector = dataModel.getDataVector();
251:                    Comparator comp = new Comparator() {
252:                        public int compare(Object o1, Object o2) {
253:                            Vector row1 = (Vector) o1;
254:                            Vector row2 = (Vector) o2;
255:                            String item1 = (String) row1.get(selectedCol);
256:                            String item2 = (String) row2.get(selectedCol);
257:                            return item1.compareTo(item2);
258:                        }
259:                    };
260:                    Collections.sort(vector, comp);
261:                    dataModel.fireTableStructureChanged();
262:                }
263:            }
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.