Export as Image Action - Not enabled at StartUp [message #1016274] |
Tue, 05 March 2013 19: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 19: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 13: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 10:59] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04493 seconds