Nodes and Explorer David Strupl Staff Engineer Sun Microsystems.

Slides:



Advertisements
Similar presentations
Chapter 23 Organizing list implementations. This chapter discusses n The notion of an iterator. n The standard Java library interface Collection, and.
Advertisements

Binary Trees. DCS – SWC 2 Binary Trees Sets and Maps in Java are also available in tree-based implementations A Tree is – in this context – a data structure.
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Principles of Object-Oriented Software Development The language Java.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Written by Liron Blecher
Java Beans.
CSC 142 O 1 CSC 142 Java More About Inheritance & Interfaces [Reading: chapter 13]
Agoracast: Design and Tools Review David Wallace Croft Senior Java Architect CroftSoft Inc Talk-Java/Drink-Java Las Colinas, Texas.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
+ A Short Java RMI Tutorial Usman Saleem
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional.
Inheritance and Access Control CS 162 (Summer 2009)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Composite A robot made of smaller robots.. * * Line with open diamond at the end means “aggregates”. Basically, it’s saying that the Component objects.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
1 Iterators & the Collection Classes. 2 » The Collection Framework classes provided in the JAVA API(Application Programmer Interface) contains many type.
Data Objects & Editors David Šimonek Sun Microsystems.
Modular Applications and the Lookup API Geertjan Wielenga NetBeans Team.
Data Objects & Editors Tim Boudreau Senior Staff Engineer Sun Microsystems.
Modular Applications and the Lookup API David Štrupl Sun Microsystems.
Chapter 32 JavaBeans and Bean Events
DHTML.
Using the Java Collection Libraries COMP 103 # T2
Actions and Behaviours
MVC in NetBeans and other modular applications Jaroslav Tulach.
Chapter 36 JavaBeans and Bean Events
Recap Modules: dependency management, revisioning, information hiding
Inheritance ITI1121 Nour El Kadri.
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Nodes and Explorer NetBeans ~ JavaBeans Tim Boudreau
Final and Abstract Classes
Data Objects & Editors David Strupl Staff Engineer Sun Microsystems.
Nodes & Explorer Views Geertjan Wielenga Sun Microsystems.
Leftover Patterns Chain of Responsibility
Multiway search trees and the (2,4)-tree
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
NetBeans ~ JavaBeans Jaroslav Tulach Sun Microsystems.
Composite Pattern SE2811 Software Component Design
Binary Tree and General Tree
Binary Trees.
(edited by Nadia Al-Ghreimil)
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
EE 422C Java FX.
7/23/2009 Many thanks to David Sun for some of the included slides!
The super Reference Constructors cannot be used in child classes, even though they have public visibility Yet we often want to use the parent's constructor.
Generic programming in Java
Dynamic Data Structures and Generics
More About Inheritance & Interfaces
Binary Search Trees 7/16/2009.
(edited by Nadia Al-Ghreimil)
Component-Based Software Engineering
Review of Previous Lesson
Final and Abstract Classes
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Heaps.
Presentation transcript:

Nodes and Explorer David Strupl Staff Engineer Sun Microsystems

Agenda Why NetBeans is called NetBeans? Nodes Node views Composition Q/A

Why is it called NetBeans? JavaBeans for the network Beans everywhere 1.0 bean context property sheet Problems API vs. SPI

API and SPI API – Application Program Interface You are given an object you can call Object should usually be a final class Otherwise you cannot change it backward-compatibly You can still use Lookup in an API to make it extensible, even though it is final SPI – Service Provider Interface You provide an implementation of some interface It adds new functionality to an existing library Which may have an API

Separating API and SPI Backward compatibility A social responsibility when creating an API Final classes for APIs Interfaces/Abstract classes for SPI Source compatibility Binary compatibility

Binary compatibility You can compatibly add methods to a final class You can compatibly remove methods from an interface If you ensure API clients can never get an actual instance of the SPI class – wrap them in a final class If you mix API and SPI, no changes are provably backward-compatible

Nodes Typed JavaBeans no reflection standard listeners extensibility Support for hierarchy correctness guaranteed Bridge to beans via BeanNode

Presentation Layer Nodes are a presentation layer Nodes are hierarchical They have child nodes that can have child nodes Nodes take a random object and provide human-friendly features Actions Display name, Description, Icon Properties (can be shown/edited in property sheet) Clipboard operations

Nodes API import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; class MyNode extends AbstractNode { public MyNode() { super(new MyChildren()); }} class MyChildren extends Children.Keys<String> { protected void addNotify() { setKeys(Collections.nCopies(1, “Child”)); } protected Node[] createNodes(String key) { MyNode n = new MyNode(); n.setName(key); return new Node[] { n };

Rules Nodes are the presentation layer – a model of data they are not the data! Child nodes are created lazily ChildFactory + Children.create() Handles creating children on a background thread Children.addNotify, Children.setKeys Make sure they garbage collect leaks with listeners possible use of removeNotify() in Children subclasses Never cast a Node to a particular type Instead, examine its Lookup's contents!

Node Actions Addition over JavaBeans Swing Actions Action[] Node.getAction(boolean) Multiselection who knows who? An Action A Node Observes Provides Common Interface

A Node's Context Lookup Node.getLookup() Passed in constructor Replacement for old getCookie(Class) No marker interface OpenCookie, EditorCookie, etc. Put an implementation of some class in the Nodes lookup Write actions sensitive to that object Multiselection ProxyLookup

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() { lkpInfo = context.lookupResult (Whatever.class); lkpInfo.addLookupListener(this); resultChanged(null); public boolean isEnabled() { init(); return super.isEnabled(); public Action createContextAwareInstance(Lookup context) { return new FooAction(context);

Explorer Views An “explorer” component is a Swing component It can show a Node and its children Many different components Trees, Lists, Combo Boxes, Tree Tables, Property Sheet all in org.openide.explorer.view Nodes provide a universal tree-model for presenting data Explorer views are components to show that data to the user

Root Container class MyPanel extends JPanel implements ExplorerManager.Provider { public MyPanel() { myManager = new ExplorerManager(); add(new BeanTreeView()); add(new PropertySheetView()); myManager.setRootContext(myNode); } public ExplorerManager getExplorerManager() { return myManager;

Views ExplorerManager root context explored context selected nodes (vetoable) General Model behind Swing BeanTreeView, ContextTreeView ListView PropertySheet TableTreeView

Property sheet protected Sheet createSheet() { Sheet sheet = super.createSheet(); Sheet.Set props = sheet.get(Sheet.PROPERTIES); if (props == null) { props = Sheet.createPropertiesSet(); sheet.put(props); } props.put(new PropertySupport.ReadWrite("name", String.class, "Nice Name", "Short desc") { String val = ""; public Object getValue() throws IllegalAccessException, InvocationTargetException { return val; public void setValue(Object val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { String old = this.val; this.val = val.toString(); firePropertyChange("name", old, val); }}); return sheet; }

Write your own View Just a visual JavaBean Overwrite addNotify and removeNotify search parents for ExplorerManager.Provider add listeners display what ExplorerManager says Control ExplorerManager call setters add vetoable listeners

Nodes and Selection Each window component has a Lookup Nodes have Lookups You can easily have the window component's Lookup proxy whatever the Lookup(s) of the selected Node(s) in an explorer view

Conclusion Nodes are typed JavaBeans Hierarchy Extensible Rich Set of Views Standalone

DEMO Standalone Explorer

Q&A http://bits.netbeans.org/dev/javadoc/org-openide-nodes/ http://bits.netbeans.org/dev/javadoc/org-openide-explorer/