Source Code Cross Referenced for StringListViewer.java in  » Report » pentaho-report » org » pentaho » designstudio » editors » actionsequence » pages » parameters » 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 » Report » pentaho report » org.pentaho.designstudio.editors.actionsequence.pages.parameters 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         */
013:        package org.pentaho.designstudio.editors.actionsequence.pages.parameters;
014:
015:        import java.util.ArrayList;
016:        import java.util.Arrays;
017:
018:        import org.eclipse.jface.action.Action;
019:        import org.eclipse.jface.action.IMenuListener;
020:        import org.eclipse.jface.action.IMenuManager;
021:        import org.eclipse.jface.action.MenuManager;
022:        import org.eclipse.jface.viewers.CellEditor;
023:        import org.eclipse.jface.viewers.ICellModifier;
024:        import org.eclipse.jface.viewers.IStructuredContentProvider;
025:        import org.eclipse.jface.viewers.LabelProvider;
026:        import org.eclipse.jface.viewers.TableViewer;
027:        import org.eclipse.jface.viewers.TextCellEditor;
028:        import org.eclipse.jface.viewers.Viewer;
029:        import org.eclipse.swt.SWT;
030:        import org.eclipse.swt.events.ControlEvent;
031:        import org.eclipse.swt.events.ControlListener;
032:        import org.eclipse.swt.widgets.Menu;
033:        import org.eclipse.swt.widgets.Table;
034:        import org.eclipse.swt.widgets.TableColumn;
035:        import org.eclipse.swt.widgets.TableItem;
036:        import org.pentaho.actionsequence.dom.ActionSequenceDocument;
037:        import org.pentaho.actionsequence.dom.ActionSequenceInput;
038:        import org.pentaho.designstudio.messages.Messages;
039:
040:        /**
041:         * Viewer used for managing input string lists within an action sequence.
042:         * @author Angelo Rodriguez
043:         */
044:        public class StringListViewer extends TableViewer {
045:
046:            static final String ADD_ITEM_PLACEHOLDER = Messages
047:                    .getString("StringListLabelProvider.UI_ADD_ITEM_LABEL"); //$NON-NLS-1$
048:
049:            public class ContentProvider implements  IStructuredContentProvider {
050:
051:                static final String LIST_ITEM_PATH = ActionSequenceDocument.DEFAULT_VAL_NAME
052:                        + "/list-item"; //$NON-NLS-1$
053:
054:                /* (non-Javadoc)
055:                 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
056:                 */
057:                public Object[] getElements(Object ioElement) {
058:                    ArrayList defStrings = new ArrayList(stringList);
059:                    defStrings.add(ADD_ITEM_PLACEHOLDER);
060:                    return defStrings.toArray();
061:                }
062:
063:                public void dispose() {
064:                }
065:
066:                public void inputChanged(Viewer viewer, Object oldInput,
067:                        Object newInput) {
068:                }
069:
070:            }
071:
072:            class CellModifier implements  ICellModifier {
073:
074:                public boolean canModify(Object element, String property) {
075:                    return true;
076:                }
077:
078:                public Object getValue(Object element, String property) {
079:                    return element;
080:                }
081:
082:                public void modify(Object element, String property, Object value) {
083:                    TableItem tableItem = (TableItem) element;
084:                    int index = getTable().indexOf(tableItem);
085:                    if (index == getTable().getItemCount() - 1) {
086:                        if (!ADD_ITEM_PLACEHOLDER.equals(value)) {
087:                            stringList.add(value);
088:                            actionSequenceInput
089:                                    .setDefaultValue((String[]) stringList
090:                                            .toArray(new String[0]));
091:                            refresh();
092:                        }
093:                    } else {
094:                        stringList.set(index, value);
095:                        actionSequenceInput
096:                                .setDefaultValue((String[]) stringList
097:                                        .toArray(new String[0]));
098:                        refresh();
099:                    }
100:                }
101:            }
102:
103:            class DeleteRowAction extends Action {
104:                public DeleteRowAction() {
105:                    super (Messages
106:                            .getString("StringListViewer.UI_DELETE_ITEM_MENU")); //$NON-NLS-1$
107:                }
108:
109:                public void run() {
110:                    removeSelectedRows();
111:                }
112:            }
113:
114:            static final int NAME_COLUMN_IDX = 0;
115:
116:            static final String COLUMN_HDR_0 = Messages
117:                    .getString("StringListViewer.UI_LIST_VALUES_COL_HEADER"); //$NON-NLS-1$
118:
119:            static final String COLUMN_PROP_0 = "Values"; //$NON-NLS-1$
120:
121:            ActionSequenceInput actionSequenceInput;
122:            ArrayList stringList = new ArrayList();
123:
124:            DeleteRowAction deleteRowAction = new DeleteRowAction();
125:
126:            ContentProvider contentProvider;
127:
128:            ArrayList tableColumns = new ArrayList();
129:
130:            /**
131:             * Creates a string list viewer.
132:             * @param parent the parent of this viewer
133:             * @param table the table to be managed by this viewer
134:             */
135:            public StringListViewer(Table table) {
136:                super (table);
137:
138:                table.setHeaderVisible(true);
139:                table.setLinesVisible(true);
140:                createColumns();
141:                createContentProvider();
142:                createLabelProvider();
143:                setCellModifier(new CellModifier());
144:                table.addControlListener(new ControlListener() {
145:
146:                    public void controlMoved(ControlEvent e) {
147:                    }
148:
149:                    public void controlResized(ControlEvent e) {
150:                        getTable().getColumn(0)
151:                                .setWidth(getTable().getSize().x);
152:                    }
153:
154:                });
155:                createPopupMenu();
156:            }
157:
158:            private void createColumns() {
159:                Table table = getTable();
160:                TableColumn tableColumn = new TableColumn(table, SWT.LEFT);
161:                tableColumn.setText(COLUMN_HDR_0);
162:                tableColumn.setWidth(getTable().getSize().x);
163:                tableColumn.setResizable(false);
164:                setCellEditors(new CellEditor[] { new TextCellEditor(table) });
165:
166:                setColumnProperties(new String[] { COLUMN_PROP_0 });
167:
168:            }
169:
170:            private void createContentProvider() {
171:                contentProvider = new ContentProvider();
172:                setContentProvider(contentProvider);
173:            }
174:
175:            private void createLabelProvider() {
176:                setLabelProvider(new LabelProvider());
177:            }
178:
179:            private void createPopupMenu() {
180:                MenuManager popupMenu = new MenuManager();
181:                popupMenu.add(deleteRowAction);
182:                popupMenu.addMenuListener(new IMenuListener() {
183:                    public void menuAboutToShow(IMenuManager manager) {
184:                        updatePopupMenuState(manager);
185:                    }
186:                });
187:
188:                Table table = getTable();
189:                Menu menu = popupMenu.createContextMenu(table);
190:                table.setMenu(menu);
191:            }
192:
193:            private void removeSelectedRows() {
194:                ArrayList modifiedElements = new ArrayList();
195:                int[] selectedIndeces = getTable().getSelectionIndices();
196:                for (int i = 0; i < stringList.size(); i++) {
197:                    boolean indexFound = false;
198:                    for (int j = 0; j < selectedIndeces.length && !indexFound; j++) {
199:                        indexFound = (i == selectedIndeces[j]);
200:                    }
201:                    if (!indexFound) {
202:                        modifiedElements.add(stringList.get(i));
203:                    }
204:                }
205:                stringList.clear();
206:                stringList.addAll(modifiedElements);
207:                actionSequenceInput.setDefaultValue((String[]) stringList
208:                        .toArray(new String[0]));
209:                refresh();
210:            }
211:
212:            private void updatePopupMenuState(IMenuManager menuMgr) {
213:                int[] selectedIndeces = getTable().getSelectionIndices();
214:                int numElements = contentProvider.getElements(null).length;
215:                boolean enabled = selectedIndeces.length > 0;
216:                for (int i = 0; i < selectedIndeces.length && enabled; i++) {
217:                    enabled = (selectedIndeces[i] != (numElements - 1));
218:                }
219:                deleteRowAction.setEnabled(enabled);
220:            }
221:
222:            /* (non-Javadoc)
223:             * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object)
224:             */
225:            protected void inputChanged(Object input, Object oldInput) {
226:                actionSequenceInput = (ActionSequenceInput) input;
227:                Object defaultValue = actionSequenceInput.getDefaultValue();
228:                stringList.clear();
229:                if (defaultValue instanceof  String[]) {
230:                    stringList.addAll(Arrays.asList((String[]) defaultValue));
231:                }
232:                super.inputChanged(input, oldInput);
233:            }
234:        }
w___w__w__.__j__a___v___a2__s__.c_o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.