Source Code Cross Referenced for XConditionsTableModel.java in  » XML-UI » xui32 » com » xoetrope » carousel » survey » 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 » XML UI » xui32 » com.xoetrope.carousel.survey 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.survey;
002:
003:        import com.xoetrope.survey.Condition;
004:        import com.xoetrope.survey.Question;
005:        import com.xoetrope.survey.QuestionGroup;
006:        import java.awt.event.ActionEvent;
007:        import java.awt.event.ActionListener;
008:        import java.util.Observable;
009:        import java.util.Observer;
010:        import java.util.Vector;
011:        import java.awt.Component;
012:        import java.awt.Point;
013:        import java.awt.event.MouseEvent;
014:        import java.awt.event.MouseListener;
015:        import javax.swing.JLabel;
016:        import javax.swing.JMenuItem;
017:        import javax.swing.JPopupMenu;
018:        import javax.swing.JTable;
019:        import javax.swing.JTextField;
020:        import javax.swing.event.ListSelectionEvent;
021:        import javax.swing.table.AbstractTableModel;
022:        import javax.swing.event.ListSelectionListener;
023:        import net.xoetrope.editor.project.XEditorProject;
024:        import net.xoetrope.xui.XProject;
025:        import net.xoetrope.xui.XProjectManager;
026:
027:        /**
028:         * A model for the conditions table
029:         *
030:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
031:         * the GNU Public License (GPL), please see license.txt for more details. If
032:         * you make commercial use of this software you must purchase a commercial
033:         * license from Xoetrope.</p>
034:         * <p> $Revision: 1.5 $</p>
035:         */
036:        public class XConditionsTableModel extends AbstractTableModel implements 
037:                MouseListener, Observer, ListSelectionListener {
038:            public static final int COL_QUESTIONID = 0;
039:            public static final int COL_QUESTION = 1;
040:            public static final int COL_QUESTIONTYPE = 2;
041:
042:            protected XRule rule;
043:            protected XTable table;
044:            protected JPopupMenu popupMenu;
045:            protected NewConditionDialog newResponseDialog;
046:            protected XNotifier notifier;
047:            protected ActionListener addResponse, deleteResponse;
048:
049:            protected XTableColumn[] columns = new XTableColumn[3];
050:
051:            public XConditionsTableModel(XTable t) {
052:                table = t;
053:                XProject project = XProjectManager.getCurrentProject();
054:                XEditorProject editorProject = (project instanceof  XEditorProject ? (XEditorProject) project
055:                        : null);
056:
057:                notifier = new XNotifier(editorProject, true);
058:
059:                columns[0] = new XTableColumn("Question id", 130, JLabel.LEFT);
060:                columns[1] = new XTableColumn("Question", 130, JLabel.LEFT);
061:                columns[2] = new XTableColumn("Question type", 130, JLabel.LEFT);
062:
063:                table.getSelectionModel().addListSelectionListener(this );
064:                table.setModel(this , columns, this );
065:                rule = null;
066:
067:                addResponse = new AddCondition();
068:                deleteResponse = new DeleteResponse();
069:
070:                newResponseDialog = new NewConditionDialog();
071:                createPopupMenu();
072:            }
073:
074:            public JTable getTable() {
075:                return table;
076:            }
077:
078:            public Observable getNotifier() {
079:                return notifier;
080:            }
081:
082:            public ActionListener getAddResponse() {
083:                return addResponse;
084:            }
085:
086:            public ActionListener getDeleteResponse() {
087:                return deleteResponse;
088:            }
089:
090:            public void refresh() {
091:                table.clearSelection();
092:                table.revalidate();
093:                table.repaint();
094:            }
095:
096:            public void createPopupMenu() {
097:                JMenuItem menuItem;
098:                popupMenu = new JPopupMenu();
099:                popupMenu.add(new JLabel("Reponse Option"));
100:                popupMenu.addSeparator();
101:                menuItem = new JMenuItem("Add..");
102:                popupMenu.add(menuItem);
103:                menuItem.addActionListener(addResponse);
104:                menuItem = new JMenuItem("Delete..");
105:                popupMenu.add(menuItem);
106:                menuItem.addActionListener(deleteResponse);
107:            }
108:
109:            public String getColumnName(int col) {
110:                return columns[col].getName();
111:            }
112:
113:            public int getRowCount() {
114:                return (rule != null ? rule.getConditions().size() : 0);
115:            }
116:
117:            public int getColumnCount() {
118:                return columns.length;
119:            }
120:
121:            public boolean isCellEditable(int row, int col) {
122:                Vector responses = rule.getConditions();
123:                Condition response = (Condition) responses.get(row);
124:
125:                QuestionGroup group = rule.getGroup();
126:                Question question = response.getQuestion();
127:
128:                boolean b = columns[col].getCellEditor() != null;
129:                b &= (question.getQuestionType() == Question.FREE_TEXT);
130:                return b;
131:            }
132:
133:            public void selectCondition(Condition condition) {
134:                int selectedRow = table.getSelectedRow();
135:                int row = -1;
136:                Vector conditions = rule.getConditions();
137:                for (int i = 0; i < conditions.size() && row == -1; i++) {
138:                    Condition c = (Condition) conditions.get(i);
139:                    if (condition.equals(c))
140:                        row = i;
141:                }
142:                if (row != -1 && row != selectedRow)
143:                    table.getSelectionModel().setSelectionInterval(row, row);
144:                else if (row == -1)
145:                    table.clearSelection();
146:                table.repaint();
147:            }
148:
149:            public Object getValueAt(int rowIndex, int columnIndex) {
150:                if (rule == null || rowIndex < 0 || rowIndex > getRowCount())
151:                    return "";
152:
153:                Condition condition = (Condition) rule.getConditions().get(
154:                        rowIndex);
155:
156:                Question question = condition.getQuestion();
157:
158:                String s = "";
159:                switch (columnIndex) {
160:                case COL_QUESTIONID:
161:                    s = (question != null ? String.valueOf(question.getId())
162:                            : "0");
163:                    break;
164:                case COL_QUESTION:
165:                    s = (question != null ? question.getText() : "");
166:                    break;
167:                case COL_QUESTIONTYPE:
168:                    s = (question != null ? question.getQuestionTypeText() : "");
169:                    break;
170:                }
171:                return s;
172:            }
173:
174:            private void showPopupMenu(MouseEvent e) {
175:                if (e.isPopupTrigger()) {
176:                    Component source = (Component) e.getSource();
177:                    boolean isQuestionOption = (source instanceof  XTable || source instanceof  JTextField);
178:                    Point p = e.getPoint();
179:                    if (!isQuestionOption) {
180:                        System.out.println(source.getParent().getParent()
181:                                .getParent().getParent());
182:                        // table->viewport->scrollpane->XPopupPanel
183:                        //s((XResponseSetEditor)( ( XPopupPanel )source.getParent().getParent().getParent() ).getOwner()).addPopupActions();
184:                    } else
185:                        popupMenu.show(source, p.x, p.y);
186:                }
187:            }
188:
189:            public void mouseClicked(MouseEvent e) {
190:            }
191:
192:            public void mousePressed(MouseEvent e) {
193:                showPopupMenu(e);
194:            }
195:
196:            public void mouseReleased(MouseEvent e) {
197:                showPopupMenu(e);
198:            }
199:
200:            public void mouseEntered(MouseEvent e) {
201:            }
202:
203:            public void mouseExited(MouseEvent e) {
204:            }
205:
206:            public void valueChanged(ListSelectionEvent e) {
207:                Condition condition = null;
208:                int row = table.getSelectedRow();
209:                if (row >= 0 && row < getRowCount())
210:                    condition = (Condition) rule.getConditions().get(row);
211:                notifier.notifyObservers(condition, false);
212:            }
213:
214:            public void update(Observable o, Object arg) {
215:                rule = (XRule) arg;
216:                table.clearSelection();
217:                table.revalidate();
218:                table.repaint();
219:            }
220:
221:            private class AddCondition implements  ActionListener {
222:                public void actionPerformed(ActionEvent e) {
223:                    if (newResponseDialog.showDialog(rule)) {
224:                        Question question = newResponseDialog.getQuestion();
225:                        rule.addCondition(question);
226:                        table.revalidate();
227:                        table.repaint();
228:                    }
229:                }
230:            }
231:
232:            private class DeleteResponse implements  ActionListener {
233:                public void actionPerformed(ActionEvent e) {
234:                    int row = table.getSelectedRow();
235:                    if (row < 0 || row >= getRowCount())
236:                        return;
237:                    rule.getConditions().remove(row);
238:                    table.clearSelection();
239:                    table.revalidate();
240:                    table.repaint();
241:                    notifier.notifyObservers(null);
242:                }
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.