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/03 11:23:24 UTC
svn commit: r572266 - in
/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor:
./ core/uima/ editor/ editor/editview/ editor/editview/validator/
editor/fsview/
Author: twgoetz
Date: Mon Sep 3 02:23:22 2007
New Revision: 572266
URL: http://svn.apache.org/viewvc?rev=572266&view=rev
Log:
Jira UIMA-526: apply UIMA-526-2.patch.
https://issues.apache.org/jira/browse/UIMA-526
Added:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/CreateFeatureStructureDialog.java
Removed:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/CreateArrayDialog.java
Modified:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.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/FeatureStructureSelectionProvider.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditView.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditViewPage.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/FeatureStructureContentProvider.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/ValueColumnLabelProvider.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/validator/CellEditorValidatorFacotory.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/FeatureStructureBrowserViewPage.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/ITypePaneListener.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/TypeSelectionPane.java
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java Mon Sep 3 02:23:22 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
@@ -47,7 +47,7 @@
* Resource bundle.
*/
private ResourceBundle mResourceBundle;
-
+
private static NlpModel sNLPModel;
/**
@@ -61,7 +61,7 @@
/**
* This method is called upon plug-in activation
- *
+ *
* @param context
* @throws Exception
*/
@@ -72,7 +72,7 @@
/**
* This method is called when the plug-in is stopped.
- *
+ *
* @param context
* @throws Exception
*/
@@ -86,7 +86,7 @@
/**
* Returns the shared instance.
- *
+ *
* @return the TaePlugin
*/
public static CasEditorPlugin getDefault() {
@@ -95,7 +95,7 @@
/**
* Returns the string from the plugin's resource bundle, or 'key' if not found.
- *
+ *
* @param key
* @return resource string
*/
@@ -111,7 +111,7 @@
/**
* Returns the plugin's resource bundle.
- *
+ *
* @return the ResourceBbundle or null if missing
*/
public ResourceBundle getResourceBundle() {
@@ -127,8 +127,8 @@
}
/**
- * Retrives the nlp model.
- *
+ * Retrieves the nlp model.
+ *
* @return the nlp model
*/
public static NlpModel getNlpModel() {
@@ -143,26 +143,26 @@
return sNLPModel;
}
-
+
/**
* Log the throwable.
- *
+ *
* @param t
*/
public static void log(Throwable t) {
getDefault().getLog().log(new Status(IStatus.ERROR, ID, IStatus.OK, t.getMessage(), t));
}
-
+
/**
- * Retrives an image.
- *
+ * 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());
}
-
+
/**
* Destroy the nlp model, only for testing.
*/
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/core/uima/AnnotatorConfiguration.java Mon Sep 3 02:23:22 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
@@ -23,8 +23,6 @@
import org.apache.uima.UIMAFramework;
import org.apache.uima.analysis_engine.AnalysisEngine;
-import org.apache.uima.analysis_engine.AnalysisEngineDescription;
-import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
import org.apache.uima.caseditor.core.TaeError;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceManager;
@@ -42,7 +40,7 @@
/**
* Initializes the instance.
- *
+ *
* @param descriptor
*/
public AnnotatorConfiguration(ResourceSpecifier descriptor) {
@@ -51,7 +49,7 @@
/**
* Only text analysis engines are supported.
- *
+ *
* @return the text analysis engine
* @throws ResourceInitializationException
*/
@@ -72,7 +70,7 @@
/**
* Sets the base folder
- *
+ *
* @param baseFolder
*/
public void setBaseFolder(IFolder baseFolder) {
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=572266&r1=572265&r2=572266&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 Mon Sep 3 02:23:22 2007
@@ -28,8 +28,9 @@
import org.apache.uima.cas.LongArrayFS;
import org.apache.uima.cas.ShortArrayFS;
import org.apache.uima.caseditor.core.TaeError;
+import org.eclipse.core.runtime.IAdaptable;
-public class ArrayValue {
+public class ArrayValue implements IAdaptable {
private final FeatureStructure arrayFS;
@@ -84,41 +85,6 @@
}
}
-// public void set(Number value) {
-//
-// if (arrayFS instanceof ByteArrayFS) {
-// ByteArrayFS array = (ByteArrayFS) arrayFS;
-// array.set(slot, (Byte) value);
-// }
-// else if (arrayFS instanceof ShortArrayFS) {
-// ShortArrayFS array = (ShortArrayFS) arrayFS;
-// array.set(slot, (Short) value);
-// }
-// else if (arrayFS instanceof IntArrayFS) {
-// IntArrayFS array = (IntArrayFS) arrayFS;
-// array.set(slot, (Integer) value);
-// }
-// else if (arrayFS instanceof LongArrayFS) {
-// LongArrayFS array = (LongArrayFS) arrayFS;
-// array.set(slot, (Long) value);
-// }
-// else if (arrayFS instanceof FloatArrayFS) {
-// FloatArrayFS array = (FloatArrayFS) arrayFS;
-// array.set(slot, (Float) value);
-// }
-// else if (arrayFS instanceof DoubleArrayFS) {
-// DoubleArrayFS array = (DoubleArrayFS) arrayFS;
-// array.set(slot, (Double) value);
-// }
-// else if (arrayFS instanceof ArrayFS) {
-// ArrayFS array = (ArrayFS) arrayFS;
-// array.set(slot, (FeatureStructure) value);
-// }
-// else {
-// throw new TaeError("Unkown array type!");
-// }
-// }
-
public Object get() {
if (arrayFS instanceof ByteArrayFS) {
ByteArrayFS array = (ByteArrayFS) arrayFS;
@@ -151,6 +117,19 @@
else {
throw new TaeError("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());
+ }
+ }
+
+ return null;
}
@Override
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/FeatureStructureSelectionProvider.java Mon Sep 3 02:23:22 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
@@ -26,7 +26,7 @@
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.caseditor.core.IDocument;
-import org.eclipse.jface.util.Assert;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
@@ -46,7 +46,7 @@
/**
* Adds an {@link ISelectionChangedListener} to this provider.
- *
+ *
* @param listener
*/
public void addSelectionChangedListener(ISelectionChangedListener listener) {
@@ -56,8 +56,8 @@
}
/**
- * Retrives the current selection.
- *
+ * Retrieves the current selection.
+ *
* @return selection
*/
public ISelection getSelection() {
@@ -66,7 +66,7 @@
/**
* Removes a registered selection listener.
- *
+ *
* @param listener
* the listener to remove
*/
@@ -76,7 +76,7 @@
/**
* Sets the current selection.
- *
+ *
* @param selection
*/
public void setSelection(ISelection selection) {
@@ -95,7 +95,7 @@
/**
* Sets the current selection to the given {@link AnnotationFS} object.
- *
+ *
* @param annotation
*/
public void setSelection(IDocument document, AnnotationFS annotation) {
@@ -111,15 +111,15 @@
}
/**
- * Replaces the current selection with an emtpy selection.
+ * Replaces the current selection with an empty selection.
*/
public void clearSelection() {
setSelection(new StructuredSelection());
}
/**
- * Replaces the current selection with an emtpy selectionw without notifiying listeners about it.
- *
+ * 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.
*/
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/CreateFeatureStructureDialog.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/CreateFeatureStructureDialog.java?rev=572266&view=auto
==============================================================================
(empty)
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditView.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditView.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditView.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditView.java Mon Sep 3 02:23:22 2007
@@ -46,7 +46,7 @@
if ((part instanceof AnnotationEditor)) {
AnnotationEditor editor = (AnnotationEditor) part;
- EditViewPage page = new EditViewPage(editor);
+ EditViewPage page = new EditViewPage(this, editor);
initPage(page);
page.createControl(getPageBook());
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditViewPage.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditViewPage.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditViewPage.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/EditViewPage.java Mon Sep 3 02:23:22 2007
@@ -20,9 +20,12 @@
package org.apache.uima.caseditor.editor.editview;
import java.util.Iterator;
+import java.util.List;
+import org.apache.uima.cas.ArrayFS;
import org.apache.uima.cas.ByteArrayFS;
import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CommonArrayFS;
import org.apache.uima.cas.DoubleArrayFS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
@@ -104,7 +107,20 @@
return value.getFeature().getRange().isPrimitive();
}
else if (element instanceof ArrayValue) {
- return true;
+
+ ArrayValue value = (ArrayValue) element;
+
+ FeatureStructure arrayFS = value.getFeatureStructure();
+
+ if (arrayFS instanceof ArrayFS) {
+ return false;
+ }
+ else if (arrayFS instanceof CommonArrayFS) {
+ return true;
+ }
+ else {
+ throw new TaeError("Unkown array type");
+ }
}
else {
throw new TaeError("Unkown element type!");
@@ -274,58 +290,92 @@
public void run() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
- FeatureValue featureValue = (FeatureValue) selection.getFirstElement();
+ if (selection.getFirstElement() instanceof FeatureValue) {
+ FeatureValue featureValue = (FeatureValue) selection.getFirstElement();
- FeatureStructure newValue;
+ FeatureStructure newValue;
- if (!featureValue.getFeature().getRange().isArray()) {
- newValue = document.getCAS().createFS(featureValue.getFeature().getRange());
- document.addFeatureStructure(newValue);
- }
- else {
- CreateArrayDialog createArrayDialog = new CreateArrayDialog(
- Display.getCurrent().getActiveShell());
+ Type fsSuperType = featureValue.getFeature().getRange();
- int returnCode = createArrayDialog.open();
+ if (!fsSuperType.isArray()) {
+ List subTypes =
+ document.getCAS().getTypeSystem().getProperlySubsumedTypes(fsSuperType);
- if (returnCode == IDialogConstants.OK_ID) {
- // get size from array dialog
- int arraySize = createArrayDialog.getArraySize();
-
- Type arrayType = featureValue.getFeature().getRange();
+ Type typeToCreate;
- if (arrayType.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) {
- newValue = document.getCAS().createByteArrayFS(arraySize);
- }
- else if (arrayType.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) {
- newValue = document.getCAS().createShortArrayFS(arraySize);
- }
- else if (arrayType.getName().equals(CAS.TYPE_NAME_INTEGER_ARRAY)) {
- newValue = document.getCAS().createIntArrayFS(arraySize);
- }
- else if (arrayType.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
- newValue = document.getCAS().createLongArrayFS(arraySize);
- }
- else if (arrayType.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
- newValue = document.getCAS().createFloatArrayFS(arraySize);
- }
- else if (arrayType.getName().equals(CAS.TYPE_NAME_DOUBLE_ARRAY)) {
- newValue = document.getCAS().createDoubleArrayFS(arraySize);
- }
- else if (arrayType.getName().equals(CAS.TYPE_NAME_FS_ARRAY)) {
- newValue = document.getCAS().createArrayFS(arraySize);
+ if (subTypes.size() == 0) {
+ typeToCreate = fsSuperType;
}
else {
- throw new TaeError("Unkown array type!");
+ CreateFeatureStructureDialog createFsDialog =
+ new CreateFeatureStructureDialog(Display.getCurrent()
+ .getActiveShell(), fsSuperType, document.getCAS().getTypeSystem());
+
+
+ int returnCode = createFsDialog.open();
+
+ if (returnCode == IDialogConstants.OK_ID) {
+ typeToCreate = createFsDialog.getType();
+ }
+ else {
+ return;
+ }
+ }
+
+ newValue = document.getCAS().createFS(typeToCreate);
+
+ document.addFeatureStructure(newValue);
+ } else {
+ Type arrayType = featureValue.getFeature().getRange();
+
+ CreateFeatureStructureDialog createArrayDialog = new CreateFeatureStructureDialog(Display.getCurrent()
+ .getActiveShell(), arrayType, document.getCAS().getTypeSystem());
+
+ int returnCode = createArrayDialog.open();
+
+ if (returnCode == IDialogConstants.OK_ID) {
+ // get size from array dialog
+ int arraySize = createArrayDialog.getArraySize();
+
+ FeatureStructure arrayFS;
+
+ if (arrayType.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) {
+ arrayFS = document.getCAS().createByteArrayFS(arraySize);
+ } else if (arrayType.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) {
+ arrayFS = document.getCAS().createShortArrayFS(arraySize);
+ } else if (arrayType.getName().equals(CAS.TYPE_NAME_INTEGER_ARRAY)) {
+ arrayFS = document.getCAS().createIntArrayFS(arraySize);
+ } else if (arrayType.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
+ arrayFS = document.getCAS().createLongArrayFS(arraySize);
+ } else if (arrayType.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
+ arrayFS = document.getCAS().createFloatArrayFS(arraySize);
+ } else if (arrayType.getName().equals(CAS.TYPE_NAME_DOUBLE_ARRAY)) {
+ arrayFS = document.getCAS().createDoubleArrayFS(arraySize);
+ } else if (arrayType.getName().equals(CAS.TYPE_NAME_FS_ARRAY)) {
+ arrayFS = document.getCAS().createArrayFS(arraySize);
+ } else {
+ throw new TaeError("Unkown array type!");
+ }
+
+ newValue = arrayFS;
+ } else {
+ return;
}
}
- else {
- return;
- }
+
+ featureValue.getFeatureStructure().setFeatureValue(featureValue.getFeature(), newValue);
+ document.update(featureValue.getFeatureStructure());
+ }
+ else if (selection.getFirstElement() instanceof ArrayValue) {
+ ArrayValue value = (ArrayValue) selection.getFirstElement();
+
+ ArrayFS array = document.getCAS().createArrayFS(2);
+
+ // create a fs of a given type
+
+ array.set(value.slot(), null);
}
- featureValue.getFeatureStructure().setFeatureValue(featureValue.getFeature(), newValue);
- document.update(featureValue.getFeatureStructure());
}
@Override
@@ -340,6 +390,17 @@
result = !featureValue.getFeature().getRange().isPrimitive() &&
featureValue.getFeatureStructure().getFeatureValue(featureValue.getFeature()) == null;
}
+ else if (selection.getFirstElement() instanceof ArrayValue) {
+ ArrayValue value = (ArrayValue) selection.getFirstElement();
+
+ if (value.getFeatureStructure() instanceof ArrayFS) {
+ ArrayFS array = (ArrayFS) value.getFeatureStructure();
+
+ if (array.get(value.slot()) == null) {
+ result = true;
+ }
+ }
+ }
}
return result;
@@ -358,7 +419,10 @@
private PinAction pinAction;
- EditViewPage(AnnotationEditor editor) {
+ private final EditView editView;
+
+ EditViewPage(EditView editView, AnnotationEditor editor) {
+ this.editView = editView;
document = editor.getDocument();
}
@@ -387,7 +451,14 @@
valueColumn.setEditingSupport(new ValueEditingSupport(viewer)
);
- viewer.setContentProvider(new FeatureStructureContentProvider(document));
+
+ FeatureStructureContentProvider contentProvider =
+ new FeatureStructureContentProvider(document);
+
+ viewer.setContentProvider(contentProvider);
+
+ viewer.setInput(null);
+ document.addChangeListener(contentProvider);
Transfer[] typesDropSupport = new Transfer[] { FeatureStructureTransfer.getInstance() };
@@ -551,20 +622,15 @@
if (fsSelection.size() == 1 && !pinAction.isChecked()) {
// filter out selection which are cause by this view itself
- if (viewer.getTree().getSelectionCount() == 1) {
- TreeItem item = viewer.getTree().getSelection()[0];
-
- if (item.getData() instanceof FeatureValue) {
- FeatureValue featureValue = (FeatureValue) item.getData();
-
- if (!featureValue.getFeature().getRange().isPrimitive()) {
- return; // do not update
- }
- }
+ if (editView != part) {
+ viewer.setInput(fsSelection.toList().get(0));
}
-
- viewer.setInput(fsSelection.toList().get(0));
}
}
+ }
+
+ @Override
+ public void dispose() {
+ getSite().getPage().removeSelectionListener(this);
}
}
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/FeatureStructureContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/FeatureStructureContentProvider.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/FeatureStructureContentProvider.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/FeatureStructureContentProvider.java Mon Sep 3 02:23:22 2007
@@ -24,6 +24,7 @@
import java.util.LinkedList;
import java.util.List;
+import org.apache.uima.cas.ArrayFS;
import org.apache.uima.cas.CommonArrayFS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
@@ -51,47 +52,63 @@
public Object[] getElements(Object inputElement) {
+
+
if (inputElement != null) {
+
FeatureStructure featureStructure = (FeatureStructure) inputElement;
Type type = featureStructure.getType();
- List featureTypes = type.getFeatures();
+ if (!type.isArray()) {
+ List featureTypes = type.getFeatures();
- Collection<FeatureValue> featureValues = new LinkedList<FeatureValue>();
+ Collection<FeatureValue> featureValues = new LinkedList<FeatureValue>();
- Iterator featuresItertor = featureTypes.iterator();
+ Iterator featuresItertor = featureTypes.iterator();
- while (featuresItertor.hasNext()) {
- Feature feature = (Feature) featuresItertor.next();
+ while (featuresItertor.hasNext()) {
+ Feature feature = (Feature) featuresItertor.next();
- featureValues.add(new FeatureValue(mDocument, featureStructure, feature));
+ featureValues.add(new FeatureValue(mDocument, featureStructure, feature));
+ }
+
+ return featureValues.toArray();
+ }
+ else {
+ int size;
+
+ if (featureStructure instanceof CommonArrayFS) {
+ CommonArrayFS array = (CommonArrayFS) featureStructure;
+ size = array.size();
+ } else if (featureStructure instanceof ArrayFS) {
+ ArrayFS array = (ArrayFS) featureStructure;
+ size = array.size();
+ } else {
+ throw new TaeError("Unkown array type!");
+ }
+
+ ArrayValue arrayValues[] = new ArrayValue[size];
+
+ for (int i = 0; i < size; i++) {
+ arrayValues[i] = new ArrayValue(featureStructure, i);
+ }
+
+ return arrayValues;
}
- return featureValues.toArray();
} else {
return new Object[0];
}
}
public void dispose() {
+ mDocument.removeChangeListener(this);
}
public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
-
this.viewer = viewer;
- if (oldInput != null) {
- mDocument.removeChangeListener(this);
- }
-
- if (newInput == null) {
- // this means empty input
- return;
- }
-
- mDocument.addChangeListener(this);
-
Display.getDefault().syncExec(new Runnable() {
public void run() {
viewer.refresh();
@@ -103,6 +120,7 @@
}
public void changed() {
+
// TODO: check if fs still exists
Display.getDefault().syncExec(new Runnable() {
@@ -114,7 +132,13 @@
}
public void removed(Collection<FeatureStructure> deletedFeatureStructure) {
- // TODO: set viewer to null if current fs was deleted
+ for(FeatureStructure fs : deletedFeatureStructure) {
+ if (viewer.getInput() == fs) {
+ viewer.setInput(null);
+ break;
+ }
+ }
+
}
public void updated(Collection<FeatureStructure> featureStructure) {
@@ -128,29 +152,26 @@
public Object[] getChildren(Object parentElement) {
- FeatureValue value = (FeatureValue) parentElement;
-
- if (!value.getFeature().getRange().isArray()) {
- FeatureStructure childStructure = (FeatureStructure) value.getValue();
- return getElements(childStructure);
- }
- else {
- FeatureStructure arrayFS = value.getFeatureStructure().getFeatureValue(value.getFeature());
+ if (parentElement instanceof FeatureValue) {
+ FeatureValue value = (FeatureValue) parentElement;
- CommonArrayFS array = (CommonArrayFS) arrayFS;
+ if (!value.getFeature().getRange().isArray()) {
+ FeatureStructure childStructure = (FeatureStructure) value.getValue();
+ return getElements(childStructure);
+ } else {
+ FeatureStructure arrayFS = value.getFeatureStructure().getFeatureValue(value.getFeature());
- // TODO: is is a bug in eclipse ??
- if (arrayFS == null) {
- return new Object[0];
+ return getElements(arrayFS);
}
+ } else if (parentElement instanceof ArrayValue) {
+ ArrayValue value = (ArrayValue) parentElement;
- ArrayValue arrayValues[] = new ArrayValue[array.size()];
+ ArrayFS array = (ArrayFS) value.getFeatureStructure();
- for (int i = 0; i < array.size(); i++) {
- arrayValues[i] = new ArrayValue(arrayFS, i);
- }
-
- return arrayValues;
+ return getElements(array.get(value.slot()));
+ }
+ else {
+ throw new TaeError("Unexpected element type!");
}
}
@@ -170,7 +191,24 @@
return value.getValue() != null;
}
} else if (element instanceof ArrayValue) {
- return false;
+
+ ArrayValue value = (ArrayValue) element;
+
+ if (value.getFeatureStructure() instanceof ArrayFS) {
+
+ ArrayFS array = (ArrayFS) value.getFeatureStructure();
+
+ if (array.get(value.slot()) != null) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ else {
+ // false for primitive arrays
+ return false;
+ }
}
else {
throw new TaeError("Unkown element type");
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/ValueColumnLabelProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/ValueColumnLabelProvider.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/ValueColumnLabelProvider.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/ValueColumnLabelProvider.java Mon Sep 3 02:23:22 2007
@@ -19,6 +19,9 @@
package org.apache.uima.caseditor.editor.editview;
+import org.apache.uima.cas.ArrayFS;
+import org.apache.uima.cas.CommonArrayFS;
+import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.caseditor.core.TaeError;
import org.apache.uima.caseditor.editor.ArrayValue;
import org.apache.uima.caseditor.editor.FeatureValue;
@@ -39,18 +42,38 @@
featureValue.getFeature()));
}
else {
+ FeatureStructure value = (FeatureStructure) featureValue.getValue();
- if (featureValue.getValue() == null) {
+ if (value == null) {
cell.setText("null");
} else {
- cell.setText("");
+ cell.setText("[" + value.getType().getShortName() + "]");
}
}
}
else if (element instanceof ArrayValue) {
+
ArrayValue value = (ArrayValue) element;
- cell.setText(value.get().toString());
+ // if primitive array
+ if (value.getFeatureStructure() instanceof CommonArrayFS) {
+ cell.setText(value.get().toString());
+ }
+ else if (value.getFeatureStructure() instanceof ArrayFS) {
+ ArrayFS array = (ArrayFS) value.getFeatureStructure();
+
+ FeatureStructure fs = array.get(value.slot());
+
+ if (fs == null) {
+ cell.setText("null");
+ }
+ else {
+ cell.setText("");
+ }
+ }
+ else {
+ throw new TaeError("Unexpected array type!");
+ }
}
else {
throw new TaeError("Unkown element!");
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/validator/CellEditorValidatorFacotory.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/validator/CellEditorValidatorFacotory.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/validator/CellEditorValidatorFacotory.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/validator/CellEditorValidatorFacotory.java Mon Sep 3 02:23:22 2007
@@ -39,7 +39,7 @@
}
private CellEditorValidatorFacotory() {
- // must not be instanciated
+ // must not be instantiated
}
/**
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/FeatureStructureBrowserViewPage.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/FeatureStructureBrowserViewPage.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/FeatureStructureBrowserViewPage.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/FeatureStructureBrowserViewPage.java Mon Sep 3 02:23:22 2007
@@ -20,16 +20,17 @@
package org.apache.uima.caseditor.editor.fsview;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;
import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.FSIndex;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.caseditor.CasEditorPlugin;
import org.apache.uima.caseditor.Images;
@@ -84,13 +85,10 @@
return new Object[] {};
}
- FSIndex index = mCAS.getIndexRepository().getIndex("TOPIndex");
-
- assert index != null : "Unable to retrive the TOPIndex!";
-
StrictTypeConstraint typeConstrain = new StrictTypeConstraint(mCurrentType);
- FSIterator strictTypeIterator = mCAS.createFilteredIterator(index.iterator(), typeConstrain);
+ FSIterator strictTypeIterator = mCAS.createFilteredIterator(
+ mCAS.getIndexRepository().getAllIndexedFS(mCurrentType), typeConstrain);
LinkedList<ModelFeatureStructure> featureStrucutreList = new LinkedList<ModelFeatureStructure>();
@@ -353,6 +351,8 @@
private Action mSelectAllAction;
+ private Collection<Type> filterTypes;
+
/**
* Initializes a new instance.
*
@@ -366,9 +366,44 @@
mSelectAllAction = new SelectAllAction();
- // TODO:
- // add here a change listener, for add and remove operations
- // the view must maybe updated
+ TypeSystem ts = mCAS.getTypeSystem();
+
+ filterTypes = new HashSet<Type>();
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_ARRAY_BASE));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_BOOLEAN_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_BYTE_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_LONG_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_SHORT_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_FLOAT_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_DOUBLE_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_BYTE));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_ANNOTATION_BASE));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_SHORT));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_LONG));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_FLOAT));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_DOUBLE));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_BOOLEAN));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_EMPTY_FLOAT_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_EMPTY_FS_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_EMPTY_STRING_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_FLOAT));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_FLOAT_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_FLOAT_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_FS_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_FS_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_INTEGER));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_INTEGER_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_INTEGER_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_LIST_BASE));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_NON_EMPTY_FLOAT_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_SOFA));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_STRING));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_STRING_ARRAY));
+ filterTypes.add(ts.getType(CAS.TYPE_NAME_STRING_LIST));
}
@Override
@@ -381,7 +416,8 @@
mInstanceComposite.setLayout(layout);
- TypeSelectionPane mTypePane = new TypeSelectionPane(mInstanceComposite, mCAS.getTypeSystem());
+ TypeSelectionPane mTypePane = new TypeSelectionPane(mInstanceComposite,
+ mCAS.getTypeSystem().getType(CAS.TYPE_NAME_TOP),mCAS.getTypeSystem(), filterTypes);
GridData typePaneData = new GridData();
typePaneData.grabExcessHorizontalSpace = true;
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/ITypePaneListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/ITypePaneListener.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/ITypePaneListener.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/ITypePaneListener.java Mon Sep 3 02:23:22 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
@@ -24,10 +24,10 @@
/**
* Notifies clients about type changes.
*/
-interface ITypePaneListener {
+public interface ITypePaneListener {
/**
* Called after the type was changed.
- *
+ *
* @param newType
*/
void typeChanged(Type newType);
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/TypeSelectionPane.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/TypeSelectionPane.java?rev=572266&r1=572265&r2=572266&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/TypeSelectionPane.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/fsview/TypeSelectionPane.java Mon Sep 3 02:23:22 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,10 +19,10 @@
package org.apache.uima.caseditor.editor.fsview;
+import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
-import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
import org.eclipse.swt.SWT;
@@ -35,25 +35,12 @@
import org.eclipse.swt.widgets.Label;
/**
- * The <code>TypeSelctionPane</code> notfies a listener about the selected type. Types are
- * retrived formt he type system.
- *
+ * The <code>TypeSelctionPane</code> notifies a listener about the selected type. Types are
+ * retrieved format the type system.
+ *
* TODO: Should be a types set to default ?
*/
-final class TypeSelectionPane extends Composite {
- private static String[] filterTypes = new String[] { CAS.TYPE_NAME_ARRAY_BASE,
- CAS.TYPE_NAME_BOOLEAN_ARRAY, CAS.TYPE_NAME_BYTE_ARRAY, CAS.TYPE_NAME_SHORT_ARRAY,
- CAS.TYPE_NAME_LONG_ARRAY, CAS.TYPE_NAME_FLOAT_ARRAY, CAS.TYPE_NAME_DOUBLE_ARRAY,
- CAS.TYPE_NAME_BYTE, CAS.TYPE_NAME_ANNOTATION_BASE, CAS.TYPE_NAME_SHORT, CAS.TYPE_NAME_LONG,
- CAS.TYPE_NAME_FLOAT, CAS.TYPE_NAME_DOUBLE, CAS.TYPE_NAME_BOOLEAN,
- CAS.TYPE_NAME_EMPTY_FLOAT_LIST, CAS.TYPE_NAME_EMPTY_FS_LIST,
- CAS.TYPE_NAME_EMPTY_INTEGER_LIST, CAS.TYPE_NAME_EMPTY_STRING_LIST, CAS.TYPE_NAME_FLOAT,
- CAS.TYPE_NAME_FLOAT_ARRAY, CAS.TYPE_NAME_FLOAT_LIST, CAS.TYPE_NAME_FS_ARRAY,
- CAS.TYPE_NAME_FS_LIST, CAS.TYPE_NAME_INTEGER, CAS.TYPE_NAME_INTEGER_ARRAY,
- CAS.TYPE_NAME_INTEGER_LIST, CAS.TYPE_NAME_LIST_BASE, CAS.TYPE_NAME_NON_EMPTY_FLOAT_LIST,
- CAS.TYPE_NAME_NON_EMPTY_FS_LIST, CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST,
- CAS.TYPE_NAME_NON_EMPTY_STRING_LIST, CAS.TYPE_NAME_SOFA, CAS.TYPE_NAME_STRING,
- CAS.TYPE_NAME_STRING_ARRAY, CAS.TYPE_NAME_STRING_LIST, CAS.TYPE_NAME_TOP };
+public final class TypeSelectionPane extends Composite {
private ITypePaneListener mListener;
@@ -61,7 +48,12 @@
private Combo mTypeCombo;
- TypeSelectionPane(Composite parent, TypeSystem typeSystem) {
+ public TypeSelectionPane(Composite parent, Type superType, TypeSystem typeSystem) {
+ this(parent, superType, typeSystem, new LinkedList<Type>());
+ }
+
+ public TypeSelectionPane(Composite parent, Type superType, TypeSystem typeSystem,
+ Collection<Type> filterTypes) {
super(parent, SWT.NONE);
mTypeSystem = typeSystem;
@@ -80,12 +72,12 @@
// insert list box
- mTypeCombo = new Combo(this, SWT.NONE);
+ mTypeCombo = new Combo(this, SWT.READ_ONLY);
mTypeCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Type newType = mTypeSystem.getType(mTypeCombo.getText());
- if (newType != null) {
+ if (mListener != null && newType != null) {
mListener.typeChanged(newType);
}
}
@@ -98,30 +90,30 @@
LinkedList<String> typeNameList = new LinkedList<String>();
+ typeNameList.add(superType.getName());
+
// get a collection of all types
- Iterator typeIterator = mTypeSystem.getTypeIterator();
+ Iterator typeIterator = mTypeSystem.getProperlySubsumedTypes(superType).iterator();
while (typeIterator.hasNext()) {
Type type = (Type) typeIterator.next();
- boolean isFilteredType = false;
-
- // TODO: use a collection here and call contains ...
- for (String filteredType : filterTypes) {
- if (type.getName().equals(filteredType)) {
- isFilteredType = true;
- }
- }
-
- if (!isFilteredType) {
+ if (!filterTypes.contains(type)) {
typeNameList.add(type.getName());
}
}
mTypeCombo.setItems(typeNameList.toArray(new String[typeNameList.size()]));
+
+ // select the super type, its the first element (and must be there)
+ mTypeCombo.select(0);
}
- void setListener(ITypePaneListener listener) {
+ public void setListener(ITypePaneListener listener) {
mListener = listener;
+ }
+
+ public Type getType() {
+ return mTypeSystem.getType(mTypeCombo.getText());
}
}