Download presentation
Presentation is loading. Please wait.
Published byRosalind Beasley Modified over 6 years ago
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
4
Model/View/Presenter
Variation of MVC Merged Input/Output GUI AJAX & co. Presenter business logic
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
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 Explorer Image viewer Editor Selection
Morphs Selection to Action's model Action
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
TopComponent1 module A TopComponent2 module B Defined together as MVP Common Interface An Action
19
Context Actions 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 “key” to complete control
@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
23
Q&A
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.