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 2011/08/30 13:40:01 UTC

svn commit: r1163176 - in /uima/uimaj/trunk: uimaj-ep-cas-editor-ide/ uimaj-ep-cas-editor/schema/ uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/

Author: joern
Date: Tue Aug 30 11:40:00 2011
New Revision: 1163176

URL: http://svn.apache.org/viewvc?rev=1163176&view=rev
Log:
UIMA-2219 Document provider is now choosen based on IEditorInput

Modified:
    uima/uimaj/trunk/uimaj-ep-cas-editor-ide/plugin.xml
    uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.editor.exsd
    uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java
    uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
    uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java

Modified: uima/uimaj/trunk/uimaj-ep-cas-editor-ide/plugin.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/plugin.xml?rev=1163176&r1=1163175&r2=1163176&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor-ide/plugin.xml (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor-ide/plugin.xml Tue Aug 30 11:40:00 2011
@@ -101,12 +101,14 @@
             id="org.apache.uima.caseditor.TypeSystemLocationPropertyPage">
             </page>
 	</extension>
- <extension
-       point="org.apache.uima.caseditor.editor">
+ <extension point="org.apache.uima.caseditor.editor">
     <provider
-          class="org.apache.uima.caseditor.ide.DefaultCasDocumentProvider">
+    	  id="org.apache.uima.caseditor.ide.DefaultCasDocumentProvider"
+          class="org.apache.uima.caseditor.ide.DefaultCasDocumentProvider"
+          inputType="org.eclipse.ui.IFileEditorInput">
     </provider>
  </extension>
+ 
  <extension point="org.eclipse.ui.preferencePages">
     <page
           class="org.apache.uima.caseditor.editor.AnnotationEditorPreferencePage"

Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.editor.exsd
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.editor.exsd?rev=1163176&r1=1163175&r2=1163176&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.editor.exsd (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.editor.exsd Tue Aug 30 11:40:00 2011
@@ -1,25 +1,5 @@
 <?xml version='1.0' encoding='UTF-8'?>
-
-<!--
-	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.    
--->
-
-
+<!-- Schema file written by PDE -->
 <schema targetNamespace="org.apache.uima.caseditor.editor" xmlns="http://www.w3.org/2001/XMLSchema">
 <annotation>
       <appinfo>
@@ -72,13 +52,30 @@
          <attribute name="class" type="string" use="required">
             <annotation>
                <documentation>
-                  
+                  the qualified name of the document provider class
                </documentation>
                <appinfo>
                   <meta.attribute kind="java" basedOn="org.apache.uima.caseditor.editor.CasDocumentProvider:"/>
                </appinfo>
             </annotation>
          </attribute>
+         <attribute name="id" type="string" use="required">
+            <annotation>
+               <documentation>
+                  the unique id of this provider
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="inputType" type="string" use="required">
+            <annotation>
+               <documentation>
+                  a qualified editor input class name
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":org.eclipse.ui.IEditorInput"/>
+               </appinfo>
+            </annotation>
+         </attribute>
       </complexType>
    </element>
 

Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java?rev=1163176&r1=1163175&r2=1163176&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/CasEditorPlugin.java Tue Aug 30 11:40:00 2011
@@ -133,6 +133,10 @@ public class CasEditorPlugin extends Abs
   public static void log(Throwable t) {
     getDefault().getLog().log(new Status(IStatus.ERROR, ID, IStatus.OK, t.getMessage(), t));
   }
+  
+  public static void log(String message, Throwable t) {
+    getDefault().getLog().log(new Status(IStatus.ERROR, ID, IStatus.OK, message, t));
+  }
 
   public static void logError(String message) {
     getDefault().getLog().log(new Status(IStatus.ERROR, ID, message));

Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=1163176&r1=1163175&r2=1163176&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Tue Aug 30 11:40:00 2011
@@ -578,7 +578,7 @@ public final class AnnotationEditor exte
   @Override
   public void init(IEditorSite site, IEditorInput input) throws PartInitException {
     CasDocumentProvider provider =
-            CasDocumentProviderFactory.instance().getDocumentProvider();
+            CasDocumentProviderFactory.instance().getDocumentProvider(input);
     
     setDocumentProvider(provider);
     

Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java?rev=1163176&r1=1163175&r2=1163176&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProviderFactory.java Tue Aug 30 11:40:00 2011
@@ -19,46 +19,104 @@
 
 package org.apache.uima.caseditor.editor;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.IEditorInput;
 
+/**
+ * Factory class to produce and lookup an appropriate document provider.
+ */
 class CasDocumentProviderFactory {
 
+  // TODO: Change to: .documentProviders
   private static final String CAS_EDITOR_EXTENSION = "org.apache.uima.caseditor.editor";
 
   private static CasDocumentProviderFactory instance;
 
-  private CasDocumentProvider documentProvider;
-
+  // map class_name to provider
+  private Map<String, CasDocumentProvider> documentProviders = new HashMap<String, CasDocumentProvider>();
+  
   CasDocumentProviderFactory() {
 
     IConfigurationElement[] config =
             Platform.getExtensionRegistry().getConfigurationElementsFor(CAS_EDITOR_EXTENSION);
 
-    for (IConfigurationElement e : config) {
+    for (IConfigurationElement element : config) {
 
-      if ("provider".equals(e.getName())) {
+      if ("provider".equals(element.getName())) {
 
-        Object o;
+        // extract id element
+        String id = element.getAttribute("id");
+        String inputType = element.getAttribute("inputType");
+        
+        Object documentProviderObject;
         try {
-          o = e.createExecutableExtension("class");
-        } catch (CoreException e1) {
-          // TODO: Log error, extension point was not specified correctly !!!
-          e1.printStackTrace();
-          o = null;
+          documentProviderObject = element.createExecutableExtension("class");
+        } catch (CoreException e) {
+          CasEditorPlugin.log("Failed to load doucment provider with id: " + id, e);
+          documentProviderObject = null;
         }
-
-        if (o instanceof CasDocumentProvider) {
-          documentProvider = (CasDocumentProvider) o;
+        
+        if (documentProviderObject instanceof CasDocumentProvider) {
+          documentProviders.put(inputType, (CasDocumentProvider) documentProviderObject);
         }
       }
     }
 
   }
 
-  CasDocumentProvider getDocumentProvider() {
-    return documentProvider;
+  /**
+   * Looks up a document provider for the provided editor input.
+   * The editor input type must be cast-able to the specified inputType.
+   * The implementation tries first to map class types, and then interface types.
+   * 
+   * @param input 
+   * 
+   * @return
+   */
+  CasDocumentProvider getDocumentProvider(IEditorInput input) {
+
+    // A class can have many types, they are defined by super classes
+    // and implemented interfaces
+    
+    // First try to match the input type to the editor input type
+    // or one of its super class
+    List<Class<?>> classList = new ArrayList<Class<?>>();
+    
+    for (Class<?> inputClass = input.getClass(); inputClass != null;) {
+      classList.add(inputClass);
+      inputClass = inputClass.getSuperclass();
+    }
+    
+    CasDocumentProvider provider = null;
+    for (Class<?> inputClass : classList) {
+      provider = documentProviders.get(inputClass.getName());
+      
+      if (provider != null)
+        return provider;
+    }
+    
+    // Now try to match an implemented interface to the input type
+    // either of the editor input class or for one of its super classes
+    if (provider == null) {
+      for (Class<?> inputClass : classList) {
+        for (Class<?> inputClassInterface : inputClass.getInterfaces()) {
+          provider = documentProviders.get(inputClassInterface.getName());
+          
+          if (provider != null)
+            return provider;
+        }
+      }
+    }
+    
+    return provider;
   }
 
   static CasDocumentProviderFactory instance() {