MVC in NetBeans 
       and other modular applications 
       
      
     
      
       Jaroslav Tulach ...

      
       Agenda 
      
     
      
       <ul>
        
         <li>MVC 
        
       </ul>
       <ul>
      ...

      
       MVC 
      
     
      
       <ul>
        
         <li>Architecture Pattern 
        
       </ul>
    ...

      
       Model/View/Presenter 
      
     
      
       <ul>
        
         <li>Variation of MVC 
        
    ...

      
       
      
     
      
       Dialogs & Wizards API 
      
     
      
       <ul>
        
         <li>De...

      
       
      
     
      
       Actions 
      
     
      
       <ul>
        
         <li>Action is view 
...

      
       Actions in NetBeans 
      
     
      
       <ul>
        
         <li>Single action 
        
       <...

      
       Critique of MVC 
      
     
      
       <ul>
        
         <li>OOP good for data modeling 
        ...

      
       DCI 
      
     
      
       <ul>
        
         <li>Scandinavian 
        
       </ul>
       <ul>
...

      
       DCI Actions in NetBeans  
      
     
      
       <ul>
        
         <li>Action seeks in context 
  ...

      
       DCI in NetBeans  
      
     
      Action 
      
     
      Selection 
      
     
      Morphs Select...

      
       Lookup 
      
     
      
       <ul>
        
         <li>“Magical Bag” 
        
       </ul>
       <...

      
       Exposing Window State 
      
     
      
       class   MyWindow   
       extends  org.openide.windows.T...

      
       Querying 
      
     
      
       <ul>
        
         <li>import org.openide.util.Utilities; 
       ...

      
       Listening 
      
     
      
       <ul>
        
         <li>Lookup.Result<SomeClass> res; 
        
  ...

      
       Create Own Lookup 
      
     
      
       <ul>
        
         <li>AbstractLookup + InstanceContent  ...

      
       Morphing 
      
     
      
       <ul>
        
         <li>class MyLazyLookup extends AbstractLookup {...

      
       Actions MVC and Modularity 
      
     
      Defined together as MVP 
      
       
       
       
    ...

      
       Context Actions 
      
     
      
       <ul>
        
         <li>http://wiki.netbeans.org/wiki/view/D...

      
       Into the Future 
      
     
      
       <ul>
        
         <li>@ActionRegistration ( 
        
    ...

      
       Into the Future II 
      
     
      
       <ul>
        
         <li>@ActionRegistration ( 
        
 ...

      
       Conclusion 
      
     
      
       <ul>
        
         <li>MVC 
        
       </ul>
       <ul>
  ...

      
       Q&A
Upcoming SlideShare
Loading in …5
×

MVC/DCI in NetBeans by Jaroslav Tulach

2,558 views

Published on

MVC/DCI in NetBeans by Jaroslav Tulach

Published in: Technology, News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,558
On SlideShare
0
From Embeds
0
Number of Embeds
36
Actions
Shares
0
Downloads
53
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • MVC/DCI in NetBeans by Jaroslav Tulach

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

    ×