MultiPageEditorActionBarContributor delete action [message #237703] |
Tue, 07 August 2007 11:30 |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
Hi,
After reading a post about MultiPageEditorActionBarContributor I write
my own. Unfortunatly I could not get delete action working.
here is my code
any hints would be appreciate
regards
package com.odcgroup.page.ui.action;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.RedoRetargetAction;
import org.eclipse.gef.ui.actions.UndoRetargetAction;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
/**
* Represent the multi page editor contributor
*
* @author Alexandre Jaquet
*
*/
public class MultiPageUIActionBarContributor extends
MultiPageEditorActionBarContributor {
private List globalActionKeys = new ArrayList();
private List retargetActions = new ArrayList();
private ActionRegistry registry = new ActionRegistry();
/**
* Initialization
*/
public void init(IActionBars bars) {
buildActions();
declareGlobalActionKeys();
super.init(bars);
}
/**
* Builds the actions.
*
* @see org.eclipse.gef.ui.actions.ActionBarContributor#buildActions ()
*/
protected void buildActions() {
addRetargetAction(new UndoRetargetAction());
addRetargetAction(new RedoRetargetAction());
addRetargetAction(new AddWidgetToPaletteRetargetAction());
addRetargetAction(new CompileRetargetAction());
}
/**
* Adds the retarded actions.
*
* @param action
* The action to add
*/
protected void addRetargetAction(RetargetAction action) {
addAction(action);
retargetActions.add(action);
getPage().addPartListener(action);
addGlobalActionKey(action.getId());
}
/**
* Adds global action key.
*
* @param key
* The key to add
*/
protected void addGlobalActionKey(String key) {
globalActionKeys.add(key);
}
/**
* Adds to action registry an action.
*
* @param action
* The action to add
*/
protected void addAction(IAction action) {
getActionRegistry().registerAction(action);
}
/**
* Gets the registry.
*
* @return ActionRegistry
* The registry
*/
protected ActionRegistry getActionRegistry() {
return registry;
}
/**
* Declares the global action keys.
*
* @see
org.eclipse.gef.ui.actions.ActionBarContributor#declareGloba lActionKeys()
*/
protected void declareGlobalActionKeys() {
addGlobalActionKey(ActionFactory.UNDO.getId());
addGlobalActionKey(ActionFactory.REDO.getId());
addGlobalActionKey(ActionFactory.COPY.getId());
addGlobalActionKey(ActionFactory.PASTE.getId());
addGlobalActionKey(ActionFactory.DELETE.getId());
addGlobalActionKey(ActionFactory.SELECT_ALL.getId());
}
protected IAction getAction(String id) {
return getActionRegistry().getAction(id);
}
/**
* Adds the undo and redo items to the toolbar.
*
* @param tbm The IToolBarManager
* @see
org.eclipse.ui.part.EditorActionBarContributor#contributeToT oolBar(IToolBarManager)
*/
public void contributeToToolBar(IToolBarManager tbm) {
tbm.add(getAction(ActionFactory.UNDO.getId()));
tbm.add(getAction(ActionFactory.REDO.getId()));
tbm.add(getAction(AddWidgetToPaletteAction.ID));
tbm.add(getAction(CompileAction.ID));
}
/**
* Sets the page to active status.
*
* @param activeEditor
* The active editor
*/
public void setActivePage(IEditorPart activeEditor) {
ActionRegistry registry = (ActionRegistry)
activeEditor.getAdapter(ActionRegistry.class);
IActionBars bars = getActionBars();
for (int i = 0; i < globalActionKeys.size(); i++) {
String id = (String) globalActionKeys.get(i);
bars.setGlobalActionHandler(id, registry.getAction(id));
}
getActionBars().updateActionBars();
}
}
|
|
|
Re: MultiPageEditorActionBarContributor delete action [message #237710 is a reply to message #237703] |
Tue, 07 August 2007 12:13 |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
I also tryed to register my actions like this
ITextEditor editor = (activeEditor instanceof ITextEditor) ?
(ITextEditor) activeEditor: null;
bars.setGlobalActionHandler(
IWorkbenchActionConstants.DELETE,
getAction(editor, ITextEditorActionConstants.DELETE));
but same effect ...
|
|
|
Re: MultiPageEditorActionBarContributor delete action [message #237715 is a reply to message #237710] |
Tue, 07 August 2007 12:35 |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
I currrently read about the multipageeditoractionbar ... and I found the
following text
"The GEF ActionBarContributor is not able to provide support for
tracking page
changes in a multi-page editor. If you need this, you can either
implement the
functionality from
org.eclipse.ui.part.MultiPageEditorActionBarContributor or
inherit from this class. But if you inherit from this class, you don’t
have the action
handling support provided by the GEF ActionBarContributor."
Does that mean I could not use action in a
MultiPageEditorActionBarContributor ????
thx
|
|
|
Re: MultiPageEditorActionBarContributor delete action [message #237741 is a reply to message #237715] |
Tue, 07 August 2007 20:29 |
Eclipse User |
|
|
|
Originally posted by: sebutkoleth.gmail.com
You can achieve the functionality you require, albeit with a bit of work
i) Look at GEF ActionBarContributor and see what it does
ii) Implement your extended version of
org.eclipse.ui.part.MultiPageEditorActionBarContributor and add the
functionality of GEF ActionBarContributor to it.
iii)Use the setActivePage(IEditorPart) method in
MultiPageEditorActionBarContributor to activate and de-activate actions
according to user switching pages.
A bit tricky, but implemented easily and works solidly.
Sebu.
Alexandre Jaquet wrote:
> I currrently read about the multipageeditoractionbar ... and I found the
> following text
>
> "The GEF ActionBarContributor is not able to provide support for
> tracking page
> changes in a multi-page editor. If you need this, you can either
> implement the
> functionality from
> org.eclipse.ui.part.MultiPageEditorActionBarContributor or
> inherit from this class. But if you inherit from this class, you don’t
> have the action
> handling support provided by the GEF ActionBarContributor."
>
> Does that mean I could not use action in a
> MultiPageEditorActionBarContributor ????
>
> thx
|
|
|
Re: MultiPageEditorActionBarContributor delete action [message #237746 is a reply to message #237741] |
Wed, 08 August 2007 06:36 |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
Hi Sebu,
First thanks for responding, what I've missed in my current
implementation of the MultiPageEditorActionBarContributor
Regards
Alexandre
package com.odcgroup.page.ui.action;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.DeleteRetargetAction;
import org.eclipse.gef.ui.actions.RedoRetargetAction;
import org.eclipse.gef.ui.actions.UndoRetargetAction;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
/**
* Represent the multi page editor contributor
*
* @author Alexandre Jaquet
*
*/
public class MultiPageUIActionBarContributor extends
MultiPageEditorActionBarContributor {
private List globalActionKeys = new ArrayList();
private List retargetActions = new ArrayList();
private ActionRegistry registry = new ActionRegistry();
/**
* Initialization
*/
public void init(IActionBars bars) {
buildActions();
declareGlobalActionKeys();
super.init(bars);
}
/**
* Builds the actions.
*
* @see org.eclipse.gef.ui.actions.ActionBarContributor#buildActions ()
*/
protected void buildActions() {
addRetargetAction(new UndoRetargetAction());
addRetargetAction(new RedoRetargetAction());
addRetargetAction(new DeleteRetargetAction());
addRetargetAction(new AddWidgetToPaletteRetargetAction());
addRetargetAction(new CompileRetargetAction());
}
/**
* Adds the retarded actions.
*
* @param action
* The action to add
*/
protected void addRetargetAction(RetargetAction action) {
addAction(action);
retargetActions.add(action);
getPage().addPartListener(action);
addGlobalActionKey(action.getId());
}
/**
* Adds global action key.
*
* @param key
* The key to add
*/
protected void addGlobalActionKey(String key) {
globalActionKeys.add(key);
}
/**
* Adds to action registry an action.
*
* @param action
* The action to add
*/
protected void addAction(IAction action) {
getActionRegistry().registerAction(action);
}
/**
* Gets the registry.
*
* @return ActionRegistry
* The registry
*/
protected ActionRegistry getActionRegistry() {
return registry;
}
/**
* Declares the global action keys.
*
* @see
org.eclipse.gef.ui.actions.ActionBarContributor#declareGloba lActionKeys()
*/
protected void declareGlobalActionKeys() {
addGlobalActionKey(ActionFactory.UNDO.getId());
addGlobalActionKey(ActionFactory.REDO.getId());
addGlobalActionKey(ActionFactory.COPY.getId());
addGlobalActionKey(ActionFactory.PASTE.getId());
addGlobalActionKey(ActionFactory.SELECT_ALL.getId());
addGlobalActionKey(ActionFactory.DELETE.getId());
}
protected IAction getAction(String id) {
return getActionRegistry().getAction(id);
}
/**
* Adds the undo and redo items to the toolbar.
*
* @param tbm The IToolBarManager
* @see
org.eclipse.ui.part.EditorActionBarContributor#contributeToT oolBar(IToolBarManager)
*/
public void contributeToToolBar(IToolBarManager tbm) {
tbm.add(getAction(ActionFactory.UNDO.getId()));
tbm.add(getAction(ActionFactory.REDO.getId()));
tbm.add(getAction(AddWidgetToPaletteAction.ID));
tbm.add(getAction(CompileAction.ID));
}
/**
* Sets the page to active status.
*
* @param activeEditor
* The active editor
*/
public void setActivePage(IEditorPart activeEditor) {
ActionRegistry registry = (ActionRegistry)
activeEditor.getAdapter(ActionRegistry.class);
IActionBars bars = getActionBars();
for (int i = 0; i < globalActionKeys.size(); i++) {
String id = (String) globalActionKeys.get(i);
bars.setGlobalActionHandler(id, registry.getAction(id));
}
getActionBars().updateActionBars();
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03409 seconds