Source Code Cross Referenced for PrintMapKeysList.java in  » Report » pentaho-report » org » pentaho » designstudio » controls » 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.controls 
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.controls;
014:
015:        import java.util.ArrayList;
016:        import java.util.Arrays;
017:        import java.util.List;
018:
019:        import org.eclipse.jface.action.Action;
020:        import org.eclipse.jface.action.IMenuListener;
021:        import org.eclipse.jface.action.IMenuManager;
022:        import org.eclipse.jface.action.MenuManager;
023:        import org.eclipse.jface.viewers.CellEditor;
024:        import org.eclipse.jface.viewers.ICellModifier;
025:        import org.eclipse.jface.viewers.IStructuredContentProvider;
026:        import org.eclipse.jface.viewers.IStructuredSelection;
027:        import org.eclipse.jface.viewers.LabelProvider;
028:        import org.eclipse.jface.viewers.TableViewer;
029:        import org.eclipse.jface.viewers.TextCellEditor;
030:        import org.eclipse.jface.viewers.Viewer;
031:        import org.eclipse.swt.SWT;
032:        import org.eclipse.swt.events.ControlEvent;
033:        import org.eclipse.swt.events.ControlListener;
034:        import org.eclipse.swt.widgets.Menu;
035:        import org.eclipse.swt.widgets.Table;
036:        import org.eclipse.swt.widgets.TableColumn;
037:        import org.eclipse.swt.widgets.TableItem;
038:        import org.pentaho.actionsequence.dom.ActionInputConstant;
039:        import org.pentaho.actionsequence.dom.IActionInputValueProvider;
040:        import org.pentaho.actionsequence.dom.actions.PrintMapValsAction;
041:
042:        /**
043:         * Table viewer used for viewing and modifying the inputs and outputs of an action
044:         * definition element.
045:         * 
046:         * @author Angelo Rodriguez
047:         */
048:        public class PrintMapKeysList extends TableViewer {
049:
050:            static final String COLUMN_HDR_0 = "Keys";
051:
052:            static final String COLUMN_PROP_0 = "Keys"; //$NON-NLS-1$
053:
054:            public class ContentProvider implements  IStructuredContentProvider {
055:
056:                public Object[] getElements(Object ioElement) {
057:                    return printMapValsAction.getKeys();
058:                }
059:
060:                public void dispose() {
061:                }
062:
063:                public void inputChanged(Viewer viewer, Object oldInput,
064:                        Object newInput) {
065:                    printMapValsAction = (PrintMapValsAction) newInput;
066:                }
067:            }
068:
069:            class CellModifier implements  ICellModifier {
070:
071:                public boolean canModify(Object element, String property) {
072:                    return true;
073:                }
074:
075:                public Object getValue(Object element, String property) {
076:                    return ((ActionInputConstant) element).getStringValue();
077:                }
078:
079:                public void modify(Object element, String property, Object value) {
080:                    if (value.toString().trim().length() > 0) {
081:                        TableItem tableItem = (TableItem) element;
082:                        String origValue = tableItem.getText();
083:                        IActionInputValueProvider[] origKeys = printMapValsAction
084:                                .getKeys();
085:                        ActionInputConstant[] newKeys = new ActionInputConstant[origKeys.length];
086:                        for (int i = 0; i < origKeys.length; i++) {
087:                            ActionInputConstant actionInputConstant = (ActionInputConstant) origKeys[i];
088:                            if (actionInputConstant.getStringValue().equals(
089:                                    origValue)) {
090:                                newKeys[i] = new ActionInputConstant(value
091:                                        .toString());
092:                                tableItem.setText(value.toString());
093:                            } else {
094:                                newKeys[i] = (ActionInputConstant) origKeys[i];
095:                            }
096:                        }
097:                        printMapValsAction.setKeys(newKeys);
098:                    }
099:                }
100:            }
101:
102:            protected class DeleteInputAction extends Action {
103:                public DeleteInputAction() {
104:                    super ("Delete"); //$NON-NLS-1$
105:                }
106:
107:                public void run() {
108:                    removeSelectedKey();
109:                }
110:            }
111:
112:            protected class AddInputAction extends Action {
113:                public AddInputAction() {
114:                    super ("Add"); //$NON-NLS-1$
115:                }
116:
117:                public void run() {
118:                    addKey();
119:                }
120:            }
121:
122:            PrintMapValsAction printMapValsAction;
123:            protected DeleteInputAction deleteIOAction = new DeleteInputAction();
124:            protected AddInputAction addIOAction = new AddInputAction();
125:            private ContentProvider contentProvider;
126:
127:            /** 
128:             * Creates an viewer
129:             * @param parent   the parent of this viewer.
130:             * @param toolkit  the form toolkit.
131:             */
132:            public PrintMapKeysList(Table table) {
133:                super (table);
134:
135:                table.setHeaderVisible(true);
136:                createColumns();
137:                contentProvider = new ContentProvider();
138:                setContentProvider(contentProvider);
139:                setLabelProvider(new LabelProvider() {
140:                    public String getText(Object element) {
141:                        String text = ""; //$NON-NLS-1$
142:                        if (element instanceof  ActionInputConstant) {
143:                            ActionInputConstant actionInputConstant = (ActionInputConstant) element;
144:                            text = actionInputConstant.getStringValue();
145:                        }
146:                        return text;
147:                    }
148:                });
149:                setCellModifier(new CellModifier());
150:                table.addControlListener(new ControlListener() {
151:
152:                    public void controlMoved(ControlEvent e) {
153:                    }
154:
155:                    public void controlResized(ControlEvent e) {
156:                        getTable().getColumn(0)
157:                                .setWidth(getTable().getSize().x);
158:                    }
159:
160:                });
161:                createPopupMenu();
162:            }
163:
164:            /** 
165:             * Creates the popup menu used by this viewer.
166:             */
167:            protected void createPopupMenu() {
168:                MenuManager popupMenu = new MenuManager();
169:
170:                popupMenu.add(addIOAction);
171:                popupMenu.add(deleteIOAction);
172:                popupMenu.addMenuListener(new IMenuListener() {
173:                    public void menuAboutToShow(IMenuManager manager) {
174:                        updatePopupMenuState(manager);
175:                    }
176:                });
177:
178:                Table table = getTable();
179:                Menu menu = popupMenu.createContextMenu(table);
180:                table.setMenu(menu);
181:            }
182:
183:            protected void updatePopupMenuState(IMenuManager menuMgr) {
184:                IStructuredSelection selection = (IStructuredSelection) getSelection();
185:                deleteIOAction.setEnabled(selection.size() > 0);
186:            }
187:
188:            /* (non-Javadoc)
189:             * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object)
190:             */
191:            protected void inputChanged(Object input, Object oldInput) {
192:                printMapValsAction = (PrintMapValsAction) input;
193:                super .inputChanged(input, oldInput);
194:            }
195:
196:            /** 
197:             * Removes the selected inputs/ouputs from the action definition.
198:             */
199:            protected void removeSelectedKey() {
200:                ArrayList keys = new ArrayList(Arrays.asList(printMapValsAction
201:                        .getKeys()));
202:                List selectedKeys = ((IStructuredSelection) getSelection())
203:                        .toList();
204:                boolean bool = keys.contains(selectedKeys.get(0));
205:                keys
206:                        .removeAll(((IStructuredSelection) getSelection())
207:                                .toList());
208:                printMapValsAction.setKeys((ActionInputConstant[]) keys
209:                        .toArray(new ActionInputConstant[0]));
210:                refresh();
211:            }
212:
213:            protected void addKey() {
214:                ArrayList keys = new ArrayList(Arrays.asList(printMapValsAction
215:                        .getKeys()));
216:                keys.add(new ActionInputConstant(getUniqueKeyName()));
217:                printMapValsAction.setKeys((ActionInputConstant[]) keys
218:                        .toArray(new ActionInputConstant[0]));
219:                refresh();
220:            }
221:
222:            private String getUniqueKeyName() {
223:                ArrayList existingKeys = new ArrayList();
224:                IActionInputValueProvider[] actionInputConstants = printMapValsAction
225:                        .getKeys();
226:                for (int i = 0; i < actionInputConstants.length; i++) {
227:                    existingKeys.add(actionInputConstants[i].getStringValue());
228:                }
229:                int index = 1;
230:                while (existingKeys.contains("key" + index)) {
231:                    index++;
232:                }
233:                return "key" + index;
234:            }
235:
236:            private void createColumns() {
237:                Table table = getTable();
238:                TableColumn tableColumn = new TableColumn(table, SWT.LEFT);
239:                tableColumn.setText(COLUMN_HDR_0);
240:                tableColumn.setWidth(getTable().getSize().x);
241:                tableColumn.setResizable(false);
242:                setCellEditors(new CellEditor[] { new TextCellEditor(table) });
243:
244:                setColumnProperties(new String[] { COLUMN_PROP_0 });
245:
246:            }
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.