org.netbeans.spi.viewmodel

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » spi » org.netbeans.spi.viewmodel 
org.netbeans.spi.viewmodel
View Model API Defines API for sharing of Tree Table View. This API has been designed for sharing Debugger Views (like Callstack View) among different modules. But it does not depends on debugger itself.

Main features:

  • One TreeView, or TreeTableView can be shared among different modules. Different modules can add different types of nodes to one view.
  • Hierarchy produced by one module can be changed by another one.
  • Allows to split UI and implementation to different modules.
  • Performance and memory consumption of this model should be much better than Node based models.
  • You do not need one instance of some class (Node) per one node visible in view. And you do not need one class per one node type.

How to use View Model API

Following example shows how to use viewmodel API to create simple files view.

Step 1.

In the first step we should create plain tree model (TreeModel).
public class TreeModelImpl implements TreeModel {
Tree Model Example 1
public Object getRoot () {
return ROOT;
}

public Object[] getChildren (Object parent, int from, int to) {
if (parent == ROOT)
return File.listRoots ();
return ((File) parent).listFiles ();
}

public boolean isLeaf (Object node) {
if (node == ROOT)
return false;
return ((File) node).isFile ();
}
}
And create a TreeView for this model:
    JComponent treeView = Models.createView (
Models.createCompoundModel (
Arrays.asList (new Model[] {
new TreeModelImpl (), // TreeModel
new ArrayList () // list of ColumnModel s
})
)
);

Step 2.

NodeModel implementation can define name, icon and tooltip for tree nodes produced by TreeModel.
public class NodeModelImpl implements NodeModel {Tree Model Example 2

public String getDisplayName (Object node) {
if (node == ROOT) return "Name";
String name = ((File) node).getName ();
if (name.length () < 1) return ((File) node).getAbsolutePath ();
return name;
}

public String getIconBase (Object node) {
if (node == ROOT) return "folder";
if (((File) node).isDirectory ()) return "folder";
return "file";
}

public String getShortDescription (Object node) {
if (node == ROOT) return "Name";
return ((File) node).getAbsolutePath ();
}
}

Step 3.

NodeActionsProvider defines set of Actions for each node, and default action..
public class NodeActionsProviderImpl implements NodeActionsProvider {

public Action[] getActions (final Object node) {
return new Action [] {
new AbstractAction ("Open") {
public void actionPerformed (ActionEvent e) {
performDefaultAction (node);
}
},
new AbstractAction ("Delete") {
public void actionPerformed (ActionEvent e) {
((File) node).delete ();
}
}
};
}

public void performDefaultAction (Object node) {
try {
JFrame f = new JFrame ("View");
f.getContentPane ().add (new JEditorPane (((File) node).toURL ()));
f.pack ();
f.show ();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Tree Model Example 3

Step 4.

TableModel and ColumnModel adds support for additional columns to tree view.
public class TableModelImpl implements TableModel {


public Object getValueAt (Object node, String columnID) {
try {
if (node == ROOT) return null;
if (columnID.equals ("sizeID")) {
if (((File) node).isDirectory ()) return "<dir>";
return "" + new FileInputStream ((File) node).getChannel ().size ();
}
} catch (Exception e) {
e.printStackTrace ();
}
return "";
}

public boolean isReadOnly (Object node, String columnID) {
return true;
}

public void setValueAt (Object node, String columnID, Object value) {
}
}
And initialization of columns looks like:
    ArrayList columns = new ArrayList ();Tree Model Example 4
columns.add (new ColumnModel () {
public String getID () { return "sizeID"; }
public String getDisplayName () { return "size"; }
public Class getType () { return String.class; }
});
JComponent treeTableView = Models.createView (
Models.createCompoundModel (
Arrays.asList (new Model[] {
new TreeModelImpl (), // TreeModel
new NodeModelImpl (), // NodeModel
new TableModelImpl (), // TableModel
new NodeActionsProviderImpl (), // NodeActionsProvider
columns // list of ColumnModel s
})
)
);




How to use Filters

We can use filters to modify content of tree table view created in our example.
  • TreeModelFilter: this filter can be used to hide fome files, to add some virtual filesystems, to add content of zip files to original tree, and so on.
  • NodeModelFilter: can be used to change names, icons or tooltips for existing files.
  • TableModelFilter: can be used to modify content of columns.
  • NodeActionsProviderFilter: can be used to add a new actions to pup-up menus, of to redefine default action.
All these actions can be done in some external module.

Java Source File NameTypeComment
ColumnModel.javaClass Defines model for one table view column.
ExtendedNodeModel.javaInterface Provides extension to NodeModel with cut/copy/paste and rename functionality, and also allowing to set icons with extension.
ExtendedNodeModelFilter.javaInterface Provides extension to NodeModelFilter , filters content of some existing ExtendedNodeModel .
Model.javaInterface Marker interface for all models.
ModelEvent.javaClass Encapsulates information describing changes to a model, and used to notify model listeners of the change.
ModelListener.javaInterface Notifies about changes in view model.
Models.javaClass Contains various utility methods for various models.
NodeActionsProvider.javaInterface Provides actions and default action for some type of objects.
NodeActionsProviderFilter.javaInterface Filters actions provided by some original NodeActionsProvider .
NodeModel.javaInterface Provides display name, icon and tooltip value for some type of objects.
NodeModelFilter.javaInterface Filters content of some existing NodeModel .
TableModel.javaInterface Adds support for columns to basic TreeModel .
TableModelFilter.javaInterface Allows to filter content of some existing TableModel .
TreeExpansionModel.javaInterface This model controlls expansion, collapsion of nodes in tree view, and defindes default expand state for all node in it.
TreeModel.javaInterface Defines data model for tree.
TreeModelFilter.javaInterface Filters content of some original tree of nodes (represented by TreeModel ).
UnknownTypeException.javaClass Used by various data models if data model is asked to resolve node of unknown type.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.