[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: plugin needs to send events to the workbench?
|
"John Arthorne" <John_Arthorne@xxxxxxxx> wrote in message
news:<3E9DCD1A.4090201@xxxxxxxx>...
> If you're using IFile.getContents and IFile.setContents, then no other
> notification is required. If it's reporting that resources are out of
> sync, this suggests that you've modified the file on disk without using
> Eclipse API (for example, using java.io.FileOutputStream). If you've
> done this, you can let Eclipse know by caling IFile.refreshLocal().
> Another possibility is that you're not properly cleaning up somewhere.
> Note that it is your responsibility to close the stream returned by
> IFile.getContents(), otherwise you're leaving a file descriptor open.
> --
Thanks for the response John. I was not closing that InputStream before,
but I am now and still getting the "Unable to delete" problem. It's a minor
annoyance since most often I won't be deleting files from my projects, but
I'd still like to see it work cleanly.
Here's the body of the run method in case anyone else can spot what the
problem is (I'm sure the formatting will be horrible):
/**
* @see IActionDelegate#run(IAction)
*
* @param action
*/
public void run( IAction action )
{
EclipsePlugin plugin = EclipsePlugin.getDefault();
IDialogSettings settings = plugin.getDialogSettings();
String styleLocation = null;
IndenterParser parser = null;
try
{
styleLocation = settings.get( STYLE_FILE );
IndenterProperties props = new IndenterProperties( styleLocation );
parser = new IndenterParser( props );
IFileEditorInput input = ( IFileEditorInput )editor_.getEditorInput();
IFile currentFile = input.getFile();
// If the file needs it, save it before formatting.
if ( editor_.isDirty() )
{
editor_.doSave( new NullProgressMonitor() );
}
ByteArrayOutputStream ostr = new ByteArrayOutputStream();
parser.prettify( currentFile.getContents(), ostr );
InputStream newStream = new ByteArrayInputStream( ostr.toByteArray()
);
ostr.flush();
currentFile.setContents( newStream, false, true, new
NullProgressMonitor() );
// clean up
currentFile.refreshLocal( IResource.DEPTH_ONE, new
NullProgressMonitor() );
newStream.close();
ostr.close();
}
catch( CoreException core )
{
handleException( core );
return;
}
catch( IndenterException ie )
{
handleException( ie );
// Don't blow away settings, the file may just be badly formatted.
// settings.put( STYLE_FILE, "" );
return;
}
catch( FileNotFoundException fnfe )
{
handleException( fnfe );
settings.put( STYLE_FILE, "" );
return;
}
catch( IOException ioe )
{
handleException( ioe );
return;
}
}
--Eric