Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » model autosave
model autosave [message #656655] Sun, 27 February 2011 23:55 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 424
Registered: September 2009
Senior Member
Hi,
I want to save automatically the model shortly after modification to a
temporary location to salvage as much as possible in the [un]likely
event of a crash.

In order to do so I attached a ChangeAdapter to the model:

getResource().setTrackingModification(true);
mta = new ChangeMonitor();
getResource().eAdapters().add(mta);

where:

private final class ChangeMonitor extends AdapterImpl {
@Override
public void notifyChanged(Notification msg) {
super.notifyChanged(msg);
synchronized (saveDate) {
changeDate = new Date();
}
if (saveJob == null) {
saveJob = new Job("saveJob") {
@Override
protected IStatus run(IProgressMonitor monitor) {
Date now = new Date();
System.out.println("saveJob():");
if (tmp == null)
try {
newTmp();
} catch (FileNotFoundException e) {
return new Status(Status.ERROR,
"it.condarelli.writer.model", "saveJob(): unable to get tmp file:
'"+e.getMessage()+"'");
}
saveTmp();
synchronized (saveDate) {
if (changeDate.before(now)) {
changeDate = null;
} else {
if (saveTmpDelay > 0)
saveJob.schedule(saveTmpDelay);
}
}
saveDate = now;
return Status.OK_STATUS;
}
};
} else {
saveJob.cancel();
}
if (saveTmpDelay >= 0)
saveJob.schedule(saveTmpDelay);
}
}

where newTmp() computes a suitable temp-file in "File tmp;" and the guts
of saveTmp() are:

public void saveTmp() {
File t = null;
try {
OutputStream os = new FileOutputStream(tmp);
try {
Map<String, String> opt = new HashMap<String, String>();
opt.put(XMLResource.OPTION_ENCODING, "UTF-8");
resource.save(os, opt);
os.close();
} catch (IOException e) {
}
} catch (FileNotFoundException e) {
}
}

This blows up because resource.save(...) does change something inside,
so ChangeMonitor.notifyChanges() is called recursively.
At the very least errors and warnings are reset.

I can (obviously) filter the changes using "Notification msg", but I am
not sure if this ie the "Right Way"(TM) to do this.

What I want to achieve is:
1) monitor changes to model.
2) wait a fixed amount of time after last change (e.g.: 1 min).
3) when timeout expired without further changes (model is "idle") save
it to a temp location.
4) when a "Save" operation is requested either save (if some unsaved
modifications exist) or rename the saved temporary to the "right"
resource name; in any case the temporary should be removed.

Is the above the right approach?
What changes should I filter out as "uninteresting" housekeeping (as
opposed to real changes in model contents?

Side issue:
I a lot of troubles because EMF defines its own URI class, but that is
not compatible with java.io.File
I ended up doing this quite often:

if (uri.isFile()) {
File f = new File(uri.toFileString());
if (f.exists())
f.delete(); // or f.renameTo(...) or some other File op.
}

Is this the right way to go?

Thanks for any comments.

Regards
Mauro
Re: model autosave [message #656828 is a reply to message #656655] Mon, 28 February 2011 17:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Hi,
> I want to save automatically the model shortly after modification to a
> temporary location to salvage as much as possible in the [un]likely
> event of a crash.
You could just listen to the stack since changes must happen as a result
of executing a command.
>
> In order to do so I attached a ChangeAdapter to the model:
>
> getResource().setTrackingModification(true);
> mta = new ChangeMonitor();
> getResource().eAdapters().add(mta);
>
> where:
>
> private final class ChangeMonitor extends AdapterImpl {
> @Override
> public void notifyChanged(Notification msg) {
> super.notifyChanged(msg);
> synchronized (saveDate) {
> changeDate = new Date();
> }
> if (saveJob == null) {
> saveJob = new Job("saveJob") {
> @Override
> protected IStatus run(IProgressMonitor monitor) {
> Date now = new Date();
> System.out.println("saveJob():");
> if (tmp == null)
> try {
> newTmp();
> } catch (FileNotFoundException e) {
> return new Status(Status.ERROR,
> "it.condarelli.writer.model", "saveJob(): unable to get tmp file:
> '"+e.getMessage()+"'");
> }
> saveTmp();
> synchronized (saveDate) {
> if (changeDate.before(now)) {
> changeDate = null;
> } else {
> if (saveTmpDelay > 0)
> saveJob.schedule(saveTmpDelay);
> }
> }
> saveDate = now;
> return Status.OK_STATUS;
> }
> };
> } else {
> saveJob.cancel();
> }
> if (saveTmpDelay >= 0)
> saveJob.schedule(saveTmpDelay);
> }
> }
>
> where newTmp() computes a suitable temp-file in "File tmp;" and the
> guts of saveTmp() are:
>
> public void saveTmp() {
> File t = null;
> try {
> OutputStream os = new FileOutputStream(tmp);
> try {
> Map<String, String> opt = new HashMap<String, String>();
> opt.put(XMLResource.OPTION_ENCODING, "UTF-8");
> resource.save(os, opt);
> os.close();
> } catch (IOException e) {
> }
> } catch (FileNotFoundException e) {
> }
> }
>
> This blows up because resource.save(...) does change something inside,
> so ChangeMonitor.notifyChanges() is called recursively.
> At the very least errors and warnings are reset.
>
> I can (obviously) filter the changes using "Notification msg", but I
> am not sure if this ie the "Right Way"(TM) to do this.
>
> What I want to achieve is:
> 1) monitor changes to model.
> 2) wait a fixed amount of time after last change (e.g.: 1 min).
> 3) when timeout expired without further changes (model is "idle") save
> it to a temp location.
> 4) when a "Save" operation is requested either save (if some unsaved
> modifications exist) or rename the saved temporary to the "right"
> resource name; in any case the temporary should be removed.
>
> Is the above the right approach?
> What changes should I filter out as "uninteresting" housekeeping (as
> opposed to real changes in model contents?
Listening to the command stack would be way more efficient.
>
> Side issue:
> I a lot of troubles because EMF defines its own URI class, but that is
> not compatible with java.io.File
Because more often than not, you're dealing with platform:/resource
which uses IFile which might not even exist in the file system
depending on the EFS implementation.
> I ended up doing this quite often:
>
> if (uri.isFile()) {
> File f = new File(uri.toFileString());
> if (f.exists())
> f.delete(); // or f.renameTo(...) or some other File op.
> }
>
> Is this the right way to go?
Aren't you dealing with workspace resources?
>
> Thanks for any comments.
>
> Regards
> Mauro
Re: model autosave [message #656850 is a reply to message #656828] Mon, 28 February 2011 19:06 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 424
Registered: September 2009
Senior Member
Thanks Ed,
Comments below.

Il 28/02/2011 18:57, Ed Merks ha scritto:
> Mauro,
>
> Comments below.
>
> Mauro Condarelli wrote:
>> Hi,
>> I want to save automatically the model shortly after modification to a
>> temporary location to salvage as much as possible in the [un]likely
>> event of a crash.
> You could just listen to the stack since changes must happen as a result
> of executing a command.
Sorry, I fail to understand You.
I have a complex model which is essentially a tree I edit in three
different ways:

1) some commands that let me insert new nodes in the tree; Later on I
want to add dreg&drop command to implement prune&graft in the tree.

2) each node type has it's own page (built around FormToolkit in
master/detail) and widgets are directly bound to model via EMF DataBinding.

3) a specific field is actually a kind of a source text and is edited
using a specialized AbstractTextEditor; upon saving this is stored in
the TEXT of one model fields (<content>Here goes the TextEditor
contents</content>).

Which "command stack" should I listen to? (please forgive me for being
naive, I'm not really an eclipse guru).

>>
>> In order to do so I attached a ChangeAdapter to the model:
>>
>> getResource().setTrackingModification(true);
>> mta = new ChangeMonitor();
>> getResource().eAdapters().add(mta);
>>
>> where:
>>
>> private final class ChangeMonitor extends AdapterImpl {
>> @Override
>> public void notifyChanged(Notification msg) {
>> super.notifyChanged(msg);
>> synchronized (saveDate) {
>> changeDate = new Date();
>> }
>> if (saveJob == null) {
>> saveJob = new Job("saveJob") {
>> @Override
>> protected IStatus run(IProgressMonitor monitor) {
>> Date now = new Date();
>> System.out.println("saveJob():");
>> if (tmp == null)
>> try {
>> newTmp();
>> } catch (FileNotFoundException e) {
>> return new Status(Status.ERROR, "it.condarelli.writer.model",
>> "saveJob(): unable to get tmp file: '"+e.getMessage()+"'");
>> }
>> saveTmp();
>> synchronized (saveDate) {
>> if (changeDate.before(now)) {
>> changeDate = null;
>> } else {
>> if (saveTmpDelay > 0)
>> saveJob.schedule(saveTmpDelay);
>> }
>> }
>> saveDate = now;
>> return Status.OK_STATUS;
>> }
>> };
>> } else {
>> saveJob.cancel();
>> }
>> if (saveTmpDelay >= 0)
>> saveJob.schedule(saveTmpDelay);
>> }
>> }
>>
>> where newTmp() computes a suitable temp-file in "File tmp;" and the
>> guts of saveTmp() are:
>>
>> public void saveTmp() {
>> File t = null;
>> try {
>> OutputStream os = new FileOutputStream(tmp);
>> try {
>> Map<String, String> opt = new HashMap<String, String>();
>> opt.put(XMLResource.OPTION_ENCODING, "UTF-8");
>> resource.save(os, opt);
>> os.close();
>> } catch (IOException e) {
>> }
>> } catch (FileNotFoundException e) {
>> }
>> }
>>
>> This blows up because resource.save(...) does change something inside,
>> so ChangeMonitor.notifyChanges() is called recursively.
>> At the very least errors and warnings are reset.
>>
>> I can (obviously) filter the changes using "Notification msg", but I
>> am not sure if this ie the "Right Way"(TM) to do this.
>>
>> What I want to achieve is:
>> 1) monitor changes to model.
>> 2) wait a fixed amount of time after last change (e.g.: 1 min).
>> 3) when timeout expired without further changes (model is "idle") save
>> it to a temp location.
>> 4) when a "Save" operation is requested either save (if some unsaved
>> modifications exist) or rename the saved temporary to the "right"
>> resource name; in any case the temporary should be removed.
>>
>> Is the above the right approach?
>> What changes should I filter out as "uninteresting" housekeeping (as
>> opposed to real changes in model contents?
> Listening to the command stack would be way more efficient.
A more detailed pointer would be *very* welcome. TiA!

>>
>> Side issue:
>> I a lot of troubles because EMF defines its own URI class, but that is
>> not compatible with java.io.File
> Because more often than not, you're dealing with platform:/resource
> which uses IFile which might not even exist in the file system depending
> on the EFS implementation.
Uhm... not my case; see below.

>> I ended up doing this quite often:
>>
>> if (uri.isFile()) {
>> File f = new File(uri.toFileString());
>> if (f.exists())
>> f.delete(); // or f.renameTo(...) or some other File op.
>> }
>>
>> Is this the right way to go?
> Aren't you dealing with workspace resources?
No.
I am editing a file in the normal filesystem (eventually over a net, but
that is not the problem). I have no workspace concept.

To give You an idea: I am doing something similar to MS-Word: I have a
complex document I need to edit and then to save in a single file that
can be moved, sent to others, reopened and re-edited using my app (or
some other app that understands the same XML schema; actually there was
another app I inherited, then I started a complete rewrite using RCP,
but the on-disk XML is basically the same).

I am calling my app with "-data @user.home/.Writer" to save Preferences
in a known place, but the actual file can be anywhere.

>>
>> Thanks for any comments.
>>
>> Regards
>> Mauro

Thanks
Mauro
Re: model autosave [message #656872 is a reply to message #656850] Mon, 28 February 2011 20:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Thanks Ed,
> Comments below.
>
> Il 28/02/2011 18:57, Ed Merks ha scritto:
>> Mauro,
>>
>> Comments below.
>>
>> Mauro Condarelli wrote:
>>> Hi,
>>> I want to save automatically the model shortly after modification to a
>>> temporary location to salvage as much as possible in the [un]likely
>>> event of a crash.
>> You could just listen to the stack since changes must happen as a result
>> of executing a command.
> Sorry, I fail to understand You.
If you look at the generated EMF editor, you'll see there's a command
stack listener already for updating the editor's dirty state.
> I have a complex model which is essentially a tree I edit in three
> different ways:
>
> 1) some commands that let me insert new nodes in the tree; Later on I
> want to add dreg&drop command to implement prune&graft in the tree.
>
> 2) each node type has it's own page (built around FormToolkit in
> master/detail) and widgets are directly bound to model via EMF
> DataBinding.
>
> 3) a specific field is actually a kind of a source text and is edited
> using a specialized AbstractTextEditor; upon saving this is stored in
> the TEXT of one model fields (<content>Here goes the TextEditor
> contents</content>).
>
> Which "command stack" should I listen to? (please forgive me for being
> naive, I'm not really an eclipse guru).
For your editor to support undo properly, you must already be using a
command stack (I assume).
>
>>>
>>> In order to do so I attached a ChangeAdapter to the model:
>>>
>>> getResource().setTrackingModification(true);
>>> mta = new ChangeMonitor();
>>> getResource().eAdapters().add(mta);
>>>
>>> where:
>>>
>>> private final class ChangeMonitor extends AdapterImpl {
>>> @Override
>>> public void notifyChanged(Notification msg) {
>>> super.notifyChanged(msg);
>>> synchronized (saveDate) {
>>> changeDate = new Date();
>>> }
>>> if (saveJob == null) {
>>> saveJob = new Job("saveJob") {
>>> @Override
>>> protected IStatus run(IProgressMonitor monitor) {
>>> Date now = new Date();
>>> System.out.println("saveJob():");
>>> if (tmp == null)
>>> try {
>>> newTmp();
>>> } catch (FileNotFoundException e) {
>>> return new Status(Status.ERROR, "it.condarelli.writer.model",
>>> "saveJob(): unable to get tmp file: '"+e.getMessage()+"'");
>>> }
>>> saveTmp();
>>> synchronized (saveDate) {
>>> if (changeDate.before(now)) {
>>> changeDate = null;
>>> } else {
>>> if (saveTmpDelay > 0)
>>> saveJob.schedule(saveTmpDelay);
>>> }
>>> }
>>> saveDate = now;
>>> return Status.OK_STATUS;
>>> }
>>> };
>>> } else {
>>> saveJob.cancel();
>>> }
>>> if (saveTmpDelay >= 0)
>>> saveJob.schedule(saveTmpDelay);
>>> }
>>> }
>>>
>>> where newTmp() computes a suitable temp-file in "File tmp;" and the
>>> guts of saveTmp() are:
>>>
>>> public void saveTmp() {
>>> File t = null;
>>> try {
>>> OutputStream os = new FileOutputStream(tmp);
>>> try {
>>> Map<String, String> opt = new HashMap<String, String>();
>>> opt.put(XMLResource.OPTION_ENCODING, "UTF-8");
>>> resource.save(os, opt);
>>> os.close();
>>> } catch (IOException e) {
>>> }
>>> } catch (FileNotFoundException e) {
>>> }
>>> }
>>>
>>> This blows up because resource.save(...) does change something inside,
>>> so ChangeMonitor.notifyChanges() is called recursively.
>>> At the very least errors and warnings are reset.
>>>
>>> I can (obviously) filter the changes using "Notification msg", but I
>>> am not sure if this ie the "Right Way"(TM) to do this.
>>>
>>> What I want to achieve is:
>>> 1) monitor changes to model.
>>> 2) wait a fixed amount of time after last change (e.g.: 1 min).
>>> 3) when timeout expired without further changes (model is "idle") save
>>> it to a temp location.
>>> 4) when a "Save" operation is requested either save (if some unsaved
>>> modifications exist) or rename the saved temporary to the "right"
>>> resource name; in any case the temporary should be removed.
>>>
>>> Is the above the right approach?
>>> What changes should I filter out as "uninteresting" housekeeping (as
>>> opposed to real changes in model contents?
>> Listening to the command stack would be way more efficient.
> A more detailed pointer would be *very* welcome. TiA!
See the generated editor.
>
>>>
>>> Side issue:
>>> I a lot of troubles because EMF defines its own URI class, but that is
>>> not compatible with java.io.File
>> Because more often than not, you're dealing with platform:/resource
>> which uses IFile which might not even exist in the file system depending
>> on the EFS implementation.
> Uhm... not my case; see below.
>
>>> I ended up doing this quite often:
>>>
>>> if (uri.isFile()) {
>>> File f = new File(uri.toFileString());
>>> if (f.exists())
>>> f.delete(); // or f.renameTo(...) or some other File op.
>>> }
>>>
>>> Is this the right way to go?
>> Aren't you dealing with workspace resources?
> No.
> I am editing a file in the normal filesystem (eventually over a net,
> but that is not the problem). I have no workspace concept.
So it's an RCP editor... Of course you can make assumption that you
know are valid in your application.
>
> To give You an idea: I am doing something similar to MS-Word: I have a
> complex document I need to edit and then to save in a single file that
> can be moved, sent to others, reopened and re-edited using my app (or
> some other app that understands the same XML schema; actually there
> was another app I inherited, then I started a complete rewrite using
> RCP, but the on-disk XML is basically the same).
>
> I am calling my app with "-data @user.home/.Writer" to save
> Preferences in a known place, but the actual file can be anywhere.
>
>>>
>>> Thanks for any comments.
>>>
>>> Regards
>>> Mauro
>
> Thanks
> Mauro
>
Re: model autosave [message #656899 is a reply to message #656872] Mon, 28 February 2011 22:24 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 424
Registered: September 2009
Senior Member
Thanks Ed,
Comments below.

Il 28/02/2011 21:28, Ed Merks ha scritto:
>>>> Hi,
>>>> I want to save automatically the model shortly after modification to a
>>>> temporary location to salvage as much as possible in the [un]likely
>>>> event of a crash.
>>> You could just listen to the stack since changes must happen as a result
>>> of executing a command.
>> Sorry, I fail to understand You.
> If you look at the generated EMF editor, you'll see there's a command
> stack listener already for updating the editor's dirty state.
>> I have a complex model which is essentially a tree I edit in three
>> different ways:
>>
>> 1) some commands that let me insert new nodes in the tree; Later on I
>> want to add dreg&drop command to implement prune&graft in the tree.
>>
>> 2) each node type has it's own page (built around FormToolkit in
>> master/detail) and widgets are directly bound to model via EMF
>> DataBinding.
>>
>> 3) a specific field is actually a kind of a source text and is edited
>> using a specialized AbstractTextEditor; upon saving this is stored in
>> the TEXT of one model fields (<content>Here goes the TextEditor
>> contents</content>).
>>
>> Which "command stack" should I listen to? (please forgive me for being
>> naive, I'm not really an eclipse guru).
> For your editor to support undo properly, you must already be using a
> command stack (I assume).

This may well be my problem.
I do not use at all neither edit nor editor.
I do use just the generated model.

This is because I did not find a way to have the generated editor work
as I like.

I do not want to have an RCP editor integrated in a generic eclipse
installation.
I want to build an application that edits my file, and thus the model.
I need something akin to RCP plugin.xml editor, but without all IDE
around it; just an editor for a single file type.

I think I missed something important, but I'm not really sure.
I do confirm I have no undo/redo in my editor (aside from the TextEditor
part, of course).

I am just plainly using DataBinding; e.g.:

private IObservableValue observableScene;

// Databinding
EMFDataBindingContext dbc = new EMFDataBindingContext();

IWidgetValueProperty text = WidgetProperties.text(SWT.Modify);
IWidgetValueProperty sel = WidgetProperties.selection();

dbc.bindValue(sel.observe(btnTitle),EMFProperties.value(it.c ondarelli.writer.model.world.WorldPackage.Literals.IBASE__UN USED).observeDetail(observableScene));
dbc.bindValue(text.observeDelayed(400,txtTitle),EMFPropertie s.value(it.condarelli.writer.model.world.WorldPackage.Litera ls.IBASE__TITLE).observeDetail(observableScene));
dbc.bindValue(text.observeDelayed(400,txtDesc),EMFProperties .value(it.condarelli.writer.model.world.WorldPackage.Literal s.IBASE__DESC).observeDetail(observableScene));


Am I doing something seriously wrong?

TiA
Mauro
Re: model autosave [message #656909 is a reply to message #656899] Mon, 28 February 2011 23:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Thanks Ed,
> Comments below.
>
> Il 28/02/2011 21:28, Ed Merks ha scritto:
>>>>> Hi,
>>>>> I want to save automatically the model shortly after modification
>>>>> to a
>>>>> temporary location to salvage as much as possible in the [un]likely
>>>>> event of a crash.
>>>> You could just listen to the stack since changes must happen as a
>>>> result
>>>> of executing a command.
>>> Sorry, I fail to understand You.
>> If you look at the generated EMF editor, you'll see there's a command
>> stack listener already for updating the editor's dirty state.
>>> I have a complex model which is essentially a tree I edit in three
>>> different ways:
>>>
>>> 1) some commands that let me insert new nodes in the tree; Later on I
>>> want to add dreg&drop command to implement prune&graft in the tree.
>>>
>>> 2) each node type has it's own page (built around FormToolkit in
>>> master/detail) and widgets are directly bound to model via EMF
>>> DataBinding.
>>>
>>> 3) a specific field is actually a kind of a source text and is edited
>>> using a specialized AbstractTextEditor; upon saving this is stored in
>>> the TEXT of one model fields (<content>Here goes the TextEditor
>>> contents</content>).
>>>
>>> Which "command stack" should I listen to? (please forgive me for being
>>> naive, I'm not really an eclipse guru).
>> For your editor to support undo properly, you must already be using a
>> command stack (I assume).
>
> This may well be my problem.
> I do not use at all neither edit nor editor.
> I do use just the generated model.
>
> This is because I did not find a way to have the generated editor work
> as I like.
Hmmm. Implementing undo isn't trivial.
>
> I do not want to have an RCP editor integrated in a generic eclipse
> installation.
I'm just guessing at what you're doing...
> I want to build an application that edits my file, and thus the model.
> I need something akin to RCP plugin.xml editor, but without all IDE
> around it; just an editor for a single file type.
RCP let's you build pretty much anything. Not sure how you're building
what you're doing. Just with SWT? Are you using JFace?
>
> I think I missed something important, but I'm not really sure.
> I do confirm I have no undo/redo in my editor (aside from the
> TextEditor part, of course).
>
> I am just plainly using DataBinding; e.g.:
>
> private IObservableValue observableScene;
>
> // Databinding
> EMFDataBindingContext dbc = new EMFDataBindingContext();
>
> IWidgetValueProperty text = WidgetProperties.text(SWT.Modify);
> IWidgetValueProperty sel = WidgetProperties.selection();
>
> dbc.bindValue(sel.observe(btnTitle),EMFProperties.value(it.c ondarelli.writer.model.world.WorldPackage.Literals.IBASE__UN USED).observeDetail(observableScene));
>
> dbc.bindValue(text.observeDelayed(400,txtTitle),EMFPropertie s.value(it.condarelli.writer.model.world.WorldPackage.Litera ls.IBASE__TITLE).observeDetail(observableScene));
>
> dbc.bindValue(text.observeDelayed(400,txtDesc),EMFProperties .value(it.condarelli.writer.model.world.WorldPackage.Literal s.IBASE__DESC).observeDetail(observableScene));
>
>
>
> Am I doing something seriously wrong?
No, it's just not what I'm expecting. Certainly you can listen to
everything like what you're doing and filter things that cause problems.
>
> TiA
> Mauro
Re: model autosave [message #657040 is a reply to message #656909] Tue, 01 March 2011 12:25 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 424
Registered: September 2009
Senior Member
Il 01/03/2011 00:00, Ed Merks ha scritto:
> Mauro,
>
> Comments below.
>
> Mauro Condarelli wrote:
>> Thanks Ed,
>> Comments below.
>>
>> Il 28/02/2011 21:28, Ed Merks ha scritto:
>>>>>> Hi,
>>>>>> I want to save automatically the model shortly after modification
>>>>>> to a
>>>>>> temporary location to salvage as much as possible in the [un]likely
>>>>>> event of a crash.
>>>>> You could just listen to the stack since changes must happen as a
>>>>> result
>>>>> of executing a command.
>>>> Sorry, I fail to understand You.
>>> If you look at the generated EMF editor, you'll see there's a command
>>> stack listener already for updating the editor's dirty state.
>>>> I have a complex model which is essentially a tree I edit in three
>>>> different ways:
>>>>
>>>> 1) some commands that let me insert new nodes in the tree; Later on I
>>>> want to add dreg&drop command to implement prune&graft in the tree.
>>>>
>>>> 2) each node type has it's own page (built around FormToolkit in
>>>> master/detail) and widgets are directly bound to model via EMF
>>>> DataBinding.
>>>>
>>>> 3) a specific field is actually a kind of a source text and is edited
>>>> using a specialized AbstractTextEditor; upon saving this is stored in
>>>> the TEXT of one model fields (<content>Here goes the TextEditor
>>>> contents</content>).
>>>>
>>>> Which "command stack" should I listen to? (please forgive me for being
>>>> naive, I'm not really an eclipse guru).
>>> For your editor to support undo properly, you must already be using a
>>> command stack (I assume).
>>
>> This may well be my problem.
>> I do not use at all neither edit nor editor.
>> I do use just the generated model.
>>
>> This is because I did not find a way to have the generated editor work
>> as I like.
> Hmmm. Implementing undo isn't trivial.
>>
>> I do not want to have an RCP editor integrated in a generic eclipse
>> installation.
> I'm just guessing at what you're doing...
This is a novel-writing program.
It helps you breaking the work into book/chapter/scene hierarchy and
keeping track of several globals like characters and places.
I have the main hierarchy in a master tree (with some virtual nodes
representing characters, places, ...) and I have a detail page to edit
each node independently.
The TextEditor (unsurprisingly!) is used to edit the actual contents of
each scene.
The accessory data helps keep consistency (who is where when?) and to
ease workflow (scene revision and rating).
This is a simplified overview just to let You know what we are speaking
about.

>> I want to build an application that edits my file, and thus the model.
>> I need something akin to RCP plugin.xml editor, but without all IDE
>> around it; just an editor for a single file type.
> RCP let's you build pretty much anything. Not sure how you're building
> what you're doing. Just with SWT? Are you using JFace?
I am using JFace and FormTooklit.
I have three EMF models in my app: the real model, a legacy format for
import/export and a small thing used in Preferences.

>>
>> I think I missed something important, but I'm not really sure.
>> I do confirm I have no undo/redo in my editor (aside from the
>> TextEditor part, of course).
>>
>> I am just plainly using DataBinding; e.g.:
>> [example deleted ...]
>> Am I doing something seriously wrong?
> No, it's just not what I'm expecting. Certainly you can listen to
> everything like what you're doing and filter things that cause problems.
I currently solved my problems adding a status variable and simply
ignoring everything happening while I'm saving to temporary.

I would really like to understand how EMF is supposed to work.
I fear I'm twisting it to do things in a non-standard way and thus not
taking advantage of all available facilities (e.g.: undo/redo).

I generated (even if I do not currently use them) edit and editor and I
see they are quite complex.

I own the latest Eclipse Rich Client Platform (Second Edition), but that
doesn't cover EMF.
Where can I find relevant documentation?
My main source of inspiration has been (up to now) Tom Schindl's
EMF-Databinding series, but I seem to understand You are looking at EMF
from a different vantage point.
I am currently struggling to get a valid overview of the whole thing,
but I either find too generic things which fall apart as soon as You try
to use them in "real life" or too-specialized snippets I fail to place
in the correct framework.

Does someone know about some better info source?

TiA
Mauro
Re: model autosave [message #657084 is a reply to message #657040] Tue, 01 March 2011 14:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Il 01/03/2011 00:00, Ed Merks ha scritto:
>> Mauro,
>>
>> Comments below.
>>
>> Mauro Condarelli wrote:
>>> Thanks Ed,
>>> Comments below.
>>>
>>> Il 28/02/2011 21:28, Ed Merks ha scritto:
>>>>>>> Hi,
>>>>>>> I want to save automatically the model shortly after modification
>>>>>>> to a
>>>>>>> temporary location to salvage as much as possible in the [un]likely
>>>>>>> event of a crash.
>>>>>> You could just listen to the stack since changes must happen as a
>>>>>> result
>>>>>> of executing a command.
>>>>> Sorry, I fail to understand You.
>>>> If you look at the generated EMF editor, you'll see there's a command
>>>> stack listener already for updating the editor's dirty state.
>>>>> I have a complex model which is essentially a tree I edit in three
>>>>> different ways:
>>>>>
>>>>> 1) some commands that let me insert new nodes in the tree; Later on I
>>>>> want to add dreg&drop command to implement prune&graft in the tree.
>>>>>
>>>>> 2) each node type has it's own page (built around FormToolkit in
>>>>> master/detail) and widgets are directly bound to model via EMF
>>>>> DataBinding.
>>>>>
>>>>> 3) a specific field is actually a kind of a source text and is edited
>>>>> using a specialized AbstractTextEditor; upon saving this is stored in
>>>>> the TEXT of one model fields (<content>Here goes the TextEditor
>>>>> contents</content>).
>>>>>
>>>>> Which "command stack" should I listen to? (please forgive me for
>>>>> being
>>>>> naive, I'm not really an eclipse guru).
>>>> For your editor to support undo properly, you must already be using a
>>>> command stack (I assume).
>>>
>>> This may well be my problem.
>>> I do not use at all neither edit nor editor.
>>> I do use just the generated model.
>>>
>>> This is because I did not find a way to have the generated editor work
>>> as I like.
>> Hmmm. Implementing undo isn't trivial.
>>>
>>> I do not want to have an RCP editor integrated in a generic eclipse
>>> installation.
>> I'm just guessing at what you're doing...
> This is a novel-writing program.
> It helps you breaking the work into book/chapter/scene hierarchy and
> keeping track of several globals like characters and places.
> I have the main hierarchy in a master tree (with some virtual nodes
> representing characters, places, ...) and I have a detail page to edit
> each node independently.
> The TextEditor (unsurprisingly!) is used to edit the actual contents
> of each scene.
> The accessory data helps keep consistency (who is where when?) and to
> ease workflow (scene revision and rating).
> This is a simplified overview just to let You know what we are
> speaking about.
>
>>> I want to build an application that edits my file, and thus the model.
>>> I need something akin to RCP plugin.xml editor, but without all IDE
>>> around it; just an editor for a single file type.
>> RCP let's you build pretty much anything. Not sure how you're building
>> what you're doing. Just with SWT? Are you using JFace?
> I am using JFace and FormTooklit.
> I have three EMF models in my app: the real model, a legacy format for
> import/export and a small thing used in Preferences.
>
>>>
>>> I think I missed something important, but I'm not really sure.
>>> I do confirm I have no undo/redo in my editor (aside from the
>>> TextEditor part, of course).
>>>
>>> I am just plainly using DataBinding; e.g.:
>>> [example deleted ...]
>>> Am I doing something seriously wrong?
>> No, it's just not what I'm expecting. Certainly you can listen to
>> everything like what you're doing and filter things that cause problems.
> I currently solved my problems adding a status variable and simply
> ignoring everything happening while I'm saving to temporary.
>
> I would really like to understand how EMF is supposed to work.
> I fear I'm twisting it to do things in a non-standard way and thus not
> taking advantage of all available facilities (e.g.: undo/redo).
Certainly I would have expected you to start with the generated editor
and morph that into what you need, or pull out the pieces to reuse them...
>
> I generated (even if I do not currently use them) edit and editor and
> I see they are quite complex.
Implementing all this complexity from scratch yourself will certainly
help you understand it better than code you've never looked at it
detail, but that's a little bit like reinventing a simpler wheel.

>
> I own the latest Eclipse Rich Client Platform (Second Edition), but
> that doesn't cover EMF.
> Where can I find relevant documentation?
You've looked at EMF documentation page and noticed there's an EMF book
(Second Edition)?
> My main source of inspiration has been (up to now) Tom Schindl's
> EMF-Databinding series, but I seem to understand You are looking at
> EMF from a different vantage point.
Tom's provided data binding support that makes use of EMF's command stack.
> I am currently struggling to get a valid overview of the whole thing,
> but I either find too generic things which fall apart as soon as You
> try to use them in "real life" or too-specialized snippets I fail to
> place in the correct framework.
>
> Does someone know about some better info source?
Not sure what you've looked at yet. There are overview papers,
tutorials, articles, podcasts, and a book.
>
> TiA
> Mauro
>
Re: model autosave [message #657277 is a reply to message #657084] Wed, 02 March 2011 10:21 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 424
Registered: September 2009
Senior Member
Thanks Ed,
comments below.

Il 01/03/2011 15:57, Ed Merks ha scritto:
> Mauro,
>
> Comments below.
>
> Mauro Condarelli wrote:
>> Il 01/03/2011 00:00, Ed Merks ha scritto:
>>>> Am I doing something seriously wrong?
>>> No, it's just not what I'm expecting. Certainly you can listen to
>>> everything like what you're doing and filter things that cause problems.
>> I currently solved my problems adding a status variable and simply
>> ignoring everything happening while I'm saving to temporary.
>>
>> I would really like to understand how EMF is supposed to work.
>> I fear I'm twisting it to do things in a non-standard way and thus not
>> taking advantage of all available facilities (e.g.: undo/redo).
> Certainly I would have expected you to start with the generated editor
> and morph that into what you need, or pull out the pieces to reuse them...
I didn't find a good way to do it.
It seemed just too different from what I needed.
Not enough knowledge at the time.
I will try again.
>>
>> I generated (even if I do not currently use them) edit and editor and
>> I see they are quite complex.
> Implementing all this complexity from scratch yourself will certainly
> help you understand it better than code you've never looked at it
> detail, but that's a little bit like reinventing a simpler wheel.
I know, but I felt like being in front of a very complex jet plan when
You really need just a bike.
I thought simpler to start from scratch than trim the boemoth down to size.
Perhaps I will know better in the next project.

>
>>
>> I own the latest Eclipse Rich Client Platform (Second Edition), but
>> that doesn't cover EMF.
>> Where can I find relevant documentation?
> You've looked at EMF documentation page and noticed there's an EMF book
> (Second Edition)?

Thanks!
I just got the book.
It will take some time to peruse through it ;)

>> My main source of inspiration has been (up to now) Tom Schindl's
>> EMF-Databinding series, but I seem to understand You are looking at
>> EMF from a different vantage point.
> Tom's provided data binding support that makes use of EMF's command stack.
I know that, the articles do cite it, but is unclear to me how to use
this feature. I still need to study a lot ;)

Many Thanks
Mauro
Re: model autosave [message #657388 is a reply to message #657277] Wed, 02 March 2011 16:19 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Thanks Ed,
> comments below.
>
> Il 01/03/2011 15:57, Ed Merks ha scritto:
>> Mauro,
>>
>> Comments below.
>>
>> Mauro Condarelli wrote:
>>> Il 01/03/2011 00:00, Ed Merks ha scritto:
>>>>> Am I doing something seriously wrong?
>>>> No, it's just not what I'm expecting. Certainly you can listen to
>>>> everything like what you're doing and filter things that cause
>>>> problems.
>>> I currently solved my problems adding a status variable and simply
>>> ignoring everything happening while I'm saving to temporary.
>>>
>>> I would really like to understand how EMF is supposed to work.
>>> I fear I'm twisting it to do things in a non-standard way and thus not
>>> taking advantage of all available facilities (e.g.: undo/redo).
>> Certainly I would have expected you to start with the generated editor
>> and morph that into what you need, or pull out the pieces to reuse
>> them...
> I didn't find a good way to do it.
> It seemed just too different from what I needed.
> Not enough knowledge at the time.
> I will try again.
It gives you a bunch of very important scaffolding and then you can
change the views it supports.
>>>
>>> I generated (even if I do not currently use them) edit and editor and
>>> I see they are quite complex.
>> Implementing all this complexity from scratch yourself will certainly
>> help you understand it better than code you've never looked at it
>> detail, but that's a little bit like reinventing a simpler wheel.
> I know, but I felt like being in front of a very complex jet plan when
> You really need just a bike.
Yes, that's the usually evolution. The newbie says they want simple.
After they learn they want powerful.
> I thought simpler to start from scratch than trim the boemoth down to
> size.
What we do ourselves from scratch always seems simpler (but only to us).
> Perhaps I will know better in the next project.
>
>>
>>>
>>> I own the latest Eclipse Rich Client Platform (Second Edition), but
>>> that doesn't cover EMF.
>>> Where can I find relevant documentation?
>> You've looked at EMF documentation page and noticed there's an EMF book
>> (Second Edition)?
>
> Thanks!
> I just got the book.
> It will take some time to peruse through it ;)
>
>>> My main source of inspiration has been (up to now) Tom Schindl's
>>> EMF-Databinding series, but I seem to understand You are looking at
>>> EMF from a different vantage point.
>> Tom's provided data binding support that makes use of EMF's command
>> stack.
> I know that, the articles do cite it, but is unclear to me how to use
> this feature. I still need to study a lot ;)
Yep.
>
> Many Thanks
> Mauro
Previous Topic:Referencing Ecore to Support ORM
Next Topic:dynamic EMF serializable xml
Goto Forum:
  


Current Time: Mon Dec 22 15:44:43 GMT 2014

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

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