Bug 2341 - Files excluded from widget archive are not clearly marked
authorEugene Ostroukhov <eugeneo@symbian.org>
Thu, 25 Mar 2010 12:51:27 -0700
changeset 282 39bbb3a15d6f
parent 281 c4e6bebd078c
child 283 c035b31473c1
Bug 2341 - Files excluded from widget archive are not clearly marked
org.symbian.tools.wrttools/icons/excluded.gif
org.symbian.tools.wrttools/plugin.xml
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/WRTImages.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/ExcludeFileAction.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IncludeFileAction.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/handlers/PackageApplicationHandler.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/PackagingInformationDecorator.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java
Binary file org.symbian.tools.wrttools/icons/excluded.gif has changed
--- a/org.symbian.tools.wrttools/plugin.xml	Fri Mar 19 15:51:45 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml	Thu Mar 25 12:51:27 2010 -0700
@@ -26,13 +26,6 @@
         
 <!-- Validator Marker -->
    
-        <extension
-           id="org.symbian.tools.wrttools.core.validator.marker"
-           name="Validator Marker"
-           point="org.eclipse.core.resources.markers">
-                 <super type="org.eclipse.core.resources.problemmarker"/>
-                 <persistent value ="true"/>
-        </extension>
         
 <!-- Web Runtime Preferences --> 
  <extension
@@ -808,5 +801,27 @@
              </and>
           </or>
     </definition>
+ </extension>
+ <extension
+       point="org.eclipse.ui.decorators">
+    <decorator
+          adaptable="true"
+          class="org.symbian.tools.wrttools.navigator.PackagingInformationDecorator"
+          icon="icons/main16.gif"
+          id="org.symbian.tools.wrttools.packagingDeclarator"
+          label="WebRuntime Packaging Information"
+          lightweight="true"
+          location="TOP_RIGHT"
+          objectClass="org.eclipse.core.resources.IResource"
+          state="true">
+    </decorator>
+ </extension>
+ <extension
+       id="org.symbian.tools.wrttools.excluded"
+       name="Excluded from WRT packaging marker"
+       point="org.eclipse.core.resources.markers">
+    <persistent
+          value="true">
+    </persistent>
  </extension>
 </plugin>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/WRTImages.java	Fri Mar 19 15:51:45 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/WRTImages.java	Thu Mar 25 12:51:27 2010 -0700
@@ -29,6 +29,7 @@
     private static final String IMAGE_NEW_WIZARD_BANNER = "WRT_wizard_banner.png";
     private static final String IMAGE_EMULATOR = "deploy_widget.gif";
     private static final String IMAGE_BLUETOOTH = "bluetooth.gif";
+    private static final String IMAGE_EXCLUDED = "excluded.gif";
 
     public static void init(ImageRegistry reg) {
         add(reg, IMAGE_IMPORT_WIZARD_BANNER);
@@ -36,6 +37,7 @@
         add(reg, IMAGE_NEW_WIZARD_BANNER);
         add(reg, IMAGE_EMULATOR);
         add(reg, IMAGE_BLUETOOTH);
+        add(reg, IMAGE_EXCLUDED);
     }
 
     private static void add(ImageRegistry reg, String key) {
@@ -62,4 +64,12 @@
         return Activator.getDefault().getImageRegistry().get(IMAGE_BLUETOOTH);
     }
 
+    public static Image getExcludedImage() {
+        return Activator.getDefault().getImageRegistry().get(IMAGE_EXCLUDED);
+    }
+
+    public static ImageDescriptor getExcludedImageDescriptor() {
+        return Activator.getDefault().getImageRegistry().getDescriptor(IMAGE_EXCLUDED);
+    }
+
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/ExcludeFileAction.java	Fri Mar 19 15:51:45 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/ExcludeFileAction.java	Thu Mar 25 12:51:27 2010 -0700
@@ -35,13 +35,13 @@
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
-
 import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.util.ProjectUtils;
 
 public class ExcludeFileAction implements IObjectActionDelegate {
 	
-	private List<IFile> selectedFiles = new ArrayList<IFile>();
-	private List<IFolder> selectedFolders = new ArrayList<IFolder>();
+	private final List<IFile> selectedFiles = new ArrayList<IFile>();
+	private final List<IFolder> selectedFolders = new ArrayList<IFolder>();
 	public ExcludeFileAction() {
 		super();
 	}
@@ -51,16 +51,12 @@
 
 	public void run(IAction action) {
 		for (IFile file : selectedFiles) {
-			try {
-				file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString());
-			} catch (CoreException x) {
-				Activator.log(IStatus.ERROR, "error setting exclude property on file: "+file.getName(), x);
-			}
+            ProjectUtils.exclude(file);
 		}
 		
 		for(IFolder folder : selectedFolders){
 			try{
-				folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString());
+                ProjectUtils.exclude(folder);
 				excludeFolder( folder);
 			}
 			catch (CoreException x) {
@@ -71,7 +67,8 @@
 		PlatformUI.getWorkbench().getDecoratorManager().update("org.symbian.tools.wrttools.decorator"); 
 	}
 	
-	public void selectionChanged(IAction action, ISelection selection) {
+    @SuppressWarnings("unchecked")
+    public void selectionChanged(IAction action, ISelection selection) {
 		selectedFiles.clear();
 		selectedFolders.clear();
 		if (selection instanceof IStructuredSelection) {
@@ -105,11 +102,11 @@
 			public boolean visit(IResource resource)throws CoreException {
 				if (resource instanceof IFile) {
 					IFile file = (IFile) resource;
-					file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString());
+                    ProjectUtils.exclude(file);
 				}
 				else if (resource instanceof IFolder) {
 					IFolder folder = (IFolder) resource;
-					folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString());	
+                    ProjectUtils.exclude(folder);
 				}
 				return true;
 			}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IncludeFileAction.java	Fri Mar 19 15:51:45 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IncludeFileAction.java	Thu Mar 25 12:51:27 2010 -0700
@@ -36,13 +36,13 @@
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
-
 import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.util.ProjectUtils;
 
 public class IncludeFileAction implements IObjectActionDelegate {
 	
-	private List<IFile> selectedFiles = new ArrayList<IFile>();
-	private List<IFolder> selectedFolders = new ArrayList<IFolder>();
+	private final List<IFile> selectedFiles = new ArrayList<IFile>();
+	private final List<IFolder> selectedFolders = new ArrayList<IFolder>();
 
 
 	public IncludeFileAction() {
@@ -54,16 +54,12 @@
 
 	public void run(IAction action) {
 		for (IFile file : selectedFiles) {			
-			try {
-				file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null);
-			} catch (CoreException x) {
-				Activator.log(IStatus.ERROR, "error setting exclude property on file: "+file.getName(), x);
-			}
+            ProjectUtils.include(file);
 		}
 		
 		for(IFolder folder : selectedFolders){
 			try{
-				folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null);
+                ProjectUtils.include(folder);
 				includeFolder( folder);				
 			}
 			catch (CoreException x) {
@@ -77,7 +73,8 @@
 	/**
 	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 	 */
-	public void selectionChanged(IAction action, ISelection selection) {
+    @SuppressWarnings("unchecked")
+    public void selectionChanged(IAction action, ISelection selection) {
 		selectedFiles.clear();
 		selectedFolders.clear();
 		if (selection instanceof IStructuredSelection) {
@@ -108,11 +105,11 @@
 			public boolean visit(IResource resource)	throws CoreException {
 				if (resource instanceof IFile) {
 					IFile file = (IFile) resource;
-					file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null);		
+                    ProjectUtils.include(file);
 				}
 				else if (resource instanceof IFolder) {
 					IFolder folder = (IFolder) resource;
-					folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null);		
+                    ProjectUtils.include(folder);
 				}
 				return true;
 			}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java	Fri Mar 19 15:51:45 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java	Thu Mar 25 12:51:27 2010 -0700
@@ -47,6 +47,7 @@
 import org.symbian.tools.wrttools.core.status.IWRTConstants;
 import org.symbian.tools.wrttools.core.status.IWRTStatusListener;
 import org.symbian.tools.wrttools.core.status.WRTStatus;
+import org.symbian.tools.wrttools.util.ProjectUtils;
 
 public class WrtPackageActionDelegate extends ActionDelegate implements
 		IObjectActionDelegate {
@@ -105,8 +106,8 @@
 							IFile file = (IFile) resource;
 							boolean add = true;
 							// skip user-excluded and automatically-excluded files
-							String value = file.getPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY);
-							if (value != null) {
+                            boolean value = ProjectUtils.isExcluded(file);
+                            if (value) {
 								add = false;
 							}
 							String name = file.getName();
@@ -134,6 +135,7 @@
 						}		
 						return true;
 					}
+
 				});
 				//<<--<<
 
@@ -156,7 +158,7 @@
 					project.refreshLocal(IResource.DEPTH_ONE, pm);
 					wgz = project.getFile(wgzPath);
 					if (wgz.exists()) {
-						wgz.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString());
+                        ProjectUtils.exclude(wgz);
 					}
 					
 				} catch (PackageException e) {
@@ -171,10 +173,11 @@
 		}	
 		return packaedSucess;
 	}
-	/**
-	 * Reporting status
-	 * @param statusMessage
-	 */
+
+    /**
+     * Reporting status
+     * @param statusMessage
+     */
 	private void reportStatus(String statusMessage) {
 		WRTStatus status = new WRTStatus();
 		WRTStatusListener statusListener = new WRTStatusListener();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/handlers/PackageApplicationHandler.java	Thu Mar 25 12:51:27 2010 -0700
@@ -0,0 +1,46 @@
+/**
+ * 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.commands.IHandler;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.ui.PlatformUI;
+import org.symbian.tools.wrttools.WRTStatusListener;
+import org.symbian.tools.wrttools.core.packager.WrtPackageActionDelegate;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+public class PackageApplicationHandler extends AbstractHandler implements IHandler {
+
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        IProject project = ProjectUtils.getProjectFromCommandContext(event);
+
+        if (project != null) {
+            PlatformUI.getWorkbench().saveAllEditors(true);
+            if (project != null) {
+                WRTStatusListener statusListener = new WRTStatusListener();
+                new WrtPackageActionDelegate().packageProject(project, statusListener);
+            }
+        }
+        return null;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/PackagingInformationDecorator.java	Thu Mar 25 12:51:27 2010 -0700
@@ -0,0 +1,63 @@
+/**
+ * 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.navigator;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.IDecoration;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ILightweightLabelDecorator;
+import org.symbian.tools.wrttools.core.WRTImages;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+public class PackagingInformationDecorator implements ILightweightLabelDecorator {
+
+    public void decorate(Object element, IDecoration decoration) {
+        IResource resource = null;
+        if (element instanceof IResource) {
+            resource = (IResource) element;
+        } else if (element instanceof IAdaptable) {
+            resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
+        }
+        if (resource != null && ProjectUtils.isExcluded(resource)) {
+            decoration.addOverlay(WRTImages.getExcludedImageDescriptor(), IDecoration.TOP_RIGHT);
+        }
+    }
+
+    public void addListener(ILabelProviderListener listener) {
+        // Do nothing
+
+    }
+
+    public void dispose() {
+        // Do nothing
+
+    }
+
+    public boolean isLabelProperty(Object element, String property) {
+        // Do nothing
+        return false;
+    }
+
+    public void removeListener(ILabelProviderListener listener) {
+        // Do nohing
+
+    }
+
+}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Fri Mar 19 15:51:45 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Thu Mar 25 12:51:27 2010 -0700
@@ -39,6 +39,7 @@
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.IResource;
@@ -78,10 +79,13 @@
 import org.eclipse.wst.validation.ValidationFramework;
 import org.symbian.tools.wrttools.Activator;
 import org.symbian.tools.wrttools.WidgetProjectNature;
+import org.symbian.tools.wrttools.core.packager.WRTPackagerConstants;
 import org.symbian.tools.wrttools.wizards.WrtLibraryWizardPage;
 
 @SuppressWarnings("restriction")
 public class ProjectUtils {
+    private static final String EXCLUDE_MARKER_ID = "org.symbian.tools.wrttools.excluded";
+
     private static final class FocusOnProjectJob extends Job {
 
         private final Display display;
@@ -388,4 +392,38 @@
         return null;
     }
 
+    public static boolean isExcluded(IResource resource) {
+        try {
+            IMarker[] markers = resource
+                    .findMarkers(EXCLUDE_MARKER_ID, false, IResource.DEPTH_ZERO);
+            return markers.length != 0;
+        } catch (CoreException e) {
+            Activator.log(e);
+            return false;
+        }
+
+    }
+
+    public static void exclude(IResource resource) {
+        try {
+            resource.createMarker(EXCLUDE_MARKER_ID);
+            resource.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString());
+        } catch (CoreException e) {
+            Activator.log(e);
+        }
+    }
+
+    public static void include(IResource resource) {
+        try {
+            IMarker[] markers = resource
+                    .findMarkers(EXCLUDE_MARKER_ID, false, IResource.DEPTH_ZERO);
+            resource.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null);
+            for (IMarker marker : markers) {
+                marker.delete();
+            }
+        } catch (CoreException e) {
+            Activator.log(e);
+        }
+    }
+
 }