You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2008/09/22 15:25:29 UTC
svn commit: r697817 - in
/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor:
./ contextmenu/
Author: joern
Date: Mon Sep 22 06:25:28 2008
New Revision: 697817
URL: http://svn.apache.org/viewvc?rev=697817&view=rev
Log:
UIMA-1179 Improved show annoations and mode context menus to provide selection events
Added:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IModeMenuListener.java (with props)
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IShowAnnotationsListener.java (with props)
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ModeMenu.java (with props)
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java (with props)
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/TypeMenu.java (with props)
Modified:
incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.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=697817&r1=697816&r2=697817&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 Mon Sep 22 06:25:28 2008
@@ -22,8 +22,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -42,11 +40,14 @@
import org.apache.uima.caseditor.editor.annotation.DrawingStyle;
import org.apache.uima.caseditor.editor.annotation.EclipseAnnotationPeer;
import org.apache.uima.caseditor.editor.context.AnnotationEditingControlCreator;
+import org.apache.uima.caseditor.editor.contextmenu.IModeMenuListener;
+import org.apache.uima.caseditor.editor.contextmenu.IShowAnnotationsListener;
+import org.apache.uima.caseditor.editor.contextmenu.ModeMenu;
+import org.apache.uima.caseditor.editor.contextmenu.ShowAnnotationsMenu;
import org.apache.uima.caseditor.editor.outline.AnnotationOutline;
import org.apache.uima.caseditor.ui.FeatureStructureTransfer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
@@ -80,10 +81,6 @@
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchActionConstants;
@@ -281,189 +278,6 @@
}
/**
- */
- private static abstract class TypeMenu extends ContributionItem {
- private Type mParentType;
-
- private TypeSystem mTypeSystem;
-
- /**
- * Initializes a new instance.
- *
- * @param parentType
- * @param typeSystem
- */
- TypeMenu(Type parentType, TypeSystem typeSystem) {
- mParentType = parentType;
- mTypeSystem = typeSystem;
- }
-
- /**
- * Fills the menu with type entries.
- *
- * @param menu
- * @param index
- */
- @Override
- public void fill(Menu menu, int index) {
- fillTypeMenu(mParentType, menu, false);
- }
-
- private void fillTypeMenu(Type parentType, Menu parentMenu, boolean isParentIncluded) {
- List<Type> childs = mTypeSystem.getDirectSubtypes(parentType);
-
- Menu newSubMenu;
-
- // has this type sub types ?
- // yes
- if (childs.size() != 0) {
-
- if (isParentIncluded) {
- MenuItem subMenuItem = new MenuItem(parentMenu, SWT.CASCADE);
- subMenuItem.setText(parentType.getShortName());
-
- newSubMenu = new Menu(subMenuItem);
- subMenuItem.setMenu(newSubMenu);
- }
- else {
- newSubMenu = parentMenu;
- }
-
- insertAction(parentType, newSubMenu);
-
- Iterator<Type> childsIterator = childs.iterator();
-
- while (childsIterator.hasNext()) {
- Type child = childsIterator.next();
-
- fillTypeMenu(child, newSubMenu, true);
- }
- }
- // no
- else {
- insertAction(parentType, parentMenu);
- }
- }
- protected abstract void insertAction(final Type type, Menu parentMenu);
- }
-
- /**
- * Creates the mode context sub menu.
- */
- private class ModeMenu extends TypeMenu {
-
- /**
- * Initializes a new instance.
- *
- * @param type
- * @param typeSystem
- */
- ModeMenu(TypeSystem typeSystem) {
- super(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION), typeSystem);
- }
-
- @Override
- protected void insertAction(final Type type, Menu parentMenu) {
- MenuItem actionItem = new MenuItem(parentMenu, SWT.PUSH);
- actionItem.setText(type.getShortName());
-
- actionItem.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event e) {
-
- IAction actionToExecute = new ChangeModeAction(type, type.getShortName(),
- AnnotationEditor.this);
-
- actionToExecute.run();
- }
- });
- }
- }
-
- /**
- * Creates the show annotations context sub menu.
- */
- private class ShowAnnotationsMenu extends TypeMenu {
-
- /**
- * This collection contains all type names which are displayed in
- * the editor.
- */
- private Collection<Type> mTypesToDisplay = new HashSet<Type>();
-
- /**
- * Initializes a new instance.
- *
- * @param type
- * @param typeSystem
- */
- ShowAnnotationsMenu(EditorAnnotationStatus status, TypeSystem typeSystem) {
- super(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION), typeSystem);
-
- for (String typeName : status.getDisplayAnnotations()) {
- mTypesToDisplay.add(getDocument().getType(typeName));
- }
- }
-
- @Override
- protected void insertAction(final Type type, Menu parentMenu) {
- final MenuItem actionItem = new MenuItem(parentMenu, SWT.CHECK);
- actionItem.setText(type.getShortName());
-
- if (getAnnotationMode().equals(type)) {
- actionItem.setSelection(true);
- }
-
- if (mTypesToDisplay.contains(type)) {
- actionItem.setSelection(true);
- }
-
- // TODO: move this to an action
- // do not access mTypesToDisplay directly !!!
- actionItem.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event e) {
- if (actionItem.getSelection()) {
- mTypesToDisplay.add(type);
-
- } else {
- mTypesToDisplay.remove(type);
- }
-
- mEditorListener.showAnnotationsChanged(getShownAnnotationTypes());
-
- // TODO: only synchronize annotation which
- // must be removed/added
- syncAnnotations();
-
- EditorAnnotationStatus status = getDocument().getProject().getEditorAnnotationStatus();
-
- getDocument().getProject().setEditorAnnotationStatus(
- new EditorAnnotationStatus(status.getMode(), getSelectedTypes()));
- }
- });
- }
-
- Collection<Type> getSelectedTypes() {
- Collection<Type> selectedTypes = new LinkedList<Type>();
-
- for (Type type : mTypesToDisplay) {
- selectedTypes.add(type);
- }
-
- return Collections.unmodifiableCollection(selectedTypes);
- }
-
- void setSelectedTypes(Collection<Type> types) {
- mTypesToDisplay = new HashSet<Type>();
-
- for (Type type : types) {
- mTypesToDisplay.add(type);
- }
-
- mEditorListener.showAnnotationsChanged(getSelectedTypes());
- }
- }
-
- /**
* Sometimes the wrong annotation is selected ... ????
*/
private class FeatureStructureDragListener implements DragSourceListener {
@@ -741,6 +555,22 @@
mShowAnnotationsMenu = new ShowAnnotationsMenu(
getDocument().getProject().getEditorAnnotationStatus(),
getDocument().getCAS().getTypeSystem());
+ mShowAnnotationsMenu.addListener(new IShowAnnotationsListener() {
+
+ public void selectionChanged(Collection<Type> selection) {
+ // TODO: only synchronize annotation which
+ // must be removed/added
+ syncAnnotations();
+
+ EditorAnnotationStatus status = getDocument().getProject().getEditorAnnotationStatus();
+
+ getDocument().getProject().setEditorAnnotationStatus(
+ new EditorAnnotationStatus(status.getMode(), selection));
+
+ if (mEditorListener != null)
+ mEditorListener.showAnnotationsChanged(selection);
+ }
+ });
EditorAnnotationStatus status = getDocument().getProject().getEditorAnnotationStatus();
@@ -786,9 +616,21 @@
TypeSystem typeSytem = getDocument().getCAS().getTypeSystem();
// mode menu
- MenuManager modeMenu = new MenuManager("Mode");
- menu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, modeMenu);
- modeMenu.add(new ModeMenu(typeSytem));
+ MenuManager modeMenuManager = new MenuManager("Mode");
+ menu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, modeMenuManager);
+
+ ModeMenu modeMenu = new ModeMenu(typeSytem);
+ modeMenu.addListener(new IModeMenuListener(){
+
+ public void modeChanged(Type newMode) {
+ IAction actionToExecute = new ChangeModeAction(newMode,
+ newMode.getShortName(),
+ AnnotationEditor.this);
+
+ actionToExecute.run();
+ }});
+
+ modeMenuManager.add(modeMenu);
// annotation menu
MenuManager showAnnotationMenu = new MenuManager("Show Annotations");
@@ -836,7 +678,7 @@
// TODO: check if this type is a subtype of Annotation
mAnnotationMode = type;
-
+
highlight(0, 0);
setProjectEditorStatus();
@@ -846,6 +688,8 @@
syncAnnotations();
fireAnnotationTypeChanged(getAnnotationMode());
+
+ mShowAnnotationsMenu.setEditorAnnotationMode(type);
}
public Collection<Type> getShownAnnotationTypes() {
@@ -856,11 +700,9 @@
* @param type
*/
private void fireAnnotationTypeChanged(Type type) {
- if (mEditorListener == null) {
- return;
+ if (mEditorListener != null) {
+ mEditorListener.annotationModeChanged(type);
}
-
- mEditorListener.annotationModeChanged(type);
}
private void showAnnotationType(Type type) {
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IModeMenuListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IModeMenuListener.java?rev=697817&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IModeMenuListener.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IModeMenuListener.java Mon Sep 22 06:25:28 2008
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.contextmenu;
+
+import org.apache.uima.cas.Type;
+
+public interface IModeMenuListener {
+
+ /**
+ * Mode was changed to a new mode.
+ *
+ * @param newMode
+ */
+ void modeChanged(Type newMode);
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IModeMenuListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IShowAnnotationsListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IShowAnnotationsListener.java?rev=697817&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IShowAnnotationsListener.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IShowAnnotationsListener.java Mon Sep 22 06:25:28 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.contextmenu;
+
+import java.util.Collection;
+
+import org.apache.uima.cas.Type;
+
+public interface IShowAnnotationsListener {
+ void selectionChanged(Collection<Type> selection);
+ }
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/IShowAnnotationsListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ModeMenu.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ModeMenu.java?rev=697817&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ModeMenu.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ModeMenu.java Mon Sep 22 06:25:28 2008
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.contextmenu;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+
+/**
+ * Creates the mode context sub menu.
+ */
+public class ModeMenu extends TypeMenu {
+
+ private Set<IModeMenuListener> listeners = new HashSet<IModeMenuListener>();
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param type
+ * @param typeSystem
+ */
+ public ModeMenu(TypeSystem typeSystem) {
+ super(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION), typeSystem);
+ }
+
+ public void addListener(IModeMenuListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(IModeMenuListener listener) {
+ listeners.remove(listener);
+ }
+
+ @Override
+ protected void insertAction(final Type type, Menu parentMenu) {
+ MenuItem actionItem = new MenuItem(parentMenu, SWT.PUSH);
+ actionItem.setText(type.getShortName());
+
+ actionItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+
+ for (IModeMenuListener listener : listeners) {
+ listener.modeChanged(type);
+ }
+ }
+ });
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ModeMenu.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java?rev=697817&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java Mon Sep 22 06:25:28 2008
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.contextmenu;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.caseditor.core.model.dotcorpus.EditorAnnotationStatus;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+
+/**
+ * Creates the show annotations context sub menu.
+ */
+public class ShowAnnotationsMenu extends TypeMenu {
+
+ private Set<IShowAnnotationsListener> listeners = new HashSet<IShowAnnotationsListener>();
+
+ /**
+ * This collection contains all type names which are displayed in the
+ * editor.
+ */
+ private Collection<Type> typesToDisplay = new HashSet<Type>();
+
+ /**
+ * Editor annotation mode type. This variable is only set if the editor
+ * annotation mode type is not already included in the typesToDisplay
+ * collection
+ */
+ private Type editorAnnotationMode;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param type
+ * @param typeSystem
+ */
+ public ShowAnnotationsMenu(EditorAnnotationStatus status,
+ TypeSystem typeSystem) {
+ super(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION), typeSystem);
+
+ for (String typeName : status.getDisplayAnnotations()) {
+ typesToDisplay.add(typeSystem.getType(typeName));
+ }
+ }
+
+ public void addListener(IShowAnnotationsListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(IShowAnnotationsListener listener) {
+ listeners.remove(listener);
+ }
+
+ @Override
+ protected void insertAction(final Type type, Menu parentMenu) {
+ final MenuItem actionItem = new MenuItem(parentMenu, SWT.CHECK);
+ actionItem.setText(type.getShortName());
+
+ // TODO: find another way to select the annotation mode also
+ if (editorAnnotationMode != null && editorAnnotationMode.equals(type)) {
+ actionItem.setSelection(true);
+ }
+
+ if (typesToDisplay.contains(type)) {
+ actionItem.setSelection(true);
+ }
+
+ // TODO: move this to an action
+ // do not access mTypesToDisplay directly !!!
+ actionItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (actionItem.getSelection()) {
+ typesToDisplay.add(type);
+
+ } else {
+ typesToDisplay.remove(type);
+ }
+
+ for (IShowAnnotationsListener listener : listeners) {
+ listener.selectionChanged(getSelectedTypes());
+ }
+ }
+ });
+ }
+
+ public Collection<Type> getSelectedTypes() {
+ Collection<Type> selectedTypes = new LinkedList<Type>();
+
+ if (editorAnnotationMode != null) {
+ selectedTypes.add(editorAnnotationMode);
+ }
+
+ for (Type type : typesToDisplay) {
+ selectedTypes.add(type);
+ }
+
+ return Collections.unmodifiableCollection(selectedTypes);
+ }
+
+ public void setSelectedTypes(Collection<Type> types) {
+ typesToDisplay = new HashSet<Type>();
+
+ for (Type type : types) {
+ typesToDisplay.add(type);
+ }
+
+ for (IShowAnnotationsListener listener : listeners) {
+ listener.selectionChanged(getSelectedTypes());
+ }
+ }
+
+ public void setEditorAnnotationMode(Type newMode) {
+
+ if (typesToDisplay.contains(newMode)) {
+ if (editorAnnotationMode != null) {
+ editorAnnotationMode = null;
+ for (IShowAnnotationsListener listener : listeners) {
+ listener.selectionChanged(getSelectedTypes());
+ }
+ }
+ } else {
+ editorAnnotationMode = newMode;
+
+ for (IShowAnnotationsListener listener : listeners) {
+ listener.selectionChanged(getSelectedTypes());
+ }
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/TypeMenu.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/TypeMenu.java?rev=697817&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/TypeMenu.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/TypeMenu.java Mon Sep 22 06:25:28 2008
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.editor.contextmenu;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+
+/**
+ * Abstract base class for menus which display the type hierarchy.
+ */
+abstract class TypeMenu extends ContributionItem {
+ private Type mParentType;
+
+ private TypeSystem mTypeSystem;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param parentType
+ * @param typeSystem
+ */
+ TypeMenu(Type parentType, TypeSystem typeSystem) {
+ mParentType = parentType;
+ mTypeSystem = typeSystem;
+ }
+
+ /**
+ * Fills the menu with type entries.
+ *
+ * @param menu
+ * @param index
+ */
+ @Override
+ public void fill(Menu menu, int index) {
+ fillTypeMenu(mParentType, menu, false);
+ }
+
+ private void fillTypeMenu(Type parentType, Menu parentMenu,
+ boolean isParentIncluded) {
+
+ List<Type> childs = mTypeSystem.getDirectSubtypes(parentType);
+
+ Menu newSubMenu;
+
+ // has this type sub types ?
+ // yes
+ if (childs.size() != 0) {
+
+ if (isParentIncluded) {
+ MenuItem subMenuItem = new MenuItem(parentMenu, SWT.CASCADE);
+ subMenuItem.setText(parentType.getShortName());
+
+ newSubMenu = new Menu(subMenuItem);
+ subMenuItem.setMenu(newSubMenu);
+ }
+ else {
+ newSubMenu = parentMenu;
+ }
+
+ insertAction(parentType, newSubMenu);
+
+ Iterator<Type> childsIterator = childs.iterator();
+
+ while (childsIterator.hasNext()) {
+ Type child = childsIterator.next();
+
+ fillTypeMenu(child, newSubMenu, true);
+ }
+ }
+ // no
+ else {
+ insertAction(parentType, parentMenu);
+ }
+ }
+
+ /**
+ * Implementing classes must implement this method to insert
+ * actions into the type menu.
+ *
+ * @param type
+ * @param parentMenu
+ */
+ protected abstract void insertAction(final Type type, Menu parentMenu);
+
+ }
\ No newline at end of file
Propchange: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/TypeMenu.java
------------------------------------------------------------------------------
svn:mime-type = text/plain