Last active
August 29, 2015 14:10
-
-
Save roberto-filho/8f5a95774c112ef598ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ComboBoxViewerCellEditor criarColumnComboBox(TableViewerColumn tvc, final Class<?> clazz, final String property, Object[] values, String titulo) { | |
return criarColunaComboBoxEditable(tvc, clazz, property, values, titulo, new ColumnLabelProvider() { | |
@Override | |
public String getText(Object element) { | |
if (clazz.isInstance(element)) { | |
return element.toString(); | |
} else { | |
Object value = ReflectionHelper.getValue(element, property); | |
return value == null ? StringUtils.EMPTY : value.toString(); | |
} | |
} | |
}); | |
} | |
private static ComboBoxViewerCellEditor criarColunaComboBoxEditable(TableViewerColumn tvc, final Class<?> clazz, final String property, Object[] values, String titulo, ColumnLabelProvider labelProvider) { | |
tvc.setLabelProvider(labelProvider); | |
ComboBoxViewerCellEditor comboCellEditor = new ComboBoxViewerCellEditor((Composite) tvc.getViewer().getControl(), SWT.READ_ONLY); | |
comboCellEditor.setContentProvider(ArrayContentProvider.getInstance()); | |
comboCellEditor.setInput(values); | |
comboCellEditor.setLabelProvider(labelProvider); | |
CustomAbstractEditingSupport<ItemDocumentoFiscal> editingSupport = new CustomAbstractEditingSupport<ItemDocumentoFiscal>((TableViewer) tvc.getViewer(), comboCellEditor) { | |
@Override | |
protected void doSetValue(ItemDocumentoFiscal element, Object value) { | |
if (clazz.isInstance(value)) | |
ReflectionHelper.setValue(element, property, value); | |
} | |
@Override | |
protected Object doGetValue(ItemDocumentoFiscal element) { | |
// Esse ReflectionHelper.getValue simplesmente busca o valor de uma propriedade de um determinado objeto utilizando reflexão | |
Object value = ReflectionHelper.getValue(element, property); | |
return value == null ? "" : value.toString(); | |
} | |
}; | |
tvc.setEditingSupport(editingSupport); | |
TableColumn tc = tvc.getColumn(); | |
tc.setText(titulo); | |
return comboCellEditor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment