You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2008/11/04 21:59:13 UTC
svn commit: r711402 [2/6] - in
/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin: ./ META-INF/ icons/
icons/svgicons/ main/ main/java/ main/java/src/ main/java/src/org/
main/java/src/org/apache/ main/java/src/org/apache/uima/
main/java/src/org/apach...
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.IInformationProviderExtension;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * TODO: move this class to external file.
+ */
+class AnnotationInformationProvider implements IInformationProvider, IInformationProviderExtension {
+ private AnnotationEditor mEditor;
+
+ AnnotationInformationProvider(AnnotationEditor editor) {
+ mEditor = editor;
+ }
+
+ /**
+ * TODO: add comment
+ *
+ * @param textViewer
+ * @param offset
+ * @return the region
+ */
+ public IRegion getSubject(ITextViewer textViewer, int offset) {
+ Point selection = textViewer.getTextWidget().getSelection();
+
+ int length = selection.y - selection.x;
+ return new Region(offset, length);
+ }
+
+ /**
+ * TODO: add comment
+ *
+ * @param textViewer
+ * @param subject
+ * @return null
+ */
+ public String getInformation(ITextViewer textViewer, IRegion subject) {
+ return null;
+ }
+
+ /**
+ * TODO: add comment
+ *
+ * @param textViewer
+ * @param subject
+ * @return the selected annotation
+ */
+ public Object getInformation2(ITextViewer textViewer, IRegion subject) {
+ List<AnnotationFS> selection = mEditor.getSelectedAnnotations();
+
+ if (selection != null && selection.size() > 0) {
+ return selection.get(0);
+ } else {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelection.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelection.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelection.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelection.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,147 @@
+/*
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.editor.util.AnnotationComparator;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ * The annotation collection contains only {@link AnnotationFS}s objects which are selected by a
+ * {@link IStructuredSelection}.
+ *
+ * Its also possible to retrieve the first and last annotation
+ */
+public class AnnotationSelection {
+
+ private List<AnnotationFS> mAnnotations;
+
+ /**
+ * Initializes the current instance.
+ *
+ * @param structures
+ */
+ public AnnotationSelection(Collection<FeatureStructure> structures) {
+ mAnnotations = new ArrayList<AnnotationFS>(structures.size());
+
+ for (FeatureStructure structure : structures) {
+ if (structure instanceof AnnotationFS) {
+ mAnnotations.add((AnnotationFS) structure);
+ }
+ }
+
+ Collections.sort(mAnnotations, new AnnotationComparator());
+ }
+
+ /**
+ * Initializes a the current instance with all AnnotationFS object that are contained in the
+ * {@link StructuredSelection}.
+ *
+ * Note: {@link AnnotationFS} instances will be sorted in this selection, the natural oder of
+ * the selection is destroyed
+ *
+ * @param selection
+ */
+ public AnnotationSelection(IStructuredSelection selection) {
+
+ mAnnotations = new ArrayList<AnnotationFS>(selection.size());
+
+ for (Iterator<FeatureStructure> it = new FeatureStructureSelectionIterator(selection);
+ it.hasNext();) {
+ FeatureStructure structure = it.next();
+
+ if (structure instanceof AnnotationFS) {
+ mAnnotations.add((AnnotationFS) structure);
+ }
+ }
+
+ Collections.sort(mAnnotations, new AnnotationComparator());
+
+ mAnnotations = Collections.unmodifiableList(mAnnotations);
+ }
+
+ /**
+ * Indicates that the selection is empty.
+ *
+ * @return true if empty false otherwise
+ */
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ /**
+ * Retrieves the size of the collection.
+ *
+ * @return the size
+ */
+ public int size() {
+ return mAnnotations.size();
+ }
+
+ /**
+ * Retrieves the first selected element.
+ *
+ * Note: If {@link #size()} == 1 then first and last element are the same instance.
+ *
+ * @return the last element
+ */
+ public AnnotationFS getFirst() {
+ return isEmpty() ? null : mAnnotations.get(0);
+ }
+
+ /**
+ * Retrieves the last selected element.
+ *
+ * Note: If {@link #size()} == 1 then first and last element are the same instance.
+ *
+ * @return the last element or null if {@link #size()} == 0
+ */
+ public AnnotationFS getLast() {
+ return isEmpty() ? null : mAnnotations.get(size() - 1);
+ }
+
+ /**
+ * Retrieves an ordered list of {@link AnnotationFS} objects.
+ *
+ * @see AnnotationComparator is used for ordering the annotations
+ *
+ * @return all selected {@link AnnotationFS} objects
+ */
+ public List<AnnotationFS> toList() {
+ return mAnnotations;
+ }
+
+ /**
+ * Retrieves a human readable string.
+ * @return human readable string
+ */
+ @Override
+ public String toString() {
+ return mAnnotations.toString();
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelectionListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelectionListener.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelectionListener.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelectionListener.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * TODO: add javadoc here
+ */
+public abstract class AnnotationSelectionListener implements ISelectionListener {
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ }
+
+ protected abstract void selectedAnnotation(Collection<AnnotationFS> annotations);
+
+ /**
+ * Indicates that the selection did not contain any annotations.
+ */
+ protected abstract void emptySelection();
+}
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationSelectionListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationStyle.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationStyle.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationStyle.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationStyle.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,197 @@
+/*
+ * 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.awt.Color;
+
+
+/**
+ * The <code>AnnotationStyle</code> describes the look of an certain annotation type in the
+ * <code>AnnotationEditor</code>.
+ */
+public final class AnnotationStyle {
+ /**
+ * The styles that can be used to draw an annotation.
+ */
+ public enum Style {
+
+ /**
+ * The background color style.
+ */
+ BACKGROUND,
+
+ /**
+ * The text color style.
+ */
+ TEXT_COLOR,
+
+ /**
+ * The token style.
+ */
+ TOKEN,
+
+ /**
+ * The squiggles style.
+ */
+ SQUIGGLES,
+
+ /**
+ * The box style.
+ */
+ BOX,
+
+ /**
+ * The underline style.
+ */
+ UNDERLINE,
+
+ /**
+ * The bracket style.
+ */
+ BRACKET
+ }
+
+ /**
+ * The default <code>DrawingStyle<code>.
+ */
+ public static final Style DEFAULT_STYLE = Style.SQUIGGLES;
+
+ /**
+ * The default drawing color.
+ */
+ public static final Color DEFAULT_COLOR = new Color(0xff, 0, 0);
+
+ public static final int DEFAULT_LAYER = 0;
+
+ private final String annotation;
+
+ private final Style style;
+
+ private final Color color;
+
+ private final int layer;
+
+ /**
+ * Initialize a new instance.
+ *
+ * @param annotation -
+ * the annotation type
+ * @param style -
+ * the drawing style
+ * @param color -
+ * annotation color
+ *
+ * @param layer - drawing layer
+ */
+ public AnnotationStyle(String annotation, Style style, Color color, int layer) {
+
+ if (annotation == null || style == null || color == null) {
+ throw new IllegalArgumentException("parameters must be not null!");
+ }
+
+ this.annotation = annotation;
+ this.style = style;
+ this.color = color;
+
+ if (layer < 0) {
+ throw new IllegalArgumentException("layer must be a positive or zero");
+ }
+
+ this.layer = layer;
+
+ }
+
+ /**
+ * Retrieves the annotation type.
+ *
+ * @return - annotation type.
+ */
+ public String getAnnotation() {
+ return annotation;
+ }
+
+ /**
+ * Retrieves the drawing style of the annotation.
+ *
+ * @return - annotation drawing style
+ */
+ public Style getStyle() {
+ return style;
+ }
+
+ /**
+ * Retrieves the color of the annotation.
+ *
+ * @return - annotation color
+ */
+ public Color getColor() {
+ return color;
+ }
+
+ /**
+ * Retrieves the drawing layer.
+ *
+ * @return
+ */
+ public int getLayer() {
+ return layer;
+ }
+
+ /**
+ * Compares if current is equal to another object.
+ */
+ @Override
+ public boolean equals(Object object) {
+ boolean isEqual;
+
+ if (object == this) {
+ isEqual = true;
+ } else if (object instanceof AnnotationStyle) {
+ AnnotationStyle style = (AnnotationStyle) object;
+
+ isEqual = annotation.equals(style.annotation) && style.style.equals(style.style)
+ && color.equals(style.color) && layer == style.layer;
+ } else {
+ isEqual = false;
+ }
+
+ return isEqual;
+ }
+
+ /**
+ * Generates a hash code using of toString()
+ */
+ @Override
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ /**
+ * Represents this object as string.
+ */
+ @Override
+ public String toString() {
+ String annotationStyle = "Type: " + annotation;
+ annotationStyle += " Style: " + getStyle().name();
+ annotationStyle += " Color: " + getColor().toString();
+ annotationStyle += " Layer: " + getLayer();
+ return annotationStyle;
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/AnnotationStyle.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ArrayValue.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ArrayValue.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ArrayValue.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ArrayValue.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,156 @@
+/*
+ * 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 org.apache.uima.cas.ArrayFS;
+import org.apache.uima.cas.BooleanArrayFS;
+import org.apache.uima.cas.ByteArrayFS;
+import org.apache.uima.cas.DoubleArrayFS;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.FloatArrayFS;
+import org.apache.uima.cas.IntArrayFS;
+import org.apache.uima.cas.LongArrayFS;
+import org.apache.uima.cas.ShortArrayFS;
+import org.apache.uima.cas.StringArrayFS;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.eclipse.core.runtime.IAdaptable;
+
+public class ArrayValue implements IAdaptable {
+
+ private final FeatureStructure arrayFS;
+
+ private final int slot;
+
+ public ArrayValue(FeatureStructure arrayFS, int slot) {
+
+ if (!arrayFS.getType().isArray()) {
+ throw new IllegalArgumentException("The arrayFS parameter must contain an array type FS!");
+ }
+
+ this.arrayFS = arrayFS;
+ this.slot = slot;
+ }
+
+ public FeatureStructure getFeatureStructure() {
+ return arrayFS;
+ }
+
+ public int slot() {
+ return slot;
+ }
+
+ public void set(String value) {
+
+ if (arrayFS instanceof BooleanArrayFS) {
+ BooleanArrayFS array = (BooleanArrayFS) arrayFS;
+ array.set(slot, Boolean.parseBoolean(value));
+ } else if (arrayFS instanceof ByteArrayFS) {
+ ByteArrayFS array = (ByteArrayFS) arrayFS;
+ array.set(slot, Byte.parseByte(value));
+ } else if (arrayFS instanceof ShortArrayFS) {
+ ShortArrayFS array = (ShortArrayFS) arrayFS;
+ array.set(slot, Short.parseShort(value));
+ } else if (arrayFS instanceof IntArrayFS) {
+ IntArrayFS array = (IntArrayFS) arrayFS;
+ array.set(slot, Integer.parseInt(value));
+ } else if (arrayFS instanceof LongArrayFS) {
+ LongArrayFS array = (LongArrayFS) arrayFS;
+ array.set(slot, Long.parseLong(value));
+ } else if (arrayFS instanceof FloatArrayFS) {
+ FloatArrayFS array = (FloatArrayFS) arrayFS;
+ array.set(slot, Float.parseFloat(value));
+ } else if (arrayFS instanceof DoubleArrayFS) {
+ DoubleArrayFS array = (DoubleArrayFS) arrayFS;
+ array.set(slot, Double.parseDouble(value));
+ } else if (arrayFS instanceof StringArrayFS) {
+ StringArrayFS array = (StringArrayFS) arrayFS;
+ array.set(slot, value);
+ } else {
+ throw new CasEditorError("Unkown array type!");
+ }
+ }
+
+ public Object get() {
+
+ if (arrayFS instanceof BooleanArrayFS) {
+ BooleanArrayFS array = (BooleanArrayFS) arrayFS;
+ return array.get(slot);
+ } else if (arrayFS instanceof ByteArrayFS) {
+ ByteArrayFS array = (ByteArrayFS) arrayFS;
+ return array.get(slot);
+ } else if (arrayFS instanceof ShortArrayFS) {
+ ShortArrayFS array = (ShortArrayFS) arrayFS;
+ return array.get(slot);
+ } else if (arrayFS instanceof IntArrayFS) {
+ IntArrayFS array = (IntArrayFS) arrayFS;
+ return array.get(slot);
+ } else if (arrayFS instanceof LongArrayFS) {
+ LongArrayFS array = (LongArrayFS) arrayFS;
+ return array.get(slot);
+ } else if (arrayFS instanceof FloatArrayFS) {
+ FloatArrayFS array = (FloatArrayFS) arrayFS;
+ return array.get(slot);
+ } else if (arrayFS instanceof DoubleArrayFS) {
+ DoubleArrayFS array = (DoubleArrayFS) arrayFS;
+ return array.get(slot);
+ } else if (arrayFS instanceof StringArrayFS) {
+ StringArrayFS array = (StringArrayFS) arrayFS;
+
+ String value = array.get(slot);
+
+ if (value == null) {
+ value = "";
+ }
+
+ return value;
+ } else if (arrayFS instanceof ArrayFS) {
+ ArrayFS array = (ArrayFS) arrayFS;
+ return array.get(slot);
+ } else {
+ throw new CasEditorError("Unkown array type!");
+ }
+ }
+
+ public Object getAdapter(Class adapter) {
+
+ if (FeatureStructure.class.equals(adapter)) {
+ if (arrayFS instanceof ArrayFS) {
+ ArrayFS array = (ArrayFS) arrayFS;
+
+ return array.get(slot());
+ }
+ }
+
+ if (AnnotationFS.class.equals(adapter)) {
+ FeatureStructure fs = (FeatureStructure) getAdapter(FeatureStructure.class);
+
+ if (fs instanceof AnnotationFS) {
+ return fs;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toString(slot()) ;
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ArrayValue.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProvider.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProvider.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProvider.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,163 @@
+/*
+ * 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.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.editor.annotation.EclipseAnnotationPeer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModelListener;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.AbstractDocumentProvider;
+
+/**
+ * Provides the {@link org.apache.uima.caseditor.editor.IDocument} for
+ * the {@link AnnotationEditor}.
+ */
+public abstract class CasDocumentProvider extends AbstractDocumentProvider {
+
+ /**
+ * The method {@link #createDocument(Object)} put error status
+ * objects for the given element in this map, if something with document creation
+ * goes wrong.
+ *
+ * The method {@link #getStatus(Object)} can then retrieve and return the status.
+ */
+ protected Map<Object, IStatus> mElementErrorStatus =
+ new HashMap<Object, IStatus>();
+
+ @Override
+ protected IAnnotationModel createAnnotationModel(Object element) throws CoreException {
+ return new IAnnotationModel() {
+
+ private org.apache.uima.caseditor.editor.IDocument mDocument;
+
+ public void addAnnotation(Annotation annotation, Position position) {
+ }
+
+ public void addAnnotationModelListener(IAnnotationModelListener listener) {
+ }
+
+ public void connect(IDocument document) {
+ mDocument = (org.apache.uima.caseditor.editor.IDocument) document;
+ }
+
+ public void disconnect(IDocument document) {
+ mDocument = null;
+ }
+
+ public Iterator<EclipseAnnotationPeer> getAnnotationIterator() {
+ return new Iterator<EclipseAnnotationPeer>() {
+ private Iterator<AnnotationFS> mAnnotations =
+ mDocument.getCAS().getAnnotationIndex().iterator();
+
+ public boolean hasNext() {
+ return mAnnotations.hasNext();
+ }
+
+ public EclipseAnnotationPeer next() {
+ AnnotationFS annotation = mAnnotations.next();
+
+ EclipseAnnotationPeer peer = new EclipseAnnotationPeer(annotation.getType().getName(), false, "");
+ peer.setAnnotation(annotation);
+ return peer;
+ }
+
+ public void remove() {
+ }};
+ }
+
+ public Position getPosition(Annotation annotation) {
+ EclipseAnnotationPeer peer = (EclipseAnnotationPeer) annotation;
+ AnnotationFS annotationFS = peer.getAnnotationFS();
+ return new Position(annotationFS.getBegin(),
+ annotationFS.getEnd() - annotationFS.getBegin());
+ }
+
+ public void removeAnnotation(Annotation annotation) {
+ }
+
+ public void removeAnnotationModelListener(IAnnotationModelListener listener) {
+ }
+ };
+ }
+
+ /**
+ * Creates the a new {@link AnnotationDocument} from the given {@link FileEditorInput}
+ * element. For all other elements null is returned.
+ */
+ @Override
+ protected abstract IDocument createDocument(Object element) throws CoreException;
+
+ @Override
+ protected abstract void doSaveDocument(IProgressMonitor monitor,
+ Object element, IDocument document, boolean overwrite) throws CoreException;
+// {
+// fireElementStateChanging(element);
+//
+// org.apache.uima.caseditor.editor.IDocument casDocument =
+// (org.apache.uima.caseditor.editor.IDocument) document;
+//
+// try {
+// casDocument.save();
+// }
+// catch (CoreException e) {
+// fireElementStateChangeFailed(element);
+// throw e;
+// }
+//
+// fireElementDirtyStateChanged(element, false);
+// }
+
+ @Override
+ protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
+ return null;
+ }
+
+ @Override
+ public IStatus getStatus(Object element) {
+ IStatus status = mElementErrorStatus.get(element);
+
+ if (status == null) {
+ status = super.getStatus(element);
+ }
+
+ return status;
+ }
+
+ protected abstract AnnotationStyle getAnnotationStyle(Object element, Type type);
+
+ protected abstract EditorAnnotationStatus getEditorAnnotationStatus(
+ Object element);
+
+ protected abstract void setEditorAnnotationStatus(Object element,
+ EditorAnnotationStatus editorAnnotationStatus);
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,72 @@
+/*
+ * 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 org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+
+class CasDocumentProviderFactory {
+
+ private static final String CAS_EDITOR_EXTENSION = "org.apache.uima.caseditor.editor";
+
+ private static CasDocumentProviderFactory instance;
+
+ private CasDocumentProvider documentProvider;
+
+ CasDocumentProviderFactory() {
+
+ IConfigurationElement[] config = Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(CAS_EDITOR_EXTENSION);
+
+ for (IConfigurationElement e : config) {
+
+ if ("provider".equals(e.getName())) {
+
+ Object o;
+ try {
+ o = e.createExecutableExtension("class");
+ } catch (CoreException e1) {
+ // TODO: Log error, extension point was not specified correctly !!!
+ e1.printStackTrace();
+ o = null;
+ }
+
+ if (o instanceof CasDocumentProvider) {
+ documentProvider = (CasDocumentProvider) o;
+ }
+ }
+ }
+
+ }
+
+ CasDocumentProvider getDocumentProvider() {
+ return documentProvider;
+ }
+
+ static CasDocumentProviderFactory instance() {
+
+ if (instance == null) {
+ instance = new CasDocumentProviderFactory();
+ }
+
+ return instance;
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorError.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorError.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorError.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorError.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+/**
+ * A general {@link RuntimeException} which is thrown if something unexpected happens.
+ */
+public class CasEditorError extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Initializes the current instance.
+ *
+ * @param message
+ */
+ public CasEditorError(String message) {
+ super(message);
+ }
+
+ /**
+ * Initializes the current instance.
+ *
+ * @param message
+ * @param cause
+ */
+ public CasEditorError(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorError.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorPlugin.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorPlugin.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorPlugin.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorPlugin.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,144 @@
+/*
+ * 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.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * TODO: add javadoc here
+ */
+public class CasEditorPlugin extends AbstractUIPlugin {
+ public static final String ID = "org.apache.uima.caseditor";
+
+ private static final String ICONS_PATH = "icons/";
+
+ /**
+ * The shared instance.
+ */
+ private static CasEditorPlugin sPlugin;
+
+ /**
+ * Resource bundle.
+ */
+ private ResourceBundle mResourceBundle;
+
+ /**
+ * The constructor.
+ */
+ public CasEditorPlugin() {
+ super();
+
+ sPlugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ *
+ * @param context
+ * @throws Exception
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /**
+ * This method is called when the plug-in is stopped.
+ *
+ * @param context
+ * @throws Exception
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+
+ sPlugin = null;
+ mResourceBundle = null;
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the TaePlugin
+ */
+ public static CasEditorPlugin getDefault() {
+ return sPlugin;
+ }
+
+ /**
+ * Returns the string from the plugin's resource bundle, or 'key' if not found.
+ *
+ * @param key
+ * @return resource string
+ */
+ public static String getResourceString(String key) {
+ ResourceBundle bundle = getDefault().getResourceBundle();
+
+ try {
+ return (bundle != null) ? bundle.getString(key) : key;
+ } catch (MissingResourceException e) {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle.
+ *
+ * @return the ResourceBbundle or null if missing
+ */
+ public ResourceBundle getResourceBundle() {
+ try {
+ if (mResourceBundle == null) {
+ mResourceBundle = ResourceBundle.getBundle("Annotator.AnnotatorPluginResources");
+ }
+ } catch (MissingResourceException x) {
+ mResourceBundle = null;
+ }
+
+ return mResourceBundle;
+ }
+
+ /**
+ * Log the throwable.
+ *
+ * @param t
+ */
+ public static void log(Throwable t) {
+ getDefault().getLog().log(new Status(IStatus.ERROR, ID, IStatus.OK, t.getMessage(), t));
+ }
+
+ /**
+ * Retrieves an image.
+ *
+ * @param image
+ * @return the requested image if not available null
+ */
+ public static ImageDescriptor getTaeImageDescriptor(Images image) {
+ return imageDescriptorFromPlugin(ID, ICONS_PATH + image.getPath());
+ }
+
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CasEditorPlugin.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ChangeModeAction.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ChangeModeAction.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ChangeModeAction.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ChangeModeAction.java Tue Nov 4 12:59:10 2008
@@ -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;
+
+import org.apache.uima.cas.Type;
+import org.eclipse.jface.action.Action;
+
+/**
+ * The {@link ChangeModeAction} changes the editor annotation mode to the newly selected one.
+ */
+final class ChangeModeAction extends Action {
+ /**
+ * The {@link AnnotationEditor} the current instance belongs to.
+ */
+ private AnnotationEditor mEditor;
+
+ /**
+ * The new target mode.
+ */
+ private Type mMode;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param newMode -target mode
+ * @param name - name of the action
+ * @param editor
+ */
+ ChangeModeAction(Type newMode, String name, AnnotationEditor editor) {
+ mMode = newMode;
+ mEditor = editor;
+ setText(name);
+ }
+
+ /**
+ * Retrieves the document.
+ *
+ * @return the document
+ */
+ protected AnnotationDocument getDocument() {
+ return mEditor.getDocument();
+ }
+
+ /**
+ * Executes the current action.
+ */
+ @Override
+ public void run() {
+ if (mEditor != null) {
+ mEditor.setAnnotationMode(mMode);
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ChangeModeAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CustomInformationControl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CustomInformationControl.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CustomInformationControl.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CustomInformationControl.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,164 @@
+/*
+ * 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 org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlExtension2;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * TODO: add javadoc here
+ */
+public class CustomInformationControl implements IInformationControl, IInformationControlExtension2 {
+ private Shell mShell;
+
+ private Control mControl;
+
+ private ICustomInformationControlContentHandler mContentHandler;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param parent
+ * @param contentHandler
+ */
+ public CustomInformationControl(Shell parent,
+ ICustomInformationControlContentHandler contentHandler) {
+ mContentHandler = contentHandler;
+
+ mShell = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP);
+ mShell.setLayout(new FillLayout());
+
+ Display display = mShell.getDisplay();
+ mShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
+ }
+
+ /**
+ * Sets the viewer control
+ *
+ * @param viewerControl
+ */
+ public void setControl(Control viewerControl) {
+ mControl = viewerControl;
+ mShell.setSize(viewerControl.getSize());
+ }
+
+ /**
+ * Retrieves the parent.
+ *
+ * @return the parent
+ */
+ public Composite getParent() {
+ return mShell;
+ }
+
+ public void setInformation(String information) {
+ // this method is replaced by the extension interface
+ // method setInput(...)
+ }
+
+ public void setSizeConstraints(int maxWidth, int maxHeight) {
+ }
+
+ public Point computeSizeHint() {
+ return mShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+
+ public void setVisible(boolean visible) {
+ mControl.setVisible(visible);
+ mShell.setVisible(visible);
+ }
+
+ public void setSize(int width, int height) {
+ // mShell.setSize(width, height);
+ }
+
+ public void setLocation(Point location) {
+ Rectangle trim = mShell.computeTrim(0, 0, 0, 0);
+
+ Point textLocation = mControl.getLocation();
+ location.x += trim.x - textLocation.x;
+ location.y += trim.y - textLocation.y;
+
+ mShell.setLocation(location);
+ }
+
+ public void dispose() {
+ if (mShell != null && !mShell.isDisposed()) {
+ mShell.dispose();
+ }
+ }
+
+ public void addDisposeListener(DisposeListener listener) {
+ mShell.addDisposeListener(listener);
+ }
+
+ public void removeDisposeListener(DisposeListener listener) {
+ mShell.removeDisposeListener(listener);
+ }
+
+ public void setForegroundColor(Color foreground) {
+ mShell.setForeground(foreground);
+ }
+
+ public void setBackgroundColor(Color background) {
+ mShell.setBackground(background);
+ }
+
+ public boolean isFocusControl() {
+ return mShell.isFocusControl();
+ }
+
+ public void setFocus() {
+ mShell.setFocus();
+ }
+
+ public void addFocusListener(FocusListener listener) {
+ mShell.addFocusListener(listener);
+ }
+
+ public void removeFocusListener(FocusListener listener) {
+ mShell.removeFocusListener(listener);
+ }
+
+ public void setInput(Object input) {
+ mContentHandler.setInput(this, input);
+
+ }
+
+ /**
+ * Retrieves the control
+ *
+ * @return the control
+ */
+ public Control getControl() {
+ return mControl;
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/CustomInformationControl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentFormat.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentFormat.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentFormat.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentFormat.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ * Specifies the format of the uima document.
+ */
+public enum DocumentFormat {
+ XCAS,
+ XMI
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentFormat.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentUimaImpl.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentUimaImpl.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentUimaImpl.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,384 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.ConstraintFactory;
+import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.FSIntConstraint;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.FeaturePath;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.impl.XCASDeserializer;
+import org.apache.uima.cas.impl.XCASSerializer;
+import org.apache.uima.cas.impl.XmiCasDeserializer;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.editor.util.Span;
+import org.apache.uima.caseditor.editor.util.StrictTypeConstraint;
+import org.apache.uima.util.XMLSerializer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.xml.sax.SAXException;
+
+/**
+ * This document implementation is based on an uima cas object.
+ */
+public class DocumentUimaImpl extends AbstractDocument {
+
+ // TODO: Remove field not needed anymore
+ private final TypeSystem mTypeSystem;
+
+ private final CAS mCAS;
+
+ private final DocumentFormat format;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param project
+ */
+ public DocumentUimaImpl(CAS cas, InputStream in,
+ DocumentFormat format) throws CoreException {
+
+ mCAS = cas;
+
+ mTypeSystem = cas.getTypeSystem();
+
+ this.format = format;
+
+ setContent(in);
+ }
+
+ /**
+ * Retrieves the {@link CAS}.
+ */
+ public CAS getCAS() {
+ return mCAS;
+ }
+
+ /**
+ * Adds the given annotation to the {@link CAS}.
+ */
+ public void addFeatureStructure(FeatureStructure annotation) {
+ mCAS.getIndexRepository().addFS(annotation);
+
+ fireAddedAnnotation(annotation);
+ }
+
+ /**
+ *
+ */
+ public void addFeatureStructures(Collection<FeatureStructure> annotations) {
+ for (FeatureStructure annotation : annotations) {
+ addFeatureStructure(annotation);
+ }
+ }
+
+ /**
+ * Remove all annotations. TODO: implement it
+ */
+ public void removeAnnotation() {
+ // must be implemented
+ }
+
+ /**
+ * Internally removes an annotation from the {@link CAS}.
+ *
+ * @param featureStructure
+ */
+ private void removeAnnotationInternal(FeatureStructure featureStructure) {
+ getCAS().getIndexRepository().removeFS(featureStructure);
+ }
+
+ /**
+ * Removes the annotations from the {@link CAS}.
+ */
+ public void removeFeatureStructure(FeatureStructure annotation) {
+ removeAnnotationInternal(annotation);
+
+ fireRemovedAnnotation(annotation);
+ }
+
+ /**
+ * Removes the given annotations from the {@link CAS}.
+ */
+ public void removeFeatureStructures(
+ Collection<FeatureStructure> annotationsToRemove) {
+
+ for (FeatureStructure annotationToRemove : annotationsToRemove) {
+ removeAnnotationInternal(annotationToRemove);
+ }
+
+ if (annotationsToRemove.size() > 0) {
+ fireRemovedAnnotations(annotationsToRemove);
+ }
+ }
+
+ /**
+ * Notifies clients about the changed annotation.
+ */
+ public void update(FeatureStructure annotation) {
+ fireUpdatedFeatureStructure(annotation);
+ }
+
+ /**
+ * Notifies clients about the changed annotation.
+ */
+ public void updateFeatureStructure(Collection<FeatureStructure> annotations) {
+ fireUpdatedFeatureStructures(annotations);
+ }
+
+ public void changed() {
+ fireChanged();
+ }
+
+ /**
+ * Retrieves annotations of the given type from the {@link CAS}.
+ */
+ public Collection<AnnotationFS> getAnnotations(Type type) {
+ FSIndex annotationIndex = mCAS.getAnnotationIndex(type);
+
+ StrictTypeConstraint typeConstrain = new StrictTypeConstraint(type);
+
+ FSIterator strictTypeIterator = mCAS.createFilteredIterator(
+ annotationIndex.iterator(), typeConstrain);
+
+ return fsIteratorToCollection(strictTypeIterator);
+ }
+
+ private Collection<AnnotationFS> fsIteratorToCollection(FSIterator iterator) {
+ LinkedList<AnnotationFS> annotations = new LinkedList<AnnotationFS>();
+ while (iterator.hasNext()) {
+ AnnotationFS annotation = (AnnotationFS) iterator.next();
+
+ annotations.addFirst(annotation);
+ }
+
+ return annotations;
+ }
+
+ /**
+ * Retrieves the annotations in the given span.
+ */
+ @Override
+ public Collection<AnnotationFS> getAnnotation(Type type, Span span) {
+ ConstraintFactory cf = getCAS().getConstraintFactory();
+
+ Type annotationType = getCAS().getAnnotationType();
+
+ FeaturePath beginPath = getCAS().createFeaturePath();
+ beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
+ FSIntConstraint beginConstraint = cf.createIntConstraint();
+ beginConstraint.geq(span.getStart());
+
+ FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath,
+ beginConstraint);
+
+ FeaturePath endPath = getCAS().createFeaturePath();
+ endPath.addFeature(annotationType.getFeatureByBaseName("end"));
+ FSIntConstraint endConstraint = cf.createIntConstraint();
+ endConstraint.leq(span.getEnd());
+
+ FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath,
+ endConstraint);
+
+ FSMatchConstraint strictType = new StrictTypeConstraint(type);
+
+ FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin,
+ embeddedEnd);
+
+ FSMatchConstraint annotationInSpanAndStrictTypeConstraint = cf.and(
+ annotatioInSpanConstraint, strictType);
+
+ FSIndex allAnnotations = getCAS().getAnnotationIndex(type);
+
+ FSIterator annotationInsideSpanIndex = getCAS().createFilteredIterator(
+ allAnnotations.iterator(),
+ annotationInSpanAndStrictTypeConstraint);
+
+ return fsIteratorToCollection(annotationInsideSpanIndex);
+ }
+
+ /**
+ * Retrieves the given type from the {@link TypeSystem}.
+ */
+ public Type getType(String type) {
+ return getCAS().getTypeSystem().getType(type);
+ }
+
+ /**
+ * Retrieves the text.
+ */
+ public String getText() {
+ return mCAS.getDocumentText();
+ }
+
+ /**
+ * Sets the content. The XCAS {@link InputStream} gets parsed.
+ */
+ private void setContent(InputStream content) throws CoreException {
+
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setValidating(false);
+
+ SAXParser saxParser;
+
+ try {
+ saxParser = saxParserFactory.newSAXParser();
+ } catch (ParserConfigurationException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+
+ if (DocumentFormat.XCAS.equals(format)) {
+ XCASDeserializer dezerializer = new XCASDeserializer(mTypeSystem);
+
+ try {
+ saxParser.parse(content, dezerializer.getXCASHandler(mCAS));
+ } catch (IOException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+ } else if (DocumentFormat.XMI.equals(format)) {
+ XmiCasDeserializer dezerializer = new XmiCasDeserializer(
+ mTypeSystem);
+
+ try {
+ saxParser.parse(content, dezerializer.getXmiCasHandler(mCAS));
+ } catch (IOException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+ } else {
+ throw new CoreException(
+ new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK,
+ "Unkown file format!", null));
+ }
+ }
+
+ /**
+ * Serializes the {@link CAS} to the given {@link OutputStream} in the XCAS
+ * format.
+ */
+ public void serialize(OutputStream out) throws CoreException {
+
+ if (DocumentFormat.XCAS.equals(format)) {
+ XCASSerializer xcasSerializer = new XCASSerializer(mCAS
+ .getTypeSystem());
+
+ XMLSerializer xmlSerialzer = new XMLSerializer(out, true);
+
+ try {
+ xcasSerializer
+ .serialize(mCAS, xmlSerialzer.getContentHandler());
+ } catch (IOException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+ } else if (DocumentFormat.XMI.equals(format)) {
+ XmiCasSerializer xmiSerializer = new XmiCasSerializer(mCAS
+ .getTypeSystem());
+
+ XMLSerializer xmlSerialzer = new XMLSerializer(out, true);
+
+ try {
+ xmiSerializer.serialize(mCAS, xmlSerialzer.getContentHandler());
+ } catch (SAXException e) {
+ String message = (e.getMessage() != null ? e.getMessage() : "");
+
+ IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
+ IStatus.OK, message, e);
+
+ throw new CoreException(s);
+ }
+ } else {
+ throw new CoreException(
+ new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK,
+ "Unkown file format!", null));
+ }
+ }
+
+// public DocumentElement getDocumentElement() {
+// return mDocumentElement;
+// }
+//
+// public void save() throws CoreException {
+// getDocumentElement().saveDocument();
+// }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/EditorAnnotationStatus.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/EditorAnnotationStatus.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/EditorAnnotationStatus.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/EditorAnnotationStatus.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,73 @@
+/*
+ * 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;
+import java.util.HashSet;
+
+import org.apache.uima.cas.Type;
+
+/**
+ * TODO: add javadoc here
+ */
+public class EditorAnnotationStatus {
+ private String mMode;
+
+ private Collection<String> mDisplayAnnotations = new HashSet<String>();
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param mode
+ * @param displayAnnotations
+ */
+ public EditorAnnotationStatus(String mode, Collection<Type> displayAnnotations) {
+ if (mode == null) {
+ throw new IllegalArgumentException("Mode must not be null!");
+ }
+
+ mMode = mode;
+
+ if (displayAnnotations != null) {
+
+ for (Type type : displayAnnotations) {
+ mDisplayAnnotations.add(type.getName());
+ }
+ }
+ }
+
+ /**
+ * Retrieves the editor mode.
+ *
+ * @return the editor mode
+ */
+ public String getMode() {
+ return mMode;
+ }
+
+ /**
+ * Retrieves the annotations which a displayed in the editor.
+ *
+ * @return the display annotations
+ */
+ public Collection<String> getDisplayAnnotations() {
+ return mDisplayAnnotations;
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/EditorAnnotationStatus.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelection.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelection.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelection.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelection.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,99 @@
+/*
+ * 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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.uima.cas.FeatureStructure;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ *
+ */
+public class FeatureStructureSelection {
+ private List<FeatureStructure> mFeatureStructures;
+
+ /**
+ * Initializes a the current instance with all FeatureStructure object that are contained in the
+ * {@link StructuredSelection}.
+ *
+ * @param selection
+ */
+ public FeatureStructureSelection(IStructuredSelection selection) {
+ mFeatureStructures = new ArrayList<FeatureStructure>(selection.size());
+
+ for (Object item : selection.toList()) {
+ FeatureStructure annotation = (FeatureStructure) Platform.getAdapterManager().getAdapter(
+ item, FeatureStructure.class);
+
+ // TODO: fix it
+ if (annotation == null && item instanceof IAdaptable) {
+ annotation = (FeatureStructure) ((IAdaptable) item).getAdapter(FeatureStructure.class);
+ }
+
+ if (annotation != null) {
+ mFeatureStructures.add(annotation);
+ }
+ }
+
+ mFeatureStructures = Collections.unmodifiableList(mFeatureStructures);
+ }
+
+ /**
+ * Retrieves the size of the collection.
+ *
+ * @return the size
+ */
+ public int size() {
+ return mFeatureStructures.size();
+ }
+
+ /**
+ * Indicates that the selection is empty.
+ *
+ * @return true if empty false otherwise
+ */
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ /**
+ * Retrieves a list of {@link FeatureStructure} objects.
+ *
+ * @return all selected {@link FeatureStructure} objects
+ */
+ public List<FeatureStructure> toList() {
+ return mFeatureStructures;
+ }
+
+ /**
+ * Retrieves a human readable string.
+ * @return human readable string
+ */
+ @Override
+ public String toString() {
+ return mFeatureStructures.toString();
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionIterator.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionIterator.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionIterator.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionIterator.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,89 @@
+/*
+ * 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.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+/**
+ * Iterates over all selected {@link FeatureStructure}s.
+ */
+public class FeatureStructureSelectionIterator implements Iterator<FeatureStructure> {
+
+ private Iterator mSelectionIterator;
+
+ private FeatureStructure mNext;
+
+ /**
+ * Initializes the current instance.
+ *
+ * @param selection
+ */
+ public FeatureStructureSelectionIterator(IStructuredSelection selection) {
+ mSelectionIterator = selection.iterator();
+ }
+
+ /**
+ * Check if there is one more element.
+ *
+ * @return true if there is one more element.
+ */
+ public boolean hasNext() {
+ while (mSelectionIterator.hasNext() && mNext == null) {
+ Object item = mSelectionIterator.next();
+
+ if (item instanceof IAdaptable) {
+ mNext = (FeatureStructure) ((IAdaptable) item).getAdapter(AnnotationFS.class);
+ }
+ }
+
+ return mNext != null;
+ }
+
+ /**
+ * Retrieves the next element.
+ *
+ * @return the next element.
+ */
+ public FeatureStructure next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ FeatureStructure result = mNext;
+ mNext = null;
+
+ return result;
+ }
+
+ /**
+ * Not supported, it throws an {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionIterator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,128 @@
+/*
+ * 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.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ * This class is a {@link ISelectionProvider} and informs its listeners about the currently selected
+ * {@link FeatureStructure}s.
+ */
+class FeatureStructureSelectionProvider implements ISelectionProvider {
+
+ private IStructuredSelection mCurrentSelection = new StructuredSelection();
+
+ private Set<ISelectionChangedListener> mListeners = new HashSet<ISelectionChangedListener>();
+
+ /**
+ * Adds an {@link ISelectionChangedListener} to this provider.
+ *
+ * @param listener
+ */
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ Assert.isNotNull(listener);
+
+ mListeners.add(listener);
+ }
+
+ /**
+ * Retrieves the current selection.
+ *
+ * @return selection
+ */
+ public ISelection getSelection() {
+ return mCurrentSelection;
+ }
+
+ /**
+ * Removes a registered selection listener.
+ *
+ * @param listener
+ * the listener to remove
+ */
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ mListeners.remove(listener);
+ }
+
+ /**
+ * Sets the current selection.
+ *
+ * @param selection
+ */
+ public void setSelection(ISelection selection) {
+ Assert.isNotNull(selection);
+
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+
+ mCurrentSelection = structuredSelection;
+
+ for (ISelectionChangedListener listener : mListeners) {
+ SelectionChangedEvent event = new SelectionChangedEvent(this, mCurrentSelection);
+
+ listener.selectionChanged(event);
+ }
+ }
+
+ /**
+ * Sets the current selection to the given {@link AnnotationFS} object.
+ *
+ * @param annotation
+ */
+ public void setSelection(IDocument document, AnnotationFS annotation) {
+ if (annotation == null) {
+ throw new IllegalArgumentException("annotation must not be null!");
+ }
+
+ setSelection(new StructuredSelection(new ModelFeatureStructure(document, annotation)));
+ }
+
+ public void setSelection(IDocument document, List<AnnotationFS> selection) {
+ setSelection(new StructuredSelection(ModelFeatureStructure.create(document, selection)));
+ }
+
+ /**
+ * Replaces the current selection with an empty selection.
+ */
+ public void clearSelection() {
+ setSelection(new StructuredSelection());
+ }
+
+ /**
+ * Replaces the current selection with an empty selection without notifying listeners about it.
+ *
+ * Use it if the selection object is removed and a new selection was already made by an other
+ * {@link ISelectionProvider} instance.
+ */
+ public void clearSelectionSilently() {
+ mCurrentSelection = new StructuredSelection();
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureValue.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureValue.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureValue.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureValue.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,112 @@
+/*
+ * 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 org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.editor.util.Primitives;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+
+public final class FeatureValue implements IAdaptable {
+ private FeatureStructure mStructure;
+
+ private Feature mFeature;
+
+ private AnnotationDocument mDocument;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param feature
+ * @param value
+ */
+ public FeatureValue(AnnotationDocument document, FeatureStructure structure, Feature feature) {
+ Assert.isNotNull(document);
+ mDocument = document;
+
+ Assert.isNotNull(feature);
+ mFeature = feature;
+
+ Assert.isNotNull(feature);
+ mStructure = structure;
+ }
+
+ public FeatureStructure getFeatureStructure() {
+ return mStructure;
+ }
+
+ public Object getValue() {
+ if (Primitives.isPrimitive(mFeature)) {
+ return Primitives.getPrimitiv(mStructure, mFeature);
+ }
+
+ return mStructure.getFeatureValue(mFeature);
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (AnnotationFS.class.equals(adapter)) {
+ if (getValue() instanceof AnnotationFS) {
+ return getValue();
+ }
+ }
+
+ if (FeatureStructure.class.equals(adapter)) {
+ if (getValue() instanceof FeatureStructure) {
+ return getValue();
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ boolean result = false;
+
+ if (this == object) {
+ result = true;
+ } else if (object != null && object instanceof FeatureValue) {
+ FeatureValue valueToCompare = (FeatureValue) object;
+
+ result = valueToCompare.mStructure.equals(mStructure)
+ && valueToCompare.mFeature.equals(mFeature);
+ }
+
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ return mStructure.hashCode() | mFeature.hashCode();
+ }
+
+ /**
+ * Retrieves the {@link Feature}.
+ *
+ * @return the {@link Feature}
+ */
+ public Feature getFeature() {
+ return mFeature;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/FeatureValue.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/IAnnotationEditorModifyListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/IAnnotationEditorModifyListener.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/IAnnotationEditorModifyListener.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/IAnnotationEditorModifyListener.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import org.apache.uima.cas.Type;
+
+public interface IAnnotationEditorModifyListener {
+
+ /**
+ * Called when the editor annotation mode changed.
+ *
+ * @param newMode
+ */
+ public void annotationModeChanged(Type newMode);
+
+ /**
+ * Called when the shown annotation types in the editor are changed.
+ *
+ * @param shownAnnotationTypes
+ */
+ public void showAnnotationsChanged(Collection<Type> shownAnnotationTypes);
+}
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/IAnnotationEditorModifyListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ICustomInformationControlContentHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ICustomInformationControlContentHandler.java?rev=711402&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ICustomInformationControlContentHandler.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ICustomInformationControlContentHandler.java Tue Nov 4 12:59:10 2008
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+public interface ICustomInformationControlContentHandler {
+ /**
+ * Sets the input object.
+ *
+ * @param control
+ * @param input
+ */
+ void setInput(CustomInformationControl control, Object input);
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/main/java/src/org/apache/uima/caseditor/editor/ICustomInformationControlContentHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain