Auto Selection on Eclipse Widget Combo option - eclipse

I would like to select widget combo first option by default which is in read only mode.Any suggestion

The select method of Combo sets the selected item.
Combo combo = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
combo.setItems(... items array ....);
// Select first item
combo.select(0);
Note that this does not generate a selection changed event. To do that you need to use the notifyListeners call:
Event event = new Event();
event.widget = combo;
event.display = combo.getDisplay();
event.type = SWT.Selection;
combo.notifyListeners(SWT.Selection, event);

Related

Knockout select binding

How to prevent select change event fires when the select biding is initiated? an add button on the page that will add select dynamically to the DOM. when each select box is adding to the DOM, the change event is firing rather than I select the item from the select?
The thing is that KnockoutJS attempts to find which element of your listbox matches the requiredItem observable. There is none in the beginning, which is why it then attempts to set it to the "caption" of the listbox. You did not provide one, so it sets requiredItem to the first element of the listbox.
What you could do is add a caption item to your array:
self.requireditems = ko.observableArray([
{ desc: "Select an option from the list...", key: 0, editable: false } // ... and then all other items]);
and if you really don't want requiredItem to be updated:
self.selectedItem = ko.observable(self.requiredItems()[0]);
Then if you want to know if a valid element has been selected from the list, you could add the following property:
self.isValidSelectedItem = ko.computed(function() {
return self.selectedItem().id;
});

GWT ListBox detect when value is re-selected

I'm having a problem using a GWT listbox. I have a case where the user selects a value from a listBox, but it can become invalidated if they change data in a related field. To validate the listBox, the user has to either select a new value, or confirm their old selection by selecting the same value again. I can't figure out how to determine if they have selected the same value so that I can restyle the listBox to look validated.
The valueChanged handler only detects if a new value is selected. The clickHandler and focusHandler fire too often because they fire when the user isn't selecting a value. Any ideas?
You can improve the clickHandler with something like this :
ignoreClick = true;
lastSelection = -1 ;
....
listBox.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
if (!ignoreClick) {
lastSelection = listBox.getSelectedIndex();
}
ignoreClick = !ignoreClick;
}
});
I tried it and the event was only fired if you selected an item. But you should rethink your user interface , like said above.

GWT:how to get the value of a checkbox of a cellTable

I have this situation , i want to delete the objects in this celltable whose checkbox is Check on the clik of this "Delete" Button ,
Any idea how to get those objects whose checkbox is checked in this cellTable, when i click the delte button ..
Thanks
#junaidp, As you haven't provided any code, I'm assuming that you have used CheckBoxCell to generate checkbox column and assigned MultiSelectionModel to your cellTable. You can use the following code:
Set<T> selectedObjects = ((MultiSelectionModel<T>)(cellTable.getSelectionModel())).getSelectedSet();
Here selectedObjects will be of type T, that you should have specified as CellTable<T>.
selectedObjects will be objects, associated to checked rows only.
You can check for a given cell's selected status with:
Column<CellInfo, Boolean> checkColumn =
new Column<MemberInfo, Boolean>(new CheckboxCell(true, false)) {
public Boolean getValue(CellInfo object) {
// Get the value from the selection model.
return selectionModel.isSelected(object);
}
};
If your requirement with delete single row, then You can use SingleSelectionModel otherwise MulitiSelectionModel in celltable. I have written some code with single selection model,It may give some idea. i.e.
selectionModel = new SingleSelectionModel<T>();
cellTable.setSelectionModel(selectionModel) //Set into your cellTable:
When you select a checkbox, then row will auto selected and object will set in to selection model.
CheckboxCell checkboxCell=new CheckboxCell(true, false);
Column<T, Boolean> boolColumn=new Column<T, Boolean>(
checkboxCell) {
#Override
public Boolean getValue(T object) {
return selectionModel.isSelected(object);
}
};
On delete button click,use selected object,It will provide you a object for delete.
selectionModel.getSelectedObject();

How to select an item in SmartGWT SelectItem?

I have a SelectItem object which has a few items. I set a value MAP with:
organizations[0] = "A";
organizations[0] = "B";
selectItem.setValueMap(organizations);
When displayed, the combo box is showing "A" as selected item. Then, I need to programatically select value "B" and select this on the current SelectItem object. I've been looking all over the place with no avail.
Anyone?
If you want any option of selectItem to be manually selected, then you should try following:
selectItem.setValue("B");
After doing this when you open the picklist of the selectItem, value "B" will be highlighted.

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.