Issue with Gwt-Radio Button - gwt

I am using same group name for two of my GWT-RadioButtons. When I click one of these, another one gets unchecked, which is good. But programmatically (when i do debug) the other radio button value is still remained as 'true' . As per my requirement it should be false. I am thinking that it is problem of GWT-RadioButton Group concept.
Does this problem of GWT - RadioButton?
The below is code snippet
indiaRadioBtn.setValue(true);
indiaRadioBtn.addClickHandler(new IndianRadioClickHandler());
othersRadioBtn.addClickHandler(new InternationalRadioClickHandler());
if (contactInfo != null) {
if (contactInfo.getPostalAddress().getCountry() != null) {
othersRadioBtn.setValue(true);
}
if (indiaRadioBtn.getValue()) {
index = -1;
for (StateOrProvince stateOrProvince : StateOrProvince.values()) {
index++;
if ((contactInfo.getPostalAddress().getState() != null)
&& contactInfo.getPostalAddress().getState().equals(stateOrProvince.name())) {
stateListBox.setSelectedIndex(index);
}
}
} else {
//some code }
class IndianRadioClickHandler implements ClickHandler {
#Override
public void onClick(ClickEvent event) {
//newOrUpdateContactInfoFormPanel.clear();
ContactInfo contactInfo = getSelectedContactInfo();
/**
* Used same panel and elements for both addresses, so clearing address for Indian.
*/
if (contactInfo != null) {
if (contactInfo.getPostalAddress().getCountry() != null
|| title.equals("Create New Address")) {
contactInfo = null;
}
}
newOrUpdateContactInfoFormPanel.add(getCompleteFormPanel(contactInfo));
}
}
if contactInfo != null then it is executing that loop, i am setting othersRadioBtn.setValue(true);
So my other radio button is should set to false according to group concept.. but it is not doing its job.

Related

JavaFX custom ListCell

I'm trying to animate ListCell when they appear.
Specially I try to animate a new cell when it was just added to the list.
For now it's working pretty OK except when I scroll the ListView, then indexes get messed up and the wrong cell is animated.
I use a boolean flag (entering) in my item model to detect when a cell is used for a brand new item.
public class TimeListCell extends ListCell<MarkItem> {
private static final String BUTTON_GOTO_MARK_CLASS = "but-markgoto";
private static final String LABEL_TIME_MARK_CLASS = "track-time";
private static final String BUTTON_DELETE_MARK_CLASS = "but-markdel";
private static final String MARK_HIGHLIGHT_CURRENT_CLASS = "highlighted";
private Instant time;
private MarkItem markItem;
protected ListCellAnimation anim;
private HBox root = new HBox();
private Button go = new Button();
private Label track = new Label();;
private Button del = new Button();
private ChangeListener<? super Boolean> highlightChange = (e, o, n) -> { setHighlighted(n); };
public TimeListCell (Consumer<MarkItem> onGoto, Consumer<MarkItem> onDelete) {
root.setAlignment(Pos.CENTER);
go.getStyleClass().add(BUTTON_GOTO_MARK_CLASS);
go.setOnAction( e -> {
if (onGoto != null) {
// Trigger GOTO consumer function
onGoto.accept(markItem);
}
});
track.getStyleClass().add(LABEL_TIME_MARK_CLASS);
del.getStyleClass().add(BUTTON_DELETE_MARK_CLASS);
del.setOnAction( e -> {
// First trigger exit animation then delete item
this.animateExit(onDelete);
});
root.getChildren().add(go);
root.getChildren().add(track);
root.getChildren().add(del);
}
#Override
protected void updateItem (final MarkItem item, boolean empty) {
super.updateItem(item, empty);
if (markItem != null) {
markItem.highlightedProperty().removeListener(highlightChange);
}
if (!empty && item != null) {
markItem = item;
time = item.getTime();
track.setText(DateUtil.format(time, DateUtil.Pattern.TIME));
setGraphic(root);
item.highlightedProperty().addListener(highlightChange);
setHighlighted(item.isHighlighted());
if (anim == null) {
//Adding Animation to the ListCell
anim = new ListCellAnimation(this);
//KeyFrame[] f = getKeyFrames(types);
KeyFrame[] frames = null;
if (anim.getKeyFrames().size() == 0) {
KeyFrame[] f = anim.getPopIn(frames);
if (f != null) {
anim.getKeyFrames().addAll(f);
}
}
}
if (item.isEntering()) {
//Checking when to play Animation
animateEnter();
item.setEntering(false);
}
} else {
setGraphic(null);
}
}
/**
* Set/unset cell highlighted style for display.
*
* #param highlighted
* Whether or not to highlight the cell
*/
public void setHighlighted (boolean highlighted) {
track.getStyleClass().remove(MARK_HIGHLIGHT_CURRENT_CLASS);
if (highlighted)
track.getStyleClass().add(MARK_HIGHLIGHT_CURRENT_CLASS);
}
/**
* Animate entering cell.
*/
private void animateEnter() {
if (anim != null && anim.getKeyFrames().size() >= 0
&& (anim.getTimeline().getStatus() == Timeline.Status.STOPPED
|| anim.getTimeline().getStatus() == Timeline.Status.PAUSED)) {
anim.getTimeline().playFromStart();
}
}
/**
* Animate exiting cell.
* Trigger DELETE consumer function when animation is complete.
*/
private void animateExit (Consumer<MarkItem> onDelete) {
anim.getReversedTimeline().setOnFinished( t -> {
// Remove item from list
if (onDelete != null) {
onDelete.accept(markItem);
}
// Prepare cell for next item to use it
scaleXProperty().set(1);
scaleYProperty().set(1);
});
anim.getReversedTimeline().playFromStart();
}
public Instant getTime () {
return time;
}
}
Has anyone any idea of what could mess up the cell indexing ?
Thanks.
If a cell which is animating is reused to display an item that is not "entering", then you need to stop the current animation:
if (item.isEntering()) {
//Checking when to play Animation
animateEnter();
item.setEntering(false);
} else {
anim.getTimeline().stop();
}
In general, you seem to be assuming that any given cell is only ever used for a single item, which is certainly not the case. There may be other bugs in your code that are consequences of this assumption, but this is the main one I can see.

How can I keep an extra empty row in a SWT table?

How can I keep an extra empty row in a SWT table without adding dummy value in the model? I want to show an empty row always for the purpose of painting a rectangle around the last row? Any clue?
Scenario: The table size is going to be fixed. If I have 5 items then I want the sixth row as empty where I can draw. If I have 100 rows then I want the empty row at the 101st position and the table should scroll on some event and show that painted rectangle.
Hope to see an answer soon.
Finally I am able to add an empty row in the table without adding a dummy value in the content provider. Here is what I did:
I extended the JFace TableViewer class and overrided the refresh(), refresh(Object element) and inputChanged(Object input, Object oldInput) method. Basically in all these three methods I first remove the empty Item if there is any and then let the original jface method call happen and then I again add the new empty table item.
Below is the code which worked for me.
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
* #author amitkumar
*/
public class ExtraEmptyRowTableViewer extends TableViewer {
boolean addExtraRow = false;
public ExtraEmptyRowTableViewer(Composite parent) {
super(parent);
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow != null
&& workbenchWindow.getActivePage() != null
&& workbenchWindow.getActivePage().getActiveEditor() != null
&& workbenchWindow.getActivePage().getActiveEditor().getClass().getName().equals(
"org.eclipse.compare.internal.CompareEditor")) {
addExtraRow = true;
}
}
public ExtraEmptyRowTableViewer(Composite composite, int style) {
super(composite, style);
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow != null
&& workbenchWindow.getActivePage() != null
&& workbenchWindow.getActivePage().getActiveEditor() != null
&& workbenchWindow.getActivePage().getActiveEditor().getClass().getName().equals(
"org.eclipse.compare.internal.CompareEditor")) {
addExtraRow = true;
}
}
#Override
public void refresh(Object element) {
if (!addExtraRow) {
super.refresh(element);
} else {
removeEmptyRow();
super.refresh(element);
}
}
#Override
protected void inputChanged(Object input, Object oldInput) {
if (!addExtraRow) {
super.inputChanged(input, oldInput);
} else {
removeEmptyRow();
super.inputChanged(input, oldInput);
#SuppressWarnings("unused")
TableItem tableItem = new TableItem(getTable(), SWT.NO_BACKGROUND | SWT.NO_FOCUS);
}
}
public void removeEmptyRow() {
try {
for (TableItem tableItem : getTable().getItems()) {
if (tableItem == null || tableItem.getText() == null
|| "".equals(tableItem.getText())) {
tableItem.dispose();
}
}
} catch (Exception e) {
}
}
#Override
public void refresh() {
if (!addExtraRow) {
super.refresh();
} else {
removeEmptyRow();
super.refresh();
#SuppressWarnings("unused")
TableItem tableItem = new TableItem(getTable(), SWT.NO_BACKGROUND | SWT.NO_FOCUS);
}
}
}
Thanks...
Amit Kumar

Dynamically and Programatically Uncheck a CheckboxCell

I have a Datagrid with a CheckboxCell column. There will be some rows that cannot be checked, and the way I would like to implement this would be to handle the "checked" event and cancel it if some criteria is met. Here is the code I have tried:
Column<Job, Boolean> selectColumn = new Column<Job, Boolean>(new CheckboxCell()) {
#Override
public Boolean getValue(Job job) {
// do I uncheck the cell here?
return JobDataGrid.this.jobSelection.isSelected(job);
}
#Override
public void onBrowserEvent(Cell.Context context, Element elem, Job object, NativeEvent event)
{
super.onBrowserEvent(context, elem, object, event);
String eventType = event.getType();
if ("change".equals(eventType)) {
// do I uncheck the cell here?
}
}
};
How do I handle the event and set the checkbox to be unchecked?
If you want to prevent the change in a checkbox, you can simply cancel the native event inside your onBrowserEvent method:
event.preventDefault();
Note that if you don't update your object when a checkbox is clicked, you can always refresh() your DataGrid and the checkbox will be displayed in its original state.
If you want to make a check box uncheckable, from the UX perspective it is better be disabled.
You can create a custom check box cell where you can control every aspect of rendering of the element including disabled state:
public class UncheckableCheckboxCell extends CheckboxCell {
interface Template extends SafeHtmlTemplates {
#Template("<input type=\"checkbox\" tabindex=\"-1\" checked/>")
SafeHtml INPUT_CHECKED();
#Template("<input type=\"checkbox\" tabindex=\"-1\"/>")
SafeHtml INPUT_UNCHECKED();
#Template("<input type=\"checkbox\" tabindex=\"-1\" disabled=\"disabled\"/>")
SafeHtml INPUT_UNCHECKED_DISABLED();
}
private static UncheckableCheckboxCell.Template template = GWT.create(UncheckableCheckboxCell.Template.class);
public UncheckableCheckboxCell(boolean dependsOnSelection, boolean handlesSelection) {
super(dependsOnSelection, handlesSelection);
}
#Override
public void render(Context context, Boolean value, SafeHtmlBuilder sb) {
// Get the view data.
Object key = context.getKey();
Boolean viewData = getViewData(key);
if (viewData != null && viewData.equals(value)) {
clearViewData(key);
viewData = null;
}
if (value != null && ((viewData != null) ? viewData : value)) {
sb.append(template.INPUT_CHECKED());
} else if (value == null) {
//use null value as an indicator of unchecked and disable state
sb.append(template.INPUT_UNCHECKED_DISABLED());
} else {
sb.append(template.INPUT_UNCHECKED());
}
}
}
Then inside your getValue() method you can return null when you want the check box to be unchecked/disabled:
#Override
public Boolean getValue(Job job) {
// is my job checkable?
if (job.checkable()) {
//return null explicitly so my custom cell knows it should be rendered as disabled
return null;
} else {
return JobDataGrid.this.jobSelection.isSelected(job);
}
}

Eclipse scout cache form page

I want to cache state in form page when switching from page to page.
So : I have 3 page with forms and I want to data stays in forms when I switch from one to another.
I found this : https://wiki.eclipse.org/Scout/Concepts/Page_Detail_Form
#Override
protected void execPageActivated() throws ProcessingException {
if (getDetailForm() == null) {
PersonDetailForm form = new PersonDetailForm();
form.setPersonNr(getPersonNr());
setDetailForm(form);
form.startView();
}
}
and says that setDetailForm() caches datas
As already said, attaching a detail form to a page means the detail form will automatically be
hidden when the page gets deactivated and shown when the page gets activated (see
PageDetailFormChanged on Desktop). So the detail form actually gets cached and does not need to
be started more than once per page. This requires that the form does not get closed.
But this don't work for me.
My code is
#Override
protected void execPageActivated() throws ProcessingException {
// / Create and open form
if (getDetailForm() == null) {
MarginCalculationForm form = new MarginCalculationForm();
form.startModify();
setDetailForm(form);
}
super.execPageActivated();
}
but it stays on last page.
For example :
If I have page A,B,C and I open page A it create it self and set it to detailForm(). If I then open page B it is OK too. But if I then click on page A again it check if the detailForm() is not null (and it is not) so it stays on page B (insted of going on page A)
EDIT :
I figure that getDetailForm() is returning the right form but apparently super.execPageActivated() don't work.
I found out what was wrong.
Problem is in DefaultPageChangeStrategy class in Scout. Method pageChanged() is like this :
#Override
public void pageChanged(IOutline outline, IPage deselectedPage, IPage selectedPage) {
if (outline == null) {
return;
}
outline.clearContextPage();
IForm detailForm = null;
ITable detailTable = null;
ISearchForm searchForm = null;
// new active page
outline.makeActivePageToContextPage();
IPage activePage = outline.getActivePage();
if (activePage != null) {
try {
activePage.ensureChildrenLoaded();
}
catch (ProcessingException e1) {
SERVICES.getService(IExceptionHandlerService.class).handleException(e1);
}
if (activePage instanceof IPageWithTable) {
IPageWithTable tablePage = (IPageWithTable) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = tablePage.getTable();
}
if (tablePage.isSearchActive()) {
searchForm = tablePage.getSearchFormInternal();
}
}
else if (activePage instanceof IPageWithNodes) {
IPageWithNodes nodePage = (IPageWithNodes) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = nodePage.getInternalTable();
}
}
}
// remove first
if (detailForm == null) {
outline.setDetailForm(null);
}
if (detailTable == null) {
outline.setDetailTable(null);
}
if (searchForm == null) {
outline.setSearchForm(null);
}
// add new
if (detailForm != null) {
outline.setDetailForm(detailForm);
}
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
if (searchForm != null) {
outline.setSearchForm(searchForm);
}
}
}
And if it is activePage a AbstractPage (and not AbstractPageWithTable AbstractPageWithNode), detailForm is always null and this break behavior.
So solution is to change AbstractPage with AbstractPageWithNode and add line
setTableVisible(false);
This line is needed because if it's not the firs time launch page will not be presented. (nodePage.getInternalTable() is not null but it is empty so :
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
will present empty page.)

eclipse rcp :how to select a single cell in tableviewer?

hwo can I change the default selection behaviour of tables, I want to make a cell selected when user click it and make it editable when user double click it.
with #nonty 's help, I get what I want.
here is my cell highlighter implemention:
package com.amarsoft.rcputil;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
public class DefaultCellFocusHighlighter extends FocusCellOwnerDrawHighlighter {
public DefaultCellFocusHighlighter(ColumnViewer viewer) {
super(viewer);
}
protected boolean onlyTextHighlighting(ViewerCell cell) {
return false;
}
protected Color getSelectedCellBackgroundColor(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE);
}
protected Color getSelectedCellForegroundColor(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_WHITE);
}
protected Color getSelectedCellForegroundColorNoFocus(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_WHITE);
}
protected Color getSelectedCellBackgroundColorNoFocus(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE);
}
protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell) {
super.focusCellChanged(newCell, oldCell);
}
}
the code to use it :
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(tv,new DefaultCellFocusHighlighter(tv));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(tv) {
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
TableViewerEditor.create(tv, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
but I got new problem :
when I double click on cell to edit it's value, there is a little area at the left side of the cell is still highlighted with dark blue color
I know why :
When a text control is created with a border, the operating system includes a platform specific inset around the contents of the control.
still seeking for fixing...
Have a look at these two JFace Snippets:
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
After digging through the code, I found the following method in the ColumnViewer class:
/**
* Hook up the editing support. Subclasses may override.
*
* #param control
* the control you want to hook on
*/
protected void hookEditingSupport(Control control) {
// Needed for backwards comp with AbstractTreeViewer and TableTreeViewer
// who are not hooked this way others may already overwrite and provide
// their
// own impl
if (viewerEditor != null) {
control.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
// Workaround for bug 185817
if (e.count != 2) {
handleMouseDown(e);
}
}
public void mouseDoubleClick(MouseEvent e) {
handleMouseDown(e);
}
});
}
}
So, I overrode that function within my TableViewer subclass:
#Override protected void hookEditingSupport(Control control) {
// We know there should be an editor avaiable
// if (viewerEditor != null) {
control.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
// Workaround for bug 185817
if (e.count != 2) {
// We don't want to edit on single clicks
// handleMouseDown(e);
}
}
public void mouseDoubleClick(MouseEvent e) {
// This method is private, so copy the implementation
// handleMouseDown(e);
ViewerCell cell = getCell(new Point(e.x, e.y));
e.count--; // A hack to make things work - pretend like it's a single click
if (cell != null) {
triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
cell, e));
}
}
});
// }
}
This works for me. Tell me if it works for you.