How to implement “Save As” functionality for our Part

て烟熏妆下的殇ゞ 提交于 2019-12-11 20:09:19

问题


I'm creating E4 RCP application in that I have one part. I want to implement "Save As" functionality for my Part, as it is implemented for Editors (Like:Java file Editor).

Requirements:

  1. When user click on my part "Save As" option should be enable.
  2. When user click on "Save As" option my code should run so that I can do what I want.

So my question is for this what should I do, is I have to implement any extension point or any this else. ?


回答1:


In a pure e4 application there is no built in support for Save As so you will need to code this yourself.

To be consistent with the @Persist support for Save I would suggest doing this with an annotation, lets call it @PersistAs:

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface PersistAs
{
}

You will have to add a command definition for 'save as' along with a handler and menu items in the usual way.

The handler for Save As would look something like:

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) final MPart part)
{
  Object client = part.getObject();
  ContextInjectionFactory.invoke(client, PersistAs.class, part.getContext());
}

and in your part you would have:

@PersistAs
public void saveAs()
{
  // You save as code
}



回答2:


In Eclipse 3 compatibility mode you implement the doSaveAs and isSaveAsAllowed methods in your EditorPart.



来源:https://stackoverflow.com/questions/19535342/how-to-implement-save-as-functionality-for-our-part

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!