If you can't read please download the document
MVC/DCI in NetBeans by Jaroslav Tulach
Embed Size (px)
DESCRIPTION
MVC/DCI in NetBeans by Jaroslav Tulach
Citation preview
- 1.MVC in NetBeans and other modular applications Jaroslav
Tulach
2. Agenda
3. MVC
-
- Model knows nothing about the rest
http://zdrojak.root.cz/clanky/prezentacni-vzory-zrodiny-mvc/ 4.
Model/View/Presenter
http://zdrojak.root.cz/clanky/prezentacni-vzory-zrodiny-mvc/ 5.
Dialogs & Wizards API
-
- Notify, Dialog, Wizard descriptors
6. Actions
-
- works with the only model
7. Actions in NetBeans
-
- knows nothing about components
-
- slightly different meaning in each
8. Critique of MVC
- OOP good for data modeling
- BankAccount & money transfer
9. DCI
-
- as different as Simula or Beta
http://www.artima.com/articles/dci_vision.html 10. DCI Actions
in NetBeans
-
- usually some specific interface
-
- enables/disables on its presence
- TopComponents provide own context
-
- morph themselves to specific interfaces
-
- system builds Menu, Toolbar
-
- binds actions to selected TopComponent's context
11. DCI in NetBeansAction Selection Morphs Selectionto Action's
modelEditor ExplorerImageviewer 12. Lookup
-
- a place to fish for an interface
-
- an object can morph to something else
13. Exposing Window State class MyWindow
extendsorg.openide.windows.TopComponent{ privateJEditorPane pane;
public org.openide.util.Lookup getLookup() {
returnLookups.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);
- doc.insertString ("Hello world!", null, 0);
15. Listening
- res = someLookup.lookupResult(SomeClass.class);
- res.allItems(); // initialize
- res.addLookupListener (new LookupListener() {
- public void resultChanged (LookupEvent e) {
- for (SomeClass : res.allInstances()) {
16. Create Own Lookup
- AbstractLookup + InstanceContent
-
- Lookupwhose 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 {
- protected voidbeforeLookup (Template t) {
- if (t.getType() == OpenCookie.class) {
- ic.add(new MorphAsOpenCookie(tc));
- classMorphAsOpenCookie implements OpenCookie {
- // implement open on MyTopComponent
18. Actions MVC and Modularity Defined together as
MVPTopComponent1module A An Action CommonInterface
TopComponent2module 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) { returnnew
FooAction(context); } } 20. Into the Future
- iconBase=org/.../Open.png
- public class MyAction extends ActionListener {
- publicMyAction(OpenCookie oc){
- // or other ways to dodependency injection
- public void actionPerformed(ActionEvent ev) {
21. Into the Future II
- iconBase=org/.../Open.png,
- public class MyAction extends ActionListener {
-
- any TopComponent can provide own action
-
- system will delegate, if found
-
- tc. getActionMap(). put ( find , new MyOwnAction());
22. Conclusion
-
- view and controller tied to model
-
- the way to morph in NetBeans
-
- define control interfaces
- Future is in @annotations
23. Q&A