Author: joern Date: Tue Oct 11 11:29:27 2011 New Revision: 1181718 URL: http://svn.apache.org/viewvc?rev=1181718&view=rev Log: UIMA-2245 Added session preferences to replace the editor annotation status object.
Removed: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/EditorAnnotationStatus.java Modified: uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasEditor.java uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java Modified: uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java?rev=1181718&r1=1181717&r2=1181718&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java (original) +++ uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java Tue Oct 11 11:29:27 2011 @@ -39,7 +39,6 @@ import org.apache.uima.caseditor.editor. import org.apache.uima.caseditor.editor.CasDocumentProvider; import org.apache.uima.caseditor.editor.DocumentFormat; import org.apache.uima.caseditor.editor.DocumentUimaImpl; -import org.apache.uima.caseditor.editor.EditorAnnotationStatus; import org.apache.uima.caseditor.editor.ICasDocument; import org.apache.uima.caseditor.editor.ICasEditor; import org.eclipse.core.resources.IFile; @@ -125,7 +124,7 @@ public class DefaultCasDocumentProvider */ private Map<String, String> documentToTypeSystemMap = new HashMap<String, String>(); - private Map<String, EditorAnnotationStatus> sharedEditorStatus = new HashMap<String, EditorAnnotationStatus>(); + private Map<String, IPreferenceStore> sessionPreferenceStores = new HashMap<String, IPreferenceStore>(); /** * This map resolves a type system to a style. It is used to cache type system @@ -425,21 +424,18 @@ public class DefaultCasDocumentProvider return typeSystemPreferences.get(getPreferenceFileForTypeSystem(tsId)); } - // TODO: How to move these two methods away? @Override - protected EditorAnnotationStatus getEditorAnnotationStatus(Object element) { - EditorAnnotationStatus status = sharedEditorStatus.get(getTypesystemId(element)); - - if (status == null) - status = new EditorAnnotationStatus(CAS.TYPE_NAME_ANNOTATION, null, CAS.NAME_DEFAULT_SOFA); - - return status; - } + public IPreferenceStore getSessionPreferenceStore(Object element) { + + // lookup one, and if it does not exist create a new one, and put it! + IPreferenceStore store = sessionPreferenceStores.get(getTypesystemId(element)); + + if (store == null) { + store = new PreferenceStore(); + sessionPreferenceStores.put(getTypesystemId(element), store); + } - @Override - protected void setEditorAnnotationStatus(Object element, - EditorAnnotationStatus editorAnnotationStatus) { - sharedEditorStatus.put(getTypesystemId(element), editorAnnotationStatus); + return store; } void setTypeSystem(String document, String typeSystem) { Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=1181718&r1=1181717&r2=1181718&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original) +++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Tue Oct 11 11:29:27 2011 @@ -601,7 +601,6 @@ public final class AnnotationEditor exte @SuppressWarnings("unchecked") public Object getAdapter(Class adapter) { - if (IContentOutlinePage.class.equals(adapter) && getDocument() != null) { if (mOutlinePage == null) { mOutlinePage = new AnnotationOutline(this); @@ -808,7 +807,9 @@ public final class AnnotationEditor exte if (getDocument() != null) { // Synchronize shown types with the editor - Collection<String> shownTypes = getCasDocumentProvider().getShownTypes(input); + String shownTypesString = getCasDocumentProvider().getSessionPreferenceStore(input).getString("LastShownTypes"); + + String[] shownTypes = shownTypesString.split(";"); for (String shownType : shownTypes) { @@ -867,7 +868,6 @@ public final class AnnotationEditor exte if (getDocument() != null) { mShowAnnotationsMenu = new ShowAnnotationsMenu( - null, getDocument().getCAS().getTypeSystem(), shownAnnotationTypes); mShowAnnotationsMenu.addListener(new IShowAnnotationsListener() { @@ -882,7 +882,6 @@ public final class AnnotationEditor exte Type addedAnnotationType = clonedCollection.get(0); showAnnotationType(addedAnnotationType, true); - getCasDocumentProvider().addShownType(getEditorInput(), addedAnnotationType); } else if (selection.size() < shownAnnotationTypes.size()) { List<Type> clonedCollection = new ArrayList<Type>(shownAnnotationTypes); @@ -890,18 +889,13 @@ public final class AnnotationEditor exte Type removedAnnotationType = clonedCollection.get(0); showAnnotationType(removedAnnotationType, false); - getCasDocumentProvider().removeShownType(getEditorInput(), removedAnnotationType); } // Repaint after annotations are changed mPainter.paint(IPainter.CONFIGURATION); - EditorAnnotationStatus status = - getCasDocumentProvider().getEditorAnnotationStatus(getEditorInput()); - - getCasDocumentProvider().setEditorAnnotationStatus(getEditorInput(), - new EditorAnnotationStatus(status.getMode(), selection, getDocument().getCAS().getViewName())); - + setEditorSessionPreferences(); + if (mEditorListener != null) { for (IAnnotationEditorModifyListener listener : mEditorListener) listener.showAnnotationsChanged(selection); @@ -909,12 +903,19 @@ public final class AnnotationEditor exte } }); - EditorAnnotationStatus status = - getCasDocumentProvider().getEditorAnnotationStatus(getEditorInput()); + IPreferenceStore sessionPreferences = + getCasDocumentProvider().getSessionPreferenceStore(getEditorInput()); - setAnnotationMode(getDocument().getType(status.getMode())); + // TODO: Define constants for these settings! - String lastActiveViewName = status.getLastActiveCasViewName(); + String lastModeTypeName = sessionPreferences.getString("LastUsedModeType"); + + if (lastModeTypeName.length() == 0) + lastModeTypeName = CAS.TYPE_NAME_ANNOTATION; + + setAnnotationMode(getDocument().getType(lastModeTypeName)); + + String lastActiveViewName = sessionPreferences.getString("LastActiveCasViewName"); try { // TODO: Missing compatibility check!!! @@ -923,7 +924,10 @@ public final class AnnotationEditor exte } catch (CASRuntimeException e) { // ignore, view is not available - // TODO: Using exceptions for control flow is very bad practice + // Note: Using exceptions for control flow is very bad practice + // TODO: Is there a way to check which views are available?! + // Maybe we should iterate over all available views, and then + // check if it is available! showView(CAS.NAME_DEFAULT_SOFA); } } @@ -1016,7 +1020,7 @@ public final class AnnotationEditor exte highlight(0, 0); - setProjectEditorStatus(); + setEditorSessionPreferences(); updateStatusLineModeItem(); @@ -1309,7 +1313,7 @@ public final class AnnotationEditor exte // All annotations will be synchronized in the document listener // Last opened view should be remembered, in case a new editor is opened - setProjectEditorStatus(); + setEditorSessionPreferences(); // Check if CAS view is compatible, only if compatible the listeners // to update the annotations in the editor can be registered @@ -1441,13 +1445,29 @@ public final class AnnotationEditor exte // getSourceViewer() returns null here ... but why ? return getSourceViewer().getTextWidget().getSelectionCount() != 0; } - - private void setProjectEditorStatus() { - // TODO: do not replace if equal ... check this - EditorAnnotationStatus status = new EditorAnnotationStatus(getAnnotationMode().getName(), - mShowAnnotationsMenu.getSelectedTypes(), getDocument().getCAS().getViewName()); - - getCasDocumentProvider().setEditorAnnotationStatus(getEditorInput(), status); + + /** + * Set the session data which should be used to initalize the next Cas Editor which + * is opened. + */ + private void setEditorSessionPreferences() { + + // TODO: Define constants with prefix for these settings ... so they don't conflict with other plugins! + + IPreferenceStore sessionStore = getCasDocumentProvider(). + getSessionPreferenceStore(getEditorInput()); + + sessionStore.setValue("LastActiveCasViewName", getDocument().getCAS().getViewName()); + sessionStore.setValue("LastUsedModeType", getAnnotationMode().getName()); + + StringBuilder shownTypesString = new StringBuilder(); + + for (Type shownType : getShownAnnotationTypes()) { + shownTypesString.append(shownType.getName()); + shownTypesString.append(";"); + } + + sessionStore.setValue("LastShownTypes", shownTypesString.toString()); } /** Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java?rev=1181718&r1=1181717&r2=1181718&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java (original) +++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java Tue Oct 11 11:29:27 2011 @@ -19,18 +19,15 @@ package org.apache.uima.caseditor.editor; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.apache.uima.cas.Type; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceStore; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.IElementStateListener; @@ -89,52 +86,36 @@ public abstract class CasDocumentProvide return elementErrorStatus.get(element); } + /** + * Retrieves the persistent per type system preference store. This store is usually + * saved in relation to the type system, e.g. an ide plugin could save a preference file + * next to the type system file. + * + * @param element + * @return + */ // Problem: Keys maybe should be pre-fixed depending on the plugin which is storing values + // TODO: Should it be renamed to getPersistentPreferenceStore? public abstract IPreferenceStore getTypeSystemPreferenceStore(Object element); // Might fail silently, only log an error public abstract void saveTypeSystemPreferenceStore(Object element); - - // TODO: We also need a set method here - // TODO: This is somehow duplicated, once in the editor annotation status - // and once in the - Collection<String> getShownTypes(Object element) { - PreferenceStore prefStore = (PreferenceStore) getTypeSystemPreferenceStore(element); - - Set<String> shownTypes = new HashSet<String>(); - - for (String prefName : prefStore.preferenceNames()) { - if (prefName.endsWith(".isShown")) { - if (prefStore.getBoolean(prefName)) - shownTypes.add(prefName.substring(0, prefName.lastIndexOf(".isShown"))); - } - } - - return shownTypes; - } - - // TODO: Move to Annotation Editor - void addShownType(Object element, Type type) { - IPreferenceStore prefStore = getTypeSystemPreferenceStore(element); - prefStore.setValue(type.getName() + ".isShown", Boolean.TRUE.toString()); - - saveTypeSystemPreferenceStore(element); - } - - // TODO: Move to Annotation Editor - void removeShownType(Object element, Type type) { - IPreferenceStore prefStore = getTypeSystemPreferenceStore(element); - prefStore.setValue(type.getName() + ".isShown", Boolean.FALSE.toString()); - - saveTypeSystemPreferenceStore(element); - } + /** + * Retrieves the session preference store. This preference store is used to + * store session data which should be used to initialize a freshly opened editor. + * + * @param element + * + * heise.@return + */ + public abstract IPreferenceStore getSessionPreferenceStore(Object element); // TODO: Redesign the editor annotation status ... maybe this could be a session and ts scoped pref store? - protected abstract EditorAnnotationStatus getEditorAnnotationStatus(Object element); + // protected abstract EditorAnnotationStatus getEditorAnnotationStatus(Object element); - protected abstract void setEditorAnnotationStatus(Object element, - EditorAnnotationStatus editorAnnotationStatus); + // protected abstract void setEditorAnnotationStatus(Object element, + // EditorAnnotationStatus editorAnnotationStatus); public abstract Composite createTypeSystemSelectorForm(ICasEditor editor, Composite parent, IStatus status); Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasEditor.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasEditor.java?rev=1181718&r1=1181717&r2=1181718&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasEditor.java (original) +++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasEditor.java Tue Oct 11 11:29:27 2011 @@ -33,5 +33,7 @@ public interface ICasEditor extends IEdi ICasDocument getDocument(); + CasDocumentProvider getCasDocumentProvider(); + void reopenEditorWithNewTypeSystem(); } Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java?rev=1181718&r1=1181717&r2=1181718&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java (original) +++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java Tue Oct 11 11:29:27 2011 @@ -28,7 +28,6 @@ import java.util.Set; import org.apache.uima.cas.CAS; import org.apache.uima.cas.Type; import org.apache.uima.cas.TypeSystem; -import org.apache.uima.caseditor.editor.EditorAnnotationStatus; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -61,8 +60,7 @@ public class ShowAnnotationsMenu extends * @param type * @param typeSystem */ - public ShowAnnotationsMenu(EditorAnnotationStatus status, - TypeSystem typeSystem, Collection<Type> shownTypes) { + public ShowAnnotationsMenu(TypeSystem typeSystem, Collection<Type> shownTypes) { super(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION), typeSystem); for (Type type : shownTypes) {