java - 如何在 eclipse RCP 中弄脏编辑器

标签 java eclipse swt 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。当我编辑编辑器的内容时​​,它不会被标记为脏,并且保存按钮仍然处于禁用状态。但是当我单击“查看”时,“保存”就会变为 Activity 状态。我正在调用 firePropertyChange(),但是当我调试程序并进入 firePropertyChange() 时,监听器列表发现为空。谁有解决方案请分享。谢谢。

最佳答案

通话

firePropertyChange(PROP_DIRTY);

将编辑器部分标记为脏。

您的编辑器的 isDirty() 方法将在不同的点被调用来检查脏状态。

关于java - 如何在 eclipse RCP 中弄脏编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25531920/

相关文章:

java - 使用java native 接口(interface)获取Windows当前用户

java 监视器 - 队列

java - 如何远程调试在同一容器中运行的两个具有相同代码库但具有不同配置文件的 Spring Boot 应用程序?

java - 无法将 MS-Excel 列粘贴到 SWT 的文本小部件中

java - 如何覆盖 Java SWT FileDialog 类的打开按钮

java - Java中耗时不一致

java - 为什么 Intellij IDEA 不接收我的 java JDK

java - 在我制作的 Java 程序中创建文件之前如何创建/修改文件的内容?

eclipse - eclipse Mars 中安装插件WebSphere Application Server V7 出错

java - 如何保存用户在下拉列表中键入的值并将其用于 `org.eclipse.swt.widgets` 的可编辑组合?