![](/img/trans.png)
[英]In Eclipse RCP, how do I disable a save toolbar button according to the “dirty” property in editor
[英]How can I make an editor dirty in eclipse RCP
`public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private IWorkbenchAction saveAction;
private IWorkbenchAction saveAllAction;
// Actions - important to allocate these only in makeActions, and then use
// them
// in the fill methods. This ensures that the actions aren't recreated
// when fillActionBars is called with FILL_PROXY.
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}
protected void makeActions(final IWorkbenchWindow window) {
saveAction = ActionFactory.SAVE.create(window);
register(saveAction);
saveAllAction = ActionFactory.SAVE_ALL.create(window);
register(saveAllAction);
}
// protected void fillMenuBar(IMenuManager menuBar) {
// }
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
saveToolbar.add(saveAction);
saveToolbar.add(saveAllAction);
coolBar.add(new ToolBarContributionItem(saveToolbar, "save"));
}
package rcp_application;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
public class CallEditor extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
BottomView view = (BottomView)page.findView(BottomView.ID);
ISelection selection = view.getSite().getSelectionProvider()
.getSelection();
if (selection != null && selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj != null) {
Person person = (Person) obj;
MyEditorInput input = new MyEditorInput(person);
try {
page.openEditor(input, MyEditor.ID);
} catch (PartInitException e) {
throw new RuntimeException(e);
}
}
}
return null;
}
}`
我嘗試了多種方法使編輯器在RCP中變臟,但無效。 我正在為我的編輯器實現IEditorPart。 當我編輯編輯器的內容時,它不會被標記為臟,並且保存按鈕保持禁用狀態。 但是,當我單擊視圖時,保存將變為活動狀態。 我正在調用firePropertyChange(),但是當我調試程序並進入firePropertyChange()時,偵聽器列表為空。 任何人都有解決方案,請分享。 謝謝。
呼叫
firePropertyChange(PROP_DIRTY);
將編輯器部件標記為臟。
您的編輯器的isDirty()
方法將在不同位置被調用以檢查臟狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.