Eclipse e4 - Add a Closing Part handler - java

I'd like to implement an handler which is triggered every time I close a part of my Application Model.
How can I do?
For instance, every time I close such part I want to print a message thru the System Console.
Moreover is there any object (that could be injected) that provides the state of an MPart? (if it's open or close)
Thanks

You can use the addPartListener method of EPartService to add a listener for changes to the state of parts:
#Inject
EPartService partService;
...
partService.addPartListener(IPartListener instance);
Be sure to import the correct IPartListener - org.eclipse.e4.ui.workbench.modeling.IPartListener

Related

Vaadin wizard addon event fire twice

I am using Vaadin wizard addon and I have a problem with the following case:
When the user only presses forward/next step, there is no problem. However, if the user wants to go to the previous step, I am accidentally adding a Button click listener to the same event(That is my assumption. I have debugged the program and saw that if the user goes to the previous page, the event fires twice)
I have tried to remove the event listener before going to the next page, however, I could not find a method to remove all of the event listeners once. Also, I don't know where to remove them, since I could not find a function executed before the user is moved to the next page in Vaadin wizard.
I am following this example:
https://github.com/tehapo/WizardsForVaadin/tree/master/wizards-for-vaadin-demo/src/main/java/org/vaadin/teemu/wizards
Is there a method to remove all of the ClickListeners?
If it exists, where should I add that functionality?
Also, I am using ListDataProvider and NativeSelect components too.
NativeSelect has HasValue.ValueChangeListener<String> listener and in the default implementation, I Could not find a method such that I can use this:
NativeSelect<String> select = new NativeSelect<>("List");
select.addValueChangeListener(new HasValue.ValueChangeListener<String>() {
// some overwritten valuechange method
}
select.removeValueChangeListener(); // This does not exist
I am setting the click listener in the public Component getContent() {} method
In Vaadin 8 you need to use the Registration interface to remove Listeners.
When you add a Listener it will return the Registration:
final Registration registration = select.addValueChangeListener(this::doSomething);
And then to remove it:
registration.remove();

Hazelcast nodes not get the first published message

I have two nodes. Both of them are subscribed for a topic.
When one of the nodes publishes a message, the other one not get the message at first time. If the node publishes a message second time, then the other node gets the message.
If i call hazelcastInstance.getTopic(TopicX) at the application initialization phase, message listeners work as desired.
I think it is about lazy-init attribute.
Is there more reliable way not to face this problem? Reliable-topic could be solution?? If so, is there any sample code to implement reliable topic with spring?
#vourla, I’d suggest using ReliableTopic since it’s backed by RingBuffer & as long as backing ringbuffer is not full, listeners can read the first message properly.
Also, please see the related doc section: https://docs.hazelcast.org/docs/3.11.1/manual/html-single/index.html#configuring-reliable-topic
Instead of adding listener programatically, add it via configuration. Also, for Topic, since events are fire and forget, if you add the listener after the event fired from another node, you wont get it, whether you define it programatically or via config, but with ReliableTopic, both should work.
You can check the Spring releated doc section & related code samples as well: https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-configuration
#gokhan-oner, thank you for the answer.
Actually I tried to implement reliable-topic at first. But I couldn't find sample implementation in spring. Syntax is a little different in spring.
Now, the implementation is done like this:
<hz:hazelcast id="instance">
<hz:ringbuffer name="topicX" capacity="1000" time-to-live-seconds="5"/>
<hz:ringbuffer name="topicY" capacity="1000" time-to-live-seconds="5"/>
<hz:reliable-topic name="topicX" topic-overload-policy="BLOCK"/>
<hz:reliable-topic name="topicY" topic-overload-policy="BLOCK"/>
</hz:hazelcast>
But, declaratively implementing topic listeners not worked. I addded listeners programmatically when context is initializing.
What is not working for me:
<hz:reliable-topic name="topicZ" topic-overload-policy="BLOCK">
<hz:message-listeners>
<hz:message-listener class-name="tr.com.test.HazelcastTopicListener"/>
</hz:message-listeners>
</hz:reliable-topic>
What is working:
HazelcastTopicListener hazelcastTopicListener = new HazelcastTopicListener();
HazelcastInstance hazelcastInstance = SpringIntegration.getBean(HazelcastInstance.class);
ITopic<Message> testTopic= hazelcastInstance.getTopic("topicZ");
testTopic.addMessageListener(hazelcastTopicListener );
#vourla, please check the hazelcast-spring-XX.xsd file. Attribute name is class-or-bean-name, not class-name. Can you try like below:
<hz:reliable-topic name="topicZ" topic-overload-policy="BLOCK">
<hz:message-listeners>
<hz:message-listener class-or-bean-name="tr.com.test.HazelcastTopicListener"/>
</hz:message-listeners>
</hz:reliable-topic>

How to get notifications when xtext's EMF model changes with proper values

We have a FormEditor containing four pages: three FormPages and fourth page is XTextEditor as a source page.
Whenever user makes any changes (e.g. changing value in text box) on FormPages, we change EMF model content inside XTextDocument.modify() method as given below:
xtextEditor.getDocument().modify(new IUnitOfWork.Void<XtextResource>() {
#Override
public void process(XtextResource state) throws Exception {
IParseResult parseResult = state.getParseResult();
Assert.isNotNull(parseResult);
EObject rootASTElement = parseResult.getRootASTElement();
if (rootASTElement instanceof MyModel) {
XyzType t = ((MyModel) rootASTElement).getXyzType();
t.setName(name); <- ‘name’ is the new value entered on FormPage text box
}
}
});
Now, we want to get notifications in FormPages, whenever EMF model gets changed when user makes some changes on source page i.e. XTextEditor.
We tried adding IXtextModelListener and IXtextDocumentContentObserver to IXtextDocument; but these get called for every character entered in XTextEditor.
Our requirement is to get notifications only when values in EMF model get changed (and not for text formatting e.g. when whitespace is inserted/removed).
Can somebody please provide some pointers?
Regards,
Akhil
You can use the EMF Client Platform (ECP), which adds an implementation of an Observer Bus to an EMF model.
They implement an own validation service which does what you described:
ecp.view.validation
This is the validation service, which monitors the domain model and
calculates validation errors.
The validation service already uses the Observer Bus of ECP to register to EMF change events. The Observer Bus itself is implemented as an EContentAdapter listening to every change of the model. It already filters the change events and provides them following the Observer Bus pattern to the event bus which you can register. There you only get the events you registered to and not all events as for the EContentAdapter which you have to filter for yourself.
I think they mainly use it to validate models to show results in their EMF Forms GUI. However, you can use the services also standalone.

SmartGWT: dynamically adding custom widget to VStack

I need some widgets that share the same code base, thus I introduced an abstract class providing these shared members and methods and created an implementation which adds additional functionality. but every time I wanted to add this to a VStack I got the following error:
java.lang.AssertionError: A widget that has an existing parent widget may not be added to the detach list
in order to verify if this is b/c of the class hierarchy I created the same in a method, but I'm still receiving the same error. the code below should describe what I want to achieve.
public class Test extends VStack {
// constructor that adds button and a clickhandler for the button
// that will call addComplex()
public void addComplex() {
HStack stack = new HStack();
stack.setHeight("22px");
stack.addMember(new IButton("remove"));
stack.addMember(new ListBox());
DynamicForm form = new DynamicForm();
form.setFields(new TextItem());
stack.addMember(form);
addMember(stack);
}
}
when I just call
addMember(new Label(""));
I get no error.
furthermore, considering that the stuff in the method addComplex is in a separate class, and I add a new instance in the constructor of this Test-class, no error is thrown. the error is only thrown when I want to add the HStack via a button click
why can't I add this HStack to my VStack?
Update
it was b/c of the ListBox, which is a GWT component, and no SmartGWT component. this was the detail I missed.
can anybody tell me: why has a GWT widget an existing parent, and a SmartGWT widget does not? or is the error message just bogus?
the problem was that ListBox is from GWT, not SmartGWT. replacing it with the appropriate SmartGWT widget it works like a charm.
I have found, as a general rule:
Thou shalt not mix GWT and SmartGWT if thou seeketh functionality beyond the basic displaying of thine widgets.
I ran into this same exception when attempting to hide/show a DynamicForm or a VLayout that contained some plain GWT widgets... The page loaded fine, but I ran into trouble when I tried to add some hide/show interaction functionality...

GWT Autobean frozen when saving graph

I am using GWT 2.4 with the editor and request factory frameworks. I have a model, Trip, which has an Address 'origin' and an Address 'destination'. When creating a Trip via the UI, the two addresses are created automatically and assigned to the Trip. User fills out details and saves. For some reason, I am getting the 'autobean frozen error' when trying to persist to the server. This code worked in GWT 2.3 and I cant switch back. I am hoping its not a bug in GWT 2.4. Here is some sample code of what I am doing:
RequestContext request = requestFactory.request();
TripProxy trip = request.create(TripProxy.class);
trip.setOrigin(request.create(AddressProxy.class));
trip.setDestination(request.create(AddressProxy.class));
driver.edit(trip, request);
this.trip = trip;
// … on save button clicked (different method)
RequestContext request = driver.flush();
request.save(trip).with(driver.getPaths()).fire(someReceiverImpl);
Results in:
java.lang.IllegalStateException: The AutoBean has been frozen
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.checkFrozen(AbstractAutoBean.java:195)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.setProperty(AbstractAutoBean.java:270)
at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
The call to fire completes successfully but somewhere from within requestfactory, the above error is thrown. Curiously, the entity is saved on the server however, validations are not enforced. When I simplify the model and remove the Address associations, the validation and save works. My main issue is the autobean frozen error; the validation stuff is secondary.
EDIT: On further investigation I found that the entities are making it to the server okay and persisting as expected. Its upon return that the above exception is thrown. AddressProxy is a ValueProxy and it looks like RF doesnt like Trip coming back with these associations. Returning null 'fixes' the problem but this obviously wont work long term.
I know this is a lot more than you're asking for, but these 3 tips have helped me out (from here):
Trying to edit locked entity.
If an entity is frozen ( locked for changes) you cannot:
change its properties
use it in requestContext method calls.
If you try to do it, you will receive the exception : java.lang.IllegalStateException: The AutoBean has been frozen.
When entity may be frozen?
every entity returned as a response is frozen
every entity which has been used in requestContext call will be frozen.
In first situation solution is easy – you just have to unlock given entity. In order to do that you must use instance of your RequestContext class and call edit() method.
StudentRequest req1 = requestFactory.studentRequest();
StudentProxy s2 = req1.edit(s1);
In second situation you should not use given entity any more, It cannot be edited because it has already a requestContext assigned. If you want to change it you must retrieve instance of this entity from server again and follow instructions for point a).
Trying to call requestContext.edit() on entity which already has a requestContext assigned.
If you have retrieved the entity from the server or created a new one, and afterwords you are trying to use ANOTHER RequestContext to edit it e.g. in this way:
StudentRequest req = requestFactory.studentRequest();
s1 = req.create(StudentProxy.class);
// s1 is connected with "req" and one context is just enough for it
StudentRequest reqZZZ = requestFactory.studentRequest();
reqZZZ.edit(s1); // you cannot do it - here exception will be thrown
you will surely recieve an exception:
java.lang.IllegalArgumentException: Attempting to edit an EntityProxy previously edited by another RequestContext
You may run into this problem in situations where you have a bean, but you have no track of request context which has created or edited the bean in some previous method call. In this situation you must save the previous requestContext somewhere, or send it along with the entity to the point of interest. The best solution may be to create some special layer which holds currently used request.
Trying to reuse a Request Context which has already been fired.
You can use a request context to create and edit many different entities (also of a different type). You can also accumulate the methods which should be fired. But what you cannot do is to try to use it twice to fire a request. If you have created a request and call the fire() method on it, you cannot do it again. If you do you will get: java.lang.IllegalStateException:A request is already in progress exception.
The solution is to simply create a new requestContext.
This was caused by not using the same EntityManager on the server.

Categories