You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/06/28 17:51:39 UTC
svn commit: r1497821 [1/2] - in /uima/sandbox/ruta/trunk/ruta-ep-addons: ./
icons/ src/main/java/org/apache/uima/ruta/check/
Author: pkluegl
Date: Fri Jun 28 15:51:38 2013
New Revision: 1497821
URL: http://svn.apache.org/r1497821
Log:
UIMA-3029
- added view for controlling cas editor instances and for accepting/rejecting annotations, which can bes stored in a separate folder. Current step in processing is stored concerning documents and types, not annotations.
- added dependency to snapshot version of cas editor for setting the annotation mode
Added:
uima/sandbox/ruta/trunk/ruta-ep-addons/icons/help.png (with props)
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AcceptHandler.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckContentProvider.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckLabelProvider.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckRootNode.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNode.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNodeComparator.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckView.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotation.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationDocumentListener.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationUtils.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocument.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentsContentHandler.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckElement.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/IAnnotationCheckTreeNode.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/RejectHandler.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SaveHandler.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesDialog.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesHandler.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SetAnnotationModeContributionFactory.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SetAnnotationModeHandler.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/UpdateTaskHandler.java
uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/XMLUtils.java
Modified:
uima/sandbox/ruta/trunk/ruta-ep-addons/plugin.xml
uima/sandbox/ruta/trunk/ruta-ep-addons/pom.xml
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/icons/help.png
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/icons/help.png?rev=1497821&view=auto
==============================================================================
Binary file - no diff available.
Propchange: uima/sandbox/ruta/trunk/ruta-ep-addons/icons/help.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: uima/sandbox/ruta/trunk/ruta-ep-addons/plugin.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/plugin.xml?rev=1497821&r1=1497820&r2=1497821&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/plugin.xml (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/plugin.xml Fri Jun 28 15:51:38 2013
@@ -722,5 +722,137 @@ under the License.
id="org.apache.uima.ruta.cde.preferences"
name="CDE">
</page>
+ </extension>
+ <extension
+ point="org.eclipse.ui.views">
+ <view
+ category="org.apache.uima.ruta.ide.ui"
+ class="org.apache.uima.ruta.check.AnnotationCheckView"
+ icon="icons/views.png"
+ id="org.apache.uima.ruta.check"
+ name="Check Annotations"
+ restorable="true">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="org.apache.uima.ruta.check.UpdateTaskHandler"
+ id="org.apache.uima.ruta.check.update"
+ name="Update">
+ </command>
+ <command
+ defaultHandler="org.apache.uima.ruta.check.SelectTypesHandler"
+ id="org.apache.uima.ruta.check.selectTypes"
+ name="Select types">
+ </command>
+ <command
+ defaultHandler="org.apache.uima.ruta.check.AcceptHandler"
+ id="org.apache.uima.ruta.check.accept"
+ name="Accept">
+ </command>
+ <command
+ defaultHandler="org.apache.uima.ruta.check.RejectHandler"
+ id="org.apache.uima.ruta.check.reject"
+ name="Reject">
+ </command>
+ <command
+ defaultHandler="org.apache.uima.ruta.check.SaveHandler"
+ id="org.apache.uima.ruta.check.save"
+ name="Save">
+ </command>
+ <command
+ defaultHandler="org.apache.uima.ruta.check.SetAnnotationModeHandler"
+ id="org.apache.uima.ruta.check.mode"
+ name="Mode">
+ <commandParameter
+ id="org.apache.uima.ruta.check.mode.type"
+ name="type"
+ optional="false">
+ </commandParameter>
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.apache.uima.ruta.check">
+ <command
+ commandId="org.apache.uima.ruta.check.update"
+ icon="icons/arrow_refresh_small.png"
+ id="org.apache.uima.ruta.check.toolbar.update"
+ label="Update"
+ style="push"
+ tooltip="Update">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.apache.uima.ruta.check">
+ <command
+ commandId="org.apache.uima.ruta.check.selectTypes"
+ icon="icons/ruta_obj.png"
+ id="org.apache.uima.ruta.check.toolbar.selectTypes"
+ label="Select types"
+ style="push"
+ tooltip="Select types">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.apache.uima.ruta.check">
+ <command
+ commandId="org.apache.uima.ruta.check.accept"
+ icon="icons/accept.png"
+ id="org.apache.uima.ruta.check.toolbar.accept"
+ label="Accept"
+ style="push"
+ tooltip="Accept">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.apache.uima.ruta.check">
+ <command
+ commandId="org.apache.uima.ruta.check.reject"
+ icon="icons/delete.png"
+ id="org.apache.uima.ruta.check.toolbar.reject"
+ label="Reject"
+ style="push"
+ tooltip="Reject">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.apache.uima.ruta.check">
+ <command
+ commandId="org.apache.uima.ruta.check.save"
+ icon="icons/disk.png"
+ id="org.apache.uima.ruta.check.toolbar.save"
+ label="Save"
+ style="push"
+ tooltip="Save">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.apache.uima.ruta.check">
+ <command
+ commandId="org.apache.uima.ruta.check.mode"
+ icon="icons/font_add.png"
+ id="org.apache.uima.ruta.check.toolbar.mode"
+ mode="FORCE_TEXT"
+ style="pulldown"
+ tooltip="Set Annotation mode">
+ <parameter
+ name="org.apache.uima.ruta.check.mode.type">
+ </parameter>
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ class="org.apache.uima.ruta.check.SetAnnotationModeContributionFactory"
+ locationURI="menu:org.apache.uima.ruta.check.toolbar.mode">
+ </menuContribution>
</extension>
</plugin>
Modified: uima/sandbox/ruta/trunk/ruta-ep-addons/pom.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/pom.xml?rev=1497821&r1=1497820&r2=1497821&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/pom.xml (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/pom.xml Fri Jun 28 15:51:38 2013
@@ -47,7 +47,12 @@
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-ep-cas-editor-ide</artifactId>
- <version>${uimaVersion}</version>
+ <version>2.4.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-ep-cas-editor</artifactId>
+ <version>2.4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
@@ -235,9 +240,9 @@
org.eclipse.ui.editors,
org.eclipse.dltk.launching;bundle-version="[3.0.0,5.0.0)",
org.eclipse.debug.ui;bundle-version="3.5.0",
- org.apache.uima.caseditor;bundle-version="2.4.0",
+ org.apache.uima.caseditor;bundle-version="2.4.1.SNAPSHOT",
org.apache.uima.ruta.caseditor;bundle-version="1.0.0",
- org.apache.uima.caseditor.ide;bundle-version="2.4.0",
+ org.apache.uima.caseditor.ide;bundle-version="2.4.1.SNAPSHOT",
org.junit4;bundle-version="4.5.0";resolution:=optional
</Require-Bundle>
<Import-Package>
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AcceptHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AcceptHandler.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AcceptHandler.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AcceptHandler.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.ruta.check;
+
+import org.apache.uima.ruta.addons.RutaAddonsPlugin;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class AcceptHandler implements IHandler {
+
+ public void addHandlerListener(IHandlerListener arg0) {
+
+ }
+
+ public void dispose() {
+
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ AnnotationCheckView acView;
+ try {
+ acView = (AnnotationCheckView) HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().showView(AnnotationCheckView.ID);
+ AnnotationCheckComposite composite = (AnnotationCheckComposite) acView.getComposite();
+ composite.accept();
+ } catch (Exception e) {
+ RutaAddonsPlugin.error(e);
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener arg0) {
+
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,620 @@
+/*
+ * 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.ruta.check;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.XmiCasDeserializer;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.addons.RutaAddonsPlugin;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.DropTargetAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.ViewPart;
+import org.xml.sax.SAXException;
+
+public class AnnotationCheckComposite extends Composite implements ISelectionChangedListener,
+ ISelectionListener {
+
+ private CheckAnnotationDocumentListener annotationListener;
+
+ private AnnotationCheckTreeNodeComparator comparator = new AnnotationCheckTreeNodeComparator();
+
+ private AnnotationCheckLabelProvider lableProvider;
+
+ private TreeViewer treeView;
+
+ private Text documentSource;
+
+ private ViewPart viewPart;
+
+ private Text typeSystem;
+
+ private HashMap<String, Image> images;
+
+ private Text documentSink;
+
+ private List<String> selectedTypes;
+
+ private CheckDocument currentDocument = null;
+
+ private String annotationMode;
+
+ private AnnotationEditor casEditor;
+
+ private List<CheckDocument> oldDocs;
+
+ public AnnotationCheckComposite(Composite parent, int style, ViewPart viewPart) {
+ super(parent, style);
+ this.viewPart = viewPart;
+ selectedTypes = new ArrayList<String>();
+ initGui();
+ annotationListener = new CheckAnnotationDocumentListener(this);
+ }
+
+ private void initGui() {
+ this.setLayout(new FormLayout());
+ this.setSize(400, 800);
+
+ documentSource = new Text(this, SWT.SINGLE | SWT.BORDER);
+ FormData fdata1 = new FormData();
+ fdata1.width = 200;
+ fdata1.left = new FormAttachment(0, 1000, 5);
+ fdata1.top = new FormAttachment(0, 1000, 5);
+ fdata1.right = new FormAttachment(1000, 1000, -5);
+ documentSource.setLayoutData(fdata1);
+ documentSource.setToolTipText("Document source folder...");
+ documentSource.setMessage("Document source folder...");
+ DropTarget dt = new DropTarget(documentSource, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ dt.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ dt.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0) {
+ String fileString = fileList[0];
+ documentSource.setText(fileString);
+ }
+ }
+ });
+
+ documentSink = new Text(this, SWT.SINGLE | SWT.BORDER);
+ FormData fdatag = new FormData();
+ fdatag.width = 200;
+ fdatag.left = new FormAttachment(0, 1000, 5);
+ fdatag.top = new FormAttachment(0, 1000, 30);
+ fdatag.right = new FormAttachment(1000, 1000, -5);
+ documentSink.setLayoutData(fdatag);
+ documentSink.setToolTipText("Document gold output folder...");
+ documentSink.setMessage("Document gold output folder...");
+ DropTarget dtg = new DropTarget(documentSink, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ dtg.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ dtg.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0) {
+ String fileString = fileList[0];
+ documentSink.setText(fileString);
+ }
+ }
+ });
+
+ typeSystem = new Text(this, SWT.SINGLE | SWT.BORDER);
+ FormData fdata2 = new FormData();
+ fdata2.width = 200;
+ fdata2.left = new FormAttachment(0, 1000, 5);
+ fdata2.top = new FormAttachment(0, 1000, 55);
+ fdata2.right = new FormAttachment(1000, 1000, -5);
+ typeSystem.setLayoutData(fdata2);
+ typeSystem.setToolTipText("Type System...");
+ typeSystem.setMessage("Type System...");
+ DropTarget dt1 = new DropTarget(typeSystem, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ dt1.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ dt1.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0) {
+ String fileString = fileList[0];
+ typeSystem.setText(fileString);
+ }
+ }
+ });
+
+ FormData fdata3 = new FormData();
+ fdata3.left = new FormAttachment(0, 1000, 3);
+ fdata3.top = new FormAttachment(0, 1000, 81);
+ fdata3.right = new FormAttachment(1000, 1000, -3);
+ fdata3.bottom = new FormAttachment(1000, 1000, -3);
+ Composite comp = new Composite(this, SWT.CENTER);
+ comp.setLayoutData(fdata3);
+ comp.setLayout(new FillLayout());
+ treeView = new TreeViewer(comp, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+
+ AnnotationCheckContentProvider provider = new AnnotationCheckContentProvider();
+ treeView.setContentProvider(provider);
+
+ treeView.getControl().addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ char c = e.character;
+ if (c == '1' || c == '2') {
+ if (c == '1') {
+ accept();
+ } else if (c == '2') {
+ reject();
+ }
+ }
+ }
+
+ });
+
+ lableProvider = new AnnotationCheckLabelProvider(this);
+ treeView.setLabelProvider(lableProvider);
+
+ viewPart.getSite().getPage().addSelectionListener(this);
+ viewPart.getSite().setSelectionProvider(treeView);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.part.Page#dispose()
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ viewPart.getSite().getPage().removeSelectionListener(this);
+ Collection<Image> values = images.values();
+ for (Image image : values) {
+ image.dispose();
+ }
+ }
+
+ public Image getImage(String name) {
+ if (images == null) {
+ initImages();
+ }
+ return images.get(name);
+ }
+
+ private void initImages() {
+ images = new HashMap<String, Image>();
+ ImageDescriptor desc;
+ Image image;
+ String name;
+
+ desc = RutaAddonsPlugin.getImageDescriptor("/icons/accept.png");
+ image = desc.createImage();
+ name = "accept";
+ images.put(name, image);
+
+ desc = RutaAddonsPlugin.getImageDescriptor("/icons/delete.png");
+ image = desc.createImage();
+ name = "delete";
+ images.put(name, image);
+
+ desc = RutaAddonsPlugin.getImageDescriptor("/icons/help.png");
+ image = desc.createImage();
+ name = "help";
+ images.put(name, image);
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if (part instanceof AnnotationCheckView) {
+ if (selection instanceof TreeSelection) {
+ TreeSelection ts = (TreeSelection) selection;
+ if (ts.getFirstElement() instanceof AnnotationCheckTreeNode) {
+ AnnotationCheckTreeNode firstElement = (AnnotationCheckTreeNode) ts.getFirstElement();
+ CheckElement element = firstElement.getElement();
+ int begin = 0;
+ int end = 0;
+ CheckDocument newDoc = null;
+ if (element instanceof CheckAnnotation) {
+ begin = ((CheckAnnotation) element).begin;
+ end = ((CheckAnnotation) element).end;
+ newDoc = ((CheckDocument) firstElement.getParent().getElement());
+ } else if (element instanceof CheckDocument) {
+ newDoc = ((CheckDocument) element);
+ }
+ if (casEditor != null && casEditor.getDocument() != null) {
+ IFile file = ((FileEditorInput) casEditor.getEditorInput()).getFile();
+ if (!newDoc.source.equals(file.getLocation().toOSString())) {
+ casEditor.getDocument().removeChangeListener(annotationListener);
+ casEditor = CheckAnnotationUtils.openInCasEditor(new File(newDoc.source), begin, end);
+ casEditor.getDocument().addChangeListener(annotationListener);
+ } else {
+ casEditor.selectAndReveal(begin, end - begin);
+ }
+ } else {
+ casEditor = CheckAnnotationUtils.openInCasEditor(new File(newDoc.source), begin, end);
+ casEditor.getDocument().addChangeListener(annotationListener);
+ }
+ setAnnotationMode(annotationMode);
+ Iterator<Type> typeIterator = casEditor.getDocument().getCAS().getTypeSystem()
+ .getTypeIterator();
+ while (typeIterator.hasNext()) {
+ Type type = (Type) typeIterator.next();
+ boolean contains = selectedTypes.contains(type.getName());
+ casEditor.setShownAnnotationType(type, contains);
+ }
+ currentDocument = newDoc;
+ treeView.getControl().setFocus();
+ }
+ }
+ }
+ }
+
+ public void selectionChanged(SelectionChangedEvent arg0) {
+ }
+
+ public void restoreState(IMemento memento) {
+ if (memento == null)
+ return;
+
+ IMemento dir = memento.getChild("documentSource");
+ if (dir != null) {
+ String id = dir.getID();
+ documentSource.setText(id);
+ }
+
+ IMemento dir2 = memento.getChild("documentSink");
+ if (dir2 != null) {
+ String id = dir2.getID();
+ documentSink.setText(id);
+ }
+
+ IMemento tsName = memento.getChild("typeSystem");
+ if (tsName != null) {
+ String id = tsName.getID();
+ typeSystem.setText(id);
+ }
+
+ for (IMemento eachMemento : memento.getChildren("selectedTypes")) {
+ IMemento child = eachMemento.getChild("type");
+ if (child != null) {
+ selectedTypes.add(child.getID());
+ }
+ }
+
+ }
+
+ public void saveState(IMemento memento) {
+ memento.createChild("documentSource", documentSource.getText());
+ memento.createChild("documentSink", documentSink.getText());
+ memento.createChild("typeSystem", typeSystem.getText());
+
+ for (String each : selectedTypes) {
+ IMemento currentMemento = memento.createChild("selectedTypes", "type");
+ currentMemento.createChild("type", each);
+ }
+
+ }
+
+ public TreeViewer getTreeViewer() {
+ return treeView;
+ }
+
+ public String getDocumentSource() {
+ return documentSource.getText();
+ }
+
+ public String getDocumentSink() {
+ return documentSink.getText();
+ }
+
+ public String getTypeSystem() {
+ return typeSystem.getText();
+ }
+
+ public List<String> getSelectedTypes() {
+ return selectedTypes;
+ }
+
+ public void setSelectedTypes(List<String> selection) {
+ this.selectedTypes = selection;
+ }
+
+ public void reject() {
+ TreeSelection selection = (TreeSelection) treeView.getSelection();
+ AnnotationCheckTreeNode firstElement = (AnnotationCheckTreeNode) selection.getFirstElement();
+ if (firstElement == null) {
+ return;
+ }
+ firstElement.getElement().checked = true;
+ firstElement.getElement().keep = false;
+ moveToNext();
+ treeView.refresh();
+ }
+
+ public void accept() {
+ TreeSelection selection = (TreeSelection) treeView.getSelection();
+ AnnotationCheckTreeNode firstElement = (AnnotationCheckTreeNode) selection.getFirstElement();
+ if (firstElement == null) {
+ return;
+ }
+ firstElement.getElement().checked = true;
+ firstElement.getElement().keep = true;
+ moveToNext();
+ treeView.refresh();
+ }
+
+ public void moveToNext() {
+ TreeSelection selection = (TreeSelection) treeView.getSelection();
+ AnnotationCheckTreeNode firstElement = (AnnotationCheckTreeNode) selection.getFirstElement();
+ if (firstElement == null) {
+ return;
+ }
+ IAnnotationCheckTreeNode parent = firstElement.getParent();
+ AnnotationCheckTreeNode[] children = parent.getChildren();
+ List<AnnotationCheckTreeNode> list = Arrays.asList(children);
+ int indexOf = list.indexOf(firstElement);
+ IAnnotationCheckTreeNode brother = null;
+ IAnnotationCheckTreeNode uncle = parent;
+ if (list == null || list.isEmpty()) {
+
+ } else if (indexOf == -1) {
+ brother = list.get(0);
+ } else if (firstElement.getElement() instanceof CheckDocument && indexOf < list.size() - 1) {
+ uncle = list.get(indexOf + 1);
+ if (uncle.getChildren().length > 0) {
+ brother = uncle.getChildren()[0];
+ }
+ } else if (indexOf < list.size() - 1) {
+ brother = list.get(indexOf + 1);
+ } else if (firstElement.getElement() instanceof CheckAnnotation) {
+ brother = null;
+ AnnotationCheckTreeNode[] children2 = parent.getParent().getChildren();
+ List<AnnotationCheckTreeNode> list2 = Arrays.asList(children2);
+ int indexOf2 = list2.indexOf(parent);
+ if (list2 == null || list2.isEmpty()) {
+
+ } else if (indexOf2 == -1) {
+ uncle = list2.get(0);
+ } else if (indexOf2 < list2.size() - 1) {
+ uncle = list2.get(indexOf2 + 1);
+ if (uncle.getChildren().length != 0) {
+ brother = uncle.getChildren()[0];
+ }
+ }
+ }
+ TreePath treePath = null;
+ if (brother == null) {
+ treePath = new TreePath(new Object[] { treeView.getInput(), uncle });
+ } else {
+ treePath = new TreePath(new Object[] { treeView.getInput(), uncle, brother });
+
+ }
+ final TreeSelection newSelection = new TreeSelection(treePath);
+ treeView.setSelection(newSelection, true);
+
+ if (firstElement.getElement() instanceof CheckAnnotation) {
+ boolean allChecked = true;
+ boolean oneKeep = false;
+ for (AnnotationCheckTreeNode each : list) {
+ CheckElement element = each.getElement();
+ allChecked &= element.checked;
+ oneKeep |= element.keep;
+ }
+ parent.getElement().checked = allChecked;
+ parent.getElement().keep = oneKeep;
+ }
+
+ }
+
+ public void save() {
+ AnnotationCheckTreeNode root = (AnnotationCheckTreeNode) treeView.getInput();
+ AnnotationCheckTreeNode[] children = root.getChildren();
+ List<CheckDocument> docs = new ArrayList<CheckDocument>(oldDocs);
+ TypeSystemDescription tsd = null;
+ try {
+ tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+ new XMLInputSource(typeSystem.getText()));
+ tsd.resolveImports();
+ } catch (InvalidXMLException e) {
+ RutaAddonsPlugin.error(e);
+ } catch (IOException e) {
+ RutaAddonsPlugin.error(e);
+ }
+ CAS cas = null;
+ try {
+ cas = CasCreationUtils.createCas(tsd, null, new FsIndexDescription[0]);
+ } catch (ResourceInitializationException e) {
+ RutaAddonsPlugin.error(e);
+ }
+
+ for (AnnotationCheckTreeNode each : children) {
+ CheckDocument cd = (CheckDocument) each.getElement();
+ if (cd.checked && cd.keep) {
+ cas.reset();
+ File oldFile = new File(cd.source);
+ File goldFile = new File(documentSink.getText(), oldFile.getName());
+ if (goldFile.exists()) {
+ try {
+ XmiCasDeserializer.deserialize(new FileInputStream(goldFile), cas, false);
+ } catch (FileNotFoundException e) {
+ RutaAddonsPlugin.error(e);
+ } catch (SAXException e) {
+ RutaAddonsPlugin.error(e);
+ } catch (IOException e) {
+ RutaAddonsPlugin.error(e);
+ }
+ } else {
+ try {
+ XmiCasDeserializer.deserialize(new FileInputStream(oldFile), cas, true);
+ } catch (FileNotFoundException e) {
+ RutaAddonsPlugin.error(e);
+ } catch (SAXException e) {
+ RutaAddonsPlugin.error(e);
+ } catch (IOException e) {
+ RutaAddonsPlugin.error(e);
+ }
+ String documentText = cas.getDocumentText();
+ cas.reset();
+ cas.setDocumentText(documentText);
+ }
+ AnnotationCheckTreeNode[] annotationNodes = each.getChildren();
+ for (AnnotationCheckTreeNode eachAN : annotationNodes) {
+ CheckAnnotation ca = (CheckAnnotation) eachAN.getElement();
+ if (ca.checked && ca.keep) {
+ Type type = cas.getTypeSystem().getType(ca.type);
+ if (type != null) {
+ AnnotationFS createAnnotation = cas.createAnnotation(type, ca.begin, ca.end);
+ cas.addFsToIndexes(createAnnotation);
+ }
+ }
+ }
+ try {
+ CheckAnnotationUtils.writeXmi(cas, goldFile);
+ } catch (Exception e) {
+ RutaAddonsPlugin.error(e);
+ }
+ cd.checkedTypes.addAll(selectedTypes);
+ if(!docs.contains(cd)) {
+ docs.add(cd);
+ }
+ }
+ File dataFile = new File(documentSink.getText(), "data.xml");
+ try {
+ XMLUtils.write(docs, dataFile);
+ } catch (IOException e) {
+ RutaAddonsPlugin.error(e);
+ }
+ }
+ }
+
+ public void setAnnotationMode(String typeString) {
+ this.annotationMode = typeString;
+ if (casEditor != null && casEditor.getDocument() != null && typeString != null) {
+ Type type = casEditor.getDocument().getCAS().getTypeSystem().getType(typeString);
+ casEditor.setAnnotationMode(type);
+ }
+ }
+
+ public void addedAnnotation(Collection<AnnotationFS> annotations) {
+ AnnotationCheckRootNode root = (AnnotationCheckRootNode) treeView.getInput();
+ AnnotationCheckTreeNode[] children = root.getChildren();
+ for (AnnotationCheckTreeNode docNode : children) {
+ if (docNode.getElement().equals(currentDocument)) {
+ List<AnnotationCheckTreeNode> annotationList = new ArrayList<AnnotationCheckTreeNode>(
+ Arrays.asList(docNode.getChildren()));
+ for (AnnotationFS eachAnnotation : annotations) {
+ CheckElement ac = new CheckAnnotation(eachAnnotation);
+ ac.checked = true;
+ ac.keep = true;
+ AnnotationCheckTreeNode anode = new AnnotationCheckTreeNode(docNode, ac);
+ annotationList.add(anode);
+ }
+ Collections.sort(annotationList, comparator);
+ docNode.setChildren(annotationList);
+ treeView.refresh(docNode);
+ break;
+ }
+ }
+ }
+
+ public void removedAnnotation(Collection<AnnotationFS> annotations) {
+ AnnotationCheckRootNode root = (AnnotationCheckRootNode) treeView.getInput();
+ AnnotationCheckTreeNode[] children = root.getChildren();
+ for (AnnotationCheckTreeNode docNode : children) {
+ if (docNode.getElement().equals(currentDocument)) {
+ AnnotationCheckTreeNode[] achildren = docNode.getChildren();
+ for (AnnotationCheckTreeNode anode : achildren) {
+ CheckAnnotation e = (CheckAnnotation) anode.getElement();
+ for (AnnotationFS eachAnnotation : annotations) {
+ if(eachAnnotation.getBegin() == e.begin && eachAnnotation.getEnd() == e.end && eachAnnotation.getType().getName().equals(e.type)) {
+ e.checked = true;
+ e.keep = false;
+ }
+ }
+ }
+ treeView.refresh(docNode);
+ break;
+ }
+ }
+ }
+
+ public void updatedAnnotation(Collection<AnnotationFS> annotations) {
+ }
+
+ public void setOldDocs(List<CheckDocument> docs) {
+ this.oldDocs = docs;
+
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckContentProvider.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckContentProvider.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckContentProvider.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckContentProvider.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,78 @@
+/*
+ * 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.ruta.check;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class AnnotationCheckContentProvider implements ITreeContentProvider {
+
+ public AnnotationCheckContentProvider() {
+ super();
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+
+ }
+
+ public Object[] getChildren(Object node) {
+ if (node instanceof IAnnotationCheckTreeNode) {
+ List<Object> result = new ArrayList<Object>();
+ IAnnotationCheckTreeNode n = (IAnnotationCheckTreeNode) node;
+ AnnotationCheckTreeNode[] children = n.getChildren();
+ for (AnnotationCheckTreeNode each : children) {
+ if (!(each instanceof AnnotationCheckRootNode)) {
+ result.add(each);
+ }
+ }
+ return result.toArray();
+ }
+ return null;
+ }
+
+ public Object[] getElements(Object node) {
+ return getChildren(node);
+ }
+
+ public Object getParent(Object node) {
+ if(node instanceof IAnnotationCheckTreeNode) {
+ IAnnotationCheckTreeNode n = (IAnnotationCheckTreeNode) node;
+ return n.getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object node) {
+ if(node instanceof IAnnotationCheckTreeNode) {
+ IAnnotationCheckTreeNode n = (IAnnotationCheckTreeNode) node;
+ return n.hasChildren();
+ }
+ return false;
+ }
+
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckLabelProvider.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckLabelProvider.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckLabelProvider.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckLabelProvider.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,82 @@
+/*
+ * 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.ruta.check;
+
+import java.io.File;
+
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+public class AnnotationCheckLabelProvider extends LabelProvider implements ILabelProvider {
+
+ private AnnotationCheckComposite composite;
+
+ public AnnotationCheckLabelProvider(AnnotationCheckComposite composite) {
+ this.composite = composite;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
+ */
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof IAnnotationCheckTreeNode) {
+ IAnnotationCheckTreeNode node = (IAnnotationCheckTreeNode) element;
+ CheckElement e = node.getElement();
+ if (!e.checked) {
+ return composite.getImage("help");
+ } else {
+ if (e.keep) {
+ return composite.getImage("accept");
+ } else {
+ return composite.getImage("delete");
+ }
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object element) {
+ if (element instanceof AnnotationCheckTreeNode) {
+ AnnotationCheckTreeNode node = (AnnotationCheckTreeNode) element;
+ CheckElement ce = node.getElement();
+ if (ce instanceof CheckAnnotation) {
+ CheckAnnotation ca = (CheckAnnotation) ce;
+ String normalizeSpace = StringUtils.normalizeSpace(ca.coveredText);
+ return "[" + ca.shortType + "]: " + normalizeSpace;
+ } else if (ce instanceof CheckDocument) {
+ CheckDocument cd = (CheckDocument) ce;
+ String name = new File(cd.source).getName();
+ return name;
+ }
+ }
+ return element.toString();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckRootNode.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckRootNode.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckRootNode.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckRootNode.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.ruta.check;
+
+
+public class AnnotationCheckRootNode extends AnnotationCheckTreeNode {
+
+ public AnnotationCheckRootNode() {
+ super(null, null);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNode.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNode.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNode.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNode.java Fri Jun 28 15:51:38 2013
@@ -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.ruta.check;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class AnnotationCheckTreeNode implements IAnnotationCheckTreeNode {
+
+ private List<AnnotationCheckTreeNode> children;
+
+ private IAnnotationCheckTreeNode parent;
+
+ private CheckElement element;
+
+ public AnnotationCheckTreeNode(IAnnotationCheckTreeNode parent, CheckElement element) {
+ super();
+ this.parent = parent;
+ this.children = new ArrayList<AnnotationCheckTreeNode>();
+ this.element = element;
+ }
+
+ public void addChild(AnnotationCheckTreeNode child) {
+ children.add(child);
+ }
+
+ public AnnotationCheckTreeNode[] getChildren() {
+ return children.toArray(new AnnotationCheckTreeNode[0]);
+ }
+
+ public Iterator<AnnotationCheckTreeNode> getChildrenIterator() {
+ return children.iterator();
+ }
+
+ public String getName() {
+ return "AbstractAnnotationCheckTreeNode";
+ }
+
+ public IAnnotationCheckTreeNode getParent() {
+ return parent;
+ }
+
+ public boolean hasChildren() {
+ return !children.isEmpty();
+ }
+
+ public CheckElement getElement() {
+ return element;
+ }
+
+ public void setChildren(List<AnnotationCheckTreeNode> annotationList) {
+ this.children = annotationList;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNodeComparator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNodeComparator.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNodeComparator.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckTreeNodeComparator.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,55 @@
+/*
+ * 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.ruta.check;
+
+import java.util.Comparator;
+
+public class AnnotationCheckTreeNodeComparator implements Comparator<AnnotationCheckTreeNode>{
+
+ public int compare(AnnotationCheckTreeNode o1, AnnotationCheckTreeNode o2) {
+ if(o1.getElement() instanceof CheckAnnotation && o1.getElement() instanceof CheckAnnotation) {
+ CheckAnnotation ca1 = (CheckAnnotation) o1.getElement();
+ CheckAnnotation ca2 = (CheckAnnotation) o2.getElement();
+ if (ca1.begin < ca2.begin) {
+ return -1;
+ } else if (ca1.begin > ca2.begin) {
+ return 1;
+ } else if (ca1.end > ca2.end) {
+ return -1;
+ } else if (ca1.end < ca2.end) {
+ return 1;
+ } else {
+ boolean equals = o1.equals(o2);
+ if (equals) {
+ return 0;
+ } else {
+ int compareTo = ca1.type.compareTo(ca2.type);
+ if (compareTo == 0) {
+ return 1;
+ } else {
+ return compareTo;
+ }
+ }
+ }
+ }
+ return 0;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckView.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckView.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckView.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckView.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,69 @@
+/*
+ * 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.ruta.check;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.ViewPart;
+
+public class AnnotationCheckView extends ViewPart {
+ public static final String ID = "org.apache.uima.ruta.check";
+
+
+ private AnnotationCheckComposite checkComp;
+
+ private IMemento memento;
+
+
+ public AnnotationCheckView() {
+ super();
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ checkComp = new AnnotationCheckComposite(parent, SWT.NULL, this);
+ if (memento != null) {
+ checkComp.restoreState(memento);
+ memento = null;
+ }
+ }
+
+ @Override
+ public void setFocus() {
+ this.checkComp.setFocus();
+ }
+
+ public AnnotationCheckComposite getComposite() {
+ return checkComp;
+ }
+
+ public void saveState(IMemento memento) {
+ checkComp.saveState(memento);
+ }
+
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
+ this.memento = memento;
+ super.init(site, memento);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotation.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotation.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotation.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotation.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.ruta.check;
+
+import org.apache.uima.cas.text.AnnotationFS;
+
+public class CheckAnnotation extends CheckElement{
+
+ public int begin;
+
+ public int end;
+
+ public String type;
+
+ public String coveredText;
+
+ public String shortType;
+
+ public CheckAnnotation(AnnotationFS afs) {
+ super();
+ this.begin = afs.getBegin();
+ this.end = afs.getEnd();
+ this.type = afs.getType().getName();
+ this.shortType = afs.getType().getShortName();
+ this.coveredText = afs.getCoveredText();
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationDocumentListener.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationDocumentListener.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationDocumentListener.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationDocumentListener.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.ruta.check;
+
+import java.util.Collection;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.editor.AbstractAnnotationDocumentListener;
+
+public class CheckAnnotationDocumentListener extends AbstractAnnotationDocumentListener {
+
+ private AnnotationCheckComposite composite;
+
+ public CheckAnnotationDocumentListener(AnnotationCheckComposite composite) {
+ super();
+ this.composite = composite;
+ }
+
+ @Override
+ protected void addedAnnotation(Collection<AnnotationFS> annotations) {
+ composite.addedAnnotation(annotations);
+ }
+
+ @Override
+ protected void removedAnnotation(Collection<AnnotationFS> annotations) {
+ composite.removedAnnotation(annotations);
+ }
+
+ @Override
+ protected void updatedAnnotation(Collection<AnnotationFS> annotations) {
+ composite.updatedAnnotation(annotations);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationUtils.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationUtils.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckAnnotationUtils.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,84 @@
+/*
+ * 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.ruta.check;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.ruta.addons.RutaAddonsPlugin;
+import org.apache.uima.util.XMLSerializer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+
+public class CheckAnnotationUtils {
+ public static AnnotationEditor openInCasEditor(File file, int begin, int end) {
+ if (file == null) {
+ return null;
+ }
+ String absolutePath = file.getAbsolutePath();
+ try {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IFile ifile = getIFile(absolutePath);
+ AnnotationEditor editor = (AnnotationEditor) page.openEditor(new FileEditorInput(ifile),
+ "org.apache.uima.caseditor.editor");
+ editor.selectAndReveal(begin, end - begin);
+ return editor;
+ } catch (PartInitException e) {
+ RutaAddonsPlugin.error(e);
+ }
+ return null;
+ }
+
+ public static IFile getIFile(String location) {
+ IPath s = Path.fromOSString(location);
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IFile ifile = workspace.getRoot().getFileForLocation(s);
+ return ifile;
+ }
+
+ public static void writeXmi(CAS aCas, File name) throws Exception {
+ FileOutputStream out = null;
+
+ try {
+ // write XMI
+ out = new FileOutputStream(name);
+ XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
+ XMLSerializer xmlSer = new XMLSerializer(out, false);
+ ser.serialize(aCas, xmlSer.getContentHandler());
+ } catch (Exception e) {
+ throw e;
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocument.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocument.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocument.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocument.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.check;
+
+import java.util.Collection;
+import java.util.TreeSet;
+
+public class CheckDocument extends CheckElement {
+
+ public String source;
+
+ public final Collection<String> checkedTypes = new TreeSet<String>();
+
+ public CheckDocument(String source) {
+ super();
+ this.source = source;
+ }
+
+ public String toXML() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<document source=\"");
+ sb.append(source);
+ sb.append("\" >");
+ sb.append("\n");
+ for (String each : checkedTypes) {
+ sb.append("<type>");
+ sb.append(each);
+ sb.append("</type>");
+ sb.append("\n");
+ }
+ sb.append("</document>");
+ sb.append("\n");
+ return sb.toString();
+ }
+
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentsContentHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentsContentHandler.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentsContentHandler.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentsContentHandler.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.ruta.check;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class CheckDocumentsContentHandler extends DefaultHandler {
+
+ private List<CheckDocument> checkDocuments = new ArrayList<CheckDocument>();
+
+
+ private CheckDocument current = null;
+
+ private String currentString;
+
+ public void startElement(String uri, String localName, String qName, Attributes attributes) {
+ if (localName.equals("document")) {
+ String source = attributes.getValue("source");
+ current = new CheckDocument(source);
+ }
+ }
+
+ public void characters(char[] ch, int start, int length) {
+ currentString = new String(ch, start, length);
+ }
+
+ public void endElement(String uri, String localName, String qName) {
+ if (localName.equals("document")) {
+ checkDocuments.add(current);
+ } else if (localName.equals("type")) {
+ current.checkedTypes.add(currentString);
+ }
+ }
+
+ public List<CheckDocument> getCheckDocuments() {
+ return checkDocuments;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckElement.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckElement.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckElement.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.ruta.check;
+
+
+public class CheckElement {
+
+ public boolean checked = false;
+
+ public boolean keep = true;
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/IAnnotationCheckTreeNode.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/IAnnotationCheckTreeNode.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/IAnnotationCheckTreeNode.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/IAnnotationCheckTreeNode.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.ruta.check;
+
+import java.util.Iterator;
+
+interface IAnnotationCheckTreeNode {
+
+ void addChild(AnnotationCheckTreeNode child);
+
+ AnnotationCheckTreeNode[] getChildren();
+
+ Iterator<AnnotationCheckTreeNode> getChildrenIterator();
+
+ String getName();
+
+ IAnnotationCheckTreeNode getParent();
+
+ boolean hasChildren();
+
+ CheckElement getElement();
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/RejectHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/RejectHandler.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/RejectHandler.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/RejectHandler.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.ruta.check;
+
+import org.apache.uima.ruta.addons.RutaAddonsPlugin;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class RejectHandler implements IHandler {
+
+ public void addHandlerListener(IHandlerListener arg0) {
+
+ }
+
+ public void dispose() {
+
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ AnnotationCheckView acView;
+ try {
+ acView = (AnnotationCheckView) HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().showView(AnnotationCheckView.ID);
+ AnnotationCheckComposite composite = (AnnotationCheckComposite) acView.getComposite();
+ composite.reject();
+ } catch (Exception e) {
+ RutaAddonsPlugin.error(e);
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener arg0) {
+
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SaveHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SaveHandler.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SaveHandler.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SaveHandler.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.ruta.check;
+
+import org.apache.uima.ruta.addons.RutaAddonsPlugin;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class SaveHandler implements IHandler {
+
+ public void addHandlerListener(IHandlerListener arg0) {
+
+ }
+
+ public void dispose() {
+
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ AnnotationCheckView acView;
+ try {
+ acView = (AnnotationCheckView) HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().showView(AnnotationCheckView.ID);
+ AnnotationCheckComposite composite = (AnnotationCheckComposite) acView.getComposite();
+ composite.save();
+ } catch (Exception e) {
+ RutaAddonsPlugin.error(e);
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener arg0) {
+
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesDialog.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesDialog.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesDialog.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesDialog.java Fri Jun 28 15:51:38 2013
@@ -0,0 +1,258 @@
+/*
+ * 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.ruta.check;
+
+import java.awt.Toolkit;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
+
+
+public class SelectTypesDialog extends Dialog implements Listener {
+
+ private Shell shell;
+
+ private Text typeNameUI;
+
+ private Table matchingTypesUI;
+
+ // private Table nameSpacesUI;
+
+ public String typeName = "error-TypeName-never-set";
+
+ private Button okButton;
+
+ private Button cancelButton;
+
+ private AnnotationCheckComposite owner;
+
+ private List<String> types;
+
+ private List<String> selectedTypes;
+
+
+ public SelectTypesDialog(Shell shell, List<String> types, boolean excluded, AnnotationCheckComposite owner) {
+ super(shell);
+ this.shell = shell;
+ this.types = types;
+ this.owner = owner;
+ this.selectedTypes = owner.getSelectedTypes();
+ createDialogArea();
+ init();
+ }
+
+ protected Control createDialogArea() {
+ Composite mainArea = (Composite) createDialogArea(shell);
+ createWideLabel(mainArea, " Type Name:");
+
+ typeNameUI = newText(mainArea, SWT.SINGLE, "Specify the type name");
+ typeNameUI.addListener(SWT.Modify, this);
+
+ createWideLabel(mainArea, " Matching Types:");
+
+ matchingTypesUI = newTable(mainArea, SWT.CHECK);
+ ((GridData) matchingTypesUI.getLayoutData()).heightHint = 250;
+ ((GridData) matchingTypesUI.getLayoutData()).minimumHeight = 100;
+ typeNameUI.addListener(SWT.CHECK, this);
+
+ displayFilteredTypes("");
+ createButtonBar(mainArea);
+ return mainArea;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing = 3;
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ @Override
+ protected Control createButtonBar(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 0;
+ layout.makeColumnsEqualWidth = true;
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ composite.setLayout(layout);
+ GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+ composite.setLayoutData(data);
+
+ createButtonsForButtonBar(composite);
+ return composite;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ okButton = createButton(parent, IDialogConstants.OK_ID, "OK", true);
+ cancelButton = createButton(parent, IDialogConstants.CANCEL_ID, " Cancel ", false);
+ }
+
+ private void init() {
+
+ TableItem[] items = matchingTypesUI.getItems();
+ for (TableItem tableItem : items) {
+ if (selectedTypes.contains(tableItem.getText())) {
+ tableItem.setChecked(true);
+ }
+ }
+
+ okButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ TableItem[] items = matchingTypesUI.getItems();
+ List<String> selection = new ArrayList<String>();
+ for (TableItem tableItem : items) {
+ if (tableItem.getChecked()) {
+ selection.add(tableItem.getText());
+ }
+ }
+ owner.setSelectedTypes(selection);
+ shell.dispose();
+ }
+ });
+
+ cancelButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ shell.dispose();
+ }
+ });
+
+ Display display = Display.getDefault();
+ int width = 300;
+ int height = 400;
+ shell.setSize(width, height);
+ shell.setMinimumSize(200, 250);
+ shell.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - width) / 2, (Toolkit
+ .getDefaultToolkit().getScreenSize().height - height) / 2);
+ shell.setLayout(new FillLayout());
+ shell.layout();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+
+ }
+
+ protected Label createWideLabel(Composite parent, String message) {
+ Label label = null;
+ label = new Label(parent, SWT.WRAP);
+ label.setText(null != message ? message : "");
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ data.verticalAlignment = SWT.CENTER;
+ label.setLayoutData(data);
+ return label;
+ }
+
+ protected Text newText(Composite parent, int style, String tip) {
+ Text t = new Text(parent, style | SWT.BORDER);
+ t.setToolTipText(tip);
+ t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ t.addListener(SWT.KeyUp, this);
+ t.addListener(SWT.MouseUp, this);
+ return t;
+ }
+
+ protected Table newTable(Composite parent, int style) {
+ Table table = new Table(parent, style | SWT.BORDER | SWT.MULTI);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ table.setLayoutData(gd);
+ table.addListener(SWT.Selection, this);
+ table.addListener(SWT.KeyUp, this);
+ return table;
+ }
+
+ private void displayFilteredTypes(String aTypeName) {
+ matchingTypesUI.setRedraw(false);
+ matchingTypesUI.removeAll();
+ String topEntry = "";
+ aTypeName = aTypeName.toLowerCase();
+ for (String type : types) {
+ String candidateTypeName = type.toLowerCase();
+ if (StringUtils.isBlank(aTypeName) || candidateTypeName.indexOf(aTypeName) != -1) {
+
+ if (StringUtils.isEmpty(topEntry)) {
+ topEntry = type;
+ }
+ TableItem item = new TableItem(matchingTypesUI, SWT.NULL);
+ item.setText(type);
+ if (selectedTypes.contains(item.getText())) {
+ item.setChecked(true);
+ }
+
+ }
+ }
+ matchingTypesUI.setRedraw(true);
+ }
+
+ public void handleEvent(Event event) {
+ if (event.widget == typeNameUI && event.type == SWT.Modify) {
+ displayFilteredTypes(typeNameUI.getText());
+ } else if (event.widget == matchingTypesUI) {
+ Widget item = event.item;
+ if (item instanceof TableItem) {
+ TableItem ti = (TableItem) item;
+ if (ti.getChecked()) {
+ selectedTypes.add(ti.getText());
+ } else {
+ selectedTypes.remove(ti.getText());
+ }
+ }
+ }
+ }
+
+ public boolean isValid() {
+ return true;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesHandler.java?rev=1497821&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesHandler.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/SelectTypesHandler.java Fri Jun 28 15:51:38 2013
@@ -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.ruta.check;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.addons.RutaAddonsPlugin;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class SelectTypesHandler implements IHandler {
+
+ public void addHandlerListener(IHandlerListener arg0) {
+
+ }
+
+ public void dispose() {
+
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ AnnotationCheckView acView;
+ try {
+ acView = (AnnotationCheckView) HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().showView(AnnotationCheckView.ID);
+ AnnotationCheckComposite composite = (AnnotationCheckComposite) acView.getComposite();
+ List<String> types = new ArrayList<String>();
+ TypeSystemDescription tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+ new XMLInputSource(new File(composite.getTypeSystem())));
+ tsd.resolveImports();
+ TypeDescription[] systemTypes = tsd.getTypes();
+ for (TypeDescription typeDescription : systemTypes) {
+ types.add(typeDescription.getName());
+ }
+ Collections.sort(types);
+ Display display = Display.getDefault();
+ Shell shell = new Shell(display, SWT.RESIZE | SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
+ shell.setText("Included types");
+ new SelectTypesDialog(shell, types, false, composite);
+ } catch (InvalidXMLException e) {
+ RutaAddonsPlugin.error(e);
+ return Status.CANCEL_STATUS;
+ } catch (IOException e) {
+ RutaAddonsPlugin.error(e);
+ return Status.CANCEL_STATUS;
+ } catch (PartInitException e) {
+ RutaAddonsPlugin.error(e);
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener arg0) {
+
+ }
+
+}