treeViewer.setContentProvider( new WorkbenchContentProvider() );
treeViewer.setLabelProvider( WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider() );
treeViewer.setSorter( new ViewerSorter() );
final ValidFileSystemResourceType validFileSystemResourceTypeAnnotation
= value.definition().getAnnotation( ValidFileSystemResourceType.class );
if( validFileSystemResourceTypeAnnotation != null )
{
if( validFileSystemResourceTypeAnnotation.value() == FileSystemResourceType.FOLDER )
{
treeViewer.addFilter( new ContainersOnlyViewerFilter() );
}
final FileExtensionsService fileExtensionsService = value.service( FileExtensionsService.class );
if( fileExtensionsService != null )
{
final ExtensionBasedViewerFilter filter = new ExtensionBasedViewerFilter( fileExtensionsService.extensions() );
treeViewer.addFilter( filter );
final Listener listener = new Listener()
{
@Override
public void handle( final Event event )
{
filter.change( fileExtensionsService.extensions() );
treeViewer.refresh();
}
};
fileExtensionsService.attach( listener );
tree.addDisposeListener
(
new DisposeListener()
{
public void widgetDisposed( final DisposeEvent event )
{
fileExtensionsService.detach( listener );
}
}
);
}
}
treeViewer.addDoubleClickListener
(
new IDoubleClickListener()
{
public void doubleClick( final DoubleClickEvent event )
{
final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if( selection != null )
{
final Object item = selection.getFirstElement();
if( treeViewer.getExpandedState( item ) )
{
treeViewer.collapseToLevel( item, 1 );
}
else
{
treeViewer.expandToLevel( item, 1 );
}
}
}
}
);
final IContainer root;
if( element instanceof CreateWorkspaceFileOp )
{
root = ( (CreateWorkspaceFileOp) element ).getRoot().target();
}
else
{
root = ResourcesPlugin.getWorkspace().getRoot();
}
treeViewer.setInput( root );
this.decorator.addEditorControl( drillDown );
this.decorator.addEditorControl( tree );
final String val = value.text();
if( val != null )
{
IPath path = new Path( val );
IResource resource = root.findMember( val );
while( resource == null )
{
path = path.removeLastSegments( 1 );
resource = root.findMember( path );
}
if( resource instanceof IFile && validFileSystemResourceTypeAnnotation.value() == FileSystemResourceType.FOLDER )
{
resource = resource.getParent();
}
treeViewer.setSelection( new StructuredSelection( resource ) );