How to coloriate differently even rows and odd rows of a List in LWUIT? - lwuit

There is a List in a LWUIT application. I want to make odd rows and even rows to be of different colors. How to achieve that ?

You can set two differents UIIDs to the rows. Setting this UIID you can modify selectively the colors of your rows.
EDIT
Ok this will be more difficult.
You need to make a Render and set it in your List with List.setRender(Render r).
The ´Render´ class will extend from ListCellRender. In this class you can set UIID to the Render, setting its Selected or Unselected styles.
See this example. #Shai Almog could have more info for your problem.
http://www.lwuit.com/2008/07/lwuit-list-renderer-by-chen-fishbein.html

What you need is the Generic List Cell Renderer, you will probably have to create the styles in code, or set the UIID from the resource editor.
List list = new List(createGenericListCellRendererModelData());
list.setRenderer(new GenericListCellRenderer(createGenericRendererContainer(), createGenericRendererContainer()));
private Container createGenericRendererContainer() {
Container c = new Container(new BorderLayout());
c.setUIID("ListRenderer");
Label name = new Label();
name.setFocusable(true);
name.setName("Name");
c.addComponent(BorderLayout.CENTER, name);
Label surname = new Label();
surname.setFocusable(true);
surname.setName("Surname");
c.addComponent(BorderLayout.SOUTH, surname);
CheckBox selected = new CheckBox();
selected.setName("Selected");
selected.setFocusable(true);
c.addComponent(BorderLayout.WEST, selected);
return c;
}
private Hashtable[] createGenericListCellRendererModelData() {
Hashtable[] data = new Hashtable[5];
data[0] = new Hashtable();
data[0].put("Name", "Shai");
data[0].put("Surname", "Almog");
data[0].put("Selected", Boolean.TRUE);
data[1] = new Hashtable();
data[1].put("Name", "Chen");
data[1].put("Surname", "Fishbein");
data[1].put("Selected", Boolean.TRUE);
data[2] = new Hashtable();
data[2].put("Name", "Ofir");
data[2].put("Surname", "Leitner");
data[3] = new Hashtable();
data[3].put("Name", "Yaniv");
data[3].put("Surname", "Vakarat");
data[4] = new Hashtable();
data[4].put("Name", "Meirav");
data[4].put("Surname", "Nachmanovitch");
return data;
}
Full details here : http://lwuit.blogspot.com/2011/03/list-rendering-easy-way-generic-list.html (code gotten from this link).

Related

NatTable - Strange behavior when sorting

I have a nattable with sort/filter capabilities based off of
http://www.eclipse.org/nattable/documentation.php?page=sorting
and example 6031_GlazedListsFilterExample.java
Initially my table has zero rows.
Scenario 1:
I view a CTabItem that contains a NatTable with no rows.
If I then populate the rows and click on the column headers, nothing happens (sorting seems disabled).
Scenario 2:
I do NOT view a CTabItem that contains the NatTable with no rows.
I then populate the rows
I then view the CTabItem that contains the NatTable which now has rows.
I click on the column headers and everything sorts as expected (sorting seems enabled)
Scenario 3:
I do NOT view a CTabItem that contains the NatTable with no rows.
I then populate the rows
I then view the CTabItem that contains the NatTable which now has rows.
I then remove all row data
I click on the column headers and everything sorts as expected (sorting seems enabled). * even though there are no rows I still see the up/down icons appear in the column header cell
Is there a reason that the column header actions are not 'updated' after the initial 'view' of the NatTable? In other words, it seems to take the presence/absence of rows into account for the rest of the tables life after the first time the NatTable is viewed, regardless of if the rows change.
Relevant Code sections shown below:
private CompositeLayer createExampleLayer(Collection<T> values,
IColumnPropertyAccessor<T> columnPropertyAccessor,
IDataProvider columnHeaderDataProvider, IConfigRegistry
configRegistry, Matcher<T> matcher) {
BodyLayerStack<T> bodyLayerStack = new BodyLayerStack<>(
values, columnPropertyAccessor);
// build the column header layer
DataLayer columnHeaderDataLayer = new
DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new
ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack,
bodyLayerStack.getSelectionLayer());
SortHeaderLayer<T> sortHeaderLayer = new SortHeaderLayer<>
(columnHeaderLayer, new GlazedListsSortModel<T>
(bodyLayerStack.getSortedList(), columnPropertyAccessor,
configRegistry,
bodyLayerStack.getBodyDataLayer()), false);
FilterRowHeaderComposite<T> filterRowHeaderLayer = new
FilterRowHeaderComposite<>(
new DefaultGlazedListsFilterStrategy<T>
(bodyLayerStack.getFilterList(), columnPropertyAccessor,
configRegistry),
sortHeaderLayer, columnHeaderDataLayer.getDataProvider(),
configRegistry);
// Omitted code for rowHeaderLayer and cornerLayer
return new GridLayer(bodyLayerStack, filterRowHeaderLayer,
rowHeaderLayer, cornerLayer);
}
public BodyLayerStack(Collection<T> values,
IColumnPropertyAccessor<T> columnPropertyAccessor) {
eventList = GlazedLists.eventList(values);
TransformedList<T, T> rowObjectsGlazedList =
GlazedLists.threadSafeList(eventList);
this.sortedList = new SortedList<>(rowObjectsGlazedList, null);
// wrap the SortedList with the FilterList
this.filterList = new FilterList<>(sortedList);
this.bodyDataProvider = new ListDataProvider<>(this.filterList,
columnPropertyAccessor);
this.bodyDataLayer = new DataLayer(getBodyDataProvider());
// layer for event handling of GlazedLists and PropertyChanges
GlazedListsEventLayer<T> glazedListsEventLayer = new
GlazedListsEventLayer<>(bodyDataLayer, this.filterList);
this.selectionLayer = new SelectionLayer(glazedListsEventLayer);
ViewportLayer viewportLayer = new ViewportLayer(getSelectionLayer());
setUnderlyingLayer(viewportLayer);
}
private void enableSorting() {
this.nattable.addConfiguration(new SingleClickSortConfiguration());
}
Looks like the creation of your SortHeaderLayer is not correct. The last parameter of the GlazedListsSortModel needs to be the IDataLayer of the column header, not the body layer.
Changing your code to the following should make things work. It did at least on my side.
SortHeaderLayer<T> sortHeaderLayer = new SortHeaderLayer<>
(columnHeaderLayer, new GlazedListsSortModel<T>
(bodyLayerStack.getSortedList(), columnPropertyAccessor,
configRegistry,
columnHeaderDataLayer), false);

DefaultCell properties are not used in my pdf created with iTextSharp

I use iTextSharp v5.5.6
I'm creating a large table.
To be consistent in my layout I want to use the DefaultCell class to set some default settings like font, padding and alignment.
I'm not doing something correct because the settings are not applied to my cells.
Here's some code:
var table = new PdfPTable(2)
{ KeepTogether = true, TotalWidth = printWidth, LockedWidth = true,
HorizontalAlignment = 0, SpacingBefore = 0, SpacingAfter = 15f };
// Set default values:
table.DefaultCell.Colspan = 1;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.DefaultCell.Padding = 5f;
table.DefaultCell.PaddingLeft = 5f;
table.DefaultCell.PaddingBottom = 5f;
table.DefaultCell.VerticalAlignment = Element.ALIGN_BOTTOM;
table.DefaultCell.BorderWidthBottom = 0f;
table.DefaultCell.Phrase = new Phrase { Font = Blue11BoldFont };
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.AddCell(new PdfPCell(new Phrase("Foo"))
{ HorizontalAlignment = Element.ALIGN_CENTER, MinimumHeight = 20f });
table.AddCell(new PdfPCell(new Phrase("Bar", Black10BoldFont))
{ Colspan = 4, HorizontalAlignment = Element.ALIGN_CENTER });
I would have expected my first cell would use my blue font and padding is applied.
But nothing is applied. In fact when I remove the DefaultCell lines I get the same result.
I've been searching for hours now and most samples I've found use something similar.
Any suggestion is much appreaciated.
You are creating PdfPCell objects yourself. In that case, the default cell is always ignored.
See What is the PdfPTable.DefaultCell property used for?
When creating a PdfPTable, you add cells.
One way is to create a PdfPCell object and to add that cell with the addCell() method. In this case, you are responsible to define the properties of each individual cell.
Another way is to use a short-cut: you don't create a PdfPCell, but you add a String or a Phrase to the table with the addCell() method. In this case, a PdfPCell is created internally using default properties. You can change the default properties by changing the properties of the default cell. The default cell is obtained using the getDefaultCell() method.
This is not a bug, this is by design. You are misinterpreting the meaning of the concept of the "default cell". Note that this concept was explained in the free ebook The Best iText Questions on StackOverflow.
If you want to be consistent in your layout, the best way to do this, is by creating your own createCell() method that creates a PdfPCell to which you apply all the properties for which you were using the default cell.

Tree Does not expand in NatTable

I am trying examples from here
I commented rowHeaderLayer, ColumnHeaderLayer, CornerLayer, GridLayer and directly set viewPortLayer to nattable. Tree shows up but I am not able to expand and collapse the tree though I have rowHideShowLayer.
Here is code snippet :
EventList<Datum> eventList = GlazedLists.eventList(datums.values());
SortedList<Datum> sortedList = new SortedList<Datum>(eventList, null);
String[] propertyNames = new String[] { "self", "bar" };
IColumnPropertyAccessor<Datum> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<Datum>(propertyNames);
// Column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ISortModel sortModel = new GlazedListsSortModel<Datum>(
sortedList,
columnPropertyAccessor,
configRegistry,
columnHeaderDataLayer);
final TreeList <Datum> treeList = new TreeList<Datum>(sortedList, new DatumTreeFormat(sortModel), new DatumExpansionModel());
GlazedListTreeData <Datum> treeData = new DatumTreeData(treeList);
GlazedListsDataProvider<Datum> bodyDataProvider = new GlazedListsDataProvider<Datum>(treeList, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
// Body layer
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(selectionLayer);
final TreeLayer treeLayer = new TreeLayer(rowHideShowLayer, new GlazedListTreeRowModel<Datum>(treeData));
ViewportLayer viewportLayer = new ViewportLayer(treeLayer);
NatTable natTable = new NatTable(parent, viewportLayer, false);`
Phew, what places our code can be found is really strange ...
I wouldn't look into googlesource, instead we host our sources in the Eclipse infrastructure, and IIRC the sources are replicated at GitHub. So the better example would be
https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_600_GlazedLists/_604_Tree/_6041_TreeGridExample.java
Regarding your question, you don't need the RowHideShowLayer, and I suggest to remove it. As you don't use a grid composition you need to set the necessary region label to the ViewportLayer to enable the configured UI bindings. So you need to add the following line of code after the creation of the ViewportLayer
viewportLayer.setRegionName(GridRegion.BODY);

ToggleGroup in a GXT ColumnConfig

I'm using a ColumnConfig for presenting and editing data. For the gender I wann to have RadioButtons which where defined by an enumeration.
In every row i want to have:
id | (x) male ( ) female | name | date
The only way I have found was adding a "button" with defined rendering code. But there I cannot get the values or actions for pushed radio.
ColumnConfig<SomeValueGto, String> begIdCol = createColumnConfig(begIdProvider, "Id", sizeBegId);
//gender
ColumnConfig<SomeValueGto, GenderCode> genderCol = createColumnConfig(GRID_PROPERTIES.sex(), "Sex*", sizeGender);
ColumnConfig<SomeValueGto, String> nameCol = createColumnConfig(GRID_PROPERTIES.name(), "Name*", sizeName);
ColumnConfig<SomeValueGto, Date> birthdateCol = createColumnConfig(GRID_PROPERTIES.birthdate(), "Birthdate*", sizeBirthdate);
DateCell gebCell = new DateCell(DateTimeFormat.getFormat("dd.MM.yyyy"));
geburtsdatumCol.setCell(gebCell);
//add fields to the row
List<ColumnConfig<SomeValueGto, ?>> columnList = new ArrayList<ColumnConfig<SomeValueGto, ?>>();
columnList.add(begIdCol);
columnList.add(genderCol);
columnList.add(nameCol);
columnList.add(birthdateCol);
ColumnModel<SomeValueGto> cm = new ColumnModel<SomeValueGto>(columnList);
ListStore<SomeValueGto> gridStore = new ListStore<SomeValueGto>(GRID_PROPERTIES.id());
myGrid = new SLGrid<SomeValueGto>(gridStore, cm);
// empty entries. default ids 1/2/3
myGrid.getStore().add(new SomeValueGto(1));
myGrid.getStore().add(new SomeValueGto(2));
myGrid.getStore().add(new SomeValueGto(3));
final GridInlineEditing<SomeValueGto> editing = new GridInlineEditing<SomeValueGto>(myGrid);
editing.setErrorSummary(false);
editing.addEditor(nameCol, new TextField());
final SLDateField dateField = new SLDateField("date", false, true);
editing.addEditor(geburtsdatumCol, new Converter<Date, Date>() {.....}, dateField);
The helper createColumnConfig:
private <T> ColumnConfig<SomeValueGto, T> createColumnConfig(ValueProvider<SomeValueGto, T> aValueProvider, String aHeader, int aWidth) {
ColumnConfig<SomeValueGto, T> columnCol = new ColumnConfig<SomeValueGto, T>(aValueProvider);
columnCol.setHeader(aHeader);
columnCol.setWidth(aWidth);
columnCol.setMenuDisabled(true);
return columnCol;
}
Does anyone have already solved a problem like this?
GXT Grids uses com.google.gwt.cell.client.Cell to render data in the grid. I don't think the kind of cell you want exist in GXT. So I think you will have to implement your own cell. You can take example of ColorPaletteCell, which allow the user to select a color from the cell itself.
So you will need to implement the render and onBrowserEvent methods to manage your radio buttons and what append when the user click on it.

Can user add new Sections in a view?

I am using eclipse 3.6 and developing RCP application with java 6.
I am using the Section and trying to let the use able to add new n-sections. I need the text in the field after that.
Now the User can see a section. I need that he is able to add a n-sections and then to write text in stopRouteStreet-field. I would like to read all the n Text written in this field.
Any idea how to do this?.
Here is my code
Section sectionStop = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TWISTIE|Section.TITLE_BAR);
td = new TableWrapData(TableWrapData.FILL);
td.colspan = 2;
sectionStop.setLayoutData(td);
sectionStop.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
form.reflow(true);
}
});
sectionStop.setText(Messages.SearchMapView_endPoint); //$NON-NLS-1$
Composite sectionClientStop = toolkit.createComposite(sectionStop);
sectionClientStop.setLayout(new GridLayout());
final Composite stopComposite = toolkit.createComposite(sectionClientStop, SWT.NONE);
final GridLayout gridLayoutStop = new GridLayout();
gridLayoutStop.numColumns = 2;
stopComposite.setLayout(gridLayoutStop);
toolkit.createLabel(stopComposite, Messages.SearchMapView_Street);
stopRouteStreet = toolkit.createText(stopComposite, "", SWT.BORDER); //$NON-NLS-1$
sectionStop.setClient(sectionClientStop);
You need a global variable (a HashMap would do), that saves a mapping between each newly created Section and the Text control.
// define global field
HashMap <Section, Text> dynamicControls = new HashMap <Section, Text> ();
// after you create the text field, save the newly created Text field
....
...
dynamicControls.put(section, text);
// Later when you need to read the values in all the text fields
for(Section s: dynamicControls.keySet()){
Text textField = dynamicControls.get(s);
System.out.println(textField.getText());
}