Sexy Models! an API for Declarative Data Models on the Desktop James Lemieux, Lombardi Software Jesse Wilson, Google
Total Page:16
File Type:pdf, Size:1020Kb
Sexy Models! An API for Declarative Data Models on the Desktop James Lemieux, Lombardi Software Jesse Wilson, Google http://publicobject.com/glazedlists/ TS-3057 2007 JavaOneSM Conference | Session TS-3057 | How Does Glazed Lists Help Me? Create a better user experience with less code Implement deep binding to make your application feel smarter. Decouple your domain model from your user interface. 2007 JavaOneSM Conference | Session TS-3057 | 2 Agenda Introduction to List Transformations “Deep Binding” Inferring Hierarchy Easy Chart Binding API Highlights 2007 JavaOneSM Conference | Session TS-3057 | 3 Agenda Introduction to List Transformations “Deep Binding” Inferring Hierarchy Easy Chart Binding API Highlights 2007 JavaOneSM Conference | Session TS-3057 | 4 Glazed Lists Project Profile “List Transformations in Java™ Programming Language” • Actively developed • Free, open source • Stable and well tested 2007 JavaOneSM Conference | Session TS-3057 | 5 You Know the API • ArrayList + Observer Pattern = EventList 2007 JavaOneSM Conference | Session TS-3057 | 6 Step 1 of 4: BasicEventList • Holds your data • Observable 2007 JavaOneSM Conference | Session TS-3057 | 7 Step 1.5 of 4: TransformedList • An EventList that decorates another EventList • Observable 2007 JavaOneSM Conference | Session TS-3057 | 8 Step 2 of 4: SortedList • One of the TransformedLists • A view of your data 2007 JavaOneSM Conference | Session TS-3057 | 9 Comparator Interface interface Comparator<T> { int compare(T alpha, T beta); } 2007 JavaOneSM Conference | Session TS-3057 | 10 Step 3 of 4: FilterList • Matcher, MatcherEditor interfaces for creating custom filters • Built-in matchers for iTunes-style filtering 2007 JavaOneSM Conference | Session TS-3057 | 11 Matcher Interface interface Matcher<T> { boolean matches(T value); } 2007 JavaOneSM Conference | Session TS-3057 | 12 Step 4 of 4: EventTableModel • TableFormat provides the columns • EventList provides the rows 2007 JavaOneSM Conference | Session TS-3057 | 13 TableFormat Interface interface TableFormat<T> { int getColumnCount(); String getColumnName(int column); Object getColumnValue(T baseObject, int column); } 2007 JavaOneSM Conference | Session TS-3057 | 14 DEMO Source, Sort, Filter, Display 2007 JavaOneSM Conference | Session TS-3057 | 15 Agenda Introduction to List Transformations “Deep Binding” Inferring Hierarchy Easy Chart Binding API Highlights 2007 JavaOneSM Conference | Session TS-3057 | 16 Deep Binding? Your data and view don’t line up perfectly • Songs to artists • Rockstars by band 2007 JavaOneSM Conference | Session TS-3057 | 17 Songs to Artists: Input • Cake, The Distance • Eminem, Lose Yourself • ACDC, Shoot to Thrill • Cake, Short Skirt Long Jacket • ACDC, Thunderstruck 2007 JavaOneSM Conference | Session TS-3057 | 18 Songs to Artists: Output • ACDC • Cake • Eminem 2007 JavaOneSM Conference | Session TS-3057 | 19 Songs to Artists: Pipeline • EventList<Song> • FunctionList of artists • UniqueList of artists • Add more songs, the corresponding artists show up automagically 2007 JavaOneSM Conference | Session TS-3057 | 20 Songs to Artists 2007 JavaOneSM Conference | Session TS-3057 | 21 Rockstars by Band: Input • Kurt Cobain, Nirvana • Billy Joe, Green Day • Mick Jagger, Rolling Stones • Keith Richards, Rolling Stones • Dave Grohl, Nirvana • Tre Cool, Green Day 2007 JavaOneSM Conference | Session TS-3057 | 22 Rockstars by Band: Output • Green Day: Billy Joe, Tre Cool • Nirvana: Kurt Cobain, Dave Grohl • Rolling Stones: Mick Jagger, Keith Richards 2007 JavaOneSM Conference | Session TS-3057 | 23 Rockstars by Band: Pipeline • EventList<Rockstar> • GroupingList groups by band using a Comparator 2007 JavaOneSM Conference | Session TS-3057 | 24 Rockstars by Band • Diagram 2007 JavaOneSM Conference | Session TS-3057 | 25 DEMO Deep Binding 2007 JavaOneSM Conference | Session TS-3057 | 26 Agenda Introduction to List Transformations “Deep Binding” Inferring Hierarchy Easy Chart Binding API Highlights 2007 JavaOneSM Conference | Session TS-3057 | 27 TreeList Overview • Filterable and sortable • Bind to trees and treetables • Infers structure from a flat list 2007 JavaOneSM Conference | Session TS-3057 | 28 Song Hierarchy: Input • Green Day: Dookie, Basket Case • Green Day: American Idiot, Welcome to Paradise • Cake: Prolonging the Magic, Sheep go to Heaven 2007 JavaOneSM Conference | Session TS-3057 | 29 Song Hierarchy: Output • Green Day • Dookie • Basket Case • American Idiot • Welcome to Paradise • Cake • Prolonging the Magic • Sheep go to Heaven 2007 JavaOneSM Conference | Session TS-3057 | 30 TreeList.Format Interface interface Format<T> { void getPath(List<T> path, T element); boolean allowsChildren(T element); Comparator<T> getComparator(int depth); } 2007 JavaOneSM Conference | Session TS-3057 | 31 DEMO Inferring Hierarchy 2007 JavaOneSM Conference | Session TS-3057 | 32 Agenda Introduction to List Transformations “Deep Binding” Inferring Hierarchy Easy Chart Binding API Highlights 2007 JavaOneSM Conference | Session TS-3057 | 33 Songs by Genre: Input • Punk Rock: Green Day, Basket Case • Punk Rock: Green Day, Welcome to Paradise • Folk Rock: Cake, Sheep Go to Heaven • Hard Rock: ACDC, High Voltage • Hard Rock: ACDC: Thunderstruck 2007 JavaOneSM Conference | Session TS-3057 | 34 Songs by Genre: Output Hard Rock Punk Rock Folk Rock 2007 JavaOneSM Conference | Session TS-3057 | 35 DEMO Chart Binding 2007 JavaOneSM Conference | Session TS-3057 | 36 Agenda Introduction to List Transformations “Deep Binding” Inferring Hierarchy Easy Chart Binding API Highlights 2007 JavaOneSM Conference | Session TS-3057 | 37 Declarative • Tell Glazed Lists what to do • Not how to do it 2007 JavaOneSM Conference | Session TS-3057 | 38 Concurrent • Read/Write locks are built-in • Background fetching is easy • Perceived and actual performance is higher 2007 JavaOneSM Conference | Session TS-3057 | 39 Productive • Goal: Write less code • You provide the business logic, Glazed Lists does the rest • Common pattern to most EventLists: implement the corresponding interface • Bean properties for implementing APIs 2007 JavaOneSM Conference | Session TS-3057 | 40 DEMO Productive APIs 2007 JavaOneSM Conference | Session TS-3057 | 41 Agenda Introduction to List Transformations “Deep Binding” Inferring Hierarchy Easy Chart Binding API Highlights Wrapping Up 2007 JavaOneSM Conference | Session TS-3057 | 42 It’s Fast • Fine-grained events allow Glazed Lists to sort and filter tables with 100,000+ elements • Uses custom data structures internally to manage indices efficiently 2007 JavaOneSM Conference | Session TS-3057 | 43 Plays Well With Others • Swing • SWT • SwingLabs • JFreeChart • Layout • Beans Binding (JSR 295) 2007 JavaOneSM Conference | Session TS-3057 | 44 Interfaces for JavaBeans™ Architecture // uses the method, Song.getArtist() Comparator<Song> songsByArtist = GlazedLists.beanPropertyComparator( Song.class, “artist”); // uses Song.getName(), getArtist() and getAlbum() TableFormat<Song> songsTableFormat = GlazedLists.tableFormat( Song.class, new String[] { “name”, “artist”, “album” }, new String[] { “Song Name”, “Artist”, “Album” }); // true if “Green Day” equals Song.getArtist() Matcher<Song> artistIsGreenDay = Matchers.beanPropertyMatcher( Song.class, “artist”, “Green Day”); 2007 JavaOneSM Conference | Session TS-3057 | 45 Glazed Lists • Easy for developers • Great for users • High performance • A powerful tool for your toolbox 2007 JavaOneSM Conference | Session TS-3057 | 46 For More Information • http://glazedlists.dev.java.net/ • http://publicobject.com/glazedlists/ 2007 JavaOneSM Conference | Session TS-3057 | 47 Q&A James Lemieux Jesse Wilson 2007 JavaOneSM Conference | Session TS-3057 | 48 Sexy Models! An API for Declarative Data Models on the Desktop James Lemieux, Lombardi Software Jesse Wilson, Google http://publicobject.com/glazedlists/ TS-3057 2007 JavaOneSM Conference | Session TS-3057 | .