Saturday, March 24, 2012

Adding functionality in Sample View - Show all projects in Sample View


How to show all resources in view?
To show all projects and all files / folders in tree structure, IResourceChangeListener interface need to be implemented in View class.
How to add actions / menu in Sample View?
1. To add actions and menus in View, org.eclipse.ui.viewActions extension need to be added.
Add viewActions extension
2. After adding this extension, add new "viewContribution" with the unique id* value. The targetID* value should be same as Sample view id value.
Add "viewContribution" under viewActions extension.
3. Adding Menu item - To create a new menu item, R-click on viewContribution and select "menu" option like below screenshot.
Add "menu" in View
4. Provide the id* and label* for this menu item like below screen-shot.
Properties of Sample Menu item.
5. After succefully create the menu item, create new group under this menu. R-click on "menu" and select "groupMarker" option. Provide the group name like: sampleGroupMarker.
Add sampleGroupMarker
6. Create another menu item (Collapse Menu), and provide the value of id*, label* and path like below screenshot.
Add another "menu" item
7. Create another group for this collapse menu and provide the name for it like: collapseGroupmarker.
Add groupMarker under Collapse Menu item
8. Create an Action : To create a new "action", R-click on "viewContribution" and select "action". Provide the all properties like below screenshot.
Note: Need to add icons file for this action in /icons folder.
Add "action" under viewContribution extension.
id*: SampleCode.collapseAction
class*: samplecode.source.view.CollapseAllActionDelegate
menubarPath: SampleCode.sampleMenu/SampleCode.collapseMenu/collapseGroupmarker

9. click on the class* link and a "New Java Class" dialog box will be opened. Click on "Finish" button. Java class will be created.
Create new java class dialog box
10. Run the project, one action button will be shown in Sample View toolbar like below screenshot and also Menu will be created for this Collapse All action.
Sample View
11. Adding functionality on Sample View for display all the projects from workspace:
Dependencies: org.eclipse.ui.ide
Open the SampleView.java file and modify the file with this code snippet:

A. samplecode.source.SampleView.java


Create below mentioned three java files in samplecode.source.view package and modify these three files with the below mentioned code snippet.

B. samplecode.source.view.SampleContentProvider.java


C. samplecode.source.view.SampleLabelProvider.java


D. samplecode.source.view.SampleViewCellModifier.java


12 .Run the project and if any projects are in workspace, it will be visible in Sample View in Tree structure like below screenshot.
Sample View display workspace project(s)
Attachment: To Download this project click here

1 comment: