Skip to main content



      Home
Home » Modeling » EMF » EMF databinding and resource change
EMF databinding and resource change [message #895076] Wed, 11 July 2012 11:38 Go to next message
Eclipse UserFriend
Hi,

I have added a new page (called "General")to the default multipage editor generated by a xcore model.

The "selectionViewer" is updated when the resource (file) has changed by another editor. But not my
new page "General".

What I need to update my new page?


The code of the new page is:

package de.bahntechnik.dd.opn.ana.sel.presentation;

import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.databinding.edit.EMFEditProperties;
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import de.bahntechnik.dd.opn.ana.sel.Analysis;
import de.bahntechnik.dd.opn.ana.sel.SelPackage;

public class GeneralPage extends Composite {

private EditingDomain editingDomain;
private Analysis analysis;
private Text projectFileText;

/**
*
* @param parent
* @param style
* @param pAnalysis a EMF model instance as the object containing properties displayed in this page.
* @param pEditingDomain
*/
public GeneralPage(Composite parent, int style, Analysis pAnalysis, EditingDomain pEditingDomain) {
this(parent, style);
editingDomain = pEditingDomain;
editingDomain.getResourceSet().getResources().get(0);
setAnalysis(pAnalysis);
}

public GeneralPage(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(3, false));

new Label(this, SWT.NONE).setText("ProjectFile:");

projectFileText = new Text(this, SWT.BORDER | SWT.SINGLE);
projectFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

Button btnPrjFileBrowse = new Button(this, SWT.NONE);
btnPrjFileBrowse.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
FileDialog lFd = new FileDialog(getShell());
lFd.setFilterExtensions(new String[] { "*.xml" });

lFd.setFilterPath(projectFileText.getText());
String lDir = lFd.open();
if (null != lDir) {
projectFileText.setText(lDir);
}
}
});
btnPrjFileBrowse.setText("Browse ...");

}

@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}

public Analysis getAnalysis() {
return analysis;
}

public void setAnalysis(Analysis newAnalysis) {
setAnalysis(newAnalysis, true);
}

public void setAnalysis(Analysis newAnalysis, boolean update) {
analysis = newAnalysis;
if(update){
IEMFEditValueProperty lProp = EMFEditProperties.value(editingDomain,
SelPackage.Literals.ANALYSIS__PROJECT_FILE);
IObservableValue lOv = lProp.observe(analysis);
EMFDataBindingContext ctx = new EMFDataBindingContext();
IWidgetValueProperty lWvp = WidgetProperties.text(SWT.Modify);
ctx.bindValue(lWvp.observe(projectFileText), lOv);
}
}
}


any hint is appreciated, Martin
Re: EMF databinding and resource change [message #895084 is a reply to message #895076] Wed, 11 July 2012 12:09 Go to previous messageGo to next message
Eclipse UserFriend
Martin,

Comments below.


On 11/07/2012 5:38 PM, Martin Jacob wrote:
> Hi,
>
> I have added a new page (called "General")to the default multipage
> editor generated by a xcore model.
>
> The "selectionViewer" is updated when the resource (file) has changed
> by another editor. But not my new page "General".
The generated editor already has an IResourceChange listener that unload
and reloads the editor when the underlying Eclipse workspace resource is
changed... Maybe you need something very similar to that?
>
> What I need to update my new page?
Is EMFEditProperties.resource relevant?
>
>
> The code of the new page is:
>
> package de.bahntechnik.dd.opn.ana.sel.presentation;
>
> import org.eclipse.core.databinding.observable.value.IObservableValue;
> import org.eclipse.emf.databinding.EMFDataBindingContext;
> import org.eclipse.emf.databinding.edit.EMFEditProperties;
> import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
> import org.eclipse.emf.edit.domain.EditingDomain;
> import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
> import org.eclipse.jface.databinding.swt.WidgetProperties;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.MouseAdapter;
> import org.eclipse.swt.events.MouseEvent;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.FileDialog;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Text;
>
> import de.bahntechnik.dd.opn.ana.sel.Analysis;
> import de.bahntechnik.dd.opn.ana.sel.SelPackage;
>
> public class GeneralPage extends Composite {
>
> private EditingDomain editingDomain;
> private Analysis analysis;
> private Text projectFileText;
>
> /**
> *
> * @param parent
> * @param style
> * @param pAnalysis a EMF model instance as the object containing
> properties displayed in this page.
> * @param pEditingDomain
> */
> public GeneralPage(Composite parent, int style, Analysis
> pAnalysis, EditingDomain pEditingDomain) {
> this(parent, style);
> editingDomain = pEditingDomain;
> editingDomain.getResourceSet().getResources().get(0);
> setAnalysis(pAnalysis);
> }
>
> public GeneralPage(Composite parent, int style) {
> super(parent, style);
> setLayout(new GridLayout(3, false));
>
> new Label(this, SWT.NONE).setText("ProjectFile:");
>
> projectFileText = new Text(this, SWT.BORDER | SWT.SINGLE);
> projectFileText.setLayoutData(new GridData(SWT.FILL,
> SWT.CENTER, true, false));
>
> Button btnPrjFileBrowse = new Button(this, SWT.NONE);
> btnPrjFileBrowse.addMouseListener(new MouseAdapter() {
> @Override
> public void mouseDown(MouseEvent e) {
> FileDialog lFd = new FileDialog(getShell());
> lFd.setFilterExtensions(new String[] { "*.xml" });
>
> lFd.setFilterPath(projectFileText.getText());
> String lDir = lFd.open();
> if (null != lDir) {
> projectFileText.setText(lDir);
> }
> }
> });
> btnPrjFileBrowse.setText("Browse ...");
>
> }
>
> @Override
> protected void checkSubclass() {
> // Disable the check that prevents subclassing of SWT components
> }
>
> public Analysis getAnalysis() {
> return analysis;
> }
>
> public void setAnalysis(Analysis newAnalysis) {
> setAnalysis(newAnalysis, true);
> }
>
> public void setAnalysis(Analysis newAnalysis, boolean update) {
> analysis = newAnalysis;
> if(update){
> IEMFEditValueProperty lProp =
> EMFEditProperties.value(editingDomain,
> SelPackage.Literals.ANALYSIS__PROJECT_FILE);
> IObservableValue lOv = lProp.observe(analysis);
> EMFDataBindingContext ctx = new EMFDataBindingContext();
> IWidgetValueProperty lWvp =
> WidgetProperties.text(SWT.Modify);
> ctx.bindValue(lWvp.observe(projectFileText), lOv);
> }
> }
> }
>
>
> any hint is appreciated, Martin
Re: EMF databinding and resource change [message #895096 is a reply to message #895084] Wed, 11 July 2012 12:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

yes I found the IResourceChange listener in the editor and that at the end the method
handleChangedResources() of the editor was called.

I add a call to generalPage.setAnalysis(getAnalysis()) to handleChangedResources(). This works fine.

But is there another elegant way to make the "General page" listening to the editing domain in case
the resource gets reloaded? As I found the domain model was destroyed and a new model was created
when reading the changed resource. But my "General page" was still observing the old domain model
object.

Do I have to release any resources, e.g. of the observer, when I set the new domain model object
("generalPage.setAnalysis(getAnalysis())")?

Martin

Ed Merks wrote, On 11.07.2012 18:09:
> Martin,
>
> Comments below.
>
>
> On 11/07/2012 5:38 PM, Martin Jacob wrote:
>> Hi,
>>
>> I have added a new page (called "General")to the default multipage editor generated by a xcore model.
>>
>> The "selectionViewer" is updated when the resource (file) has changed by another editor. But not
>> my new page "General".
> The generated editor already has an IResourceChange listener that unload and reloads the editor when
> the underlying Eclipse workspace resource is changed... Maybe you need something very similar to that?
>>
>> What I need to update my new page?
> Is EMFEditProperties.resource relevant?
>>
>>
>> The code of the new page is:
>>
>> package de.bahntechnik.dd.opn.ana.sel.presentation;
>>
>> import org.eclipse.core.databinding.observable.value.IObservableValue;
>> import org.eclipse.emf.databinding.EMFDataBindingContext;
>> import org.eclipse.emf.databinding.edit.EMFEditProperties;
>> import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
>> import org.eclipse.emf.edit.domain.EditingDomain;
>> import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
>> import org.eclipse.jface.databinding.swt.WidgetProperties;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.events.MouseAdapter;
>> import org.eclipse.swt.events.MouseEvent;
>> import org.eclipse.swt.layout.GridData;
>> import org.eclipse.swt.layout.GridLayout;
>> import org.eclipse.swt.widgets.Button;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.widgets.FileDialog;
>> import org.eclipse.swt.widgets.Label;
>> import org.eclipse.swt.widgets.Text;
>>
>> import de.bahntechnik.dd.opn.ana.sel.Analysis;
>> import de.bahntechnik.dd.opn.ana.sel.SelPackage;
>>
>> public class GeneralPage extends Composite {
>>
>> private EditingDomain editingDomain;
>> private Analysis analysis;
>> private Text projectFileText;
>>
>> /**
>> *
>> * @param parent
>> * @param style
>> * @param pAnalysis a EMF model instance as the object containing properties displayed in this page.
>> * @param pEditingDomain
>> */
>> public GeneralPage(Composite parent, int style, Analysis pAnalysis, EditingDomain pEditingDomain) {
>> this(parent, style);
>> editingDomain = pEditingDomain;
>> editingDomain.getResourceSet().getResources().get(0);
>> setAnalysis(pAnalysis);
>> }
>>
>> public GeneralPage(Composite parent, int style) {
>> super(parent, style);
>> setLayout(new GridLayout(3, false));
>>
>> new Label(this, SWT.NONE).setText("ProjectFile:");
>>
>> projectFileText = new Text(this, SWT.BORDER | SWT.SINGLE);
>> projectFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
>>
>> Button btnPrjFileBrowse = new Button(this, SWT.NONE);
>> btnPrjFileBrowse.addMouseListener(new MouseAdapter() {
>> @Override
>> public void mouseDown(MouseEvent e) {
>> FileDialog lFd = new FileDialog(getShell());
>> lFd.setFilterExtensions(new String[] { "*.xml" });
>>
>> lFd.setFilterPath(projectFileText.getText());
>> String lDir = lFd.open();
>> if (null != lDir) {
>> projectFileText.setText(lDir);
>> }
>> }
>> });
>> btnPrjFileBrowse.setText("Browse ...");
>>
>> }
>>
>> @Override
>> protected void checkSubclass() {
>> // Disable the check that prevents subclassing of SWT components
>> }
>>
>> public Analysis getAnalysis() {
>> return analysis;
>> }
>>
>> public void setAnalysis(Analysis newAnalysis) {
>> setAnalysis(newAnalysis, true);
>> }
>>
>> public void setAnalysis(Analysis newAnalysis, boolean update) {
>> analysis = newAnalysis;
>> if(update){
>> IEMFEditValueProperty lProp = EMFEditProperties.value(editingDomain,
>> SelPackage.Literals.ANALYSIS__PROJECT_FILE);
>> IObservableValue lOv = lProp.observe(analysis);
>> EMFDataBindingContext ctx = new EMFDataBindingContext();
>> IWidgetValueProperty lWvp = WidgetProperties.text(SWT.Modify);
>> ctx.bindValue(lWvp.observe(projectFileText), lOv);
>> }
>> }
>> }
>>
>>
>> any hint is appreciated, Martin
>
>
Re: EMF databinding and resource change [message #895140 is a reply to message #895096] Wed, 11 July 2012 15:25 Go to previous messageGo to next message
Eclipse UserFriend
Martin,

A Resource is a Notifier so you can monitor the changes to its
contents. You'd definitely need to stop observing the old contents and
start observing the new contents.

On 11/07/2012 6:37 PM, Martin Jacob wrote:
> Hi Ed,
>
> yes I found the IResourceChange listener in the editor and that at the
> end the method handleChangedResources() of the editor was called.
>
> I add a call to generalPage.setAnalysis(getAnalysis()) to
> handleChangedResources(). This works fine.
>
> But is there another elegant way to make the "General page" listening
> to the editing domain in case the resource gets reloaded? As I found
> the domain model was destroyed and a new model was created when
> reading the changed resource. But my "General page" was still
> observing the old domain model object.
>
> Do I have to release any resources, e.g. of the observer, when I set
> the new domain model object ("generalPage.setAnalysis(getAnalysis())")?
>
> Martin
>
> Ed Merks wrote, On 11.07.2012 18:09:
>> Martin,
>>
>> Comments below.
>>
>>
>> On 11/07/2012 5:38 PM, Martin Jacob wrote:
>>> Hi,
>>>
>>> I have added a new page (called "General")to the default multipage
>>> editor generated by a xcore model.
>>>
>>> The "selectionViewer" is updated when the resource (file) has
>>> changed by another editor. But not
>>> my new page "General".
>> The generated editor already has an IResourceChange listener that
>> unload and reloads the editor when
>> the underlying Eclipse workspace resource is changed... Maybe you
>> need something very similar to that?
>>>
>>> What I need to update my new page?
>> Is EMFEditProperties.resource relevant?
>>>
>>>
>>> The code of the new page is:
>>>
>>> package de.bahntechnik.dd.opn.ana.sel.presentation;
>>>
>>> import org.eclipse.core.databinding.observable.value.IObservableValue;
>>> import org.eclipse.emf.databinding.EMFDataBindingContext;
>>> import org.eclipse.emf.databinding.edit.EMFEditProperties;
>>> import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
>>> import org.eclipse.emf.edit.domain.EditingDomain;
>>> import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
>>> import org.eclipse.jface.databinding.swt.WidgetProperties;
>>> import org.eclipse.swt.SWT;
>>> import org.eclipse.swt.events.MouseAdapter;
>>> import org.eclipse.swt.events.MouseEvent;
>>> import org.eclipse.swt.layout.GridData;
>>> import org.eclipse.swt.layout.GridLayout;
>>> import org.eclipse.swt.widgets.Button;
>>> import org.eclipse.swt.widgets.Composite;
>>> import org.eclipse.swt.widgets.FileDialog;
>>> import org.eclipse.swt.widgets.Label;
>>> import org.eclipse.swt.widgets.Text;
>>>
>>> import de.bahntechnik.dd.opn.ana.sel.Analysis;
>>> import de.bahntechnik.dd.opn.ana.sel.SelPackage;
>>>
>>> public class GeneralPage extends Composite {
>>>
>>> private EditingDomain editingDomain;
>>> private Analysis analysis;
>>> private Text projectFileText;
>>>
>>> /**
>>> *
>>> * @param parent
>>> * @param style
>>> * @param pAnalysis a EMF model instance as the object containing
>>> properties displayed in this page.
>>> * @param pEditingDomain
>>> */
>>> public GeneralPage(Composite parent, int style, Analysis pAnalysis,
>>> EditingDomain pEditingDomain) {
>>> this(parent, style);
>>> editingDomain = pEditingDomain;
>>> editingDomain.getResourceSet().getResources().get(0);
>>> setAnalysis(pAnalysis);
>>> }
>>>
>>> public GeneralPage(Composite parent, int style) {
>>> super(parent, style);
>>> setLayout(new GridLayout(3, false));
>>>
>>> new Label(this, SWT.NONE).setText("ProjectFile:");
>>>
>>> projectFileText = new Text(this, SWT.BORDER | SWT.SINGLE);
>>> projectFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
>>> true, false));
>>>
>>> Button btnPrjFileBrowse = new Button(this, SWT.NONE);
>>> btnPrjFileBrowse.addMouseListener(new MouseAdapter() {
>>> @Override
>>> public void mouseDown(MouseEvent e) {
>>> FileDialog lFd = new FileDialog(getShell());
>>> lFd.setFilterExtensions(new String[] { "*.xml" });
>>>
>>> lFd.setFilterPath(projectFileText.getText());
>>> String lDir = lFd.open();
>>> if (null != lDir) {
>>> projectFileText.setText(lDir);
>>> }
>>> }
>>> });
>>> btnPrjFileBrowse.setText("Browse ...");
>>>
>>> }
>>>
>>> @Override
>>> protected void checkSubclass() {
>>> // Disable the check that prevents subclassing of SWT components
>>> }
>>>
>>> public Analysis getAnalysis() {
>>> return analysis;
>>> }
>>>
>>> public void setAnalysis(Analysis newAnalysis) {
>>> setAnalysis(newAnalysis, true);
>>> }
>>>
>>> public void setAnalysis(Analysis newAnalysis, boolean update) {
>>> analysis = newAnalysis;
>>> if(update){
>>> IEMFEditValueProperty lProp = EMFEditProperties.value(editingDomain,
>>> SelPackage.Literals.ANALYSIS__PROJECT_FILE);
>>> IObservableValue lOv = lProp.observe(analysis);
>>> EMFDataBindingContext ctx = new EMFDataBindingContext();
>>> IWidgetValueProperty lWvp = WidgetProperties.text(SWT.Modify);
>>> ctx.bindValue(lWvp.observe(projectFileText), lOv);
>>> }
>>> }
>>> }
>>>
>>>
>>> any hint is appreciated, Martin
>>
>>
Re: EMF databinding and resource change [message #895173 is a reply to message #895084] Wed, 11 July 2012 17:18 Go to previous message
Eclipse UserFriend
[...]

>> What I need to update my new page?
> Is EMFEditProperties.resource relevant?
>>

This only provides an observable of Resource.getContents()

Tom
Previous Topic:[EMF .Edit] Customizing child creation behaviour
Next Topic:[CDO] Factory not found: org.eclipse.emf.cdo.server.queryHandlerFactories[ocl]
Goto Forum:
  


Current Time: Mon Jul 14 18:08:30 EDT 2025

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

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

Back to the top