Author: pkluegl
Date: Thu Jun 13 14:29:34 2013
New Revision: 1492685

URL: http://svn.apache.org/r1492685
Log:
UIMA-2993
- added html view

Added:
    
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/
    
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlView.java
    
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPage.java
    
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPreferencePage.java
Modified:
    uima/sandbox/ruta/trunk/ruta-ep-caseditor/plugin.xml
    uima/sandbox/ruta/trunk/ruta-ep-caseditor/pom.xml
    
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/RutaCasEditorPlugin.java

Modified: uima/sandbox/ruta/trunk/ruta-ep-caseditor/plugin.xml
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-caseditor/plugin.xml?rev=1492685&r1=1492684&r2=1492685&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-caseditor/plugin.xml (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-caseditor/plugin.xml Thu Jun 13 14:29:34 
2013
@@ -37,6 +37,17 @@ under the License.
       </view>
    </extension>
    <extension
+         point="org.eclipse.ui.views">
+      <view
+            category="org.apache.uima.caseditor.ui.views"
+            class="org.apache.uima.ruta.caseditor.view.html.HtmlView"
+            id="org.apache.uima.caseditor.html"
+            icon="icons/views.png"
+            name="Html View"
+            restorable="true">
+      </view>
+   </extension>
+   <extension
          point="org.eclipse.ui.preferencePages">
          <page
            category="org.apache.uima.caseditor.ide.CasEditorPreference"
@@ -46,6 +57,15 @@ under the License.
      </page>
    </extension>
    <extension
+         point="org.eclipse.ui.preferencePages">
+         <page
+           category="org.apache.uima.caseditor.ide.CasEditorPreference"
+           
class="org.apache.uima.ruta.caseditor.view.html.HtmlViewPreferencePage"
+           id="org.apache.uima.ruta.caseditor.view.html.preferences"
+           name="Cas Editor Html View">
+     </page>
+   </extension>
+   <extension
          point="org.eclipse.core.runtime.preferences">
     <initializer
           
class="org.apache.uima.ruta.caseditor.view.preferences.CasEditorViewPreferenceInitializer">

Modified: uima/sandbox/ruta/trunk/ruta-ep-caseditor/pom.xml
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-caseditor/pom.xml?rev=1492685&r1=1492684&r2=1492685&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-caseditor/pom.xml (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-caseditor/pom.xml Thu Jun 13 14:29:34 2013
@@ -51,6 +51,12 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.eclipse.core</groupId>
+      <artifactId>resources</artifactId>
+      <version>[3.3.0,5.0.0)</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.eclipse</groupId>
       <artifactId>ui</artifactId>
       <version>[3.3.0,5.0.0)</version>
@@ -81,6 +87,12 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.eclipse.ui</groupId>
+      <artifactId>workbench</artifactId>
+      <version>[3.3.0.0,5.0.0)</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.eclipse.jface</groupId>
       <artifactId>text</artifactId>
       <version>[3.3.0.0,5.0.0)</version>
@@ -161,6 +173,7 @@
                   org.eclipse.ui.editors,
                   org.eclipse.ui.workbench.texteditor,
                   org.eclipse.ui,
+                  org.eclipse.ui.ide,
                   org.eclipse.ui.workbench,
                   org.eclipse.core.runtime,
                   org.eclipse.core.resources,

Modified: 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/RutaCasEditorPlugin.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/RutaCasEditorPlugin.java?rev=1492685&r1=1492684&r2=1492685&view=diff
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/RutaCasEditorPlugin.java
 (original)
+++ 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/RutaCasEditorPlugin.java
 Thu Jun 13 14:29:34 2013
@@ -21,6 +21,7 @@ package org.apache.uima.ruta.caseditor;
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
@@ -78,4 +79,9 @@ public class RutaCasEditorPlugin extends
     error(t.getMessage(), t);
   }
 
+  public static ImageDescriptor getImageDescriptor(String path) {
+    return imageDescriptorFromPlugin(PLUGIN_ID, path);
+  }
+
+  
 }

Added: 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlView.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlView.java?rev=1492685&view=auto
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlView.java
 (added)
+++ 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlView.java
 Thu Jun 13 14:29:34 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.ruta.caseditor.view.html;
+
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.caseditor.editor.CasEditorView;
+import org.apache.uima.caseditor.editor.ICasEditor;
+import org.eclipse.ui.part.IPageBookViewPage;
+
+public class HtmlView extends CasEditorView {
+
+       public static final String ID = "org.apache.uima.caseditor.html";
+
+       public static final String HTML_SOURCE = 
"org.apache.uima.caseditor.html.source";
+       
+       public HtmlView() {
+               super("The instance view is currently not available.");
+       }
+
+       protected IPageBookViewPage doCreatePage(ICasEditor editor) {
+               IPageBookViewPage result = null;
+               if (editor.getDocument() != null && editor instanceof 
AnnotationEditor) {
+                       HtmlViewPage page = new HtmlViewPage((AnnotationEditor) 
editor);
+                       result = page;
+               }
+               return result;
+       }
+}

Added: 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPage.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPage.java?rev=1492685&view=auto
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPage.java
 (added)
+++ 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPage.java
 Thu Jun 13 14:29:34 2013
@@ -0,0 +1,176 @@
+/*
+ * 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.ruta.caseditor.view.html;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.impl.XmiCasDeserializer;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
+import org.apache.uima.caseditor.editor.ICasDocument;
+import org.apache.uima.caseditor.editor.ICasEditorInputListener;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
+import org.apache.uima.ruta.caseditor.RutaCasEditorPlugin;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.FileUtils;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
+import org.xml.sax.SAXException;
+
+public class HtmlViewPage extends Page implements ICasEditorInputListener {
+
+  private AnnotationEditor editor;
+
+  private Browser browser;
+
+  public HtmlViewPage(AnnotationEditor editor) {
+    super();
+    this.editor = editor;
+  }
+
+  @Override
+  public void init(IPageSite pageSite) {
+    super.init(pageSite);
+  }
+
+  @Override
+  public void createControl(Composite parent) {
+    Composite composite = parent;
+
+    browser = new Browser(composite, SWT.NONE);
+    updateHtml();
+    getSite().setSelectionProvider(new ISelectionProvider() {
+
+      public void setSelection(ISelection selection) {
+
+      }
+
+      public void removeSelectionChangedListener(ISelectionChangedListener 
listener) {
+
+      }
+
+      public ISelection getSelection() {
+        return null;
+      }
+
+      public void addSelectionChangedListener(ISelectionChangedListener 
listener) {
+
+      }
+    });
+    editor.addCasEditorInputListener(this);
+    browser.refresh();
+  }
+
+  @Override
+  public void setFocus() {
+  }
+
+  @Override
+  public void dispose() {
+    browser.dispose();
+  }
+
+  public void casDocumentChanged(IEditorInput oldInput, ICasDocument 
oldDocument,
+          IEditorInput newInput, ICasDocument newDocument) {
+    updateHtml();
+  }
+
+  @Override
+  public Control getControl() {
+    return browser;
+  }
+
+  private void updateHtml() {
+    if (editor == null) {
+      return;
+    }
+    IPreferenceStore store = 
RutaCasEditorPlugin.getDefault().getPreferenceStore();
+    String htmlSource = store.getString(HtmlView.HTML_SOURCE);
+    if (StringUtils.isBlank(htmlSource)) {
+      setHtmlWithEditor();
+    } else {
+      IEditorInput editorInput = editor.getEditorInput();
+      if (editorInput instanceof FileEditorInput) {
+        FileEditorInput fei = (FileEditorInput) editorInput;
+        String name = fei.getFile().getName();
+        String[] split = name.split("[.]");
+        File dir = new File(htmlSource);
+        File[] listFiles = dir.listFiles();
+        File selected = null;
+        for (File file : listFiles) {
+          String[] split2 = file.getName().split("[.]");
+          if(split[0].equals(split2[0])) {
+            selected = file;
+            break;
+          }
+        }
+        if(selected == null) {
+          setHtmlWithEditor();
+          return;
+        }
+        try {
+          String html = "";
+          if (selected.getName().endsWith(".html") || 
selected.getName().endsWith(".txt")) {
+            html = FileUtils.file2String(selected);
+          } else if(selected.getName().endsWith(".xmi")){
+            try {
+              TypeSystemDescription tsd = new TypeSystemDescription_impl();
+              CAS dummyCas = CasCreationUtils.createCas(tsd, null, null);
+              XmiCasDeserializer.deserialize(new FileInputStream(selected), 
dummyCas, true);
+              html = dummyCas.getDocumentText();
+              dummyCas.release();
+            } catch (ResourceInitializationException e) {
+              RutaCasEditorPlugin.error(e);
+            } catch (SAXException e) {
+              RutaCasEditorPlugin.error(e);
+            }
+          }
+          browser.setText(html);
+          browser.refresh();
+        } catch (IOException e) {
+          RutaCasEditorPlugin.error(e);
+        }
+      }
+    }
+  }
+
+  private void setHtmlWithEditor() {
+    CAS cas = editor.getDocument().getCAS();
+    String html = cas.getDocumentText();
+    browser.setText(html);
+    browser.refresh();
+  }
+
+}

Added: 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPreferencePage.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPreferencePage.java?rev=1492685&view=auto
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPreferencePage.java
 (added)
+++ 
uima/sandbox/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/html/HtmlViewPreferencePage.java
 Thu Jun 13 14:29:34 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.ruta.caseditor.view.html;
+
+import org.apache.uima.ruta.caseditor.RutaCasEditorPlugin;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class HtmlViewPreferencePage extends FieldEditorPreferencePage 
implements
+        IWorkbenchPreferencePage {
+  
+  private StringFieldEditor htmlSource;
+
+  public HtmlViewPreferencePage() {
+    setPreferenceStore(RutaCasEditorPlugin.getDefault().getPreferenceStore());
+    setDescription("Html View Preferences.");
+  }
+
+  @Override
+  protected void createFieldEditors() {
+    htmlSource = new StringFieldEditor(HtmlView.HTML_SOURCE,
+            "Html source: ", getFieldEditorParent());
+    addField(htmlSource);
+
+  }
+
+  public void init(IWorkbench workbench) {
+  }
+
+}


Reply via email to