Saving a modified file in the plugin

Help
2011-05-30
2013-04-06
  • Kristjan Veskimäe

    Hi!

    I am playing with ClearCase plugin source code and I am trying to save a modified file. I found from

    net.sourceforge.eclipseccase.ui.actions.ClearCaseAction.saveModifiedResources(..)

    a way to do that, but I cannot get it working (there are open dirty editors looped there, which is possibly causing trouble for me). I would like to ask where is the implementation code for saving a modified file?

    Kristjan

     
  • Mikael Petterson

    Hi,

    Are you also developing a plugin? What kind?

    Here is the code for saving modified resources:

    IRunnableWithProgress createSaveModifiedResourcesRunnable(final IFile dirtyFiles) {
    return new IRunnableWithProgress() {
    public void run(final IProgressMonitor pm) {
    IEditorPart editorsToSave = getDirtyEditors(getShell());
    pm.beginTask("saving modified resources", editorsToSave.length); //$NON-NLS-1$
    try {
    List dirtyFilesList = Arrays.asList(dirtyFiles);
    for (int i = 0; i < editorsToSave.length; i++) {
    if (editorsToSave_.getEditorInput() instanceof IFileEditorInput) {
    IFile dirtyFile = ((IFileEditorInput) editorsToSave.getEditorInput()).getFile();
    if (dirtyFilesList.contains((dirtyFile))) {
    editorsToSave.doSave(new SubProgressMonitor(pm, 1));
    }
    }
    pm.worked(1);
    }
    } finally {
    pm.done();
    }
    }
    };
    }

    //mike_

     
  • Kristjan Veskimäe

    Hi again!

    No, I am not developing a plugin, I am actually trying to solve a problem with saving compare results in ClearCase plugin.
    Maybe we can override method saveChanges in net.sourceforge.eclipseccase.ui.compare.VersionCompareInput from its superclass org.eclipse.compare.CompareEditorInput with the following:
    Here is the

        public void saveChanges(IProgressMonitor pm) throws CoreException {
            super.saveChanges(pm);
            if (!(rightElement instanceof ResourceNode && rightElement instanceof BufferedContent)) {
                return;
            }
            ResourceNode rn = (ResourceNode)rightElement;
            BufferedContent bc = (BufferedContent)rightElement;
            IResource resource= rn.getResource();
            if (resource instanceof IFile) {
                byte[] bytes= bc.getContent();
                ByteArrayInputStream is= new ByteArrayInputStream(bytes);
                try {
                    IFile file= (IFile) resource;
                    if (file.exists()) {
                        file.setContents(is, false, true, pm);
                    }else {
                        file.create(is, false, pm);
                    }
                } finally {
                    if (is != null)
                        try {
                            is.close();
                            setDirty(false);
                        } catch(IOException ex) {
                            // Ignored
                        }
                        resource.getParent().refreshLocal(IResource.DEPTH_INFINITE, pm);
                }
            }
        }
    

    This is the code used by another implementation of compare editor input ResourceCompareInput that I think is used e.g. by the Eclipse SVN plugin. Do you think that the refresh is needed here?

    Kristjan

     
  • Mikael Petterson

    Hi Kristjan,

    Good news I really need developer resources in this project :-) Currently I am the only one developing and I have a lot of features people want implemented.

    Anyway I looked at the code in svn:

    http://dev.eclipse.org/viewcvs/viewvc.cgi/trunk/org.eclipse.team.svn.ui/src/org/eclipse/team/svn/ui/compare/?root=Technology_SUBVERSIVE

    but could not see the code you are referring to. What feature is missing in the saveChanges() in the superclass?
    The code looks ok to me but I guess we need some more investigation.

    By the way if you want to present yourself please send me an email (mikaelpetterson at hotmail dot com) and tell me about yourself and what you like developing (of course this is not mandatory but nice when working in the team).

    //mike

     
  • Mikael Petterson

    Hi,

    I checked a bit yesterday and I think we should try your code.

    br,

    //mike

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks