Source Code Cross Referenced for XMLSimpleTablePanel.java in  » Workflow-Engines » JaWE » org » enhydra » jawe » base » panel » panels » 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 » Workflow Engines » JaWE » org.enhydra.jawe.base.panel.panels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.jawe.base.panel.panels;
002:
003:        import java.awt.Color;
004:        import java.awt.Dimension;
005:        import java.util.ArrayList;
006:        import java.util.Iterator;
007:        import java.util.List;
008:        import java.util.Vector;
009:
010:        import javax.swing.JScrollPane;
011:        import javax.swing.JTable;
012:        import javax.swing.ListSelectionModel;
013:        import javax.swing.table.DefaultTableModel;
014:        import javax.swing.table.TableColumn;
015:
016:        import org.enhydra.jawe.base.panel.PanelContainer;
017:        import org.enhydra.jawe.base.panel.PanelSettings;
018:        import org.enhydra.shark.xpdl.XMLCollection;
019:        import org.enhydra.shark.xpdl.XMLComplexElement;
020:        import org.enhydra.shark.xpdl.XMLElement;
021:
022:        /**
023:         * Creates a table panel.
024:         * @author Sasa Bojanic
025:         * @author Zoran Milakovic
026:         * @author Miroslav Popov
027:         */
028:        public class XMLSimpleTablePanel extends XMLBasicPanel {
029:
030:            protected static Dimension miniTableDimension = new Dimension(450,
031:                    125);
032:            protected static Dimension smallTableDimension = new Dimension(450,
033:                    200);
034:            protected static Dimension mediumTableDimension = new Dimension(
035:                    550, 200);
036:            protected static Dimension largeTableDimension = new Dimension(650,
037:                    200);
038:
039:            protected JTable allItems;
040:
041:            protected Vector columnNames;
042:            protected List columnsToShow;
043:
044:            public XMLSimpleTablePanel(PanelContainer pc,
045:                    XMLCollection myOwner, List columnsToShow,
046:                    List elementsToShow, String title, boolean hasBorder,
047:                    boolean hasEmptyBorder, boolean automaticWidth) {
048:                super (pc, myOwner, title, true, hasBorder, hasEmptyBorder);
049:
050:                columnNames = getColumnNames(columnsToShow);
051:                this .columnsToShow = columnsToShow;
052:                allItems = new JTable(new Vector(), columnNames) {
053:                    public boolean isCellEditable(int row, int col) {
054:                        return false;
055:                    }
056:                };
057:
058:                Color bkgCol = new Color(245, 245, 245);
059:                if (pc.getSettings() instanceof  PanelSettings) {
060:                    bkgCol = ((PanelSettings) pc.getSettings())
061:                            .getBackgroundColor();
062:                }
063:                allItems.setBackground(bkgCol);
064:
065:                setupTable(automaticWidth);
066:                fillTableContent(elementsToShow);
067:
068:                add(createScrollPane());
069:
070:            }
071:
072:            public JTable getTable() {
073:                return allItems;
074:            }
075:
076:            public XMLElement getSelectedElement() {
077:                int row = allItems.getSelectedRow();
078:                if (row >= 0) {
079:                    return (XMLElement) allItems.getValueAt(row, 0);
080:                }
081:                return null;
082:
083:            }
084:
085:            public void addRow(XMLElement e) {
086:                int rowpos = allItems.getRowCount();
087:                DefaultTableModel dtm = (DefaultTableModel) allItems.getModel();
088:                Vector v = getRow(e);
089:                dtm.insertRow(rowpos, v);
090:            }
091:
092:            public void removeRow(XMLElement e) {
093:                int row = getElementRow(e);
094:                if (row >= 0) {
095:                    DefaultTableModel dtm = (DefaultTableModel) allItems
096:                            .getModel();
097:                    dtm.removeRow(row);
098:                }
099:            }
100:
101:            public List getElements() {
102:                List els = new ArrayList();
103:                for (int i = 0; i < allItems.getRowCount(); i++) {
104:                    els.add(allItems.getValueAt(i, 0));
105:                }
106:                return els;
107:            }
108:
109:            protected Vector getColumnNames(List columnsToShow) {
110:                // creating a table which do not allow cell editing
111:                Vector cnames = new Vector();
112:                cnames.add("Object");
113:                XMLElement cel = ((XMLCollection) getOwner())
114:                        .generateNewElement();
115:                if (cel instanceof  XMLComplexElement) {
116:                    Iterator it = columnsToShow.iterator();
117:                    while (it.hasNext()) {
118:                        String elemName = (String) it.next();
119:                        XMLElement el = ((XMLComplexElement) cel).get(elemName);
120:                        if (el != null) {
121:                            cnames.add(pc.getLabelGenerator().getLabel(el));
122:                        } else {
123:                            it.remove();
124:                        }
125:                    }
126:                } else {
127:                    cnames.add(pc.getLabelGenerator().getLabel(cel));
128:                }
129:                return cnames;
130:            }
131:
132:            protected void setupTable(boolean automaticWidth) {
133:                TableColumn column;
134:                // setting the first column (object column) to be invisible
135:                column = allItems.getColumnModel().getColumn(0);
136:                column.setMinWidth(0);
137:                column.setMaxWidth(0);
138:                column.setPreferredWidth(0);
139:                column.setResizable(false);
140:                // setting fields that will not be displayed within the table
141:
142:                // setting some table properties
143:                allItems.setColumnSelectionAllowed(false);
144:                allItems.setRowSelectionAllowed(true);
145:                allItems.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
146:                allItems.getTableHeader().setReorderingAllowed(false);
147:
148:                Dimension tDim;
149:                int noOfVisibleColumns = columnNames.size() - 1;
150:                if (noOfVisibleColumns <= 3) {
151:                    tDim = new Dimension(smallTableDimension);
152:                } else if (noOfVisibleColumns <= 5) {
153:                    tDim = new Dimension(mediumTableDimension);
154:                } else {
155:                    tDim = new Dimension(largeTableDimension);
156:                }
157:
158:                if (automaticWidth) {
159:                    tDim.width = allItems.getPreferredScrollableViewportSize().width;
160:                }
161:                allItems
162:                        .setPreferredScrollableViewportSize(new Dimension(tDim));
163:
164:            }
165:
166:            protected void fillTableContent(List elementsToShow) {
167:                DefaultTableModel dtm = (DefaultTableModel) allItems.getModel();
168:                Iterator it = elementsToShow.iterator();
169:
170:                while (it.hasNext()) {
171:                    XMLElement elem = (XMLElement) it.next();
172:                    Vector v = getRow(elem);
173:                    dtm.addRow(v);
174:                }
175:            }
176:
177:            protected Vector getRow(XMLElement elem) {
178:                Vector v = new Vector();
179:                if (elem instanceof  XMLComplexElement) {
180:                    Iterator itAllElems = columnsToShow.iterator();
181:                    v = new Vector();
182:                    XMLComplexElement cmel = (XMLComplexElement) elem;
183:                    while (itAllElems.hasNext()) {
184:                        String elName = (String) itAllElems.next();
185:                        XMLElement el = cmel.get(elName);
186:                        if (el != null) {
187:                            v.add(new XMLElementView(pc, el,
188:                                    XMLElementView.TOVALUE));
189:                        }
190:                    }
191:                } else {
192:                    v.add(new XMLElementView(pc, elem, XMLElementView.TOVALUE));
193:                }
194:                v.add(0, elem);
195:                return v;
196:            }
197:
198:            protected JScrollPane createScrollPane() {
199:                // creates panel
200:                JScrollPane allItemsPane = new JScrollPane();
201:                allItemsPane.setViewportView(allItems);
202:                return allItemsPane;
203:            }
204:
205:            protected int getElementRow(XMLElement el) {
206:                int row = -1;
207:                for (int i = 0; i < allItems.getRowCount(); i++) {
208:                    XMLElement toCompare = (XMLElement) allItems.getValueAt(i,
209:                            0);
210:                    if (el == toCompare) {
211:                        row = i;
212:                        break;
213:                    }
214:                }
215:                return row;
216:            }
217:
218:            public void cleanup() {
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.