Home » Eclipse Projects » NatTable » Using NatTable freezeSelectionCommand not working
Using NatTable freezeSelectionCommand not working [message #1031419] |
Mon, 01 April 2013 18:18 |
Nandita Uppalapati Messages: 16 Registered: March 2013 |
Junior Member |
|
|
Hi,
I am trying to display custom data in a table and trying to freeze the first two coulmns of the table. Below is the code that I am using. I am not sure what I am doing wrong here but the table is not visible after execution.
I am creating the nattable object at a different place and configuring and adding the layers in a different class
NatTable tblPCRResults = new NatTable(patientCareResultsGroup, false);
This is my data provider:
IDataProvider myDataProvider = new IDataProvider(){
public int getColumnCount() {
return eventEndDtTms.size()+2;
}
public int getRowCount() {
return patientCareResultsRecords.size()+1;
}
public Object getDataValue(int columnIndex, int rowIndex) {
int index =0;
for(List<PatientCareResultsRecord>pcrRecords:
patientCareResultsRecords){
if(columnIndex ==0){
return pcrRecords.get(0).getCategory();
}
if(columnIndex==1){
return pcrRecords.get(0).getEventName();
}
for(PatientCareResultsRecord pcrRecord: pcrRecords){
int correctColumn =getFirstIndex(
pcrRecord.getEventEndDtTmDate(),eventEndDtTms);
int correctRow = index;
Object record = null;
if(columnIndex-2==correctColumn && rowIndex-1 == correctRow){
record = this.getDataValue(, rowIndex);
}
String recordResult ="";
if(record!=null){
recordResult = (String)record;
}
if(recordResult!=null && !recordResult.isEmpty()){
recordResult+= System.getProperty("line.separator");
recordResult+=buildPatientCareResultDispVal(pcrRecord);
}else{
recordResult = buildPatientCareResultDispVal(pcrRecord);
}
if(columnIndex-2 ==correctColumn && rowIndex-1 == index){
return recordResult;
}
}
index++;
}
return null;
}
public void setDataValue(int columnIndex, int rowIndex, Object newValue)
{
}
};
DataLayer bodyDataLayer = new DataLayer(myDataProvider,245,200);
DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
FreezeLayer freezeLayer = new FreezeLayer(selectionLayer);
CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
This is my column data provider code:
IDataProvider columnHeaderDataProvider = new IDataProvider(
public int getColumnCount() {
return eventEndDtTms.size()+2;
}
public int getRowCount() {
return patientCareResultsRecords.size()+1;
}
public Object getDataValue(int columnIndex, int rowIndex) {
String colDateHeader="";
DateAndTimeZoneUtil eventEndDt = null;
if(rowIndex ==0){
if(coulmnIndex ==0){
return "Category";
}
if(columnIndex==1){
return "Event Name";
}
if(eventEndDtTms.get(columnIndex)!=null){
eventEndDt = (DateAndTimeZoneUtil)eventEndDtTms.get(columnIndex);
}
if(utc) {
colDateHeader = DateTimeHelper.formatDateUTC(eventEndDt.getEventDt(), eventEndDt.getTz(), pattern);
}
else {
colDateHeader = sdf.format(eventEndDt.getEventDt()) + eventEndDt.getTzString();
}
}
return colDateHeader;
}
public void setDataValue(int columnIndex, int rowIndex, Object newValue)
{
}
};
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DefaultColumnHeaderDataLayer(columnHeaderDataProvider), compositeFreezeLayer, selectionLayer);
This is my row data provider:
IDataProvider rowDataProvider = new IDataProvider()
{
public Object getDataValue(int columnIndex, int rowIndex) {
return null;
}
public void setDataValue(int columnIndex, int rowIndex, Object newValue)
{
}
@Override
public int getColumnCount() {
return eventEndDtTms.size()+2;
}
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return patientCareResultsRecords.size()+1;
}
};
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(rowDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(rowHeaderDataProvider), compositeFreezeLayer, selectionLayer);
This is the other code namely the corner layer, grid layer and setting up the nattable
DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
CornerLayer cornerLayer = new CornerLayer(new DataLayer(cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
GridLayer gridLayer = new GridLayer(compositeFreezeLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
patientCareResultsComposite.tblPCRResults.setLayer(gridLayer);
patientCareResultsComposite.tblPCRResults.addConfiguration(new DefaultNatTableStyleConfiguration());
patientCareResultsComposite.tblPCRResults.addConfiguration(new HeaderMenuConfiguration(patientCareResultsComposite.tblPCRResults));
patientCareResultsComposite.tblPCRResults.configure();
selectionLayer.setSelectedCell(2, 0);
patientCareResultsComposite.tblPCRResults.doCommand(new FreezeSelectionCommand());
selectionLayer.clear();
Am I doing anything horribly out of place here?
|
|
| | |
Re: Using NatTable freezeSelectionCommand not working [message #1033023 is a reply to message #1033020] |
Wed, 03 April 2013 19:27 |
Nandita Uppalapati Messages: 16 Registered: March 2013 |
Junior Member |
|
|
public class StandaloneNatExampleRunner
{
public static void run(INatExample example)
{
run(800, 800, example);
}
public static void run(int shellWidth, int shellHeight, INatExample example)
{
Display display = Display.getDefault();
Shell shell = new Shell(display, 1264);
shell.setLayout(new FillLayout());
shell.setSize(shellWidth, shellHeight);
shell.setText(example.getName());
Composite comp = new Composite(shell,SWT.FILL);
comp.setRedraw(true);
//final Display display = shell.getDisplay();
GridLayout gridLayout = new GridLayout();
comp.setLayout(gridLayout);
comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Group dateRangeGroup = new Group(comp,SWT.NONE);
final GridLayout gridLayout_1 = new GridLayout();
gridLayout_1.numColumns = 3;
dateRangeGroup.setLayout(gridLayout_1);
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
dateRangeGroup.setLayoutData(gridData);
Label startDateBetweenLabel;
startDateBetweenLabel = new Label(dateRangeGroup, SWT.NONE);
startDateBetweenLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
startDateBetweenLabel.setText("Date between");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -20);
Calendar cal_1 = Calendar.getInstance();
int dateRangeDays = 10;
cal_1.add(Calendar.DATE, -dateRangeDays);
Date disallowBeforeDate = cal_1.getTime();
Calendar cal_2 = Calendar.getInstance();
cal_2.add(Calendar.DATE, 1);
Date disallowAfterDate = cal_2.getTime();
CalendarCombo startCalendar = new CalendarCombo(dateRangeGroup, SWT.NONE);
startCalendar.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));//new GridData(93, SWT.DEFAULT));
startCalendar.setDisallowBeforeDate(disallowBeforeDate);
startCalendar.setDisallowAfterDate(disallowAfterDate);
startCalendar.setDate(cal);
//final Label space = new Label(dateRangeGroup, SWT.NONE);
cal = Calendar.getInstance();
CalendarCombo endCalendar = new CalendarCombo(dateRangeGroup, SWT.NONE);
endCalendar.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));//new GridData(93, SWT.DEFAULT));
endCalendar.setDisallowBeforeDate(disallowBeforeDate);
endCalendar.setDisallowAfterDate(disallowAfterDate);
endCalendar.setDate(cal);
final Group filterGroup = new Group(comp,SWT.NONE);
final GridLayout gridLayout_filter = new GridLayout();
gridLayout_filter.numColumns = 3;
filterGroup.setLayout(gridLayout_filter);
GridData gridData_filter = new GridData();
gridData_filter.horizontalAlignment = SWT.FILL;
gridData_filter.grabExcessHorizontalSpace = true;
filterGroup.setLayoutData(gridData_filter);
//combo box
Label filterLabel = new Label(filterGroup, SWT.NONE);
filterLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
filterLabel.setText("Select from");
//filterLabel.setText(" Lab Results Filter: ");
Combo orderTypeCombo = new Combo(filterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
orderTypeCombo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
orderTypeCombo.select(0);
orderTypeCombo.setDragDetect(false);
orderTypeCombo.setVisibleItemCount(30);
new Label(filterGroup, SWT.NONE);
final Group patientCareResultsGroup = new Group(comp, SWT.HORIZONTAL);
GridData gridData_1 = new GridData();
/*gridData_1.horizontalAlignment = SWT.FILL;
gridData_1.verticalAlignment = SWT.FILL;
gridData_1.grabExcessHorizontalSpace = true;
gridData_1.grabExcessVerticalSpace = true;
patientCareResultsGroup.setLayoutData(gridData_1);*/
Control exampleControl =null;
try{
exampleControl = example.createExampleControl(patientCareResultsGroup);
comp.redraw();
example.onStart();
}catch(Exception e){
e.printStackTrace();
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
example.onStop();
exampleControl.dispose();
shell.dispose();
display.dispose();
}
}
|
|
|
Re: Using NatTable freezeSelectionCommand not working [message #1033024 is a reply to message #1033023] |
Wed, 03 April 2013 19:28 |
Nandita Uppalapati Messages: 16 Registered: March 2013 |
Junior Member |
|
|
public class _001_Getting_Started extends AbstractNatExample
{
private IDataProvider bodyDataProvider;
private String[] propertyNames;
private BodyLayerStack bodyLayer;
private Map<String, String> propertyToLabels;
private int height =0, width =0;
public static void main(String[] args)
{
StandaloneNatExampleRunner.run(600, 400, new _001_Getting_Started());
}
@Override
public Control createExampleControl(Composite parent) {
this.bodyDataProvider = setupBodyDataProvider();
DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(this.propertyNames, this.propertyToLabels);
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(this.bodyDataProvider);
this.bodyLayer = new BodyLayerStack(this.bodyDataProvider);
ColumnHeaderLayerStack columnHeaderLayer = new ColumnHeaderLayerStack(colHeaderDataProvider);
RowHeaderLayerStack rowHeaderLayer = new RowHeaderLayerStack(rowHeaderDataProvider);
DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(colHeaderDataProvider, rowHeaderDataProvider);
CornerLayer cornerLayer = new CornerLayer(new DataLayer(cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
GridLayer gridLayer = new GridLayer(this.bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(parent, gridLayer);
// Region r =parent.getRegion();
// System.out.println(r.);
natTable.addListener(SWT.Paint, new Listener(){
@Override
public void handleEvent(Event arg0) {
for (int i=0; i < natTable.getColumnCount(); i++) {
InitializeAutoResizeColumnsCommand columnCommand = new InitializeAutoResizeColumnsCommand( natTable, i, natTable.getConfigRegistry(), new GCFactory(natTable));
natTable.doCommand(columnCommand);
}
for (int i=0; i < natTable.getRowCount(); i++) {
InitializeAutoResizeRowsCommand rowCommand = new InitializeAutoResizeRowsCommand(natTable, i, natTable.getConfigRegistry(), new GCFactory(natTable));
natTable.doCommand(rowCommand);
}
natTable.removeListener(SWT.Paint, this);
}
});
// nattable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// nattable.setLayer(gridLayer);
natTable.redraw();
natTable.pack();
return natTable;
}
private IDataProvider setupBodyDataProvider()
{
List people = Arrays.asList(new Person[] {
new Person(100, "Mickey Mouse", new Date(1000000L)),
new Person(110, "Batman", new Date(2000000L)),
new Person(120, "Bender", new Date(3000000L)),
new Person(130, "Cartman", new Date(4000000L)),
new Person(140, "Dogbert", new Date(5000000L)) });
this.propertyToLabels = new HashMap();
this.propertyToLabels.put("id", "ID");
this.propertyToLabels.put("name", "First Name");
this.propertyToLabels.put("birthDate", "DOB");
this.propertyNames = new String[] { "id", "name", "birthDate" };
return new ListDataProvider(people, new ReflectiveColumnPropertyAccessor(this.propertyNames));
}
public class BodyLayerStack extends AbstractLayerTransform
{
private SelectionLayer selectionLayer;
public BodyLayerStack(IDataProvider dataProvider) {
DataLayer bodyDataLayer = new DataLayer(dataProvider);
height = bodyDataLayer.getHeight();
width = bodyDataLayer.getWidth();
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
this.selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(this.selectionLayer);
setUnderlyingLayer(viewportLayer);
}
public SelectionLayer getSelectionLayer() {
return this.selectionLayer;
}
}
public class ColumnHeaderLayerStack extends AbstractLayerTransform
{
public ColumnHeaderLayerStack(IDataProvider dataProvider) {
DataLayer dataLayer = new DataLayer(dataProvider);
ColumnHeaderLayer colHeaderLayer = new ColumnHeaderLayer(dataLayer, _001_Getting_Started.this.bodyLayer, _001_Getting_Started.this.bodyLayer.getSelectionLayer());
setUnderlyingLayer(colHeaderLayer);
}
}
public class RowHeaderLayerStack extends AbstractLayerTransform
{
public RowHeaderLayerStack(IDataProvider dataProvider) {
DataLayer dataLayer = new DataLayer(dataProvider, 50, 20);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(dataLayer, _001_Getting_Started.this.bodyLayer, _001_Getting_Started.this.bodyLayer.getSelectionLayer());
setUnderlyingLayer(rowHeaderLayer);
}
}
}
|
|
| | |
Goto Forum:
Current Time: Sun Sep 22 18:02:18 GMT 2024
Powered by FUDForum. Page generated in 0.04317 seconds
|