Author: joern
Date: Fri Oct 1 12:55:26 2010
New Revision: 1003520
URL: http://svn.apache.org/viewvc?rev=1003520&view=rev
Log:
UIMA-1887 Moved Annoation Styling UI and handling over to the actual editor.
See point 2. in the issue.
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/IAnnotationStyleListener.java
(with props)
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleView.java
(with props)
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleViewPage.java
(with props)
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationTypeNode.java
(with props)
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/EditorAnnotationPropertyPage.java
(with props)
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/NlpAnnotationPropertyPage.java
(with props)
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml
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/DefaultCasDocumentProvider.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/NlpPerspectiveFactory.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/AnnotationPropertyPage.java
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml?rev=1003520&r1=1003519&r2=1003520&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml Fri Oct 1 12:55:26 2010
@@ -66,6 +66,12 @@
class="org.apache.uima.caseditor.editor.fsview.FeatureStructureBrowserView"
icon="icons/svgicons/fsview.png"
category="org.apache.uima.caseditor.ui.views" />
+
+ <view id="org.apache.uima.caseditor.styleview"
+ name="Annotation Styles"
+
class="org.apache.uima.caseditor.editor.styleview.AnnotationStyleView"
+ icon="icons/svgicons/fsview.png"
+ category="org.apache.uima.caseditor.ui.views" />
</extension>
<extension point="org.eclipse.ui.editors">
@@ -216,14 +222,23 @@
</enabledWhen>
</page>
<page
-
class="org.apache.uima.caseditor.ui.property.AnnotationPropertyPage"
+
class="org.apache.uima.caseditor.ui.property.NlpAnnotationPropertyPage"
icon="icons/svgicons/corpus.png"
- id="org.apache.uima.caseditor.annotationspropertypage"
+
id="org.apache.uima.caseditor.nlpannotationspropertypage"
name="Annotations">
<enabledWhen>
<instanceof
value="org.apache.uima.caseditor.core.model.NlpProject"/>
</enabledWhen>
</page>
+ <page
+
class="org.apache.uima.caseditor.ui.property.EditorAnnotationPropertyPage"
+ icon="icons/svgicons/corpus.png"
+ id="org.apache.uima.caseditor.annotationspropertypage"
+ name="Annotations">
+ <enabledWhen>
+ <instanceof
value="org.apache.uima.caseditor.editor.styleview.AnnotationTypeNode"/>
+ </enabledWhen>
+ </page>
</extension>
<extension point="org.eclipse.core.runtime.adapters">
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=1003520&r1=1003519&r2=1003520&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
Fri Oct 1 12:55:26 2010
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Type;
@@ -513,7 +514,7 @@ public final class AnnotationEditor exte
*/
private IContentOutlinePage mOutlinePage;
- private IAnnotationEditorModifyListener mEditorListener;
+ private Set<IAnnotationEditorModifyListener> mEditorListener = new
HashSet<IAnnotationEditorModifyListener>();
/**
* TODO: Do we really need this position variable ?
@@ -534,6 +535,8 @@ public final class AnnotationEditor exte
private DocumentListener mAnnotationSynchronizer;
+ private IAnnotationStyleListener mAnnotationStyleListener;
+
private CloseEditorListener closeEditorListener;
private Collection<Type> shownAnnotationTypes = new HashSet<Type>();
@@ -697,8 +700,10 @@ public final class AnnotationEditor exte
getDocumentProvider().setEditorAnnotationStatus(getEditorInput(),
new EditorAnnotationStatus(status.getMode(), selection));
- if (mEditorListener != null)
- mEditorListener.showAnnotationsChanged(selection);
+ if (mEditorListener != null) {
+ for (IAnnotationEditorModifyListener listener : mEditorListener)
+ listener.showAnnotationsChanged(selection);
+ }
}
});
@@ -741,9 +746,19 @@ public final class AnnotationEditor exte
mAnnotationSynchronizer = new DocumentListener();
getDocument().addChangeListener(mAnnotationSynchronizer);
-
+
+ mAnnotationStyleListener = new IAnnotationStyleListener() {
+
+ public void annotationStylesChanged(Collection<AnnotationStyle>
styles) {
+ // TODO: Only sync changed types
+ syncAnnotationTypes();
+ }
+ };
+
+ getDocumentProvider().addAnnotationStyleListener(getEditorInput(),
mAnnotationStyleListener);
+
Collection<String> shownTypes =
getDocumentProvider().getShownTypes(input);
-
+
for (String shownType : shownTypes) {
// Types can be deleted from the type system but still be marked
@@ -847,13 +862,18 @@ public final class AnnotationEditor exte
public Collection<Type> getShownAnnotationTypes() {
return mShowAnnotationsMenu.getSelectedTypes();
}
+
+ public void setShownAnnotationType(Type type, boolean isShown) {
+ mShowAnnotationsMenu.setSelectedType(type, isShown);
+ }
/**
* @param type
*/
private void fireAnnotationTypeChanged(Type type) {
if (mEditorListener != null) {
- mEditorListener.annotationModeChanged(type);
+ for (IAnnotationEditorModifyListener listener : mEditorListener)
+ listener.annotationModeChanged(type);
}
}
@@ -920,7 +940,7 @@ public final class AnnotationEditor exte
* @param listener
*/
public void addAnnotationListener(IAnnotationEditorModifyListener listener) {
- mEditorListener = listener;
+ mEditorListener.add(listener);
}
/**
@@ -1153,6 +1173,11 @@ public final class AnnotationEditor exte
.removeResourceChangeListener(closeEditorListener);
}
+ CasDocumentProvider provider = getDocumentProvider();
+
+ if (provider != null)
+ provider.removeAnnotationStyleListener(getEditorInput(),
mAnnotationStyleListener);
+
super.dispose();
}
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=1003520&r1=1003519&r2=1003520&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
Fri Oct 1 12:55:26 2010
@@ -21,7 +21,9 @@ 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;
@@ -39,6 +41,9 @@ import org.eclipse.ui.texteditor.Abstrac
*/
public abstract class CasDocumentProvider extends AbstractDocumentProvider {
+ private Set<IAnnotationStyleListener> annotationStyleListeners =
+ new HashSet<IAnnotationStyleListener>();
+
/**
* The method {...@link #createDocument(Object)} put error status objects
for the given element in
* this map, if something with document creation goes wrong.
@@ -79,11 +84,27 @@ public abstract class CasDocumentProvide
return status;
}
- protected abstract AnnotationStyle getAnnotationStyle(Object element, Type
type);
+ /**
+ * Retrieves an <code>AnnotationStyle</code> from the underlying storage.
+ *
+ * @param element
+ * @param type
+ * @return
+ */
+ public abstract AnnotationStyle getAnnotationStyle(Object element, Type
type);
+ /**
+ *
+ * @param element
+ * @param style
+ */
+ public abstract void setAnnotationStyle(Object element, AnnotationStyle
style);
+
+ // TODO: We also need a set method here
+
protected abstract Collection<String> getShownTypes(Object element);
- protected abstract void addShownType(Object elemtn, Type type);
+ protected abstract void addShownType(Object element, Type type);
protected abstract void removeShownType(Object element, Type type);
@@ -91,4 +112,25 @@ public abstract class CasDocumentProvide
protected abstract void setEditorAnnotationStatus(Object element,
EditorAnnotationStatus editorAnnotationStatus);
+
+ // TODO:
+ // This case only works if there is a single shared state between all editors
+ // An implementation should track the listeners per shared type system
+ //
+ // Must that be already done for multiple CAS Editor projects, or do they
have an instance
+ // per project ???
+ // Is there one doc provider instance per editor, or one for many editors ?!
+ public void addAnnotationStyleListener(Object element,
IAnnotationStyleListener listener) {
+ annotationStyleListeners.add(listener);
+ }
+
+ public void removeAnnotationStyleListener(Object element,
IAnnotationStyleListener listener) {
+ annotationStyleListeners.remove(listener);
+ }
+
+ public void fireAnnotationStyleChanged(Object element,
Collection<AnnotationStyle> styles) {
+ for (IAnnotationStyleListener listener : annotationStyleListeners) {
+ listener.annotationStylesChanged(styles);
+ }
+ }
}
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java?rev=1003520&r1=1003519&r2=1003520&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java
(original)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java
Fri Oct 1 12:55:26 2010
@@ -125,7 +125,7 @@ public class DefaultCasDocumentProvider
}
@Override
- protected AnnotationStyle getAnnotationStyle(Object element, Type type) {
+ public AnnotationStyle getAnnotationStyle(Object element, Type type) {
if (type == null)
throw new IllegalArgumentException("type parameter must not be null!");
@@ -136,6 +136,13 @@ public class DefaultCasDocumentProvider
}
@Override
+ public void setAnnotationStyle(Object element, AnnotationStyle style) {
+ INlpElement nlpElement = getNlpElement(element);
+
+ nlpElement.getNlpProject().getDotCorpus().setStyle(style);
+ }
+
+ @Override
protected Collection<String> getShownTypes(Object element) {
INlpElement nlpElement = getNlpElement(element);
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/IAnnotationStyleListener.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/IAnnotationStyleListener.java?rev=1003520&view=auto
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/IAnnotationStyleListener.java
(added)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/IAnnotationStyleListener.java
Fri Oct 1 12:55:26 2010
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor;
+
+import java.util.Collection;
+
+public interface IAnnotationStyleListener {
+ void annotationStylesChanged(Collection<AnnotationStyle> styles);
+}
Propchange:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/IAnnotationStyleListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1003520&r1=1003519&r2=1003520&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
Fri Oct 1 12:55:26 2010
@@ -103,9 +103,7 @@ public class ShowAnnotationsMenu extends
typesToDisplay.remove(type);
}
- for (IShowAnnotationsListener listener :
listeners) {
-
listener.selectionChanged(getSelectedTypes());
- }
+ fireChanged();
}
});
}
@@ -124,6 +122,28 @@ public class ShowAnnotationsMenu extends
return Collections.unmodifiableCollection(selectedTypes);
}
+ private void fireChanged() {
+ for (IShowAnnotationsListener listener : listeners) {
+ listener.selectionChanged(getSelectedTypes());
+ }
+ }
+
+ public void setSelectedType(Type type, boolean isShown) {
+
+ if (typesToDisplay.contains(type)) {
+ if (!isShown) {
+ typesToDisplay.remove(type);
+ fireChanged();
+ }
+ }
+ else {
+ if (isShown) {
+ typesToDisplay.add(type);
+ fireChanged();
+ }
+ }
+ }
+
public void setSelectedTypes(Collection<Type> types) {
typesToDisplay = new HashSet<Type>();
@@ -141,16 +161,12 @@ public class ShowAnnotationsMenu extends
if (typesToDisplay.contains(newMode)) {
if (editorAnnotationMode != null) {
editorAnnotationMode = null;
- for (IShowAnnotationsListener listener :
listeners) {
-
listener.selectionChanged(getSelectedTypes());
- }
+ fireChanged();
}
} else {
editorAnnotationMode = newMode;
- for (IShowAnnotationsListener listener : listeners) {
- listener.selectionChanged(getSelectedTypes());
- }
+ fireChanged();
}
}
}
\ No newline at end of file
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleView.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleView.java?rev=1003520&view=auto
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleView.java
(added)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleView.java
Fri Oct 1 12:55:26 2010
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.styleview;
+
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.caseditor.editor.AnnotationEditorView;
+import org.apache.uima.caseditor.editor.ICasEditor;
+
+// Tree Table, one column contains a tree, representing the tree structure
+// of the uima types
+public class AnnotationStyleView extends AnnotationEditorView {
+
+ /**
+ * The ID of the type view.
+ */
+ public static final String ID = "org.apache.uima.caseditor.styleview";
+
+ public AnnotationStyleView() {
+ super("The annotation style view is currently not available.");
+ }
+
+ @Override
+ protected PageRec doCreatePage(ICasEditor editor) {
+ PageRec result = null;
+
+ if (editor.getDocument() != null && editor instanceof AnnotationEditor) {
+ AnnotationStyleViewPage page = new
AnnotationStyleViewPage((AnnotationEditor) editor);
+
+ initPage(page);
+ page.createControl(getPageBook());
+
+ result = new PageRec(editor, page);
+ }
+
+ return result;
+ }
+}
Propchange:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleView.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleViewPage.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleViewPage.java?rev=1003520&view=auto
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleViewPage.java
(added)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleViewPage.java
Fri Oct 1 12:55:26 2010
@@ -0,0 +1,364 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.styleview;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.Images;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.caseditor.editor.AnnotationStyle;
+import org.apache.uima.caseditor.editor.IAnnotationEditorModifyListener;
+import org.apache.uima.caseditor.editor.IAnnotationStyleListener;
+import org.apache.uima.caseditor.ui.property.EditorAnnotationPropertyPage;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.preference.IPreferenceNode;
+import org.eclipse.jface.preference.PreferenceManager;
+import org.eclipse.jface.preference.PreferenceNode;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.eclipse.ui.internal.dialogs.PropertyDialog;
+import org.eclipse.ui.part.Page;
+
+// TODO: Subscribe to style change events
+// create new listener interface for this
+class AnnotationStyleViewPage extends Page {
+
+ static class AnnotationTypeContentProvider implements ITreeContentProvider {
+
+ private AnnotationTypeNode[] annotationTypes;
+
+ private AnnotationEditor editor;
+
+ AnnotationTypeContentProvider(AnnotationEditor editor) {
+ this.editor = editor;
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ if (newInput instanceof TypeSystem) {
+ TypeSystem ts = (TypeSystem) newInput;
+
+ List<Type> annotationTypeList =
+ ts.getProperlySubsumedTypes(ts.getType(CAS.TYPE_NAME_ANNOTATION));
+ annotationTypeList.add(ts.getType(CAS.TYPE_NAME_ANNOTATION));
+
+ annotationTypes = new AnnotationTypeNode[annotationTypeList.size()];
+
+ for (int i = 0; i < annotationTypeList.size(); i++) {
+ annotationTypes[i] = new AnnotationTypeNode(editor,
annotationTypeList.get(i));
+ }
+ }
+ else {
+ annotationTypes = null;
+ }
+
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return annotationTypes;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+ }
+
+ static class AnnotationStylingLabelProvider implements ITableLabelProvider,
IColorProvider {
+
+ private static int TYPE_NAME_COLUMN = 0;
+ private static int STYLE_NAME_COLUMN = 1;
+
+ private AnnotationEditor editor;
+
+ AnnotationStylingLabelProvider(AnnotationEditor editor) {
+ this.editor = editor;
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+
+ AnnotationTypeNode typeNode = (AnnotationTypeNode) element;
+
+ Type type = typeNode.getAnnotationType();
+
+ // TODO: Get this information trough the editor ... its easier
+ AnnotationStyle style =
editor.getDocumentProvider().getAnnotationStyle(editor.getEditorInput(), type);
+
+ if (TYPE_NAME_COLUMN == columnIndex) {
+ return type.getShortName().trim();
+ }
+ else if (STYLE_NAME_COLUMN == columnIndex) {
+ return style.getStyle().toString();
+ }
+ else {
+ throw new IllegalStateException("Unkown column!");
+ }
+ }
+
+ public Color getForeground(Object element) {
+ return null;
+ }
+
+ public Color getBackground(Object element) {
+
+ AnnotationTypeNode typeNode = (AnnotationTypeNode) element;
+
+ Type type = typeNode.getAnnotationType();
+ // TODO: Get this information trough the editor ... its easier
+ AnnotationStyle style =
editor.getDocumentProvider().getAnnotationStyle(editor.getEditorInput(), type);
+
+ return new Color(Display.getCurrent(), style.getColor().getRed(),
+ style.getColor().getGreen(), style.getColor().getBlue());
+ }
+ }
+
+ private AnnotationEditor editor;
+
+ private IAnnotationEditorModifyListener editorListener;
+
+ private IAnnotationStyleListener changeListener;
+
+ private CheckboxTableViewer treeViewer;
+
+ AnnotationStyleViewPage(AnnotationEditor editor) {
+ this.editor = editor;
+ }
+
+ private static AnnotationTypeNode[] typesToNodes(Collection<Type> types,
AnnotationEditor editor) {
+ Collection<Type> shownTypes = editor.getShownAnnotationTypes();
+
+ AnnotationTypeNode[] selectedNodes = new
AnnotationTypeNode[shownTypes.size()];
+
+ int typeIndex = 0;
+ for (Type shownType : shownTypes) {
+ selectedNodes[typeIndex++] = new AnnotationTypeNode(editor, shownType);
+ }
+
+ return selectedNodes;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+
+ Table table = new Table(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
+ SWT.CHECK | SWT.NO_FOCUS);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ final Color defaultForegroundColor = table.getForeground();
+
+ table.addListener(SWT.EraseItem, new Listener() {
+ public void handleEvent(Event event) {
+ if((event.detail & SWT.SELECTED) != 0 ){
+ event.detail &= ~SWT.SELECTED;
+ event.gc.setForeground(defaultForegroundColor);
+ }
+ }
+ });
+
+ treeViewer = new CheckboxTableViewer(table);
+
+ TableColumn typeColumn = new TableColumn(table, SWT.LEFT);
+ typeColumn.setAlignment(SWT.LEFT);
+ typeColumn.setText("Type");
+ typeColumn.setWidth(120);
+
+ TableColumn stlyeColumn = new TableColumn(table, SWT.LEFT);
+ stlyeColumn.setAlignment(SWT.LEFT);
+ stlyeColumn.setText("Style");
+ stlyeColumn.setWidth(100);
+
+ treeViewer.setContentProvider(new AnnotationTypeContentProvider(editor));
+ treeViewer.setLabelProvider(new AnnotationStylingLabelProvider(editor));
+
+ treeViewer.setInput(editor.getDocument().getCAS().getTypeSystem());
+ getSite().setSelectionProvider(treeViewer);
+
+ changeListener = new IAnnotationStyleListener() {
+
+
+ public void annotationStylesChanged(Collection<AnnotationStyle> styles) {
+
+ // Update all changed style elements in the table
+
+ AnnotationTypeNode typeNodes[] = new AnnotationTypeNode[styles.size()];
+
+ int i = 0;
+ for (AnnotationStyle style : styles) {
+
+ typeNodes[i++] = new AnnotationTypeNode(editor,
+ editor.getDocument().getType(style.getAnnotation()));
+ }
+
+ treeViewer.update(typeNodes, null);
+ }
+ };
+
+ editor.getDocumentProvider().addAnnotationStyleListener(
+ editor.getEditorInput(), changeListener);
+
+
treeViewer.setCheckedElements(typesToNodes(editor.getShownAnnotationTypes(),
editor));
+
+ treeViewer.setGrayed(new AnnotationTypeNode(editor,
editor.getAnnotationMode()), true);
+
+ treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+
+ AnnotationTypeNode typeNode = (AnnotationTypeNode) event.getElement();
+
+ // The grayed mode annotation cannot be unselected, if the
+ // user clicks on it prevent the state change
+ if (typeNode.getAnnotationType().equals(editor.getAnnotationMode())) {
+ treeViewer.setChecked(event.getElement(), true);
+ }
+ else {
+ editor.setShownAnnotationType(typeNode.getAnnotationType(),
+ event.getChecked());
+ }
+ }
+ });
+
+ editorListener = new IAnnotationEditorModifyListener() {
+
+ public void showAnnotationsChanged(Collection<Type>
shownAnnotationTypes) {
+ treeViewer.setCheckedElements(typesToNodes(shownAnnotationTypes,
editor));
+ }
+
+ public void annotationModeChanged(Type newMode) {
+ // maybe slow if there are many types
+ treeViewer.setAllGrayed(false);
+ treeViewer.setGrayed(new AnnotationTypeNode(editor, newMode), true);
+ }
+ };
+
+ // TODO: must this listener be removed ?!
+ editor.addAnnotationListener(editorListener);
+
+ // register a listener to change state
+ // create a action handle to push changes to editor
+ }
+
+ @Override
+ public void makeContributions(IMenuManager menuManager, IToolBarManager
toolBarManager,
+ IStatusLineManager statusLineManager) {
+ super.makeContributions(menuManager, toolBarManager, statusLineManager);
+
+ // TODO: Figure out how to use open properties dialog action here correctly
+ // see http://wiki.eclipse.org/FAQ_How_do_I_open_a_Property_dialog%3F
+
+ IAction action = new Action() {
+ @Override
+ public void run() {
+ super.run();
+
+ ISelection sel = new StructuredSelection(new
AnnotationTypeNode(editor, null));
+ PropertyPage page = new EditorAnnotationPropertyPage();
+ page.setElement(new AnnotationTypeNode(editor, null));
+ page.setTitle("Styles");
+ PreferenceManager mgr = new PreferenceManager();
+ IPreferenceNode node = new PreferenceNode("1", page);
+ mgr.addToRoot(node);
+ PropertyDialog dialog = new PropertyDialog(getSite().getShell(), mgr,
sel);
+ dialog.create();
+ dialog.setMessage(page.getTitle());
+ dialog.open();
+ }
+ };
+
+ action.setImageDescriptor(CasEditorPlugin
+ .getTaeImageDescriptor(Images.MODEL_PROCESSOR_FOLDER));
+
+ toolBarManager.add(action);
+ }
+
+ @Override
+ public Control getControl() {
+ return treeViewer.getControl();
+ }
+
+ @Override
+ public void setFocus() {
+// treeViewer.getControl().setFocus();
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+
+ editor.getDocumentProvider().removeAnnotationStyleListener(
+ editor.getEditorInput(), changeListener);
+ }
+}
Propchange:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationStyleViewPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationTypeNode.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationTypeNode.java?rev=1003520&view=auto
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationTypeNode.java
(added)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationTypeNode.java
Fri Oct 1 12:55:26 2010
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.styleview;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.eclipse.core.runtime.IAdaptable;
+
+public class AnnotationTypeNode implements IAdaptable{
+
+ private AnnotationEditor editor;
+ private Type type;
+
+ AnnotationTypeNode(AnnotationEditor editor, Type type) {
+ this.editor = editor;
+ this.type = type;
+ }
+
+ public AnnotationEditor getEditor() {
+ return editor;
+ }
+
+ public Type getAnnotationType() {
+ return type;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (obj instanceof AnnotationTypeNode) {
+
+ AnnotationTypeNode typeNode = (AnnotationTypeNode) obj;
+
+ return type.equals(typeNode.type);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return type.hashCode();
+ }
+
+ public Object getAdapter(Class adapter) {
+
+ if (AnnotationTypeNode.class.equals(adapter)) {
+ return this;
+ }
+
+ return null;
+ }
+}
Propchange:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/styleview/AnnotationTypeNode.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/NlpPerspectiveFactory.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/NlpPerspectiveFactory.java?rev=1003520&r1=1003519&r2=1003520&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/NlpPerspectiveFactory.java
(original)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/NlpPerspectiveFactory.java
Fri Oct 1 12:55:26 2010
@@ -22,6 +22,7 @@ package org.apache.uima.caseditor.ui;
import org.apache.uima.caseditor.editor.editview.EditView;
import org.apache.uima.caseditor.editor.fsview.FeatureStructureBrowserView;
+import org.apache.uima.caseditor.editor.styleview.AnnotationStyleView;
import org.apache.uima.caseditor.ui.corpusview.CorpusExplorerView;
import org.apache.uima.caseditor.ui.wizards.NewNlpProjectWizard;
import org.apache.uima.caseditor.ui.wizards.WizardNewFileCreation;
@@ -62,7 +63,9 @@ public class NlpPerspectiveFactory imple
// add "show views"
layout.addShowViewShortcut(CorpusExplorerView.ID);
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
+ layout.addShowViewShortcut(AnnotationStyleView.ID);
+
// add "open perspective"
layout.addPerspectiveShortcut(NlpPerspectiveFactory.ID);
}
@@ -81,6 +84,10 @@ public class NlpPerspectiveFactory imple
right.addView(IPageLayout.ID_OUTLINE);
right.addView(FeatureStructureBrowserView.ID);
+
+ IFolderLayout rightBottomCorner =
layout.createFolder("rightBottomCorner", IPageLayout.BOTTOM,
+ 0.75f, "right");
+ rightBottomCorner.addView(AnnotationStyleView.ID);
// bottom views
IFolderLayout rightBottom = layout.createFolder("rightBottom",
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/AnnotationPropertyPage.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/AnnotationPropertyPage.java?rev=1003520&r1=1003519&r2=1003520&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/AnnotationPropertyPage.java
(original)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/AnnotationPropertyPage.java
Fri Oct 1 12:55:26 2010
@@ -20,14 +20,17 @@
package org.apache.uima.caseditor.ui.property;
import java.awt.Color;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+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.CasEditorPlugin;
import org.apache.uima.caseditor.core.model.DotCorpusElement;
-import org.apache.uima.caseditor.core.model.INlpElement;
import org.apache.uima.caseditor.core.model.NlpProject;
import org.apache.uima.caseditor.core.model.TypesystemElement;
import org.apache.uima.caseditor.editor.AnnotationEditor;
@@ -61,9 +64,10 @@ import org.eclipse.ui.dialogs.PropertyPa
* This is the <code>AnnotationPropertyPage</code>. this page configures the
project dependent
* and type dependent annotation appearance in the
<code>AnnotationEditor</code>.
*/
-public class AnnotationPropertyPage extends PropertyPage {
- private DotCorpusElement mDotCorpusElement;
+public abstract class AnnotationPropertyPage extends PropertyPage {
+ private boolean isTypeSystemPresent = true;
+
private Combo mStyleCombo;
private ColorSelector mColorSelector;
@@ -72,7 +76,7 @@ public class AnnotationPropertyPage exte
private AnnotationStyle mCurrentSelectedAnnotation = null;
- private NlpProject mProject;
+ private Map<String, AnnotationStyle> changedStyles = new HashMap<String,
AnnotationStyle>();
private AnnotationStyle getDefaultAnnotation() {
@@ -84,40 +88,63 @@ public class AnnotationPropertyPage exte
AnnotationStyle.DEFAULT_COLOR,
mCurrentSelectedAnnotation.getLayer());
}
+ protected abstract AnnotationStyle getAnnotationStyle(Type type);
+
+ // does not make sense, just give it a list with new annotation styles,
+ // to save them and notify other about the chagne
+
+ protected final void setAnnotationStyle(AnnotationStyle style) {
+ changedStyles.put(mCurrentSelectedAnnotation.getAnnotation(),
mCurrentSelectedAnnotation);
+ }
+
+ protected abstract TypeSystem getTypeSystem();
+
private void itemSelected() {
IStructuredSelection selection = (IStructuredSelection)
mTypeList.getSelection();
Type selectedType = (Type) selection.getFirstElement();
- AnnotationStyle style = mDotCorpusElement.getAnnotation(selectedType);
-
- mCurrentSelectedAnnotation = style;
-
- if (style == null) {
- style = new AnnotationStyle(selectedType.getName(),
AnnotationStyle.DEFAULT_STYLE,
- AnnotationStyle.DEFAULT_COLOR,
mCurrentSelectedAnnotation.getLayer());
+ if( selectedType != null) {
+
+ AnnotationStyle style = getAnnotationStyle(selectedType);
+
+ mCurrentSelectedAnnotation = style;
+
+ if (style == null) {
+ style = new AnnotationStyle(selectedType.getName(),
AnnotationStyle.DEFAULT_STYLE,
+ AnnotationStyle.DEFAULT_COLOR,
mCurrentSelectedAnnotation.getLayer());
+ }
+
+ mStyleCombo.setText(style.getStyle().name());
+ mStyleCombo.setEnabled(true);
+
+ Color color = style.getColor();
+ mColorSelector.setColorValue(new RGB(color.getRed(), color.getGreen(),
color.getBlue()));
+ mColorSelector.setEnabled(true);
+
+ // TODO: Enable move up down buttons
+ }
+ else {
+ // no type selected
+ mStyleCombo.setEnabled(false);
+ mColorSelector.setEnabled(false);
+
+ // TODO: Disable up down button
}
-
- mStyleCombo.setText(style.getStyle().name());
- mStyleCombo.setEnabled(true);
-
- Color color = style.getColor();
- mColorSelector.setColorValue(new RGB(color.getRed(), color.getGreen(),
color.getBlue()));
- mColorSelector.setEnabled(true);
}
-
+
/**
* Creates the annotation property page controls.
*/
@Override
protected Control createContents(Composite parent) {
- mProject = ((INlpElement) getElement()).getNlpProject();
-
- mDotCorpusElement = mProject.getDotCorpus();
- TypesystemElement typesystem = mProject.getTypesystemElement();
+ TypeSystem typeSystem = getTypeSystem();
- if (typesystem == null) {
+ if (typeSystem == null) {
+
+ isTypeSystemPresent = false;
+
Label message = new Label(parent, SWT.NONE);
message.setText("Please set a valid typesystem file first.");
@@ -171,16 +198,14 @@ public class AnnotationPropertyPage exte
Type type = (Type) cell.getElement();
- AnnotationStyle style = mDotCorpusElement.getAnnotation(type);
+ AnnotationStyle style = getAnnotationStyle(type);
cell.setText(Integer.toString(style.getLayer()));
}});
- TypeSystem typeSytstem = mProject.getTypesystemElement().getTypeSystem();
+ Type annotationType = typeSystem.getType(CAS.TYPE_NAME_ANNOTATION);
- Type annotationType = typeSytstem.getType(CAS.TYPE_NAME_ANNOTATION);
-
- List<Type> types = typeSytstem.getProperlySubsumedTypes(annotationType);
+ List<Type> types = typeSystem.getProperlySubsumedTypes(annotationType);
for (Type type : types) {
// inserts objects with type Type
@@ -219,7 +244,7 @@ public class AnnotationPropertyPage exte
.valueOf(mStyleCombo.getText()),
mCurrentSelectedAnnotation.getColor(),
mCurrentSelectedAnnotation.getLayer());
- mDotCorpusElement.setStyle(mCurrentSelectedAnnotation);
+ setAnnotationStyle(mCurrentSelectedAnnotation);
}
public void widgetDefaultSelected(SelectionEvent e) {
@@ -253,7 +278,7 @@ public class AnnotationPropertyPage exte
mCurrentSelectedAnnotation.getAnnotation(),
mCurrentSelectedAnnotation.getStyle(),
color, mCurrentSelectedAnnotation.getLayer());
- mDotCorpusElement.setStyle(mCurrentSelectedAnnotation);
+ setAnnotationStyle(mCurrentSelectedAnnotation);
}
});
@@ -275,7 +300,7 @@ public class AnnotationPropertyPage exte
.valueOf(mStyleCombo.getText()),
mCurrentSelectedAnnotation.getColor(),
mCurrentSelectedAnnotation.getLayer() + 1);
- mDotCorpusElement.setStyle(mCurrentSelectedAnnotation);
+ setAnnotationStyle(mCurrentSelectedAnnotation);
mTypeList.refresh(((IStructuredSelection)
mTypeList.getSelection()).getFirstElement(),
true);
@@ -299,7 +324,7 @@ public class AnnotationPropertyPage exte
.getAnnotation(),
AnnotationStyle.Style.valueOf(mStyleCombo.getText()),
mCurrentSelectedAnnotation.getColor(),
mCurrentSelectedAnnotation.getLayer() - 1);
- mDotCorpusElement.setStyle(mCurrentSelectedAnnotation);
+ setAnnotationStyle(mCurrentSelectedAnnotation);
mTypeList.update(((IStructuredSelection)
mTypeList.getSelection()).getFirstElement(),
null);
@@ -316,28 +341,21 @@ public class AnnotationPropertyPage exte
return base;
}
+ protected abstract boolean saveChanges(Collection<AnnotationStyle>
changedStyles);
+
/**
* Executed after the OK button was pressed.
*/
@Override
public boolean performOk() {
- // workaround for type system not present problem
- if (mProject.getTypesystemElement() == null
- || mProject.getTypesystemElement().getTypeSystem() == null) {
+
+ if (!isTypeSystemPresent)
return true;
- }
-
- try {
- mDotCorpusElement.serialize();
- } catch (CoreException e) {
- CasEditorPlugin.log(e);
+
+ if (!saveChanges(changedStyles.values()))
return false;
- }
-
- // Repaint annotations of all open editors
- for (AnnotationEditor editor : AnnotationEditor.getAnnotationEditors()) {
- editor.syncAnnotationTypes();
- }
+
+ changedStyles.clear();
return true;
}
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/EditorAnnotationPropertyPage.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/EditorAnnotationPropertyPage.java?rev=1003520&view=auto
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/EditorAnnotationPropertyPage.java
(added)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/EditorAnnotationPropertyPage.java
Fri Oct 1 12:55:26 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.ui.property;
+
+import java.util.Collection;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.caseditor.editor.AnnotationStyle;
+import org.apache.uima.caseditor.editor.styleview.AnnotationTypeNode;
+
+public class EditorAnnotationPropertyPage extends AnnotationPropertyPage {
+
+ AnnotationEditor getEditor() {
+ AnnotationTypeNode typeNode = (AnnotationTypeNode)
getElement().getAdapter(AnnotationTypeNode.class);
+
+ return typeNode.getEditor();
+ }
+
+ @Override
+ protected AnnotationStyle getAnnotationStyle(Type type) {
+ // TODO: Use the editor directly ...
+ return getEditor().getDocumentProvider().getAnnotationStyle(
+ getEditor().getEditorInput(), type);
+ }
+
+ @Override
+ protected TypeSystem getTypeSystem() {
+ return getEditor().getDocument().getCAS().getTypeSystem();
+ }
+
+ @Override
+ protected boolean saveChanges(Collection<AnnotationStyle> changedStyles) {
+
+ for (AnnotationStyle style : changedStyles) {
+ getEditor().getDocumentProvider().setAnnotationStyle(
+ getEditor().getEditorInput(), style);
+ }
+
+
getEditor().getDocumentProvider().fireAnnotationStyleChanged(getEditor().getEditorInput(),
+ changedStyles);
+
+ return true;
+ }
+}
Propchange:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/EditorAnnotationPropertyPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/NlpAnnotationPropertyPage.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/NlpAnnotationPropertyPage.java?rev=1003520&view=auto
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/NlpAnnotationPropertyPage.java
(added)
+++
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/NlpAnnotationPropertyPage.java
Fri Oct 1 12:55:26 2010
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.ui.property;
+
+import java.util.Collection;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.core.model.DotCorpusElement;
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.apache.uima.caseditor.core.model.NlpProject;
+import org.apache.uima.caseditor.core.model.TypesystemElement;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.caseditor.editor.AnnotationStyle;
+import org.eclipse.core.runtime.CoreException;
+
+public class NlpAnnotationPropertyPage extends AnnotationPropertyPage {
+
+ private NlpProject mProject;
+ private DotCorpusElement mDotCorpusElement;
+
+ protected AnnotationStyle getAnnotationStyle(Type type) {
+ return mDotCorpusElement.getAnnotation(type);
+ }
+
+ protected TypeSystem getTypeSystem() {
+
+ // TODO: Refactor this code
+ mProject = ((INlpElement) getElement()).getNlpProject();
+
+ mDotCorpusElement = mProject.getDotCorpus();
+
+ TypesystemElement tsElement = mProject.getTypesystemElement();
+
+ if (tsElement != null) {
+ return tsElement.getTypeSystem();
+ }
+ else {
+ return null;
+ }
+ }
+
+ protected boolean saveChanges(Collection<AnnotationStyle> changedStyles) {
+
+ for (AnnotationStyle style : changedStyles) {
+ mDotCorpusElement.setStyle(style);
+ }
+
+ // workaround for type system not present problem
+ if (mProject.getTypesystemElement() == null
+ || mProject.getTypesystemElement().getTypeSystem() == null) {
+ return true;
+ }
+
+ try {
+ mDotCorpusElement.serialize();
+ } catch (CoreException e) {
+ CasEditorPlugin.log(e);
+ return false;
+ }
+
+ // Repaint annotations of all open editors
+ AnnotationEditor editors[] = AnnotationEditor.getAnnotationEditors();
+
+ if (editors.length > 0)
+
editors[0].getDocumentProvider().fireAnnotationStyleChanged(editors[0].getEditorInput(),
+ changedStyles);
+
+ return true;
+ }
+
+}
Propchange:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/NlpAnnotationPropertyPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain