2013-06-27 46 views
0

我正在編輯基於GEF(圖形編輯框架)並使用Eclipse屬性視圖。我的問題是,當我在此視圖中更改屬性時,編輯器不知道此更改,並且不建議我保存。 我該如何解決這個問題?GEF編輯器和選項卡式屬性視圖

+0

你可以使用其他編輯器手動編輯文件嗎?檢查權限以查看是否可以編輯該文件並使用其他編輯器保存該文件。這可能是一個權限問題。 –

+0

實際上,當我在屬性視圖中編輯屬性時,我的模型知道這個變化。例如,組件的名稱可以被編輯,但編輯器並不建議我保存。 –

+0

你真的編碼了編輯器嗎? 編輯器是否允許您在更改不屬於屬性視圖時保存? – user1125516

回答

0

當您在編輯器的命令堆棧外執行編輯時,通常會發生這種情況。實際上,髒標誌(您提到的保存建議)由綁定到它自己的GEF圖形編輯器的org.eclipse.gef.commands.CommandStack控制。

假設你是通過擴展AdvancedPropertySection實現屬性表編輯器,你必須得到來自IWorkbenchPartCommandStack適配器,並將其保存以備後用:

public class GEFAdvancedPropertySection extends AdvancedPropertySection { 
    public void setInput(IWorkbenchPart part, ISelection selection) { 
     CommandStack commandStack = (CommandStack) part.getAdapter(CommandStack.class); 
     if (cs != null) 
      page.setRootEntry(new GEFPropertySheetEntry(commandStack)); 
     super.setInput(part, selection); 
    } 
} 

在你PropertySheetEntry實現(實際上是在GEFPropertySheetEntry上面的例子)你必須通過org.eclipse.gef.commands.Command正在執行模型更改CommandStack

public class GEFPropertySheetEntry extends PropertySheetEntry { 

    protected CommandStack commandStack; 

    public GEFPropertySheetEntry(CommandStack commandStack) { 
     this.commandStack = commandStack; 
    } 

    protected void valueChanged(PropertySheetEntry entry) { 
     GEFCommand command = new GEFCommand(); 

     // here you have to configure the command 
     // such that it can perform 
     // the expected model modifications 

     commandStack.execute(command); 
    } 
} 

這個技巧是通過使用特定的GEFCommand完成的,它通過CommandStack執行模型修改,該模型修改綁定到原始編輯器並將其標記爲污點。

+0

非常感謝! –

+0

不客氣!如果您發現答案有用,您能否將其標記爲正確? –