Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Using NatTable freezeSelectionCommand not working
Using NatTable freezeSelectionCommand not working [message #1031419] Mon, 01 April 2013 18:18 Go to next message
Nandita Uppalapati is currently offline Nandita UppalapatiFriend
Messages: 14
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 #1031757 is a reply to message #1031419] Tue, 02 April 2013 06:42 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1434
Registered: July 2012
Senior Member
Hard to say, but I think the column and row header data provider are not correct. Why should the column header data provider have the same amount of rows as the body (usually the column header has only one row)? And why does the row header data provider have as much columns as the body (usually it only has one column)?

But maybe that's intended. So usually if something breaks at startup there should be exceptions. So do you see some?

Also NatTable is a SWT control. Is it added to your application in a way the layout manager is able to add and scale it correctly?
Re: Using NatTable freezeSelectionCommand not working [message #1033020 is a reply to message #1031757] Wed, 03 April 2013 19:25 Go to previous messageGo to next message
Nandita Uppalapati is currently offline Nandita UppalapatiFriend
Messages: 14
Registered: March 2013
Junior Member
Dirk Fauth wrote on Tue, 02 April 2013 02:42
Hard to say, but I think the column and row header data provider are not correct. Why should the column header data provider have the same amount of rows as the body (usually the column header has only one row)? And why does the row header data provider have as much columns as the body (usually it only has one column)?

But maybe that's intended. So usually if something breaks at startup there should be exceptions. So do you see some?

Also NatTable is a SWT control. Is it added to your application in a way the layout manager is able to add and scale it correctly?
Thanks for replying. I changed the column and row header data providers according to your inputs. I did a nattable.pack() and I see that it is going to the getDataValue() but it only returns the rowIndex 0 and columnIndex 0 data and runs in an infinite loop.Maybe something wrong with the way I coded. It is not throwing any exceptions.

I have created the nattable in a group and am using GridLayout for the group. It did not display anything at all before using nattable.pack(). But after using pack() it was showing nattable but in a weird manner. It is not filling up the group. So I modified the StandAloneExampleRunner.java and _001_Getting_Started.java to reflect my UI though with simple data. I still have the same problem. Nattable is not filling up the whole group. The following is my modified code.
Re: Using NatTable freezeSelectionCommand not working [message #1033023 is a reply to message #1033020] Wed, 03 April 2013 19:27 Go to previous messageGo to next message
Nandita Uppalapati is currently offline Nandita UppalapatiFriend
Messages: 14
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 Go to previous messageGo to next message
Nandita Uppalapati is currently offline Nandita UppalapatiFriend
Messages: 14
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);
    }
  }


}


Re: Using NatTable freezeSelectionCommand not working [message #1033025 is a reply to message #1033024] Wed, 03 April 2013 19:28 Go to previous messageGo to next message
Nandita Uppalapati is currently offline Nandita UppalapatiFriend
Messages: 14
Registered: March 2013
Junior Member
Using this code, I am getting the output something like this

http://i46.tinypic.com/15yagt2.png
Re: Using NatTable freezeSelectionCommand not working [message #1033377 is a reply to message #1033025] Thu, 04 April 2013 07:11 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1434
Registered: July 2012
Senior Member
Hi Nandita,

you should search for that issue in your layout code and not in NatTable. Seems you forgot to tell the patientCareResultsGroup to use the GridLayout. I'm also not sure why you are calling redraw() and pack() all the time on initialization.

Greez,
Dirk
Previous Topic:Bug in assigning converters
Next Topic:Strange behavior with RowResizeCommand
Goto Forum:
  


Current Time: Sat Dec 20 05:17:17 GMT 2014

Powered by FUDForum. Page generated in 0.01763 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software