| [news.eclipse.tools.emf] Re: newbiew qn: how to add a viewer to the EMF editor plugin |
Charles,
Comments below.
Thanks EdThis makes me think you aren't so much tracking user's changes but something else since users always want to be able to undo the changes they make directly.
So while the undo feature of EMF is quite nice, for my application, I don't really need it. What I need (I think) is to know the best way to acquire and release a lock on an EMF resource.
See, I need to be able to track when the resource lock is acquired and when it is released because I need to synchronize my views (plots) with the default resource editor. This is because plots can take up to 1 minute to compute, and I don't want to lock the entire GUI while the plot calculations are running. But at the same time, I don't want the user editing the EMF resource while a plot is being computed. That is, I don't want the user to try to reload the EMF model from the database, or to change any of the EMF model attributes. So I would like to detect when the Plot View acquires the lock on the EMF resource so the Editor Load Action can be disabled.This makes me think that in some ways it's more like a wholesale resource update kind of issue and obviously isn't a set of user changes you'd want to undo. In fact, it's probably most similar to how the editor would respond after getting a resource delta in the workspace. I.e., the existing model needs to be unloaded, reloaded with the new version, and then command stack needs to be flushed because the state is inconsistent.
At first it seemed as if the EMF Transaction Model would be a good choice, but I am not 100%. Certainly I do want to be able to load a resource and modify it, and the EMF Transaction Model supports this.Yes, that part is good, but I do get the sense there is more going on than just editing. I.e., I don't see the plot generation as an undoable editing step.
But it also seems that here I need to acquire a lock the EMF model without ever modifying it (except, perhaps, to set a flag saying that the lock has been acquired)It's possible via the editing domain to mark a resource as read only and thereby disable all modification commands for it.
So what I am little unclear on, however, is how to know when the lock as actually be acquired by the TransactionEditiongDomain, or whether I should simply ad a flag to my EMF model to indicate is locked?I get the sense that perhaps you should be generating the plot as a separate job that does it's work in the background and whose behavior is not visible to the UI. Perhaps during that period, editing of the model should be prevented by making the resource behave as if it's read only. Likely before the job begins, you'd need to consider if the model is already dirty and if the end result of the job would be to lose changes.
I'm not entirely clear how the generated plot relates to what the user is editing. Are there really two models? The data being fed into the plot and the plot that's produced from their data? Is the later editable or only the former? If only the input data is editable and the plot is like a derived model, you'd probably want to have a read transaction for the data and cooperatively yield so that the UI isn't locked out. When the plot is done, you'd likely want to completely replace the plot currently being viewed. I.e., don't modify the existing plot but rather replace it after it's recomputed...
I assume the (only) way to do this is to use an EditingCommand to set a flg on the EMF model to indicate a lock has been aquired, and to attach a Resource ResourceSetListener to the TranactionalEditingDomain that sends processing the notification that that the resource has been changed.
Or perhaps I should just be using the standard Eclipse locking mechanism in the Eclipse 3.0 Jobs API What makes this a bit confusing is some of the on-line example assumes the use of the ResourcesPlugin (i.e. not an RCP):Unfortunately, assumptions about workspace resources being used have tended to permeate a lot of APIs. I suspect you would want to make use of Jobs for this type of thing; the transaction support will help with controlled access from such jobs.
EMF's resources are designed to support a purely RESTful style of access. No assumptions are made about how the contents for URIs are set and retrieved and all access is delegated to the URIConverter; EMF 2.4 strengthens these APIs further to support the full life cycle, including delete. Eclipse's workspace is more analogous in some ways to a repository where you can always know the full closure of all the data known to the application (what I often refer to as a closed world model as opposed to REST which is an open world model because the data space knows no bounds).http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html
I guess it is still just a bit confusing how the EMF use of resources differs from the Eclipse ResourcesPlugin ?
At first I naively thought I could just take advantage of the Eclipse Resources Plugin and the ResourceChangeNotifications there, but after having look at this a while, it appears that this is NOT the thing to do with EMF (especially for an Eclipse EMF RCP).I suppose you could if the plot itself was saved to a resource and the editor was displaying the contents of that resource.
Of course, I could just "punt" and use the Java 1.5 Concurrency Libraries and manage the locks myself, but this just does not seem to be the Eclipse way or the EMF way.I think you'd likely want to use jobs.
Again, any clarification is appreciated, and I am continuing to plug through as much of this as I can.Probably I don't quite understand how the user's data is related to the plot and if the plot itself is editable or just something that's viewed.
Yes, I suppose the question is do you want to have a plot resource that keeps itself up-to-date whenever the inputs change. Certainly that approach turns it into a simpler problem of unload and reloading a resource based on a workspace delta...Thanks again
Charles
P.S. I have also considered using the Eclipse framework for Natures and Builders to treat my calculations like a compilation, and to have a "run button" . Still, this is a bit of an overkil for what I am doing presently, and I still am not 100% sure how to intermingle this with EMF, and within an RCP.