Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Problem with diagram creation from model file
Problem with diagram creation from model file [message #116188] Mon, 02 April 2007 09:23 Go to next message
Eclipse UserFriend
Originally posted by: christian.daenekas.informatik.uni-oldenburg.de

Hello,

I think I discovered a potential problem with the creation of diagrams
from model files. I use this function in my RCP diagram editor and it
seemed to work pretty good. But yesterday I discovered a wrong diagram
being created from a valid model file. I have 5 EMF classes.
Specializations of these classes (distinguished by different attribute
initializations) are represented as nodes that can directly be created
by the tools from the palette. Some of these "TopLevel" nodes have
compartments, some not. Also the child references that are associated
with a compartment are different from node to node (even if it
references the same EMF class). Now the problem:

I´ve got a model file with one root node. This node has multiple
childnodes. Some of these childnodes do have childnodes themselfes and
so on. I´ve noticed that there are sometimes wrong nodes selected to
represent an element in the semantic model. This leads to the situation
that an element with child elements is represented by a node without a
compartement and the child elements are not displayed and cannot be
altered. Still the elements stay in the semantic model. This situation
seems to depend on the depth in the treestructure the element is placed
in. Are the nodes that represent a certain EMF class randomly chosen
during diagram creation (if there is more than one possibility for a
class)? This situation severly impacts the functionality of my
application, so any advice on this is more than welcome. Thanks in advance.

Greetings,
Christian
Re: Problem with diagram creation from model file [message #116227 is a reply to message #116188] Mon, 02 April 2007 09:48 Go to previous messageGo to next message
Eclipse UserFriend
Hello Christian,

In .gmfmap model below each NodeMapping you can create Constraint and FeatureSequenceInitializer
elements. AFAIU you have only FeatureSequenceInitializers try adding Constraings
to your .gmfmap model. If you already have constraints check that there is
always only one node mapping valid for each semantic model element. If there
are two node mappings applicable to the same domain model element then first
one will be selected according to the generated code (.gmfgen model).

-----------------
Alex Shatalin
Re: Problem with diagram creation from model file [message #116264 is a reply to message #116227] Mon, 02 April 2007 10:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: christian.daenekas.informatik.uni-oldenburg.de

Thank you for your fast answer. Yes I have one
FeatureSequenceInitializer per top node that initializes one attribute
(named "class") with a String value. I didn´t know about the usage of
constraints here (and honestly didn´t think about the problem I´ve got
now). So if I understand you correctly I can define a constraint like
"If the semantic element has the value "test" for the attribute "class"
then accept this node mapping" ? Can you give me any advice on how to
define such a constraint? I only used constraints in the context of
audits for model checking. Thank you.

Greetings,
Christian

Alex Shatalin schrieb:
> Hello Christian,
>
> In .gmfmap model below each NodeMapping you can create Constraint and
> FeatureSequenceInitializer elements. AFAIU you have only
> FeatureSequenceInitializers try adding Constraings to your .gmfmap
> model. If you already have constraints check that there is always only
> one node mapping valid for each semantic model element. If there are two
> node mappings applicable to the same domain model element then first one
> will be selected according to the generated code (.gmfgen model).
>
> -----------------
> Alex Shatalin
>
>
Re: Problem with diagram creation from model file [message #116344 is a reply to message #116264] Mon, 02 April 2007 10:18 Go to previous messageGo to next message
Eclipse UserFriend
Hello Christian,

Yes, you are right. OCL constraint should looks like: self.class = 'test'


-----------------
Alex Shatalin
Re: Problem with diagram creation from model file [message #116352 is a reply to message #116344] Mon, 02 April 2007 11:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: christian.daenekas.informatik.uni-oldenburg.de

Okay,

I tried this, but it seems that the constraints are not evaluated. The
behaviour of the creation process doesn´t change and the Method matches
that should do the evaluation is not called. Since the action for
diagram creation isn´t included in the RCP version of an editor I
created a class myself that is responsible for diagram creation. Do I
have to call the constraint evaluation explicitly or is this an internal
thing. Maybe you could take a look on the code to tell me if I forgot
something:

package de.permeter.analysis.editor.metric.diagram.part;

import java.io.IOException;
import java.util.Collections;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.OperationHistoryFactory ;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.ui.URIEditorInput;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
import
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTr ansactionalCommand;
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.WorkbenchException;

import de.permeter.analysis.editor.metric.DocumentRoot;
import de.permeter.analysis.editor.metric.diagram.edit.parts.Metric EditPart;


public class MetricEditOperation
{
IStructuredSelection mySelection;
String metricId;
String metricPath;
IWorkbench workbench;
IWorkbenchPart myPart;


public MetricEditOperation(IStructuredSelection mySelection, String
metricId, String metricPath,
IWorkbench workbench, IWorkbenchPart myPart)
{
super();
this.mySelection = mySelection;
this.metricId = metricId;
this.metricPath = metricPath;
this.workbench = workbench;
this.myPart = myPart;
}


public void execute() {
// Creation of URIEditorInput that is used to create diagram resource
URI modelUri = URI.createFileURI(metricPath);
URIEditorInput input = new URIEditorInput(modelUri);

// Root Object of the semantic model is resolved
TransactionalEditingDomain editingDomain =
GMFEditingDomainFactory.INSTANCE.createEditingDomain();
ResourceSet resourceSet = editingDomain.getResourceSet();
EObject diagramRoot = null;
try
{
Resource resource = resourceSet.getResource(input.getURI(), true);
diagramRoot = (EObject) resource.getContents().get(0);
}
catch (WrappedException ex)
{
MetricDiagramEditorPlugin.getInstance().logError(
"Unable to load resource: " + input.getURI().toFileString(), ex);
//$NON-NLS-1$
}
if (diagramRoot == null)
{
MessageDialog.openError(myPart.getSite().getShell(), "Error", "Model
file loading failed");
return;
}

// Hidden root object of type DocumentRoot is replaced by actual root
object metric for diagram creation
DocumentRoot docRoot = (DocumentRoot) diagramRoot;
final EObject myDiagramRoot = docRoot.getMetric();
//System.out.println("Root: " + myDiagramRoot.toString());

// Diagram will be stored in the same place as semantic model by the
same name (extension .metric is replaced by .metric_diagram)
String originalFileName = metricPath.subSequence(0,
metricPath.length() - 7).toString();
String fileExtension = ".metric_diagram"; //$NON-NLS-1$
String fileName = originalFileName + fileExtension;
//System.out.println("Zu erstellende Datei: " + fileName);

// Input for diagram editor is created
URI diagramFileUri = URI.createFileURI(fileName);
URIEditorInput diagramFile = new URIEditorInput(diagramFileUri);
//System.out.println("Diagram da?: " + diagramFile.exists());

final Resource diagramResource =
resourceSet.createResource(diagramFile.getURI());

// If there is already an diagram file it is opened, otherwise it gets
created.
if (diagramFile.exists())
{
try
{

workbench.showPerspective(" de.permeter.analysis.editor.metric.diagram.MetricPerspective ",
workbench
.getActiveWorkbenchWindow());
MetricDiagramEditorUtil.openDiagram(diagramResource);
}
catch (PartInitException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (WorkbenchException ex)
{
// TODO Auto-generated catch block
ex.printStackTrace();
}
}

else
{
// creation of diagram contents
AbstractTransactionalCommand command = new
AbstractTransactionalCommand(editingDomain,
"Initializing diagram contents", null) { //$NON-NLS-1$

protected CommandResult doExecuteWithResult(IProgressMonitor
monitor, IAdaptable info)
throws ExecutionException
{
int diagramVID =
MetricVisualIDRegistry.getDiagramVisualID(myDiagramRoot);
if (diagramVID != MetricEditPart.VISUAL_ID)
{
return CommandResult.newErrorCommandResult("Incorrect model object
stored as a root resource object"); //$NON-NLS-1$
}
Diagram diagram = ViewService.createDiagram(myDiagramRoot,
MetricEditPart.MODEL_ID,
MetricDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
diagramResource.getContents().add(diagram);
return CommandResult.newOKCommandResult();
}
};

// diagram is saved to file, perspective gets switched to editor and
diagram gets opened.
try
{
OperationHistoryFactory.getOperationHistory().execute(comman d, new
NullProgressMonitor(), null);
diagramResource.save(Collections.EMPTY_MAP);
try
{

workbench.showPerspective(" de.permeter.analysis.editor.metric.diagram.MetricPerspective ",
workbench
.getActiveWorkbenchWindow());
}
catch (WorkbenchException ex)
{
// TODO Auto-generated catch block
ex.printStackTrace();
}
MetricDiagramEditorUtil.openDiagram(diagramResource);
}
catch (ExecutionException ex)
{
MetricDiagramEditorPlugin.getInstance().logError("Unable to create
model and diagram", ex); //$NON-NLS-1$
}
catch (IOException ex)
{
MetricDiagramEditorPlugin.getInstance().logError(
"Save operation failed for: " + diagramFileUri.toFileString(),
ex); //$NON-NLS-1$
}
catch (PartInitException ex)
{
MetricDiagramEditorPlugin.getInstance().logError("Unable to open
editor", ex); //$NON-NLS-1$
}

}



Alex Shatalin schrieb:
> Hello Christian,
>
> Yes, you are right. OCL constraint should looks like: self.class = 'test'
>
>
> -----------------
> Alex Shatalin
>
>
Re: Problem with diagram creation from model file [message #116356 is a reply to message #116352] Mon, 02 April 2007 12:09 Go to previous messageGo to next message
Eclipse UserFriend
Hello Christian,

I see! Your action responsible for creation only root diagram element. The
rest will be created by CanonicalEditpolicy .. and we have following defect
filed: https://bugs.eclipse.org/bugs/show_bug.cgi?id=150257. The reason of
your problem is similar. You can vote for this request + add your situation
description there - this will be helpfull for fixing it.

For now you can:
- make your diagram "non-synchronized"
- generate code for it
- take generated "???InitDiagramFileAciton" and patch it for your situation
- use it in your RCP application.

This code will use correspondign constraints to initialize the diagram

-----------------
Alex Shatalin
Re: Problem with diagram creation from model file [message #116360 is a reply to message #116356] Mon, 02 April 2007 12:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: christian.daenekas.informatik.uni-oldenburg.de

Ok, could you explain your suggestion any further? "non-synchronized" is
an option I can find in a model (gmfgen?)? And afterwards I generate a
NON-RCP version of the diagram plugin? Would be nice if you could let me
know if I got everything right you suggested.

Alex Shatalin schrieb:
> Hello Christian,
>
> I see! Your action responsible for creation only root diagram element.
> The rest will be created by CanonicalEditpolicy .. and we have following
> defect filed: https://bugs.eclipse.org/bugs/show_bug.cgi?id=150257. The
> reason of your problem is similar. You can vote for this request + add
> your situation description there - this will be helpfull for fixing it.
>
> For now you can:
> - make your diagram "non-synchronized"
> - generate code for it
> - take generated "???InitDiagramFileAciton" and patch it for your situation
> - use it in your RCP application.
>
> This code will use correspondign constraints to initialize the diagram
>
> -----------------
> Alex Shatalin
>
>
Re: Problem with diagram creation from model file [message #116368 is a reply to message #116360] Mon, 02 April 2007 14:33 Go to previous message
Eclipse UserFriend
Hello Christian,

> Ok, could you explain your suggestion any further? "non-synchronized"
> is an option I can find in a model (gmfgen?)? And afterwards I
Yes there is a boolean property for GenDiagram - "synchronized". You can
set it to "false" and regenrate the code.

> generate a NON-RCP version of the diagram plugin? Would be nice if you
> could let me know if I got everything right you suggested.
That's right. I'm suggesting to generate non-RCP version of non-synchronized
diagram for your mapping, take generated "InitDiagramFileAction" and patch
it to make it applicable for RCP version..

-----------------
Alex Shatalin
Previous Topic:Problems with multi-page editors
Next Topic:Defaults from ECORE model don't appear in XML data from diagram.
Goto Forum:
  


Current Time: Fri Jun 06 03:17:06 EDT 2025

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

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

Back to the top