Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Export as Image Action - Not enabled at StartUp
Export as Image Action - Not enabled at StartUp [message #1016274] Tue, 05 March 2013 19:03 Go to next message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
Hi,

I've got another problem this time Smile

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 #1016382 is a reply to message #1016274] Wed, 06 March 2013 10:14 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
This "action based" approach is deprecated from my point of view. You should implement that using the command framework.
Re: Export as Image Action - Not enabled at StartUp [message #1016385 is a reply to message #1016382] Wed, 06 March 2013 10:17 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
Thanks for your answer...

I'll try to use the command framework.

Is there any tutorial or implementation available, by any chance?
Where I could see how to achieve this?

Thanks,
Tim
Re: Export as Image Action - Not enabled at StartUp [message #1016387 is a reply to message #1016385] Wed, 06 March 2013 10:20 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
http://wiki.eclipse.org/Platform_Command_Framework
Re: Export as Image Action - Not enabled at StartUp [message #1016390 is a reply to message #1016387] Wed, 06 March 2013 10:24 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
Thanks a lot, I'll read it...
Re: Export as Image Action - Not enabled at StartUp [message #1017115 is a reply to message #1016390] Sat, 09 March 2013 13:43 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
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

Re: Export as Image Action - Not enabled at StartUp [message #1018807 is a reply to message #1017115] Thu, 14 March 2013 14:01 Go to previous messageGo to next message
Tim E. is currently offline Tim E.Friend
Messages: 56
Registered: November 2012
Member
Does nobody have an idea?
Or at least does know, that it is not possible in the way I'd like to have it?

Anything?
Re: Export as Image Action - Not enabled at StartUp [message #1022659 is a reply to message #1018807] Fri, 22 March 2013 09:55 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I've never need that. But I would like to know if it's possible as well. I've posted questions for this topic here and here.
Meanwhile you have to put the command in its own toolbar.
Re: Export as Image Action - Not enabled at StartUp [message #1088043 is a reply to message #1016274] Fri, 16 August 2013 13:47 Go to previous message
Alexandre Torres is currently offline Alexandre TorresFriend
Messages: 139
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.
Previous Topic:Figure cant shown in Diagram
Next Topic:Installation issues [Resolved]
Goto Forum:
  


Current Time: Tue Mar 19 04:11:39 GMT 2024

Powered by FUDForum. Page generated in 0.07379 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top