Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to call data binding from a toolbar handler(This is related to data binding and handler coding)
How to call data binding from a toolbar handler [message #867280] Tue, 01 May 2012 08:02 Go to next message
Allan Zarsuela is currently offline Allan ZarsuelaFriend
Messages: 5
Registered: April 2012
Junior Member
Hi all,

Good day! I would like to ask for help regarding the
accessing of data binding from the handler side.Declaration of the UI component, model and binding context are declared in viewpart. The scenario is: upon clicking the next button in the toolbar the next row will be selected in the table and the databinding should be activated so that the details form in the right side will be called.I already make a working code only for table traversal in the viewpart without error. Now when I called it in the handler it kinda work but throws error.Thanks in advance! I hope I can receive a positive response. I am new to data binding and handler usage.

Regards,
Lanz
Re: How to call data binding from a toolbar handler [message #868442 is a reply to message #867280] Wed, 02 May 2012 00:58 Go to previous messageGo to next message
Allan Zarsuela is currently offline Allan ZarsuelaFriend
Messages: 5
Registered: April 2012
Junior Member
Hi all,

I addressed the error by creating instance of another databinding context in the handler as seen below:
//-->>
public class PreviousHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart part = HandlerUtil.getActivePart(event);
int currentSelectedRow= -1;
int previousRow= -1;

...
IObservableValue masterSelection = germplasmDataEntryViewPart.getMasterSelection();

DataBindingContext ctx = new DataBindingContext();
IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(germplasmDataEntryViewPart.getTextTrait1());
IObservableValue modelValue = BeanProperties.value(Germplasm.class, "trait1").observeDetail(
masterSelection);
ctx.bindValue(widgetValue, modelValue);

...
//<<--

In here I don't know why I have to create a binding on at least one UI component(textfield) just to trigger the binding in the viewpart.
Without this, databinding is not activated as I traverse the rows of the table via next,previous button in the toolbar.
Nevertheless, this works. Any ideas?

-Lanz
Re: How to call data binding from a toolbar handler [message #868456 is a reply to message #868442] Wed, 02 May 2012 02:04 Go to previous messageGo to next message
Allan Zarsuela is currently offline Allan ZarsuelaFriend
Messages: 5
Registered: April 2012
Junior Member
I'm sorry this is still wrong because creating an instance of a new databinding context in the handler conflicts with another databinding context declared
in the viewpart. So again I tried the code below for the handler. This works but throws an error:

//-->>
DataBindingContext ctx = germplasmDataEntryViewPart.getBindingContext();//new DataBindingContext();
//<<--

!ENTRY org.eclipse.ui 4 0 2012-05-02 09:52:44.968
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
at org.irri.inger.ingeris.prototype.handler.NextHandler.execute(NextHandler.java:91)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.irri.inger.ingeris.prototype.Application.start(Application.java:86)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)


Your ideas are welcome!
Thanks,
Lanz
Re: How to call data binding from a toolbar handler [message #869031 is a reply to message #868456] Wed, 02 May 2012 21:49 Go to previous messageGo to next message
Vincenzo Caselli is currently offline Vincenzo CaselliFriend
Messages: 235
Registered: January 2012
Senior Member

Hi Lanz,
making the databinding in the handler is somewhat strange: the detail view should be aware of selection change (whoever is firing it) and provide for its own databinding.

I suggest the following pattern.

1) in the view that contains the table in which the selection changes do this when you create the tableviewer
getViewSite().setSelectionProvider(viewer);
(this will fire the selection change to whoever will register for this event)

2) in the detail view, when creating the widgets do this:
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
		.getSelectionService()
		.addSelectionListener(new ISelectionListener() {
			@Override
			public void selectionChanged(IWorkbenchPart part,
					ISelection selection) {
				//Selection is changed => call the databinding
			}
		});


3) since the databindings on a new selection should be made after having removed the databindings on the old selection, it is advisable using a WritableValue attribute, which takes care of this automatically. Just do this:
define, in the detail view, a WritableValue
private WritableValue value = new WritableValue();

the use it to bind to the widgets (an example of this can be found among our tutorials (search "RCP Vision WindowBuilder: advanced databinding with CDO" on Google), just see the part after the definition of the WritableValue)

Hope this help
Let me know

Vincenzo Caselli
RCP Vision

Re: How to call data binding from a toolbar handler [message #869159 is a reply to message #869031] Thu, 03 May 2012 02:35 Go to previous message
Allan Zarsuela is currently offline Allan ZarsuelaFriend
Messages: 5
Registered: April 2012
Junior Member
Hi Vincenzo,

I'm sorry I am having a hard time implementing your suggestion. The table and the other UI components for detail information are
all in a single viewpart. The handler need to activate the data binding when the user clicks
on the toolbar item next and previous button. What I did was I created a dummy text field in the viewpart
with a dummy attribute in the model class(Germplasm); and make this this dummy text field invisible. Now it's working.
//-->> in the viewpart
dummyFieldText = new Text(grpSeedTraits, SWT.BORDER);
dummyFieldText.setBounds(304, 75, 76, 19);
dummyFieldText.setVisible(false);
//<<--

//-->> in the handler
DataBindingContext ctx = germplasmDataEntryViewPart.getBindingContext();
IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(germplasmDataEntryViewPart.getDummyFieldText());
IObservableValue modelValue = BeanProperties.value(Germplasm.class, "dummyField").observeDetail(
masterSelection);
ctx.bindValue(widgetValue, modelValue);

//<<--

You're ideas are welcome.

Regards,
Lanz
Previous Topic:D&amp;D in TextEditor
Next Topic:Custom program launcher options?
Goto Forum:
  


Current Time: Tue Mar 19 06:46:55 GMT 2024

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

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

Back to the top