Author: pkluegl
Date: Fri Apr 26 12:06:13 2013
New Revision: 1476156

URL: http://svn.apache.org/r1476156
Log:
UIMA-2831
- added command

Added:
    
uima/sandbox/textmarker/trunk/textmarker-ep-addons/src/main/java/org/apache/uima/textmarker/utils/update/
    
uima/sandbox/textmarker/trunk/textmarker-ep-addons/src/main/java/org/apache/uima/textmarker/utils/update/UpdateProjectHandler.java
Modified:
    uima/sandbox/textmarker/trunk/textmarker-ep-addons/plugin.xml
    
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java

Modified: uima/sandbox/textmarker/trunk/textmarker-ep-addons/plugin.xml
URL: 
http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-addons/plugin.xml?rev=1476156&r1=1476155&r2=1476156&view=diff
==============================================================================
--- uima/sandbox/textmarker/trunk/textmarker-ep-addons/plugin.xml (original)
+++ uima/sandbox/textmarker/trunk/textmarker-ep-addons/plugin.xml Fri Apr 26 
12:06:13 2013
@@ -308,6 +308,11 @@ under the License.
             id="org.apache.uima.textmarker.utils.apply.script.noxmi"
             name="ApplyScriptNoXMICommand">
       </command>
+      <command
+            
defaultHandler="org.apache.uima.textmarker.utils.update.UpdateProjectHandler"
+            id="org.apache.uima.textmarker.utils.update"
+            name="Update Project">
+      </command>
    </extension>   <extension
          point="org.eclipse.ui.menus">
       <menuContribution
@@ -428,6 +433,25 @@ under the License.
             </visibleWhen>
          </command>
       </menuContribution>
+      <menuContribution
+            locationURI="popup:org.apache.uima.textmarker.utils.popup.submenu">
+         <command
+               commandId="org.apache.uima.textmarker.utils.update"
+               disabledIcon="icons/tm_obj.png"
+               hoverIcon="icons/tm_obj.png"
+               icon="icons/tm_obj.png"
+               id="org.apache.uima.textmarker.utils.update.popup"
+               label="Update Project"
+               style="push"
+               tooltip="Update basic templates for descriptors">
+              <visibleWhen
+                    checkEnabled="true">
+                 <reference
+                       
definitionId="org.apache.uima.textmarker.utils.update.definition">
+                 </reference>
+              </visibleWhen>
+         </command>
+      </menuContribution>
    </extension>   <extension
          point="org.eclipse.core.expressions.definitions">
       <definition
@@ -469,6 +493,19 @@ under the License.
             </test>
          </adapt>
       </definition>
+      <definition
+            id="org.apache.uima.textmarker.utils.update.definition">
+         <with
+               variable="selection">
+            <iterate
+                  ifEmpty="true">
+               <or>
+                  <instanceof
+                        value="org.eclipse.dltk.core.IScriptProject ">
+                  </instanceof></or>
+            </iterate>
+         </with>
+      </definition>
    </extension>   <extension
          point="org.eclipse.ui.bindings">
       <key

Added: 
uima/sandbox/textmarker/trunk/textmarker-ep-addons/src/main/java/org/apache/uima/textmarker/utils/update/UpdateProjectHandler.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-addons/src/main/java/org/apache/uima/textmarker/utils/update/UpdateProjectHandler.java?rev=1476156&view=auto
==============================================================================
--- 
uima/sandbox/textmarker/trunk/textmarker-ep-addons/src/main/java/org/apache/uima/textmarker/utils/update/UpdateProjectHandler.java
 (added)
+++ 
uima/sandbox/textmarker/trunk/textmarker-ep-addons/src/main/java/org/apache/uima/textmarker/utils/update/UpdateProjectHandler.java
 Fri Apr 26 12:06:13 2013
@@ -0,0 +1,143 @@
+/*
+ * 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.textmarker.utils.update;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.textmarker.addons.TextMarkerAddonsPlugin;
+import org.apache.uima.textmarker.ide.core.TextMarkerNature;
+import org.apache.uima.textmarker.ide.core.builder.TextMarkerProjectUtils;
+import 
org.apache.uima.textmarker.ide.ui.wizards.TextMarkerProjectCreationWizard;
+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.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.resources.IResource;
+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.dltk.core.IScriptProject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class UpdateProjectHandler 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) {
+      List<IScriptProject> projects = new ArrayList<IScriptProject>();
+      ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+      if (currentSelection instanceof IStructuredSelection) {
+        StructuredSelection selection = (StructuredSelection) currentSelection;
+        Iterator<?> iter = selection.iterator();
+        while (iter.hasNext()) {
+          Object object = iter.next();
+          if (object instanceof IScriptProject) {
+            IScriptProject p = (IScriptProject) object;
+            projects.add(p);
+          }
+        }
+      }
+      monitor.beginTask("Updating descriptor files...", projects.size());
+      for (IScriptProject each : projects) {
+        IProject project = each.getProject();
+
+        // update old projects
+//        try {
+//          IProjectNature oldNature = 
project.getNature(TextMarkerNature.NATURE_ID);
+//          if (oldNature != null) {
+//            IProjectDescription description = project.getDescription();
+//            String[] natureIds = description.getNatureIds();
+//            int counter = 0;
+//            for (String id : Arrays.asList(natureIds)) {
+//              if (id.equals(TextMarkerNature.NATURE_ID)) {
+//                natureIds[counter] = TextMarkerNature.NATURE_ID;
+//              }
+//              counter++;
+//            }
+//          }
+//        } catch (CoreException e) {
+//          TextMarkerAddonsPlugin.error(e);
+//        }
+
+        try {
+          IProjectNature nature = 
project.getNature(TextMarkerNature.NATURE_ID);
+          if (nature != null) {
+            List<IFolder> descriptorFolders = 
TextMarkerProjectUtils.getDescriptorFolders(project);
+            if (descriptorFolders != null && !descriptorFolders.isEmpty()) {
+              IFolder descFolder = descriptorFolders.get(0);
+              TextMarkerProjectCreationWizard.copyDescriptors(descFolder);
+              descFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+            }
+          }
+        } catch (CoreException e) {
+          TextMarkerAddonsPlugin.error(e);
+        }
+        monitor.worked(1);
+      }
+      monitor.done();
+      return Status.OK_STATUS;
+
+    }
+  }
+
+  public void addHandlerListener(IHandlerListener handlerListener) {
+  }
+
+  public void dispose() {
+  }
+
+  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) {
+
+  }
+
+}

Modified: 
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java?rev=1476156&r1=1476155&r2=1476156&view=diff
==============================================================================
--- 
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java
 (original)
+++ 
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java
 Fri Apr 26 12:06:13 2013
@@ -137,7 +137,7 @@ public class TextMarkerProjectCreationWi
 
   }
 
-  private void copyDescriptors(IFolder descFolder) {
+  public static void copyDescriptors(IFolder descFolder) {
     File descDir = descFolder.getLocation().toFile();
     File utilsDir = new File(descFolder.getLocation().toFile(), "utils/");
     copy(descDir, "BasicTypeSystem.xml");
@@ -156,7 +156,7 @@ public class TextMarkerProjectCreationWi
     copy(utilsDir, "HtmlConverter.xml");
   }
 
-  private void copy(File dir, String fileName) {
+  private static void copy(File dir, String fileName) {
     InputStream in = null;
     OutputStream out = null;
     in = TextMarkerEngine.class.getResourceAsStream(fileName);


Reply via email to