简体   繁体   中英

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

}`

I have tried many ways to make an editor dirty in RCP but non worked. I am implementing IEditorPart for my editor. When I edit the contents of editor it does not get marked dirty and save button remains disable. But when I click on view then Save become active. I'm calling firePropertyChange() but when I debug my program and step into firePropertyChange() the list of listeners found null. Anyone have the solution please do share. Thanks.

Call

firePropertyChange(PROP_DIRTY);

to mark the editor part as dirty.

Your editor's isDirty() method will be called at various points to check the dirty state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM