Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to use "ToggleSnapToGeometryAction"
How to use "ToggleSnapToGeometryAction" [message #190649] Fri, 05 August 2005 13:28 Go to next message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Hi,

I want to use the "ToggleSnapToGeometryAction" in my ActionBarContributor
...but the ToggleSnapToGeometryAction needs a 'GraphicalViewer' in the constructor.

I don't know how to retrieve this in my ActionBarContributor.

Is there a common way to enabel/disable the Grid in my GEF Editor?


Greeetings


Andreas
Re: How to use "ToggleSnapToGeometryAction" [message #190660 is a reply to message #190649] Fri, 05 August 2005 14:07 Go to previous messageGo to next message
Roger Villars is currently offline Roger VillarsFriend
Messages: 57
Registered: July 2009
Member
Hi Andreas!

I did it this way!
Create the Action in your editor class in the configureGraphicalViewer
method:

protected void configureGraphicalViewer()
{
super.configureGraphicalViewer();
IAction action = new ToggleSnapToGeometryAction(getGraphicalViewer());
getActionRegistry.registerAction(action);
getSelectionActions().add(action.getId());
}

Create a ToggleSnapToGeometryRetargetAction:

public class ToggleSnapToGeometryRetargetAction extends RetargetAction
{
public ToggleSnapToGeometryRetargetAction()
{
super(null, null, IAction.AS_CHECK_BOX);
setText("Snap to geometry");
setId(GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY);
setToolTipText("Snap to geometry");
setActionDefinitionId(GEFActionConstants.TOGGLE_SNAP_TO_GEOM ETRY);
}
}

In your ActionBarContributor class:

protected void buildActions()
{
addRetargetAction(new SnapToGeometryRetargetAction());
}

public void contributeToMenu(IMenuManager menubar)
{
super.contributeToMenu(menubar);
MenuManager myMenu = new MenuManager("My Menu");
myMenu.add(getAction(GEFActionConstants.TOGGLE_SNAP_TO_GEOME TRY));
menubar.insertAfter(IWorkbenchActionConstants.M_WINDOW, myMenu);
}

If you use a MultiPageEditor things are a bit more complicate.
Hope this helps.
Roger

"FreeGroup" <a.herz@FreeGroup.de> schrieb im Newsbeitrag
news:dcvpo5$7aj$1@news.eclipse.org...
> Hi,
>
> I want to use the "ToggleSnapToGeometryAction" in my ActionBarContributor
> ..but the ToggleSnapToGeometryAction needs a 'GraphicalViewer' in the
> constructor.
>
> I don't know how to retrieve this in my ActionBarContributor.
>
> Is there a common way to enabel/disable the Grid in my GEF Editor?
>
>
> Greeetings
>
>
> Andreas
Re: How to use "ToggleSnapToGeometryAction" [message #190668 is a reply to message #190660] Fri, 05 August 2005 15:34 Go to previous message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Hi,

thanks a lot!!!

I have changed the RetargetAction constructor to:

public class ToggleSnapToGeometryRetargetAction extends RetargetAction
{
public ToggleSnapToGeometryRetargetAction()
{
super(GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY,
GEFMessages.ToggleSnapToGeometry_Label, IAction.AS_CHECK_BOX);
setToolTipText(GEFMessages.ToggleSnapToGeometry_Label);
setImageDescriptor(JacobDesigner.getImageDescriptor("alignGeometry.png "));
}
}


and it works fine. I have add an image for the toolbar too.


Thanks!!

Andreas


Roger Villars wrote:
> Hi Andreas!
>
> I did it this way!
> Create the Action in your editor class in the configureGraphicalViewer
> method:
>
> protected void configureGraphicalViewer()
> {
> super.configureGraphicalViewer();
> IAction action = new ToggleSnapToGeometryAction(getGraphicalViewer());
> getActionRegistry.registerAction(action);
> getSelectionActions().add(action.getId());
> }
>
> Create a ToggleSnapToGeometryRetargetAction:
>
> public class ToggleSnapToGeometryRetargetAction extends RetargetAction
> {
> public ToggleSnapToGeometryRetargetAction()
> {
> super(null, null, IAction.AS_CHECK_BOX);
> setText("Snap to geometry");
> setId(GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY);
> setToolTipText("Snap to geometry");
> setActionDefinitionId(GEFActionConstants.TOGGLE_SNAP_TO_GEOM ETRY);
> }
> }
>
> In your ActionBarContributor class:
>
> protected void buildActions()
> {
> addRetargetAction(new SnapToGeometryRetargetAction());
> }
>
> public void contributeToMenu(IMenuManager menubar)
> {
> super.contributeToMenu(menubar);
> MenuManager myMenu = new MenuManager("My Menu");
> myMenu.add(getAction(GEFActionConstants.TOGGLE_SNAP_TO_GEOME TRY));
> menubar.insertAfter(IWorkbenchActionConstants.M_WINDOW, myMenu);
> }
>
> If you use a MultiPageEditor things are a bit more complicate.
> Hope this helps.
> Roger
>
> "FreeGroup" <a.herz@FreeGroup.de> schrieb im Newsbeitrag
> news:dcvpo5$7aj$1@news.eclipse.org...
>
>>Hi,
>>
>>I want to use the "ToggleSnapToGeometryAction" in my ActionBarContributor
>>..but the ToggleSnapToGeometryAction needs a 'GraphicalViewer' in the
>>constructor.
>>
>>I don't know how to retrieve this in my ActionBarContributor.
>>
>>Is there a common way to enabel/disable the Grid in my GEF Editor?
>>
>>
>>Greeetings
>>
>>
>> Andreas
>
>
>
Previous Topic:REQ_DELETE_DEPENDANT
Next Topic:Adding BreadCrumbs to Palette Viewer
Goto Forum:
  


Current Time: Thu Dec 26 20:36:14 GMT 2024

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

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

Back to the top