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/01 17:28:50 UTC

svn commit: r1152828 [6/6] - in /uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils: ./ META-INF/ bin/ icons/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/uima/ src/main/java/org/...

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/convert/ConvertSyntaxParser.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/convert/ConvertSyntaxParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/MultiTWLConverterHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/MultiTWLConverterHandler.java?rev=1152828&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/MultiTWLConverterHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/MultiTWLConverterHandler.java Mon Aug  1 15:28:46 2011
@@ -0,0 +1,143 @@
+package org.apache.uima.tm.textmarker.ui.twl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.resource.trie.MultiTreeWordList;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+public class MultiTWLConverterHandler implements IHandler {
+  private class ConverterHandlerJob extends Job {
+    ExecutionEvent event;
+
+    ConverterHandlerJob(ExecutionEvent event) {
+      super("Converting...");
+      this.event = event;
+      setUser(true);
+    }
+
+    @Override
+    public IStatus run(IProgressMonitor monitor) {
+      monitor.beginTask("Collecting files...", 1);
+
+      if (HandlerUtil.getCurrentSelection(event) instanceof IStructuredSelection) {
+        StructuredSelection selection = (StructuredSelection) HandlerUtil
+                .getCurrentSelection(event);
+        Iterator<?> iter = selection.iterator();
+        IResource first = null;
+
+        List<String> paths = new ArrayList<String>();
+        while (iter.hasNext()) {
+          Object object = iter.next();
+          if (object instanceof IResource) {
+            IResource resource = (IResource) object;
+            if (first == null) {
+              first = resource;
+            }
+            paths.addAll(getPaths(resource));
+          }
+        }
+        monitor.beginTask("Compiling generated.mtwl...", 1);
+        if (!paths.isEmpty()) {
+          MultiTreeWordList trie = new MultiTreeWordList(paths.toArray(new String[0]));
+
+          IPath parent = first.getLocation().removeLastSegments(1);
+          IPath newPath = parent.append("generated.mtwl");
+
+          File file = newPath.toFile();
+          final String absolutePath = file.getAbsolutePath();
+
+          trie.createMTWLFile(absolutePath);
+
+          IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+          IContainer container = myWorkspaceRoot.getContainerForLocation(parent);
+          final String localPath = container.getProjectRelativePath() + "/" + container.getName()
+                  + "/" + "generated.mtwl";
+          try {
+            container.getParent().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+          } catch (CoreException e) {
+          }
+          // event.getShell().getDisplay().asyncExec(new Runnable() {
+          // public void run() {
+          // MessageDialog.openInformation(window.getShell(), "Multi TWL created",
+          // "A multi TWL was created:\n" + localPath);
+          // }
+          // });
+        }
+
+      }
+
+      monitor.done();
+      return Status.OK_STATUS;
+
+    }
+  }
+
+  public void addHandlerListener(IHandlerListener handlerListener) {
+  }
+
+  public void dispose() {
+  }
+
+  @Override
+  public Object execute(ExecutionEvent event) throws ExecutionException {
+    new ConverterHandlerJob(event).schedule();
+    return null;
+  }
+
+  private List<String> getPaths(IResource resource) {
+    List<String> paths = new ArrayList<String>();
+    if (resource instanceof IFile) {
+      IFile file = (IFile) resource;
+      String fileExtension = file.getFileExtension();
+      if ("txt".equals(fileExtension)) {
+        String path = file.getRawLocation().toString();
+        paths.add(path);
+      }
+    } else if (resource instanceof IFolder) {
+      IFolder folder = (IFolder) resource;
+      try {
+        IResource[] members = folder.members();
+        for (IResource each : members) {
+          paths.addAll(getPaths(each));
+        }
+      } catch (CoreException e) {
+      }
+    }
+    return paths;
+  }
+
+  public boolean isEnabled() {
+    return true;
+  }
+
+  public boolean isHandled() {
+    return true;
+  }
+
+  public void removeHandlerListener(IHandlerListener handlerListener) {
+
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/MultiTWLConverterHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/MultiTWLConverterHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/TWLConverterHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/TWLConverterHandler.java?rev=1152828&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/TWLConverterHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/TWLConverterHandler.java Mon Aug  1 15:28:46 2011
@@ -0,0 +1,98 @@
+package org.apache.uima.tm.textmarker.ui.twl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.resource.TreeWordList;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+public class TWLConverterHandler implements IHandler {
+
+  private class ConverterHandlerJob extends Job {
+    ExecutionEvent event;
+
+    ConverterHandlerJob(ExecutionEvent event) {
+      super("Converting...");
+      this.event = event;
+      setUser(true);
+    }
+
+    @Override
+    public IStatus run(IProgressMonitor monitor) {
+      monitor.beginTask("Collecting files...", 1);
+      List<IFile> files = new ArrayList<IFile>();
+      if (HandlerUtil.getCurrentSelection(event) instanceof IStructuredSelection) {
+        StructuredSelection selection = (StructuredSelection) HandlerUtil
+                .getCurrentSelection(event);
+        Iterator<Object> iter = selection.iterator();
+        while (iter.hasNext()) {
+          Object object = iter.next();
+          if (object instanceof IFile) {
+            IFile file = (IFile) object;
+            files.add(file);
+          }
+        }
+      }
+      monitor.beginTask("Converting files...", files.size());
+      for (IFile file : files) {
+        monitor.setTaskName("Compiling " + file.getLocation().lastSegment() + "...");
+        String path = file.getRawLocation().toString();
+        TreeWordList list = new TreeWordList(path);
+        String exportPath = path.substring(0, path.length() - 3) + "twl";
+        list.createXMLFile(exportPath, "UTF-8");
+        IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+        IContainer container = myWorkspaceRoot.getContainerForLocation(file.getLocation());
+        try {
+          container.getParent().refreshLocal(1, null);
+        } catch (CoreException e) {
+        }
+        monitor.worked(1);
+      }
+      monitor.done();
+      return Status.OK_STATUS;
+
+    }
+  }
+
+  public void addHandlerListener(IHandlerListener handlerListener) {
+  }
+
+  public void dispose() {
+  }
+
+  @Override
+  public Object execute(ExecutionEvent event) throws ExecutionException {
+    new ConverterHandlerJob(event).schedule();
+    return null;
+  }
+
+  public boolean isEnabled() {
+    return true;
+  }
+
+  public boolean isHandled() {
+    return true;
+  }
+
+  public void removeHandlerListener(IHandlerListener handlerListener) {
+
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/TWLConverterHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/twl/TWLConverterHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/utils/TextMarkerUtilsPlugin.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/utils/TextMarkerUtilsPlugin.java?rev=1152828&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/utils/TextMarkerUtilsPlugin.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/utils/TextMarkerUtilsPlugin.java Mon Aug  1 15:28:46 2011
@@ -0,0 +1,54 @@
+package org.apache.uima.tm.textmarker.ui.utils;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class TextMarkerUtilsPlugin extends AbstractUIPlugin {
+
+  // The plug-in ID
+  public static final String PLUGIN_ID = "org.apache.uima.tm.textmarker.ui.utils";
+
+  // The shared instance
+  private static TextMarkerUtilsPlugin plugin;
+
+  /**
+   * The constructor
+   */
+  public TextMarkerUtilsPlugin() {
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+   */
+  @Override
+  public void start(BundleContext context) throws Exception {
+    super.start(context);
+    plugin = this;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+   */
+  @Override
+  public void stop(BundleContext context) throws Exception {
+    plugin = null;
+    super.stop(context);
+  }
+
+  /**
+   * Returns the shared instance
+   * 
+   * @return the shared instance
+   */
+  public static TextMarkerUtilsPlugin getDefault() {
+    return plugin;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/utils/TextMarkerUtilsPlugin.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.ui.utils/src/main/java/org/apache/uima/tm/textmarker/ui/utils/TextMarkerUtilsPlugin.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain