Source Code Cross Referenced for ListViewerScenario.java in  » IDE-Eclipse » jface » org » eclipse » jface » tests » databinding » scenarios » 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 » IDE Eclipse » jface » org.eclipse.jface.tests.databinding.scenarios 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *     Brad Reynolds - bug 116920
011:         *     Brad Reynolds - bug 160000
012:         *******************************************************************************/package org.eclipse.jface.tests.databinding.scenarios;
013:
014:        import org.eclipse.core.databinding.beans.BeansObservables;
015:        import org.eclipse.core.databinding.observable.Realm;
016:        import org.eclipse.core.databinding.observable.list.IObservableList;
017:        import org.eclipse.core.databinding.observable.map.IObservableMap;
018:        import org.eclipse.core.databinding.observable.value.IObservableValue;
019:        import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
020:        import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
021:        import org.eclipse.jface.databinding.viewers.ViewersObservables;
022:        import org.eclipse.jface.examples.databinding.model.Adventure;
023:        import org.eclipse.jface.examples.databinding.model.Catalog;
024:        import org.eclipse.jface.examples.databinding.model.Lodging;
025:        import org.eclipse.jface.examples.databinding.model.SampleData;
026:        import org.eclipse.jface.viewers.IStructuredSelection;
027:        import org.eclipse.jface.viewers.ListViewer;
028:        import org.eclipse.swt.SWT;
029:        import org.eclipse.swt.widgets.List;
030:
031:        /**
032:         * To run the tests in this class, right-click and select "Run As JUnit Plug-in
033:         * Test". This will also start an Eclipse instance. To clean up the launch
034:         * configuration, open up its "Main" tab and select "[No Application] - Headless
035:         * Mode" as the application to run.
036:         */
037:
038:        public class ListViewerScenario extends ScenariosTestCase {
039:
040:            private Catalog catalog;
041:
042:            private List list;
043:
044:            private ListViewer listViewer;
045:
046:            protected void setUp() throws Exception {
047:                super .setUp();
048:                // do any setup work here
049:                list = new List(getComposite(), SWT.READ_ONLY | SWT.SINGLE);
050:                listViewer = new ListViewer(list);
051:                catalog = SampleData.CATALOG_2005; // Lodging source
052:            }
053:
054:            protected void tearDown() throws Exception {
055:                list.dispose();
056:                list = null;
057:                listViewer = null;
058:                super .tearDown();
059:            }
060:
061:            public void testScenario01() {
062:                // Bind the catalog's lodgings to the combo
063:                IObservableList lodgings = BeansObservables.observeList(Realm
064:                        .getDefault(), catalog, "lodgings");
065:                ObservableListContentProvider contentProvider = new ObservableListContentProvider();
066:
067:                IObservableMap[] attributeMaps = BeansObservables.observeMaps(
068:                        contentProvider.getKnownElements(), Lodging.class,
069:                        new String[] { "name" });
070:                listViewer.setContentProvider(contentProvider);
071:                listViewer.setLabelProvider(new ObservableMapLabelProvider(
072:                        attributeMaps));
073:                listViewer.setInput(lodgings);
074:
075:                // Verify that the combo's items are the lodgings
076:                for (int i = 0; i < catalog.getLodgings().length; i++) {
077:                    assertEquals(catalog.getLodgings()[i], listViewer
078:                            .getElementAt(i));
079:                }
080:                // Verify that the String being shown in the list viewer is the
081:                // "toString" of the combo viewer
082:                String[] lodgingStrings = new String[catalog.getLodgings().length];
083:                for (int i = 0; i < catalog.getLodgings().length; i++) {
084:                    lodgingStrings[i] = catalog.getLodgings()[i].getName();
085:                }
086:                assertArrayEquals(lodgingStrings, list.getItems());
087:
088:                // Verify that the list has no selected item
089:                assertEquals(null, ((IStructuredSelection) listViewer
090:                        .getSelection()).getFirstElement());
091:
092:                // Now bind the selection of the combo to the "defaultLodging" property
093:                // of an adventure
094:                final Adventure adventure = SampleData.WINTER_HOLIDAY;
095:
096:                IObservableValue selection = ViewersObservables
097:                        .observeSingleSelection(listViewer);
098:                getDbc().bindValue(
099:                        selection,
100:                        BeansObservables.observeValue(adventure,
101:                                "defaultLodging"), null, null);
102:
103:                // Verify that the list selection is the default lodging
104:                assertEquals(((IStructuredSelection) listViewer.getSelection())
105:                        .getFirstElement(), adventure.getDefaultLodging());
106:
107:                // Change the model and verify that the list selection changes
108:                adventure.setDefaultLodging(SampleData.CAMP_GROUND);
109:                assertEquals(adventure.getDefaultLodging(),
110:                        SampleData.CAMP_GROUND);
111:                assertEquals(((IStructuredSelection) listViewer.getSelection())
112:                        .getFirstElement(), adventure.getDefaultLodging());
113:
114:                // Change the list selection and verify that the model changes
115:                listViewer.getList().select(3);
116:                assertEquals(((IStructuredSelection) listViewer.getSelection())
117:                        .getFirstElement(), adventure.getDefaultLodging());
118:
119:                adventure.setDefaultLodging(SampleData.YOUTH_HOSTEL);
120:                spinEventLoop(0);
121:                assertEquals(((IStructuredSelection) listViewer.getSelection())
122:                        .getFirstElement(), adventure.getDefaultLodging());
123:
124:            }
125:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.