org.netbeans.core.spi.multiview

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 » core » org.netbeans.core.spi.multiview 
org.netbeans.core.spi.multiview
This SPI handles the lifecycle of a multiview component.

Creation

New instance of MultiView TopComponent can be created by calling MultiViewFactory.createMultiView The resulting TopComponent can be docked in arbitrary mode at your convenience. The factory method requires an array of {@link org.netbeans.core.spi.multiview.MultiViewDescription}s that describe the content of the view.
Each description in the View shall have a unique display name and preferredId. All the descriptions shall be lightweight classes, which create the actual visual components on demand in {@link org.netbeans.core.spi.multiview.MultiViewDescription#createElement}
The multiview component is cloneable by default. If any of your embedded elements cannot be cloned, or you don't intend to allow the users to clone the component, please use the appropriate factory method to create a non-cloneable instance.

Lifecycle

Once the multiview component is opened, the element for the default MultiViewDescription is created. Creation of other Elements is delayed to the moment these are required.
All created Elements get notified of changes in the lifecycle of the multiview component and their own. The notification callback method have the same name and similar semantics as the TopComponent ones.
  • When the element is shown for the first time, componentOpened() is called.
  • Everytime the element is selected in the component, componentShowing() is called on the new selection and componentHidden() on the one deselected.
  • When focusing the whole component, the currently selected element receives componentActivated(). When switching elements, the element loosing focus gets called componentDeactivated(), the one gaining focus is called componentActivated()
  • Whenever the multiview component gets notified of it's state changes (showing/hidden/activate/deactivated) by the window system, these are propagated to the currently selected element only.
  • For all elements that were created during the lifecycle of the component, componentClosed() is called when the component is about to be closed. Closing the component is special because the elements can be in non-deterministic state and a dataloss  situation is possible. Each created MultiViewElement is queried for it's state, the environment calls {@link org.netbeans.core.spi.multiview.MultiViewElement#canCloseElement}. The owner of the multiview component resolves the problems (silently or by asking the user) in {@link org.netbeans.core.spi.multiview.CloseOperationHandler#resolveCloseOperation}

Persistence

TopComponents decide about persistence based on the TopComponent.getPersistenceType()  return values. Possible values are:
  • TopComponent.PERSISTENCE_ALWAYS,
  • TopComponent.PERSISTENCE_NEVER,
  • TopComponent.PERSISTENCE_ONLY_OPENED.
The multiview component decides what it's return value is based on the values returned by MultiViewDescription.getPersistenceType() of all  embedded MultiViewDescriptions. 
  • When at least one of them returns PERSISTENCE_ALWAYS, it is returned by the TopComponent as well.
  • If at least one requires PERSISTENCE_ONLY_OPENED and none needs PERSISTENCE_ALWAYS, the TopComponent's state will be stored only when it's opened on IDE exit.
  • The multiview topcomponent is not persisted if all descriptions return PERSISTENCE_NEVER, or any of the descriptions are not serializable.
In other words, ALWAYS has higher priority than ONLY_OPENED and NEVER has the lowest priority of all.

When the multiview's TopComponent gets persisted, all of it's {@link org.netbeans.core.spi.multiview.MultiViewDescription} instances get serialized. Thus they need to implement Serializable.  Then for all MultiViewDescriptions that were opened (created their {@link org.netbeans.core.spi.multiview.MultiViewElement} instances) and don't declare PERSISTENCE_NEVER in their getPersistenceType() method, the MultiViewElement instance gets persisted as well.
Note: If any of the MultiViewDescription instances is not Serializable, the TopComponent will not get persisted. Please note that even if your MultiViewDescription returns PERSISTENCE_NEVER, it should be possible to serialize the Description instance. After restoration the deserialized instance will create a fresh MultiViewElement instance.

If you define your own {@link org.netbeans.core.spi.multiview.CloseOperationHandler} implementation for the multiview component, then you also ought to define it Serializable.
When restoring the multiview TopComponent, all the MultiViewDescriptions are deserialized, also all the stored MultiViewElements are deserialized.  These are kept and the createElement() method is not called on the matching MultiViewDescription.

Manipulating the multiview

MultiViewElements get a chance to manipulate the enclosed topcomponent. Each of them is passed an instance of {@link org.netbeans.core.spi.multiview.MultiViewElementCallback} on creation or deserialization. (Please don't serialize with your element's data, for performance reasons) It can be used during lifecycle of the element.
  • To request activation.
  • To request visibility.
  • To get the default topcomponent actions (shall be used to contruct the Element's getActions() array).
  • To change the title for the topcomponent.

If your MultiViewElement is a TopComponent or provides a TopComponent in getVisualRepresentation(), you can manipulate the activatedNodes of the whole multiview component by setting the appropriate nodes on your own TopComponent. when elements are switched, the activated nodes get updated as well according to the shown element.

Embedding editors

A typical MultiViewElement for embedding editor extends CloneableEditor and delegates some of the functionality to the multiview component.
The multiview component implements CloneableEditorSupport.Pane and the CloneableEditorSupport instance's createPane() method shall return the overall multiview component, rather than the MultiViewElement's component. In such case the opening the component shall be always done using the openCloneableTopComponent() call which will register the MultiView component as a holder of the editor pane for that CloneableEditorSupport instance. The multiview component will always delegate to the currently selected element when communication with the editor support classes. Keep that in mind when trying to manipulate the editor pane. Always switch to the editor's element first.

Please note: The multiview component is just a placeholder for the enclosed components. Any data related synchronizations are to be performed in the client code. This is especially important when multiple elements work over the same data/files.

At least the requestActive() and requestVisible() methods shall be overriden to delegate to the MultiViewElementCallback. Sample code:
       public void requestActive() {
            if (multiViewCallback != null) {
                multiViewCallback.requestActive();
            } else {
                super.requestActive();
            }
        }

Since TopComponent's lifecycle callback methods (componentOpened(), componentShowing() etc) are defined with protected scope, you will have to redefine the to be public to be in synch with the MultiViewElement interface signature. If the lifecycle within the multiview component differs from the default behaviour, additional handling goes here as well.

To create the editor's toolbar, the one provided by the NbDocument.CustomToobar is the obvious choice.

       public JComponent getToolbarRepresentation() {
            if (toolbar == null) {
                JEditorPane pane = getEditorPane();
                if (pane != null) {
                    Document doc = pane.getDocument();
                    if (doc instanceof NbDocument.CustomToolbar) {
                        toolbar = ((NbDocument.CustomToolbar)doc).createToolbar(pane);
                    }
                }
                if (toolbar == null) {
                    //attempt to create own toolbar?
                    toolbar = new JPanel();
                }
            }
            return toolbar;
        }

The owner/creator of the multiview component is responsible to handle proper closing of the editor via the {@link org.netbeans.core.spi.multiview.CloseOperationHandler#resolveCloseOperation} method implementation.

Java Source File NameTypeComment
AccessorImpl.javaClass
CloseOperationHandler.javaInterface Handles closing of the MultiView component globally.
CloseOperationState.javaClass instances of this class describe the MultiViewElement's state when the component is about to be closed.
MultiViewCloneableEditor.javaClass
MultiViewDescription.javaInterface Description of multi view element.
MultiViewElement.javaInterface View element for multi view, provides the UI components to the multiview component.
MultiViewElementCallback.javaClass Requester type of class, allowing implementors of MultiViewElement to send requests back to enclosing component and window system.
MultiViewFactory.javaClass Factory class for creating top components handling multi views.
SourceViewMarker.javaInterface A marker interface for MultiViewDescription instances that allows to identify them as containing source code.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.