TableViewer selection binding with converter and validation [message #1015538] |
Fri, 01 March 2013 02:51  |
Eclipse User |
|
|
|
Hello!
I have some trouble with a TableViewer and the selection binding. Hopefully somebody can help or explain the problem to me.
I have a simple TitleAreaDialog with a TableViewer, where the User may selected one or more things and the standard ok and cancel button. The multiselection binding works fine. But now i have to enable/disable the ok button depending on the selection in the TableViewer (Nothing selected disabled else enabled).
Pretty simple but the problem is that the validation rule is never checked and it seems that the converter is also just called when the number of selections increases.
I use the xwt databindings with validations, and converters very often but only with other widgets and had no problems. Is there a limitation with the selection binding? How could i realise something like this (without adding a selectionlistener in java code).
Here is my sample code (modified the xwt samples) maybe someone knows more about this issue.
Thanks in advance and best regards
Weinma
<Composite xmlns="http://www.eclipse.org/xwt/presentation"
xmlns:x="http://www.eclipse.org/xwt"
xmlns:j="clr-namespace:test"
DataContext="{StaticResource myCompany}">
<Composite.layout>
<GridLayout numColumns="2"/>
</Composite.layout>
<Composite.Resources>
<j:Company x:Key="myCompany">
<j:Company.employees>
<x:Array Type="j:Employee">
<j:Employee Name="Thomas" Age="32"/>
<j:Employee Name="Jin" Age="27"/>
</x:Array>
</j:Company.employees>
</j:Company>
</Composite.Resources>
<TableViewer x:style="MULTI | FULL_SELECTION | BORDER" Name="TableViewer" input="{Binding Path=employees}">
<TableViewer.multiSelection>
<Binding path="selectedEmployees" updateSourceTrigger="PropertyChanged">
<Binding.validationRules>
<j:TestValidationRule/>
</Binding.validationRules>
<Binding.converter>
<j:TestConverter/>
</Binding.converter>
</Binding>
</TableViewer.multiSelection>
<TableViewer.columns>
<TableViewerColumn width="150" text="Name" bindingPath="name"/>
<TableViewerColumn width="150" text="Age" bindingPath="age"/>
</TableViewer.columns>
<TableViewer.control.layoutData>
<GridData horizontalAlignment="FILL"
grabExcessHorizontalSpace="true"/>
</TableViewer.control.layoutData>
<TableViewer.table headervisible="true" linesvisible="true"/>
</TableViewer>
</Composite>
package test;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.e4.xwt.IValidationRule;
public class TestValidationRule implements IValidationRule {
public TestValidationRule() {
System.out.println("Created ValidationRule");
}
public IStatus validate(Object value) {
System.out.println("Validation");
return ValidationStatus.ok();
}
public Direction getBindingMode() {
return Direction.Both;
}
public Phase getPhase() {
return Phase.AfterConvert;
}
public IStatus validateBack(Object value) {
System.out.println("Validation back");
return ValidationStatus.ok();
}
}
package test;
import org.eclipse.e4.xwt.IValueConverter;
public class TestConverter implements IValueConverter{
public TestConverter() {
System.out.println("Created TestConverter");
}
public Object getFromType() {
return Object.class;
}
public Object getToType() {
return Employee.class;
}
public Object convert(Object fromObject) {
System.out.println("Converting");
return fromObject;
}
public Object convertBack(Object value) {
System.out.println("Converting back");
return value;
}
}
package test;
/*******************************************************************************
* Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Soyatec - initial API and implementation
*******************************************************************************/
public class Company {
protected Employee[] employees;
protected Employee[] selectedEmployees;
public Company() {
}
public Employee[] getEmployees() {
return employees;
}
public void setEmployees(Employee[] employees) {
this.employees = employees;
}
public Employee[] getSelectedEmployees() {
System.out.println("Get selected employees "+getSelectedEmployeesSize());
return selectedEmployees;
}
private int getSelectedEmployeesSize() {
int size = 0;
if(selectedEmployees != null) {
size = selectedEmployees.length;
}
return size;
}
public void setSelectedEmployees(Employee[] selectedEmployees) {
this.selectedEmployees = selectedEmployees;
System.out.println("Set selected employees "+getSelectedEmployeesSize());
}
}
|
|
|
|
|
Re: TableViewer selection binding with converter and validation [message #1015624 is a reply to message #1015584] |
Fri, 01 March 2013 07:42  |
Eclipse User |
|
|
|
Jürgen Weinberger wrote on Fri, 01 March 2013 10:42
As i mentioned before i would prefer not to use the SelectionListener / Handler and thought this should all be possible by the validation in the binding.
The validator should just validate. You want it to disable/enable a button?
If you make the button available to the xwt form, you could use xwt to enable/disable it:
<Composite.parent.yourOkButtonAsProperty enabled="{Binding elementName=TableViewer, path=singleSelection}" />
Jürgen Weinberger wrote on Fri, 01 March 2013 10:42
Maybe another idea why the validation is not called ?
Can you check if the validator is called with single selection ("selection" instead of "multiSelection")? If yes, that may be a bug.
|
|
|
Powered by
FUDForum. Page generated in 0.04514 seconds