MVC/DCI in NetBeans by Jaroslav Tulach

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    MVC/DCI in NetBeans by Jaroslav Tulach - Presentation Transcript

    1. MVC in NetBeans and other modular applications Jaroslav Tulach
    2. Agenda
      • MVC
      • DCI
      • NetBeans APIs
      • Towards Future
      • Q/A
    3. MVC
      • Architecture Pattern
      • Separating Application
        • Model knows nothing about the rest
        • Better maintenance
      • Separate Input/Output
        • Mainframes
        • Web
      • Controller
        • knows it all
      http://zdrojak.root.cz/clanky/prezentacni-vzory-zrodiny-mvc/
    4. Model/View/Presenter
      • Variation of MVC
      • Merged Input/Output
        • GUI
        • AJAX & co.
      • Presenter
        • business
        • logic
      http://zdrojak.root.cz/clanky/prezentacni-vzory-zrodiny-mvc/
    5. Dialogs & Wizards API
      • Descriptor is model
        • Notify, Dialog, Wizard descriptors
      • DialogDisplayer
        • presenter
      • Wizards
        • Iterator, Panel
        • Internal view
      • No modularity
    6. Actions
      • Action is view
        • enables/disables
        • updates name
      • Editor is model
        • text
        • selection
        • history
      • Action tight to editor
        • works with the only model
    7. Actions in NetBeans
      • Single action
        • knows nothing about components
        • slightly different meaning in each
      • Multiple Components
        • from various modules
      • Not really MVC
    8. Critique of MVC
      • OOP good for data modeling
      • Where to put operations?
      • BankAccount & money transfer
        • operation on account?
        • asymmetric
        • all or nothing
        • transactions
      • Projection of user mind
    9. DCI
      • Scandinavian
        • as different as Simula or Beta
      • Interactions
        • specify required context
      • Data
        • morphed
        • fed to the context
        • manipulated by
        • operations
      http://www.artima.com/articles/dci_vision.html
    10. DCI Actions in NetBeans
      • Action seeks in context
        • usually some specific interface
        • enables/disables on its presence
        • operates on it
      • TopComponents provide own context
        • morph themselves to specific interfaces
      • Selection
        • system builds Menu, Toolbar
        • binds actions to selected TopComponent's context
    11. DCI in NetBeans Action Selection Morphs Selection to Action's model Editor Explorer Image viewer
    12. Lookup
      • “Magical Bag”
        • a place to “fish” for an interface
      • Adaptable Pattern
        • an object can “morph” to something else
      • Supports changes
        • “swim in and out”
        • listeners
      • Type safe
    13. Exposing Window State class MyWindow extends org.openide.windows.TopComponent { private JEditorPane pane; public org.openide.util.Lookup getLookup() { return Lookups.singleton(pane.getDocument()); } }
    14. Querying
      • import org.openide.util.Utilities;
      • class MyInsertAction extends AbstractAction {
      • public void actionPerformed (ActionEvent ev) {
      • Lookup lkp = Utilities.actionGlobalContext();
      • Document doc = lkp.lookup (Document.class);
      • if (doc != null) {
      • doc.insertString ("Hello world!", null, 0);
      • }
      • }
      • }
    15. Listening
      • Lookup.Result<SomeClass> res;
      • res = someLookup.lookupResult(SomeClass.class);
      • res.allItems(); // initialize
      • res.addLookupListener (new LookupListener() {
      • public void resultChanged (LookupEvent e) {
      • for (SomeClass : res.allInstances()) {
      •   //handler code here
      • }
      • });
    16. Create Own Lookup
      • AbstractLookup + InstanceContent
        • Lookup whose contents you can manage
      • Lookups.singleton( Object ) - one item Lookup
      • Lookups.fixed( Object... ) - unchanging Lookup
      • Lookups.exclude ( Lookup, Class[] );
      • ProxyLookup ( Lookup[] otherLookups ) - compose multiple lookups
    17. Morphing
      • class MyLazyLookup extends AbstractLookup {
      • MyTopComponent tc;
      • protected <T> void beforeLookup (Template<T> t) {
      • if (t.getType() == OpenCookie.class) {
      • ic.add(new MorphAsOpenCookie(tc));
      • }
      • }
      • }
      • class MorphAsOpenCookie implements OpenCookie {
      • public void open() {
      • // implement “open” on MyTopComponent
      • }
      • }
    18. Actions MVC and Modularity Defined together as MVP TopComponent1 module A An Action Common Interface TopComponent2 module B
    19. Context Actions
      • http://wiki.netbeans.org/wiki/view/DevFaqActionContextSensitive
      public class FooAction extends AbstractAction implements LookupListener, ContextAwareAction { private Lookup context; Lookup.Result lkpInfo; public FooAction() { this( Utilities.actionsGlobalContext() ); } private FooAction(Lookup context) { this.context = context; } void init() { Lookup.Template tpl = new Lookup.Template( Whatever.class ); lkpInfo = context.lookup (tpl); lkpInfo.addLookupListener(this); resultChanged(null); } public boolean isEnabled() { init(); return super.isEnabled(); } public Action createContextAwareInstance(Lookup context) { return new FooAction(context); } }
    20. Into the Future
      • @ActionRegistration (
      • displayName=”Open Action”,
      • iconBase=”org/.../Open.png”
      • )
      • public class MyAction extends ActionListener {
      • private OpenCookie oc;
      • public MyAction(OpenCookie oc) {
      • // or other ways to do dependency injection
      • this.oc = oc;
      • }
      • public void actionPerformed(ActionEvent ev) {
      • oc.open();
      • }
      • }
    21. Into the Future II
      • @ActionRegistration (
      • displayName=”Find Action”,
      • iconBase=”org/.../Open.png”,
      • key=”find”
      • )
      • public class MyAction extends ActionListener {
      • }
      • “key” to complete control
        • any TopComponent can provide own action
        • system will delegate, if found
        • tc. getActionMap(). put ( “find” , new MyOwnAction());
    22. Conclusion
      • MVC
        • view and controller tied to model
      • DCI
        • morphing & adaptation
      • Lookup
        • the way to morph in NetBeans
      • Actions
        • define control interfaces
      • Future is in @annotations
    23. Q&A
    SlideShare Zeitgeist 2009

    + guestb9a4bfguestb9a4bf Nominate

    custom

    404 views, 0 favs, 0 embeds more stats

    MVC/DCI in NetBeans by Jaroslav Tulach

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 404
      • 404 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 8
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories