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/12 18:40:30 UTC
svn commit: r575007 - in
/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor:
editor/ editor/editview/ ui/action/ ui/corpusview/
Author: twgoetz
Date: Wed Sep 12 09:40:23 2007
New Revision: 575007
URL: http://svn.apache.org/viewvc?rev=575007&view=rev
Log:
Jira UIMA-568: apply UIMA-568.patch.
https://issues.apache.org/jira/browse/UIMA-568
Added:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/CleanDocumentActionRunnable.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/DocumentActionRunnable.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java
Modified:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/editview/FeatureStructureContentProvider.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/AnnotatorActionGroup.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=575007&r1=575006&r2=575007&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Wed Sep 12 09:40:23 2007
@@ -274,6 +274,8 @@
}
public void changed() {
+ mFeatureStructureSelectionProvider.clearSelection();
+
syncAnnotations();
}
}
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=575007&r1=575006&r2=575007&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 Wed Sep 12 09:40:23 2007
@@ -85,8 +85,6 @@
public Object[] getElements(Object inputElement) {
-
-
if (inputElement != null) {
FeatureStructure featureStructure = (FeatureStructure) inputElement;
@@ -132,11 +130,13 @@
public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
this.viewer = viewer;
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- viewer.refresh();
- }
- });
+ if (newInput != null) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ viewer.refresh();
+ }
+ });
+ }
}
public void added(Collection<FeatureStructure> newFeatureStructure) {
@@ -144,12 +144,9 @@
public void changed() {
- // TODO: check if fs still exists
-
Display.getDefault().syncExec(new Runnable() {
public void run() {
- viewer.setSelection(viewer.getSelection());
- viewer.refresh();
+ viewer.setInput(null);
}
});
}
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java?rev=575007&r1=575006&r2=575007&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java Wed Sep 12 09:40:23 2007
@@ -20,34 +20,20 @@
package org.apache.uima.caseditor.ui.action;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
-import org.apache.uima.caseditor.CasEditorPlugin;
-import org.apache.uima.caseditor.core.IDocument;
+import org.apache.uima.cas.CAS;
import org.apache.uima.caseditor.core.model.DocumentElement;
import org.apache.uima.caseditor.core.uima.AnnotatorConfiguration;
-import org.apache.uima.caseditor.editor.AnnotationEditor;
import org.apache.uima.resource.ResourceInitializationException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
/**
*/
-public final class AnnotatorActionRunnable implements IRunnableWithProgress {
+public final class AnnotatorActionRunnable extends DocumentActionRunnable {
private AnnotatorConfiguration mAnnotatorConfiguration;
-
- private Collection<DocumentElement> mDocuments;
+ private AnalysisEngine annotatorInstance;
/**
* Initializes a new instance.
@@ -58,114 +44,122 @@
*/
public AnnotatorActionRunnable(AnnotatorConfiguration annotator,
Collection<DocumentElement> documents) {
- mAnnotatorConfiguration = annotator;
- mDocuments = documents;
- }
+ super("Run Analysis Engine ", documents);
- /**
- * Creates a list of all {@link AnnotationEditor} which are currently opened.
- */
- private AnnotationEditor[] getAnnotationEditors() {
-
- ArrayList<AnnotationEditor> dirtyParts = new ArrayList<AnnotationEditor>();
- IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
- for (IWorkbenchWindow element : windows) {
- IWorkbenchPage pages[] = element.getPages();
- for (IWorkbenchPage page : pages) {
- IEditorPart[] parts = page.getEditors();
-
- for (IEditorPart part : parts) {
- if (part instanceof AnnotationEditor) {
- AnnotationEditor editor = (AnnotationEditor) part;
- dirtyParts.add(editor);
- }
- }
- }
- }
-
- return dirtyParts.toArray(new AnnotationEditor[dirtyParts.size()]);
+ mAnnotatorConfiguration = annotator;
}
- /**
- * Executes the action.
- */
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- monitor.beginTask("Tagging", IProgressMonitor.UNKNOWN);
-
- monitor.subTask("Initializing tagger, " + "please stand by.");
-
- AnalysisEngine annotatorInstance;
-
+ @Override
+ protected void initialize() throws InvocationTargetException {
try {
annotatorInstance = mAnnotatorConfiguration.createAnnotator();
} catch (final ResourceInitializationException e) {
throw new InvocationTargetException(e);
}
+ }
- monitor.subTask("Tagging, please stand by.");
-
- Map<DocumentElement, AnnotationEditor> editorMap =
- new HashMap<DocumentElement, AnnotationEditor>();
+ @Override
+ protected boolean process(CAS cas) throws InvocationTargetException {
- for (AnnotationEditor annotationEditor : getAnnotationEditors()) {
- editorMap.put(annotationEditor.getDocument().getDocumentElement(), annotationEditor);
+ try {
+ annotatorInstance.process(cas);
+ } catch (AnalysisEngineProcessException e) {
+ throw new InvocationTargetException(e);
}
- for (DocumentElement element : mDocuments) {
-
- final IDocument document;
- try {
- document = element.getDocument(false); // retrieve the working copy
- } catch (CoreException e1) {
- throw new InvocationTargetException(e1);
- }
-
- try {
- annotatorInstance.process(document.getCAS());
- } catch (AnalysisEngineProcessException e) {
- throw new InvocationTargetException(e);
- }
-
- // currently all updates are made from the ui thread, just post this call to change
- // to the ui job queue
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- document.changed();
- }
- });
-
- try {
-
- if (editorMap.get(element) == null) {
- // file is not opened in any editor, just save the changes
- element.saveDocument();
- }
- else if (!editorMap.get(element).isDirty()) {
- // element is opened in editor and not dirty
- AnnotationEditor editor = editorMap.get(element);
- editor.setDirty();
- }
- else {
- // element is opened in editor and dirty, do nothing
- }
- } catch (CoreException e) {
+ return true;
+ }
- // TODO: Show the user an error dialog
- CasEditorPlugin.log(e);
- }
- }
-
- try {
+ @Override
+ protected void completedProcessing() throws InvocationTargetException {
+ try {
annotatorInstance.collectionProcessComplete();
- }
- catch (AnalysisEngineProcessException e) {
+ } catch (AnalysisEngineProcessException e) {
throw new InvocationTargetException(e);
}
annotatorInstance.destroy();
annotatorInstance = null;
-
- monitor.done();
}
+
+
+// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+// monitor.beginTask("Tagging", IProgressMonitor.UNKNOWN);
+//
+// monitor.subTask("Initializing tagger, " + "please stand by.");
+//
+// AnalysisEngine annotatorInstance;
+//
+// try {
+// annotatorInstance = mAnnotatorConfiguration.createAnnotator();
+// } catch (final ResourceInitializationException e) {
+// throw new InvocationTargetException(e);
+// }
+//
+// monitor.subTask("Tagging, please stand by.");
+//
+// Map<DocumentElement, AnnotationEditor> editorMap =
+// new HashMap<DocumentElement, AnnotationEditor>();
+//
+// for (AnnotationEditor annotationEditor : getAnnotationEditors()) {
+// editorMap.put(annotationEditor.getDocument().getDocumentElement(), annotationEditor);
+// }
+//
+// for (DocumentElement element : mDocuments) {
+//
+// final IDocument document;
+// try {
+// document = element.getDocument(false); // retrieve the working copy
+// } catch (CoreException e1) {
+// throw new InvocationTargetException(e1);
+// }
+//
+// try {
+// annotatorInstance.process(document.getCAS());
+// } catch (AnalysisEngineProcessException e) {
+// throw new InvocationTargetException(e);
+// }
+//
+// // currently all updates are made from the ui thread, just post this call to change
+// // to the ui job queue
+// Display.getDefault().syncExec(new Runnable() {
+// public void run() {
+// document.changed();
+// }
+// });
+//
+// try {
+//
+// if (editorMap.get(element) == null) {
+// // file is not opened in any editor, just save the changes
+// element.saveDocument();
+// }
+// else if (!editorMap.get(element).isDirty()) {
+// // element is opened in editor and not dirty
+// AnnotationEditor editor = editorMap.get(element);
+// editor.setDirty();
+// }
+// else {
+// // element is opened in editor and dirty, do nothing
+// }
+// } catch (CoreException e) {
+//
+// // TODO: Show the user an error dialog
+// CasEditorPlugin.log(e);
+// }
+// }
+//
+// try {
+// annotatorInstance.collectionProcessComplete();
+// }
+// catch (AnalysisEngineProcessException e) {
+// throw new InvocationTargetException(e);
+// }
+//
+// annotatorInstance.destroy();
+// annotatorInstance = null;
+//
+// monitor.done();
+// }
}
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/CleanDocumentActionRunnable.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/CleanDocumentActionRunnable.java?rev=575007&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/CleanDocumentActionRunnable.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/CleanDocumentActionRunnable.java Wed Sep 12 09:40:23 2007
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.ui.action;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.caseditor.core.model.DocumentElement;
+
+/**
+ * Removes all added feature structures from the document.
+ *
+ * TODO: Should support multi sofa cas documents
+ */
+public final class CleanDocumentActionRunnable extends DocumentActionRunnable {
+
+ public CleanDocumentActionRunnable( Collection<DocumentElement> documents) {
+ super("Clean documents", documents);
+ }
+
+ /**
+ * Removes all feature structures from the given {@link CAS} object.
+ */
+ @Override
+ protected boolean process(CAS cas) throws InvocationTargetException {
+
+ String documentText = cas.getDocumentText();
+
+ cas.reset();
+
+ cas.setDocumentText(documentText);
+
+ return true;
+ }
+}
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/DocumentActionRunnable.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/DocumentActionRunnable.java?rev=575007&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/DocumentActionRunnable.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/DocumentActionRunnable.java Wed Sep 12 09:40:23 2007
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.ui.action;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.core.IDocument;
+import org.apache.uima.caseditor.core.model.DocumentElement;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This class can be reused by ui actions which want to modify documents.
+ */
+abstract class DocumentActionRunnable implements IRunnableWithProgress {
+
+ private final Collection<DocumentElement> documents;
+ private final String taskName;
+
+ /**
+ * Initializes the current instance.
+ *
+ * @param documents
+ */
+ protected DocumentActionRunnable(String taskName, Collection<DocumentElement> documents) {
+ this.taskName = taskName;
+ this.documents = documents;
+ }
+
+ /**
+ * Creates a list of all {@link AnnotationEditor} which are currently opened.
+ */
+ protected AnnotationEditor[] getAnnotationEditors() {
+
+ ArrayList<AnnotationEditor> dirtyParts = new ArrayList<AnnotationEditor>();
+ IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for (IWorkbenchWindow element : windows) {
+ IWorkbenchPage pages[] = element.getPages();
+ for (IWorkbenchPage page : pages) {
+ IEditorPart[] parts = page.getEditors();
+
+ for (IEditorPart part : parts) {
+ if (part instanceof AnnotationEditor) {
+ AnnotationEditor editor = (AnnotationEditor) part;
+ dirtyParts.add(editor);
+ }
+ }
+ }
+ }
+
+ return dirtyParts.toArray(new AnnotationEditor[dirtyParts.size()]);
+ }
+
+ /**
+ * This method is called before the processing of the documents is started.
+ *
+ * @throws InvocationTargetException
+ */
+ protected void initialize() throws InvocationTargetException {
+ }
+
+ /**
+ * Processes the given cas object.
+ *
+ * @param cas
+ *
+ * @return true if the implementation changed the cas object otherwise false.
+ *
+ * @throws InvocationTargetException
+ */
+ protected abstract boolean process(CAS cas) throws InvocationTargetException;
+
+ /**
+ * This method is called after the processing of the documents.
+ *
+ * @throws InvocationTargetException
+ */
+ protected void completedProcessing() throws InvocationTargetException {
+ }
+
+ /**
+ * Processes the provided documents. Modified documents are synchronized with
+ * the file system or with the corresponding editor.
+ */
+ public final void run(IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+
+ monitor.beginTask(taskName, documents.size());
+
+ monitor.subTask("Initializing");
+
+ initialize();
+
+ Map<DocumentElement, AnnotationEditor> editorMap = new HashMap<DocumentElement, AnnotationEditor>();
+
+ for (AnnotationEditor annotationEditor : getAnnotationEditors()) {
+ editorMap.put(annotationEditor.getDocument().getDocumentElement(), annotationEditor);
+ }
+
+ monitor.subTask("Processing documents, please wait!");
+
+ for (DocumentElement documentElement : documents) {
+
+ final IDocument doc;
+
+ try {
+ doc = documentElement.getDocument(false);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+
+ boolean wasCasChanged = process(doc.getCAS());
+
+ if (wasCasChanged) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ doc.changed();
+ }
+ });
+
+ try {
+
+ if (editorMap.get(documentElement) == null) {
+ // file is not opened in any editor, just save the changes
+ documentElement.saveDocument();
+ } else if (!editorMap.get(documentElement).isDirty()) {
+ // element is opened in editor and not dirty
+ AnnotationEditor editor = editorMap.get(documentElement);
+ editor.setDirty();
+ } else {
+ // element is opened in editor and dirty, do nothing
+ }
+ } catch (CoreException e) {
+
+ // TODO: Show the user an error dialog
+ CasEditorPlugin.log(e);
+ }
+ }
+
+ monitor.worked(1);
+ }
+
+ monitor.subTask("Completing processing!");
+
+ completedProcessing();
+
+ monitor.done();
+ }
+}
\ No newline at end of file
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/AnnotatorActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/AnnotatorActionGroup.java?rev=575007&r1=575006&r2=575007&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/AnnotatorActionGroup.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/AnnotatorActionGroup.java Wed Sep 12 09:40:23 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
@@ -44,8 +44,8 @@
private Shell mShell;
/**
- * Initializes a new instance with the given shell.
- *
+ * Initializes the current instance with the given shell.
+ *
* @param shell
*/
AnnotatorActionGroup(Shell shell) {
@@ -55,11 +55,11 @@
/**
* Adds for each uima annotator an appropriate configured <code>AnnotatorAction</code> to the
* given menu.
- *
+ *
* Note: The action appears only in the menu if a document or corpus is selected.
- *
+ *
* @param menu -
- * the context menu manager // hier auf listen ???
+ * the context menu manager
*/
@Override
public void fillContextMenu(IMenuManager menu) {
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java?rev=575007&r1=575006&r2=575007&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java Wed Sep 12 09:40:23 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
@@ -40,200 +40,195 @@
/**
* Main corpus explorer action group.
*/
-final class CorpusExplorerActionGroup extends ActionGroup implements
- ICorpusExplorerActionGroup
-{
- private OpenActionGroup mOpenActionGroup;
-
- private RefactorGroup mRefactorGroup;
-
- protected ImportResourcesAction mImportAction;
-
-// protected ExportResourcesAction mExportAction;
-
- private WorkspaceActionGroup mWorkspaceGroup;
-
- private AnnotatorActionGroup mAnnotatorActionGroup;
-
- private ConsumerCorpusActionGroup mConsumerCorpusActionGroup;
-
- private PropertyDialogAction mPropertyAction;
-
- private IWorkbenchWindow mWindow;
-
- private IAction mRetargetPropertiesAction;
-
- /**
- * Creates a <code>CorpusExplorerActionGroup</code> object.
- *
- * @param view -
- * the coresponding <code>CorpusExplorerView</code>
- */
- CorpusExplorerActionGroup(CorpusExplorerView view)
- {
- mWindow = view.getSite().getPage().getWorkbenchWindow();
-
- Shell shell = view.getSite().getShell();
-
- mOpenActionGroup = new OpenActionGroup(view.getSite().getPage());
-
- mRefactorGroup = new RefactorGroup(shell, mWindow);
-
- mImportAction = new ImportResourcesAction(mWindow);
-
-// mExportAction = new ExportResourcesAction(mWindow);
-
- mWorkspaceGroup = new WorkspaceActionGroup(shell, mWindow);
-
- mAnnotatorActionGroup = new AnnotatorActionGroup(shell);
-
- mConsumerCorpusActionGroup = new ConsumerCorpusActionGroup(shell);
-
- mPropertyAction = new PropertyDialogAction(
- new SameShellProvider(shell), view.getTreeViewer());
-
- mRetargetPropertiesAction = ActionFactory.PROPERTIES.create(mWindow);
- }
-
+final class CorpusExplorerActionGroup extends ActionGroup implements ICorpusExplorerActionGroup {
+ private OpenActionGroup openActionGroup;
+
+ private RefactorGroup refactorGroup;
+
+ protected ImportResourcesAction importAction;
+
+ // protected ExportResourcesAction mExportAction;
+
+ private WorkspaceActionGroup workspaceGroup;
+
+ private AnnotatorActionGroup annotatorActionGroup;
+
+ private ConsumerCorpusActionGroup consumerCorpusActionGroup;
+
+ private UimaRefactorActionGroup uimaRefactorActionGroup;
+
+ private PropertyDialogAction propertyAction;
+
+ private IWorkbenchWindow mWindow;
+
+ private IAction mRetargetPropertiesAction;
+
+ /**
+ * Creates a <code>CorpusExplorerActionGroup</code> object.
+ *
+ * @param view -
+ * the corresponding <code>CorpusExplorerView</code>
+ */
+ CorpusExplorerActionGroup(CorpusExplorerView view) {
+ mWindow = view.getSite().getPage().getWorkbenchWindow();
+
+ Shell shell = view.getSite().getShell();
+
+ openActionGroup = new OpenActionGroup(view.getSite().getPage());
+
+ refactorGroup = new RefactorGroup(shell, mWindow);
+
+ importAction = new ImportResourcesAction(mWindow);
+
+ // mExportAction = new ExportResourcesAction(mWindow);
+
+ workspaceGroup = new WorkspaceActionGroup(shell, mWindow);
+
+ annotatorActionGroup = new AnnotatorActionGroup(shell);
+
+ consumerCorpusActionGroup = new ConsumerCorpusActionGroup(shell);
+
+ uimaRefactorActionGroup = new UimaRefactorActionGroup(shell);
+
+ propertyAction = new PropertyDialogAction(new SameShellProvider(shell), view.getTreeViewer());
+
+ mRetargetPropertiesAction = ActionFactory.PROPERTIES.create(mWindow);
+ }
+
/**
* Fills the context menu with all the actions.
*/
- @Override
- public void fillContextMenu(IMenuManager menu)
- {
- IStructuredSelection selection = (IStructuredSelection) getContext()
- .getSelection();
-
- // For action order see "Eclipse User Interface Guidelines"
-
- // 1. New actions
- IAction newAction = ActionFactory.NEW.create(mWindow);
- newAction.setText("New");
- menu.add(newAction);
- menu.add(new Separator());
-
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
+
+ // For action order see "Eclipse User Interface Guidelines"
+
+ // 1. New actions
+ IAction newAction = ActionFactory.NEW.create(mWindow);
+ newAction.setText("New");
+ menu.add(newAction);
+ menu.add(new Separator());
+
// 2. Open actions
- mOpenActionGroup.fillContextMenu(menu);
- menu.add(new Separator());
-
- // 3. Navigate + Show In
-
- // 4.1 Cut, Copy, Paste, Delete, Rename and other refactoring commands
- mRefactorGroup.fillContextMenu(menu);
- menu.add(new Separator());
-
- // 4.2
- menu.add(ActionFactory.IMPORT.create(mWindow));
-
-// menu.add(ActionFactory.EXPORT.create(mWindow));
-
- menu.add(new Separator());
-
- // 5. Other Plugin Additons
- mWorkspaceGroup.fillContextMenu(menu);
- menu.add(new Separator());
-
- // 5.2 annotator additions
- MenuManager taggerMenu = new MenuManager("Annotator");
- menu.add(taggerMenu);
-
- mAnnotatorActionGroup.fillContextMenu(taggerMenu);
-
- // 5.3 consumer additions
- MenuManager trainerMenu = new MenuManager("Consumer");
- menu.add(trainerMenu);
-
- mConsumerCorpusActionGroup.fillContextMenu(trainerMenu);
-
- // 5.4 Annotator Plugin Additions
- menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
-
+ openActionGroup.fillContextMenu(menu);
+ menu.add(new Separator());
+
+ // 3. Navigate + Show In
+
+ // 4.1 Cut, Copy, Paste, Delete, Rename and other refactoring commands
+ refactorGroup.fillContextMenu(menu);
+ menu.add(new Separator());
+
+ // 4.2
+ menu.add(ActionFactory.IMPORT.create(mWindow));
+
+ // menu.add(ActionFactory.EXPORT.create(mWindow));
+
+ menu.add(new Separator());
+
+ // 5. Other Plugin Additons
+ workspaceGroup.fillContextMenu(menu);
+ menu.add(new Separator());
+
+ // 5.2 annotator additions
+ MenuManager taggerMenu = new MenuManager("Annotator");
+ menu.add(taggerMenu);
+
+ annotatorActionGroup.fillContextMenu(taggerMenu);
+
+ // 5.3 consumer additions
+ MenuManager trainerMenu = new MenuManager("Consumer");
+ menu.add(trainerMenu);
+
+ consumerCorpusActionGroup.fillContextMenu(trainerMenu);
+
+ MenuManager uimaRefactorMenu = new MenuManager("Refactor");
+ menu.add(uimaRefactorMenu);
+
+ uimaRefactorActionGroup.fillContextMenu(uimaRefactorMenu);
+
+ // 5.4 Annotator plugin additions
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+
// 6. Properties action
- boolean isOnlyOneResourceSelected = selection.size() == 1;
- if (isOnlyOneResourceSelected)
- {
- menu.add(mRetargetPropertiesAction);
- }
+ boolean isOnlyOneResourceSelected = selection.size() == 1;
+ if (isOnlyOneResourceSelected) {
+ menu.add(mRetargetPropertiesAction);
}
-
+ }
+
/**
* Fills the action bars
*/
- @Override
- public void fillActionBars(IActionBars actionBars)
- {
- actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(),
- mPropertyAction);
-
- actionBars.updateActionBars();
-
- mOpenActionGroup.fillActionBars(actionBars);
- mRefactorGroup.fillActionBars(actionBars);
- mWorkspaceGroup.fillActionBars(actionBars);
- }
-
+ @Override
+ public void fillActionBars(IActionBars actionBars) {
+ actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), propertyAction);
+
+ actionBars.updateActionBars();
+
+ openActionGroup.fillActionBars(actionBars);
+ refactorGroup.fillActionBars(actionBars);
+ workspaceGroup.fillActionBars(actionBars);
+ }
+
/**
* Updates the actions.
*/
- @Override
- public void updateActionBars()
- {
- IStructuredSelection selection = (IStructuredSelection) getContext()
- .getSelection();
-
- mPropertyAction.setEnabled(selection.size() == 1);
-
- mOpenActionGroup.updateActionBars();
- mRefactorGroup.updateActionBars();
- mWorkspaceGroup.updateActionBars();
- }
-
+ @Override
+ public void updateActionBars() {
+ IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
+
+ propertyAction.setEnabled(selection.size() == 1);
+
+ openActionGroup.updateActionBars();
+ refactorGroup.updateActionBars();
+ workspaceGroup.updateActionBars();
+ }
+
/**
* Sets the context to the action groups.
*/
- @Override
- public void setContext(ActionContext context)
- {
- super.setContext(context);
-
- mOpenActionGroup.setContext(context);
- mRefactorGroup.setContext(context);
- mWorkspaceGroup.setContext(context);
- mAnnotatorActionGroup.setContext(context);
- mConsumerCorpusActionGroup.setContext(context);
- }
-
+ @Override
+ public void setContext(ActionContext context) {
+ super.setContext(context);
+
+ openActionGroup.setContext(context);
+ refactorGroup.setContext(context);
+ workspaceGroup.setContext(context);
+ annotatorActionGroup.setContext(context);
+ consumerCorpusActionGroup.setContext(context);
+ uimaRefactorActionGroup.setContext(context);
+ }
+
/**
* Executes the default action, in this case the open action.
*/
- public void executeDefaultAction(IStructuredSelection selection)
- {
- if (selection.getFirstElement() instanceof INlpElement) {
- INlpElement nlpElement = (INlpElement) selection.getFirstElement();
-
- mOpenActionGroup.executeDefaultAction(new StructuredSelection(
- nlpElement.getResource()));
- }
- else {
- mOpenActionGroup.executeDefaultAction(selection);
- }
+ public void executeDefaultAction(IStructuredSelection selection) {
+ if (selection.getFirstElement() instanceof INlpElement) {
+ INlpElement nlpElement = (INlpElement) selection.getFirstElement();
+
+ openActionGroup.executeDefaultAction(new StructuredSelection(nlpElement.getResource()));
+ } else {
+ openActionGroup.executeDefaultAction(selection);
}
-
+ }
+
/**
- * Dispose all resources created by the current object.
- */
- @Override
- public void dispose()
- {
- super.dispose();
-
- mOpenActionGroup.dispose();
- mRefactorGroup.dispose();
- mImportAction.dispose();
-// mExportAction.dispose();
- mWorkspaceGroup.dispose();
- mAnnotatorActionGroup.dispose();
- mConsumerCorpusActionGroup.dispose();
- mPropertyAction.dispose();
- }
+ * Dispose all resources created by the current object.
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+
+ openActionGroup.dispose();
+ refactorGroup.dispose();
+ importAction.dispose();
+ // mExportAction.dispose();
+ workspaceGroup.dispose();
+ annotatorActionGroup.dispose();
+ consumerCorpusActionGroup.dispose();
+ uimaRefactorActionGroup.dispose();
+ propertyAction.dispose();
+ }
}
Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java?rev=575007&r1=575006&r2=575007&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java Wed Sep 12 09:40:23 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
@@ -35,55 +35,55 @@
* This group contains refactoring actions.
*/
final class RefactorGroup extends ActionGroup {
-
+
/**
* The Clipboard for the copy/paste actions. Must be diposed!
*/
private Clipboard mClipboard;
-
+
/**
* Action that actually copy the resource.
*/
private CopyAction mCopyAction;
-
+
/**
* The copy retarget action
*/
private IWorkbenchAction mRetargetCopyAction;
-
+
/**
- * Actin that actually paste the resource.
+ * Action that actually paste the resource.
*/
private PasteAction mPasteAction;
-
+
/**
* The paste retarget action.
*/
private IWorkbenchAction mRetargetPasteAction;
-
+
/**
* Action that actually delete the resource.
*/
private DeleteResourceAction mDeleteAction;
-
+
/**
* The delete retarget action.
*/
private IWorkbenchAction mRetargetDeleteAction;
-
+
/**
* Action that actually rename the resource.
*/
private RenameResourceAction mRenameAction;
-
+
/**
* The rename retarget action.
*/
private IWorkbenchAction mRetargetRenameAction;
-
+
/**
* Initializes a new instance.
- *
+ *
* @param shell
* @param window
*/
@@ -92,25 +92,25 @@
// copy action
mCopyAction = new CopyAction(mClipboard);
-
+
mRetargetCopyAction = ActionFactory.COPY.create(window);
-
+
// paste action
mPasteAction = new PasteAction(shell, mClipboard);
-
+
mRetargetPasteAction = ActionFactory.PASTE.create(window);
-
+
// delete action
mDeleteAction = new DeleteResourceAction(shell);
-
+
mRetargetDeleteAction = ActionFactory.DELETE.create(window);
-
+
// rename action
mRenameAction = new RenameResourceAction(shell);
-
+
mRetargetRenameAction = ActionFactory.RENAME.create(window);
}
-
+
/**
* Fills the context menu with actions.
*/
@@ -146,7 +146,7 @@
// 7. other refactoring commands
}
-
+
/**
* Fill the ActionBars with defined actions.
*/
@@ -162,7 +162,7 @@
actionBars.updateActionBars();
}
-
+
/**
* Update the selction of the actions.
*/
@@ -172,25 +172,25 @@
IStructuredSelection selection = CorpusExplorerUtil
.convertNLPElementsToResources((IStructuredSelection) getContext().getSelection());
-
+
mCopyAction.selectionChanged(selection);
mPasteAction.selectionChanged(selection);
mDeleteAction.selectionChanged(selection);
mRenameAction.selectionChanged(selection);
}
-
+
/**
* Destroy all swt elements which where created by this instance.
*/
@Override
public void dispose() {
-
+
mClipboard.dispose();
mRetargetCopyAction.dispose();
mRetargetPasteAction.dispose();
mRetargetDeleteAction.dispose();
mRetargetRenameAction.dispose();
-
+
super.dispose();
}
}
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java?rev=575007&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java Wed Sep 12 09:40:23 2007
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.ui.corpusview;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.uima.caseditor.core.model.CorpusElement;
+import org.apache.uima.caseditor.core.model.DocumentElement;
+import org.apache.uima.caseditor.ui.action.CleanDocumentActionRunnable;
+import org.apache.uima.caseditor.ui.action.RunnableAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.ActionGroup;
+
+public class UimaRefactorActionGroup extends ActionGroup {
+
+ private Shell shell;
+
+ /**
+ * Initializes the current instance with the given shell.
+ *
+ * @param shell
+ */
+ UimaRefactorActionGroup(Shell shell) {
+ this.shell = shell;
+ }
+
+
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
+
+ LinkedList<DocumentElement> documentElements = new LinkedList<DocumentElement>();
+
+ if (!CorpusExplorerUtil.isContaingNLPProjectOrNonNLPResources(selection)) {
+ Iterator resources = selection.iterator();
+ while (resources.hasNext()) {
+ Object resource = resources.next();
+
+ if (resource instanceof CorpusElement) {
+ documentElements.addAll(((CorpusElement) resource).getDocuments());
+ }
+
+ if (resource instanceof DocumentElement) {
+ documentElements.add(((DocumentElement) resource));
+ }
+ }
+ }
+
+ if (!documentElements.isEmpty()) {
+
+ IRunnableWithProgress annotatorRunnableAction = new CleanDocumentActionRunnable(
+ documentElements);
+
+ RunnableAction annotatorAction = new RunnableAction(shell, "Clean documents",
+ annotatorRunnableAction);
+
+ menu.add(annotatorAction);
+ }
+ }
+}
\ No newline at end of file