From: http://blog.csdn.net/windy444/archive/2007/12/30/2005315.aspx
Translated by windy444.
Original article name: Building a common navigator framework (CNF) viewer Part I: defining the view part, Author: Michael elder, source:Http://scribbledideas.blogspot.com/(I have never been able to open it ).
Copyright first
The opinions and ideas expressed tables are my own and do not represent the intent, opinion, or official statement of any company or organization.
All postings by me to this site are copyrighted (c) by Michael D. elder, 2006 and made available under the terms of the eclipse Public License 1.0 with the constraint that any reuse of the content must contain this copyright statement.
For specific documentation on the extension points and APIs, you can find them in the eclipse platform help (help> help content, platform Plug-in developer's guide> reference> API reference | extension points reference, which involves Org. eclipse. UI. navigator. viewer, org. eclipse. UI. navigator. navigatorcontent. The related API package is org. Eclipse. UI. Navigator. If you want to know thisArticleMore details about the things mentioned in. These things can be used as a reference.
Okay. Where can I start? First, we will configure the plug-in that contains the view and add org. Eclipse. UI. navigator to the dependency (dependencies. Then, we use the org. Eclipse. UI. Views extension point to define a view part and use the org. Eclipse. UI. Navigator. commonnavigator class as the implementation class of the view part. This class provides some basic functions for our views. Then, we define the org. Eclipse. UI. Navigator. Viewer extension point and configure the view as a common navigator ). Finally, you can associate extension points and views by defining org. Eclipse. UI. Navigator. navigatorcontent extension points and binding (Org. Eclipse. UI. Navigator. Viewer/viewercontentbinding.
You can not only use Org. eclipse. UI. navigator. commonnavigator, which applies the architecture to the navigator. You can use Org. eclipse. UI. navigator. inavigatorcontentservice uses this architecture anywhere from the dialog box to the editor, or defines your own views and view parts. But here we will focus only on basic functions.
Basic settings
The general Navigator architecture is a new feature of eclipse 3.2. Therefore, you must install eclipse 3.2 at least. (Note: The following are things that people who have developed plug-ins know. I skipped here)
Define view Part
To define a view with the general navigator function, you must define an actual view part, which is the container of your view.
(Note: it is irrelevant to skip a section. Plug-in development beginners can refer to the development of basic view. After definition, the plugin file is as follows :)
Define view Configuration
Once the view part is defined. eclipse. UI. navigator. viewer makes some configuration extensions for our views. These extensions will tell the architecture some basic things, such as which view part of the general navigator is and what structure the pop-up menu is, whether to define object contributions and attributes that will affect the default view behavior.
(Translator's note: the process of defining the plugin. xml file will be included later)
Some Comments on the pop-up menu. The general Navigator architecture provides two ways for views to customize menus. The first method is to specify the popupmenuid of the viewer under the org. Eclipse. UI. Navigator. Viewer extension point to accept the default delimiter and the Group mark ID of the menu. The default value is recorded under the org. Eclipse. UI. Navigator. Viewer extension point, which is listed below for convenience.
"Group. New" separator = "true"
"Group. Goto"
"Group. Open" separator = "true"
"Group. openwith"
"Group. Edit" separator = "true"
"Group. Show" separator = "true"
"Group. reorganize"
"Group. Port"
"Group. Generate" separator = "true"
"Group. Search" separator = "true"
"Group. Build" separator = "true"
"Additions" separator = "true"
"Group. properties" separator = "true"
Alternatively, you can choose not to specify popupmenuid as a replacement. You can specify <popupmenu/> as a sub-element of the <viewer/> element. Here, you can define your own separator and group mark ID (menus can be added by users later ). If you want to bind the platform (resource, javatm) to provide content or actions, we recommend that you use the default group (listed above ).
Some Comments on Option. <Viewer/> the <options/> element under the element allows you to specify a string-based name = value pair. Here, some options are used by the infrastructure (in org. eclipse. UI. navigator. the examples in the viewer extension point document are documented), but you can use this mechanism to provide additional extensions for your own views or extension points. See the API for reading the attributes of the <viewer/> element in org. Eclipse. UI. Navigator. inavigatorviewerdescriptor. You can obtain the view descriptor through org. Eclipse. UI. Navigator. inavigatorcontentservice in the general navigator view.
The In in file after the viewerid is defined:
After the view is defined, we need to add content extensions and bind them to the view. I will provide more detailed information in the next article. As an example, we simply bind the default resource content (defined by the org. Eclipse. UI. Navigator. Resources plug-in) to the view.
(Note: Some basic operations are skipped. The plugin file after definition is as follows :)
Now you can start the workbench (run...> New eclipse application). Then you can see our view. However, we have not bound the view. Therefore, you still need to create a project in the resource navigator or package browser to see the project in our view. Later, we will add resource operations and filters, But now, let's take a look at the default behavior of this view. Currently, You can collapse all buttons (collapse all), link with editor buttons, filter buttons (and a "available filters" tag ), and an extension label ("available content ").
To bind a resource filter, add another contentextension element to the </shortdes> element and specify "org. Eclipse. UI. Navigator. Resources. Filters. *" as the identifier. This selects all the filters defined by org. Eclipse. UI. Navigator. Resources. Of course, you can refer to the plugin file org. Eclipse. UI. Navigator. Resources to select the identifier of the filter you want.
Select Run... again, and check that some resource filters appear in the filter dialog box.
Next, we will bind the default resource operations. To bind, add a vieweractionbinding element under the root of our extension point. (Note: Some operations are skipped. The plugin file after definition is as follows :)
Now, after starting the workbench, you can see the new, import, export, and refresh operations in the default empty view (right-click the blank area in the view. When you select an element in the view, the menu appears similar to that in the resource navigator.
(Note: skipping an operation once again does not affect your understanding of the Article)
Define Filter
The last thing we will do today is to use eclipse core expressions (core expressions) to define a filter for our views. The core expression architecture document is in the org. Eclipse. Core. Expressions plug-in. We will use the property testers defined by org. Eclipse. Core. Resources to test the nature of a specific project and then hide all projects without that nature.
(Note: Some operations are skipped. The plugin file after definition is as follows :)
You can also set the activebydefault attribute in the extension point to determine whether the filter is activated in the default configuration.
Finally, we need to define contentextension for our views as part of viewercontentbinding. Make sure that the ID of the newly created filter is used, or a general style (for example, "org. eclipse. UI. examples. navigator. filters. * ") to bind all filters of matching styles that we will define in the future. The final plug. XML is as follows:
Now, start the workbench for the last time. Create a new simple project and Java project. When "hide non-Java Projects" is activated, the simple project will be hidden.
(Note: The first part is finally translated)