| Export as Image Action - Not enabled at StartUp [message #1016274] |
Tue, 05 March 2013 14:03  |
Tim E. Messages: 56 Registered: November 2012 |
Member |
|
|
Hi,
I've got another problem this time 
I implemented a "Export as Image" Action.
The code is as follows:
public class ExportAsImageAction extends EditorPartAction {
/**
* Id of this action
*/
public static final String EXPORT_AS_IMAGE_ID = "export as image";
private static final String DESCRIPTION = "Export as image";
/**
* Constructor
*
* @param editor
*/
public ExportAsImageAction(IEditorPart editor) {
super(editor);
setDescription(DESCRIPTION);
setImageDescriptor(ImageDescriptor.createFromImage(IconProvider.loadImage(IconProvider.EXPORT_ICON)));
setText("Export");
}
@Override
protected void init() {
super.init();
setId(EXPORT_AS_IMAGE_ID);
}
@Override
public void run() {
ImageSaveUtil.save(getEditorPart());
}
@Override
protected boolean calculateEnabled() {
return getEditorPart() != null;
}
@Override
public void setEditorPart(IEditorPart part) {
super.setEditorPart(part);
}
}
and in my ActionBarContributor I do the following:
private ExportAsImageAction exportAction;
@Override
protected void buildActions() {
...
exportAction = new ExportAsImageAction(null);
addAction(exportAction);
}
@Override
public void setActiveEditor(IEditorPart editor) {
// override this so that the exportAction instance can track the
// current editor
super.setActiveEditor(editor);
exportAction.setEditorPart(editor);
}
Unfortunately, the action is not enabled when I open my editor.
After I click on another Eclipse View or anything, and then click back to my
editor, the action is enabled.
Apparently, the IEditorPart is not set at startup and I cannot figure out
how to do it. I tried to pass "getPage().getActiveEditor()" instead of null
like this, but it did not help either
@Override
protected void buildActions() {
...
exportAction = new ExportAsImageAction(getPage().getActiveEditor());
addAction(exportAction);
}
Is there anything I can do about that?
Is this in general the right way to register this action?
Thanks in advance,
Tim
[Updated on: Tue, 05 March 2013 14:04] Report message to a moderator
|
|
|
|
|
|
|
| Re: Export as Image Action - Not enabled at StartUp [message #1017115 is a reply to message #1016390] |
Sat, 09 March 2013 08:43   |
Tim E. Messages: 56 Registered: November 2012 |
Member |
|
|
Sooo I've read through it and it looks promising.
But there is still one thing, I don't know how to achieve.
My Editor has a ActionBarContributor, which is only visible
if my editor is open.
If I understood it correctly, I can make my Command-Menu-Contribution
do the same via Eclipse Core Expressions.
But is there a way to put the command into my menu, contributed
by the ActionBarContributor?
So whenever somebody moves the redo/undo arrows and zooming option,
which are currently provided by the ActionBarContribution,
the command is also moved?
Thanks in advance,
Tim
[Updated on: Sun, 10 March 2013 06:59] Report message to a moderator
|
|
|
|
|
| Re: Export as Image Action - Not enabled at StartUp [message #1088043 is a reply to message #1016274] |
Fri, 16 August 2013 09:47  |
Alexandre Torres Messages: 135 Registered: July 2009 |
Senior Member |
|
|
Hi Jan,
I have the same problem porting my GEF action based commands to Kepler.
All that worked so well on eclipse 3 now just does not work anymore - and I don“t even know where should I start to make that thing work again! (and it is not listed on "what is new about GEF" either...just another "surprise feature").
Does ActionBarContributor can work together with this "new" Command interface?
Or should I just forget about GEF integration completely?
If actions are deprecated, why GEF uses actions?
Thanks for this topic, is the only one I found in the subject.
|
|
|
Powered by
FUDForum. Page generated in 0.06882 seconds