You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2019/07/19 13:39:31 UTC

svn commit: r1863391 - /uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/

Author: schor
Date: Fri Jul 19 13:39:30 2019
New Revision: 1863391

URL: http://svn.apache.org/viewvc?rev=1863391&view=rev
Log:
[UIMA-6094] when switching to Tree from TableTree, the setSelection no longer silently ignores out-of-bounds indexes, so check for validity before trying to set the selection

Modified:
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractImportablePartSection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/CapabilitySection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/IndexSection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterDelegatesSection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterSection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/PriorityListSection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/SofaMapSection.java
    uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractImportablePartSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractImportablePartSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractImportablePartSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractImportablePartSection.java Fri Jul 19 13:39:30 2019
@@ -25,7 +25,6 @@ import org.apache.uima.resource.metadata
 import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.taeconfigurator.editors.MultiPageEditor;
 import org.apache.uima.taeconfigurator.model.BuiltInTypes;
-import org.eclipse.swt.custom.TableTreeItem;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.TreeItem;
 

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java Fri Jul 19 13:39:30 2019
@@ -2552,4 +2552,20 @@ implements Listener, StandardStrings {
       return "sorted";
     return indexKind;
   }
+  
+  /**
+   * set the selection one above this item, unless it's the top one already.
+   * Used when removing the item
+   */
+  public static void setSelectionOneUp(Tree tt, TreeItem item) {
+    int itemIndex = tt.indexOf(item);
+    maybeSetSelection(tt, itemIndex - 1);
+  }
+  
+  public static void maybeSetSelection(Tree tt, int itemIndex) {
+    TreeItem[] items = tt.getItems();
+    if (itemIndex >= 0 && itemIndex < items.length) {
+      tt.setSelection(items[itemIndex]);
+    }
+  }
 }

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/CapabilitySection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/CapabilitySection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/CapabilitySection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/CapabilitySection.java Fri Jul 19 13:39:30 2019
@@ -44,8 +44,6 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.swt.widgets.TreeItem;
@@ -235,7 +233,7 @@ public class CapabilitySection extends A
         TreeItem item = new TreeItem(tt, SWT.NONE);
         item.setText(TITLE_COL, CAPABILITY_SET);
         item.setData(cs[i]);
-        tt.setSelection(new TreeItem[] { item }); // set default selection
+        tt.setSelection( item ); // set default selection
         fillCapability(item, cs[i]);
         // if (0 == i) {
         item.setExpanded(true);
@@ -541,7 +539,7 @@ public class CapabilitySection extends A
     createSofaHeaderGui(item);
 
     item.setExpanded(true);
-    tt.setSelection(new TreeItem[] { item });
+    tt.setSelection( item );
     if (tt.getItemCount() == 1)
       tt.getColumn(TITLE_COL).pack();
     finishAction();
@@ -769,17 +767,14 @@ public class CapabilitySection extends A
    * @param itemKind the item kind
    */
   private void handleRemove(TreeItem removeItem, int itemKind) {
-//    Table table = tt.getTable();
-//    int previousSelection = tt.getSelectionIndex() - 1;
     int selectionIndex = tt.indexOf(tt.getSelection()[0]);
-    int previousSelection = selectionIndex - 1;
     Capability c = getCapability(removeItem);
     switch (itemKind) {
       case CS: {
         if (Window.CANCEL == Utility.popOkCancel("Confirm Remove",
                 "This action will remove an entire capability set.  Please confirm.",
                 MessageDialog.WARNING)) {
-          tt.setSelection(tt.getItems()[selectionIndex + 1]);
+          maybeSetSelection(tt, selectionIndex + 1);
           return;
         }
         removeCapabilitySet(c);
@@ -798,7 +793,7 @@ public class CapabilitySection extends A
                         "Confirm Removal of Sofa",
                         "This action will remove this Sofa as a capability, and delete its mappings if no other capability set declares this Sofa."
                                 + "  Please confirm.", MessageDialog.WARNING)) {
-          tt.setSelection(tt.getItems()[selectionIndex + 1]);
+          maybeSetSelection(tt, selectionIndex + 1);
           return;
         }
         String sofaName = removeItem.getText(NAME_COL);
@@ -834,7 +829,7 @@ public class CapabilitySection extends A
         if (Window.CANCEL == Utility.popOkCancel("Confirm Removal of Type",
                 "This action will remove this type as a capability.  Please confirm.",
                 MessageDialog.WARNING)) {
-          tt.setSelection(tt.getItems()[selectionIndex + 1]);
+          maybeSetSelection(tt, selectionIndex + 1);
           return;
         }
         TreeItem[] features = removeItem.getItems();
@@ -859,7 +854,7 @@ public class CapabilitySection extends A
         throw new InternalErrorCDE("invalid state");
     }
 
-    tt.setSelection(tt.getItems()[previousSelection]);
+    maybeSetSelection(tt, selectionIndex - 1);
     finishAction();
   }
 
@@ -1160,7 +1155,7 @@ public class CapabilitySection extends A
     }
     parentItem.setExpanded(true);
     tt.getColumn(NAME_COL).pack();
-    tt.setSelection(new TreeItem[] { parentItem });
+    tt.setSelection( parentItem );
 
     c.setInputs(replaceFeaturesKeepingTypes(c.getInputs(), typeName, inputsL));
     c.setOutputs(replaceFeaturesKeepingTypes(c.getOutputs(), typeName, outputsL));

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/IndexSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/IndexSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/IndexSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/IndexSection.java Fri Jul 19 13:39:30 2019
@@ -34,7 +34,6 @@ import org.apache.uima.taeconfigurator.w
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.TableTreeItem;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
@@ -282,8 +281,8 @@ public class IndexSection extends Abstra
 
       updateIndexSpec(new TreeItem(tt, SWT.NONE), id);
 
-      TreeItem[] items = tt.getItems();
-      tt.setSelection(items[items.length - 1]);
+      
+      maybeSetSelection(tt, tt.getItemCount() - 1);
       packTree(tt);
       setFileDirty();
     } else if (event.widget == addKeyButton) {
@@ -322,9 +321,8 @@ public class IndexSection extends Abstra
         FsIndexDescription fsid = getFsIndexDescriptionFromTableTreeItem(parent);
         removeFsIndexKeyDescription(fsid, (FsIndexKeyDescription) o);
       }
-      TreeItem selectionItem = tt.getSelection()[0];
+      setSelectionOneUp(tt, item);
 //      tt.setSelection(tt.getTable().getSelectionIndex() - 1);
-      tt.setSelection(tt.getItems()[tt.indexOf(selectionItem) - 1]);
       item.dispose();
       setFileDirty();
     } else if (event.widget == editButton || event.type == SWT.MouseDoubleClick) {
@@ -549,8 +547,9 @@ public class IndexSection extends Abstra
     downButton.setEnabled(false);
     if (selected) {
       if (null != parent && notBuiltInSelected) {
-        TreeItem firstItem = parent.getItems()[0];
-        TreeItem lastItem = parent.getItems()[parent.getItems().length - 1];
+        TreeItem[] items = parent.getItems();
+        TreeItem firstItem = items[0];
+        TreeItem lastItem = items[items.length - 1];
         upButton.setEnabled(item != firstItem);
         downButton.setEnabled(item != lastItem);
       }

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterDelegatesSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterDelegatesSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterDelegatesSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterDelegatesSection.java Fri Jul 19 13:39:30 2019
@@ -137,10 +137,7 @@ public class ParameterDelegatesSection e
       if (null != fcd) {
         addDelegateToGUI(fcd.getKey(), fcd.getSpecifier());
       }
-      TreeItem[] items = tree.getItems();
-      if (items.length > 0)
-        // scrolls to top, also
-        tree.setSelection(new TreeItem[] { items[0] });
+      maybeSetSelection(tree, 0);
     }
     enable();
   }

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterSection.java Fri Jul 19 13:39:30 2019
@@ -298,7 +298,7 @@ public class ParameterSection extends Ab
     splitGroupNames = false;
     clearAndRefillTree(usingGroupsButton.getSelection());
 
-    tree.setSelection(new TreeItem[] { tree.getItems()[0] });
+    maybeSetSelection(tree, 0);
     enable();
 
     // sync settings page to catch use case of switching from sourceEditor
@@ -784,7 +784,7 @@ public class ParameterSection extends Ab
     // fill(commonParms, item); // don't add common parsm, they're added by definition
     addGroupToModel(cg);
     cg.setNames(groupNameArray);
-    tree.setSelection(new TreeItem[] { item });
+    tree.setSelection( item );
     return new ConfigGroup(cpd, cg);
   }
 
@@ -858,7 +858,7 @@ public class ParameterSection extends Ab
 
     }
 
-    tree.setSelection(new TreeItem[] { item });
+    tree.setSelection( item );
     return true;
   }
 

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/PriorityListSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/PriorityListSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/PriorityListSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/PriorityListSection.java Fri Jul 19 13:39:30 2019
@@ -135,8 +135,7 @@ public class PriorityListSection extends
         item.setExpanded(true);
       }
     }
-    if (tree.getItemCount() > 0)
-      tree.setSelection(new TreeItem[] { tree.getItems()[0] });
+    maybeSetSelection(tree, 0);
     enable();
   }
 
@@ -172,7 +171,7 @@ public class PriorityListSection extends
       TreeItem item = new TreeItem(tree, SWT.NONE);
       item.setText(PRIORITY_LIST);
 
-      tree.setSelection(new TreeItem[] { item });
+      tree.setSelection( item );
       setFileDirty();
     } else if (event.widget == addButton) { // add type to set
       if (editor.isTypePriorityDescriptor() && !editor.getIsContextLoaded()) {
@@ -235,7 +234,7 @@ public class PriorityListSection extends
       TreeItem previousSelection = getPreviousSelection(parent == null ? tree.getItems() : parent
               .getItems(), item);
       if (null != previousSelection)
-        tree.setSelection(new TreeItem[] { previousSelection });
+        tree.setSelection(previousSelection);
       item.dispose();
       setFileDirty();
     }
@@ -257,7 +256,7 @@ public class PriorityListSection extends
         new TreeItem(parent, SWT.NONE, i).setText(formatName(types[i]));
         TreeItem t = new TreeItem(parent, SWT.NONE, i + 1);
         t.setText(formatName(types[i + 1]));
-        tree.setSelection(new TreeItem[] { t });
+        tree.setSelection( t);
 
         items[i].dispose();
         items[i + 1].dispose();
@@ -268,7 +267,7 @@ public class PriorityListSection extends
 
         TreeItem t = new TreeItem(parent, SWT.NONE, i - 1);
         t.setText(formatName(types[i - 1]));
-        tree.setSelection(new TreeItem[] { t });
+        tree.setSelection( t);
         new TreeItem(parent, SWT.NONE, i).setText(formatName(types[i]));
 
         items[i - 1].dispose();

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/SofaMapSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/SofaMapSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/SofaMapSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/SofaMapSection.java Fri Jul 19 13:39:30 2019
@@ -146,7 +146,7 @@ public class SofaMapSection extends Abst
 
       fillMap(inputAggrSofas, INPUT);
       fillMap(outputSofaNames, OUTPUT);
-      tree.setSelection(new TreeItem[] { tree.getItems()[0] });
+      maybeSetSelection(tree, 0);
 
       if (0 == (inputAggrSofas.length + outputSofaNames.length)) {
         getSection().setText("Sofa Mappings (No Sofas are defined)");

Modified: uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java?rev=1863391&r1=1863390&r2=1863391&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java Fri Jul 19 13:39:30 2019
@@ -548,7 +548,7 @@ public class TypeSection extends Abstrac
     TreeItem[] items = tt.getItems();
     for (int i = 0; i < items.length; i++) {
       if (td.getName().equals(((TypeDescription) items[i].getData()).getName())) {
-        tt.setSelection(new TreeItem[] { items[i] });
+        tt.setSelection( items[i]);
         return;
       }
     }
@@ -1009,9 +1009,7 @@ public class TypeSection extends Abstrac
       removeAllowedValue(td, av);
 
       // update GUI
-      TreeItem selectedItem = tt.getSelection()[0];
-      tt.setSelection(tt.getItems()[tt.indexOf(selectedItem) - 1]);
-//      tt.setSelection(tt.getTable().getSelectionIndex() - 1);
+      setSelectionOneUp(tt, item);
       item.dispose();
     } else {
       refresh();
@@ -1028,7 +1026,7 @@ public class TypeSection extends Abstrac
    * @param item the item
    */
   // same - for built-in <could be created outside of the CDE>
-  private void handleRemoveFeature(TreeItem item) {
+  private void handleRemoveFeature(final TreeItem item) {
     TypeDescription td = getTypeDescriptionFromTableTreeItem(item.getParentItem());
     FeatureDescription fd = getFeatureDescriptionFromTableTreeItem(item);
 
@@ -1055,8 +1053,7 @@ public class TypeSection extends Abstrac
         refresh();
       else {
         // update GUI
-        TreeItem selectedItem = tt.getSelection()[0];
-        tt.setSelection(tt.getItems()[tt.indexOf(selectedItem) - 1]);    
+        setSelectionOneUp(tt, item);
 //        tt.getTable().setSelection(tt.getTable().getSelectionIndex() - 1);
         item.dispose();
       }
@@ -1156,7 +1153,7 @@ public class TypeSection extends Abstrac
    *
    * @param item the item
    */
-  private void handleRemoveType(TreeItem item) {
+  private void handleRemoveType(final TreeItem item) {
 
     TypeDescription td = getTypeDescriptionFromTableTreeItem(item);
 
@@ -1190,9 +1187,7 @@ public class TypeSection extends Abstrac
     } else {
       removeType(td, getMergedTypeSystemDescription());
       // update GUI
-      TreeItem selectedItem = tt.getSelection()[0];
-      tt.setSelection(tt.getItems()[tt.indexOf(selectedItem) - 1]);
-//      tt.getTable().setSelection(tt.getTable().getSelectionIndex() - 1);
+      setSelectionOneUp(tt, item);
       item.dispose();
     }