boolean isIDE = CommonUIUtils.isIDEEnvironment();
if ( isIDE )
{
// Asking the user for the location where to 'save as' the file
final SaveAsDialog dialog = new SaveAsDialog( shell );
String inputClassName = input.getClass().getName();
if ( input instanceof FileEditorInput )
// FileEditorInput class is used when the file is opened
// from a project in the workspace.
{
dialog.setOriginalFile( ( ( FileEditorInput ) input ).getFile() );
}
else if ( input instanceof IPathEditorInput )
{
dialog.setOriginalFile( ResourcesPlugin.getWorkspace().getRoot()
.getFile( ( ( IPathEditorInput ) input ).getPath() ) );
}
else if ( inputClassName.equals( "org.eclipse.ui.internal.editors.text.JavaFileEditorInput" ) //$NON-NLS-1$
|| inputClassName.equals( "org.eclipse.ui.ide.FileStoreEditorInput" ) ) //$NON-NLS-1$
// The class 'org.eclipse.ui.internal.editors.text.JavaFileEditorInput'
// is used when opening a file from the menu File > Open... in Eclipse 3.2.x
// The class 'org.eclipse.ui.ide.FileStoreEditorInput' is used when
// opening a file from the menu File > Open... in Eclipse 3.3.x
{
dialog.setOriginalFile( ResourcesPlugin.getWorkspace().getRoot()
.getFile( new Path( input.getToolTipText() ) ) );
}
else
{
dialog.setOriginalName( "config.ldif" ); //$NON-NLS-1$
}
// Open the dialog
if ( openDialogInUIThread( dialog ) != Dialog.OK )
{
return null;
}
// Getting if the resulting file
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile( dialog.getResult() );
// Creating the file if it does not exist
if ( !file.exists() )
{
file.create( new ByteArrayInputStream( "".getBytes() ), true, null ); //$NON-NLS-1$