check a property while reading file [message #219397] |
Fri, 20 February 2009 05:15  |
Eclipse User |
|
|
|
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 #219747 is a reply to message #219723] |
Mon, 23 February 2009 11:20  |
Eclipse User |
|
|
|
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
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.02754 seconds