Java Reference
In-Depth Information
try {
// Remember the file.
final IFile modelFile = getModelFile();
// Do the work within an operation.
WorkspaceModifyOperation operation = new WorkspaceModifyOperation()
{
@Override
protected void execute(IprogressMonitor progressMonitor) {
try {
// Create a resource set.
ResourceSet resourceSet = new ResourceSetImpl();
// Get the URI of the model file.
URI fileURI = URI.createPlatformResourceURI(
modelFile.getFullPath().toString(), true);
// Create a resource for this file.
Resource resource = resourceSet.createResource(fileURI);
// Add the initial model object to the contents.
EObject rootObject = createInitialModel();
if (rootObject != null) {
resource.getContents().add(rootObject);
}
// Create the diagram.
Diagram diagram = ViewService.createDiagram(rootObject,
ModelEditPart.MODEL_ID,
RequirementsDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
if (diagram != null) {
resource.getContents().add(diagram);
diagram.setName(fileURI.lastSegment());
diagram.setElement(rootObject);
}
// Save the contents of the resource to the file system.
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING,
initialObjectCreationPage.getEncoding());
resource.save(options);
} catch (Exception exception) {
RequirementsEditorPlugin.INSTANCE.log(exception);
} finally {
progressMonitor.done();
}
}
};
// . . .
}
We'll use this Wizard exclusively to create requirements models, so we can
remove the newWizards contribution in our diagram plug-in manifest.
Search WWH ::




Custom Search