diff --git a/lib/idcanet-x4o-bin.jar b/lib/idcanet-x4o-bin.jar index 2ec1c38..5fd5748 100644 Binary files a/lib/idcanet-x4o-bin.jar and b/lib/idcanet-x4o-bin.jar differ diff --git a/src/com/idcanet/vasc/core/column/VascColumnValue.java b/src/com/idcanet/vasc/core/column/VascColumnValue.java index 9588b60..99df430 100644 --- a/src/com/idcanet/vasc/core/column/VascColumnValue.java +++ b/src/com/idcanet/vasc/core/column/VascColumnValue.java @@ -33,5 +33,5 @@ package com.idcanet.vasc.core.column; */ public interface VascColumnValue { - public Object getValue(VascTableColumn column); + public Object getValue(VascTableColumn column,Object record); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/column/BeanPropertyVascColumnValue.java b/src/com/idcanet/vasc/impl/column/BeanPropertyVascColumnValue.java index 74c5cce..de28e18 100644 --- a/src/com/idcanet/vasc/impl/column/BeanPropertyVascColumnValue.java +++ b/src/com/idcanet/vasc/impl/column/BeanPropertyVascColumnValue.java @@ -28,6 +28,7 @@ package com.idcanet.vasc.impl.column; import com.idcanet.vasc.core.column.VascColumnValue; import com.idcanet.vasc.core.column.VascTableColumn; +import com.idcanet.x4o.impl.DefaultElementParameterHelper; /** * @@ -45,14 +46,20 @@ public class BeanPropertyVascColumnValue implements VascColumnValue { setProperty(property); } - public Object getValue(VascTableColumn column) { + public Object getValue(VascTableColumn column,Object record) { if(getProperty()==null) { return null; } if(getProperty().equals("")) { return ""; } - return getProperty(); + DefaultElementParameterHelper helper = new DefaultElementParameterHelper(); + try { + return helper.getParameter(record, getProperty()); + } catch (Exception e) { + e.printStackTrace(); + return "Err"; + } } /** diff --git a/src/com/idcanet/vasc/impl/column/NullVascColumnValue.java b/src/com/idcanet/vasc/impl/column/NullVascColumnValue.java index 530714a..9f23c00 100644 --- a/src/com/idcanet/vasc/impl/column/NullVascColumnValue.java +++ b/src/com/idcanet/vasc/impl/column/NullVascColumnValue.java @@ -36,7 +36,7 @@ import com.idcanet.vasc.core.column.VascTableColumn; */ public class NullVascColumnValue implements VascColumnValue { - public Object getValue(VascTableColumn column) { + public Object getValue(VascTableColumn column,Object record) { return null; } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java b/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java index 3595336..1bb16e8 100644 --- a/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java +++ b/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java @@ -29,9 +29,11 @@ package com.idcanet.vasc.impl.serv5; import java.util.List; import java.util.logging.Level; +import org.hibernate.Query; + import com.idcanet.serv5.services.hibernate3.Hibernate3Factory; import com.idcanet.vasc.core.VascDataSource; -import com.idcanet.xtes.xpql.query.Query; +import com.idcanet.xtes.xpql.query.QueryParameterValue; /** * @@ -49,37 +51,20 @@ public class Serv5HibernateVascDataSource implements VascDataSource { setSession(session); } - public List executeQuery(Query query) throws Exception { + public List executeQuery(com.idcanet.xtes.xpql.query.Query query) throws Exception { try { - /* - Query q = Hibernate3Factory.getSession("flowstats").createQuery(query.toString()); - q.setMaxResults(crudTable.getQueryLimit()); - if(crudTable.getViewOnly()) { - q.setReadOnly(true); - } - for(CrudParameterOption para:crudTable.getQueryParameterOptions().values()) { - if(para.getValueHolder().getValue()==null) { - logger.finer("Value is null of parameter: "+para.getName()); - return; - } - try { - Object value = para.getValueHolder().getValue(); - logger.finer("Setting parameter: "+para.getName()+" with: "+value); - if(para.getValueProperty()!=null) { - q.setParameter(para.getName(),BeanUtils.getValue(value,BeanUtils.getPropertyDescriptor(value,para.getValueProperty()))); - } else { - q.setParameter(para.getName(),value); - } - } catch (Exception e) { - logger.log(Level.WARNING,e.getMessage(),e); - } - } + Query q = Hibernate3Factory.getSession(getSession()).createQuery(query.toPreparedSQL(query)); + + List values = query.getOrderQueryParameterValues(); + int i = 0; + for (QueryParameterValue value:values) { + q.setParameter(i,value.getValue()); + i++; + } List data = q.list(); - logger.info("Query returned: "+data.size()+" of: "+crudTable.getQueryName()); - crudTable.getSelectionInList().setList(data); - */ - return null; + //logger.info("Query returned: "+data.size()+" of: "+crudTable.getQueryName()); + return data; } finally { Hibernate3Factory.getSession("flowstats").close(); // close session in threads } diff --git a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java index 9ac62b3..e5f607e 100644 --- a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java @@ -31,10 +31,15 @@ import java.util.Collections; import java.util.List; import java.util.logging.Logger; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -51,10 +56,6 @@ import com.idcanet.vasc.core.VascViewRenderer; import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.column.VascTableColumn; -import fr.jayasoft.binding.jface.adapter.JFaceComponentFactory; -import fr.jayasoft.binding.jface.utils.table.AbstractColumn; -import fr.jayasoft.binding.jface.utils.table.PropertyColumn; - /** * * @author Willem Cazander @@ -72,6 +73,14 @@ public class SwtVascViewRenderer implements VascViewRenderer { } public void renderView(VascTable table) { + + try { + table.setTableData(table.getVascDataSource().executeQuery(table.getQuery())); + } catch (Exception e) { + e.printStackTrace(); + } + + this.table=table; GridLayout layout = new GridLayout(); layout.marginHeight = 0; @@ -143,12 +152,29 @@ public class SwtVascViewRenderer implements VascViewRenderer { public void createBody(Composite body) { logger.finer("Creating body"); - final TableViewer tableViewer = JFaceComponentFactory.createTableViewer(body,table.getSelectionInList(),getTableColumns(crudTable),false); + //final TableViewer tableViewer = JFaceComponentFactory.createTableViewer(body,table.getSelectionInList(),getTableColumns(crudTable),false); + // Create the table viewer to display the players + final TableViewer tableViewer = new TableViewer(body); final Table table2 = tableViewer.getTable(); table2.setLayoutData(new GridData(GridData.FILL_BOTH)); table2.setHeaderVisible(true); table2.setLinesVisible(true); + // Set the content and label providers + tableViewer.setContentProvider(new ListConverterContentProvider()); + tableViewer.setLabelProvider(new DefaultLabelProvider(table)); + //tv.setSorter(new PlayerViewerSorter()); + tableViewer.setInput(table); + + for(VascTableColumn c:table.getTableColumns()) { + TableColumn tc = new TableColumn(table2, SWT.LEFT); + tc.setText(c.getName()); + tc.setToolTipText(c.getToolTip()); + tc.setMoveable(false); + tc.setResizable(true); + } + + //Add sort indicator and sort data when column selected Listener sortListener = new Listener() { public void handleEvent(Event e) { @@ -200,6 +226,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { logger.fine("Table with columns created: "+table2.getColumnCount()); } + /* private static AbstractColumn[] getTableColumns(VascTable crudTable) { AbstractColumn[] cols = new AbstractColumn[crudTable.getCrudTableColumns().size()]; int i=0; @@ -212,7 +239,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { i++; } return cols; - } + }*/ public void createFooter(Composite footer) { logger.finest("Creating footer"); @@ -232,5 +259,86 @@ public class SwtVascViewRenderer implements VascViewRenderer { * Is called when all createPartControl is done with creating Parts */ public void partCreated() { + + } + + class DefaultLabelProvider implements ITableLabelProvider { + + private VascTable table = null; + + public DefaultLabelProvider(VascTable table) { + this.table=table; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) + */ + public Image getColumnImage(Object arg0, int arg1) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) + */ + public String getColumnText(Object bean, int columnNumber) { + System.out.println("Rending column; "+columnNumber+" bean: "+bean); + VascTableColumn vtc = table.getTableColumns().get(columnNumber); + if (vtc.getColumnRenderer()!=null) { + //do iets + return "RENDER"; + } else { + return ""+vtc.getVascColumnValue().getValue(vtc,bean); + } + + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + public void addListener(ILabelProviderListener arg0) { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) + */ + public boolean isLabelProperty(Object arg0, String arg1) { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + public void removeListener(ILabelProviderListener arg0) { + } + + } + + class ListConverterContentProvider implements IStructuredContentProvider { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object obj) { + return ((VascTable)obj).getTableData().toArray(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + } + } } \ No newline at end of file diff --git a/tests/com/idcanet/vasc/tests/SimpleTest.java b/tests/com/idcanet/vasc/tests/SimpleTest.java index e26a7f5..279d505 100644 --- a/tests/com/idcanet/vasc/tests/SimpleTest.java +++ b/tests/com/idcanet/vasc/tests/SimpleTest.java @@ -67,15 +67,21 @@ public class SimpleTest extends TestCase { public void testAll() throws Exception { + // get GUI Display display = new Display(); Shell shell = new Shell(display); shell.setText("Hello, world!"); + // define query XTESParser parser = new XTESParser(); parser.parseResource("/META-INF/xtes/tests.xml"); TemplateStore store = XTESParser.getTemplateStore(parser.getElementContext()); Query query = store.getQuery("testUsers2"); + // define redering + SwtVascViewRenderer render = new SwtVascViewRenderer(shell); + + // config table VascTable table = new VascTable(); table.setName("Testje"); table.setHeaderName("TableHeader"); @@ -84,7 +90,7 @@ public class SimpleTest extends TestCase { table.setHelpId("someKey"); table.setVascDataSource(new Serv5HibernateVascDataSource("flowstats")); table.setVascTextValue(new DefaultVascTextValue()); - table.setVascViewRenderer(new SwtVascViewRenderer(shell)); + table.setVascViewRenderer(render); table.setQuery(query); table.setVascRecordCreator(new BeanVascRecordCreator()); @@ -99,9 +105,10 @@ public class SimpleTest extends TestCase { column.setVascColumnValue(new BeanPropertyVascColumnValue("someValue")); table.addTableColumns(column); - - table.getV + // render + render.renderView(table); + // view shell.open(); // Set up the event loop. while (!shell.isDisposed()) {