You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/09/04 18:47:07 UTC
svn commit: r572734 - in
/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor:
AnnotationEditor.java AnnotationInformationProvider.java ArrayValue.java
QuickTypeSelectionDialog.java context/AnnotationEditingControl.java
Author: twgoetz
Date: Tue Sep 4 09:47:07 2007
New Revision: 572734
URL: http://svn.apache.org/viewvc?rev=572734&view=rev
Log:
Jira UIMA-559: apply Joern's UIMA-559.patch.
https://issues.apache.org/jira/browse/UIMA-559
Added:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/QuickTypeSelectionDialog.java
Modified:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/ArrayValue.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/context/AnnotationEditingControl.java
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=572734&r1=572733&r2=572734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Tue Sep 4 09:47:07 2007
@@ -139,7 +139,7 @@
getDocument().addFeatureStructure(annotation);
- mFeatureStructureSelectionProvider.setSelection(getDocument(), annotation);
+ setAnnotationSelection(annotation);
}
}
@@ -148,6 +148,22 @@
}
}
+ private class SmartAnnotateAction extends Action {
+
+ @Override
+ public void run() {
+
+ if (isSomethingSelected()) {
+
+ QuickTypeSelectionDialog typeDialog =
+ new QuickTypeSelectionDialog(Display.getCurrent().getActiveShell(),
+ AnnotationEditor.this);
+
+ typeDialog.open();
+ }
+ }
+ }
+
/**
* Shows the annotation editing context for the active annotation.
*/
@@ -538,7 +554,7 @@
private ShowAnnotationsMenu mShowAnnotationsMenu;
-private DocumentListener mAnnotationSynchronizer;
+ private DocumentListener mAnnotationSynchronizer;
/**
* Creates an new AnnotationEditor object.
@@ -960,11 +976,20 @@
// create annotate action
AnnotateAction annotateAction = new AnnotateAction(getSourceViewer().getTextWidget());
- annotateAction.setActionDefinitionId(ITextEditorActionDefinitionIds.SMART_ENTER);
+ final String annotateActionID = "Enter";
+
+ annotateAction.setActionDefinitionId(annotateActionID);
+
+ setAction(annotateActionID, annotateAction);
+ setActionActivationCode(annotateActionID, '\r', SWT.CR,
+ SWT.NONE);
+
+ SmartAnnotateAction smartAnnotateAction = new SmartAnnotateAction();
+ smartAnnotateAction.setActionDefinitionId(ITextEditorActionDefinitionIds.SMART_ENTER);
+ setAction(ITextEditorActionDefinitionIds.SMART_ENTER, smartAnnotateAction);
- setAction(ITextEditorActionDefinitionIds.SMART_ENTER, annotateAction);
setActionActivationCode(ITextEditorActionDefinitionIds.SMART_ENTER, '\r', SWT.CR,
- SWT.DEFAULT);
+ SWT.SHIFT);
// create delete action
DeleteFeatureStructureAction deleteAnnotationAction = new DeleteFeatureStructureAction(
@@ -1000,5 +1025,9 @@
public void setDirty() {
getDocument().fireDocumentChanged();
+ }
+
+ void setAnnotationSelection(AnnotationFS annotation) {
+ mFeatureStructureSelectionProvider.setSelection(getDocument(), annotation);
}
}
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java?rev=572734&r1=572733&r2=572734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationInformationProvider.java Tue Sep 4 09:47:07 2007
@@ -6,9 +6,9 @@
* 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
@@ -41,7 +41,7 @@
/**
* TODO: add comment
- *
+ *
* @param textViewer
* @param offset
* @return the region
@@ -55,7 +55,7 @@
/**
* TODO: add comment
- *
+ *
* @param textViewer
* @param subject
* @return null
@@ -66,10 +66,10 @@
/**
* TODO: add comment
- *
+ *
* @param textViewer
* @param subject
- * @return the selected annoation
+ * @return the selected annotation
*/
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
List<AnnotationFS> selection = mEditor.getSelectedAnnotations();
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/ArrayValue.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/ArrayValue.java?rev=572734&r1=572733&r2=572734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/ArrayValue.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/ArrayValue.java Tue Sep 4 09:47:07 2007
@@ -20,6 +20,7 @@
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;
@@ -27,6 +28,8 @@
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.apache.uima.caseditor.core.TaeError;
import org.eclipse.core.runtime.IAdaptable;
@@ -55,66 +58,73 @@
}
public void set(String value) {
- if (arrayFS instanceof ByteArrayFS) {
- ByteArrayFS array = (ByteArrayFS) arrayFS;
+ 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) {
+ } else if (arrayFS instanceof ShortArrayFS) {
ShortArrayFS array = (ShortArrayFS) arrayFS;
array.set(slot, Short.parseShort(value));
- }
- else if (arrayFS instanceof IntArrayFS) {
+ } else if (arrayFS instanceof IntArrayFS) {
IntArrayFS array = (IntArrayFS) arrayFS;
array.set(slot, Integer.parseInt(value));
- }
- else if (arrayFS instanceof LongArrayFS) {
+ } else if (arrayFS instanceof LongArrayFS) {
LongArrayFS array = (LongArrayFS) arrayFS;
array.set(slot, Long.parseLong(value));
- }
- else if (arrayFS instanceof FloatArrayFS) {
+ } else if (arrayFS instanceof FloatArrayFS) {
FloatArrayFS array = (FloatArrayFS) arrayFS;
array.set(slot, Float.parseFloat(value));
- }
- else if (arrayFS instanceof DoubleArrayFS) {
+ } else if (arrayFS instanceof DoubleArrayFS) {
DoubleArrayFS array = (DoubleArrayFS) arrayFS;
array.set(slot, Double.parseDouble(value));
- }
- else {
+ } else if (arrayFS instanceof StringArrayFS) {
+ StringArrayFS array = (StringArrayFS) arrayFS;
+ array.set(slot, value);
+ } else {
throw new TaeError("Unkown array type!");
}
}
public Object get() {
- if (arrayFS instanceof ByteArrayFS) {
+
+ 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) {
+ } else if (arrayFS instanceof ShortArrayFS) {
ShortArrayFS array = (ShortArrayFS) arrayFS;
return array.get(slot);
- }
- else if (arrayFS instanceof IntArrayFS) {
+ } else if (arrayFS instanceof IntArrayFS) {
IntArrayFS array = (IntArrayFS) arrayFS;
return array.get(slot);
- }
- else if (arrayFS instanceof LongArrayFS) {
+ } else if (arrayFS instanceof LongArrayFS) {
LongArrayFS array = (LongArrayFS) arrayFS;
return array.get(slot);
- }
- else if (arrayFS instanceof FloatArrayFS) {
+ } else if (arrayFS instanceof FloatArrayFS) {
FloatArrayFS array = (FloatArrayFS) arrayFS;
return array.get(slot);
- }
- else if (arrayFS instanceof DoubleArrayFS) {
+ } else if (arrayFS instanceof DoubleArrayFS) {
DoubleArrayFS array = (DoubleArrayFS) arrayFS;
return array.get(slot);
- }
- else if (arrayFS instanceof ArrayFS) {
+ } 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 {
+ } else {
throw new TaeError("Unkown array type!");
}
}
@@ -126,6 +136,14 @@
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;
}
}
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/QuickTypeSelectionDialog.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/QuickTypeSelectionDialog.java?rev=572734&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/QuickTypeSelectionDialog.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/QuickTypeSelectionDialog.java Tue Sep 4 09:47:07 2007
@@ -0,0 +1,189 @@
+/*
+ * 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.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.eclipse.jface.dialogs.PopupDialog;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+/**
+ * This is a lightweight popup dialog which creates an annotation of the
+ * chosen type.
+ */
+class QuickTypeSelectionDialog extends PopupDialog {
+
+ private final AnnotationEditor editor;
+
+ private Text filterText;
+
+ QuickTypeSelectionDialog(Shell parent, AnnotationEditor editor) {
+ super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, true, false, true, null, null);
+
+ this.editor = editor;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ filterText = new Text(composite, SWT.NONE);
+ filterText.setBackground(parent.getBackground());
+ filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);
+ separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ final TreeViewer typeTree = new TreeViewer(composite, SWT.SINGLE | SWT.V_SCROLL);
+ typeTree.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL |
+ GridData.FILL_VERTICAL));
+
+ filterText.addKeyListener(new KeyListener() {
+
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) {
+ typeTree.getControl().setFocus();
+ }
+ }
+
+ public void keyReleased(KeyEvent e) {
+ typeTree.refresh(false);
+ }
+ });
+
+ typeTree.setContentProvider(new ITreeContentProvider() {
+
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ TypeSystem typeSystem = (TypeSystem) inputElement;
+
+ List types = typeSystem.getProperlySubsumedTypes(typeSystem
+ .getType(CAS.TYPE_NAME_ANNOTATION));
+
+ return types.toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ });
+
+ typeTree.setFilters(new ViewerFilter[] { new ViewerFilter() {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+
+ // check if the string from the filterText is contained in the type name
+ Type type = (Type) element;
+
+ return type.getName().contains(filterText.getText());
+ }
+ } });
+
+ typeTree.getControl().addMouseMoveListener(new MouseMoveListener() {
+
+ public void mouseMove(MouseEvent e) {
+
+ Tree tree = (Tree) typeTree.getControl();
+
+ TreeItem item = tree.getItem(new Point(e.x, e.y));
+
+ if (item != null) {
+ tree.setSelection(item);
+ }
+ }
+ });
+
+ typeTree.addOpenListener(new IOpenListener() {
+
+ public void open(OpenEvent event) {
+
+ StructuredSelection selection = (StructuredSelection) event.getSelection();
+
+ Type annotationType = (Type) selection.getFirstElement();
+
+ if (annotationType != null) {
+ Point textSelection = editor.getSelection();
+
+ AnnotationFS annotation = editor.getDocument().getCAS().createAnnotation(annotationType,
+ textSelection.x, textSelection.y);
+
+ editor.getDocument().addFeatureStructure(annotation);
+
+ if (annotation.getType().equals(editor.getAnnotationMode())) {
+ editor.setAnnotationSelection(annotation);
+ }
+ }
+
+ QuickTypeSelectionDialog.this.close();
+ }
+ });
+
+ typeTree.setInput(editor.getDocument().getCAS().getTypeSystem());
+
+ ISelection modeSelection = new StructuredSelection(new Object[] { editor.getAnnotationMode() });
+
+ typeTree.setSelection(modeSelection, true);
+
+ return composite;
+ }
+
+ @Override
+ protected Point getInitialSize() {
+ return new Point(250, 300);
+ }
+}
\ No newline at end of file
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/context/AnnotationEditingControl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/context/AnnotationEditingControl.java?rev=572734&r1=572733&r2=572734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/context/AnnotationEditingControl.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/context/AnnotationEditingControl.java Tue Sep 4 09:47:07 2007
@@ -6,9 +6,9 @@
* 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
@@ -19,7 +19,6 @@
package org.apache.uima.caseditor.editor.context;
-import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
@@ -33,7 +32,7 @@
/**
* Initializes the current instance.
- *
+ *
* @param parent
*/
public AnnotationEditingControl(Composite parent) {
@@ -49,12 +48,12 @@
/**
* Display this feature structure.
- *
- * @param structure
+ *
+ * @param structure
*/
public void displayFeatureStructure(FeatureStructure structure) {
- Feature hack = structure.getType().getFeatureByBaseName("byte");
- structure.setFeatureValue(hack, structure.getCAS().createByteArrayFS(5));
+
+
}
}