2012-07-17 55 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