.getRoot()
.getFile(
new Path(getPreferenceFileForTypeSystem(typeSystemFile.getFullPath()
.toPortableString())));
PreferenceStore tsPrefStore = typeSystemPreferences.get(prefFile.getFullPath()
.toPortableString());
// If lookup for store failed ...
if (tsPrefStore == null) {
if (prefFile.exists()) {
tsPrefStore = new PreferenceStore(prefFile.getName());
try {
tsPrefStore.load(prefFile.getContents()); // TODO: Close stream!
} catch (IOException e) {
e.printStackTrace(); // TODO: Handle this correctly!
}
} else {
// UIMA-2245
// DotCorpus to Eclipse PreferenceStore migration code.
// If there is DotCorpus style file and not yet a preference store file
// the settings from the DotCorpus style file should be written into a preference store
// file.
IFile styleFile = ResourcesPlugin
.getWorkspace()
.getRoot()
.getFile(
new Path(getStyleFileForTypeSystem(typeSystemFile.getFullPath()
.toPortableString())));
if (styleFile.exists()) {
InputStream styleFileIn = null;
;
DotCorpus dotCorpus = null;
try {
styleFileIn = styleFile.getContents();
dotCorpus = DotCorpusSerializer.parseDotCorpus(styleFileIn);
} finally {
if (styleFileIn != null)
try {
styleFileIn.close();
} catch (IOException e) {
CasEditorPlugin.log(e);
}
}
if (dotCorpus != null) {
tsPrefStore = new PreferenceStore(prefFile.getName());
for (AnnotationStyle style : dotCorpus.getAnnotationStyles()) {
AnnotationStyle.putAnnotatationStyleToStore(tsPrefStore, style);
}
for (String shownType : dotCorpus.getShownTypes()) {
tsPrefStore.putValue(shownType + ".isShown", "true");
}
ByteArrayOutputStream prefOut = new ByteArrayOutputStream();
try {
tsPrefStore.save(prefOut, "");
} catch (IOException e) {
// Should never happen!
CasEditorPlugin.log(e);
}
// TODO: Do we need to handle exceptions here?
prefFile.create(new ByteArrayInputStream(prefOut.toByteArray()), IFile.FORCE, null);
}
}
}
// No preference defined, lets use defaults
if (tsPrefStore == null) {
tsPrefStore = new PreferenceStore(prefFile.getName());
CAS cas = DocumentUimaImpl.getVirginCAS(typeSystemFile);
TypeSystem ts = cas.getTypeSystem();
Collection<AnnotationStyle> defaultStyles = getConfiguredAnnotationStyles(tsPrefStore,
ts);
Collection<AnnotationStyle> newStyles = DefaultColors.assignColors(ts, defaultStyles);
// TODO: Settings defaults must be moved to the AnnotationEditor
for (AnnotationStyle style : newStyles) {
AnnotationStyle.putAnnotatationStyleToStore(tsPrefStore, style);
}
}
typeSystemPreferences.put(prefFile.getFullPath().toPortableString(), tsPrefStore);
}
documentToTypeSystemMap.put(casFile.getFullPath().toPortableString(), typeSystemFile
.getFullPath().toPortableString());
IPreferenceStore store = sessionPreferenceStores.get(getTypesystemId(element));
if (store == null) {
PreferenceStore newStore = new PreferenceStore();
sessionPreferenceStores.put(getTypesystemId(element), newStore);
newStore.addPropertyChangeListener(new SaveSessionPreferencesTrigger(element));
String sessionPreferenceString = typeSystemFile.getPersistentProperty(new QualifiedName(
"", CAS_EDITOR_SESSION_PROPERTIES));
if (sessionPreferenceString != null) {
try {
newStore.load(new ByteArrayInputStream(sessionPreferenceString.getBytes("UTF-8")));
} catch (IOException e) {
CasEditorPlugin.log(e);
}
}
}