// https://bugs.eclipse.org/bugs/show_bug.cgi?id=215997
//
final Composite tableParentComposite = new Composite( tableComposite, SWT.NULL );
tableParentComposite.setLayoutData( gdwhint( gdfill(), 1 ) );
final TableColumnLayout tableColumnLayout = new TableColumnLayout();
tableParentComposite.setLayout( tableColumnLayout );
this.tableViewer = new CustomTableViewer( tableParentComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI );
this.table = this.tableViewer.getTable();
this.decorator.addEditorControl( this.table );
final List<Control> relatedControls = new ArrayList<Control>();
this.table.setData( RELATED_CONTROLS, relatedControls );
this.table.addListener
(
SWT.MeasureItem,
new org.eclipse.swt.widgets.Listener()
{
public void handleEvent( final org.eclipse.swt.widgets.Event event )
{
// The rows should be 18 pixels at minimum to allow sufficient
// room for the cell editors.
event.height = Math.max( event.height, 18 );
}
}
);
this.columnHandlers = new ArrayList<ColumnHandler>();
final ColumnViewerEditorActivationStrategy activationStrategy = new ColumnViewerEditorActivationStrategy( this.tableViewer )
{
protected boolean isEditorActivationEvent( final ColumnViewerEditorActivationEvent event )
{
final int columnIndex = ( (ViewerCell) event.getSource() ).getColumnIndex();
final ColumnHandler columnHandler = getColumnHandler( columnIndex );
return columnHandler.isEditorActivationEvent( event );
}
};
TableViewerEditor.create( this.tableViewer, null, activationStrategy, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_CYCLE_IN_ROW );
this.table.setHeaderVisible( showHeader );
this.selectionProvider = new SelectionProvider( this.tableViewer );
this.table.addFocusListener
(
new FocusAdapter()
{
@Override
public void focusGained( final FocusEvent event )
{
handleTableFocusGainedEvent();
}
}
);
this.refreshOperation = new Runnable()
{
boolean running = false;
public void run()
{
if( TablePropertyEditorPresentation.this.table.isDisposed() )
{
return;
}
if( this.running == true )
{
return;
}
this.running = true;
try
{
TablePropertyEditorPresentation.this.tableViewer.refresh();
if( TablePropertyEditorPresentation.this.table.isDisposed() )
{
return;
}
TablePropertyEditorPresentation.this.table.notifyListeners( SWT.Selection, null );
tableParentComposite.layout();
}
finally
{
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.