关于gmf编辑器的保存操作
a) First, in class DiagramDocumentEditor, the method
public void doSave(IProgressMonitor progressMonitor) { }
b) Second, the method above call the methon:
protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) {}
this method is in class DiagramDocumentEditor.
c)AbstractDocumentProvider)中的方法
public final void saveDocument(IProgressMonitor monitor, final Object element, final IDocument document, final boolean overwrite) throws CoreException {
if (element == null)
return;
executeOperation(getSaveOperation(element, document, overwrite), monitor);
}
d) 在自己的Document provider里面冲载方法
protected void saveDocumentToFile(IDocument document, IFile file,
boolean overwrite, IProgressMonitor monitor) throws CoreException {}
e) FileDiagramDocumentProvider种的方法
protected void saveDocumentToFile(IDocument document, IFile file, boolean overwrite, IProgressMonitor monitor)
throws CoreException {
Diagram diagram = (Diagram)document.getContent();
Resource resource = diagram.eResource();
IFile resourceFile = WorkspaceSynchronizer.getFile(resource);
// if the diagram in the document is referring to another file, then we should
// create a copy of this diagram and save it to the new file, save as scenario.
if(resourceFile != null && !resourceFile.equals(file)) {
diagram = copyDiagramResource(diagram, file);
}
IDiagramDocument diagramDocument = (IDiagramDocument)document;
TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
doSave(domain, file, diagram, null, monitor);
}
protected void doSave(TransactionalEditingDomain domain, IFile file,
Diagram diagram, Map options, IProgressMonitor monitor)
throws CoreException {
if (options == null) {
DiagramIOUtil.save(domain, file, diagram, DiagramIOUtil
.hasUnrecognizedData(diagram.eResource()), monitor);
} else {
DiagramIOUtil.save(domain, file, diagram, monitor, options);
}
}
static public void save(TransactionalEditingDomain domain, IFile file, Diagram diagram, boolean bKeepUnrecognizedData, IProgressMonitor progressMonitor) throws CoreException {
Map options = new HashMap();
if(bKeepUnrecognizedData)
options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
save(domain, file, diagram, progressMonitor, options);
}
static public void save(TransactionalEditingDomain domain, IFile file, Diagram diagram, IProgressMonitor progressMonitor, Map options) throws CoreException {
Resource notationModel = ((EObject) diagram).eResource();
String fileName = file.getFullPath().toOSString();
notationModel.setURI(URI.createPlatformResourceURI(fileName, true));
try {
notationModel.save(options);
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, EditorPlugin
.getPluginId(), EditorStatusCodes.RESOURCE_FAILURE, e
.getLocalizedMessage(), null));
}
if (progressMonitor != null)
progressMonitor.done();
}
public void doSave(IProgressMonitor progressMonitor) { }
b) Second, the method above call the methon:
protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) {}
this method is in class DiagramDocumentEditor.
c)AbstractDocumentProvider)中的方法
public final void saveDocument(IProgressMonitor monitor, final Object element, final IDocument document, final boolean overwrite) throws CoreException {
if (element == null)
return;
executeOperation(getSaveOperation(element, document, overwrite), monitor);
}
d) 在自己的Document provider里面冲载方法
protected void saveDocumentToFile(IDocument document, IFile file,
boolean overwrite, IProgressMonitor monitor) throws CoreException {}
e) FileDiagramDocumentProvider种的方法
protected void saveDocumentToFile(IDocument document, IFile file, boolean overwrite, IProgressMonitor monitor)
throws CoreException {
Diagram diagram = (Diagram)document.getContent();
Resource resource = diagram.eResource();
IFile resourceFile = WorkspaceSynchronizer.getFile(resource);
// if the diagram in the document is referring to another file, then we should
// create a copy of this diagram and save it to the new file, save as scenario.
if(resourceFile != null && !resourceFile.equals(file)) {
diagram = copyDiagramResource(diagram, file);
}
IDiagramDocument diagramDocument = (IDiagramDocument)document;
TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
doSave(domain, file, diagram, null, monitor);
}
protected void doSave(TransactionalEditingDomain domain, IFile file,
Diagram diagram, Map options, IProgressMonitor monitor)
throws CoreException {
if (options == null) {
DiagramIOUtil.save(domain, file, diagram, DiagramIOUtil
.hasUnrecognizedData(diagram.eResource()), monitor);
} else {
DiagramIOUtil.save(domain, file, diagram, monitor, options);
}
}
static public void save(TransactionalEditingDomain domain, IFile file, Diagram diagram, boolean bKeepUnrecognizedData, IProgressMonitor progressMonitor) throws CoreException {
Map options = new HashMap();
if(bKeepUnrecognizedData)
options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
save(domain, file, diagram, progressMonitor, options);
}
static public void save(TransactionalEditingDomain domain, IFile file, Diagram diagram, IProgressMonitor progressMonitor, Map options) throws CoreException {
Resource notationModel = ((EObject) diagram).eResource();
String fileName = file.getFullPath().toOSString();
notationModel.setURI(URI.createPlatformResourceURI(fileName, true));
try {
notationModel.save(options);
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, EditorPlugin
.getPluginId(), EditorStatusCodes.RESOURCE_FAILURE, e
.getLocalizedMessage(), null));
}
if (progressMonitor != null)
progressMonitor.done();
}