1 | try↵ | | 1 | try↵
|
2 | {↵ | | 2 | {↵
|
3 | // Remember the file.↵ | | 3 | // Remember the file.↵
|
4 | //↵ | | 4 | //↵
|
5 | final IFile modelFile = getModelFile();↵ | | 5 | final IFile modelFile = getModelFile();↵
|
|
6 | // Do the work within an operation.↵ | | 6 | // Do the work within an operation.↵
|
7 | //↵ | | 7 | //↵
|
8 | WorkspaceModifyOperation operation =↵ | | 8 | WorkspaceModifyOperation operation =↵
|
9 | new WorkspaceModifyOperation()↵ | | 9 | new WorkspaceModifyOperation()↵
|
10 | {↵ | | 10 | {↵
|
11 | @Override↵ | | 11 | @Override↵
|
12 | protected void execute(IProgressMonitor progressMonitor)↵ | | 12 | protected void execute(IProgressMonitor progressMonitor)↵
|
13 | {↵ | | 13 | {↵
|
14 | try↵ | | 14 | try↵
|
15 | {↵ | | 15 | {↵
|
16 | // Create a resource set↵ | | 16 | // Create a resource set↵
|
17 | //↵ | | 17 | //↵
|
18 | ResourceSet resourceSet = new ResourceSetImpl();↵ | | 18 | ResourceSet resourceSet = new ResourceSetImpl();↵
|
|
19 | // Get the URI of the model file.↵ | | 19 | // Get the URI of the model file.↵
|
20 | //↵ | | 20 | //↵
|
21 | URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);↵ | | 21 | URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);↵
|
|
22 | // Create a resource for this file.↵ | | 22 | // Create a resource for this file.↵
|
23 | //↵ | | 23 | //↵
|
24 | Resource resource = resourceSet.createResource(fileURI, Ecore2XMLPackage.eCONTENT_TYPE);↵ | | 24 | Resource resource = resourceSet.createResource(fileURI, Ecore2EcorePackage.eCONTENT_TYPE);↵
|
|
25 | // Add the initial model object to the contents.↵ | | 25 | // Add the initial model object to the contents.↵
|
26 | //↵ | | 26 | //↵
|
27 | EObject rootObject = createInitialModel();↵ | | 27 | EObject rootObject = createInitialModel();↵
|
28 | if (rootObject != null)↵ | | 28 | if (rootObject != null)↵
|
29 | {↵ | | 29 | {↵
|
30 | resource.getContents().add(rootObject);↵ | | 30 | resource.getContents().add(rootObject);↵
|
31 | }↵ | | 31 | }↵
|
|
32 | // Save the contents of the resource to the file system.↵ | | 32 | // Save the contents of the resource to the file system.↵
|
33 | //↵ | | 33 | //↵
|
34 | Map<Object, Object> options = new HashMap<Object, Object>();↵ | | 34 | Map<Object, Object> options = new HashMap<Object, Object>();↵
|
35 | options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());↵ | | 35 | options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());↵
|
36 | resource.save(options);↵ | | 36 | resource.save(options);↵
|
37 | }↵ | | 37 | }↵
|
38 | catch (Exception exception)↵ | | 38 | catch (Exception exception)↵
|
39 | {↵ | | 39 | {↵
|
40 | Ecore2XMLUIPlugin.INSTANCE.log(exception);↵ | | 40 | Ecore2EcoreEditorPlugin.INSTANCE.log(exception);↵
|
41 | }↵ | | 41 | }↵
|
42 | finally↵ | | 42 | finally↵
|
43 | {↵ | | 43 | {↵
|
44 | progressMonitor.done();↵ | | 44 | progressMonitor.done();↵
|
45 | }↵ | | 45 | }↵
|
46 | }↵ | | 46 | }↵
|
47 | };↵ | | 47 | };↵
|
|
48 | getContainer().run(false, false, operation);↵ | | 48 | getContainer().run(false, false, operation);↵
|
|
49 | // Select the new file resource in the current view.↵ | | 49 | // Select the new file resource in the current view.↵
|
50 | //↵ | | 50 | //↵
|
51 | IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();↵ | | 51 | IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();↵
|
52 | IWorkbenchPage page = workbenchWindow.getActivePage();↵ | | 52 | IWorkbenchPage page = workbenchWindow.getActivePage();↵
|
53 | final IWorkbenchPart activePart = page.getActivePart();↵ | | 53 | final IWorkbenchPart activePart = page.getActivePart();↵
|
54 | if (activePart instanceof ISetSelectionTarget)↵ | | 54 | if (activePart instanceof ISetSelectionTarget)↵
|
55 | {↵ | | 55 | {↵
|
56 | final ISelection targetSelection = new StructuredSelection(modelFile);↵ | | 56 | final ISelection targetSelection = new StructuredSelection(modelFile);↵
|
57 | getShell().getDisplay().asyncExec↵ | | 57 | getShell().getDisplay().asyncExec↵
|
58 | (new Runnable()↵ | | 58 | (new Runnable()↵
|
59 | {↵ | | 59 | {↵
|
60 | public void run()↵ | | 60 | public void run()↵
|
61 | {↵ | | 61 | {↵
|
62 | ((ISetSelectionTarget)activePart).selectReveal(targetSelection);↵ | | 62 | ((ISetSelectionTarget)activePart).selectReveal(targetSelection);↵
|
63 | }↵ | | 63 | }↵
|
64 | });↵ | | 64 | });↵
|
65 | }↵ | | 65 | }↵
|
|
66 | // Open an editor on the new file.↵ | | 66 | // Open an editor on the new file.↵
|
67 | //↵ | | 67 | //↵
|
68 | try↵ | | 68 | try↵
|
69 | {↵ | | 69 | {↵
|
70 | page.openEditor↵ | | 70 | page.openEditor↵
|
71 | (new FileEditorInput(modelFile),↵ | | 71 | (new FileEditorInput(modelFile),↵
|
72 | workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());↵ | | 72 | workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());↵
|
73 | }↵ | | 73 | }↵
|
74 | catch (PartInitException exception)↵ | | 74 | catch (PartInitException exception)↵
|
75 | {↵ | | 75 | {↵
|
76 | MessageDialog.openError(workbenchWindow.getShell(), Ecore2XMLUIPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); //$NON-NLS-1$↵ | | 76 | MessageDialog.openError(workbenchWindow.getShell(), Ecore2EcoreEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());↵
|
77 | return false;↵ | | 77 | return false;↵
|
78 | }↵ | | 78 | }↵
|
|
79 | return true;↵ | | 79 | return true;↵
|
80 | }↵ | | 80 | }↵
|
81 | catch (Exception exception)↵ | | 81 | catch (Exception exception)↵
|
82 | {↵ | | 82 | {↵
|
83 | Ecore2XMLUIPlugin.INSTANCE.log(exception);↵ | | 83 | Ecore2EcoreEditorPlugin.INSTANCE.log(exception);↵
|
84 | return false;↵ | | 84 | return false;↵
|
85 | } | | 85 | }
|