Vaadin table rows - vaadin

I'm using vaadin for UI,I have a entity class which has #OneToMany relationship, so Entity class has a list. so I want to display those values in a vaadin table,Could anyone explain me how to do that? Thank you, here is my class details
#OneToMany
private List<Driver> driverList = new ArrayList<Driver>()
This field in TempLocation class.
so when I query from the data I get one city and list of drivers. In vaadin table I could display query result in a single row(assume I have only one record in a database with more than one Driver)
Lets say my table has two columns "Location" and "Driver", so I want to display the results in multiple rows,I want to go through the List and take one drive at time display along with the City
Currently how it display in the table.
|Driver_______________| Location | (Table head)
[Driver1,Driver2,Driver3] | Kolonnanwa (row)
I want display this
|Driver______________| Location | (Table head)
Driver1______________|Kolonnawa (row 1)
Driver2______________| Kolonnawa (row 2)
Driver3______________| Kolonnanwa (row 3)
"_" used to display spaces ,
Hope you got what I want to express and can anyone tell me how to do this?
Thankxx in Advance
Thank you,
Cheers

If you only want a different way of filling the table , I recommend just iterating over the List of your drivers and create one row for everyone (assuming every driver knows his city)
Check this example:
/* Create the table with a caption. */
Table table = new Table("This is my Table");
/* Define the names and data types of columns.
* The "default value" parameter is meaningless here. */
table.addContainerProperty("Driver", String.class, null);
table.addContainerProperty("City", String.class, null);
/* Add a few items in the table. */
int i = 1;
for(Driver driver : driverslist){
table.addItem(new Object[] {
driver.getName(),driver.getCity(), new Integer(i));
i++
}
The Integer in the addItem()-method is for the rownumber.
Please check the articles given in the vaadin book about the use of the table component.

Related

Table converter integer to image

I am fairly new to Vaadin and am creating a small application. Here I display a table with some columns. In one of the columns I have an integer which, depending on its value, I wish to show an image in that cell.
I have been looking onto table converters but have not find what I am looking for. Could someone help me on the road to get this to work?
Thanks!
You can accomplish this using a column generator.
table.addGeneratedColumn("imageNr", new Table.ColumnGenerator() {
#Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Integer i = (Integer) source.getItem(itemId).getItemProperty("imageNr").getValue();
Resource res = getImageResource(i); // get the resource depending the integer value
return new Image(null, res);
}
});
The column id "imageNr" on the first line doesn't have to be the same as the item property id, but if it is it replaces the integer column in the table and also makes this column sortable according to the underlying integer value.

Convert a Dart Row Object to a Map. (sqlJocky)

I'd like to get the row data given to me by sqlJocky in my Dart Server application and convert it (with column names) to a Map. Ie. row['email'] == "somename".
The row data is a "_BinaryDataPacket" which is an extension of Row type. Right now the method recommended by the sqlJocky developer to access the data involves either knowing the column name of what your accessing in the database:
row.email == "somename"
or just ignoring the column name all together:
row[0] == "somename"
I've tried a few hacks to get at the column data and even edited the original sqlJockey code to get at _BinaryDataPacket._fieldIndex to made it public. While that did give me access to Symbol instances of the Column titles to build a map with, I would like to avoid modifying the developers stable code if at all possible.
I assume there has to be an easy way to get the column names and put them in a Map with the row data.
TLDR:
I want to Convert alpha.brava == "charle" into alpha["bravo"] == "charle".
Thanks
In your results, you have a fields list attribute.
So you could do this :
.then((Results results) {
results.forEach((Row row) {
Map r = new Map();
for(int i=0; i<results.fields.length; i++) {
r[results.fields[i].name] = row[i];
}
});
});
This will map the data from a row to the map

What is the best way to create a List<string> of column names where the column names do not exist in a string[]?

I have a DataTable and I want to create a List<string> of the column names unless those column names are included in string[] excludedColList.
I know how to get a list of all column names:
List<string> colNamesList = (from DataColumn column in gridTable.Columns select column.ColumnName).ToList();
I don't know how to add the filter to exclude those listed in the excludeColList.
I am not sure how to ask this question so that a Google search returns applicable results, so I am trying to explain it here.
I am fine with changing excludedColList from a string[] to a string if it helps.
I do need it to be an exclusion list rather than an inclusion list.
UPDATE
As often seems to happen, as soon as I ask the question, I find an answer. This works for me:
List<string> colNamesList = (from DataColumn column in gridTable.Columns select column.ColumnName).Except(excludedColList).ToList();
(from System.Data.DataColumn column in gridTable.Columns
where !excludedColList.Contains(column.ColumnName)
select column.ColumnName).ToList()
or
(from System.Data.DataColumn column in gridTable.Columns
select column.ColumnName).Except(excludedColList).ToList()
would both work

Combining table, web service data in Grails

I'm trying to figure out the best approach to display combined tables based on matching logic and input search criteria.
Here is the situation:
We have a table of customers stored locally. The fields of interest are ssn, first name, last name and date of birth.
We also have a web service which provides the same information. Some of the customers from the web service are the same as the local file, some different.
SSN is not required in either.
I need to combine this data to be viewed on a Grails display.
The criteria for combination are 1) match on SSN. 2) For any remaining records, exact match on first name, last name and date of birth.
There's no need at this point for soundex or approximate logic.
It looks like what I should do is extract all the records from both inputs into a single collection, somehow making it a set on SSN. Then remove the blank ssn.
This will handle the SSN matching (once I figure out how to make that a set).
Then, I need to go back to the original two input sources (cached in a collection to prevent a re-read) and remove any records that exist in the SSN set derived previously.
Then, create another set based on first name, last name and date of birth - again if I can figure out how to make a set.
Then combine the two derived collections into a single collection. The collection should be sorted for display purposes.
Does this make sense? I think the search criteria will limit the number of record pulled in so I can do this in memory.
Essentially, I'm looking for some ideas on how the Grails code would look for achieving the above logic (assuming this is a good approach). The local customer table is a domain object, while what I'm getting from the WS is an array list of objects.
Also, I'm not entirely clear on how the maxresults, firstResult, and order used for the display would be affected. I think I need to read in all the records which match the search criteria first, do the combining, and display from the derived collection.
The traditional Java way of doing this would be to copy both the local and remote objects into TreeSet containers with a custom comparator, first for SSN, second for name/birthdate.
This might look something like:
def localCustomers = Customer.list()
def remoteCustomers = RemoteService.get()
TreeSet ssnFilter = new TreeSet(new ClosureComparator({c1, c2 -> c1.ssn <=> c2.ssn}))
ssnFilter.addAll(localCustomers)
ssnFilter.addAll(remoteCustomers)
TreeSet nameDobFilter = new TreeSet(new ClosureComparator({c1, c2 -> c1.firstName + c1.lastName + c1.dob <=> c2.firstName + c2.lastName + c2.dob}))
nameDobFilter.addAll(ssnFilter)
def filteredCustomers = nameDobFilter as List
At this point, filteredCustomers has all the records, except those that are duplicates by your two criteria.
Another approach is to filter the lists by sorting and doing a foldr operation, combining adjacent elements if they match. This way, you have an opportunity to combine the data from both sources.
For example:
def combineByNameAndDob(customers) {
customers.sort() {
c1, c2 -> (c1.firstName + c1.lastName + c1.dob) <=>
(c2.firstName + c2.lastName + c2.dob)
}.inject([]) { cs, c ->
if (cs && c.equalsByNameAndDob(cs[-1])) {
cs[-1].combine(c) //combine the attributes of both records
cs
} else {
cs << c
}
}
}

Silverlight / Data Challenging Issue

I'm a little stumped on this one. Anyone have any ideas? I'll try to lay out the example as brief as possible.
Creating Silverlight 3.0 application against SQL 2005 database. Using RIA Services and Entity Framework for data access.
I need to be able to populate a grid against a table. However, my grid UI and my table structure is different. Basically my grid needs to turn rows into columns (like a PIVOT table). Here are my challenges / assumptions
I have no idea until runtime which columns I will have on the grid.
Silverlight 3 only supports binding to properties
Silverlight 3 does not allow you to add a row to the grid and manually populate data.
As we all know, Silverlight does not have the System.Data (mainly DataTable) namespace
So, how do I create an object w/ dynamic properties so that I can bind to the grid. Every idea I've had (multi-dimensional arrays, hash tables, etc.) fall apart b/c SL needs a property to bind to, I can't manually add/fill a data row, and I can't figure out a way to add dynamic properties. I've seen an article on a solution involving a linked list but I'm looking for a better alternative. It may come down to making a special "Cody Grid" which will be a bunch of text boxes/labels. Doable for sure but I'll lose some grid functionality that users expect
The ONLY solution I have been able to come up is to create a PIVOT table query in SQL 2005 and use an entity based on that query/view. SQL 2008 would help me with that. I would prefer to do it in Silverlight but if that is the last resort, so be it. If I go the PIVOT route, how do I implement a changing data structure in Entity Framework?
Data Sample.
Table
Name Date Value
Cody 1/1/09 15
Cody 1/2/09 18
Mike 1/1/09 20
Mike 1/8/09 77
Grid UI should look like
Name 1/1/09 1/2/09 1/3/09 .... 1/8/09
Cody 15 18 NULL NULL
Mike 20 NULL NULL 77
Cody
My team came up with a good solution. I'm not sure who deserves the credit but it's somewhere in google land. So far it works pretty good.
Essentially the solution comes down to using reflection to build a dynamic object based on this dynamic data. The function takes in a 2-dimensional array and turns it into a List
object with properties that can be bound. We put this process in a WCF Service and it seems to do exactly what we need so far.
Here is some of the code that builds the object using Reflection
AppDomain myDomain = AppDomain.CurrentDomain;
AssemblyName myAsmName = new AssemblyName("MyAssembly");
AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
ModuleBuilder myModule = myAssembly.DefineDynamicModule(myAsmName.Name);
TypeBuilder myType = myModule.DefineType("DataSource", TypeAttributes.Public);
string columnName = "whatever";
for (int j = 0; j <= array.GetUpperBound(1); j++)
{
Type properyType = typeof(T);
FieldBuilder exField = myType.DefineField("_" + "columnName" + counter, properyType, FieldAttributes.Private);
//The following line is where I’m passing columnName + counter and getting errors with some strings but not others.
PropertyBuilder exProperty = myType.DefineProperty(columnName + counter.ToString(), PropertyAttributes.None, properyType, Type.EmptyTypes);
//Get
MethodBuilder exGetMethod = myType.DefineMethod("get_" + "columnName" + counter, MethodAttributes.Public, properyType, Type.EmptyTypes); ILGenerator getIlgen = exGetMethod.GetILGenerator();
//IL for a simple getter:
//ldarg.0
//ldfld int32 SilverlightClassLibrary1.Class1::_Age
//ret
getIlgen.Emit(OpCodes.Ldarg_0);
getIlgen.Emit(OpCodes.Ldfld, exField);
getIlgen.Emit(OpCodes.Ret);
exProperty.SetGetMethod(exGetMethod);
//Set
MethodBuilder exSetMethod = myType.DefineMethod("set_" + "columnName" + counter, MethodAttributes.Public, null, new Type[] { properyType }); ILGenerator setIlgen = exSetMethod.GetILGenerator();
//IL for a simple setter:
//ldarg.0
//ldarg.1
//stfld int32 SilverlightClassLibrary1.Class1::_Age
//ret
setIlgen.Emit(OpCodes.Ldarg_0);
setIlgen.Emit(OpCodes.Ldarg_1);
setIlgen.Emit(OpCodes.Stfld, exField); setIlgen.Emit(OpCodes.Ret);
exProperty.SetSetMethod(exSetMethod);
counter++;
}
finished = myType.CreateType();
You can dynamically set columns with their associated bindings (ensuring that AutoGenerateColumns is off):
For instance, the name column:
DataGridTextColumn txtColumn = new DataGridTextColumn();
textColumn.Header = "Name";
textColumn.Binding = new Binding("FirstName");
myDataGrid.Columns.Add(txttColumn);
The ObservableCollection you use to store the data that is queried could possibly be overriden to support pivoting, making sure to change the binding of the DataGrid columns, as shown above.
Note: This is a fair amount of hand waving i'm sure (haven't touched silverlight for over a year); but I hope it's enough to formulate another strategy.
if you are working with two dimensional array then adding columns dynamically as shown above will not work.
The problem is with silverlight it cannot understand the binding of columns to a list.
So we have to create list of rows with row convertor that will represent our two dimensional arrays.
this one worked for me
http://www.scottlogic.co.uk/blog/colin/2010/03/binding-a-silverlight-3-datagrid-to-dynamic-data-via-idictionary-updated/

Resources