|
|
Re: using part of EMF model in Preferences [message #1735769 is a reply to message #1735738] |
Wed, 22 June 2016 14:41 |
Martin Jacob Messages: 191 Registered: July 2009 |
Senior Member |
|
|
Thanks Ed,
Note:
- mVehicleSelection it's the root EObject of the later XML snipped
my solution reading:
ComposedAdapterFactory adapterFactory = new
ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
BasicCommandStack commandStack = new BasicCommandStack();
mEditingDomain = new AdapterFactoryEditingDomain(adapterFactory,
commandStack, new HashMap<Resource, Boolean>());
IPreferenceStore lPreferenceStore =
Activator.getDefault().getPreferenceStore();
XMLResource lXMLResource = new XMLResourceImpl();
String lPref =
lPreferenceStore.getString(PreferenceConstants.P_VEHICLE_CHART_TYPE_ENGINE_ALL);
StringReader lStringReader = new StringReader(lPref);
InputSource lInputSource = new InputSource(lStringReader);
Map<Object, Object> lOptions = new HashMap<Object, Object>();
try {
lXMLResource.load(lInputSource, lOptions);
} catch (IOException e) {
e.printStackTrace();
}
mVehicleSelection = EcoreUtil.copy((VehicleSelection)
lXMLResource.getContents().get(0));
Note:
- Its important to create a copy of the XMLResource.getContent().get(0)
as the content is read only.
solution writing:
IPreferenceStore lPreferenceStore =
Activator.getDefault().getPreferenceStore();
XMLResource lXMLResource = new XMLResourceImpl();
Map<Object, Object> lOptions = new HashMap<Object, Object>();
List<EObject> lRoot = new ArrayList<EObject>();
lRoot.add(mVehicleSelection);
lOptions.put(XMLResource.OPTION_ROOT_OBJECTS, lRoot);
StringWriter lStringWriter = new StringWriter();
URIConverter.WriteableOutputStream lUws = new
URIConverter.WriteableOutputStream(lStringWriter, "UTF-8");
try {
lXMLResource.save(lUws, lOptions);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String lPref = lStringWriter.toString();
lPreferenceStore.setValue(PreferenceConstants.P_VEHICLE_CHART_TYPE_ENGINE_ALL,
lPref);
Martin
|
|
|
Powered by
FUDForum. Page generated in 0.04306 seconds