[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.gef] Re: implementing cut/copy/paste

Well lets go over all the steps.

1. Create Cut/Copy/Paste commands based on org.eclipse.gef.commands.Command

2. Create Cut/Copy actions based on org.eclipse.gef.ui.actions.SelectionAction
paste probably wont be a selection action since its not based on selection
be sure to properly override calculateEnabled()
be sure in the init method or some other appropriate place to
setID(ActionFactory.PASTE.getId());




3. Override createActions of GraphicalEditor
NOTE: these are not retarget actions but the ones you created in step 2

super.createActions();
action = new CopyAction((IworkbenchPart)this);
registry.registerAction(action)
getSelectionActions().add(action.getId());


4. in your editorContributor override buildActions and add retarget actions here


//first create and register the retarget action
IWorkbenchWindow = getPage().getWorkbenchWindow();
addRetargetAction((RetargetAction)ActionFactory.COPY.create(iww));

//then add it to a menu or toolbar
override ContributeToToolBar(IToolBarManager tbm) or wherever you want to add the actions


tbm.add(getAction(ActionFactory.COPY.getId()));

or contributeToMenu

Only way off hand I know how to use the editor contributor is by telling the xml file to use it if you extend the point org.eclipse.ui.editors add

contributorClass = "MyContributor"

Wish I could be more help with a more direct route, but I think you got this part fixed anyway since you are actually seeing the buttons and menuitems.







Jesper Eskilson wrote:
Randy Hudson wrote:

The registry should hold onto actions maintained by the Editor instance.
RetargetActions should only be created by the ActionBarContributor, not each
editor instance.


The purpose of retarget actions is to map a single ActionBarContributor to
multiple editor instances within a given WorkbenchWindow. I think actionbar
contributors were designed as 1-per-window-per-editor-type to reduce flicker
and repainting when changing between multiple java CU editors. It also
reduces the number of native widgets created.


Ok, thanks. The mist is clearing a little now.

The problem was (I think) that I added the retarget-actions to the editors registry instead of using addRetargetAction().

So, now I've changed my actionbar-contributor to do the following:

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
addRetargetAction((RetargetAction) ActionFactory.CUT.create(window));
addRetargetAction((RetargetAction) ActionFactory.COPY.create(window));
addRetargetAction((RetargetAction) ActionFactory.PASTE.create(window));


but now I get a ClassCastException() in

org.eclipse.ui.actions.RetargetAction.propagateChange(RetargetAction.java:195)


Apparently this mist didn't clear enough. :-)

/Jesper


--
Respectfully,


CL Gilbert

"Verily, verily, I say unto you, He that entereth not by the door() into the sheepfold{}, but climbeth up some other *way, the same is a thief and a robber."

GnuPG Key Fingerprint:
82A6 8893 C2A1 F64E A9AD  19AE 55B2 4CD7 80D2 0A2D

For a free Java interface to Freechess.org see http://www.rigidsoftware.com/Chess/chess.html