Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » check a property while reading file
check a property while reading file [message #219397] Fri, 20 February 2009 10:15 Go to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 189
Registered: July 2009
Senior Member
Hi,

I want to check an property of an element while reading the file and generating the diagram. Where
is the hook I can start? I am looking for a hint from some one who know the process while reading
the file.
Or may be I can use a feature in GMF while opening a diagram and set some constrain?

My problem is that another tool is generating the xmi file. The xmi file contains a version. I need
to check whether the version of the generated file fit to my diagram plugin.

thanks for any hint, Martin
Re: check a property while reading file [message #219421 is a reply to message #219397] Fri, 20 February 2009 10:57 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Martin,

You can start with org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.Di agramDocumentEditor.setInput().
DiagramDocumentEditor is one of the superclasses for generated ???DiagramEditor
class.

-----------------
Alex Shatalin
Re: check a property while reading file [message #219512 is a reply to message #219421] Fri, 20 February 2009 13:06 Go to previous messageGo to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 189
Registered: July 2009
Senior Member
Hi,

thank you! I debug the suggested methods.
Now I running into the problem that the document element is not the xmi root element. The document
element name is "Network" and is a child of element "PSC". The property I want to check is a
attribute of "PSC" with name "version". How can I access the value of attribute "version"?
Any suggestion?

Martin


Alex Shatalin wrote, On 20.02.2009 11:57:
> Hello Martin,
>
> You can start with
> org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.Di agramDocumentEditor.setInput().
> DiagramDocumentEditor is one of the superclasses for generated
> ???DiagramEditor class.
>
> -----------------
> Alex Shatalin
>
>
Re: check a property while reading file [message #219723 is a reply to message #219512] Mon, 23 February 2009 13:05 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Martin,

If you load model file using EMY api then you'll gen instances of EMF-generated
classes and you can use EMF-generated api to access corresponding properties
like:

Network network = ...;
if (network.getPSC().getVersion() = ...) {
....
}

-----------------
Alex Shatalin
Re: check a property while reading file [message #219747 is a reply to message #219723] Mon, 23 February 2009 16:20 Go to previous message
Martin Jacob is currently offline Martin JacobFriend
Messages: 189
Registered: July 2009
Senior Member
Hi Alex,

I solved the problem as follow:

I adapted the generated class
....model.diagram.part.XXXNewDiagramFileWizard.DiagramRootEl ementSelectionPage. This class is used as
the wizard to generate the xxx_diagram file.
1. XXXNewDiagramFileWizard constructor: set the diagramRoot element in class
DiagramRootElementSelectionPage (new Property in that class)
2. adapt method "validatePage" to check the property "version" of documentRoot

for details see the following source code as CVS difference to the generated source code:

private static class DiagramRootElementSelectionPage extends
ModelElementSelectionPage {
+ /**
+ * @generated NOT
+ */
+ protected PSC diagramRoot;
+
+ /*
+ * @generated NOT
+ * @see ModelElementSelectionPage#setModelElement(org.eclipse.emf.ec ore.EObject)
+ */
+ @Override
+ public void setModelElement(EObject modelElement) {
+ if(modelElement instanceof PSC)
+ {
+ diagramRoot = (PSC) modelElement;
+ }
+ super.setModelElement(modelElement);
+ }

/**
* @generated
@@ -178,20 +197,33 @@
}

/**
- * @generated
+ * @generated NOT
*/
protected boolean validatePage() {
- if (selectedModelElement == null) {
+ boolean lRet = true;
+ if(null == diagramRoot){
+ setErrorMessage(Messages.PscNewDiagramFileWizard_RootSelecti onPageNoSelectionMessage);
+ lRet = false;
+ }
+ else if (selectedModelElement == null) {
setErrorMessage(Messages.PscNewDiagramFileWizard_RootSelecti onPageNoSelectionMessage);
- return false;
+ lRet = false;
+ }
+ else if(!Versions.isCompatiblePSCVersion(diagramRoot.getVersion() )){
+ setErrorMessage(NLS.bind(Messages.PscNewDiagramFileWizard_Wr ongPSCVersion,
+ diagramRoot.getVersion(), Versions.getActualPSCVersion()));
+ lRet = false;
+ }
+ else
+ {
+ lRet = ViewService.getInstance().provides(
+ new CreateDiagramViewOperation(new EObjectAdapter(
+ selectedModelElement), NetworkEditPart.MODEL_ID,
+ PscDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT));
+ setErrorMessage(lRet ? null
+ : Messages.PscNewDiagramFileWizard_RootSelectionPageInvalidSel ectionMessage);
}
- boolean result = ViewService.getInstance().provides(
- new CreateDiagramViewOperation(new EObjectAdapter(
- selectedModelElement), NetworkEditPart.MODEL_ID,
- PscDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT));
- setErrorMessage(result ? null
- : Messages.PscNewDiagramFileWizard_RootSelectionPageInvalidSel ectionMessage);
- return result;
+ return lRet;
}
}
}


BR, Martin

Alex Shatalin wrote, On 23.02.2009 14:05:
> Hello Martin,
>
> If you load model file using EMY api then you'll gen instances of
> EMF-generated classes and you can use EMF-generated api to access
> corresponding properties like:
>
> Network network = ...;
> if (network.getPSC().getVersion() = ...) {
> ....
> }
>
> -----------------
> Alex Shatalin
>
>
>
Previous Topic:Show containment reference as tree in property sheet
Next Topic:Building 2.2
Goto Forum:
  


Current Time: Sat Mar 06 11:11:46 GMT 2021

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

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

Back to the top