Home » Modeling » GMF (Graphical Modeling Framework) » XXXViewFactory.decorateView -> different behavior in GMF 2.1 vs. GMF 2.1.1
| |
Re: XXXViewFactory.decorateView -> different behavior in GMF 2.1 vs. GMF 2.1.1 [message #207193 is a reply to message #207136] |
Sat, 27 September 2008 10:56 |
Thomas Beyer Messages: 47 Registered: July 2009 |
Member |
|
|
This is a multi-part message in MIME format.
--------------080606050600060409030403
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Alex,
I tried this also with the same result.
The Node is created, I can add layoutconstraint to it, but the children
are missing.
Debugging the corresponding ViewFactory show, that the child nodes (for
labels and compartments) are created fine, but somehow not attached to
the parent-view resp. they dont go in the notation model.
My routine is as follows:
public static Resource createDiagram(URI diagramURI, URI modelURI,
IProgressMonitor progressMonitor, final Document doc) {
TransactionalEditingDomain editingDomain =
GMFEditingDomainFactory.INSTANCE
.createEditingDomain();
progressMonitor.beginTask(Settings.Lbl_ProgressTask_CreateDi agram, 3);
final Resource diagramResource = editingDomain.getResourceSet()
.createResource(diagramURI);
final Resource modelResource = editingDomain.getResourceSet()
.createResource(modelURI);
// set model name from last segment without file extension
final String diagramName =
diagramURI.trimFileExtension().lastSegment();
AbstractTransactionalCommand command = new
AbstractTransactionalCommand(
editingDomain, Settings.Lbl_Cmd_CreateDiagram,
Collections.EMPTY_LIST) {
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
// create diagram and domain diagram
HMIDiagram diagramM =
HmiFactory.eINSTANCE.createHMIDiagram();
diagramM.setName(diagramName);
Diagram diagramD = ViewService.createDiagram(diagramM,
HMIDiagramEditPart.MODEL_ID, DPH);
diagramD.setName(diagramName);
// create contents of diagram
createContents(diagramM, diagramD, doc);
// add tree to resources
if (diagramD != null) {
diagramResource.getContents().add(diagramD);
}
if (diagramM != null)
modelResource.getContents().add(diagramM);
// save resources
try {
modelResource.save(hmi.diagram.part.HmiDiagramEditorUtil
.getSaveOptions());
diagramResource.save(hmi.diagram.part.HmiDiagramEditorUtil
.getSaveOptions());
}
catch (IOException e) {
Activator.getDefault()
.logError(Settings.Msg_Store_Error, e);
//$NON-NLS-1$
}
return CommandResult.newOKCommandResult();
}
};
try {
OperationHistoryFactory.getOperationHistory().execute(comman d,
new SubProgressMonitor(progressMonitor, 1), null);
setCharset(WorkspaceSynchronizer.getFile(modelResource));
setCharset(WorkspaceSynchronizer.getFile(diagramResource));
}
catch (ExecutionException e) {
Activator.getDefault().logError(
Settings.Msg_CreateDiagram_Error, e); //$NON-NLS-1$
}
return diagramResource;
}
in the createContents-method, the actual content is being created.
something like:
Desktop desktopModel = HmiFactory.eINSTANCE.createDesktop();
diagramM.getToplevelDisplayNodes().add(desktopModel);
View desktopView = ViewService.createNode(containerView,
desktopModel,"2012", DPH);
//set bounds of Node
setLayoutConstraints(desktopView);
What am I doing wrong?
TIA
Thomas
Alex Shatalin schrieb:
> Hello Thomas,
>
> Use ViewService API co create all vew instances. As a result all
> necessary child views (compartments/labels) will be created
> automatically.
>
> -----------------
> Alex Shatalin
>
>
--------------080606050600060409030403
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Alex,<br>
<br>
I tried this also with the same result.<br>
The Node is created, I can add layoutconstraint to it, but the children
are missing.<br>
Debugging the corresponding ViewFactory show, that the child nodes (for
labels and compartments) are created fine, but somehow not attached to
the parent-view resp. they dont go in the notation model.<br>
<br>
My routine is as follows:<br>
<br>
public static Resource createDiagram(URI diagramURI, URI modelURI,<br>
IProgressMonitor progressMonitor, final Document doc) {<br>
TransactionalEditingDomain editingDomain =
GMFEditingDomainFactory.INSTANCE<br>
.createEditingDomain();<br>
<br>
progressMonitor.beginTask(Settings.Lbl_ProgressTask_CreateDi agram, 3);<br>
final Resource diagramResource = editingDomain.getResourceSet()<br>
.createResource(diagramURI);<br>
final Resource modelResource = editingDomain.getResourceSet()<br>
.createResource(modelURI);<br>
<br>
// set model name from last segment without file extension<br>
final String diagramName =
diagramURI.trimFileExtension().lastSegment();<br>
<br>
AbstractTransactionalCommand command = new
AbstractTransactionalCommand(<br>
editingDomain, Settings.Lbl_Cmd_CreateDiagram,<br>
Collections.EMPTY_LIST) {<br>
protected CommandResult doExecuteWithResult(<br>
IProgressMonitor monitor, IAdaptable info)<br>
throws ExecutionException {<br>
<br>
// create diagram and domain diagram<br>
HMIDiagram diagramM =
HmiFactory.eINSTANCE.createHMIDiagram();<br>
diagramM.setName(diagramName);<br>
<br>
Diagram diagramD = ViewService.createDiagram(diagramM,<br>
HMIDiagramEditPart.MODEL_ID, DPH);<br>
<br>
diagramD.setName(diagramName);<br>
<br>
// create contents of diagram<br>
<font color="#3366ff">createContents(diagramM,
diagramD, doc);</font><br>
<br>
// add tree to resources<br>
if (diagramD != null) {<br>
diagramResource.getContents().add(diagramD);<br>
}<br>
if (diagramM != null)<br>
modelResource.getContents().add(diagramM);<br>
<br>
// save resources<br>
try {<br>
modelResource.save(hmi.diagram.part.HmiDiagramEditorUtil<br >
.getSaveOptions());<br>
diagramResource.save(hmi.diagram.part.HmiDiagramEditorUtil<br >
.getSaveOptions());<br>
}<br>
catch (IOException e) {<br>
Activator.getDefault()<br>
.logError(Settings.Msg_Store_Error, e);
//$NON-NLS-1$<br>
}<br>
return CommandResult.newOKCommandResult();<br>
}<br>
};<br>
<br>
try {<br>
OperationHistoryFactory.getOperationHistory().execute(comman d, <br>
new SubProgressMonitor(progressMonitor, 1), null);<br>
setCharset(WorkspaceSynchronizer.getFile(modelResource));<br >
setCharset(WorkspaceSynchronizer.getFile(diagramResource));<br >
}<br>
catch (ExecutionException e) {<br>
Activator.getDefault().logError(<br>
Settings.Msg_CreateDiagram_Error, e); //$NON-NLS-1$<br>
}<br>
return diagramResource;<br>
}<br>
<br>
in the createContents-method, the actual content is being created.<br>
something like:<br>
Desktop desktopModel = HmiFactory.eINSTANCE.createDesktop();<br>
diagramM.getToplevelDisplayNodes().add(desktopModel);<br>
<font color="#3366ff">View desktopView =
ViewService.createNode(containerView, desktopModel,"2012", DPH);</font><br>
//set bounds of Node<br>
setLayoutConstraints(desktopView);<br>
<br>
What am I doing wrong?<br>
<br>
TIA<br>
Thomas<br>
<br>
<br>
<br>
Alex Shatalin schrieb:
<blockquote cite="mid:3c3172e626f688caede972e52f67@news.eclipse.org"
type="cite">Hello Thomas,
<br>
<br>
Use ViewService API co create all vew instances. As a result all
necessary child views (compartments/labels) will be created
automatically.
<br>
<br>
-----------------
<br>
Alex Shatalin
<br>
<br>
<br>
</blockquote>
<br>
</body>
</html>
--------------080606050600060409030403--
|
|
| |
Re: XXXViewFactory.decorateView -> different behavior in GMF 2.1vs. GMF 2.1.1 [message #208335 is a reply to message #207225] |
Fri, 10 October 2008 22:38 |
Thomas Beyer Messages: 47 Registered: July 2009 |
Member |
|
|
Hello Alex,
thank for your pointer.
I did a lot of debugging and testing.
However, the behavior seems absurd to me.
Creating Views via ViewService triggers the correct generated
XXViewFactories.
I can see, that the create-method of BasicNodeViewFactory calls the
specific decorate-method in generated XXXViewFactory. There the nodes
for label and compartment are created (I can access them), but NOT
persisted in the notation model?!
I fell back to my initial solution by subclassing the generated
XXXViewFactories to make the protected decorate-view method public.
Additionally i had to add the domain element in the notationa view and
then decorate it.
After all these are the steps:
1. Create a the domain model object
2. Create the view object via ViewService
3. Add the domain model object to the created view object
(setElement...) -> actually ViewService should be doing this already,
but doesn't!
4. decorate the created view with the subclassed generated
XXXViewFactories to generated label and compartment-nodes.
It seems quiet odd.
I also noticed, that in the BasicNodeViewFactory, there have been made
some changes in the EMF-operation options (the static definitions at the
begininning).
Simply creating a view (with corresponding labels and compartments) view
ViewService doesn't work.
Given that my DSL is quiet complex, a have to do a hell lot of redundant
coding, to make this work.
Maybe there still is a bug somewhere.
Regards
Thomas
Alex Shatalin schrieb:
> Hello Thomas,
>
>> Debugging the corresponding ViewFactory show, that the child nodes
>> (for labels and compartments) are created fine, but somehow not
>> attached to
>> the parent-view resp. they dont go in the notation model.
> See BasicNodeViewFactory.createView()
> ("ViewUtil.insertChildView(containerView, node, index, persisted);"
> method call).
> Corresponding child elements (compartments/labels) should be attached to
> the parent element there.
>
>> My routine is as follows:
> Looks reasonable. At least, I can not find anythis incorrect in this
> code from the very beggining. Try to continue debugging view factory to
> see the reason of incorrect child elements creation.
>
> -----------------
> Alex Shatalin
>
>
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 22:10:51 GMT 2024
Powered by FUDForum. Page generated in 0.03362 seconds
|