2012-07-17 56 views
0

Iam开发由视图和编辑器组成的RCP应用程序。我可以在编辑器中更改这些值并编辑一些参数的值。当一个值发生变化时,我需要使编辑器变脏,并且还想启用保存按钮。到现在为止,我还没有实现我的保存按钮。任何人都可以指导我如何使保存按钮启用以及如何编辑器中发生一些修改时使编辑器变脏。在RCP产品中保存选项

在此先感谢。任何帮助将不胜感激。

问候, 吉里什

+0

Kelibiano给出了更完整的答案。基本上,你有一个全局的isDirty布尔值,当你进行修改时,你设置为true。一旦isDirty布尔值为true,Eclipse GUI将启用保存按钮。 – 2012-07-18 14:59:58

回答

1

这里是表单编辑器逻辑的概述,跳它会帮你。

public class TestEditor extends FormEditor { 

    @Override 
    protected void addPages() { 
     // this method is called when the editor is being created 
     // to add the necessary pages 
     // page classes should be like following 
     // class TestEditorPage extends FormPage 
     try { 
      TestEditorPage pageTest = new TestEditorPage(this); 
      addPage(pageTest); 
     } catch (PartInitException e) { 
     } 
    } 

    @Override 
    public void doSave(IProgressMonitor monitor) { 
     // this method will be called on save action 
     // (or Ctrl + s shortcut) 
    } 

    @Override 
    public void doSaveAs() { 
     // this method will be called on save-as 
     //call (or Ctrl + Shift + s shortcut) 
    } 


    @Override 
    public boolean isSaveAsAllowed() { 
     // put here the call to the logic that 
     // check if the save is allowed 
     return true; 
    } 


    @Override 
    public boolean isDirty() { 
     // Here the call for the logic that 
     // defines if the editor is dirty or not 
     return true; 
    } 
} 
+0

嗨Kelibiano,感谢您的即时回复。我还没有实现保存按钮逻辑。你能帮我实现吗?如何在工具栏中显示保存按钮。我们可以使用org.eclipse.ui.file.save命令吗? – 2012-07-19 03:45:57

+0

首先在ApplicationWorkbenchWindowAdvisor-preWindowOpen()方法中添加configurer.setShowCoolBar(true);然后在ApplicationActionBarAdvisor-makeActions(...)方法中添加注册表(ActionFactory.SAVE.create(window));线。并将此xml添加到您的plugin.xml Kelibiano 2012-07-19 11:35:25