|
Lines 27-37
Link Here
|
| 27 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
27 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
| 28 |
IStructuredSelection selection |
28 |
IStructuredSelection selection |
| 29 |
= (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); |
29 |
= (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); |
| 30 |
|
30 |
|
| 31 |
// only applies for a singly selected objects that adapt to JpaXmlResource or XmlFile |
31 |
for (Object selectedObject : selection.toArray()) { |
| 32 |
Object selectedObject = selection.getFirstElement(); |
32 |
upgradeXmlFileVersion(selectedObject); |
|
|
33 |
} |
| 34 |
return null; |
| 35 |
} |
| 36 |
|
| 37 |
protected void upgradeXmlFileVersion(Object selectedObject) { |
| 33 |
JpaXmlResource xmlResource = |
38 |
JpaXmlResource xmlResource = |
| 34 |
(JpaXmlResource) Platform.getAdapterManager().getAdapter(selectedObject, JpaXmlResource.class); |
39 |
(JpaXmlResource) Platform.getAdapterManager().getAdapter(selectedObject, JpaXmlResource.class); |
| 35 |
if (xmlResource == null) { |
40 |
if (xmlResource == null) { |
| 36 |
XmlFile xmlFile = |
41 |
XmlFile xmlFile = |
| 37 |
(XmlFile) Platform.getAdapterManager().getAdapter(selectedObject, XmlFile.class); |
42 |
(XmlFile) Platform.getAdapterManager().getAdapter(selectedObject, XmlFile.class); |
|
Lines 40-60
Link Here
|
| 40 |
} |
45 |
} |
| 41 |
} |
46 |
} |
| 42 |
if (xmlResource == null) { |
47 |
if (xmlResource == null) { |
| 43 |
return null; |
48 |
return; |
| 44 |
} |
49 |
} |
| 45 |
|
50 |
|
| 46 |
final JpaRootEObject root = xmlResource.getRootObject(); |
51 |
final JpaRootEObject root = xmlResource.getRootObject(); |
| 47 |
IContentType contentType = xmlResource.getContentType(); |
52 |
IContentType contentType = xmlResource.getContentType(); |
| 48 |
JpaProject jpaProject = JptCorePlugin.getJpaProject(xmlResource.getProject()); |
53 |
JpaProject jpaProject = JptCorePlugin.getJpaProject(xmlResource.getProject()); |
| 49 |
final String newVersion = jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(contentType).getVersion(); |
54 |
final String newVersion = jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(contentType).getVersion(); |
| 50 |
|
55 |
|
| 51 |
xmlResource.modify( |
56 |
xmlResource.modify( |
| 52 |
new Runnable() { |
57 |
new Runnable() { |
| 53 |
public void run() { |
58 |
public void run() { |
| 54 |
root.setVersion(newVersion); |
59 |
root.setVersion(newVersion); |
| 55 |
} |
60 |
} |
| 56 |
}); |
61 |
}); |
| 57 |
|
|
|
| 58 |
return null; |
| 59 |
} |
62 |
} |
| 60 |
} |
63 |
} |