Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » passing view reference into actions
passing view reference into actions [message #330600] Tue, 05 August 2008 09:39 Go to next message
Eclipse UserFriend
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
Re: passing view reference into actions [message #330861 is a reply to message #330600] Thu, 14 August 2008 17:35 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

That is one of the most common ways to use your own actions, simply
create them in the view part itself.

If your actions are limited to the view part and you don't need
keybindings, that should work fine.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: passing view reference into actions [message #331004 is a reply to message #330861] Thu, 21 August 2008 01:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marc.esher.comcast.net

thanks for responding, Paul.

If I'm not creating actions in the view itself as inner classes, is there a
preferred way for accessing the view in the manner I've described?

thanks!

marc



"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:g81qln$shn$2@build.eclipse.org...
> That is one of the most common ways to use your own actions, simply create
> them in the view part itself.
>
> If your actions are limited to the view part and you don't need
> keybindings, that should work fine.
>
> PW
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
Re: passing view reference into actions [message #331153 is a reply to message #331004] Tue, 26 August 2008 18:21 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Marc E wrote:
> thanks for responding, Paul.
>
> If I'm not creating actions in the view itself as inner classes, is
> there a preferred way for accessing the view in the manner I've described?
>

For commands and implementations of AbstractHandler, the currently
active part can be retrieved using HandlerUtil static methods.

Then you can check to see if it is your IViewPart.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: passing view reference into actions [message #331155 is a reply to message #331153] Tue, 26 August 2008 21:35 Go to previous message
Eclipse UserFriend
Originally posted by: marc.esher.comcast.net

Cool. thanks Paul.

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:g91hss$3oq$2@build.eclipse.org...
> Marc E wrote:
>> thanks for responding, Paul.
>>
>> If I'm not creating actions in the view itself as inner classes, is there
>> a preferred way for accessing the view in the manner I've described?
>>
>
> For commands and implementations of AbstractHandler, the currently active
> part can be retrieved using HandlerUtil static methods.
>
> Then you can check to see if it is your IViewPart.
>
> PW
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
Previous Topic:FocusListener on Section
Next Topic:Using Saxon 6.5 in Eclipse 3.4
Goto Forum:
  


Current Time: Mon Jul 22 05:13:58 GMT 2024

Powered by FUDForum. Page generated in 0.03730 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top