refrash underlying diagrammodel [message #672212] |
Fri, 20 May 2011 10:42 |
AlexejS Mising name Messages: 25 Registered: May 2010 |
Junior Member |
|
|
Hi, when I add Elements to my diagramm my model is synchronized with my diagramfile until I don't open a sub diagram and add there new elemnts.
The model of my basediagram don't recognize changes in my subdiagram and don't update itself.
My question: How can I programaticaly update my model for example out of my file.
Something like it is done by open whole editor in:
protected void setDocumentContent(IDocument document, IEditorInput element)
throws CoreException {
IDiagramDocument diagramDocument = (IDiagramDocument) document;
TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
if (element instanceof URIEditorInput) {
URI uri = ((URIEditorInput) element).getURI();
Resource resource = null;
try {
resource = domain.getResourceSet().getResource(
uri.trimFragment(), false);
if (resource == null) {
resource = domain.getResourceSet().createResource(
uri.trimFragment());
}
if (!resource.isLoaded()) {
try {
Map options = new HashMap(GMFResourceFactory
.getDefaultLoadOptions());
// @see 171060
// options.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
resource.load(options);
} catch (IOException e) {
resource.unload();
throw e;
}
}
if (uri.fragment() != null) {
EObject rootElement = resource.getEObject(uri.fragment());
if (rootElement instanceof Diagram) {
document.setContent((Diagram) rootElement);
return;
}
} else {
for (Iterator it = resource.getContents().iterator(); it
.hasNext();) {
Object rootElement = it.next();
if (rootElement instanceof Diagram) {
document.setContent((Diagram) rootElement);
return;
}
}
}
throw new RuntimeException(
Messages.PetrinetsModelDocumentProvider_NoDiagramInResourceError);
} catch (Exception e) {
CoreException thrownExcp = null;
if (e instanceof CoreException) {
thrownExcp = (CoreException) e;
} else {
String msg = e.getLocalizedMessage();
thrownExcp = new CoreException(
new Status(
IStatus.ERROR,
PetrinetsModelDiagramEditorPlugin.ID,
0,
msg != null ? msg
: Messages.PetrinetsModelDocumentProvider_DiagramLoadingError,
e));
}
throw thrownExcp;
}
} else {
throw new CoreException(
new Status(
IStatus.ERROR,
PetrinetsModelDiagramEditorPlugin.ID,
0,
NLS
.bind(
Messages.PetrinetsModelDocumentProvider_IncorrectInputError,
new Object[] { element,
"org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$
null));
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03003 seconds