Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [DataBinding] TableViewer with detail fields; Validation issues
[DataBinding] TableViewer with detail fields; Validation issues [message #644268] Fri, 10 December 2010 10:22
Code Monkey is currently offline Code MonkeyFriend
Messages: 4
Registered: December 2010
Junior Member
Dear all!

I'm searching for a best practice of something that I think is pretty much standard: A table that can be edited through detail fields (no inline editing). Contents of the table come from an ObservableList. The table selection is observed and bound to the detail fields (see code below). I have got everything working so far except the validation. The problem appears when nothing is selected in the table or the table is empty, which happens at least after startup. Without the selection the detail fields are bound to a null object which obviously causes all validations to fail. What I need is some way of temporary disabling binding or validation so there will not be displayed any error. The only way know to solve this, is to remove the binding every time the selection goes away and rebind if selection is no null. But this seems ugly to me. Is there a smarter way to do this?

(Code Monkey)

Here is the binding code (I left out the Validators here):

foerderungSelection = ViewersObservables.observeSingleSelection(foerderungViewer);
		ObservableListContentProvider contentProvider =
		    new ObservableListContentProvider();
		foerderungViewer.setContentProvider( contentProvider );
		    new ObservableMapLabelProvider(BeansObservables.observeMaps(
			        new String[] {
			        	"foerdergeber", "foerderprogramm", "projektnr", "rolleFh",
		        		"ansprechperson", "notiz" } )) {
		    	public String getColumnText(Object element, int columnIndex) {
		    		if (columnIndex == 0) {
		    			if (element != null) {
		    				if (((Foerderung)element).getFoerdergeber() != null) {
		    					return ((Foerderung)element).getFoerdergeber().getBezeichnung();
		    			return null;
		    		return super.getColumnText(element, columnIndex);
		IObservableValue guiFoerderungGeberFHAuswahl = ViewersObservables.
		IObservableValue guiFoerderungRolleFHAuswahl = ViewersObservables.
		IObservableValue guiFoerderungProgrammText = SWTObservables
			.observeText(foerderungProgrammText, SWT.Modify);
		IObservableValue guiFoerderungAnsprechpersonText = SWTObservables
			.observeText(foerderungAnsprechpersonText, SWT.Modify);
		IObservableValue guiFoerderungProjektnrText = SWTObservables
			.observeText(foerderungProjektnrText, SWT.Modify);
		IObservableValue guiFoerderungNotizText = SWTObservables
			.observeText(foerderungNotizText, SWT.Modify);
		// binding der detail ansicht zu aktuellen auswahl in der tabelle	
		bindingContext.bindValue(guiFoerderungGeberFHAuswahl, BeansObservables
				.observeDetailValue(foerderungSelection, "foerdergeber", Foerdergeber.class));
		bindingContext.bindValue(guiFoerderungRolleFHAuswahl, BeansObservables
				.observeDetailValue(foerderungSelection, "rolleFh", FoerderungRolleEnum.class));
		bindingContext.bindValue(guiFoerderungProgrammText, BeansObservables
				.observeDetailValue(foerderungSelection, "foerderprogramm", String.class));
		bindingContext.bindValue(guiFoerderungAnsprechpersonText, BeansObservables
				.observeDetailValue(foerderungSelection, "ansprechperson", String.class));
		bindingContext.bindValue(guiFoerderungProjektnrText, BeansObservables
				.observeDetailValue(foerderungSelection, "projektnr", String.class));
		bindingContext.bindValue(guiFoerderungNotizText, BeansObservables
				.observeDetailValue(foerderungSelection, "notiz", String.class));

Previous Topic:Embedding images in a org.eclipse.ui.editors.text.TextEditor
Next Topic:How to set a initial value of the line height when you creae a tableviewer
Goto Forum:

Current Time: Mon Jun 18 07:56:47 GMT 2018

Powered by FUDForum. Page generated in 0.02218 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top