Don't understand Eclipse - MVC, yet [message #677823] |
Thu, 09 June 2011 09:40  |
Eclipse User |
|
|
|
Hello together,
I don't really get into it how to correctly interact between views/editors etc. and the corresponding controllers or handlers.
In my case I have a TreeViewer (view) which shows the open projects. With a context menu on a selected project - the command "deleProject" can be triggered that deletes the selected project, with the help of the corresponding "deleteProjectHandler" (controller !?).
Now I don't really know how to update the view, namely the treeviewer. I couldn't find a adequate listener that can be used by the view.
Summary:
View --> Controller: with the use of commands
Controller --> View: ??
In my opinion the "deleteProjectHandler" need to get the instance of the "treeViewer" and triggering the refresh method. But what is the best way to get the corresponding instance of the view?
Its really hard to get into the eclipse framework as a eclipse framework newbie. The documentation is really indifferent with a wild mixture of conecpts like commands and actions. And even the snippets or examples are still using actions even though they are deprecated. Figuring out simple things like context menus (e.g. with the use of commands and menuContributions) need way to much time to get into it. My last ten days were just searching, searching, searching the internet and try and error. Making it hard for newbies is not a good thing for frameworks in general.
[Updated on: Thu, 09 June 2011 09:43] by Moderator
|
|
|
Re: Don't understand Eclipse - MVC, yet [message #680747 is a reply to message #677823] |
Thu, 09 June 2011 12:12  |
Eclipse User |
|
|
|
Right now I've done it in this way:
I added a "removeObject(Object)" and a "refresh()" method to my View which contains the TreeViewer. They are just triggering the same methods in the TreeViewer object:
public void removeObject(Object elementsOrTreePaths) {
this.viewer.remove(elementsOrTreePaths);
}
public void refresh() {
this.viewer.refresh();
}
The command "Delete Project", within the context menu of the TreeViewer, triggers the execute() method in the DeleteProjectHandler Class:
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if(selection instanceof IStructuredSelection) {
if (((IStructuredSelection)selection).getFirstElement() instanceof IProject) {
IProject project = (IProject)((IStructuredSelection)selection).getFirstElement();
try {
project.delete(true, false, null);
IViewPart viewpart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("myTreeView");
if (viewpart instanceof MyTreeViewClass) {
((MyTreeViewClass)viewpart).removeObject(project);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
return null;
}
Basically the DeleteProjectHandler searches for the specific view which need to updated, and is then triggering the views refresh() resp. the deleteObject() methods.
IViewPart viewpart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("myTreeView");
if (viewpart instanceof MyTreeViewClass) {
((MyTreeViewClass)viewpart).removeObject(project);
}
So:
View --> Handler: via Command
Handler --> View: via search View and then triggering the objects methods.
Is this a good way? It seems not that cool to me. But I really have no clue how to do it in another way, as I already mentioned, I don't know how to do it via an EventListener.
Thanks in advance for your help
Bjoern
|
|
|
Powered by
FUDForum. Page generated in 0.76784 seconds