this.running = false;
}
}
};
final Listener listener = new FilteredListener<PropertyContentEvent>()
{
@Override
protected void handleTypedEvent( final PropertyContentEvent event )
{
TablePropertyEditorPresentation.this.refreshOperation.run();
}
};
property.attach( listener );
addOnDisposeOperation
(
new Runnable()
{
public void run()
{
property.detach( listener );
}
}
);
boolean showImages = true;
final String columnWidthsHint = part.getRenderingHint( PropertyEditorDef.HINT_COLUMN_WIDTHS, "" );
final StringTokenizer columnWidthsHintTokenizer = new StringTokenizer( columnWidthsHint, "," );
for( final ModelPath childPropertyPath : part.getChildProperties() )
{
final PropertyDef childProperty = property.definition().getType().property( childPropertyPath );
final PropertyEditorDef childPropertyEditorDef = part.definition().getChildPropertyEditor( childPropertyPath );
final TableViewerColumn tableViewerColumn = new TableViewerColumn( this.tableViewer, SWT.NONE );
if( childPropertyEditorDef == null )
{
final String label = childProperty.getLabel( false, CapitalizationType.TITLE_STYLE, false );
tableViewerColumn.getColumn().setText( label );
}
else
{
final MutableReference<FunctionResult> labelFunctionResultRef = new MutableReference<FunctionResult>();
final Runnable updateLabelOp = new Runnable()
{
public void run()
{
String label = (String) labelFunctionResultRef.get().value();
label = LabelTransformer.transform( label, CapitalizationType.TITLE_STYLE, false );
tableViewerColumn.getColumn().setText( label );
}
};
final FunctionResult labelFunctionResult = part.initExpression
(
childPropertyEditorDef.getLabel().content(),
String.class,
Literal.create( childProperty.getLabel( false, CapitalizationType.NO_CAPS, true ) ),
updateLabelOp
);
labelFunctionResultRef.set( labelFunctionResult );
updateLabelOp.run();
addOnDisposeOperation
(
new Runnable()
{
public void run()
{
labelFunctionResult.dispose();
}
}
);
}
ColumnWeightData columnWeightData = null;
if( columnWidthsHintTokenizer.hasMoreTokens() )
{
final String columnWidthHint = columnWidthsHintTokenizer.nextToken();
final String[] columnWidthHintSplit = columnWidthHint.split( ":" );
if( columnWidthHintSplit.length == 1 || columnWidthHintSplit.length == 2 )
{
try
{
final int minColumnWidth = Integer.parseInt( columnWidthHintSplit[ 0 ].trim() );
final int columnWeight;
if( columnWidthHintSplit.length == 2 )
{
columnWeight = Integer.parseInt( columnWidthHintSplit[ 1 ].trim() );
}
else
{
columnWeight = 0;
}
columnWeightData = new ColumnWeightData( columnWeight, minColumnWidth, true );
}
catch( NumberFormatException e ) {}
}
}
if( columnWeightData == null )
{
columnWeightData = new ColumnWeightData( 1, 100, true );
}
tableColumnLayout.setColumnData( tableViewerColumn.getColumn(), columnWeightData );
final ColumnHandler columnHandler = createColumnHandler( this.columnHandlers, childPropertyPath, showImages, childPropertyEditorDef );
showImages = false; // Only the first column should ever show the image.
tableViewerColumn.setLabelProvider( columnHandler.getLabelProvider() );
tableViewerColumn.setEditingSupport( columnHandler.getEditingSupport() );
final TableColumn tableColumn = tableViewerColumn.getColumn();
tableColumn.addSelectionListener
(
new SelectionAdapter()
{
@Override
public void widgetSelected( final SelectionEvent event )
{
final TableColumn currentSortColumn = TablePropertyEditorPresentation.this.table.getSortColumn();
if( currentSortColumn != tableColumn )
{
TablePropertyEditorPresentation.this.table.setSortColumn( tableColumn );
TablePropertyEditorPresentation.this.table.setSortDirection( SWT.DOWN );
TablePropertyEditorPresentation.this.tableViewer.setComparator( new TableSorter( columnHandler, SWT.DOWN ) );
}
else
{
final int currentSortDirection = TablePropertyEditorPresentation.this.table.getSortDirection();
if( currentSortDirection == SWT.DOWN )
{
TablePropertyEditorPresentation.this.table.setSortDirection( SWT.UP );
TablePropertyEditorPresentation.this.tableViewer.setComparator( new TableSorter( columnHandler, SWT.UP ) );
}
else
{
TablePropertyEditorPresentation.this.table.setSortColumn( null );
TablePropertyEditorPresentation.this.tableViewer.setComparator( null );
}
}
for( SapphireAction action : actions.getActions() )
{
for( SapphireActionHandler handler : action.getActiveHandlers() )
{
if( handler instanceof PropertyEditorActionHandler )
{
( (PropertyEditorActionHandler) handler ).refreshEnablementState();
}
}
}
}
}
);
}
final IStructuredContentProvider contentProvider = new IStructuredContentProvider()
{
public Object[] getElements( final Object inputElement )
{
final ElementList<?> list = property();
final Map<Element,TableRow> rows = new LinkedHashMap<Element,TableRow>();
for( Element element : list )
{
TableRow row = null;
if( TablePropertyEditorPresentation.this.rows != null )
{
row = TablePropertyEditorPresentation.this.rows.remove( element );
}
if( row == null )
{
ImageProvider imageProvider = null;
final ImageService imageService = element.service( ImageService.class );
if( imageService != null )
{
imageProvider = new ImageProvider()
{
private Listener imageServiceListener;
@Override
public ImageData image()
{
if( this.imageServiceListener == null )
{
this.imageServiceListener = new Listener()
{
@Override
public void handle( final Event event )
{
update( row() );