Can user add new Sections in a view? - eclipse

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());
}

Related

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.

How to set ImageHyperlink to have title and description like in the welcome page?

I need to draw an ImageHyperlink that looks exactly like the ones in
Eclipse's welcome page where the text consists of bold title and
description but I can't find this feature in the ImageHyperlink widget
itself, do I have to override the paintHyperlink() myself ? if so, could
someone provide a snippet?
If I read the source correctly (and it is very complex) the welcome page is actually done using HTML and not ImageHyperlink.
You an override the paintHyperlink method of ImageHyperlink:
protected void paintHyperlink(GC gc, Rectangle bounds)
so you should be able to do something similar.
Or, as an option, you can try to mimic appearance, by using standard approach of creating composites (just style it as you wish;)):
private void demoHyperlinks() {
form.getBody().setLayout(new GridLayout());
Composite container = new Composite(form.getBody(), SWT.NONE);
container.setLayout(new GridLayout());
ImageHyperlink imageHyperlink = toolkit.createImageHyperlink(container, SWT.NULL);
imageHyperlink.setText("This is an image hyperlink.");
imageHyperlink.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
imageHyperlink.setFont(new Font(form.getDisplay(), new FontData("Verdana", 20, SWT.BOLD)));
imageHyperlink.setImage(new Image(getShell().getDisplay(), "images/help.gif"));
imageHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
#Override
public void linkActivated(HyperlinkEvent e) {
System.out.println("Image hyperlink activated.");
}
});
Composite descriptionContainer = new Composite(container, SWT.NONE);
GridLayout gl = new GridLayout();
gl.marginLeft = 25;
descriptionContainer.setLayout(gl);
Hyperlink hyperlink = toolkit.createHyperlink(descriptionContainer, "This is a hyperlink link", SWT.NULL);
hyperlink.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
HyperlinkGroup group = new HyperlinkGroup(getShell().getDisplay());
group.add(imageHyperlink);
group.add(hyperlink);
group.setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_NEVER);
}

How to pass a Parameterized Command to a CommandContributionItem

Using Eclipse and SWT I am currently trying to get a CommandContributionItem (CCI) as a Button into a ViewPart with two text fields. When I push the button my ParameterizedCommand should be called using the current text values of the text fields as parameters.
I was able to pass the initial values of the text fields to the CCI like that:
public void createPartControl(Composite parent) {
parent.setLayout(new GridLayout(1, false));
text = new Text(parent, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
text_1 = new Text(parent, SWT.BORDER);
text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Map<String, String> params = new HashMap<String, String>();
params.put("myString", text.getText());
params.put("mySecondString", text_1.getText());
CommandContributionItemParameter p = new CommandContributionItemParameter(getSite(),
"commandSyso","com.voo.example.commandparameter.simple.sysoCommand", CommandContributionItem.STYLE_PUSH);
p.label = "My Label";
p.parameters = params;
CommandContributionItem item = new CommandContributionItem(p);
item.fill(parent);
}
But it is a static one-time pass. Is there a way to update this dynamically every time the CCI is called?
CommandContributionItem parameters are static in nature. You can't modify them, only create a new instance of CommandContributionItem.
When working with commands, implementation of IHandler should look for the current selection using the ExecutionEvent.getApplicationContext(). If it is an IEvaluationContext, the selection can be retrieved using org.eclipse.ui.handlers.HandlerUtil
But in your example, you would need some way to supply the values of your 2 text fields to the framework, either by implementing an ISelectionProvider, an ISourceProvider (where you could provide each text field under a new name), or by having your handler check for your IViewPart and then access the information through accessors.

How to coloriate differently even rows and odd rows of a List in 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).

Editable SWT table

How to edit SWT table Values without Using Mouse Listeners?
Do the TableEditor snippets in the below link help?
SWT Snippets
The first example in the TableEditor section uses a SelectionListener on the table (unlike the second example which uses a MouseDown event you mentioned you don't want)
You could perhaps make use of the TraverseListener or KeyListener too to help you achieve what you want.
final int EDITABLECOLUMN = 1;
tblProvisionInfo.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
// Clean up any previous editor control
final TableEditor editor = new TableEditor(tblProvisionInfo);
// The editor must have the same size as the cell and must
// not be any smaller than 50 pixels.
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.minimumWidth = 50;
Control oldEditor = editor.getEditor();
if (oldEditor != null)
oldEditor.dispose();
// Identify the selected row
TableItem item = (TableItem) e.item;
if (item == null)
return;
// The control that will be the editor must be a child of the
// Table
Text newEditor = new Text(tblProvisionInfo, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent me) {
Text text = (Text) editor.getEditor();
editor.getItem()
.setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
Here tblProvision is the name of your table. you can just now edit Your table by clicking on it. I have Declare EDITABLECOLUMN. this is the column that u want to edit.
If you can use JFace as well and not just pain SWT, have a look at the JFace Snippets, especially
Snippet036FocusBorderCellHighlighter - Demonstrates keyboard navigation by highlighting the currently selected cell with a focus border showing once more the flexibility of the new cell navigation support
Snippet034CellEditorPerRowNewAPI - Demonstrates different CellEditor-Types in one COLUMN with 3.3-API of JFace-Viewers
You can get or set the value of a item, for example:
Table table = new Table(parent, SWT.NONE);
TableItem item = new TableItem(table, SWT.NONE);
item.setText("My new Text");
I suggest you to us TableViewer, it is very powerful table which it you can use databinding very easy too.