passing view reference into actions [message #330600] |
Tue, 05 August 2008 09:39 |
Eclipse User |
|
|
|
Originally posted by: marc.esher.comcast.net
Greetings all. I've got a view. it has a panel with a Tree in it. I have an
action that does stuff to the tree.
My question is simple: is it appropriate to pass the view reference into the
action so that the action can get the tree and operate on it? Or is there
some other, more preferred way?
Here's actual code I'm using.
From my view:
public void makeActions(){
....
toggleTreeItemsAction = new ToggleTreeItemsAction(this); // Pass the view
into the action's constructor
toggleTreeItemsAction.setText("Expand/Collapse All");
toggleTreeItemsAction.setToolTipText("Expand/Collapse all Tree Items
(Ctrl-+)");
toggleTreeItemsAction.setImageDescriptor(
ResourceManager.getImageDescriptor(ResourceManager.EXPANDCOL LAPSEALL)
);
.....
}
Then, the Action:
public final class ToggleTreeItemsAction extends Action {
private MyView view;
public ToggleTreeItemsAction(MyView view){
this.view = view;
}
public void run(){
//view.getTestsViewer() returns the tree in the view
if(view.getTestsViewer().getVisibleExpandedElements().length ==0){
view.getTestsViewer().expandAll();
}else{
view.getTestsViewer().collapseAll();
}
}
}
Thanks for any input!
marc
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03852 seconds