Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在EclipseRCP中使编辑器变脏_Java_Eclipse_Swt_Rcp - Fatal编程技术网

Java 如何在EclipseRCP中使编辑器变脏

Java 如何在EclipseRCP中使编辑器变脏,java,eclipse,swt,rcp,Java,Eclipse,Swt,Rcp,我已经尝试了很多方法让一个编辑器在RCP中变脏,但都没用。我正在为我的编辑器实现IEditorPart。当我编辑编辑器的内容时,它不会被标记为脏,保存按钮保持禁用状态。但是,当我单击“查看”时,“保存”将变为活动状态。我正在调用firePropertyChange(),但当我调试程序并进入firePropertyChange()时,侦听器列表发现为空。任何人都有解决方案,请分享。谢谢。打电话 `public class ApplicationActionBarAdvisor extends Ac

我已经尝试了很多方法让一个编辑器在RCP中变脏,但都没用。我正在为我的编辑器实现IEditorPart。当我编辑编辑器的内容时,它不会被标记为脏,保存按钮保持禁用状态。但是,当我单击“查看”时,“保存”将变为活动状态。我正在调用firePropertyChange(),但当我调试程序并进入firePropertyChange()时,侦听器列表发现为空。任何人都有解决方案,请分享。谢谢。

打电话

`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;
    }

}`
将编辑器零件标记为脏零件


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

您是直接实现
IEditorPart
还是扩展
EditorPart
?@greg-449我正在扩展EditorPart@greg-449我正在调用firePropertyChange(),但当我调试程序并进入firePropertyChange()时侦听器列表为空。如果侦听器列表为空,则可能是未激发
org.eclipse.ui.internal.BaseSaveAction
中的部分侦听器。你是如何打开编辑器的?@greg-449我正在通过发出命令打开编辑器。检查代码我做了,但它不工作。当我在调试时进入fireProperty change时,我发现侦听器列表为空,并从那里返回。不再调用侦听器。这是所有编辑器使用的标准机制。你最好给我们看看代码。
firePropertyChange(PROP_DIRTY);