labelProvider = new FileSystemLabelProvider( p );
viewerComparator = new FileSystemNodeComparator();
input = new Object();
}
final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( p.shell(), labelProvider, contentProvider );
dialog.setTitle( property.definition().getLabel( false, CapitalizationType.TITLE_STYLE, false ) );
dialog.setMessage( createBrowseDialogMessage( property.definition().getLabel( true, CapitalizationType.NO_CAPS, false ) ) );
dialog.setAllowMultiple( false );
dialog.setHelpAvailable( false );
dialog.setInput( input );
dialog.setComparator( viewerComparator );
final Path currentPathAbsolute = convertToAbsolute( (Path) ( (Value<?>) property ).content() );
if( currentPathAbsolute != null )
{
Object initialSelection = null;
if( contentProvider instanceof WorkspaceContentProvider )
{
final URI uri = currentPathAbsolute.toFile().toURI();
final IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
final IFile[] files = wsroot.findFilesForLocationURI( uri );
if( files.length > 0 )
{
final IFile file = files[ 0 ];
if( file.exists() )
{
initialSelection = file;
}
}
if( initialSelection == null )
{
final IContainer[] containers = wsroot.findContainersForLocationURI( uri );
if( containers.length > 0 )
{
final IContainer container = containers[ 0 ];
if( container.exists() )
{
initialSelection = container;
}
}
}
}
else
{
initialSelection = ( (FileSystemContentProvider) contentProvider ).find( currentPathAbsolute );
}
if( initialSelection != null )
{
dialog.setInitialSelection( initialSelection );
}
}
if( this.type == FileSystemResourceType.FILE )
{
dialog.setValidator( new FileSelectionStatusValidator() );
}
else if( this.type == FileSystemResourceType.FOLDER )
{
dialog.addFilter( new ContainersOnlyViewerFilter() );
}
if( ! extensions.isEmpty() )
{
dialog.addFilter( new ExtensionBasedViewerFilter( extensions ) );
}
if( dialog.open() == Window.OK )
{
final Object firstResult = dialog.getFirstResult();
if( firstResult instanceof IResource )
{
selectedAbsolutePath = ( (IResource) firstResult ).getLocation().toString();
}
else
{
selectedAbsolutePath = ( (FileSystemNode) firstResult ).getFile().getPath();
}
}
}
else if( this.type == FileSystemResourceType.FOLDER )
{
final DirectoryDialog dialog = new DirectoryDialog( p.shell() );
dialog.setText( property.definition().getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false ) );
dialog.setMessage( createBrowseDialogMessage( property.definition().getLabel( true, CapitalizationType.NO_CAPS, false ) ) );
final Value<?> value = (Value<?>) property;
final Path path = (Path) value.content();
if( path != null )
{
dialog.setFilterPath( path.toOSString() );
}
else if( roots.size() > 0 )
{
dialog.setFilterPath( roots.get( 0 ).toOSString() );
}
selectedAbsolutePath = dialog.open();
}
else
{
final FileDialog dialog = new FileDialog( p.shell() );
dialog.setText( property.definition().getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false ) );
final Value<?> value = (Value<?>) property;
final Path path = (Path) value.content();
if( path != null && path.segmentCount() > 1 )
{
dialog.setFilterPath( path.removeLastSegments( 1 ).toOSString() );
dialog.setFileName( path.lastSegment() );
}
else if( roots.size() > 0 )
{
dialog.setFilterPath( roots.get( 0 ).toOSString() );
}
if( ! extensions.isEmpty() )
{
final StringBuilder buf = new StringBuilder();
for( String extension : extensions )
{
if( buf.length() > 0 )
{
buf.append( ';' );
}
buf.append( "*." );
buf.append( extension );
}
dialog.setFilterExtensions( new String[] { buf.toString() } );
}
selectedAbsolutePath = dialog.open();
}
if( selectedAbsolutePath != null )
{
final Path relativePath = convertToRelative( new Path( selectedAbsolutePath ) );