Source Code Cross Referenced for NonScriptAndCompListener.java in  » Ajax » ItsNat » org » itsnat » feashow » features » components » 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 
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;
017:
018:        import javax.servlet.ServletRequest;
019:        import javax.servlet.http.HttpSession;
020:        import javax.swing.DefaultListModel;
021:        import javax.swing.ListModel;
022:        import javax.swing.ListSelectionModel;
023:        import org.itsnat.comp.ItsNatComponentManager;
024:        import org.itsnat.comp.html.ItsNatHTMLInputText;
025:        import org.itsnat.comp.html.ItsNatHTMLSelectMult;
026:        import org.itsnat.core.ItsNatDocument;
027:        import org.itsnat.core.ItsNatServletRequest;
028:        import org.itsnat.core.domutil.ItsNatDOMUtil;
029:        import org.itsnat.core.http.ItsNatHttpSession;
030:        import org.w3c.dom.Document;
031:        import org.w3c.dom.Element;
032:        import org.w3c.dom.css.CSSStyleDeclaration;
033:        import org.w3c.dom.css.ElementCSSInlineStyle;
034:
035:        public class NonScriptAndCompListener {
036:            protected ItsNatServletRequest itsNatRequest;
037:            protected ItsNatHTMLSelectMult listComp;
038:
039:            public NonScriptAndCompListener(ItsNatServletRequest itsNatRequest) {
040:                this .itsNatRequest = itsNatRequest;
041:
042:                try {
043:                    ItsNatDocument itsNatDoc = itsNatRequest
044:                            .getItsNatDocument();
045:                    ItsNatComponentManager componentMgr = itsNatDoc
046:                            .getItsNatComponentManager();
047:
048:                    this .listComp = (ItsNatHTMLSelectMult) componentMgr
049:                            .addItsNatComponentById("listId");
050:                    ListSelectionModel selModel = listComp
051:                            .getListSelectionModel();
052:                    selModel
053:                            .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
054:
055:                    ServletRequest request = itsNatRequest.getServletRequest();
056:                    String action = null;
057:
058:                    if (request.getParameter("remove") != null)
059:                        action = "remove";
060:                    else if (request.getParameter("insert") != null)
061:                        action = "insert";
062:                    else if (request.getParameter("update") != null)
063:                        action = "update";
064:
065:                    if (action == null)
066:                        firstTime();
067:                    else
068:                        processAction(action);
069:
070:                    int selectedIndex = listComp.getSelectedIndex();
071:                    if (selectedIndex != -1) {
072:                        ItsNatHTMLInputText itemComp = (ItsNatHTMLInputText) componentMgr
073:                                .addItsNatComponentById("itemId");
074:                        itemComp.setText(listComp.getListModel().getElementAt(
075:                                listComp.getSelectedIndex()).toString());
076:
077:                        ItsNatHTMLInputText posComp = (ItsNatHTMLInputText) componentMgr
078:                                .addItsNatComponentById("posId");
079:                        posComp.setText(Integer.toString(listComp
080:                                .getSelectedIndex()));
081:                    }
082:                } finally {
083:                    saveDocumentToSession();
084:                }
085:            }
086:
087:            public void firstTime() {
088:                DefaultListModel dataModel = (DefaultListModel) listComp
089:                        .getListModel();
090:                dataModel.addElement("Madrid");
091:                dataModel.addElement("Sevilla");
092:                dataModel.addElement("Segovia");
093:                dataModel.addElement("Barcelona");
094:                dataModel.addElement("Oviedo");
095:                dataModel.addElement("Valencia");
096:
097:                ListSelectionModel selModel = listComp.getListSelectionModel();
098:                selModel.setSelectionInterval(2, 3);
099:            }
100:
101:            public void processAction(String action) {
102:                ItsNatDocument itsNatDocPrev = loadDocumentFromSession();
103:
104:                ItsNatHTMLSelectMult prevListComp = (ItsNatHTMLSelectMult) itsNatDocPrev
105:                        .getItsNatComponentManager().findItsNatComponentById(
106:                                "listId");
107:                DefaultListModel model = (DefaultListModel) prevListComp
108:                        .getListModel();
109:                prevListComp.dispose(); // to disconnect the data model from the old markup
110:
111:                listComp.setListModel(model);// Reusing the data model
112:
113:                setSelection();
114:
115:                if (action.equals("remove")) // remove selected
116:                {
117:                    ListSelectionModel selModel = listComp
118:                            .getListSelectionModel();
119:                    int size = model.getSize();
120:                    for (int i = size - 1; i >= 0; i--) // Removing from last to first to avoid index changes
121:                    {
122:                        if (selModel.isSelectedIndex(i))
123:                            model.removeElementAt(i);
124:                    }
125:                } else if (action.equals("insert") || action.equals("update")) {
126:                    ServletRequest request = itsNatRequest.getServletRequest();
127:
128:                    String item = request.getParameter("item");
129:                    int pos;
130:                    try {
131:                        pos = Integer.parseInt(request.getParameter("pos"));
132:                        if (action.equals("insert"))
133:                            model.insertElementAt(item, pos);
134:                        else
135:                            model.setElementAt(item, pos);
136:                    } catch (NumberFormatException ex) {
137:                        setErrorMessage("Bad Position");
138:                    } catch (ArrayIndexOutOfBoundsException ex) {
139:                        setErrorMessage("Bad Position");
140:                    }
141:                }
142:            }
143:
144:            public int[] setSelection() {
145:                ServletRequest request = itsNatRequest.getServletRequest();
146:                String[] selectedParam = request.getParameterValues("list");
147:                if (selectedParam == null)
148:                    return new int[0];
149:
150:                int[] selected = new int[selectedParam.length];
151:                for (int i = 0; i < selected.length; i++)
152:                    selected[i] = listComp.indexOf(selectedParam[i]); // Fails with duplicated names
153:
154:                ListModel model = listComp.getListModel();
155:                boolean[] state = new boolean[model.getSize()];
156:                for (int i = 0; i < selected.length; i++)
157:                    state[selected[i]] = true;
158:
159:                ListSelectionModel selModel = listComp.getListSelectionModel();
160:                for (int i = 0; i < state.length; i++) {
161:                    boolean newState = state[i];
162:                    if (newState != selModel.isSelectedIndex(i)) {
163:                        if (newState)
164:                            addSelectionIntervalJKD14(selModel, i, i);
165:                        else
166:                            selModel.removeSelectionInterval(i, i);
167:                    }
168:                }
169:
170:                return selected;
171:            }
172:
173:            public void saveDocumentToSession() {
174:                ItsNatDocument itsNatDoc = itsNatRequest.getItsNatDocument();
175:                ItsNatHttpSession itsNatSession = (ItsNatHttpSession) itsNatRequest
176:                        .getItsNatSession();
177:                HttpSession session = itsNatSession.getHttpSession();
178:                session.setAttribute("previous_doc", itsNatDoc);
179:            }
180:
181:            public ItsNatDocument loadDocumentFromSession() {
182:                ItsNatHttpSession itsNatSession = (ItsNatHttpSession) itsNatRequest
183:                        .getItsNatSession();
184:                HttpSession session = itsNatSession.getHttpSession();
185:                ItsNatDocument itsNatDocPrev = (ItsNatDocument) session
186:                        .getAttribute("previous_doc");
187:                session.removeAttribute("previous_doc"); // No longer available
188:                return itsNatDocPrev;
189:            }
190:
191:            public static void addSelectionIntervalJKD14(
192:                    ListSelectionModel selModel, int first, int end) {
193:                int mode = selModel.getSelectionMode();
194:                if (mode == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
195:                    for (int i = first - 1; (i >= 0)
196:                            && selModel.isSelectedIndex(i); i--)
197:                        first = i;
198:
199:                    int max = selModel.getMaxSelectionIndex();
200:                    for (int i = end + 1; (i <= max)
201:                            && selModel.isSelectedIndex(i); i++)
202:                        end = i;
203:                }
204:
205:                selModel.addSelectionInterval(first, end);
206:            }
207:
208:            public void setErrorMessage(String msg) {
209:                ItsNatDocument itsNatDoc = itsNatRequest.getItsNatDocument();
210:                Document doc = itsNatDoc.getDocument();
211:                Element errorElem = doc.getElementById("errorId");
212:                ItsNatDOMUtil.setTextContent(errorElem, msg);
213:                ElementCSSInlineStyle errorCSS = (ElementCSSInlineStyle) itsNatDoc
214:                        .getItsNatNode(errorElem);
215:                CSSStyleDeclaration style = errorCSS.getStyle();
216:                style.removeProperty("display"); // makes visible
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.