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 2006/12/13 22:11:54 UTC

svn commit: r486840 - in /incubator/uima/uimaj/trunk/uimaj-ep-configurator: META-INF/ src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/

Author: schor
Date: Wed Dec 13 13:11:52 2006
New Revision: 486840

URL: http://svn.apache.org/viewvc?view=rev&rev=486840
Log:
UIMA-2 Content Assist and CAS Type Picker now converted to
non EPL derivative works.  The Content Assist uses
Eclipse 3.2 features, won't work with 3.1.  Still need to
handle this (by testing and not having content assist).

Added:
    incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/SelectTypeDialog.java
    incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/TypesWithNameSpaces.java
Modified:
    incubator/uima/uimaj/trunk/uimaj-ep-configurator/META-INF/MANIFEST.MF
    incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AbstractDialog.java
    incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddFeatureDialog.java
    incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddIndexDialog.java
    incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddTypeDialog.java

Modified: incubator/uima/uimaj/trunk/uimaj-ep-configurator/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/META-INF/MANIFEST.MF?view=diff&rev=486840&r1=486839&r2=486840
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/META-INF/MANIFEST.MF (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/META-INF/MANIFEST.MF Wed Dec 13 13:11:52 2006
@@ -7,17 +7,14 @@
 Bundle-Activator: org.eclipse.core.internal.compatibility.PluginActivator
 Bundle-Vendor: The Apache Software Foundation
 Bundle-Localization: plugin
-Export-Package: .,
- org.apache.uima.taeconfigurator,
+Export-Package: org.apache.uima.taeconfigurator,
  org.apache.uima.taeconfigurator.editors,
  org.apache.uima.taeconfigurator.editors.ui,
  org.apache.uima.taeconfigurator.editors.ui.dialogs,
  org.apache.uima.taeconfigurator.editors.xml,
  org.apache.uima.taeconfigurator.files,
  org.apache.uima.taeconfigurator.model,
- org.apache.uima.taeconfigurator.wizards,
- org.apache.uima.typesystem,
- org.apache.uima.typesystem.contentassist
+ org.apache.uima.taeconfigurator.wizards
 Require-Bundle: org.eclipse.core.runtime.compatibility,
  org.eclipse.ui.ide,
  org.eclipse.jface.text,

Modified: incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AbstractDialog.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AbstractDialog.java?view=diff&rev=486840&r1=486839&r2=486840
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AbstractDialog.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AbstractDialog.java Wed Dec 13 13:11:52 2006
@@ -19,14 +19,21 @@
 
 package org.apache.uima.taeconfigurator.editors.ui.dialogs;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Set;
 
+import org.apache.uima.taeconfigurator.StandardStrings;
+import org.apache.uima.taeconfigurator.editors.MultiPageEditor;
+import org.apache.uima.taeconfigurator.editors.MultiPageEditorContributor;
+import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.jface.bindings.keys.ParseException;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.TextContentAdapter;
+import org.eclipse.jface.fieldassist.TextControlCreator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.events.KeyEvent;
@@ -45,17 +52,19 @@
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swt.widgets.Text;
-
-import org.apache.uima.taeconfigurator.StandardStrings;
-import org.apache.uima.taeconfigurator.editors.MultiPageEditor;
-import org.apache.uima.taeconfigurator.editors.MultiPageEditorContributor;
-import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
-import org.apache.uima.typesystem.ITypeSystemInfo;
-import org.apache.uima.typesystem.OpenTypeSystemSelectionDialog;
-import org.apache.uima.typesystem.contentassist.ControlContentAssistHelper;
-import org.apache.uima.typesystem.contentassist.TypeSystemCompletionProcessor;
+import org.eclipse.ui.fieldassist.ContentAssistField;
 
 public abstract class AbstractDialog extends Dialog implements Listener, StandardStrings {
+  
+  public final static char[] contentAssistActivationChars  = new char[0];
+  public final static KeyStroke contentAssistActivationKey;
+  static {
+    try {
+      contentAssistActivationKey = KeyStroke.getInstance("Ctrl+Space");
+    } catch (ParseException e) {
+      throw new RuntimeException(e);
+    }
+  }
 
   protected MultiPageEditor editor;
 
@@ -224,7 +233,7 @@
    * @return
    */
   protected Table newTable(Composite parent, int style) {
-    Table table = new Table(parent, style);
+    Table table = new Table(parent, style | SWT.BORDER);
     GridData gd = new GridData(GridData.FILL_BOTH);
     table.setLayoutData(gd);
     table.addListener(SWT.Selection, this);
@@ -332,38 +341,63 @@
     return allTypes;
   }
 
-  protected Text newLabeledTypeInput(Composite parent, String label, String tip) {
+  protected Text newLabeledTypeInput(AbstractSection aSection, Composite parent, String label, String tip) {
     setTextAndTip(new Label(parent, SWT.NONE), label, tip);
-    return newTypeInput(parent);
+    return newTypeInput(aSection, parent);
   }
 
   /**
    * @param twoCol
    */
-  protected Text newTypeInput(Composite twoCol) {
+  protected Text newTypeInput(AbstractSection aSection, Composite twoCol) {
     Composite tc = new2ColumnComposite(twoCol);
-    final Text text = newText(tc, SWT.NONE,
-            "Enter a Type name. Content Assist is available (press Ctrl + Space)");
-    final ArrayList candidatesToPickFrom = getTypeSystemInfoList(); // provide an ArrayList of
-    // ITypeSystemInfo
+    final TypesWithNameSpaces candidatesToPickFrom = getTypeSystemInfoList(); // provide an ArrayList of
+
+    ContentAssistField caf = new ContentAssistField(tc, SWT.BORDER, new TextControlCreator(), 
+            new TextContentAdapter(), candidatesToPickFrom,
+            null, null);
+    caf.getContentAssistCommandAdapter().setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
+    final Text text = (Text)caf.getControl();
+    text.setToolTipText("Enter a Type name. Content Assist is available on Eclipse 3.2 and beyond (press Ctrl + Space)");
+    text.getParent().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+    text.addListener(SWT.KeyUp, this);
+    text.addListener(SWT.MouseUp, this); // for paste operation
+    
+//    newText(tc, SWT.NONE,
+//    "Enter a Type name. Content Assist is available on Eclipse 3.2 and beyond (press Ctrl + Space)");
+
+//    ContentProposalAdapter adapter = new ContentProposalAdapter(
+//            text, new TextContentAdapter(),
+//            candidatesToPickFrom,
+//            contentAssistActivationKey, 
+//            contentAssistActivationChars);
+//    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
+    
     Button browseButton = newPushButton(tc, "Browse", "Click here to browse possible types");
     browseButton.removeListener(SWT.Selection, this);
+    final AbstractSection finalSection = aSection;
     browseButton.addListener(SWT.Selection, new Listener() {
       public void handleEvent(Event event) {
         errorMessageUI.setText("");
-        ArrayList typeList = candidatesToPickFrom;
-        OpenTypeSystemSelectionDialog dialog = new OpenTypeSystemSelectionDialog(getShell(),
-                typeList);
+        SelectTypeDialog dialog = new SelectTypeDialog(finalSection, candidatesToPickFrom); 
+//          OpenTypeSystemSelectionDialog dialog = 
+//              new OpenTypeSystemSelectionDialog(getShell(), typeList);
         if (dialog.open() != IDialogConstants.OK_ID)
           return;
+        
+        text.setText(dialog.nameSpaceName + "." + dialog.typeName);
+        enableOK();
+    /*
         Object[] types = dialog.getResult();
         if (types != null && types.length > 0) {
           ITypeSystemInfo selectedType = (ITypeSystemInfo) types[0];
           text.setText(selectedType.getFullName());
           enableOK();
         }
+    */
       }
     });
+    /*
     TypeSystemCompletionProcessor processor = new TypeSystemCompletionProcessor(
             candidatesToPickFrom);
     ControlContentAssistHelper.createTextContentAssistant(text, processor);
@@ -377,23 +411,28 @@
         textModifyCallback(e);
       }
     });
+    */
     return text;
   }
 
   public void textModifyCallback(Event e) {
   }
-
+ 
   // default implementation - always overridden when used
-  public ArrayList getTypeSystemInfoList() {
-    return new ArrayList();
+  public TypesWithNameSpaces getTypeSystemInfoList() {
+    return new TypesWithNameSpaces();
   }
 
-  protected boolean typeContainedInTypeSystemInfoList(String fullTypeName, List infoList) {
-    for (Iterator it = infoList.iterator(); it.hasNext();) {
-      if (fullTypeName.equals(((ITypeSystemInfo) it.next()).getFullName()))
-        return true;
-    }
-    return false;
+  protected boolean typeContainedInTypeSystemInfoList(String fullTypeName, TypesWithNameSpaces types) {
+    String key = AbstractSection.getShortName(fullTypeName);
+    String nameSpace = AbstractSection.getNameSpace(fullTypeName);
+    
+    Set s = (Set)types.sortedNames.get(key);
+    
+    if (null == s) 
+      return false;
+    
+    return s.contains(nameSpace);
   }
 
   /**

Modified: incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddFeatureDialog.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddFeatureDialog.java?view=diff&rev=486840&r1=486839&r2=486840
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddFeatureDialog.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddFeatureDialog.java Wed Dec 13 13:11:52 2006
@@ -19,11 +19,11 @@
 
 package org.apache.uima.taeconfigurator.editors.ui.dialogs;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
+import org.apache.uima.cas.Type;
+import org.apache.uima.resource.metadata.FeatureDescription;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
+import org.apache.uima.taeconfigurator.editors.ui.TypeSection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.custom.StyledText;
@@ -34,13 +34,6 @@
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Text;
 
-import org.apache.uima.cas.Type;
-import org.apache.uima.resource.metadata.FeatureDescription;
-import org.apache.uima.resource.metadata.TypeDescription;
-import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
-import org.apache.uima.taeconfigurator.editors.ui.TypeSection;
-import org.apache.uima.typesystem.TypeSystemInfo;
-
 public class AddFeatureDialog extends AbstractDialogKeyVerify {
 
   private static final int ONLY_NON_PRIMITIVE_TYPES = 0;
@@ -71,7 +64,7 @@
 
   private FeatureDescription existingFd;
 
-  private List allTypesList;
+  private TypesWithNameSpaces allTypesList;
 
   private Composite multiRefComposite;
 
@@ -112,7 +105,7 @@
     featureNameUI = newLabeledSingleLineStyledText(twoCol, "Feature Name", S_);
 
     typeFilter = ALL_TYPES;
-    featureRangeNameUI = newLabeledTypeInput(twoCol, "Range Type:",
+    featureRangeNameUI = newLabeledTypeInput(section, twoCol, "Range Type:",
             "The range type specifies the type of value this feature can hold.");
 
     multiRefComposite = new2ColumnComposite(twoCol);
@@ -127,7 +120,7 @@
     elementTypeComposite = new2ColumnComposite(twoCol);
     ((GridData) elementTypeComposite.getLayoutData()).horizontalSpan = 2;
     typeFilter = ONLY_NON_PRIMITIVE_TYPES;
-    elementRangeNameUI = newLabeledTypeInput(elementTypeComposite, "Element Type:",
+    elementRangeNameUI = newLabeledTypeInput(section, elementTypeComposite, "Element Type:",
             "The element type of each element in the Array or List object");
 
     descriptionUI = newDescription(twoCol, S_);
@@ -162,10 +155,10 @@
     }
   }
 
-  public ArrayList getTypeSystemInfoList() {
-    ArrayList result = new ArrayList();
+  public TypesWithNameSpaces getTypeSystemInfoList() {
+    TypesWithNameSpaces result = new TypesWithNameSpaces();
     Type[] allTypes = (Type[]) editor.allTypes.get().values().toArray(new Type[0]);
-    Arrays.sort(allTypes, new Comparator() {
+/*    Arrays.sort(allTypes, new Comparator() {
 
       public int compare(Object o1, Object o2) {
         Type t1 = (Type) o1;
@@ -173,14 +166,15 @@
         return t1.getShortName().compareTo(t2.getShortName());
       }
     });
+    */
     for (int i = 0; i < allTypes.length; i++) {
       Type type = allTypes[i];
       if (typeFilter == ONLY_NON_PRIMITIVE_TYPES) {
         if (!type.isPrimitive()) {
-          result.add(new TypeSystemInfo(type.getName()));
+          result.add(type.getName());
         }
       } else {
-        result.add(new TypeSystemInfo(type.getName()));
+        result.add(type.getName());
       }
     }
     if (typeFilter == ALL_TYPES)

Modified: incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddIndexDialog.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddIndexDialog.java?view=diff&rev=486840&r1=486839&r2=486840
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddIndexDialog.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddIndexDialog.java Wed Dec 13 13:11:52 2006
@@ -22,6 +22,12 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.cas.admin.FSIndexComparator;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.FsIndexKeyDescription;
+import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
+import org.apache.uima.taeconfigurator.editors.ui.IndexSection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.custom.StyledText;
@@ -35,14 +41,6 @@
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swt.widgets.Text;
 
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.cas.admin.FSIndexComparator;
-import org.apache.uima.resource.metadata.FsIndexDescription;
-import org.apache.uima.resource.metadata.FsIndexKeyDescription;
-import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
-import org.apache.uima.taeconfigurator.editors.ui.IndexSection;
-import org.apache.uima.typesystem.TypeSystemInfo;
-
 public class AddIndexDialog extends AbstractDialogKeyVerifyJavaNames {
 
   private static final String TYPE_PRIORITY = "Type Priority";
@@ -128,7 +126,7 @@
     indexKindUI.add("set");
 
     new Label(twoCol, SWT.NONE).setText("CAS Type");
-    indexTypeUI = newTypeInput(twoCol);
+    indexTypeUI = newTypeInput(section, twoCol);
 
     setTextAndTip(
             keyTable = new Label(twoCol, SWT.NONE),
@@ -176,11 +174,11 @@
     return mainArea;
   }
 
-  public ArrayList getTypeSystemInfoList() {
-    ArrayList result = new ArrayList();
+  public TypesWithNameSpaces getTypeSystemInfoList() {
+    TypesWithNameSpaces result = new TypesWithNameSpaces();
     String[] allTypes = getAllTypesAsSortedArray();
     for (int i = 0; i < allTypes.length; i++) {
-      result.add(new TypeSystemInfo(allTypes[i]));
+      result.add(allTypes[i]);
     }
     return result;
   }

Modified: incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddTypeDialog.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddTypeDialog.java?view=diff&rev=486840&r1=486839&r2=486840
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddTypeDialog.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/AddTypeDialog.java Wed Dec 13 13:11:52 2006
@@ -19,11 +19,14 @@
 
 package org.apache.uima.taeconfigurator.editors.ui.dialogs;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
-import java.util.List;
 
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
+import org.apache.uima.taeconfigurator.editors.ui.TypeSection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.layout.GridData;
@@ -33,13 +36,6 @@
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.Type;
-import org.apache.uima.resource.metadata.TypeDescription;
-import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
-import org.apache.uima.taeconfigurator.editors.ui.TypeSection;
-import org.apache.uima.typesystem.TypeSystemInfo;
-
 public class AddTypeDialog extends AbstractDialogKeyVerifyJavaNames {
 
   private StyledText typeNameUI;
@@ -60,7 +56,7 @@
 
   private TypeDescription existingTd = null;
 
-  private List allTypesList;
+  private TypesWithNameSpaces allTypesList;
 
   // private boolean seenThisAlready = false;
 
@@ -99,7 +95,7 @@
     typeNameUI.setText("some.typename.you.Choose");
 
     new Label(twoCol, SWT.NONE).setText("Supertype:");
-    supertypeNameUI = newTypeInput(twoCol);
+    supertypeNameUI = newTypeInput(section, twoCol);
     descriptionUI = newDescription(twoCol, S_);
     newErrorMessage(twoCol, 2);
 
@@ -122,15 +118,15 @@
    * 
    * @see org.apache.uima.taeconfigurator.editors.ui.dialogs.AbstractDialog#getTypeSystemInfoList()
    */
-  public ArrayList getTypeSystemInfoList() {
-    ArrayList result = new ArrayList();
+  public TypesWithNameSpaces getTypeSystemInfoList() {
+    TypesWithNameSpaces result = new TypesWithNameSpaces();
     boolean hasFeatures = false;
     boolean hasAllowedValues = false;
     if (null != existingTd) {
       hasFeatures = ((null != existingTd.getFeatures()) && (existingTd.getFeatures().length > 0));
       hasAllowedValues = ((null != existingTd.getAllowedValues()) && (existingTd.getAllowedValues().length > 0));
       if (hasAllowedValues) {
-        result.add(new TypeSystemInfo(CAS.TYPE_NAME_STRING));
+        result.add(CAS.TYPE_NAME_STRING);
         allTypesList = result;
         return result;
       }
@@ -150,7 +146,7 @@
         continue;
       if (hasFeatures && CAS.TYPE_NAME_STRING.equals(type.getName()))
         continue;
-      result.add(new TypeSystemInfo(type.getName()));
+      result.add(type.getName());
     }
     allTypesList = result;
     return result;

Added: incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/SelectTypeDialog.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/SelectTypeDialog.java?view=auto&rev=486840
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/SelectTypeDialog.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/SelectTypeDialog.java Wed Dec 13 13:11:52 2006
@@ -0,0 +1,172 @@
+/*
+ * 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.taeconfigurator.editors.ui.dialogs;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+
+public class SelectTypeDialog extends AbstractDialog {
+
+  private Text typeNameUI;
+  private Table matchingTypesUI;
+  private Table nameSpacesUI;
+  public String typeName = "error-TypeName-never-set";
+  public String nameSpaceName = "error-NameSpaceName-never-set";
+  private TypesWithNameSpaces types;
+  /**
+   * @param aSection
+   * @param title
+   * @param description
+   */
+  public SelectTypeDialog(AbstractSection section, TypesWithNameSpaces types) {
+    super(section, "Select Type Name", "Select an Existing CAS Type name from the set of defined types");
+    this.types = types;
+  }
+
+  /*
+   * (non-Javadoc)
+   * @see org.apache.uima.taeconfigurator.editors.ui.dialogs.AbstractDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+   * 
+   * Use labels on left (2 column layout)
+   * Create a text input area labeled: Type:
+   * Create a list output area labeled: Matching:
+   * Create a list output area labeled: NameSpaces:
+   * Bottom gets normal OK / Cancel buttons
+   */
+  protected Control createDialogArea(Composite parent) {
+    Composite mainArea = (Composite)super.createDialogArea(parent);
+    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.SINGLE);
+    ((GridData)matchingTypesUI.getLayoutData()).heightHint = 250;
+    ((GridData)matchingTypesUI.getLayoutData()).minimumHeight = 100;
+    typeNameUI.addListener(SWT.Selection, this);
+
+    
+    createWideLabel(mainArea, "NameSpaces:");
+    
+    nameSpacesUI = newTable(mainArea, SWT.SINGLE);
+    ((GridData)nameSpacesUI.getLayoutData()).heightHint = 75;
+    ((GridData)nameSpacesUI.getLayoutData()).minimumHeight = 40;
+    
+    displayFilteredTypes("");
+        
+    return mainArea;
+  }
+   
+  private void displayFilteredTypes(String aTypeName) {
+    matchingTypesUI.setRedraw(false);
+    matchingTypesUI.removeAll();
+    Map.Entry topEntry = null;
+    aTypeName = aTypeName.toLowerCase();
+    for (Iterator it = types.sortedNames.entrySet().iterator(); it.hasNext();) {
+      Map.Entry entry = (Map.Entry) it.next();
+      String candidateTypeName = ((String)entry.getKey()).toLowerCase();
+      if (candidateTypeName.startsWith(aTypeName)) {
+        if (null == topEntry)
+          topEntry = entry;
+        TableItem item = new TableItem(matchingTypesUI, SWT.NULL);
+        item.setText((String) entry.getKey());
+        item.setData(entry);
+      }
+    }
+    if (matchingTypesUI.getItemCount() > 0) {
+      matchingTypesUI.select(0);
+      displayNameSpacesForSelectedItem(topEntry);
+    }
+    
+    matchingTypesUI.setRedraw(true);    
+  }
+
+  private void displayNameSpacesForSelectedItem(Map.Entry entry) {
+    Set nameSpaces = (Set)entry.getValue();
+    nameSpacesUI.removeAll();
+    for (Iterator it = nameSpaces.iterator(); it.hasNext();) {
+      String nameSpace = (String) it.next();
+      TableItem item = new TableItem(nameSpacesUI, SWT.NULL);
+      item.setText(nameSpace);
+      item.setData(entry);
+    }
+    if (nameSpacesUI.getItemCount() > 0) {
+      nameSpacesUI.select(0);
+    }
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.taeconfigurator.editors.ui.dialogs.AbstractDialog#handleEvent(org.eclipse.swt.widgets.Event)
+   */
+  public void handleEvent(Event event) {
+    if (event.widget == typeNameUI && event.type == SWT.Modify) {
+      typeName = typeNameUI.getText(); 
+      displayFilteredTypes(typeName);
+    }
+    
+    else if (event.widget == matchingTypesUI && event.type == SWT.Selection) {
+      displayNameSpacesForSelectedItem(
+              (Map.Entry)(matchingTypesUI.getSelection()[0].getData()));
+    }
+    enableOK();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.taeconfigurator.editors.ui.dialogs.AbstractDialog#copyValuesFromGUI()
+   */
+  public void copyValuesFromGUI() {
+    if (0 < matchingTypesUI.getSelectionCount()) {
+      typeName = matchingTypesUI.getSelection()[0].getText();
+    }
+    if (0 < nameSpacesUI.getSelectionCount()) {
+      nameSpaceName = nameSpacesUI.getSelection()[0].getText();
+    }
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.taeconfigurator.editors.ui.dialogs.AbstractDialog#enableOK()
+   */
+  public void enableOK() {
+    copyValuesFromGUI();
+    okButton.setEnabled( (0 < nameSpacesUI.getSelectionCount()) &&
+                         (0 < matchingTypesUI.getSelectionCount()));
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.taeconfigurator.editors.ui.dialogs.AbstractDialog#isValid()
+   */
+  public boolean isValid() {
+    return true;
+  }
+
+}

Added: incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/TypesWithNameSpaces.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/TypesWithNameSpaces.java?view=auto&rev=486840
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/TypesWithNameSpaces.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/dialogs/TypesWithNameSpaces.java Wed Dec 13 13:11:52 2006
@@ -0,0 +1,152 @@
+/*
+ * 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.taeconfigurator.editors.ui.dialogs;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+
+public class TypesWithNameSpaces implements IContentProposalProvider {
+
+  public SortedMap sortedNames = new TreeMap();
+  
+  private CasTypeProposal [] proposalArray = null;
+  
+  public static class CasTypeProposal 
+      implements IContentProposal, Comparable {
+    private final String labelForm;
+    private final String fullName;
+    private final String compareKey;
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.fieldassist.IContentProposal#getContent()
+     */
+    CasTypeProposal(String aCompareKey, String shortName, String nameSpace) {
+      fullName = (null == nameSpace)? shortName : nameSpace + "." + shortName;
+      labelForm = (null == nameSpace)? shortName : shortName + " - " + nameSpace;
+      compareKey = aCompareKey.toLowerCase();
+    }
+       
+    public String getContent() {
+      return fullName;
+    }
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.fieldassist.IContentProposal#getCursorPosition()
+     */
+    public int getCursorPosition() {
+      return fullName.length();
+    }
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.fieldassist.IContentProposal#getDescription()
+     */
+    public String getDescription() {
+      return null;
+    }
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.fieldassist.IContentProposal#getLabel()
+     */
+    public String getLabel() {
+      if (labelForm.toLowerCase().startsWith(compareKey))
+        return labelForm;
+      else
+        return fullName;
+    }
+    
+    public String getCompareKey() {
+      return compareKey;
+    }
+    /* (non-Javadoc)
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    public int compareTo(Object arg0) throws ClassCastException {
+        final CasTypeProposal c = (CasTypeProposal) arg0;
+        return this.compareKey.compareTo(c.getCompareKey()); 
+    }
+  }
+  
+  public void add(String fullname) {
+    String key = AbstractSection.getShortName(fullname);
+    String nameSpace = AbstractSection.getNameSpace(fullname);
+    Set entry = (Set) sortedNames.get(key);
+    if (null == entry) {
+      entry = new TreeSet();
+      entry.add(nameSpace);
+      sortedNames.put(key, entry);
+    } else {
+      entry.add(nameSpace);
+    }
+  }
+
+  private void createProposalArray() {
+    List r = new ArrayList(sortedNames.size()*2);
+    
+    // item a.b.c.name creates 2 entries in the suggestions:
+    //   compare key: a.b.c.name  label:  name - a.b.c    content: a.b.c.name
+    //   compare key: name        label:  name - a.b.c    content: a.b.c.name 
+    
+    for (Iterator it = sortedNames.entrySet().iterator(); it.hasNext();) {
+      Map.Entry entry = (Map.Entry)it.next();
+      Set nameSpaces = (Set)entry.getValue();
+      for (Iterator nsi = nameSpaces.iterator(); nsi.hasNext();) {
+        String nameSpace = (String)nsi.next();
+        String shortName = (String)entry.getKey();
+        r.add(new CasTypeProposal(shortName, shortName, nameSpace));
+        if (null != nameSpace) {
+          r.add(new CasTypeProposal(nameSpace + "." + shortName, shortName, nameSpace));
+        }
+      }
+    }
+    proposalArray = (CasTypeProposal[])r.toArray(new CasTypeProposal[r.size()]);
+    Arrays.sort(proposalArray);
+  }
+  
+  /* (non-Javadoc)
+   * @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
+   */
+  public IContentProposal[] getProposals(String contents, int position) {
+    if (null == proposalArray)
+      createProposalArray();
+    String keyString = contents.substring(0, position).toLowerCase();
+    CasTypeProposal key = new CasTypeProposal(keyString, null, null); 
+    int i = Arrays.binarySearch(proposalArray, key);
+    
+    if (i < 0) {
+      i = Math.abs(i + 1);
+    }
+    List rl = new ArrayList(proposalArray.length - i);
+    for (; i < proposalArray.length; i++) {
+      if (proposalArray[i].getCompareKey().startsWith(keyString)) {
+        rl.add(proposalArray[i]);
+      } else
+        break;
+    }
+    return (CasTypeProposal[])rl.toArray(new CasTypeProposal[rl.size()]);
+  } 
+  
+}