Bug 2306 - Synchronize Package and Deployment Options
authorEugene Ostroukhov <eugeneo@symbian.org>
Fri, 19 Mar 2010 15:51:45 -0700
changeset 281 c4e6bebd078c
parent 279 2c8fd0932460
child 282 39bbb3a15d6f
Bug 2306 - Synchronize Package and Deployment Options Bug 2305 - Right click on .js file and select Package - nothing happens
org.symbian.tools.wrttools/plugin.xml
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/handlers/DeployHandler.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java
--- a/org.symbian.tools.wrttools/plugin.xml	Fri Mar 19 11:59:35 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml	Fri Mar 19 15:51:45 2010 -0700
@@ -64,22 +64,6 @@
 -->                
     
       
-	  <objectContribution
-           objectClass="org.eclipse.core.resources.IResource" 
-		   adaptable="true"         
-           id="org.symbian.tools.wrttools.widget.wrttool">
-	 	   <filter
-	     	name="projectNature"
-	     	value="org.symbian.tools.wrttools.WidgetProjectNature"/>
-	       <action
-	             class="org.symbian.tools.wrttools.core.packager.WrtPackageActionDelegate"
-	             enablesFor="+"
-	             icon="icons/package_widget.gif"
-	             id="org.symbian.tools.wrttools.widget.package.WrtPackageActionDelegate"
-	             label="Package WRT Application"
-	             menubarPath="org.symbian.tools.wrttools.contextMenuGroupMarker">
-	       </action>
-      </objectContribution> 
       <objectContribution
             objectClass="org.eclipse.core.resources.IResource"            
             id="org.symbian.tools.wrttools.widget.wrttool.packageoptions">
@@ -665,10 +649,16 @@
     </category>
     <command
           categoryId="org.symbian.tools.wrttools.commands.maincategory"
-          description="Deploys application to phone or emulator"
+          description="Deploys an application to phone or emulator"
           id="org.symbian.tools.wrttools.commands.deploy"
           name="Deploy Application">
     </command>
+    <command
+          categoryId="org.symbian.tools.wrttools.commands.maincategory"
+          description="Packages an application for distribution or deployment"
+          id="org.symbian.tools.wrttools.commands.package"
+          name="Package Application">
+    </command>
  </extension>
  <extension
        point="org.eclipse.ui.menus">
@@ -679,12 +669,85 @@
           <command
                 commandId="org.symbian.tools.wrttools.commands.deploy"
                 icon="icons/deploy_widget.gif"
-                id="org.symbian.tools.wrttools.toolbars.deploy"
-                label="Deploy"
-                tooltip="Deploy application">
+                id="org.symbian.tools.wrttools.toolbars.deploy">
+          </command>
+          <command
+                commandId="org.symbian.tools.wrttools.commands.package"
+                icon="icons/package_widget.gif"
+                id="org.symbian.tools.wrttools.toolbars.package">
           </command>
        </toolbar>
     </menuContribution>
+    <menuContribution
+          locationURI="menu:project?after=additions">
+       <separator
+             name="org.symbian.tools.wrttools.beginwert"
+             visible="true">
+       </separator>
+       <command
+             commandId="org.symbian.tools.wrttools.commands.deploy"
+             icon="icons/deploy_widget.gif"
+             id="org.symbian.tools.wrttools.toolbars.deploy">
+       </command>
+       <command
+             commandId="org.symbian.tools.wrttools.commands.package"
+             icon="icons/package_widget.gif"
+             id="org.symbian.tools.wrttools.toolbars.package">
+       </command>
+       <separator
+             name="org.symbian.tools.wrttools.endwrt"
+             visible="true">
+       </separator>
+    </menuContribution>
+    <menuContribution
+          locationURI="popup:org.eclipse.ui.popup.any?after=sourceMenuId">
+       <separator
+             name="org.symbian.tools.wrttools.beginwert"
+             visible="true">
+       </separator>
+       <command
+             commandId="org.symbian.tools.wrttools.commands.deploy"
+             icon="icons/deploy_widget.gif"
+             id="org.symbian.tools.wrttools.toolbars.deploy">
+          <visibleWhen>
+             <and>
+                <iterate
+                      ifEmpty="false"
+                      operator="and">
+                   <adapt
+                         type="org.eclipse.core.resources.IProject">
+                   </adapt>
+                </iterate>
+                <count
+                      value="1">
+                </count>
+             </and>
+          </visibleWhen>
+       </command>
+       <command
+             commandId="org.symbian.tools.wrttools.commands.package"
+             icon="icons/package_widget.gif"
+             id="org.symbian.tools.wrttools.toolbars.package">
+          <visibleWhen>
+             <and>
+                <iterate
+                      ifEmpty="false"
+                      operator="and">
+                   <adapt
+                         type="org.eclipse.core.resources.IProject">
+                   </adapt>
+                </iterate>
+                <count
+                      value="1">
+                </count>
+             </and>
+          </visibleWhen>
+       </command>
+       <separator
+             name="org.symbian.tools.wrttools.endwrt"
+             visible="true">
+       </separator>
+    </menuContribution>
  </extension>
  <extension
        point="org.eclipse.ui.handlers">
@@ -692,6 +755,25 @@
           class="org.symbian.tools.wrttools.handlers.DeployHandler"
           commandId="org.symbian.tools.wrttools.commands.deploy">
        <enabledWhen>
+          <reference
+                definitionId="org.symbian.tools.wrttools.symbianproject">
+          </reference>
+       </enabledWhen>
+    </handler>
+    <handler
+          class="org.symbian.tools.wrttools.handlers.PackageApplicationHandler"
+          commandId="org.symbian.tools.wrttools.commands.package">
+       <enabledWhen>
+          <reference
+                definitionId="org.symbian.tools.wrttools.symbianproject">
+          </reference>
+       </enabledWhen>
+    </handler>
+ </extension>
+ <extension
+       point="org.eclipse.core.expressions.definitions">
+    <definition
+          id="org.symbian.tools.wrttools.symbianproject">
           <or>
              <with
                    variable="selection">
@@ -725,7 +807,6 @@
                 </with>
              </and>
           </or>
-       </enabledWhen>
-    </handler>
+    </definition>
  </extension>
 </plugin>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/handlers/DeployHandler.java	Fri Mar 19 11:59:35 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/handlers/DeployHandler.java	Fri Mar 19 15:51:45 2010 -0700
@@ -1,18 +1,32 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
 package org.symbian.tools.wrttools.handlers;
 
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.handlers.HandlerUtil;
 import org.symbian.tools.wrttools.WRTProject;
+import org.symbian.tools.wrttools.util.ProjectUtils;
 import org.symbian.tools.wrttools.wizards.deploy.DeployWizard;
 
 /**
@@ -34,24 +48,10 @@
     public Object execute(ExecutionEvent event) throws ExecutionException {
         IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
 
-        IResource resource = null;
-
-        IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
-        if (activePart instanceof IEditorPart) {
-            resource = (IResource) ((IEditorPart) activePart).getEditorInput().getAdapter(IResource.class);
-        } else {
-            ISelection selection = HandlerUtil.getCurrentSelection(event);
-            if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
-                Object[] array = ((IStructuredSelection) selection).toArray();
-                if (array.length == 1 && array[0] instanceof IAdaptable) {
-                    resource = (IResource) ((IAdaptable) array[0]).getAdapter(IResource.class);
-                }
-            }
-        }
-        if (resource != null) {
+        IProject project = ProjectUtils.getProjectFromCommandContext(event);
+        if (project != null) {
             window.getActivePage().saveAllEditors(true);
-            WizardDialog dialog = new WizardDialog(window.getShell(), new DeployWizard(new WRTProject(resource
-                    .getProject())));
+            WizardDialog dialog = new WizardDialog(window.getShell(), new DeployWizard(new WRTProject(project)));
             dialog.open();
         }
 
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Fri Mar 19 11:59:35 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Fri Mar 19 15:51:45 2010 -0700
@@ -34,6 +34,7 @@
 
 import javax.swing.filechooser.FileSystemView;
 
+import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.resources.ICommand;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
@@ -46,6 +47,7 @@
 import org.eclipse.core.resources.IWorkspaceRunnable;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -54,12 +56,16 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IViewReference;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
 import org.eclipse.ui.part.ISetSelectionTarget;
@@ -359,4 +365,27 @@
         return false;
     }
 
+    public static IProject getProjectFromCommandContext(ExecutionEvent event) {
+        IResource resource = null;
+        IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+        if (activePart instanceof IEditorPart) {
+            resource = (IResource) ((IEditorPart) activePart).getEditorInput().getAdapter(IResource.class);
+        } else {
+            ISelection selection = HandlerUtil.getCurrentSelection(event);
+            if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
+                Object[] array = ((IStructuredSelection) selection).toArray();
+                if (array.length == 1 && array[0] instanceof IAdaptable) {
+                    resource = (IResource) ((IAdaptable) array[0]).getAdapter(IResource.class);
+                }
+            }
+        }
+        if (resource != null) {
+            IProject project = resource.getProject();
+            if (hasWrtNature(project)) {
+                return project;
+            }
+        }
+        return null;
+    }
+
 }