Actions added, but they are disabled [message #439029] |
Sun, 30 October 2005 21:02  |
Eclipse User |
|
|
|
Originally posted by: mailoz.163.com
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private IWorkbenchAction cutAction;
private IWorkbenchAction copyAction;
private IWorkbenchAction pasteAction;
...
protected void makeActions(final IWorkbenchWindow window) {
cutAction = ActionFactory.CUT.create(window);
register(cutAction);
copyAction = ActionFactory.COPY.create(window);
register(copyAction);
pasteAction = ActionFactory.PASTE.create(window);
register(pasteAction);
...
}
protected void fillMenuBar(IMenuManager menuBar) {
...
editmenu.add(cutAction);
editmenu.add(copyAction);
editmenu.add(pasteAction);
}
...
}
nothing else is done or changed in my project's codes
i just want to use the worbench actions such as COPY PASTE in my RCP
appliaction
after running the application, actions are all in the <edit> menu but
they're disabled
i also want to know the differences between register() and
registerGlobalAction()
jackaroo need your help, thanks :)
|
|
|
|
Re: Actions added, but they are disabled [message #448243 is a reply to message #439029] |
Wed, 19 April 2006 17:47   |
Eclipse User |
|
|
|
Hi,
CUT, COPY, PASTE are RetargetActions. You have to register a global
ActionHandler for every view you will suport those actions:
site.getActionBars().setGlobalActionHandler(ActionFactory.CO PY.getId(),
MyCopyAction);
With MyCopyAction implementing IWorkbenchAction like this one:
public class MyCopyAction extends Action implements ISelectionListener,
IWorkbenchAction {
IWorkbenchWindow _workbenchWindow;
public MyCopyAction(IWorkbenchWindow window) {
_workbenchWindow = window;
window.getSelectionService().addSelectionListener(this);
}
@Override
public void run() {
System.out.println("MyCopyAction");
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!selection.isEmpty()) {
setEnabled(true);
} else {
setEnabled(false);
}
}
public void dispose() {
_workbenchWindow.getSelectionService().removeSelectionListen er(this);
}
}
Notice that this registers itself to the workbench's selection service
to control it's enabled state (this is optional of course).
Regards
Peter
yongjian wrote:
> public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
> private IWorkbenchAction cutAction;
> private IWorkbenchAction copyAction;
> private IWorkbenchAction pasteAction;
> ...
> protected void makeActions(final IWorkbenchWindow window) {
> cutAction = ActionFactory.CUT.create(window);
> register(cutAction);
> copyAction = ActionFactory.COPY.create(window);
> register(copyAction);
> pasteAction = ActionFactory.PASTE.create(window);
> register(pasteAction);
> ...
> }
> protected void fillMenuBar(IMenuManager menuBar) {
> ... editmenu.add(cutAction);
> editmenu.add(copyAction);
> editmenu.add(pasteAction);
> }
> ...
> }
> nothing else is done or changed in my project's codes
> i just want to use the worbench actions such as COPY PASTE in my RCP
> appliaction
> after running the application, actions are all in the <edit> menu but
> they're disabled
> i also want to know the differences between register() and
> registerGlobalAction()
> jackaroo need your help, thanks :)
>
|
|
|
Re: Actions added, but they are disabled [message #448268 is a reply to message #448243] |
Thu, 20 April 2006 00:36  |
Eclipse User |
|
|
|
Originally posted by: malathi_r.rediffmail.com
Thanks Peter for your email.
I am sorry but I am not able to fix the problem.
Just to quickly review the issue I have at hand: I was able to display the
Cut/Copy/Paste etc options (using ActionFactory), but they are greyed out.
I want to enable them.
I am new to Java and hence would appreciate it if you could give me the
whole fix to the problem.
Appreciate your quick response.
Thanks in advance,
-m
My code is as follows:
------------------------------------------------------------ ------------
package timelineGUI;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import actions.DirFileChooseAction;
//import actions.MessagePopupAction;
import actions.OpenViewAction;
import views.LogDisplayView;
/**
* An action bar advisor is responsible for creating, adding, and
disposing of the
* actions added to a workbench window. Each window will be populated with
* new actions.
*/
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
// Actions - important to allocate these only in makeActions, and then
use them
// in the fill methods. This ensures that the actions aren't recreated
// when fillActionBars is called with FILL_PROXY.
//File
private IWorkbenchAction exitAction;
private IWorkbenchAction closeAction;
private IWorkbenchAction closeAllAction;
//Edit
private IWorkbenchAction undoAction;
private IWorkbenchAction redoAction;
private IWorkbenchAction cutAction;
private IWorkbenchAction copyAction;
private IWorkbenchAction pasteAction;
private IWorkbenchAction deleteAction;
private IWorkbenchAction selectAllAction;
private IWorkbenchAction findAction;
//Tool
//private IWorkbenchAction reportAction;
//Help
private IWorkbenchAction aboutAction;
private IWorkbenchAction newWindowAction;
//to be deleted later
private OpenViewAction openViewAction;
//private Action messagePopupAction;
private Action dirFileChooseAction;
// private Action reportGenAction;
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}
protected void makeActions(final IWorkbenchWindow window) {
// Creates the actions and registers them.
// Registering is needed to ensure that key bindings work.
// The corresponding commands keybindings are defined in the
plugin.xml file.
// Registering also provides automatic disposal of the actions when
// the window is closed.
//File
exitAction = ActionFactory.QUIT.create(window);
register(exitAction);
//Edit
undoAction = ActionFactory.UNDO.create(window);
register(undoAction);
redoAction = ActionFactory.REDO.create(window);
register(redoAction);
cutAction = ActionFactory.CUT.create(window);
register(cutAction);
copyAction = ActionFactory.COPY.create(window);
register(copyAction);
pasteAction = ActionFactory.PASTE.create(window);
register(pasteAction);
deleteAction = ActionFactory.DELETE.create(window);
register(deleteAction);
selectAllAction = ActionFactory.SELECT_ALL.create(window);
register(selectAllAction);
findAction = ActionFactory.FIND.create(window);
register(findAction);
closeAction = ActionFactory.CLOSE.create(window);
register(closeAction);
closeAllAction = ActionFactory.CLOSE_ALL.create(window);
register(closeAllAction);
deleteAction = ActionFactory.DELETE.create(window);
register(deleteAction);
//Tool
//Help
aboutAction = ActionFactory.ABOUT.create(window);
register(aboutAction);
newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(window);
register(newWindowAction);
openViewAction = new OpenViewAction(window, "Open Another Message
View", LogDisplayView.ID);
register(openViewAction);
//messagePopupAction = new MessagePopupAction("Open Message",
window);
//register(messagePopupAction);
dirFileChooseAction = new DirFileChooseAction("Choose log files",
window);
register(dirFileChooseAction);
//report generator is here
}
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager fileMenu = new MenuManager("&File",
IWorkbenchActionConstants.M_FILE);
MenuManager editMenu = new MenuManager("&Edit",
IWorkbenchActionConstants.M_EDIT);
// MenuManager toolMenu = new MenuManager("&Tool",
IWorkbenchActionConstants.M_TOOL);
MenuManager helpMenu = new MenuManager("&Help",
IWorkbenchActionConstants.M_HELP);
menuBar.add(fileMenu);
// Add a group marker indicating where action set menus will
appear.
menuBar.add(new
GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuBar.add(editMenu);
// menuBar.add(toolMenu);
menuBar.add(helpMenu);
// File
fileMenu.add(newWindowAction);
fileMenu.add(new Separator());
fileMenu.add(dirFileChooseAction);
fileMenu.add(closeAction);
fileMenu.add(closeAllAction);
fileMenu.add(new Separator());
fileMenu.add(new Separator());
fileMenu.add(exitAction);
//Edit
editMenu.add(undoAction);
editMenu.add(redoAction);
editMenu.add(new Separator());
editMenu.add(cutAction);
editMenu.add(copyAction);
editMenu.add(pasteAction);
editMenu.add(deleteAction);
editMenu.add(new Separator());
editMenu.add(selectAllAction);
editMenu.add(new Separator());
editMenu.add(findAction);
//Tool
// toolMenu.add(new Separator());
// Help
helpMenu.add(aboutAction);
}
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));
toolbar.add(closeAction);
toolbar.add(deleteAction);
//toolbar.add(openViewAction);
toolbar.add(dirFileChooseAction);
//toolbar.add(messagePopupAction);
}
}
------------------------------------------------------------ ---------
|
|
|
Powered by
FUDForum. Page generated in 0.03768 seconds