ControlsFx BreadCrumbBar setOnAction event listener issue - javafx-8

I am trying to add a BreadCrumbbar to my JavaFx application using ControlsFx library.
It is getting added but i am not able to add listener to listen for any click action on my breadcrumbbar.
I have tried setonCrumbAction() function but not able to exactly implement that.
Any sample for same would be really helpful
Thanks in advance

Try following code.
breadCrumBar.setOnCrumbAction(new EventHandler<BreadCrumbBar.BreadCrumbActionEvent<TreeItem<?>>>()
{
#Override
public void handle(BreadCrumbActionEvent<TreeItem<?>> event)
{
// TODO Auto-generated method stub
}
});
Hopefully it will resolve your issue

Related

GWT - How to handle multiple handlers for the same event

I'm currently working on a GWT project. I have a common block shared between multiple pages. I have some action buttons on that common block and the pages have a handler for the event launched on the click of those action buttons.
The problem I'm facing is that when I click on one of those action buttons on Page A, the handler from Page B previsouly registered would be called too.
So the solution I thought of was to remove the handler from a page when we leave it so there would be only one page at once with a registered handler to the same action button event.
First, I register to the action button click events and save the HandlerRegistration object returned from the addHandler method:
HandlerRegistration actionButtonClickEventHandlerRegistration=eventBus.addHandler(CommonBlockActionButtonClickedEvent.TYPE, someHandler);
And then, on page change event, I call removeHandler from the previously saved HandlerRegistration object
eventBus.addHandler(PageChangeEvent.TYPE, new PageChangeEventHandler() {
#Override
public void onMainPageChange(PageChangeEvent event) {
actionButtonClickEventHandlerRegistration.removeHandler();
}
});
So I do that on every pages, except that when I lauch my app and go to two of those pages, I get this error:
Caused by: java.lang.AssertionError: redundant remove call
Do you guys have any idea of why I'm getting this error or another way to solve my issue ?
Thanks a lot !
I would set the handler to null after removing it and I would check if it is actually null before removing it.
Like this:
eventBus.addHandler(PageChangeEvent.TYPE, new PageChangeEventHandler() {
#Override
public void onMainPageChange(PageChangeEvent event) {
if(actionButtonClickEventHandlerRegistration != null ) {
actionButtonClickEventHandlerRegistration.removeHandler();
actionButtonClickEventHandlerRegistration = null;
}
}
});
Nevertheless you seem to remove the handler at least twice and should check your program logic for that.
A good approach to do that is to set a breakpoint in the debugger (of your browser) on the line removing the handler. If you look at the call stack for every call to it, you should be able to spot the duplicate call and fix it.

How to close a dialog in code?

So I'm making a eclipse plugin and I have a made my own dialog by extending the dialog class.
My dialog basically populates a treeview with data from a server. Sometimes the data cannot be populated (because the server is down) so my treeview is empty.
I have made another dialog appear reporting the error if I am unable to connect to the server.
My problem is that I would like to close the initial dialog when I press ok in the error dialog.
I have not been able to find a good way to do this.
I have tried setting setBlockOnOpen to false.
I have tried calling cancelPressed.
Neither of them have worked.
I called them in the createDialogArea function.
Any Ideas on how I could get this to work?
It is basically user cancelling dialog. you need to invoke cancelPressed() so it will be consistent handling if you have any code that depends on returnCode
if(noDataLoaded){
Display.getDefault().asyncExec(new Runnable() {
public void run() {
cancelPressed():
}
});
}
You need to do the close call after the dialog creation has finished. You can do this by using this code:
parent.getDisplay().asyncExec(new Runnable()
{
#Override
public void run()
{
close();
}
});
in your createDialogArea method. However the dialog may appear briefly. It would be better to do your check before creating the dialog.

Finish an activity from other activity

I have called two activities as intent. One activity is loaded in background and another activity is called on top of that, by setting the theme 'dialog', so that it looks like a dialog. Now I need to finish the background activity when the dialog activity is finished.
can anybody suggest a way to accomplish this.
Thanks in advance.
Sundeep.S.
Override onRestart method of your first activity, and call finish() there, as shown below.
#Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
finish();
}
This may help you out, I guess.

Eclipse Modeling Framework: Linking an alternative view to the model

I have an ECore model I exploit to automatically generate the model source and JFace edit package. I am trying to develop an alternative view for contents of that model, basically a graph view based on JFreeChart. I have managed to create a JFreeChart based view plugin. Now I need to link the view with the model. How can I do that? I would like to edit the model with the TreeBased editor and see the effects of such editing in the graph view. Is that possible?
thank you
If you open your Graphbased-View ask for the IFile of the current opened editor. After you got the file, you can load the model (see the generated Editor how to load the Model from the underlying resource) attach a IResourceChangeListener to get a notification, if the underlying IFile of your EMF Model changed.
After a notification you can reload the model from your file and show the model in your view.
In addition you have to register a PartListener to get a notification if the user brings another emf-editor to top or he closes the editor (you also have to unload (on close) or refresh (another editor with your emf-model was brought to top).
Yes, it is, as the generated EMF code provides a notification layer: use EObject.eAdapters to add a new adapter, that is notified if the model is changed.
object.eAdapters().add(new Adapter() {
public void setTarget(Notifier newTarget) {
// TODO Auto-generated method stub
}
public void notifyChanged(Notification notification) {
// TODO Auto-generated method stub
}
public boolean isAdapterForType(Object type) {
// TODO Auto-generated method stub
return false;
}
public Notifier getTarget() {
// TODO Auto-generated method stub
return null;
}
});
Ok I have managed to do that following the Zoltán suggestions. Anyway I admit I would have preferred a more structured answer, and that is why I am answering my own question with a brief summary of the solution.
basically the idea is that a view plugin implements the ViewPart interface. Because of this it can actually invoke the following methods
getSite().getWorkbenchWindow().getSelectionService()
in order to get the workbench selection service. You can therefore invoke the SelectionService method
addSelectionListener(ISelectionListener listener)
passing as parameter your own ISelectionListener which can be the same ViewPart you are implementing. You just have to implement the ISelectionListener interface and thus provide an implementation of the selectionChanged method
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection)

[GWT]Block the event of the browser in the case of link

I want to handle the event in the case of link by my own event listener.If we click on a link in browser, browser will open the address given in the link but i want to call my own event listener. I tried to do it in GWT by removing the attribute of the anchor tag which worked but it is not a clean solution.
So if you are having any idea how to block the browser from opening that link please reply.
In GWT 1.6 the correct code is:
ClickHandler foo = new ClickHandler() {
public void onClick(ClickEvent event) {
/// do your stuff
event.stopPropagation(); // stops the event from bubbling to parent
event.preventDefault(); // prevents the browsers default action,
// following a link, etc
}
}
This is roughly equivalent to:
Link
Isn't that what this widget does:
http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/ui/Hyperlink.html
eg: it looks like a normal hyperlink but lets you handle the onclick event?
You can just call event.cancel() (GWT 1.6) or
Event.getCurrentEvent().cancelBubble(true); // In 1.4 and earlier
DOM.eventCancelBubble(DOM.eventGetCurrentEvent(), true); // In 1.5
There is also a method to cancel an event from its instance within GWT 1.5, but I can't remember.