Standard Navigator view has the "Link with Editor" action button. If this button checked, each click on Navigator view element should open (or activate) proper resource editor.
And this feature is implemented and works perfect in all cases, but...
In our application we have to implement another very useful feature: user should have an opportunity to drag any elements of Navigator view and drop it on the proper editor. In our specific case this is the Graphical Editor and drag and drop the similar element to opened editor have to create a proper "call" graphical node.
This requirement conflicts with "link" one.
It seems to be simple: add to the editor drop() method line that disables the "link" functionality, complete the drop operation and enable "link" backward. Unfortunately,
this solution does not work, the "drop" is too late! Certainly, user can uncheck link button temporarily, but he wants them both!
The solution is a little bit sophisticated: we have to enter to the drag operation.
This is a proper startDrag() method of CommonDragAdapter class, so we have to extent this class and override it's startDrag() method... But this class is final!
Then we have to take a code of this class and copy it to our own, let us say MyDragAdapter. We have to extend the CommonViewer class to override it's initDragAndDrop() method. But this new MyViewer class' createCommonActionGroup() method does not except this class instance as parameter, and so on... So this is final design:
1. Take the Eclipse CommonNavigatorManager, CommonNavigatorActionGroup, LinkEditorAction, CommonViewer and CommonNavigator classes code and copy it to your own classes.
2. Change proper fields, constructors and methods to get your own classes instances.
3. Take the CommonDragAdapter code to your own MyDragAdapter class.
Change startDrag()method:
4. Override initDragAndDrop() method in your MyViewer class:
5. Then, in NavigatorLinkHelper class add code below to the activateEditor() method:
6. And, finally, do not forget to add call setLinkEditorEnabled(true) in your editor' handleDrop() method!
Sunday, September 13, 2009
Add Actions according conditions
It is known how to add some actions to an Eclipse application. Also, it is known that to remove unwanted actions is more complicated task.In our case we had to add "Migrate to new version" action according the condition that application was not migrated to this new version yet.First of all, as usual, we've added the actionSet extension to the basic project MANIFEST.MF (plugin.xml) file:
Then, in the application starting code, when all application resources are loaded (for example, in application Navigator view), we try to read the application resource version property:
Where getApplication() method returns application instance and isMigrated() method returns true if application version property is higher or same as specified. In this case the “Migrate” action became invisible.
Then, in the application starting code, when all application resources are loaded (for example, in application Navigator view), we try to read the application resource version property:
Where getApplication() method returns application instance and isMigrated() method returns true if application version property is higher or same as specified. In this case the “Migrate” action became invisible.
Subscribe to:
Posts (Atom)