Home » Modeling » EMF » Failed on loading xcore model programmatically
| |
Re: Failed on loading xcore model programmatically [message #1809412 is a reply to message #1809405] |
Mon, 15 July 2019 18:50 |
Dimg Cim Messages: 59 Registered: December 2015 |
Member |
|
|
Hi Ed,
thanks for the quick reply. I load the xcore file in a rcp with jdt plug-ins. I use this dialog to open the xcore file
public class EcoreResourceDialog extends ResourceDialog {
public EcoreResourceDialog(Shell parent, String title, int style) {
super(parent, title, style);
}
@Override
protected void prepareBrowseFileSystemButton(Button browseFileSystemButton) {
browseFileSystemButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
FileDialog fileDialog = new FileDialog(getShell(), style);
fileDialog.setFilterExtensions(new String[] { "*.ecore" });
fileDialog.open();
String filterPath = fileDialog.getFilterPath();
if (isMulti()) {
String[] fileNames = fileDialog.getFileNames();
StringBuffer uris = new StringBuffer();
for (int i = 0, len = fileNames.length; i < len; i++) {
uris.append(URI.createFileURI(filterPath + File.separator + fileNames[i]).toString());
uris.append(" ");
}
uriField.setText((uriField.getText() + " " + uris.toString()).trim());
} else {
String fileName = fileDialog.getFileName();
if (fileName != null) {
uriField.setText(URI.createFileURI(filterPath + File.separator + fileName).toString());
}
}
}
});
}
@Override
protected void prepareBrowseWorkspaceButton(Button browseWorkspaceButton) {
browseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
List<ViewerFilter> filters = new ArrayList<ViewerFilter>();
filters.add(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IFile) {
return "ecore".equals(((IFile) element).getFileExtension());
}
return true;
}
});
if (isMulti()) {
StringBuffer uris = new StringBuffer();
IFile[] files = WorkspaceResourceDialog.openFileSelection(getShell(), null, null, true,
getContextSelection(), filters);
for (int i = 0, len = files.length; i < len; i++) {
uris.append(URI.createPlatformResourceURI(files[i].getFullPath().toString(), true));
uris.append(" ");
}
uriField.setText((uriField.getText() + " " + uris.toString()).trim());
} else {
IFile file = null;
if (isSave()) {
String path = getContextPath();
file = WorkspaceResourceDialog.openNewFile(getShell(), null, null,
path != null ? new Path(path) : null, filters);
} else {
IFile[] files = WorkspaceResourceDialog.openFileSelection(getShell(), null, null, false,
getContextSelection(), filters);
if (files.length != 0) {
file = files[0];
}
}
if (file != null) {
uriField.setText(URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
}
}
}
private String getContextPath() {
return context != null && context.isPlatformResource()
? URI.createURI(".").resolve(context).path().substring(9)
: null;
}
private Object[] getContextSelection() {
String path = getContextPath();
if (path != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(path);
if (resource != null && resource.isAccessible()) {
return new Object[] { resource };
}
}
return null;
}
});
}
}
and with the upper code to load the xcore file.
This dialog is opened by a command via context menu in PackageExplorer.
[Updated on: Mon, 15 July 2019 19:18] Report message to a moderator
|
|
| |
Re: Failed on loading xcore model programmatically [message #1809439 is a reply to message #1809436] |
Tue, 16 July 2019 08:41 |
Dimg Cim Messages: 59 Registered: December 2015 |
Member |
|
|
Thank you for your help, it seems to work now. It worked with the file:/c:/ URI.
Another question to the xcore. I modelled this
@GenModel(multipleEditorPages="false",
creationIcons="false",
editDirectory="/de.example.edit/src-gen",
editorDirectory="/de.example.editor/src-gen",
richClientPlatform="true",
codeFormatting="true",
importerID="org.eclipse.emf.importer.ecore",
runtimePlatform="RCP",
fileExtensions="dec",
tableProviders="true", dataTypeConverters="true")
package de.example
class DecProject{
contains Section[0..*] sections
}
* How can I access the package "de.example"
* After loading the xcore model, I get a XPackageImpl, from this object I cannot found the package path "de.example"
* How can I access the XPackage#eStorage, in the XPackageMapping are a lot of information I want to read out, e.g. here one of the information would be the baspackage.
* If a file extension is defined I can read it out via String fileExtensions = xPackage.getAnnotations().get(1).getDetails().get("fileExtensions"); but if not, should I use the XPackageMapping?
P.S. With som experementing I got this
EList<Adapter> adapters = xPackage.eAdapters();
Adapter adapter = adapters.get(2);
if (adapter instanceof XPackageMapping) {
XPackageMapping mapping = (XPackageMapping) adapter;
String basePackage = mapping.getGenPackage().getBasePackage();
}
Are there a nicer way to get this?
[Updated on: Tue, 16 July 2019 10:47] Report message to a moderator
|
|
| |
Re: Failed on loading xcore model programmatically [message #1809483 is a reply to message #1809412] |
Tue, 16 July 2019 18:24 |
Dimg Cim Messages: 59 Registered: December 2015 |
Member |
|
|
My goal is to generate a tree view which is worked for all defined emf xcore model with emf.edit support like undo, redo, editing support, dnd, etc. Currently I implement this for JavaFX, later for more frontend apis like vaadin. I know there are a lot of rendering framework for EMF, but for better understanding is to work in there. Further I defined a small dsl in xtext, which generate all classes required for the treeview and it needs {Model]Factory, {Model}Package, {Model}Switch etc. e.g. for the context menu to create new items in the treeview.
|
|
| | |
Goto Forum:
Current Time: Fri Mar 29 00:38:28 GMT 2024
Powered by FUDForum. Page generated in 0.03637 seconds
|