专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Java教程 » netbeans:NetBeans Selection Management Tutorial I—Using a TopComponent's Lookup »正文

netbeans:NetBeans Selection Management Tutorial I—Using a TopComponent's Lookup

来源: 发布时间:星期四, 2009年1月8日 浏览:11次 评论:0
  To follow this tutorial, you need the software and resources listed in the following table.

Software or Resource Version Required
NetBeans IDE version version 6.1 or

  version 6.0
Java Developer Kit (JDK) version 6 or

  version 5

  Optionally, for troubleshooting purposes, you can download the completed sample.

  Introduction to Selection  "Selection" is an important concept for any non-trivial application. NetBeans has two basic concepts of selection—the contents of the focused TopComponent's Lookup, and the focused TopComponent's activated Node(s). Here you will deal _disibledevent="NetBeans Selection Management Tutorial I—Using a TopComponent's Lookup" />

  Providing More Than One Object  This is all well and good for decoupling, but isn't providing this one object from your component a bit like having a Map that only contains one key and one value? The answer is, yes, it is like that. Where this technique becomes even more powerful is when you provide multiple objects from multiple APIs.

  As an example, it is very common in NetBeans to provide context sensitive actions. A in po is the built-in SaveAction that is part of NetBeans' Actions API. What this action actually does is, it simply listens for the presence of something called SaveCookie on the global context— the same way your viewer window listens for APIObject. If a SaveCookie appears (editors typically add one to their lookup when the content of the file is modied but not yet saved), the action becomes enabled, so the Save toolbar button and menu items become enabled. When the Save action is invoked, it calls SaveCookie.save, which in turn causes the SaveCookie to disappear, so the Save action then becomes disabled until a one appears.

  As you may have noticed, context sensitivity was one option in the New Action wizard. The actions currently generated by the wizard actually use a way of doing this that pre-dates Lookup; the Lookup-based way of doing such context sensitive actions is described in the developer FAQ.

  So the pattern in practice is to provide more than just a single object from your component's Lookup—dferent auxilliary components and dferent actions will be erested in dferent aspects of the object being edited. These aspects can be cleanly separated o erfaces which those auxilliary components and actions can depend on and listen for.

  Miscellaneous Things Worth Noticing  While not directly related to the topic of this tutorial, it's worth noticing that you open three MyEditor instances, and shut down and restart NetBeans, you end up with three MyEditor instances magically appearing on restart. By default, your editors are serialized to disk on shutdown and restored on restart.

  If you do not want this behavior, there are two other choices. Override the following method on MyEditor to cause editors never to be reopened on restart:

public getPersistenceType {
   PERSISTENCE_NEVER;
}
  If you want to persist the components that are open but discard those that have been closed, PERSISTENCE_ONLY_OPENED instead. The default (for backward compatibility reasons) is PERSISTENCE_ALWAYS, which is not appropriate for editor-style componenents—it means that even editors that have been closed are kept forever and reloaded on restart.

  Note, though, that part of what is serialized to disk is the location of your component in the window. So singleton TopComponentss such as the property sheet, or our viewer component, should use PERSISTENCE_ALWAYS - otherwise they are closed once by the user, the next time they are opened they will appear in the editor area instead of where they are supposed to be.

  Optional Clean-Up  The module template, by default, assumes you will want to use the layer.xml file to objects. In the of the My API module, it is actually not used. So a polite thing to do to get a slight improvement in startup time would be the following:

  Expand the Important Files node of the My API project

  Double click the Module Manest node

  Delete the following line from the manest:OpenIDE-Module-Layer: org/myorg/myapi/layer.xml

  Then delete the corresponding layer.xml file in org.myorg.myapi

0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: