# HG changeset patch # User Eugene Ostroukhov # Date 1281392314 25200 # Node ID 7a8f9fa8d278f936b0c2f97a57c965da62ad19a1 # Parent c0bff5ed874c6d678d4708999d95aee1e0c18554 Project model introduction and JSDT classpath support diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/.project --- a/org.symbian.tools.mtw.core/.project Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.core/.project Mon Aug 09 15:18:34 2010 -0700 @@ -1,6 +1,6 @@ - org.symbian.tools.mtw.core + org.symbian.tools.tmw.core diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/META-INF/MANIFEST.MF --- a/org.symbian.tools.mtw.core/META-INF/MANIFEST.MF Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.core/META-INF/MANIFEST.MF Mon Aug 09 15:18:34 2010 -0700 @@ -1,17 +1,19 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Mobile Tools for Web Core Plug-in -Bundle-SymbolicName: org.symbian.tools.mtw.core;singleton:=true +Bundle-SymbolicName: org.symbian.tools.tmw.core;singleton:=true Bundle-Version: 1.0.0.qualifier -Bundle-Activator: org.symbian.tools.mtw.core.MTWCore +Bundle-Activator: org.symbian.tools.tmw.core.TMWCore Bundle-Vendor: Symbian Foundation Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.core.resources;bundle-version="3.6.0", - org.eclipse.core.expressions;bundle-version="3.4.200" + org.eclipse.core.expressions;bundle-version="3.4.200", + org.eclipse.wst.common.project.facet.core;bundle-version="1.4.100", + org.eclipse.wst.jsdt.core;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy -Export-Package: org.symbian.tools.mtw.core, - org.symbian.tools.mtw.core.projects, - org.symbian.tools.mtw.core.runtimes, - org.symbian.tools.mtw.core.utilities +Export-Package: org.symbian.tools.tmw.core, + org.symbian.tools.tmw.core.projects, + org.symbian.tools.tmw.core.runtimes, + org.symbian.tools.tmw.core.utilities diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/plugin.xml --- a/org.symbian.tools.mtw.core/plugin.xml Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.core/plugin.xml Mon Aug 09 15:18:34 2010 -0700 @@ -4,5 +4,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Allows the application to query GPS location using runtime-specific APIs + + + + + + + + + + + + + + + + + + + + + + + + Provides core mobile web runtime APIs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/schema/packagers.exsd --- a/org.symbian.tools.mtw.core/schema/packagers.exsd Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.core/schema/packagers.exsd Mon Aug 09 15:18:34 2010 -0700 @@ -1,9 +1,9 @@ - + - + Packagers can package given application for specified runtime @@ -55,30 +55,44 @@ - + - + ID of the runtime that the application will be deployed to. - + - + + + + + + + + ID of the runtime that the project should support so it could be deployed to targetRuntime. If this attribute is empty then the project should target the targetRuntime directly - + + + + + + + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/schema/projectProvider.exsd --- a/org.symbian.tools.mtw.core/schema/projectProvider.exsd Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.core/schema/projectProvider.exsd Mon Aug 09 15:18:34 2010 -0700 @@ -1,9 +1,9 @@ - + - + These providers enables extension providers to add support for a different project models (i.e. coming from other IDEs). MTW will not provide facilities for creating, converting and configuring non-MTW projects. MTW will only ensure that most features (like deployment and debugging) are available to those projects. @@ -60,7 +60,7 @@ - + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/schema/runtimeIncludePath.exsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/schema/runtimeIncludePath.exsd Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,182 @@ + + + + + + + + + This extension point will let adapters provide JSDT include path entries for their mobile web runtime. Files may be available depending on project target runtime, enabled facets or both. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Provides entries that will be shown when facet is enabled. If this element is used as a subelement of the runtime-include-path then both runtime and facet will be taken into the consideration. +If there are several contributions for the same facet they will be joined to one. + + + + + + + + + + + + + + + + + + + + + Version string or empty to provide entries for any facet version + + + + + + + + + + Runtime-specific include path. If there are several contribution for the same runtime they will be combined together. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/schema/runtimes.exsd --- a/org.symbian.tools.mtw.core/schema/runtimes.exsd Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.core/schema/runtimes.exsd Mon Aug 09 15:18:34 2010 -0700 @@ -1,9 +1,9 @@ - + - + Mobile Web Runtimes are specific sets of JavaScript APIs, specifications and conventions that define how the application needs to be defined so it could be deployed to targets that support given runtime. @@ -49,7 +49,20 @@ - + + + + + + + + + + + + + + @@ -69,6 +82,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/MTWCore.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/MTWCore.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -package org.symbian.tools.mtw.core; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.osgi.framework.BundleContext; -import org.symbian.tools.mtw.core.internal.projects.ProjectsSupportManager; -import org.symbian.tools.mtw.core.internal.runtimes.RuntimesManagerImpl; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntimeManager; - -/** - * The activator class controls the plug-in life cycle - */ -public class MTWCore extends Plugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.symbian.tools.mtw.core"; //$NON-NLS-1$ - - // The shared instance - private static MTWCore plugin; - - private final IMobileWebRuntimeManager runtimesManager = new RuntimesManagerImpl(); - private final ProjectsSupportManager projectsSupport = new ProjectsSupportManager(); - - /** - * The constructor - */ - public MTWCore() { - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - 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) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - public IMobileWebRuntimeManager getRuntimesManager() { - return runtimesManager; - } - - public IMTWProject create(IProject project) { - return projectsSupport.create(project); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static MTWCore getDefault() { - return plugin; - } - - public static void log(String message, Exception exception) { - getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); - } - - public static void log(String message, Object... args) { - log(String.format(message, args), (Exception) null); - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/projects/ProjectProvider.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/projects/ProjectProvider.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/** - * 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.mtw.core.internal.projects; - -import org.eclipse.core.expressions.EvaluationContext; -import org.eclipse.core.expressions.EvaluationResult; -import org.eclipse.core.expressions.Expression; -import org.eclipse.core.expressions.ExpressionConverter; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.projects.IMTWProjectProvider; - -public class ProjectProvider implements IMTWProjectProvider { - private final IConfigurationElement element; - private final Expression expression; - private IMTWProjectProvider provider; - - public ProjectProvider(IConfigurationElement element) throws CoreException { - this.element = element; - IConfigurationElement[] children = element.getChildren("enablement"); - if (children.length == 1) { - expression = ExpressionConverter.getDefault().perform(children[0]); - } else { - expression = null; - if (children.length > 1) { - MTWCore.log( - "Project extension in plugin %s has several elements. All expressions will be ignored.", - element.getNamespaceIdentifier()); - } - } - } - - public IMTWProject create(IProject project) { - return getProvider().create(project); - } - - private IMTWProjectProvider getProvider() { - if (provider == null) { - try { - provider = (IMTWProjectProvider) element.createExecutableExtension("class"); - } catch (CoreException e) { - throw new RuntimeException(e); - } - } - return provider; - } - - public boolean isSupportedProject(final IProject project) { - try { - final EvaluationResult result = expression.evaluate(new EvaluationContext(null, project)); - if (EvaluationResult.TRUE.equals(result)) { - return getProvider().isSupportedProject(project); - } - } catch (CoreException e) { - MTWCore.log(null, e); - } - return false; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/projects/ProjectsSupportManager.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/projects/ProjectsSupportManager.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/** - * 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.mtw.core.internal.projects; - -import java.util.Collection; -import java.util.LinkedList; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; - -public class ProjectsSupportManager { - private Collection providers = null; - - public IMTWProject create(IProject project) { - if (providers == null) { - readProviders(); - } - for (ProjectProvider provider : providers) { - if (provider.isSupportedProject(project)) { - return provider.create(project); - } - } - return null; - } - - private void readProviders() { - providers = new LinkedList(); - IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor( - MTWCore.PLUGIN_ID, "projectProvider"); - for (IConfigurationElement element : configurationElements) { - if (element.getName().equals("projectProvider")) { - try { - providers.add(new ProjectProvider(element)); - } catch (CoreException e) { - MTWCore.log(null, e); - } - } - } - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/LazyPackager.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/LazyPackager.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/** - * 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.mtw.core.internal.runtimes; - -import java.io.File; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.core.runtimes.IPackagerDelegate; - -public class LazyPackager implements IPackager { - private final IConfigurationElement element; - private IPackagerDelegate packager; - - public LazyPackager(IConfigurationElement element) { - this.element = element; - } - - public File packageApplication(IMTWProject project, IProgressMonitor monitor) - throws CoreException { - return getPackager().packageApplication(project, monitor); - } - - private IPackagerDelegate getPackager() { - if (packager == null) { - try { - packager = (IPackagerDelegate) element.createExecutableExtension("delegate"); - } catch (CoreException e) { - MTWCore.log(String.format("Cannot instantiate %s from plugin %s", element.getAttribute("delegate"), - element.getDeclaringExtension().getNamespaceIdentifier()), e); - throw new RuntimeException(e); - } - } - return packager; - } - - public IPath getPathInPackage(IResource resource) { - return getPackager().getPathInPackage(resource); - } - - public String getFileType(IMTWProject project) { - return getPackager().getFileType(project); - } - - public IMobileWebRuntime getTargetRuntime() { - String id = element.getAttribute("targetRuntime"); - if (id != null) { - return MTWCore.getDefault().getRuntimesManager().getRuntime(id); - } else { - return getSourceRuntime(); - } - } - - public IMobileWebRuntime getSourceRuntime() { - IMobileWebRuntime runtime = MTWCore.getDefault().getRuntimesManager() - .getRuntime(element.getAttribute("sourceRuntime")); - return runtime; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/MobileWebRuntime.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/MobileWebRuntime.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/** - * 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.mtw.core.internal.runtimes; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; - -public final class MobileWebRuntime implements IMobileWebRuntime { - private final IConfigurationElement element; - - public MobileWebRuntime(IConfigurationElement element) { - this.element = element; - } - - public String getId() { - return element.getAttribute("id"); - } - - public String getName() { - return element.getAttribute("name"); - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/RuntimesManagerImpl.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/RuntimesManagerImpl.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/** - * 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.mtw.core.internal.runtimes; - -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; -import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntimeManager; -import org.symbian.tools.mtw.core.runtimes.IPackager; - -public final class RuntimesManagerImpl implements IMobileWebRuntimeManager { - private final Map runtimes = new TreeMap(); - private final Map> packagers = new HashMap>(); - - public RuntimesManagerImpl() { - collectRuntimes(); - collectPackagers(); - } - - private void collectPackagers() { - IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( - MTWCore.PLUGIN_ID, "packagers"); - for (IConfigurationElement element : elements) { - final String target = element.getAttribute("targetRuntime"); - final IMobileWebRuntime targetRuntime = getRuntime(target); - if (targetRuntime == null) { - MTWCore.log("Runtime %s referenced from plugin %s was not found", target, element - .getDeclaringExtension().getNamespaceIdentifier()); - break; - } - - final String source = element.getAttribute("sourceRuntime"); - IMobileWebRuntime sourceRuntime; - if (source == null) { - sourceRuntime = targetRuntime; - } else { - sourceRuntime = getRuntime(source); - if (sourceRuntime == null) { - MTWCore.log("Runtime %s referenced from plugin %s was not found", source, element - .getDeclaringExtension().getNamespaceIdentifier()); - break; - } - } - IPackager packager = new LazyPackager(element); - Map map = packagers.get(targetRuntime); - if (map == null) { - map = new HashMap(); - packagers.put(targetRuntime, map); - } - map.put(sourceRuntime, packager); - } - } - - private void collectRuntimes() { - IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( - MTWCore.PLUGIN_ID, "runtimes"); - for (IConfigurationElement element : elements) { - final MobileWebRuntime runtime = new MobileWebRuntime(element); - runtimes.put(runtime.getId(), runtime); - } - } - - public IPackager getPackager(IMTWProject project) { - return getPackager(project, project.getTargetRuntime()); - } - - public IPackager getPackager(IMTWProject project, IMobileWebRuntime runtime) { - final Map map = packagers.get(runtime); - if (map != null) { - return map.get(project.getTargetRuntime()); - } - return null; - } - - public IMobileWebRuntime getRuntime(String id) { - return runtimes.get(id); - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/projects/IMTWProject.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/projects/IMTWProject.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/** - * 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.mtw.core.projects; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IProgressMonitor; -import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; - -public interface IMTWProject { - /** - * @return primary target runtime of this project. Can never return null. - */ - IMobileWebRuntime getTargetRuntime(); - - /** - * @return workspace project that back this MTW project. - */ - IProject getProject(); - - /** - * @return symbolic MTW project name. - */ - String getName(); - - /** - * Validate project configuration and contents. - * - * @return true if the project has no errors. Warnings do not count. - */ - boolean validate(IProgressMonitor monitor); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/projects/IMTWProjectProvider.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/projects/IMTWProjectProvider.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/** - * 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.mtw.core.projects; - -import org.eclipse.core.resources.IProject; - -/** - * Bridges between project models. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface IMTWProjectProvider { - /** - * Returns {@link IMTWProject} object that works with specified {@link IProject} object. - * @return non-null object - */ - IMTWProject create(IProject project); - - /** - * @return true if the {@link IMTWProject} object can be created. - */ - boolean isSupportedProject(IProject project); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IMobileWebRuntime.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IMobileWebRuntime.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/** - * 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.mtw.core.runtimes; - -/** - * Represents mobile web runtimes supported by the IDE - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface IMobileWebRuntime { - /** - * @return unique runtime ID - */ - String getId(); - - /** - * @return user-readable runtime name - */ - String getName(); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IMobileWebRuntimeManager.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IMobileWebRuntimeManager.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/** - * 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.mtw.core.runtimes; - -import org.symbian.tools.mtw.core.projects.IMTWProject; - -/** - * Manages mobile web runtimes. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface IMobileWebRuntimeManager { - /** - * Shorthand method to obtain packager for project default runtime. - */ - IPackager getPackager(IMTWProject project); - - /** - * Returns packager that can create a packaged application for provided - * runtime from the given project. - * - * @return null if the project cannot be packaged for - * specified runtime - */ - IPackager getPackager(IMTWProject project, IMobileWebRuntime runtime); - - /** - * Returns runtimes for the given ID. Runtime will not be null. - * - * @throws IllegalArgumentException if there is no runtime with the - * provided ID. It is assumed that this can only be caused by a broken - * install or coding error on IDE provider side. - */ - IMobileWebRuntime getRuntime(String id); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackager.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackager.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/** - * 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.mtw.core.runtimes; - -import java.io.File; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.symbian.tools.mtw.core.projects.IMTWProject; - -/** - * Packager creates a runtime-specific application package that can be - * deployed to compatible targets. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface IPackager { - /** - * Synchronously packages application for the specified runtime. - * - * @return {@link File} denoting location of the application package that can be deployed to targets - */ - File packageApplication(IMTWProject project, IProgressMonitor monitor) - throws CoreException; - - /** - * @return application package root-relative path where the workspace resource will be packaged. Can be null. - */ - IPath getPathInPackage(IResource resource); - - /** - * @return file type of the application archive - */ - String getFileType(IMTWProject project); - - /** - * @return target runtime that this packager packages for - */ - IMobileWebRuntime getTargetRuntime(); - - /** - * @return source runtime. It is the runtime that the project should target to be packaged with this packager. - */ - IMobileWebRuntime getSourceRuntime(); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackagerDelegate.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackagerDelegate.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/** - * 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.mtw.core.runtimes; - -import java.io.File; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.symbian.tools.mtw.core.projects.IMTWProject; - -/** - * Delegate performs application packaging. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface IPackagerDelegate { - /** - * Synchronously packages application for the specified runtime. - * - * @return URI of the application package that can be deployed to targets - */ - File packageApplication(IMTWProject project, IProgressMonitor monitor) throws CoreException; - - /** - * @return application package root-relative path where the workspace resource will be packaged. Can be null. - */ - IPath getPathInPackage(IResource resource); - - /** - * @return file type of the application archive - */ - String getFileType(IMTWProject project); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/utilities/ZipApplicationVisitor.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/utilities/ZipApplicationVisitor.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -/** - * 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.mtw.core.utilities; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.runtimes.IPackagerDelegate; - -/** - * Use this visitor to zip application if the web runtime uses zip archive as application - * distribution format. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public class ZipApplicationVisitor implements IResourceVisitor { - private static final int DEFAULT_BUFFER_SIZE = 65536; - private final ZipOutputStream zipStream; - private final IPackagerDelegate packager; - - public ZipApplicationVisitor(ZipOutputStream zipStream, IPackagerDelegate packager) { - this.zipStream = zipStream; - this.packager = packager; - } - - public boolean visit(IResource resource) throws CoreException { - IPath path = packager.getPathInPackage(resource); - if (path != null && resource.getType() == IResource.FILE) { - zip(path, resource); - } - return true; - } - - private void zip(IPath path, IResource file) throws CoreException { - ZipEntry zipEntry = new ZipEntry(path.toString()); - try { - zipStream.putNextEntry(zipEntry); - if (file.getType() == IResource.FILE) { - InputStream contents = ((IFile) file).getContents(); - try { - copy(contents, zipStream); - } finally { - contents.close(); - } - } - zipStream.closeEntry(); - } catch (IOException e) { - throw new CoreException(new Status(IStatus.ERROR, MTWCore.PLUGIN_ID, String.format("Can't package %s", file - .getFullPath().toString()), e)); - } - } - - public static int copy(InputStream input, OutputStream output) throws IOException { - long count = copyLarge(input, output); - if (count > Integer.MAX_VALUE) { - return -1; - } - return (int) count; - } - - public static long copyLarge(InputStream input, OutputStream output) throws IOException { - byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; - long count = 0; - int n = 0; - while (-1 != (n = input.read(buffer))) { - output.write(buffer, 0, n); - count += n; - } - return count; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/ITMWConstants.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/ITMWConstants.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,24 @@ +/** + * 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.tmw.core; + +public interface ITMWConstants { + String CORE_FACET = "tmw.core"; + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/TMWCore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/TMWCore.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,84 @@ +package org.symbian.tools.tmw.core; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; +import org.symbian.tools.tmw.core.internal.projects.ProjectsSupportManager; +import org.symbian.tools.tmw.core.internal.runtimes.RuntimeClasspathManager; +import org.symbian.tools.tmw.core.internal.runtimes.RuntimesManagerImpl; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntimeManager; + +/** + * The activator class controls the plug-in life cycle + */ +public class TMWCore extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.symbian.tools.tmw.core"; //$NON-NLS-1$ + + // The shared instance + private static TMWCore plugin; + + private IMobileWebRuntimeManager runtimesManager; + private ProjectsSupportManager projectsSupport; + private RuntimeClasspathManager classpathManager; + + /** + * The constructor + */ + public TMWCore() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + runtimesManager = new RuntimesManagerImpl(); + projectsSupport = new ProjectsSupportManager(); + classpathManager = new RuntimeClasspathManager(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + public IMobileWebRuntimeManager getRuntimesManager() { + return runtimesManager; + } + + public RuntimeClasspathManager getClasspathManager() { + return classpathManager; + } + + public IMTWProject create(IProject project) { + return projectsSupport.create(project); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TMWCore getDefault() { + return plugin; + } + + public static void log(String message, Exception exception) { + getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); + } + + public static void log(String message, Object... args) { + log(String.format(message, args), (Exception) null); + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/InstallFacetAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/InstallFacetAction.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,55 @@ +/** + * 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.tmw.core.internal.facets; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.wst.common.project.facet.core.IDelegate; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.jsdt.core.IIncludePathEntry; +import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.core.JavaScriptCore; + +public class InstallFacetAction implements IDelegate { + + public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) + throws CoreException { + final IJavaScriptProject jsProject = JavaScriptCore.create(project); + final IIncludePathEntry[] rawIncludepath = jsProject.getRawIncludepath(); + final Path path = new Path("tmw.coreLibrary"); + final int originalEntryCount = rawIncludepath.length; + + IIncludePathEntry[] newIncludepath = new IIncludePathEntry[originalEntryCount + 1]; + System.arraycopy(rawIncludepath, 0, newIncludepath, 0, originalEntryCount); + for (IIncludePathEntry entry : rawIncludepath) { + if (entry.getPath().equals(path)) { + newIncludepath = null; + break; + } + } + if (newIncludepath != null) { + final IIncludePathEntry newContainerEntry = JavaScriptCore.newContainerEntry(path, false); + newIncludepath[originalEntryCount] = newContainerEntry; + jsProject.setRawIncludepath(newIncludepath, monitor); + } + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/UninstallFacetAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/UninstallFacetAction.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,35 @@ +/** + * 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.tmw.core.internal.facets; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.wst.common.project.facet.core.IDelegate; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; + +public class UninstallFacetAction implements IDelegate { + + public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) + throws CoreException { + // TODO Auto-generated method stub + + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/LazyIncludePathProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/LazyIncludePathProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,48 @@ +/** + * 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.tmw.core.internal.projects; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.wst.jsdt.core.IIncludePathEntry; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IFacetIncludePathProvider; +import org.symbian.tools.tmw.core.projects.IMTWProject; + +public class LazyIncludePathProvider implements IFacetIncludePathProvider { + private final IConfigurationElement element; + private LazyIncludePathProvider provider; + + public LazyIncludePathProvider(IConfigurationElement element) { + this.element = element; + } + + public IIncludePathEntry[] getEntries(IMTWProject project) { + if (provider == null) { + try { + provider = (LazyIncludePathProvider) element.createExecutableExtension("class"); + } catch (CoreException e) { + TMWCore.log(null, e); + return new IIncludePathEntry[0]; + } + } + return provider.getEntries(project); + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/MTWFacetedProjectProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/MTWFacetedProjectProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,51 @@ +/** + * 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.tmw.core.internal.projects; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; +import org.symbian.tools.tmw.core.ITMWConstants; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.projects.IMTWProjectProvider; + +public class MTWFacetedProjectProvider implements IMTWProjectProvider { + private final Map projects = new WeakHashMap(); + + public IMTWProject create(IProject project) { + if (!projects.containsKey(project)) { + projects.put(project, new TMWFacetedProject(project)); + } + return projects.get(project); + } + + public boolean isSupportedProject(IProject project) { + try { + return FacetedProjectFramework.hasProjectFacet(project, ITMWConstants.CORE_FACET); + } catch (CoreException e) { + TMWCore.log(null, e); + return false; + } + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/ProjectProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/ProjectProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,78 @@ +/** + * 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.tmw.core.internal.projects; + +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.expressions.EvaluationResult; +import org.eclipse.core.expressions.Expression; +import org.eclipse.core.expressions.ExpressionConverter; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.projects.IMTWProjectProvider; + +public class ProjectProvider implements IMTWProjectProvider { + private final IConfigurationElement element; + private final Expression expression; + private IMTWProjectProvider provider; + + public ProjectProvider(IConfigurationElement element) throws CoreException { + this.element = element; + IConfigurationElement[] children = element.getChildren("enablement"); + if (children.length == 1) { + expression = ExpressionConverter.getDefault().perform(children[0]); + } else { + expression = null; + if (children.length > 1) { + TMWCore.log( + "Project extension in plugin %s has several elements. All expressions will be ignored.", + element.getNamespaceIdentifier()); + } + } + } + + public IMTWProject create(IProject project) { + return getProvider().create(project); + } + + private IMTWProjectProvider getProvider() { + if (provider == null) { + try { + provider = (IMTWProjectProvider) element.createExecutableExtension("class"); + } catch (CoreException e) { + throw new RuntimeException(e); + } + } + return provider; + } + + public boolean isSupportedProject(final IProject project) { + try { + final EvaluationResult result = expression.evaluate(new EvaluationContext(null, project)); + if (!EvaluationResult.FALSE.equals(result)) { + return getProvider().isSupportedProject(project); + } + } catch (CoreException e) { + TMWCore.log(null, e); + } + return false; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/ProjectsSupportManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/ProjectsSupportManager.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,60 @@ +/** + * 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.tmw.core.internal.projects; + +import java.util.Collection; +import java.util.LinkedList; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; + +public class ProjectsSupportManager { + private Collection providers = null; + + public IMTWProject create(IProject project) { + if (providers == null) { + readProviders(); + } + for (ProjectProvider provider : providers) { + if (provider.isSupportedProject(project)) { + return provider.create(project); + } + } + return null; + } + + private void readProviders() { + providers = new LinkedList(); + IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCore.PLUGIN_ID, "projectProvider"); + for (IConfigurationElement element : configurationElements) { + if (element.getName().equals("projectProvider")) { + try { + providers.add(new ProjectProvider(element)); + } catch (CoreException e) { + TMWCore.log(null, e); + } + } + } + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/StaticIncludePathProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/StaticIncludePathProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,66 @@ +/** + * 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.tmw.core.internal.projects; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.wst.jsdt.core.IIncludePathEntry; +import org.eclipse.wst.jsdt.core.JavaScriptCore; +import org.osgi.framework.Bundle; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IFacetIncludePathProvider; +import org.symbian.tools.tmw.core.projects.IMTWProject; + +public class StaticIncludePathProvider implements IFacetIncludePathProvider { + private final IConfigurationElement element; + private IIncludePathEntry[] entries; + + public StaticIncludePathProvider(IConfigurationElement element) { + this.element = element; + } + + public IIncludePathEntry[] getEntries(IMTWProject project) { + if (entries == null) { + final String name = element.getContributor().getName(); + final String path = element.getAttribute("file"); + final Bundle bundle = Platform.getBundle(name); + final URL url = FileLocator.find(bundle, new Path(path), null); + try { + final URL fileURL = FileLocator.toFileURL(url); + final File file = new File(fileURL.toURI()); + final IIncludePathEntry entry = JavaScriptCore.newLibraryEntry(new Path(file.getAbsolutePath()), null, + null); + entries = new IIncludePathEntry[] { entry }; + } catch (IOException e) { + TMWCore.log(String.format("Can't find file %s in plugin %s", path, name), e); + } catch (URISyntaxException e) { + TMWCore.log(String.format("Can't find file %s in plugin %s", path, name), e); + } + } + return entries; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,91 @@ +/** + * 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.tmw.core.internal.projects; + +import java.util.List; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +public class TMWFacetedProject implements IMTWProject { + private final IProject project; + + public TMWFacetedProject(IProject project) { + this.project = project; + } + + public String getName() { + return project.getName(); + } + + public IProject getProject() { + return project; + } + + public IMobileWebRuntime getTargetRuntime() { + try { + final IFacetedProject fproj = ProjectFacetsManager.create(project); + final IRuntime runtime = fproj.getPrimaryRuntime(); + if (runtime != null) { + final List components = runtime.getRuntimeComponents(); + if (!components.isEmpty()) { + final IRuntimeComponentVersion version = components.get(0).getRuntimeComponentVersion(); + return TMWCore.getDefault().getRuntimesManager() + .getRuntime(version.getRuntimeComponentType().getId(), version.getVersionString()); + } + } + } catch (CoreException e) { + TMWCore.log(null, e); + } + return null; + } + + public boolean validate(IProgressMonitor monitor) { + try { + project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + IMarker[] markers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); + + boolean hasErrors = false; + for (IMarker marker : markers) { + if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) { + hasErrors = true; + break; + } + } + return !hasErrors; + } catch (CoreException e1) { + // Proofing from coding exceptions in JSDT + TMWCore.log(null, e1); + } + return false; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWPropertyTester.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWPropertyTester.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,40 @@ +/** + * 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.tmw.core.internal.projects; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IResource; +import org.symbian.tools.tmw.core.TMWCore; + +public class TMWPropertyTester extends PropertyTester { + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + if ("istmwproject".equals(property)) { + return isTMWProject(receiver); + } + return false; + } + + private boolean isTMWProject(Object receiver) { + if (receiver instanceof IResource) { + return TMWCore.getDefault().create(((IResource) receiver).getProject()) != null; + } + return false; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/LazyPackager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/LazyPackager.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,83 @@ +/** + * 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.tmw.core.internal.runtimes; + +import java.io.File; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.core.runtimes.IPackagerDelegate; + +public class LazyPackager implements IPackager { + private final IConfigurationElement element; + private IPackagerDelegate packager; + + public LazyPackager(IConfigurationElement element) { + this.element = element; + } + + public File packageApplication(IMTWProject project, IProgressMonitor monitor) throws CoreException { + return getPackager().packageApplication(project, monitor); + } + + private IPackagerDelegate getPackager() { + if (packager == null) { + try { + packager = (IPackagerDelegate) element.createExecutableExtension("delegate"); + } catch (CoreException e) { + TMWCore.log(String.format("Cannot instantiate %s from plugin %s", element.getAttribute("delegate"), + element.getDeclaringExtension().getNamespaceIdentifier()), e); + throw new RuntimeException(e); + } + } + return packager; + } + + public IPath getPathInPackage(IResource resource) { + return getPackager().getPathInPackage(resource); + } + + public String getFileType(IMTWProject project) { + return getPackager().getFileType(project); + } + + public IMobileWebRuntime getTargetRuntime() { + String id = element.getAttribute("target-runtime"); + if (id != null) { + return TMWCore.getDefault().getRuntimesManager() + .getRuntime(id, element.getAttribute("target-runtime-version")); + } else { + return getSourceRuntime(); + } + } + + public IMobileWebRuntime getSourceRuntime() { + IMobileWebRuntime runtime = TMWCore.getDefault().getRuntimesManager() + .getRuntime(element.getAttribute("source-runtime"), element.getAttribute("source-runtime-version")); + return runtime; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainer.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,81 @@ +/** + * 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.tmw.core.internal.runtimes; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.eclipse.wst.jsdt.core.IIncludePathEntry; +import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.core.IJsGlobalScopeContainer; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +public class MobileRuntimeLibraryContainer implements IJsGlobalScopeContainer { + private final IPath containerPath; + private final IJavaScriptProject project; + + public MobileRuntimeLibraryContainer(IJavaScriptProject project, IPath containerPath) { + this.project = project; + this.containerPath = containerPath; + } + + public IIncludePathEntry[] getIncludepathEntries() { + final IMTWProject proj = TMWCore.getDefault().create(project.getProject()); + if (proj != null) { + try { + IFacetedProject facetedProject = ProjectFacetsManager.create(project.getProject(), false, + new NullProgressMonitor()); + if (facetedProject != null) { + return TMWCore.getDefault().getClasspathManager().getProjectClasspathEntries(facetedProject); + } + } catch (CoreException e) { + TMWCore.log(null, e); + } + } + return new IIncludePathEntry[0]; + } + + public String getDescription() { + final IMTWProject proj = TMWCore.getDefault().create(project.getProject()); + if (proj != null) { + final IMobileWebRuntime targetRuntime = proj.getTargetRuntime(); + if (targetRuntime != null) { + return String.format("%s API", targetRuntime.getName()); + } + } + return "Mobile Web Runtime Library"; + } + + public int getKind() { + return K_SYSTEM; + } + + public IPath getPath() { + return containerPath; + } + + public String[] resolvedLibraryImport(String realImport) { + return new String[] { realImport }; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainerInitializer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainerInitializer.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,116 @@ +/** + * 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.tmw.core.internal.runtimes; + +import java.net.URI; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.wst.jsdt.core.IIncludePathEntry; +import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.core.IJsGlobalScopeContainer; +import org.eclipse.wst.jsdt.core.IJsGlobalScopeContainerInitializer; +import org.eclipse.wst.jsdt.core.JavaScriptCore; +import org.eclipse.wst.jsdt.core.JsGlobalScopeContainerInitializer; +import org.eclipse.wst.jsdt.core.compiler.libraries.LibraryLocation; +import org.symbian.tools.tmw.core.TMWCore; + +public class MobileRuntimeLibraryContainerInitializer extends JsGlobalScopeContainerInitializer implements + IJsGlobalScopeContainerInitializer { + + public boolean allowAttachJsDoc() { + return false; + } + + public boolean canUpdateJsGlobalScopeContainer(IPath containerPath, IJavaScriptProject project) { + return true; + } + + public String[] containerSuperTypes() { + return new String[0]; + } + + public Object getComparisonID(IPath containerPath, IJavaScriptProject project) { + return containerPath.append(project.getElementName()); + } + + @Override + public String getDescription() { + return "Project library with mobile web runtime APIs"; + } + + public String getDescription(IPath containerPath, IJavaScriptProject project) { + return getDescription(); + } + + public IJsGlobalScopeContainer getFailureContainer(final IPath containerPath, IJavaScriptProject project) { + return new IJsGlobalScopeContainer() { + + public String getDescription() { + final String description = MobileRuntimeLibraryContainerInitializer.this.getDescription(); + return description; + } + + public IIncludePathEntry[] getIncludepathEntries() { + return new IIncludePathEntry[0]; + } + + public int getKind() { + return K_APPLICATION; + } + + public IPath getPath() { + return containerPath; + } + + public String[] resolvedLibraryImport(String a) { + return new String[0]; + } + }; + } + + public URI getHostPath(IPath path, IJavaScriptProject project) { + return null; + } + + public String getInferenceID() { + return null; + } + + public LibraryLocation getLibraryLocation() { + return null; + } + + public void initialize(IPath containerPath, IJavaScriptProject project) throws CoreException { + if (!project.isOpen() || TMWCore.getDefault().create(project.getProject()) != null) { + JavaScriptCore.setJsGlobalScopeContainer(containerPath, new IJavaScriptProject[] { project }, + new IJsGlobalScopeContainer[] { new MobileRuntimeLibraryContainer(project, containerPath) }, null); + } + } + + public void removeFromProject(IJavaScriptProject project) { + // Do nothing + } + + public void requestJsGlobalScopeContainerUpdate(IPath containerPath, IJavaScriptProject project, + IJsGlobalScopeContainer containerSuggestion) throws CoreException { + // TODO + System.out.println("abc"); + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeStub.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeStub.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,70 @@ +/** + * 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.tmw.core.internal.runtimes; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeBridge; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion; +import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +/** + * Integrates mobile web runtime with the faceted project runtime framework. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +@SuppressWarnings("unchecked") +public class MobileRuntimeStub implements IRuntimeBridge.IStub { + private final IMobileWebRuntime runtime; + private final Map properties = new TreeMap(); + + public MobileRuntimeStub(IMobileWebRuntime runtime) { + this.runtime = runtime; + properties.put("localized-name", runtime.getName()); + } + + private IRuntimeComponent getComponent(String string, String version) { + final IRuntimeComponentType componentType = RuntimeManager.getRuntimeComponentType(string); + final IRuntimeComponentVersion v = componentType.getVersion(version); + return RuntimeManager.createRuntimeComponent(v, Collections.EMPTY_MAP); + } + + public List getRuntimeComponents() { + final List components = new LinkedList(); + components.add(getComponent(runtime.getId(), runtime.getVersion())); + components.add(getComponent("tmw.core", "1.0")); + for (IConfigurationElement element : ((MobileWebRuntime) runtime).getComponentElements()) { + components.add(getComponent(element.getAttribute("id"), element.getAttribute("version"))); + } + return components; + } + + public Map getProperties() { + return properties; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimesBridge.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimesBridge.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,56 @@ +/** + * 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.tmw.core.internal.runtimes; + +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeBridge; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +public class MobileRuntimesBridge implements IRuntimeBridge { + private final Map stubs = new TreeMap(); + + public Set getExportedRuntimeNames() throws CoreException { + final IMobileWebRuntime[] allRuntimes = TMWCore.getDefault().getRuntimesManager().getAllRuntimes(); + final Set ids = new TreeSet(); + for (IMobileWebRuntime runtime : allRuntimes) { + ids.add(runtime.getId() + ":" + runtime.getVersion()); + } + return ids; + } + + public IStub bridge(String name) throws CoreException { + if (!stubs.containsKey(name)) { + final int ind = name.indexOf(":"); + if (ind > 0) { + stubs.put( + name, + new MobileRuntimeStub(TMWCore.getDefault().getRuntimesManager() + .getRuntime(name.substring(0, ind), name.substring(ind + 1)))); + } + } + return stubs.get(name); + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileWebRuntime.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileWebRuntime.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,47 @@ +/** + * 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.tmw.core.internal.runtimes; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +public final class MobileWebRuntime implements IMobileWebRuntime { + private final IConfigurationElement element; + + public MobileWebRuntime(IConfigurationElement element) { + this.element = element; + } + + public String getId() { + return element.getAttribute("component-id"); + } + + public String getVersion() { + return element.getAttribute("component-version"); + } + + public String getName() { + return element.getAttribute("name"); + } + + public IConfigurationElement[] getComponentElements() { + return element.getChildren("runtime-component"); + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimeClasspathManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimeClasspathManager.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,237 @@ +/** + * 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.tmw.core.internal.runtimes; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.common.project.facet.core.IVersion; +import org.eclipse.wst.common.project.facet.core.IVersionExpr; +import org.eclipse.wst.common.project.facet.core.util.internal.VersionExpr; +import org.eclipse.wst.common.project.facet.core.util.internal.Versionable; +import org.eclipse.wst.jsdt.core.IIncludePathEntry; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.internal.projects.LazyIncludePathProvider; +import org.symbian.tools.tmw.core.internal.projects.StaticIncludePathProvider; +import org.symbian.tools.tmw.core.projects.IFacetIncludePathProvider; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +@SuppressWarnings("restriction") +public class RuntimeClasspathManager { + private static final class VersionedEntry { + protected final IVersionExpr versionExpression; + protected final T entry; + + public VersionedEntry(String versionExpression, T entry) { + if (versionExpression == null) { + this.versionExpression = null; + } else { + IVersionExpr expr; + try { + expr = new VersionExpr(new VersionableObject(), versionExpression, null); + } catch (CoreException e) { + expr = null; + TMWCore.log(null, e); + } + this.versionExpression = expr; + } + this.entry = entry; + } + + public boolean matches(String version) { + if (versionExpression == null) { // Any version + return true; + } + if (version == null) { // Unspecified + return false; + } + return versionExpression.check(new Version(version)); + } + } + + private static final class VersionableObject extends Versionable { + @Override + public String getPluginId() { + return TMWCore.PLUGIN_ID; + } + + @Override + public String createVersionNotFoundErrMsg(String verstr) { + return "Version not found"; + } + } + + private static final class Version implements IVersion { + private final String version; + + public Version(String version) { + this.version = version; + } + + public int compareTo(Object o) { + return version.compareTo(((IVersion) o).getVersionString()); + } + + public String getVersionString() { + return version; + } + } + + private final Map>>>>> providers = new HashMap>>>>>(); + private final boolean ready = false; + + public IIncludePathEntry[] getProjectClasspathEntries(IFacetedProject project) { + collectProviders(); + final IMTWProject p = TMWCore.getDefault().create(project.getProject()); + if (p != null) { + final IMobileWebRuntime runtime = p.getTargetRuntime(); + final Map>> facetToEntry; + if (runtime != null) { + facetToEntry = join(getMatchingEntries(runtime.getId(), runtime.getVersion(), providers)); + } else { + facetToEntry = join(getMatchingEntries(null, null, providers)); + } + final Collection entries = getMatchingEntries(null, null, facetToEntry); + final Set facets = project.getProjectFacets(); + for (IProjectFacetVersion facet : facets) { + entries.addAll(getMatchingEntries(facet.getProjectFacet().getId(), facet.getVersionString(), + facetToEntry)); + } + final Collection pathEntries = new HashSet(); + for (IFacetIncludePathProvider[] providers : entries) { + for (IFacetIncludePathProvider provider : providers) { + pathEntries.addAll(Arrays.asList(provider.getEntries(p))); + } + } + return pathEntries.toArray(new IIncludePathEntry[pathEntries.size()]); + } + return new IIncludePathEntry[0]; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private synchronized void collectProviders() { + if (!ready) { + final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCore.PLUGIN_ID, "runtimeIncludePath"); + final Map>> entries = collectFaceletEntries(elements); + final VersionedEntry>>> entry = new VersionedEntry( + null, entries); + providers.put(null, Collections.singleton(entry)); + for (IConfigurationElement element : elements) { + if ("runtime-include-path".equals(element.getName())) { + final String id = element.getAttribute("id"); + Collection>>>> versions = providers + .get(id); + if (versions == null) { + versions = new LinkedList>>>>(); + providers.put(id, versions); + } + final Map>> facetProviders = new HashMap>>(); + final IFacetIncludePathProvider[] collection = collectProviders(element.getChildren()); + final VersionedEntry ent = new VersionedEntry(null, collection); + facetProviders.put(null, Collections.singleton(ent)); + facetProviders.putAll(collectFaceletEntries(element.getChildren())); + final VersionedEntry>>> ver = new VersionedEntry>>>( + element.getAttribute("version"), facetProviders); + versions.add(ver); + } + } + } + } + + private IFacetIncludePathProvider[] collectProviders(IConfigurationElement[] children) { + final Collection providers = new LinkedList(); + for (IConfigurationElement element : children) { + if ("include-path-entry".equals(element.getName())) { + providers.add(new StaticIncludePathProvider(element)); + } else if ("include-path-provider".equals(element.getName())) { + providers.add(new LazyIncludePathProvider(element)); + } + } + return providers.toArray(new IFacetIncludePathProvider[providers.size()]); + } + + public Map>> collectFaceletEntries( + IConfigurationElement[] elements) { + final Map>> faceletsToProviders = new HashMap>>(); + for (IConfigurationElement element : elements) { + if ("facet-include-path".equals(element.getName())) { + final IFacetIncludePathProvider[] providers = collectProviders(element.getChildren()); + final VersionedEntry versionedEntry = new VersionedEntry( + element.getAttribute("version"), providers); + final String id = element.getAttribute("facelet-id"); + Collection> provs = faceletsToProviders.get(id); + if (provs == null) { + provs = new LinkedList>(); + faceletsToProviders.put(id, provs); + } + provs.add(versionedEntry); + } + } + return faceletsToProviders; + } + + private Map> join(Collection>> maps) { + final Map> res = new HashMap>(); + for (Map> map : maps) { + for (Map.Entry> entry : map.entrySet()) { + if (res.containsKey(entry.getKey())) { + res.get(entry.getKey()).addAll(entry.getValue()); + } else { + res.put(entry.getKey(), new LinkedList(entry.getValue())); + } + } + } + return res; + } + + private Collection getMatchingEntries(String id, String version, + Map>> map) { + final Collection> entries = new LinkedList>(); + Collection> versionedEntries = map.get(null); + if (versionedEntries != null) { + entries.addAll(versionedEntries); + } + if (id != null) { + versionedEntries = map.get(id); + if (versionedEntries != null) { + entries.addAll(versionedEntries); + } + } + final Collection res = new LinkedList(); + for (VersionedEntry versionedEntry : entries) { + if (versionedEntry.matches(version)) { + res.add(versionedEntry.entry); + } + } + return res; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimesManagerImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimesManagerImpl.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,105 @@ +/** + * 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.tmw.core.internal.runtimes; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntimeManager; +import org.symbian.tools.tmw.core.runtimes.IPackager; + +public final class RuntimesManagerImpl implements IMobileWebRuntimeManager { + private Map> packagers; + private Map runtimes; + + public RuntimesManagerImpl() { + collectRuntimes(); + } + + private void collectPackagers() { + packagers = new HashMap>(); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCore.PLUGIN_ID, "packagers"); + for (IConfigurationElement element : elements) { + IPackager packager = new LazyPackager(element); + Map map = packagers.get(packager.getTargetRuntime()); + if (map == null) { + map = new HashMap(); + packagers.put(packager.getTargetRuntime(), map); + } + map.put(packager.getSourceRuntime(), packager); + } + } + + private void collectRuntimes() { + runtimes = new TreeMap(); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCore.PLUGIN_ID, "runtimes"); + for (IConfigurationElement element : elements) { + final MobileWebRuntime runtime = new MobileWebRuntime(element); + runtimes.put(getInternalId(runtime.getId(), runtime.getVersion()), runtime); + } + } + + public IMobileWebRuntime[] getAllRuntimes() { + if (runtimes == null) { + collectRuntimes(); + } + final Collection rts = runtimes.values(); + return rts.toArray(new IMobileWebRuntime[rts.size()]); + } + + public IPackager getPackager(IMTWProject project) { + return getPackager(project, project.getTargetRuntime()); + } + + public IPackager getPackager(IMTWProject project, IMobileWebRuntime runtime) { + if (packagers == null) { + collectPackagers(); + } + final Map map = packagers.get(runtime); + if (map != null) { + return map.get(project.getTargetRuntime()); + } + return null; + } + + public IMobileWebRuntime getRuntime(String id, String version) { + if (runtimes == null) { + collectRuntimes(); + } + final IMobileWebRuntime runtime = runtimes.get(getInternalId(id, version)); + if (runtime == null) { + TMWCore.log(String.format("Runtime %s@%s", id, version), new Exception()); + } + return runtime; + } + + private String getInternalId(String id, String version) { + return id + ":" + version; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IFacetIncludePathProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IFacetIncludePathProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,25 @@ +/** + * 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.tmw.core.projects; + +import org.eclipse.wst.jsdt.core.IIncludePathEntry; + +public interface IFacetIncludePathProvider { + IIncludePathEntry[] getEntries(IMTWProject project); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IMTWProject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IMTWProject.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,47 @@ +/** + * 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.tmw.core.projects; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +public interface IMTWProject { + /** + * @return primary target runtime of this project. Can never return null. + */ + IMobileWebRuntime getTargetRuntime(); + + /** + * @return workspace project that back this MTW project. + */ + IProject getProject(); + + /** + * @return symbolic MTW project name. + */ + String getName(); + + /** + * Validate project configuration and contents. + * + * @return true if the project has no errors. Warnings do not count. + */ + boolean validate(IProgressMonitor monitor); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IMTWProjectProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IMTWProjectProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,39 @@ +/** + * 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.tmw.core.projects; + +import org.eclipse.core.resources.IProject; + +/** + * Bridges between project models. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IMTWProjectProvider { + /** + * Returns {@link IMTWProject} object that works with specified {@link IProject} object. + * @return non-null object + */ + IMTWProject create(IProject project); + + /** + * @return true if the {@link IMTWProject} object can be created. + */ + boolean isSupportedProject(IProject project); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntime.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntime.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,41 @@ +/** + * 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.tmw.core.runtimes; + +/** + * Represents mobile web runtimes supported by the IDE + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IMobileWebRuntime { + /** + * @return unique runtime ID + */ + String getId(); + + /** + * @return version of the primary runtime component + */ + String getVersion(); + + /** + * @return user-readable runtime name + */ + String getName(); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntimeManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntimeManager.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,56 @@ +/** + * 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.tmw.core.runtimes; + +import org.symbian.tools.tmw.core.projects.IMTWProject; + +/** + * Manages mobile web runtimes. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IMobileWebRuntimeManager { + /** + * Shorthand method to obtain packager for project default runtime. + */ + IPackager getPackager(IMTWProject project); + + /** + * Returns packager that can create a packaged application for provided + * runtime from the given project. + * + * @return null if the project cannot be packaged for + * specified runtime + */ + IPackager getPackager(IMTWProject project, IMobileWebRuntime runtime); + + /** + * Returns runtimes for the given ID. Runtime will not be null. + * + * @throws IllegalArgumentException if there is no runtime with the + * provided ID. It is assumed that this can only be caused by a broken + * install or coding error on IDE provider side. + */ + IMobileWebRuntime getRuntime(String id, String version); + + /** + * @return list of all runtimes known to an IDE + */ + IMobileWebRuntime[] getAllRuntimes(); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IPackager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IPackager.java Mon Aug 09 15:18:34 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.tmw.core.runtimes; + +import java.io.File; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.symbian.tools.tmw.core.projects.IMTWProject; + +/** + * Packager creates a runtime-specific application package that can be + * deployed to compatible targets. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IPackager { + /** + * Synchronously packages application for the specified runtime. + * + * @return {@link File} denoting location of the application package that can be deployed to targets + */ + File packageApplication(IMTWProject project, IProgressMonitor monitor) + throws CoreException; + + /** + * @return application package root-relative path where the workspace resource will be packaged. Can be null. + */ + IPath getPathInPackage(IResource resource); + + /** + * @return file type of the application archive + */ + String getFileType(IMTWProject project); + + /** + * @return target runtime that this packager packages for + */ + IMobileWebRuntime getTargetRuntime(); + + /** + * @return source runtime. It is the runtime that the project should target to be packaged with this packager. + */ + IMobileWebRuntime getSourceRuntime(); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IPackagerDelegate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/runtimes/IPackagerDelegate.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,51 @@ +/** + * 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.tmw.core.runtimes; + +import java.io.File; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.symbian.tools.tmw.core.projects.IMTWProject; + +/** + * Delegate performs application packaging. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IPackagerDelegate { + /** + * Synchronously packages application for the specified runtime. + * + * @return URI of the application package that can be deployed to targets + */ + File packageApplication(IMTWProject project, IProgressMonitor monitor) throws CoreException; + + /** + * @return application package root-relative path where the workspace resource will be packaged. Can be null. + */ + IPath getPathInPackage(IResource resource); + + /** + * @return file type of the application archive + */ + String getFileType(IMTWProject project); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/utilities/ZipApplicationVisitor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/utilities/ZipApplicationVisitor.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,99 @@ +/** + * 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.tmw.core.utilities; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IPackagerDelegate; + +/** + * Use this visitor to zip application if the web runtime uses zip archive as application + * distribution format. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public class ZipApplicationVisitor implements IResourceVisitor { + private static final int DEFAULT_BUFFER_SIZE = 65536; + private final ZipOutputStream zipStream; + private final IPackagerDelegate packager; + + public ZipApplicationVisitor(ZipOutputStream zipStream, IPackagerDelegate packager) { + this.zipStream = zipStream; + this.packager = packager; + } + + public boolean visit(IResource resource) throws CoreException { + IPath path = packager.getPathInPackage(resource); + if (path != null && resource.getType() == IResource.FILE) { + zip(path, resource); + } + return true; + } + + private void zip(IPath path, IResource file) throws CoreException { + ZipEntry zipEntry = new ZipEntry(path.toString()); + try { + zipStream.putNextEntry(zipEntry); + if (file.getType() == IResource.FILE) { + InputStream contents = ((IFile) file).getContents(); + try { + copy(contents, zipStream); + } finally { + contents.close(); + } + } + zipStream.closeEntry(); + } catch (IOException e) { + throw new CoreException(new Status(IStatus.ERROR, TMWCore.PLUGIN_ID, String.format("Can't package %s", file + .getFullPath().toString()), e)); + } + } + + public static int copy(InputStream input, OutputStream output) throws IOException { + long count = copyLarge(input, output); + if (count > Integer.MAX_VALUE) { + return -1; + } + return (int) count; + } + + public static long copyLarge(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + long count = 0; + int n = 0; + while (-1 != (n = input.read(buffer))) { + output.write(buffer, 0, n); + count += n; + } + return count; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/.project --- a/org.symbian.tools.mtw.ui/.project Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.ui/.project Mon Aug 09 15:18:34 2010 -0700 @@ -1,6 +1,6 @@ - org.symbian.tools.mtw.ui + org.symbian.tools.tmw.ui diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/META-INF/MANIFEST.MF --- a/org.symbian.tools.mtw.ui/META-INF/MANIFEST.MF Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.ui/META-INF/MANIFEST.MF Mon Aug 09 15:18:34 2010 -0700 @@ -1,9 +1,9 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Mobile Tools for Web main UI plug-in -Bundle-SymbolicName: org.symbian.tools.mtw.ui;singleton:=true +Bundle-SymbolicName: org.symbian.tools.tmw.ui;singleton:=true Bundle-Version: 1.0.0.qualifier -Bundle-Activator: org.symbian.tools.mtw.ui.MTWCoreUI +Bundle-Activator: org.symbian.tools.tmw.ui.TMWCoreUI Bundle-Vendor: Symbian Foundation Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, @@ -13,11 +13,12 @@ org.eclipse.wst.jsdt.ui;bundle-version="1.1.0", org.eclipse.wst.jsdt.core;bundle-version="1.1.0", org.eclipse.ui.console;bundle-version="3.5.0", - org.symbian.tools.mtw.core;bundle-version="1.0.0" + org.symbian.tools.tmw.core;bundle-version="1.0.0", + org.eclipse.wst.common.project.facet.ui;bundle-version="1.4.100", + org.eclipse.core.expressions;bundle-version="3.4.200" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Bundle-ClassPath: lib/org.bluecove_2.1.1.jar, . -Export-Package: org.symbian.tools.mtw.ui, - org.symbian.tools.mtw.ui.deployment, - org.symbian.tools.mtw.ui.deployment.bluetooth +Export-Package: org.symbian.tools.tmw.ui, + org.symbian.tools.tmw.ui.deployment diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/plugin.xml --- a/org.symbian.tools.mtw.ui/plugin.xml Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.ui/plugin.xml Mon Aug 09 15:18:34 2010 -0700 @@ -102,7 +102,7 @@ @@ -125,31 +125,31 @@ + definitionId="org.symbian.tools.tmwprojectselected"> + point="org.symbian.tools.tmw.ui.deploymentTargetType"> @@ -158,8 +158,8 @@ + adaptableType="org.symbian.tools.tmw.ui.deployment.bluetooth.BluetoothTarget" + class="org.symbian.tools.tmw.ui.deployment.bluetooth.BluetoothTargetAdapterFactory"> @@ -168,19 +168,74 @@ + adaptableType="org.symbian.tools.tmw.internal.deployment.targets.ExternalApplicationDeploymentType" + class="org.symbian.tools.tmw.internal.deployment.targets.AdapterFactory"> + point="org.symbian.tools.tmw.ui.targetPresentation"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/schema/deploymentTargetType.exsd --- a/org.symbian.tools.mtw.ui/schema/deploymentTargetType.exsd Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.ui/schema/deploymentTargetType.exsd Mon Aug 09 15:18:34 2010 -0700 @@ -1,9 +1,9 @@ - + - + MTW extenders can provide deployment targets - these include bluetooth devices, device emulators etc. @@ -62,7 +62,7 @@ - + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/schema/targetPresentation.exsd --- a/org.symbian.tools.mtw.ui/schema/targetPresentation.exsd Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.mtw.ui/schema/targetPresentation.exsd Mon Aug 09 15:18:34 2010 -0700 @@ -1,9 +1,9 @@ - + - + Provides UI extensions to customize deployment target presentation. @@ -55,7 +55,7 @@ - + @@ -65,7 +65,7 @@ Details pane that will show information about selected deployment target. This pane is limited in height. - + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DefaultDeploymentTypePresentation.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DefaultDeploymentTypePresentation.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Text; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.ITargetDetailsPane; - -public class DefaultDeploymentTypePresentation implements ITargetDetailsPane { - private Text text; - - public void init(Context page) { - } - - public void setTarget(IDeploymentTarget target) { - text.setText(target.getDescription()); - } - - public void createControl(Composite parent) { - text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); - } - - public Control getControl() { - return text; - } - - public IStatus validate() { - return Status.OK_STATUS; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeployWizardContext.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeployWizardContext.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.ui.MTWCoreUI; - -public class DeployWizardContext { - private DeploymentTargetWrapper target; - private final IMTWProject project; - private boolean logging; - - public DeployWizardContext(IMTWProject project) { - this.project = project; - } - - public void setTarget(DeploymentTargetWrapper target) { - this.target = target; - } - - public DeploymentTargetWrapper getTarget() { - return target; - } - - public IMTWProject getProject() { - return project; - } - - public DeploymentTargetWrapper[] getDeploymentTargets() { - final DeploymentTargetTypeDescriptor[] providers = MTWCoreUI.getDefault().getDeploymentTypesRegistry() - .getProviders(); - Collection targets = new HashSet(); - - for (DeploymentTargetTypeDescriptor provider : providers) { - if (provider.supports(project)) { - targets.addAll(Arrays.asList(provider.getTargets(project))); - } - } - return targets.toArray(new DeploymentTargetWrapper[targets.size()]); - } - - public void doSearch(IProgressMonitor monitor) throws CoreException { - final DeploymentTargetTypeDescriptor[] providers = MTWCoreUI.getDefault().getDeploymentTypesRegistry() - .getProviders(); - monitor.beginTask("Discovering deployment targets", providers.length * 10); - for (DeploymentTargetTypeDescriptor descriptor : providers) { - descriptor.discoverTargets(new SubProgressMonitor(monitor, 10)); - } - monitor.done(); - } - - public boolean areTargetsReady() { - final DeploymentTargetTypeDescriptor[] providers = MTWCoreUI.getDefault().getDeploymentTypesRegistry() - .getProviders(); - for (DeploymentTargetTypeDescriptor descriptor : providers) { - if (!descriptor.targetsDiscovered()) { - return false; - } - } - return true; - } - - public void setLogging(boolean logging) { - this.logging = logging; - } - - public boolean isLogging() { - return logging; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetPresentationsManager.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetPresentationsManager.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; -import org.symbian.tools.mtw.ui.deployment.ITargetDetailsPane; - -public class DeploymentTargetPresentationsManager { - private Map presentations; - - public ITargetDetailsPane createDetailsPane(IDeploymentTargetType targetType) { - readRegistry(); - final IConfigurationElement element = presentations.get(targetType); - if (element != null && element.getAttribute("detailsPane") != null) { - try { - return (ITargetDetailsPane) element.createExecutableExtension("detailsPane"); - } catch (CoreException e) { - MTWCoreUI.log(e); - } - } - return new DefaultDeploymentTypePresentation(); - } - - private synchronized void readRegistry() { - if (presentations == null) { - presentations = new HashMap(); - final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( - MTWCoreUI.PLUGIN_ID, "targetPresentation"); - for (IConfigurationElement element : elements) { - final String runtimeId = element.getAttribute("targetTypeId"); - final IDeploymentTargetType targetType = MTWCoreUI.getDefault().getDeploymentTypesRegistry() - .getType(runtimeId); - if (targetType == null) { - MTWCoreUI.log("Runtime %s was not found. It is referenced from plugin %s", runtimeId, element - .getContributor().getName()); - continue; - } else { - presentations.put(targetType, element); - } - } - } - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetTypeDescriptor.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetTypeDescriptor.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import java.util.Map; -import java.util.WeakHashMap; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.jface.resource.ImageDescriptor; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; - -public final class DeploymentTargetTypeDescriptor implements IDeploymentTargetType { - public class NullProvider implements IDeploymentTargetType { - public IDeploymentTarget[] getTargets(IMTWProject project) { - return null; - } - - public void discoverTargets(IProgressMonitor monitor) throws CoreException { - // Do nothing - } - - public IDeploymentTarget findTarget(IMTWProject project, String id) { - return null; - } - - public boolean targetsDiscovered() { - return true; - } - - public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { - return null; // No scheduling - } - } - - private static final DeploymentTargetWrapper[] NO_TARGETS = new DeploymentTargetWrapper[0]; - private final IConfigurationElement element; - private IDeploymentTargetType type; - private final Map wrappers = new WeakHashMap(); - private ImageDescriptor imageDescriptor = null; - - public DeploymentTargetTypeDescriptor(IConfigurationElement element) { - this.element = element; - } - - public boolean supports(IMTWProject project) { - // We will support more declarative filtering later - return true; - } - - public DeploymentTargetWrapper[] getTargets(IMTWProject project) { - final DeploymentTargetWrapper[] targets = wrap(getProvider().getTargets(project)); - return targets != null ? targets : NO_TARGETS; - } - - private DeploymentTargetWrapper[] wrap(IDeploymentTarget[] targets) { - if (targets == null) { - return new DeploymentTargetWrapper[0]; - } else { - final DeploymentTargetWrapper[] w = new DeploymentTargetWrapper[targets.length]; - for (int i = 0; i < targets.length; i++) { - w[i] = wrap(targets[i]); - } - return w; - } - } - - private DeploymentTargetWrapper wrap(final IDeploymentTarget target) { - DeploymentTargetWrapper wrapper = wrappers.get(target); - if (wrapper == null) { - wrapper = new DeploymentTargetWrapper(target, this); - wrappers.put(target, wrapper); - } - return wrapper; - } - - public void discoverTargets(IProgressMonitor monitor) throws CoreException { - getProvider().discoverTargets(monitor); - } - - public IDeploymentTarget findTarget(IMTWProject project, String id) { - return wrap(getProvider().findTarget(project, id)); - } - - private synchronized IDeploymentTargetType getProvider() { - if (type == null) { - try { - type = (IDeploymentTargetType) element.createExecutableExtension("class"); - } catch (CoreException e) { - MTWCoreUI.log("Cannot instantiate provider " + getId(), e); - type = new NullProvider(); - } - } - return type; - } - - public String getId() { - return element.getAttribute("id"); - } - - public boolean targetsDiscovered() { - return getProvider().targetsDiscovered(); - } - - public int getPriority() { - final String attribute = element.getAttribute("priority"); - if (attribute != null && attribute.trim().length() > 0) { - try { - return Integer.parseInt(attribute); - } catch (NumberFormatException e) { - MTWCoreUI.log("%s is not a valid priority value for %s provider", attribute, getId()); - } - } - return 0; - } - - public ImageDescriptor getImageDescriptor() { - if (imageDescriptor == null) { - final String image = element.getAttribute("icon"); - if (image == null) { - imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); - } else { - imageDescriptor = MTWCoreUI.imageDescriptorFromPlugin(element.getNamespaceIdentifier(), image); - } - } - return imageDescriptor; - } - - public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { - return type.getSchedulingRule(target); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (obj instanceof IDeploymentTargetType) { - return obj.equals(type); - } - if (getClass() != obj.getClass()) { - return false; - } - DeploymentTargetTypeDescriptor other = (DeploymentTargetTypeDescriptor) obj; - if (getId() == null) { - if (other.getId() != null) { - return false; - } - } else if (!getId().equals(other.getId())) { - return false; - } - return true; - } - - public boolean isLongRunning() { - return Boolean.valueOf(element.getAttribute("long-running")); - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetTypesRegistry.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetTypesRegistry.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; - -public class DeploymentTargetTypesRegistry { - private DeploymentTargetTypeDescriptor[] descriptors; - - public DeploymentTargetTypesRegistry() { - readExtensions(); - } - - private void readExtensions() { - final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( - MTWCoreUI.PLUGIN_ID, "deploymentTargetType"); - descriptors = new DeploymentTargetTypeDescriptor[elements.length]; - for (int i = 0; i < elements.length; i++) { - descriptors[i] = new DeploymentTargetTypeDescriptor(elements[i]); - } - } - - public DeploymentTargetTypeDescriptor[] getProviders() { - return descriptors; - } - - public IDeploymentTargetType getType(String id) { - DeploymentTargetTypeDescriptor[] providers = getProviders(); - for (DeploymentTargetTypeDescriptor descriptor : providers) { - if (descriptor.getId().equals(id)) { - return descriptor; - } - } - return null; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetWizardPage.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetWizardPage.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,248 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import java.lang.reflect.InvocationTargetException; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.util.Policy; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.jface.wizard.IWizardContainer; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.part.PageBook; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.ProjectMemo; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; -import org.symbian.tools.mtw.ui.deployment.ITargetDetailsPane; - -public class DeploymentTargetWizardPage extends WizardPage implements ITargetDetailsPane.Context { - private final DeployWizardContext context; - private PageBook descriptions; - private Control emptyness; - private final Set inited = new HashSet(); - private TableViewer list; - private final Map panes = new HashMap(); - private final IDeploymentTarget prev; - - public DeploymentTargetWizardPage(DeployWizardContext context, ProjectMemo memo) { - super("TargetPage", "Select Deployment Target", null); - this.context = context; - prev = memo.getPreviousDeploymentTarget(); - setDescription(MessageFormat.format("Select emulator or device to deploy WRT application ''{0}''", context - .getProject().getProject().getName())); - } - - public void createControl(Composite parent) { - Composite root = new Composite(parent, SWT.NONE); - - root.setLayout(new FormLayout()); - - list = new TableViewer(root, SWT.BORDER); - list.setContentProvider(new ArrayContentProvider()); - list.setLabelProvider(new WorkbenchLabelProvider()); - list.setSorter(new ViewerSorter() { - @Override - public int category(Object element) { - return ((DeploymentTargetWrapper) element).getCategory(); - } - }); - list.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = ((IStructuredSelection) event.getSelection()); - DeploymentTargetWrapper target = (DeploymentTargetWrapper) selection.getFirstElement(); - selectDeploymentTarget(target); - } - }); - list.addDoubleClickListener(new IDoubleClickListener() { - public void doubleClick(DoubleClickEvent event) { - if (getWizard().performFinish()) { - IWizardContainer container = getWizard().getContainer(); - if (container instanceof WizardDialog) { - ((WizardDialog) container).close(); - } - } - } - }); - final Button search = new Button(root, SWT.NONE); - search.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - doBluetoothSearch(search); - } - }); - search.setText("Discover"); - search.setImage(MTWCoreUI.getImages().getDiscoverButtonIcon()); - - descriptions = new PageBook(root, SWT.BORDER); - emptyness = new Composite(descriptions, SWT.NONE); - - FormData data = new FormData(); - data.left = new FormAttachment(0, 5); - data.right = new FormAttachment(100, -5); - data.bottom = new FormAttachment(100, -5); - data.height = 80; - descriptions.setLayoutData(data); - - data = new FormData(); - data.top = new FormAttachment(0, 5); - data.right = new FormAttachment(100, -5); - search.setLayoutData(data); - - data = new FormData(); - data.left = new FormAttachment(0, 5); - data.top = new FormAttachment(0, 5); - data.bottom = new FormAttachment(descriptions, -10); - data.right = new FormAttachment(search, -10); - - list.getControl().setLayoutData(data); - list.setInput(context.getDeploymentTargets()); - setPageComplete(false); - - if (prev != null) { - list.setSelection(new StructuredSelection(prev)); - } - setControl(root); - } - - protected void doBluetoothSearch(final Button search) { - try { - final ISelection sel = list.getSelection(); - getContainer().run(true, true, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - monitor.beginTask("Searching for Bluetooth devices", IProgressMonitor.UNKNOWN); - try { - context.doSearch(new SubProgressMonitor(monitor, 100)); - } catch (CoreException e) { - Policy.getStatusHandler().show(e.getStatus(), "WRT Application Deployment"); - } - monitor.done(); - search.getDisplay().asyncExec(new Runnable() { - public void run() { - list.setInput(context.getDeploymentTargets()); - if (!sel.isEmpty()) { - list.setSelection(sel); - selectDeploymentTarget((DeploymentTargetWrapper) ((IStructuredSelection) sel) - .getFirstElement()); - } else { - DeploymentTargetWrapper[] deploymentTargets = context.getDeploymentTargets(); - if (deploymentTargets.length == 0) { - selectDeploymentTarget(null); - } else { - list.setSelection(new StructuredSelection(deploymentTargets[0])); - selectDeploymentTarget(deploymentTargets[0]); - } - } - } - }); - } - }); - } catch (InvocationTargetException e) { - MTWCoreUI.log(e); - } catch (InterruptedException e) { - MTWCoreUI.log(e); - } - } - - private IPackager getPackager() { - return MTWCore.getDefault().getRuntimesManager().getPackager(context.getProject()); - } - - protected void selectDeploymentTarget(DeploymentTargetWrapper target) { - if (target != null) { - if (!inited.contains(target)) { - target.init(context.getProject(), getPackager(), - MTWCoreUI.getMemo(context.getProject()).getMemo(target.getType().getId(), target)); - inited.add(target); - } - context.setTarget(target); - - IDeploymentTargetType type = target.getType(); - ITargetDetailsPane pane = panes.get(type); - if (pane == null) { - pane = MTWCoreUI.getDefault().getPresentations().createDetailsPane(type); - pane.createControl(descriptions); - pane.init(this); - panes.put(type, pane); - } - pane.setTarget(target.getActualTarget()); - descriptions.showPage(pane.getControl()); - } else { - descriptions.showPage(emptyness); - context.setTarget(null); - setPageComplete(false); - setMessage(null); - } - revalidate(); - } - - protected void toggleLogging(boolean logging) { - context.setLogging(logging); - } - - public void revalidate() { - String error = null; - String warning = !context.areTargetsReady() ? "Press \"Discover\" to find more deployment targets" : null; - if (context.getTarget() == null) { - error = "Select device or emulator to deploy the application"; - } else { - final IStatus validate = panes.get(context.getTarget().getType()).validate(); - if (validate.getSeverity() == IStatus.ERROR) { - error = validate.getMessage(); - } else if (validate.getSeverity() == IStatus.WARNING) { - warning = validate.getMessage(); - } - } - setErrorMessage(error); - setMessage(warning, IStatus.WARNING); - setPageComplete(error == null); - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetWrapper.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetWrapper.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.ui.model.IWorkbenchAdapter2; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; - -public class DeploymentTargetWrapper implements IDeploymentTarget { - public class WorkbenchAdapter2Wrapper implements IWorkbenchAdapter2 { - private final IWorkbenchAdapter2 adapter; - - public WorkbenchAdapter2Wrapper(IWorkbenchAdapter2 adapter) { - this.adapter = adapter; - } - - public RGB getForeground(Object element) { - return adapter.getForeground(((DeploymentTargetWrapper) element).getActualTarget()); - } - - public RGB getBackground(Object element) { - return adapter.getBackground(((DeploymentTargetWrapper) element).getActualTarget()); - } - - public FontData getFont(Object element) { - return adapter.getFont(((DeploymentTargetWrapper) element).getActualTarget()); - } - } - - public class WorkbenchAdapterWrapper implements IWorkbenchAdapter { - private final IWorkbenchAdapter adapter; - - public WorkbenchAdapterWrapper(IWorkbenchAdapter adapter) { - this.adapter = adapter; - } - - public Object[] getChildren(Object o) { - return adapter.getChildren(((DeploymentTargetWrapper) o).getActualTarget()); - } - - public ImageDescriptor getImageDescriptor(Object object) { - return adapter.getImageDescriptor(((DeploymentTargetWrapper) object).getActualTarget()); - } - - public String getLabel(Object o) { - return adapter.getLabel(((DeploymentTargetWrapper) o).getActualTarget()); - } - - public Object getParent(Object o) { - return adapter.getParent(((DeploymentTargetWrapper) o).getActualTarget()); - } - } - - private final DeploymentTargetTypeDescriptor type; - private final IDeploymentTarget target; - - public void save(IMemento memento) { - target.save(memento); - } - - public void init(IMTWProject project, IPackager packager, IMemento memento) { - target.init(project, packager, memento); - } - - public DeploymentTargetWrapper(IDeploymentTarget target, DeploymentTargetTypeDescriptor type) { - this.target = target; - this.type = type; - } - - public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) - throws CoreException { - return target.deploy(project, packager, monitor); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - DeploymentTargetWrapper other = (DeploymentTargetWrapper) obj; - if (target == null) { - if (other.target != null) { - return false; - } - } else if (!target.equals(other.target)) { - return false; - } - return true; - } - - public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { - Object a = target.getAdapter(adapter); - if (IWorkbenchAdapter.class.isAssignableFrom(adapter)) { - return a == null ? new TargetWorkbenchAdapter(this) : new WorkbenchAdapterWrapper((IWorkbenchAdapter) a); - } else if (IWorkbenchAdapter2.class.isAssignableFrom(adapter)) { - return a == null ? new TargetWorkbenchAdapter(this) : new WorkbenchAdapter2Wrapper((IWorkbenchAdapter2) a); - } else { - return a; - } - } - - public int getCategory() { - return type.getPriority() * 0xFFFF + (type.getId().hashCode() & 0xFFFF); - } - - public String getId() { - return target.getId(); - } - - public String getName() { - return target.getName(); - } - - public String getProviderId() { - return type.getId(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((target == null) ? 0 : target.hashCode()); - return result; - } - - public DeploymentTargetTypeDescriptor getType() { - return type; - } - - public IDeploymentTarget getActualTarget() { - return target; - } - - public String getDescription() { - return target.getDescription(); - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/TargetWorkbenchAdapter.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/TargetWorkbenchAdapter.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/** - * 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.mtw.internal.deployment; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.ui.model.IWorkbenchAdapter2; - -public class TargetWorkbenchAdapter implements IWorkbenchAdapter, IWorkbenchAdapter2 { - /** - * - */ - private final DeploymentTargetWrapper deploymentTargetWrapper; - - /** - * @param deploymentTargetWrapper - */ - TargetWorkbenchAdapter(DeploymentTargetWrapper deploymentTargetWrapper) { - this.deploymentTargetWrapper = deploymentTargetWrapper; - } - - public String getLabel(Object object) { - return this.deploymentTargetWrapper.getName(); - } - - public ImageDescriptor getImageDescriptor(Object object) { - return this.deploymentTargetWrapper.getType().getImageDescriptor(); - } - - public RGB getForeground(Object element) { - // TODO Auto-generated method stub - return null; - } - - public RGB getBackground(Object element) { - // TODO Auto-generated method stub - return null; - } - - public FontData getFont(Object element) { - // TODO Auto-generated method stub - return null; - } - - public Object[] getChildren(Object o) { - // TODO Auto-generated method stub - return null; - } - - public Object getParent(Object o) { - // TODO Auto-generated method stub - return null; - } -} \ No newline at end of file diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/externalapp/FilesystemDeploymentTarget.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/externalapp/FilesystemDeploymentTarget.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/** - * 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.mtw.internal.deployment.externalapp; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; - -public class FilesystemDeploymentTarget implements IDeploymentTargetType { - - public FilesystemDeploymentTarget() { - // TODO Auto-generated constructor stub - } - - public IDeploymentTarget[] getTargets(IMTWProject project) { - // TODO Auto-generated method stub - return null; - } - - public void discoverTargets(IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public IDeploymentTarget findTarget(IMTWProject project, String id) { - // TODO Auto-generated method stub - return null; - } - - public boolean targetsDiscovered() { - // TODO Auto-generated method stub - return false; - } - - public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { - // TODO Auto-generated method stub - return null; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/AdapterFactory.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/AdapterFactory.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/** - * 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.mtw.internal.deployment.targets; - -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.ui.model.WorkbenchAdapter; - -@SuppressWarnings("rawtypes") -public class AdapterFactory implements IAdapterFactory { - private final IWorkbenchAdapter adapter = new WorkbenchAdapter() { - @Override - public ImageDescriptor getImageDescriptor(Object object) { - if (object instanceof ExternalApplicationDeploymentType) { - return ImageDescriptor.createFromImageData(((ExternalApplicationDeploymentType) object).getProgram() - .getImageData()); - } - return super.getImageDescriptor(object); - } - - public String getLabel(Object object) { - if (object instanceof ExternalApplicationDeploymentType) { - return ((ExternalApplicationDeploymentType) object).getName(); - } - return super.getLabel(object); - }; - }; - - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (adaptableObject instanceof ExternalApplicationDeploymentType - && IWorkbenchAdapter.class.isAssignableFrom(adapterType)) { - return adapter; - } - return null; - } - - public Class[] getAdapterList() { - return new Class[] { IWorkbenchAdapter.class }; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/ExternalApplicationDeploymentType.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/ExternalApplicationDeploymentType.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/** - * 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.mtw.internal.deployment.targets; - -import java.io.File; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.swt.program.Program; -import org.eclipse.ui.IMemento; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; - -public class ExternalApplicationDeploymentType extends PlatformObject implements IDeploymentTargetType, - IDeploymentTarget { - - private IMTWProject project; - - public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) - throws CoreException { - Program app = getExternalApp(project); - File file = packager.packageApplication(project, monitor); - if (file != null) { - app.execute(file.toString()); - return new Status( - IStatus.OK, - MTWCore.PLUGIN_ID, - "Mobile web application was passed as an argument to external application. Please follow its prompts to complete deployment."); - } else { - return new Status(IStatus.ERROR, MTWCore.PLUGIN_ID, "Application packaging failed"); - } - } - - public void discoverTargets(IProgressMonitor monitor) throws CoreException { - // Do nothing - } - - public IDeploymentTarget findTarget(IMTWProject project, String id) { - if (getExternalApp(project) != null) { - return this; - } else { - return null; - } - } - - public String getDescription() { - return getExternalApp(project).getName(); - } - - private Program getExternalApp(IMTWProject project) { - this.project = project; - IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project); - if (packager != null) { - return Program.findProgram(packager.getFileType(project)); - } else { - return null; - } - } - - public String getId() { - return "mtw.externalapp"; - } - - public String getName() { - return "Use external application"; - } - - public Program getProgram() { - return getExternalApp(project); - } - - public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { - return null; - } - - public IDeploymentTarget[] getTargets(IMTWProject project) { - if (getExternalApp(project) != null) { - return new IDeploymentTarget[] { this }; - } else { - return null; - } - } - - public void init(IMTWProject project, IPackager packager, IMemento memento) { - // Do nothing - } - - public void save(IMemento memento) { - // Do nothing - } - - public boolean targetsDiscovered() { - return true; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/FilesystemDeploymentTarget.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/FilesystemDeploymentTarget.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/** - * 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.mtw.internal.deployment.targets; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -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.Path; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.ui.IMemento; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; - -public class FilesystemDeploymentTarget extends PlatformObject implements IDeploymentTargetType, IDeploymentTarget { - private String defaultName; - private IPath path; - - public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException { - final File file = packager.packageApplication(project, monitor); - try { - final InputStream inputStream = new BufferedInputStream(new FileInputStream(file)); - final OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(path.toFile())); - try { - final byte[] buffer = new byte[16384]; - int read = -1; - while ((read = inputStream.read(buffer)) > 0) { - outputStream.write(buffer, 0, read); - } - } finally { - inputStream.close(); - outputStream.close(); - } - } catch (IOException e) { - throw new CoreException( - new Status(IStatus.ERROR, MTWCoreUI.PLUGIN_ID, "Failed to copy application file", e)); - } finally { - file.delete(); - } - return Status.OK_STATUS; - } - - public void discoverTargets(IProgressMonitor monitor) throws CoreException { - // Do nothing - } - - public IDeploymentTarget findTarget(IMTWProject project, String id) { - return getId().equals(id) ? this : null; - } - - public String getDefaultName() { - return defaultName; - } - - public String getDescription() { - return "Copies application package to a location in the local filesystem"; - } - - public String getId() { - return "mtw.filesystem"; - } - - public String getName() { - return "Local filesystem"; - } - - public IPath getPath() { - return path; - } - - public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { - return null; - } - - public IDeploymentTarget[] getTargets(IMTWProject project) { - return new IDeploymentTarget[] { this }; - } - - public void init(IMTWProject project, IPackager packager, IMemento memento) { - defaultName = new Path(project.getName()).addFileExtension(packager.getFileType(project)).toOSString(); - path = null; - String string = memento != null ? memento.getString("path") : null; - if (string == null) { - string = MTWCoreUI.getDefault().getPreferenceStore().getString("path"); - if (string != null) { - final IPath p = Path.fromPortableString(string); - if (p.toFile().isDirectory()) { - this.path = p.append(defaultName); - } - } - } else { - path = Path.fromPortableString(string); - if (!path.removeLastSegments(1).toFile().isDirectory()) { - path = null; - } - } - } - - public void save(IMemento memento) { - memento.putString("path", path.toPortableString()); - MTWCoreUI.getDefault().getPreferenceStore().setValue("path", path.removeLastSegments(1).toPortableString()); - } - - public void setPath(IPath path) { - this.path = path; - } - - public boolean targetsDiscovered() { - return true; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/LocalFileSystemPane.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/targets/LocalFileSystemPane.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/** - * 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.mtw.internal.deployment.targets; - -import java.io.File; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.ITargetDetailsPane; - -public class LocalFileSystemPane implements ITargetDetailsPane { - private Composite root; - private Text location; - private FilesystemDeploymentTarget target; - private Context page; - - public void init(Context page) { - this.page = page; - } - - public void setTarget(IDeploymentTarget target) { - this.target = (FilesystemDeploymentTarget) target; - IPath path = this.target.getPath(); - String string; - if (path == null) { - string = ""; - } else { - string = path.toOSString(); - } - location.setText(string); - page.revalidate(); - } - - public void createControl(Composite parent) { - root = new Composite(parent, SWT.NONE); - root.setLayout(new GridLayout(2, false)); - Label label = new Label(root, SWT.NONE); - label.setText("File name:"); - GridDataFactory.generate(label, 2, 1); - location = new Text(root, SWT.BORDER); - location.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - location.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - page.revalidate(); - } - }); - final Button button = new Button(root, SWT.NONE); - button.setText("Browse..."); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - browse(); - } - }); - } - - protected void browse() { - final FileDialog dialog = new FileDialog(location.getShell(), SWT.SAVE); - dialog.setText("Select Application Package Location"); - dialog.setFileName(target.getDefaultName()); - final IPath path = target.getPath(); - if (path != null) { - dialog.setFilterPath(path.removeLastSegments(1).toOSString()); - } - String newPath = dialog.open(); - if (newPath != null) { - location.setText(newPath); - page.revalidate(); - } - } - - public IStatus validate() { - target.setPath(null); - String path = location.getText(); - if (path.trim().length() == 0) { - return new Status(IStatus.ERROR, MTWCoreUI.PLUGIN_ID, "File name must be specified"); - } else { - final File file = new File(path); - if (!file.getParentFile().isDirectory()) { - return new Status(IStatus.ERROR, MTWCoreUI.PLUGIN_ID, String.format("%s is not a valid folder", - file.getParent())); - } else { - IStatus status = ResourcesPlugin.getWorkspace().validateName(file.getName(), IResource.FILE); - if (status.getSeverity() == IStatus.ERROR) { - return status; - } else { - Path p = new Path(path.trim()); - target.setPath(p); - if (p.toFile().exists()) { - return new Status(IStatus.WARNING, MTWCoreUI.PLUGIN_ID, - "Target file already exists. It will be overwritten."); - } else { - return status; - } - } - } - } - } - - public Control getControl() { - return root; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/ConsoleFactory.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/ConsoleFactory.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2009 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.mtw.ui; - -import org.eclipse.ui.console.ConsolePlugin; -import org.eclipse.ui.console.IConsole; -import org.eclipse.ui.console.IConsoleFactory; -import org.eclipse.ui.console.IConsoleManager; -import org.eclipse.ui.console.MessageConsole; -import org.eclipse.ui.console.MessageConsoleStream; - -public class ConsoleFactory implements IConsoleFactory { - - private static MessageConsole console; - - public void openConsole() { - getConsole(); - console.activate(); - } - - public static MessageConsoleStream createStream() { - getConsole(); - return console.newMessageStream(); - } - - public static void activateConsole() { - getConsole(); - console.activate(); - } - - private synchronized static MessageConsole getConsole() { - if (console == null) { - console = new MessageConsole("Mobile Web Console", null, true); - IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); - consoleManager.addConsoles(new IConsole[]{console}); - } - return console; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/Images.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/Images.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/** - * 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.mtw.ui; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.swt.graphics.Image; - -public final class Images { - private final String DISCOVER_ICON = "icons/full/obj16/discover.gif"; - private final String EXCLUDED_ICON = "icons/full/obj16/excluded.gif"; - private final String BLUETOOTH_ICON = "icons/full/obj16/bluetooth.gif"; - - private final ImageRegistry registry; - - Images(final ImageRegistry registry) { - this.registry = registry; - add(registry, DISCOVER_ICON); - add(registry, EXCLUDED_ICON); - add(registry, BLUETOOTH_ICON); - } - - private void add(final ImageRegistry registry, String icon) { - ImageDescriptor descriptor = MTWCoreUI.imageDescriptorFromPlugin(MTWCoreUI.PLUGIN_ID, icon); - registry.put(icon, descriptor); - } - - public Image getDiscoverButtonIcon() { - return registry.get(DISCOVER_ICON); - } - - public ImageDescriptor getExcludedIconDescriptor() { - return registry.getDescriptor(EXCLUDED_ICON); - } - - public ImageDescriptor getBluetoothImageDescriptor() { - return registry.getDescriptor(BLUETOOTH_ICON); - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/MTWCoreUI.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/MTWCoreUI.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -package org.symbian.tools.mtw.ui; - -import java.util.Map; -import java.util.WeakHashMap; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.internal.deployment.DeploymentTargetPresentationsManager; -import org.symbian.tools.mtw.internal.deployment.DeploymentTargetTypesRegistry; - -/** - * The activator class controls the plug-in life cycle - */ -public class MTWCoreUI extends AbstractUIPlugin { - private final Map MEMOS = new WeakHashMap(); - private final DeploymentTargetTypesRegistry typesRegistry = new DeploymentTargetTypesRegistry(); - - // The plug-in ID - public static final String PLUGIN_ID = "org.symbian.tools.mtw.ui"; //$NON-NLS-1$ - - // The shared instance - private static MTWCoreUI plugin; - private Images images; - private final DeploymentTargetPresentationsManager presentations = new DeploymentTargetPresentationsManager(); - - /** - * The constructor - */ - public MTWCoreUI() { - } - - @Override - protected void initializeImageRegistry(ImageRegistry reg) { - super.initializeImageRegistry(reg); - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - 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) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static MTWCoreUI getDefault() { - return plugin; - } - - public static void log(String message, Exception e) { - getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, e)); - } - - public static void log(String message, Object... args) { - log(String.format(message, args), (Exception) null); - } - - public static void log(Exception e) { - log(null, e); - } - - public static ProjectMemo getMemo(IMTWProject project) { - return getDefault().getMemoForProject(project); - } - - private synchronized ProjectMemo getMemoForProject(IMTWProject project) { - ProjectMemo memo = MEMOS.get(project.getProject()); - if (memo == null) { - memo = new ProjectMemo(project); - MEMOS.put(project.getProject(), memo); - } - return memo; - } - - public DeploymentTargetTypesRegistry getDeploymentTypesRegistry() { - return typesRegistry; - } - - public static Images getImages() { - if (getDefault().images == null) { - getDefault().images = new Images(getDefault().getImageRegistry()); - } - return getDefault().images; - } - - public DeploymentTargetPresentationsManager getPresentations() { - return presentations; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/ProjectMemo.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/ProjectMemo.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/** - * 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.mtw.ui; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.Writer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.XMLMemento; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; - -public class ProjectMemo { - private static final String TARGET_TYPE = "typeId"; - private static final String TARGET = "targetId"; - private static final String TARGET_CONFIGURATION = "target"; - private static final String MEMO_TYPE = "deployment"; - - private final IMTWProject project; - private XMLMemento memento; - - public ProjectMemo(IMTWProject project) { - this.project = project; - } - - public synchronized void setDeploymentTarget(String providerId, IDeploymentTarget target) { - try { - checkMemento(); - memento.putString(TARGET_TYPE, providerId); - memento.putString(TARGET, target.getId()); - IMemento child = null; - IMemento[] children = memento.getChildren(TARGET_CONFIGURATION); - for (IMemento memento : children) { - if (providerId.equals(memento.getString(TARGET_TYPE)) - && target.getId().equals(memento.getString(TARGET))) { - child = memento; - } - } - if (child == null) { - child = memento.createChild(TARGET_CONFIGURATION); - child.putString(TARGET_TYPE, providerId); - child.putString(TARGET, target.getId()); - } - target.save(child); - saveMemento(); - } catch (CoreException e) { - MTWCoreUI.log(e); - } catch (IOException e) { - MTWCoreUI.log(e); - } - } - - private void saveMemento() throws IOException, CoreException { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - final Writer writer = new OutputStreamWriter(os); - memento.save(writer); - writer.close(); - final InputStream stream = new ByteArrayInputStream(os.toByteArray()); - IFile file = getMemoFile(); - if (file.exists()) { - file.setContents(stream, IFile.KEEP_HISTORY, null); - } else { - file.create(stream, false, null); - } - } - - private IFile getMemoFile() { - return project.getProject().getFile(new Path(".settings").append(MTWCoreUI.PLUGIN_ID).addFileExtension("xml")); - } - - private void checkMemento() throws CoreException, IOException { - IFile memoFile = getMemoFile(); - if (memoFile.exists()) { - memento = XMLMemento.createReadRoot(new InputStreamReader(memoFile.getContents(), memoFile.getCharset())); - } else { - memento = XMLMemento.createWriteRoot(MEMO_TYPE); - } - } - - public IDeploymentTarget getPreviousDeploymentTarget() { - try { - checkMemento(); - String type = memento.getString(TARGET_TYPE); - if (type != null) { - final IDeploymentTargetType provider = MTWCoreUI.getDefault().getDeploymentTypesRegistry() - .getType(type); - if (provider != null) { - IDeploymentTarget target = provider.findTarget(project, memento.getString(TARGET)); - if (target != null) { - return target; - } - } - } - } catch (CoreException e) { - MTWCoreUI.log(e); - } catch (IOException e) { - MTWCoreUI.log(e); - } - return null; - } - - public IMemento getMemo(String targetType, IDeploymentTarget target) { - if (memento != null) { - IMemento[] children = memento.getChildren(TARGET_CONFIGURATION); - for (IMemento memento : children) { - if (targetType.equals(memento.getString(TARGET_TYPE)) - && target.getId().equals(memento.getString(TARGET))) { - return memento; - } - } - } - return null; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/UIUtils.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/UIUtils.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/** - * 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.mtw.ui; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.resources.IProject; -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.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; - -public class UIUtils { - public static IMTWProject 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(); - return MTWCore.getDefault().create(project); - } - return null; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/commands/DeployHandler.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/commands/DeployHandler.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/** - * 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.mtw.ui.commands; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.handlers.HandlerUtil; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.ui.UIUtils; -import org.symbian.tools.mtw.ui.deployment.DeployWizard; - -/** - * Our sample handler extends AbstractHandler, an IHandler base class. - * @see org.eclipse.core.commands.IHandler - * @see org.eclipse.core.commands.AbstractHandler - */ -public class DeployHandler extends AbstractHandler { - /** - * The constructor. - */ - public DeployHandler() { - } - - /** - * the command has been executed, so extract extract the needed information - * from the application context. - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); - - final IMTWProject project = UIUtils.getProjectFromCommandContext(event); - if (project != null) { - window.getActivePage().saveAllEditors(true); - if (validate(project, window)) { - new WizardDialog(window.getShell(), new DeployWizard(project)).open(); - } - } - - return null; - } - - private boolean validate(final IMTWProject project, final IWorkbenchWindow window) { - final boolean[] retvalue = { false }; - final ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell()); - try { - dialog.run(true, true, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - retvalue[0] = project.validate(monitor); - } - }); - } catch (InvocationTargetException e) { - MTWCore.log(null, e); - } catch (InterruptedException e) { - MTWCore.log(null, e); - } - if (!retvalue[0]) { - retvalue[0] = MessageDialog.openQuestion(window.getShell(), "Deploying Mobile Web Project", - String.format("Project %s has errors. Are you sure you want to deploy it?", project.getName())); - if (!retvalue[0]) { - try { - window.getActivePage().showView(IPageLayout.ID_PROBLEM_VIEW); - } catch (PartInitException e) { - MTWCore.log(null, e); - } - } - } - return retvalue[0]; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/DeployWizard.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/DeployWizard.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -/** - * 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.mtw.ui.deployment; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.MultiRule; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.ui.statushandlers.StatusManager; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.internal.deployment.DeployWizardContext; -import org.symbian.tools.mtw.internal.deployment.DeploymentTargetWizardPage; -import org.symbian.tools.mtw.internal.deployment.DeploymentTargetWrapper; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.ProjectMemo; - -public final class DeployWizard extends Wizard { - private final DeployWizardContext context; - private final IMTWProject project; - - public DeployWizard(IMTWProject project) { - this.project = project; - setNeedsProgressMonitor(true); - setWindowTitle("Deploy WRT Application"); - context = new DeployWizardContext(project); - } - - @Override - public void addPages() { - addPage(new DeploymentTargetWizardPage(context, MTWCoreUI.getMemo(project))); - } - - @Override - public boolean performFinish() { - final DeploymentTargetWrapper target = context.getTarget(); - if (target.getType().isLongRunning()) { - DeployJob job = new DeployJob(context.getProject(), target); - job.schedule(); - return true; - } else { - final IStatus[] retval = new IStatus[1]; - try { - getContainer().run(false, true, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - retval[0] = doDeploy(target, context.getProject(), monitor); - } - }); - } catch (InvocationTargetException e) { - MTWCoreUI.log(e); - } catch (InterruptedException e) { - MTWCoreUI.log(e); - } - switch (retval[0].getSeverity()) { - case IStatus.ERROR: - StatusManager.getManager().handle(retval[0], StatusManager.SHOW | StatusManager.BLOCK); - return false; - case IStatus.WARNING: - StatusManager.getManager().handle(retval[0], StatusManager.SHOW | StatusManager.BLOCK); - default: - return true; - } - } - } - - @Override - public boolean needsPreviousAndNextButtons() { - return false; - } - - private IStatus doDeploy(DeploymentTargetWrapper target, IMTWProject project, IProgressMonitor monitor) { - IStatus status; - try { - IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project); - status = target.deploy(project, packager, monitor); - } catch (CoreException e) { - status = e.getStatus(); - } - ProjectMemo memo = MTWCoreUI.getMemo(project); - memo.setDeploymentTarget(target.getProviderId(), target); - return status; - } - - private final class DeployJob extends Job { - private final DeploymentTargetWrapper target; - private final IMTWProject project; - - private DeployJob(IMTWProject project, DeploymentTargetWrapper deploymentTarget) { - super(String.format("Deploying %s to %s", project.getName(), deploymentTarget.getName())); - ISchedulingRule rule = deploymentTarget.getType().getSchedulingRule(deploymentTarget.getActualTarget()); - if (rule != null) { - rule = MultiRule.combine(rule, project.getProject()); - } else { - rule = project.getProject(); - } - setRule(rule); - setUser(true); - this.project = project; - this.target = deploymentTarget; - } - - public IStatus run(IProgressMonitor monitor) { - final IStatus status = doDeploy(target, project, monitor); - if (status.getSeverity() != IStatus.ERROR && status.getSeverity() != IStatus.WARNING) { - StatusManager.getManager().handle(status, StatusManager.SHOW); - } - return status; - } - - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/IDeploymentTarget.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/IDeploymentTarget.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/** - * 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.mtw.ui.deployment; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.ui.IMemento; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; - -/** - *

This is particular deployment target instance. It can be a Bluetooth phone - * connection, installed device emulator, FTP server, etc.

- * - *

Targets can be cached and {@link #setProject(WRTProject)} will be called - * if active project was changed. Targets are single-threaded. This class - * methods can be called from non-SWT thread.

- * - *

Following adapters can be provided by either overriding getAdapter method - * or by contributing to org.eclipse.core.runtime.adapters extension point:

- *
  • {@link org.eclipse.ui.IPersistable} - to persist advanced per- - * project target configuration
  • - * {@link org.eclipse.ui.model.IWorkbenchAdapter} or - * {@link org.eclipse.ui.model.IWorkbenchAdapter2} to customize target - * presentation in IDE user interface.
- * - *

Overwriting equals and hashCode might be desirable - * if new objects are created each time user does discovery process.

- * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface IDeploymentTarget extends IAdaptable { - /** - * Returns unique ID. There is no restriction on ID string format. Cannot - * be null - */ - String getId(); - - /** - *

Returns user-readable name. Can be null if - * {@link org.eclipse.ui.model.IWorkbenchAdapter} is provided.

- *

Name is not used for purposes other then presentation and may change - * between invocations

- */ - String getName(); - - /** - * Provides more details about target. This information is only displayed - * to the user and is not important for the application. - */ - String getDescription(); - - /** - * Deploy application to this target. - * - * @param project project to deploy to the target - * @param runtime runtime that will be used to run packaged application - * @param monitor progress monitor to report deployment progress - */ - IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException; - - /** - * Save project-specific settings to the memento. Workspace-wide settings - * should be managed separately. - */ - void save(IMemento memento); - - /** - * Initialize target for project deployment. - */ - void init(IMTWProject project, IPackager packager, IMemento memento); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/IDeploymentTargetType.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/IDeploymentTargetType.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/** - * 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.mtw.ui.deployment; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.symbian.tools.mtw.core.projects.IMTWProject; - -/** - * This interface is for deployment targets providers. - * - * @author Eugene - */ -public interface IDeploymentTargetType { - /** - * Returns list of the targets that accept provided project. Project - * cannot be null. - * @return List of the valid deployment targets. Both null and - * empty array are a valid return value when there are no available targets. - */ - IDeploymentTarget[] getTargets(IMTWProject project); - - /** - * Discovers targets. This can be a long-running task and in most cases - * will be triggered by the user. - */ - void discoverTargets(IProgressMonitor monitor) throws CoreException; - - /** - * Find target based on project and target ID. This method returns - * null if target with given ID cannot be found or if - * the target does not accept project any longer. - */ - IDeploymentTarget findTarget(IMTWProject project, String id); - - /** - * Return false if user needs to trigger long-running - * discovery to see all potential deployment targets. - */ - boolean targetsDiscovered(); - - /** - * @param target that will be used by a {@link org.eclipse.core.runtime.jobs.Job} - * @return scheduling rule that will be used to properly schedule jobs to - * avoid resource access conflicts. Can be null - */ - ISchedulingRule getSchedulingRule(IDeploymentTarget target); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/ITargetDetailsPane.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/ITargetDetailsPane.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/** - * 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.mtw.ui.deployment; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -/** - * Objects of this class provide UI for the users to visualize or configure - * their deployment targets. This object will not be reused between wizard - * deployment wizard restarts. - * There will be one instance for the target type. This object will not be - * instantiated for each target. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface ITargetDetailsPane { - interface Context { - void revalidate(); - } - void init(Context page); - void setTarget(IDeploymentTarget target); - void createControl(Composite parent); - Control getControl(); - IStatus validate(); -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothRule.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothRule.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package org.symbian.tools.mtw.ui.deployment.bluetooth; - -import org.eclipse.core.runtime.jobs.ISchedulingRule; - -public class BluetoothRule implements ISchedulingRule { - public static final ISchedulingRule INSTANCE = new BluetoothRule(); - - private BluetoothRule() { - // No instantiation - } - - public boolean contains(ISchedulingRule rule) { - return isConflicting(rule); - } - - public boolean isConflicting(ISchedulingRule rule) { - return rule instanceof BluetoothRule; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTarget.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTarget.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,321 +0,0 @@ -/** - * 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.mtw.ui.deployment.bluetooth; - -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.MessageFormat; -import java.util.Collection; -import java.util.LinkedList; - -import javax.bluetooth.BluetoothConnectionException; -import javax.bluetooth.BluetoothStateException; -import javax.bluetooth.DeviceClass; -import javax.bluetooth.DiscoveryListener; -import javax.bluetooth.LocalDevice; -import javax.bluetooth.RemoteDevice; -import javax.bluetooth.ServiceRecord; -import javax.bluetooth.UUID; -import javax.microedition.io.Connector; -import javax.obex.ClientSession; -import javax.obex.HeaderSet; -import javax.obex.Operation; -import javax.obex.ResponseCodes; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.ui.IMemento; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; - -public class BluetoothTarget extends PlatformObject implements IDeploymentTarget { - private static final UUID OBEX_OBJECT_PUSH = new UUID(0x1105); - private String serviceURL; - private RemoteDevice device; - protected String[] exceptionCodes = new String[] { "OBEX_HTTP_UNSUPPORTED_TYPE", "OBEX_HTTP_FORBIDDEN" }; - private String message = "Deployment was successful. Please follow on-screen instructions to complete application deployment on your device."; - private final String name; - private final BluetoothTargetType provider; - private final Collection statuses = new LinkedList(); - - public BluetoothTarget(String name, RemoteDevice device, BluetoothTargetType provider) { - this.name = name; - this.device = device; - this.provider = provider; - } - - public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException { - message = "Deployment was successful. Please follow on-screen instructions to complete application deployment on your device."; - statuses.clear(); - monitor.beginTask(String.format("Deploying application %s to %s", project.getName(), name), - IProgressMonitor.UNKNOWN); - final File application = packager.packageApplication(project, new SubProgressMonitor(monitor, 100)); - try { - deployWidget(application, packager.getFileType(project), new SubProgressMonitor(monitor, 10)); - } finally { - application.delete(); - } - monitor.done(); - MultiStatus multiStatus = new MultiStatus(MTWCore.PLUGIN_ID, 0, message, null); - for (IStatus status : statuses) { - multiStatus.add(status); - } - return multiStatus; - } - - private void deployWidget(File inputWidget, String fileType, IProgressMonitor progressMonitor) throws CoreException { - if (device == null) { - provider.discoverTargets(new SubProgressMonitor(progressMonitor, 10)); - if (device == null) { - throw new CoreException(new Status(IStatus.ERROR, MTWCore.PLUGIN_ID, String.format( - "Device %s is not available", name))); - } - } - progressMonitor.beginTask("Deploying application", IProgressMonitor.UNKNOWN); - InputStream in = null; - OutputStream os = null; - Operation putOperation = null; - ClientSession clientSession = null; - try { - if (!provider.isBloothToothConnected()) { - String msg = "Bluetooth is either disabled or not present in the system."; - emitStatus(IStatus.ERROR, msg, progressMonitor); - return; - } - - String message = MessageFormat.format("Searching for the service for the selected device \"{0}\"", - new Object[] { getName() }); - emitStatus(IStatus.OK, message, progressMonitor); - String servicesFound = getServicesFound(); - if (servicesFound == null || servicesFound.length() < 1) { - message = MessageFormat.format("Cannot find service to the device \"{0}\"", new Object[] { getName() }); - emitStatus(IStatus.ERROR, message, progressMonitor); - return; - } - - message = MessageFormat.format("Service for the device \"{0}\" found", new Object[] { getName() }); - emitStatus(IStatus.OK, message, progressMonitor); - - clientSession = (ClientSession) Connector.open(servicesFound); - HeaderSet hsConnectReply = clientSession.connect(null); - if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) { - emitStatus(IStatus.OK, "Failed to connect to the service", progressMonitor); - } - - emitStatus(IStatus.OK, "Deployment Started", progressMonitor); - - HeaderSet hsOperation = clientSession.createHeaderSet(); - - if (progressMonitor.isCanceled()) { - emitStatus(IStatus.CANCEL, "Deployment was canceled", progressMonitor); - return; - } - - // Send widget to server - in = new FileInputStream(inputWidget); - message = MessageFormat.format("Deploying file from {0}", new Object[] { inputWidget.getAbsolutePath() }); - emitStatus(IStatus.OK, message, progressMonitor); - - hsOperation.setHeader(HeaderSet.NAME, inputWidget.getName()); - hsOperation.setHeader(HeaderSet.TYPE, fileType); - int size = (int) inputWidget.length(); - byte file[] = new byte[size]; - hsOperation.setHeader(HeaderSet.LENGTH, new Long(file.length)); - - // Create PUT Operation - putOperation = clientSession.put(hsOperation); - - os = putOperation.openOutputStream(); - - long start = System.currentTimeMillis(); - - byte[] buf = new byte[16 * 1024]; - int len; - while ((len = in.read(buf)) > 0) { - os.write(buf, 0, len); - if (progressMonitor.isCanceled()) { - putOperation.abort(); - emitStatus(IStatus.CANCEL, "Deployment was canceled", progressMonitor); - return; - } - } - - os.flush(); - os.close(); - - long elapsed = System.currentTimeMillis() - start; - emitStatus(IStatus.OK, "elapsed time: " + elapsed / 1000.0 + " seconds", progressMonitor); - - int responseCode = putOperation.getResponseCode(); - if (responseCode == ResponseCodes.OBEX_HTTP_OK) { - message = MessageFormat.format("File deployed to {0}", new Object[] { getName() }); - emitStatus(IStatus.OK, message, progressMonitor); - } else { - message = "Error during deployment, OBEX error: " + responseCode; - emitStatus(IStatus.ERROR, message, progressMonitor); - } - - } catch (BluetoothConnectionException x) { - String message = getExceptionMessage(x.getMessage()); - emitStatus(IStatus.ERROR, message, progressMonitor); - } catch (IOException e) { - String message = getExceptionMessage(e.getMessage()); - emitStatus(IStatus.ERROR, message, progressMonitor); - } finally { - try { - if (in != null) { - in.close(); - } - if (putOperation != null) { - putOperation.close(); - } - if (clientSession != null) { - clientSession.disconnect(null); - clientSession.close(); - } - } catch (EOFException eof) { - // EOFException is now caught - // Ignore the error since deployment has already completed - //Activator.log(IStatus.ERROR, "EOF encountered while cleaning up Bluetooth deployment", eof); - } catch (IOException x) { - MTWCore.log("Error cleaning up BlueTooth deployment", x); - } - } - return; - } - - protected void emitStatus(int severity, String statusDescription, IProgressMonitor monitor) { - statuses.add(new Status(severity, MTWCore.PLUGIN_ID, statusDescription)); - monitor.setTaskName(statusDescription); - if (severity != IStatus.OK) { - message = statusDescription; - } - } - - /** - * Returns the customized methods from the exception error code. If it - * matches it returns the customized message else returns the exception itself - * @param message exception message - * @return the customized message - */ - protected String getExceptionMessage(String message) { - - if (message.contains(exceptionCodes[0])) { - return "Device does not support the widget deployment"; - } else if (message.contains(exceptionCodes[1])) { - return "Deployment rejected by the device"; - } - return message; - } - - public String getId() { - return getName(); - } - - public String getName() { - return name; - } - - private String getServicesFound() { - try { - serviceURL = ""; - UUID serviceUUID = OBEX_OBJECT_PUSH; - - final Object serviceSearchCompletedEvent = new Object(); - - DiscoveryListener listener = new DiscoveryListener() { - - public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { - } - - public void inquiryCompleted(int discType) { - } - - public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { - try { - for (int i = 0; i < servRecord.length; i++) { - if (servRecord[i].getHostDevice().getFriendlyName(false).equals(name)) { - serviceURL = servRecord[i].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, - false); - } - } - } catch (BluetoothStateException e) { - MTWCore.log(e.getMessage(), e); - } catch (IOException e) { - MTWCore.log(e.getMessage(), e); - } - } - - public void serviceSearchCompleted(int transID, int respCode) { - synchronized (serviceSearchCompletedEvent) { - serviceSearchCompletedEvent.notifyAll(); - } - } - - }; - - UUID[] searchUuidSet = new UUID[] { serviceUUID }; - int[] attrIDs = new int[] { 0x0100 }; // Service name - - synchronized (serviceSearchCompletedEvent) { - LocalDevice.getLocalDevice().getDiscoveryAgent() - .searchServices(attrIDs, searchUuidSet, device, listener); - serviceSearchCompletedEvent.wait(); - } - - } catch (IOException e) { - MTWCore.log("Error in Bluetooth service discovery", e); - } catch (InterruptedException e) { - MTWCore.log("Error in Bluetooth service discovery", e); - } - return serviceURL; - } - - public void init(IMTWProject project, IPackager packager, IMemento memento) { - // nothing - } - - public void save(IMemento memento) { - // nothing - } - - public void setAddress(RemoteDevice device) { - this.device = device; - } - - public boolean isDiscovered() { - return device != null; - } - - public String getDescription() { - return device == null ? "This device was remembered from past sessions and may not be available" : String - .format("Remote device with address %s", device.getBluetoothAddress()); - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTargetAdapterFactory.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTargetAdapterFactory.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/** - * 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.mtw.ui.deployment.bluetooth; - -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.ui.model.IWorkbenchAdapter2; - -@SuppressWarnings({ "unchecked", "rawtypes" }) -public class BluetoothTargetAdapterFactory implements IAdapterFactory { - private final BluetoothTargetWorkbenchAdapter workbenchAdapter = new BluetoothTargetWorkbenchAdapter(); - - public Object getAdapter(Object adaptableObject, Class adapterType) { - if ((adapterType.isAssignableFrom(IWorkbenchAdapter.class) || adapterType - .isAssignableFrom(IWorkbenchAdapter2.class)) && adaptableObject instanceof BluetoothTarget) { - return workbenchAdapter; - } - return null; - } - - public Class[] getAdapterList() { - return new Class[] { IWorkbenchAdapter2.class, IWorkbenchAdapter.class }; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTargetType.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTargetType.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -/** - * 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.mtw.ui.deployment.bluetooth; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Collection; -import java.util.Map; -import java.util.TreeMap; - -import javax.bluetooth.BluetoothStateException; -import javax.bluetooth.DeviceClass; -import javax.bluetooth.DiscoveryAgent; -import javax.bluetooth.DiscoveryListener; -import javax.bluetooth.LocalDevice; -import javax.bluetooth.RemoteDevice; -import javax.bluetooth.ServiceRecord; - -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.ISchedulingRule; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.ui.ConsoleFactory; -import org.symbian.tools.mtw.ui.MTWCoreUI; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; - -import com.intel.bluetooth.BlueCoveImpl; - -/** - * Discovers Bluetooth-enabled devices. This code is generic and will not - * perform any checks if the discovered device can run application being - * deployed. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public class BluetoothTargetType implements IDeploymentTargetType { - private final class WrtDiscoveryListener implements DiscoveryListener { - final Object inquiryCompletedEvent; - boolean isCanceled; - final Map prevTargets; - final IProgressMonitor progressMonitor; - - private WrtDiscoveryListener(Map previousTargets, Object inquiryCompletedEvent, - IProgressMonitor progressMonitor) { - this.prevTargets = previousTargets; - this.inquiryCompletedEvent = inquiryCompletedEvent; - this.progressMonitor = progressMonitor; - } - - private void checkCanceled() { - if (!isCanceled && progressMonitor != null) { - if (progressMonitor.isCanceled()) { - try { - LocalDevice.getLocalDevice().getDiscoveryAgent().cancelInquiry(listener); - } catch (BluetoothStateException e) { - MTWCoreUI.log(e); - } - } - } - } - - public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { - try { - final String name = btDevice.getFriendlyName(false); - if (name != null && name.length() > 0) { - final BluetoothTarget target = prevTargets.get(name); - if (target != null) { - target.setAddress(btDevice); - targets.put(name, target); - } else { - targets.put(name, new BluetoothTarget(name, btDevice, BluetoothTargetType.this)); - } - checkCanceled(); - } - } catch (BluetoothStateException e) { - MTWCoreUI.log(e.getMessage(), e); - } catch (IOException e) { - MTWCoreUI.log(e.getMessage(), e); - } - } - - public void inquiryCompleted(int discType) { - synchronized (inquiryCompletedEvent) { - inquiryCompletedEvent.notifyAll(); - } - } - - public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { - } - - public void serviceSearchCompleted(int transID, int respCode) { - } - } - - private static PrintStream savedSysOut; - private boolean discovered = false; - private WrtDiscoveryListener listener; - private Map targets = new TreeMap(); - - public BluetoothTargetType() { - // set parameters for BlueCove - String param = Integer.toString(65 * 1024); - System.setProperty("bluecove.obex.mtu", param); - BlueCoveImpl.setConfigProperty("bluecove.obex.mtu", param); - } - - public void discoverTargets(IProgressMonitor monitor) throws CoreException { - if (!isBloothToothConnected()) { - throw new CoreException(new Status(IStatus.ERROR, MTWCoreUI.PLUGIN_ID, "Bluetooth is not available")); - } - monitor.beginTask("Discovering Bluetooth devices", IProgressMonitor.UNKNOWN); - final Object inquiryCompletedEvent = new Object(); - final Map previousTargets = targets; - targets = new TreeMap(); - - listener = new WrtDiscoveryListener(previousTargets, inquiryCompletedEvent, monitor); - - synchronized (inquiryCompletedEvent) { - boolean started; - try { - started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, listener); - if (started) { - inquiryCompletedEvent.wait(); - discovered = true; - } - } catch (BluetoothStateException e) { - MTWCoreUI.log(e.getMessage(), e); - } catch (InterruptedException e) { - MTWCoreUI.log(e.getMessage(), e); - } - } - monitor.done(); - } - - /** Toggle BlueCove logging - */ - public void enableBlueCoveDiagnostics(boolean enable) { - System.setProperty("bluecove.debug", Boolean.valueOf(enable).toString()); - BlueCoveImpl.instance().enableNativeDebug(enable); - if (enable) { - System.setOut(new PrintStream(ConsoleFactory.createStream())); - } else { - System.setOut(savedSysOut); - } - } - - public IDeploymentTarget findTarget(IMTWProject project, String id) { - if (!isBloothToothConnected()) { - return null; - } - if (discovered) { - return targets.get(id); - } else { - BluetoothTarget target = targets.get(id); - if (target == null) { - target = new BluetoothTarget(id, null, this); - targets.put(id, target); - } - return target; - } - } - - public IDeploymentTarget[] getTargets(IMTWProject project) { - if (targets != null) { - final Collection values = targets.values(); - return values.toArray(new IDeploymentTarget[values.size()]); - } else { - return null; - } - } - - /** - * Check whether the bluetooth is on or not. - * - * @return whether the device is on. - */ - public boolean isBloothToothConnected() { - return LocalDevice.isPowerOn(); - } - - public boolean targetsDiscovered() { - return discovered; - } - - public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { - return BluetoothRule.INSTANCE; - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTargetWorkbenchAdapter.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTargetWorkbenchAdapter.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/** - * 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.mtw.ui.deployment.bluetooth; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.ui.model.IWorkbenchAdapter2; -import org.symbian.tools.mtw.ui.MTWCoreUI; - -public class BluetoothTargetWorkbenchAdapter implements IWorkbenchAdapter, IWorkbenchAdapter2 { - public RGB getForeground(Object element) { - final BluetoothTarget target = (BluetoothTarget) element; - if (!target.isDiscovered()) { - return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay() - .getSystemColor(SWT.COLOR_DARK_GRAY).getRGB(); - } - return null; - } - - public RGB getBackground(Object element) { - return null; - } - - public FontData getFont(Object element) { - return null; - } - - public Object[] getChildren(Object o) { - return null; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return MTWCoreUI.getImages().getBluetoothImageDescriptor(); - } - - public String getLabel(Object o) { - final BluetoothTarget target = (BluetoothTarget) o; - return target.getName(); - } - - public Object getParent(Object o) { - return null; - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/navigator/PackagingInformationDecorator.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/navigator/PackagingInformationDecorator.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/** - * 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.mtw.ui.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.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.ui.MTWCoreUI; - -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 && resource.isAccessible()) { - IMTWProject project = MTWCore.getDefault().create(resource.getProject()); - if (project != null) { - IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project); - if (packager.getPathInPackage(resource) != null) { - decoration.addOverlay(MTWCoreUI.getImages().getExcludedIconDescriptor(), 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 - - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/navigator/RenameMoveActionProvider.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/navigator/RenameMoveActionProvider.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/** - * 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.mtw.ui.navigator; - -import java.util.Collection; -import java.util.HashSet; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.actions.ActionContext; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.navigator.CommonActionProvider; -import org.eclipse.ui.navigator.ICommonActionExtensionSite; -import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; -import org.eclipse.wst.jsdt.ui.actions.IJavaEditorActionDefinitionIds; -import org.eclipse.wst.jsdt.ui.actions.JdtActionConstants; -import org.eclipse.wst.jsdt.ui.actions.MoveAction; -import org.eclipse.wst.jsdt.ui.actions.RenameAction; -import org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction; - -public class RenameMoveActionProvider extends CommonActionProvider { - private SelectionDispatchAction fMoveAction; - private SelectionDispatchAction fRenameAction; - - private final Collection fActions = new HashSet(); - - public void fillActionBars(IActionBars actionBars) { - if (fActions.size() > 0) { - actionBars.setGlobalActionHandler(JdtActionConstants.RENAME, fRenameAction); - actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), fRenameAction); - - actionBars.setGlobalActionHandler(JdtActionConstants.MOVE, fMoveAction); - actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), fMoveAction); - } - } - - public void fillContextMenu(IMenuManager menu) { - menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, new Separator()); - for (IAction action : fActions) { - menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, action); - } - } - - public void init(ICommonActionExtensionSite site) { - ICommonViewerWorkbenchSite workbenchSite= null; - if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) { - workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite(); - } - - // we only initialize the refactor group when in a view part - // (required for the constructor) - if (workbenchSite != null) { - if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { - IViewPart viewPart= (IViewPart) workbenchSite.getPart(); - IWorkbenchPartSite s = viewPart.getSite(); - - fRenameAction= new RenameAction(s); - initUpdatingAction(fRenameAction, workbenchSite.getSelectionProvider(), workbenchSite.getSelectionProvider().getSelection(), IJavaEditorActionDefinitionIds.RENAME_ELEMENT); - fMoveAction= new MoveAction(s); - initUpdatingAction(fMoveAction, workbenchSite.getSelectionProvider(), workbenchSite.getSelectionProvider().getSelection(), IJavaEditorActionDefinitionIds.RENAME_ELEMENT); - } - } - } - - private void initUpdatingAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, String actionDefinitionId){ - action.setActionDefinitionId(actionDefinitionId); - action.update(selection); - if (provider != null) { - provider.addSelectionChangedListener(action); - } - fActions.add(action); - } - - - public void setContext(ActionContext context) { - // Do nothing - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DefaultDeploymentTypePresentation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DefaultDeploymentTypePresentation.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,51 @@ +/** + * 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.tmw.internal.deployment; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Text; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.ITargetDetailsPane; + +public class DefaultDeploymentTypePresentation implements ITargetDetailsPane { + private Text text; + + public void init(Context page) { + } + + public void setTarget(IDeploymentTarget target) { + text.setText(target.getDescription()); + } + + public void createControl(Composite parent) { + text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); + } + + public Control getControl() { + return text; + } + + public IStatus validate() { + return Status.OK_STATUS; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeployWizardContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeployWizardContext.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,93 @@ +/** + * 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.tmw.internal.deployment; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.ui.TMWCoreUI; + +public class DeployWizardContext { + private DeploymentTargetWrapper target; + private final IMTWProject project; + private boolean logging; + + public DeployWizardContext(IMTWProject project) { + this.project = project; + } + + public void setTarget(DeploymentTargetWrapper target) { + this.target = target; + } + + public DeploymentTargetWrapper getTarget() { + return target; + } + + public IMTWProject getProject() { + return project; + } + + public DeploymentTargetWrapper[] getDeploymentTargets() { + final DeploymentTargetTypeDescriptor[] providers = TMWCoreUI.getDefault().getDeploymentTypesRegistry() + .getProviders(); + Collection targets = new HashSet(); + + for (DeploymentTargetTypeDescriptor provider : providers) { + if (provider.supports(project)) { + targets.addAll(Arrays.asList(provider.getTargets(project))); + } + } + return targets.toArray(new DeploymentTargetWrapper[targets.size()]); + } + + public void doSearch(IProgressMonitor monitor) throws CoreException { + final DeploymentTargetTypeDescriptor[] providers = TMWCoreUI.getDefault().getDeploymentTypesRegistry() + .getProviders(); + monitor.beginTask("Discovering deployment targets", providers.length * 10); + for (DeploymentTargetTypeDescriptor descriptor : providers) { + descriptor.discoverTargets(new SubProgressMonitor(monitor, 10)); + } + monitor.done(); + } + + public boolean areTargetsReady() { + final DeploymentTargetTypeDescriptor[] providers = TMWCoreUI.getDefault().getDeploymentTypesRegistry() + .getProviders(); + for (DeploymentTargetTypeDescriptor descriptor : providers) { + if (!descriptor.targetsDiscovered()) { + return false; + } + } + return true; + } + + public void setLogging(boolean logging) { + this.logging = logging; + } + + public boolean isLogging() { + return logging; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetPresentationsManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetPresentationsManager.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,66 @@ +/** + * 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.tmw.internal.deployment; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; +import org.symbian.tools.tmw.ui.deployment.ITargetDetailsPane; + +public class DeploymentTargetPresentationsManager { + private Map presentations; + + public ITargetDetailsPane createDetailsPane(IDeploymentTargetType targetType) { + readRegistry(); + final IConfigurationElement element = presentations.get(targetType); + if (element != null && element.getAttribute("detailsPane") != null) { + try { + return (ITargetDetailsPane) element.createExecutableExtension("detailsPane"); + } catch (CoreException e) { + TMWCoreUI.log(e); + } + } + return new DefaultDeploymentTypePresentation(); + } + + private synchronized void readRegistry() { + if (presentations == null) { + presentations = new HashMap(); + final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCoreUI.PLUGIN_ID, "targetPresentation"); + for (IConfigurationElement element : elements) { + final String runtimeId = element.getAttribute("targetTypeId"); + final IDeploymentTargetType targetType = TMWCoreUI.getDefault().getDeploymentTypesRegistry() + .getType(runtimeId); + if (targetType == null) { + TMWCoreUI.log("Runtime %s was not found. It is referenced from plugin %s", runtimeId, element + .getContributor().getName()); + continue; + } else { + presentations.put(targetType, element); + } + } + } + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypeDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypeDescriptor.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,190 @@ +/** + * 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.tmw.internal.deployment; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.jface.resource.ImageDescriptor; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; + +public final class DeploymentTargetTypeDescriptor implements IDeploymentTargetType { + public class NullProvider implements IDeploymentTargetType { + public IDeploymentTarget[] getTargets(IMTWProject project) { + return null; + } + + public void discoverTargets(IProgressMonitor monitor) throws CoreException { + // Do nothing + } + + public IDeploymentTarget findTarget(IMTWProject project, String id) { + return null; + } + + public boolean targetsDiscovered() { + return true; + } + + public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { + return null; // No scheduling + } + } + + private static final DeploymentTargetWrapper[] NO_TARGETS = new DeploymentTargetWrapper[0]; + private final IConfigurationElement element; + private IDeploymentTargetType type; + private final Map wrappers = new WeakHashMap(); + private ImageDescriptor imageDescriptor = null; + + public DeploymentTargetTypeDescriptor(IConfigurationElement element) { + this.element = element; + } + + public boolean supports(IMTWProject project) { + // We will support more declarative filtering later + return true; + } + + public DeploymentTargetWrapper[] getTargets(IMTWProject project) { + final DeploymentTargetWrapper[] targets = wrap(getProvider().getTargets(project)); + return targets != null ? targets : NO_TARGETS; + } + + private DeploymentTargetWrapper[] wrap(IDeploymentTarget[] targets) { + if (targets == null) { + return new DeploymentTargetWrapper[0]; + } else { + final DeploymentTargetWrapper[] w = new DeploymentTargetWrapper[targets.length]; + for (int i = 0; i < targets.length; i++) { + w[i] = wrap(targets[i]); + } + return w; + } + } + + private DeploymentTargetWrapper wrap(final IDeploymentTarget target) { + DeploymentTargetWrapper wrapper = wrappers.get(target); + if (wrapper == null) { + wrapper = new DeploymentTargetWrapper(target, this); + wrappers.put(target, wrapper); + } + return wrapper; + } + + public void discoverTargets(IProgressMonitor monitor) throws CoreException { + getProvider().discoverTargets(monitor); + } + + public IDeploymentTarget findTarget(IMTWProject project, String id) { + return wrap(getProvider().findTarget(project, id)); + } + + private synchronized IDeploymentTargetType getProvider() { + if (type == null) { + try { + type = (IDeploymentTargetType) element.createExecutableExtension("class"); + } catch (CoreException e) { + TMWCoreUI.log("Cannot instantiate provider " + getId(), e); + type = new NullProvider(); + } + } + return type; + } + + public String getId() { + return element.getAttribute("id"); + } + + public boolean targetsDiscovered() { + return getProvider().targetsDiscovered(); + } + + public int getPriority() { + final String attribute = element.getAttribute("priority"); + if (attribute != null && attribute.trim().length() > 0) { + try { + return Integer.parseInt(attribute); + } catch (NumberFormatException e) { + TMWCoreUI.log("%s is not a valid priority value for %s provider", attribute, getId()); + } + } + return 0; + } + + public ImageDescriptor getImageDescriptor() { + if (imageDescriptor == null) { + final String image = element.getAttribute("icon"); + if (image == null) { + imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); + } else { + imageDescriptor = TMWCoreUI.imageDescriptorFromPlugin(element.getNamespaceIdentifier(), image); + } + } + return imageDescriptor; + } + + public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { + return type.getSchedulingRule(target); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (obj instanceof IDeploymentTargetType) { + return obj.equals(type); + } + if (getClass() != obj.getClass()) { + return false; + } + DeploymentTargetTypeDescriptor other = (DeploymentTargetTypeDescriptor) obj; + if (getId() == null) { + if (other.getId() != null) { + return false; + } + } else if (!getId().equals(other.getId())) { + return false; + } + return true; + } + + public boolean isLongRunning() { + return Boolean.valueOf(element.getAttribute("long-running")); + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypesRegistry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypesRegistry.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,55 @@ +/** + * 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.tmw.internal.deployment; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; + +public class DeploymentTargetTypesRegistry { + private DeploymentTargetTypeDescriptor[] descriptors; + + public DeploymentTargetTypesRegistry() { + readExtensions(); + } + + private void readExtensions() { + final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCoreUI.PLUGIN_ID, "deploymentTargetType"); + descriptors = new DeploymentTargetTypeDescriptor[elements.length]; + for (int i = 0; i < elements.length; i++) { + descriptors[i] = new DeploymentTargetTypeDescriptor(elements[i]); + } + } + + public DeploymentTargetTypeDescriptor[] getProviders() { + return descriptors; + } + + public IDeploymentTargetType getType(String id) { + DeploymentTargetTypeDescriptor[] providers = getProviders(); + for (DeploymentTargetTypeDescriptor descriptor : providers) { + if (descriptor.getId().equals(id)) { + return descriptor; + } + } + return null; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWizardPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWizardPage.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,248 @@ +/** + * 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.tmw.internal.deployment; + +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.util.Policy; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.jface.wizard.IWizardContainer; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.part.PageBook; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.ProjectMemo; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; +import org.symbian.tools.tmw.ui.deployment.ITargetDetailsPane; + +public class DeploymentTargetWizardPage extends WizardPage implements ITargetDetailsPane.Context { + private final DeployWizardContext context; + private PageBook descriptions; + private Control emptyness; + private final Set inited = new HashSet(); + private TableViewer list; + private final Map panes = new HashMap(); + private final IDeploymentTarget prev; + + public DeploymentTargetWizardPage(DeployWizardContext context, ProjectMemo memo) { + super("TargetPage", "Select Deployment Target", null); + this.context = context; + prev = memo.getPreviousDeploymentTarget(); + setDescription(MessageFormat.format("Select emulator or device to deploy the application ''{0}''", context + .getProject().getProject().getName())); + } + + public void createControl(Composite parent) { + Composite root = new Composite(parent, SWT.NONE); + + root.setLayout(new FormLayout()); + + list = new TableViewer(root, SWT.BORDER); + list.setContentProvider(new ArrayContentProvider()); + list.setLabelProvider(new WorkbenchLabelProvider()); + list.setSorter(new ViewerSorter() { + @Override + public int category(Object element) { + return ((DeploymentTargetWrapper) element).getCategory(); + } + }); + list.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = ((IStructuredSelection) event.getSelection()); + DeploymentTargetWrapper target = (DeploymentTargetWrapper) selection.getFirstElement(); + selectDeploymentTarget(target); + } + }); + list.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + if (getWizard().performFinish()) { + IWizardContainer container = getWizard().getContainer(); + if (container instanceof WizardDialog) { + ((WizardDialog) container).close(); + } + } + } + }); + final Button search = new Button(root, SWT.NONE); + search.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + doBluetoothSearch(search); + } + }); + search.setText("Discover"); + search.setImage(TMWCoreUI.getImages().getDiscoverButtonIcon()); + + descriptions = new PageBook(root, SWT.BORDER); + emptyness = new Composite(descriptions, SWT.NONE); + + FormData data = new FormData(); + data.left = new FormAttachment(0, 5); + data.right = new FormAttachment(100, -5); + data.bottom = new FormAttachment(100, -5); + data.height = 80; + descriptions.setLayoutData(data); + + data = new FormData(); + data.top = new FormAttachment(0, 5); + data.right = new FormAttachment(100, -5); + search.setLayoutData(data); + + data = new FormData(); + data.left = new FormAttachment(0, 5); + data.top = new FormAttachment(0, 5); + data.bottom = new FormAttachment(descriptions, -10); + data.right = new FormAttachment(search, -10); + + list.getControl().setLayoutData(data); + list.setInput(context.getDeploymentTargets()); + setPageComplete(false); + + if (prev != null) { + list.setSelection(new StructuredSelection(prev)); + } + setControl(root); + } + + protected void doBluetoothSearch(final Button search) { + try { + final ISelection sel = list.getSelection(); + getContainer().run(true, true, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + monitor.beginTask("Searching for Bluetooth devices", IProgressMonitor.UNKNOWN); + try { + context.doSearch(new SubProgressMonitor(monitor, 100)); + } catch (CoreException e) { + Policy.getStatusHandler().show(e.getStatus(), "Application Deployment"); + } + monitor.done(); + search.getDisplay().asyncExec(new Runnable() { + public void run() { + list.setInput(context.getDeploymentTargets()); + if (!sel.isEmpty()) { + list.setSelection(sel); + selectDeploymentTarget((DeploymentTargetWrapper) ((IStructuredSelection) sel) + .getFirstElement()); + } else { + DeploymentTargetWrapper[] deploymentTargets = context.getDeploymentTargets(); + if (deploymentTargets.length == 0) { + selectDeploymentTarget(null); + } else { + list.setSelection(new StructuredSelection(deploymentTargets[0])); + selectDeploymentTarget(deploymentTargets[0]); + } + } + } + }); + } + }); + } catch (InvocationTargetException e) { + TMWCoreUI.log(e); + } catch (InterruptedException e) { + TMWCoreUI.log(e); + } + } + + private IPackager getPackager() { + return TMWCore.getDefault().getRuntimesManager().getPackager(context.getProject()); + } + + protected void selectDeploymentTarget(DeploymentTargetWrapper target) { + if (target != null) { + if (!inited.contains(target)) { + target.init(context.getProject(), getPackager(), + TMWCoreUI.getMemo(context.getProject()).getMemo(target.getType().getId(), target)); + inited.add(target); + } + context.setTarget(target); + + IDeploymentTargetType type = target.getType(); + ITargetDetailsPane pane = panes.get(type); + if (pane == null) { + pane = TMWCoreUI.getDefault().getPresentations().createDetailsPane(type); + pane.createControl(descriptions); + pane.init(this); + panes.put(type, pane); + } + pane.setTarget(target.getActualTarget()); + descriptions.showPage(pane.getControl()); + } else { + descriptions.showPage(emptyness); + context.setTarget(null); + setPageComplete(false); + setMessage(null); + } + revalidate(); + } + + protected void toggleLogging(boolean logging) { + context.setLogging(logging); + } + + public void revalidate() { + String error = null; + String warning = !context.areTargetsReady() ? "Press \"Discover\" to find more deployment targets" : null; + if (context.getTarget() == null) { + error = "Select device or emulator to deploy the application"; + } else { + final IStatus validate = panes.get(context.getTarget().getType()).validate(); + if (validate.getSeverity() == IStatus.ERROR) { + error = validate.getMessage(); + } else if (validate.getSeverity() == IStatus.WARNING) { + warning = validate.getMessage(); + } + } + setErrorMessage(error); + setMessage(warning, IStatus.WARNING); + setPageComplete(error == null); + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWrapper.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,168 @@ +/** + * 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.tmw.internal.deployment; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.model.IWorkbenchAdapter2; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; + +public class DeploymentTargetWrapper implements IDeploymentTarget { + public class WorkbenchAdapter2Wrapper implements IWorkbenchAdapter2 { + private final IWorkbenchAdapter2 adapter; + + public WorkbenchAdapter2Wrapper(IWorkbenchAdapter2 adapter) { + this.adapter = adapter; + } + + public RGB getForeground(Object element) { + return adapter.getForeground(((DeploymentTargetWrapper) element).getActualTarget()); + } + + public RGB getBackground(Object element) { + return adapter.getBackground(((DeploymentTargetWrapper) element).getActualTarget()); + } + + public FontData getFont(Object element) { + return adapter.getFont(((DeploymentTargetWrapper) element).getActualTarget()); + } + } + + public class WorkbenchAdapterWrapper implements IWorkbenchAdapter { + private final IWorkbenchAdapter adapter; + + public WorkbenchAdapterWrapper(IWorkbenchAdapter adapter) { + this.adapter = adapter; + } + + public Object[] getChildren(Object o) { + return adapter.getChildren(((DeploymentTargetWrapper) o).getActualTarget()); + } + + public ImageDescriptor getImageDescriptor(Object object) { + return adapter.getImageDescriptor(((DeploymentTargetWrapper) object).getActualTarget()); + } + + public String getLabel(Object o) { + return adapter.getLabel(((DeploymentTargetWrapper) o).getActualTarget()); + } + + public Object getParent(Object o) { + return adapter.getParent(((DeploymentTargetWrapper) o).getActualTarget()); + } + } + + private final DeploymentTargetTypeDescriptor type; + private final IDeploymentTarget target; + + public void save(IMemento memento) { + target.save(memento); + } + + public void init(IMTWProject project, IPackager packager, IMemento memento) { + target.init(project, packager, memento); + } + + public DeploymentTargetWrapper(IDeploymentTarget target, DeploymentTargetTypeDescriptor type) { + this.target = target; + this.type = type; + } + + public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) + throws CoreException { + return target.deploy(project, packager, monitor); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + DeploymentTargetWrapper other = (DeploymentTargetWrapper) obj; + if (target == null) { + if (other.target != null) { + return false; + } + } else if (!target.equals(other.target)) { + return false; + } + return true; + } + + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + Object a = target.getAdapter(adapter); + if (IWorkbenchAdapter.class.isAssignableFrom(adapter)) { + return a == null ? new TargetWorkbenchAdapter(this) : new WorkbenchAdapterWrapper((IWorkbenchAdapter) a); + } else if (IWorkbenchAdapter2.class.isAssignableFrom(adapter)) { + return a == null ? new TargetWorkbenchAdapter(this) : new WorkbenchAdapter2Wrapper((IWorkbenchAdapter2) a); + } else { + return a; + } + } + + public int getCategory() { + return type.getPriority() * 0xFFFF + (type.getId().hashCode() & 0xFFFF); + } + + public String getId() { + return target.getId(); + } + + public String getName() { + return target.getName(); + } + + public String getProviderId() { + return type.getId(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((target == null) ? 0 : target.hashCode()); + return result; + } + + public DeploymentTargetTypeDescriptor getType() { + return type; + } + + public IDeploymentTarget getActualTarget() { + return target; + } + + public String getDescription() { + return target.getDescription(); + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/TargetWorkbenchAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/TargetWorkbenchAdapter.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,72 @@ +/** + * 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.tmw.internal.deployment; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.model.IWorkbenchAdapter2; + +public class TargetWorkbenchAdapter implements IWorkbenchAdapter, IWorkbenchAdapter2 { + /** + * + */ + private final DeploymentTargetWrapper deploymentTargetWrapper; + + /** + * @param deploymentTargetWrapper + */ + TargetWorkbenchAdapter(DeploymentTargetWrapper deploymentTargetWrapper) { + this.deploymentTargetWrapper = deploymentTargetWrapper; + } + + public String getLabel(Object object) { + return this.deploymentTargetWrapper.getName(); + } + + public ImageDescriptor getImageDescriptor(Object object) { + return this.deploymentTargetWrapper.getType().getImageDescriptor(); + } + + public RGB getForeground(Object element) { + // TODO Auto-generated method stub + return null; + } + + public RGB getBackground(Object element) { + // TODO Auto-generated method stub + return null; + } + + public FontData getFont(Object element) { + // TODO Auto-generated method stub + return null; + } + + public Object[] getChildren(Object o) { + // TODO Auto-generated method stub + return null; + } + + public Object getParent(Object o) { + // TODO Auto-generated method stub + return null; + } +} \ No newline at end of file diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/externalapp/FilesystemDeploymentTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/externalapp/FilesystemDeploymentTarget.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,59 @@ +/** + * 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.tmw.internal.deployment.externalapp; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; + +public class FilesystemDeploymentTarget implements IDeploymentTargetType { + + public FilesystemDeploymentTarget() { + // TODO Auto-generated constructor stub + } + + public IDeploymentTarget[] getTargets(IMTWProject project) { + // TODO Auto-generated method stub + return null; + } + + public void discoverTargets(IProgressMonitor monitor) throws CoreException { + // TODO Auto-generated method stub + + } + + public IDeploymentTarget findTarget(IMTWProject project, String id) { + // TODO Auto-generated method stub + return null; + } + + public boolean targetsDiscovered() { + // TODO Auto-generated method stub + return false; + } + + public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { + // TODO Auto-generated method stub + return null; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/AdapterFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/AdapterFactory.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,58 @@ +/** + * 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.tmw.internal.deployment.targets; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.model.WorkbenchAdapter; + +@SuppressWarnings("rawtypes") +public class AdapterFactory implements IAdapterFactory { + private final IWorkbenchAdapter adapter = new WorkbenchAdapter() { + @Override + public ImageDescriptor getImageDescriptor(Object object) { + if (object instanceof ExternalApplicationDeploymentType) { + return ImageDescriptor.createFromImageData(((ExternalApplicationDeploymentType) object).getProgram() + .getImageData()); + } + return super.getImageDescriptor(object); + } + + public String getLabel(Object object) { + if (object instanceof ExternalApplicationDeploymentType) { + return ((ExternalApplicationDeploymentType) object).getName(); + } + return super.getLabel(object); + }; + }; + + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof ExternalApplicationDeploymentType + && IWorkbenchAdapter.class.isAssignableFrom(adapterType)) { + return adapter; + } + return null; + } + + public Class[] getAdapterList() { + return new Class[] { IWorkbenchAdapter.class }; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/ExternalApplicationDeploymentType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/ExternalApplicationDeploymentType.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,118 @@ +/** + * 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.tmw.internal.deployment.targets; + +import java.io.File; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.swt.program.Program; +import org.eclipse.ui.IMemento; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; + +public class ExternalApplicationDeploymentType extends PlatformObject implements IDeploymentTargetType, + IDeploymentTarget { + + private IMTWProject project; + + public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) + throws CoreException { + Program app = getExternalApp(project); + File file = packager.packageApplication(project, monitor); + if (file != null) { + app.execute(file.toString()); + return new Status( + IStatus.OK, + TMWCore.PLUGIN_ID, + "Mobile web application was passed as an argument to external application. Please follow its prompts to complete deployment."); + } else { + return new Status(IStatus.ERROR, TMWCore.PLUGIN_ID, "Application packaging failed"); + } + } + + public void discoverTargets(IProgressMonitor monitor) throws CoreException { + // Do nothing + } + + public IDeploymentTarget findTarget(IMTWProject project, String id) { + if (getExternalApp(project) != null) { + return this; + } else { + return null; + } + } + + public String getDescription() { + return getExternalApp(project).getName(); + } + + private Program getExternalApp(IMTWProject project) { + this.project = project; + IPackager packager = TMWCore.getDefault().getRuntimesManager().getPackager(project); + if (packager != null) { + return Program.findProgram(packager.getFileType(project)); + } else { + return null; + } + } + + public String getId() { + return "mtw.externalapp"; + } + + public String getName() { + return "Use external application"; + } + + public Program getProgram() { + return getExternalApp(project); + } + + public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { + return null; + } + + public IDeploymentTarget[] getTargets(IMTWProject project) { + if (getExternalApp(project) != null) { + return new IDeploymentTarget[] { this }; + } else { + return null; + } + } + + public void init(IMTWProject project, IPackager packager, IMemento memento) { + // Do nothing + } + + public void save(IMemento memento) { + // Do nothing + } + + public boolean targetsDiscovered() { + return true; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/FilesystemDeploymentTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/FilesystemDeploymentTarget.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,142 @@ +/** + * 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.tmw.internal.deployment.targets; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +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.Path; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.ui.IMemento; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; + +public class FilesystemDeploymentTarget extends PlatformObject implements IDeploymentTargetType, IDeploymentTarget { + private String defaultName; + private IPath path; + + public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException { + final File file = packager.packageApplication(project, monitor); + try { + final InputStream inputStream = new BufferedInputStream(new FileInputStream(file)); + final OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(path.toFile())); + try { + final byte[] buffer = new byte[16384]; + int read = -1; + while ((read = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, read); + } + } finally { + inputStream.close(); + outputStream.close(); + } + } catch (IOException e) { + throw new CoreException( + new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, "Failed to copy application file", e)); + } finally { + file.delete(); + } + return Status.OK_STATUS; + } + + public void discoverTargets(IProgressMonitor monitor) throws CoreException { + // Do nothing + } + + public IDeploymentTarget findTarget(IMTWProject project, String id) { + return getId().equals(id) ? this : null; + } + + public String getDefaultName() { + return defaultName; + } + + public String getDescription() { + return "Copies application package to a location in the local filesystem"; + } + + public String getId() { + return "mtw.filesystem"; + } + + public String getName() { + return "Local filesystem"; + } + + public IPath getPath() { + return path; + } + + public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { + return null; + } + + public IDeploymentTarget[] getTargets(IMTWProject project) { + return new IDeploymentTarget[] { this }; + } + + public void init(IMTWProject project, IPackager packager, IMemento memento) { + defaultName = new Path(project.getName()).addFileExtension(packager.getFileType(project)).toOSString(); + path = null; + String string = memento != null ? memento.getString("path") : null; + if (string == null) { + string = TMWCoreUI.getDefault().getPreferenceStore().getString("path"); + if (string != null) { + final IPath p = Path.fromPortableString(string); + if (p.toFile().isDirectory()) { + this.path = p.append(defaultName); + } + } + } else { + path = Path.fromPortableString(string); + if (!path.removeLastSegments(1).toFile().isDirectory()) { + path = null; + } + } + } + + public void save(IMemento memento) { + memento.putString("path", path.toPortableString()); + TMWCoreUI.getDefault().getPreferenceStore().setValue("path", path.removeLastSegments(1).toPortableString()); + } + + public void setPath(IPath path) { + this.path = path; + } + + public boolean targetsDiscovered() { + return true; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/LocalFileSystemPane.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/LocalFileSystemPane.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,140 @@ +/** + * 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.tmw.internal.deployment.targets; + +import java.io.File; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.ITargetDetailsPane; + +public class LocalFileSystemPane implements ITargetDetailsPane { + private Composite root; + private Text location; + private FilesystemDeploymentTarget target; + private Context page; + + public void init(Context page) { + this.page = page; + } + + public void setTarget(IDeploymentTarget target) { + this.target = (FilesystemDeploymentTarget) target; + IPath path = this.target.getPath(); + String string; + if (path == null) { + string = ""; + } else { + string = path.toOSString(); + } + location.setText(string); + page.revalidate(); + } + + public void createControl(Composite parent) { + root = new Composite(parent, SWT.NONE); + root.setLayout(new GridLayout(2, false)); + Label label = new Label(root, SWT.NONE); + label.setText("File name:"); + GridDataFactory.generate(label, 2, 1); + location = new Text(root, SWT.BORDER); + location.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + location.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + page.revalidate(); + } + }); + final Button button = new Button(root, SWT.NONE); + button.setText("Browse..."); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + browse(); + } + }); + } + + protected void browse() { + final FileDialog dialog = new FileDialog(location.getShell(), SWT.SAVE); + dialog.setText("Select Application Package Location"); + dialog.setFileName(target.getDefaultName()); + final IPath path = target.getPath(); + if (path != null) { + dialog.setFilterPath(path.removeLastSegments(1).toOSString()); + } + String newPath = dialog.open(); + if (newPath != null) { + location.setText(newPath); + page.revalidate(); + } + } + + public IStatus validate() { + target.setPath(null); + String path = location.getText(); + if (path.trim().length() == 0) { + return new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, "File name must be specified"); + } else { + final File file = new File(path); + if (!file.getParentFile().isDirectory()) { + return new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, String.format("%s is not a valid folder", + file.getParent())); + } else { + IStatus status = ResourcesPlugin.getWorkspace().validateName(file.getName(), IResource.FILE); + if (status.getSeverity() == IStatus.ERROR) { + return status; + } else { + Path p = new Path(path.trim()); + target.setPath(p); + if (p.toFile().exists()) { + return new Status(IStatus.WARNING, TMWCoreUI.PLUGIN_ID, + "Target file already exists. It will be overwritten."); + } else { + return status; + } + } + } + } + } + + public Control getControl() { + return root; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/MTWGlobalScopeContainerUI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/MTWGlobalScopeContainerUI.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,34 @@ +/** + * 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.tmw.internal.libraries; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.internal.ui.IJsGlobalScopeContainerInitializerExtension; + +@SuppressWarnings("restriction") +public class MTWGlobalScopeContainerUI implements IJsGlobalScopeContainerInitializerExtension { + + public ImageDescriptor getImage(IPath containerPath, String element, IJavaScriptProject project) { + System.out.println(project); + return null; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/TMWContainerPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/TMWContainerPage.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,73 @@ +/** + * 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.tmw.internal.libraries; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.wst.jsdt.core.IIncludePathEntry; +import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.core.JavaScriptCore; +import org.eclipse.wst.jsdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.wst.jsdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.wst.jsdt.ui.wizards.IJsGlobalScopeContainerPage; + +@SuppressWarnings("restriction") +public class TMWContainerPage extends WizardPage implements IJsGlobalScopeContainerPage { + private static final String CONTAINER_ID = "org.symbian.tools.mtw.core.mobileWebLibrary"; //$NON-NLS-1$ + + public TMWContainerPage() { + super("TMWLibraryWizzardPage"); //$NON-NLS-1$ + setTitle("Mobile Web Runtime Library"); + } + + public boolean finish() { + return true; + } + + public IIncludePathEntry getSelection() { + return null; + } + + public void setSelection(IIncludePathEntry containerEntry) { + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + DialogField field = new DialogField(); + + field.setLabelText("Library added to a project"); + LayoutUtil.doDefaultLayout(composite, new DialogField[] { field }, false, SWT.DEFAULT, SWT.DEFAULT); + Dialog.applyDialogFont(composite); + setControl(composite); + setDescription("Mobile application support"); + } + + public void initialize(IJavaScriptProject project, IIncludePathEntry[] currentEntries) { + // nothing to initialize + } + + public IIncludePathEntry[] getNewContainers() { + IIncludePathEntry library = JavaScriptCore.newContainerEntry(new Path(CONTAINER_ID)); + return new IIncludePathEntry[] { library }; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/ConsoleFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/ConsoleFactory.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2009 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.tmw.ui; + +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleFactory; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +public class ConsoleFactory implements IConsoleFactory { + + private static MessageConsole console; + + public void openConsole() { + getConsole(); + console.activate(); + } + + public static MessageConsoleStream createStream() { + getConsole(); + return console.newMessageStream(); + } + + public static void activateConsole() { + getConsole(); + console.activate(); + } + + private synchronized static MessageConsole getConsole() { + if (console == null) { + console = new MessageConsole("Mobile Web Console", null, true); + IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); + consoleManager.addConsoles(new IConsole[]{console}); + } + return console; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/Images.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/Images.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,55 @@ +/** + * 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.tmw.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; + +public final class Images { + private final String DISCOVER_ICON = "icons/full/obj16/discover.gif"; + private final String EXCLUDED_ICON = "icons/full/obj16/excluded.gif"; + private final String BLUETOOTH_ICON = "icons/full/obj16/bluetooth.gif"; + + private final ImageRegistry registry; + + Images(final ImageRegistry registry) { + this.registry = registry; + add(registry, DISCOVER_ICON); + add(registry, EXCLUDED_ICON); + add(registry, BLUETOOTH_ICON); + } + + private void add(final ImageRegistry registry, String icon) { + ImageDescriptor descriptor = TMWCoreUI.imageDescriptorFromPlugin(TMWCoreUI.PLUGIN_ID, icon); + registry.put(icon, descriptor); + } + + public Image getDiscoverButtonIcon() { + return registry.get(DISCOVER_ICON); + } + + public ImageDescriptor getExcludedIconDescriptor() { + return registry.getDescriptor(EXCLUDED_ICON); + } + + public ImageDescriptor getBluetoothImageDescriptor() { + return registry.getDescriptor(BLUETOOTH_ICON); + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/ProjectMemo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/ProjectMemo.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,140 @@ +/** + * 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.tmw.ui; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.XMLMemento; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; + +public class ProjectMemo { + private static final String TARGET_TYPE = "typeId"; + private static final String TARGET = "targetId"; + private static final String TARGET_CONFIGURATION = "target"; + private static final String MEMO_TYPE = "deployment"; + + private final IMTWProject project; + private XMLMemento memento; + + public ProjectMemo(IMTWProject project) { + this.project = project; + } + + public synchronized void setDeploymentTarget(String providerId, IDeploymentTarget target) { + try { + checkMemento(); + memento.putString(TARGET_TYPE, providerId); + memento.putString(TARGET, target.getId()); + IMemento child = null; + IMemento[] children = memento.getChildren(TARGET_CONFIGURATION); + for (IMemento memento : children) { + if (providerId.equals(memento.getString(TARGET_TYPE)) + && target.getId().equals(memento.getString(TARGET))) { + child = memento; + } + } + if (child == null) { + child = memento.createChild(TARGET_CONFIGURATION); + child.putString(TARGET_TYPE, providerId); + child.putString(TARGET, target.getId()); + } + target.save(child); + saveMemento(); + } catch (CoreException e) { + TMWCoreUI.log(e); + } catch (IOException e) { + TMWCoreUI.log(e); + } + } + + private void saveMemento() throws IOException, CoreException { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + final Writer writer = new OutputStreamWriter(os); + memento.save(writer); + writer.close(); + final InputStream stream = new ByteArrayInputStream(os.toByteArray()); + IFile file = getMemoFile(); + if (file.exists()) { + file.setContents(stream, IFile.KEEP_HISTORY, null); + } else { + file.create(stream, false, null); + } + } + + private IFile getMemoFile() { + return project.getProject().getFile(new Path(".settings").append(TMWCoreUI.PLUGIN_ID).addFileExtension("xml")); + } + + private void checkMemento() throws CoreException, IOException { + IFile memoFile = getMemoFile(); + if (memoFile.exists()) { + memento = XMLMemento.createReadRoot(new InputStreamReader(memoFile.getContents(), memoFile.getCharset())); + } else { + memento = XMLMemento.createWriteRoot(MEMO_TYPE); + } + } + + public IDeploymentTarget getPreviousDeploymentTarget() { + try { + checkMemento(); + String type = memento.getString(TARGET_TYPE); + if (type != null) { + final IDeploymentTargetType provider = TMWCoreUI.getDefault().getDeploymentTypesRegistry() + .getType(type); + if (provider != null) { + IDeploymentTarget target = provider.findTarget(project, memento.getString(TARGET)); + if (target != null) { + return target; + } + } + } + } catch (CoreException e) { + TMWCoreUI.log(e); + } catch (IOException e) { + TMWCoreUI.log(e); + } + return null; + } + + public IMemento getMemo(String targetType, IDeploymentTarget target) { + if (memento != null) { + IMemento[] children = memento.getChildren(TARGET_CONFIGURATION); + for (IMemento memento : children) { + if (targetType.equals(memento.getString(TARGET_TYPE)) + && target.getId().equals(memento.getString(TARGET))) { + return memento; + } + } + } + return null; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,108 @@ +package org.symbian.tools.tmw.ui; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.internal.deployment.DeploymentTargetPresentationsManager; +import org.symbian.tools.tmw.internal.deployment.DeploymentTargetTypesRegistry; + +/** + * The activator class controls the plug-in life cycle + */ +public class TMWCoreUI extends AbstractUIPlugin { + private final Map MEMOS = new WeakHashMap(); + private final DeploymentTargetTypesRegistry typesRegistry = new DeploymentTargetTypesRegistry(); + + // The plug-in ID + public static final String PLUGIN_ID = "org.symbian.tools.tmw.ui"; //$NON-NLS-1$ + + // The shared instance + private static TMWCoreUI plugin; + private Images images; + private final DeploymentTargetPresentationsManager presentations = new DeploymentTargetPresentationsManager(); + + /** + * The constructor + */ + public TMWCoreUI() { + } + + @Override + protected void initializeImageRegistry(ImageRegistry reg) { + super.initializeImageRegistry(reg); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + 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) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TMWCoreUI getDefault() { + return plugin; + } + + public static void log(String message, Exception e) { + getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, e)); + } + + public static void log(String message, Object... args) { + log(String.format(message, args), (Exception) null); + } + + public static void log(Exception e) { + log(null, e); + } + + public static ProjectMemo getMemo(IMTWProject project) { + return getDefault().getMemoForProject(project); + } + + private synchronized ProjectMemo getMemoForProject(IMTWProject project) { + ProjectMemo memo = MEMOS.get(project.getProject()); + if (memo == null) { + memo = new ProjectMemo(project); + MEMOS.put(project.getProject(), memo); + } + return memo; + } + + public DeploymentTargetTypesRegistry getDeploymentTypesRegistry() { + return typesRegistry; + } + + public static Images getImages() { + if (getDefault().images == null) { + getDefault().images = new Images(getDefault().getImageRegistry()); + } + return getDefault().images; + } + + public DeploymentTargetPresentationsManager getPresentations() { + return presentations; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/UIUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/UIUtils.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,54 @@ +/** + * 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.tmw.ui; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IProject; +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.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; + +public class UIUtils { + public static IMTWProject 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(); + return TMWCore.getDefault().create(project); + } + return null; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/commands/DeployHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/commands/DeployHandler.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,98 @@ +/** + * 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.tmw.ui.commands; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.HandlerUtil; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.ui.UIUtils; +import org.symbian.tools.tmw.ui.deployment.DeployWizard; + +/** + * Our sample handler extends AbstractHandler, an IHandler base class. + * @see org.eclipse.core.commands.IHandler + * @see org.eclipse.core.commands.AbstractHandler + */ +public class DeployHandler extends AbstractHandler { + /** + * The constructor. + */ + public DeployHandler() { + } + + /** + * the command has been executed, so extract extract the needed information + * from the application context. + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + + final IMTWProject project = UIUtils.getProjectFromCommandContext(event); + if (project != null) { + window.getActivePage().saveAllEditors(true); + if (validate(project, window)) { + new WizardDialog(window.getShell(), new DeployWizard(project)).open(); + } + } + + return null; + } + + private boolean validate(final IMTWProject project, final IWorkbenchWindow window) { + final boolean[] retvalue = { false }; + final ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell()); + try { + dialog.run(true, true, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + retvalue[0] = project.validate(monitor); + } + }); + } catch (InvocationTargetException e) { + TMWCore.log(null, e); + } catch (InterruptedException e) { + TMWCore.log(null, e); + } + if (!retvalue[0]) { + retvalue[0] = MessageDialog.openQuestion(window.getShell(), "Deploying Mobile Web Project", + String.format("Project %s has errors. Are you sure you want to deploy it?", project.getName())); + if (!retvalue[0]) { + try { + window.getActivePage().showView(IPageLayout.ID_PROBLEM_VIEW); + } catch (PartInitException e) { + TMWCore.log(null, e); + } + } + } + return retvalue[0]; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/DeployWizard.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/DeployWizard.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,134 @@ +/** + * 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.tmw.ui.deployment; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.MultiRule; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.statushandlers.StatusManager; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.internal.deployment.DeployWizardContext; +import org.symbian.tools.tmw.internal.deployment.DeploymentTargetWizardPage; +import org.symbian.tools.tmw.internal.deployment.DeploymentTargetWrapper; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.ProjectMemo; + +public final class DeployWizard extends Wizard { + private final DeployWizardContext context; + private final IMTWProject project; + + public DeployWizard(IMTWProject project) { + this.project = project; + setNeedsProgressMonitor(true); + setWindowTitle("Deploy Mobile Application"); + context = new DeployWizardContext(project); + } + + @Override + public void addPages() { + addPage(new DeploymentTargetWizardPage(context, TMWCoreUI.getMemo(project))); + } + + @Override + public boolean performFinish() { + final DeploymentTargetWrapper target = context.getTarget(); + if (target.getType().isLongRunning()) { + DeployJob job = new DeployJob(context.getProject(), target); + job.schedule(); + return true; + } else { + final IStatus[] retval = new IStatus[1]; + try { + getContainer().run(false, true, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + retval[0] = doDeploy(target, context.getProject(), monitor); + } + }); + } catch (InvocationTargetException e) { + TMWCoreUI.log(e); + } catch (InterruptedException e) { + TMWCoreUI.log(e); + } + switch (retval[0].getSeverity()) { + case IStatus.ERROR: + StatusManager.getManager().handle(retval[0], StatusManager.SHOW | StatusManager.BLOCK); + return false; + case IStatus.WARNING: + StatusManager.getManager().handle(retval[0], StatusManager.SHOW | StatusManager.BLOCK); + default: + return true; + } + } + } + + @Override + public boolean needsPreviousAndNextButtons() { + return false; + } + + private IStatus doDeploy(DeploymentTargetWrapper target, IMTWProject project, IProgressMonitor monitor) { + IStatus status; + try { + IPackager packager = TMWCore.getDefault().getRuntimesManager().getPackager(project); + status = target.deploy(project, packager, monitor); + } catch (CoreException e) { + status = e.getStatus(); + } + ProjectMemo memo = TMWCoreUI.getMemo(project); + memo.setDeploymentTarget(target.getProviderId(), target); + return status; + } + + private final class DeployJob extends Job { + private final DeploymentTargetWrapper target; + private final IMTWProject project; + + private DeployJob(IMTWProject project, DeploymentTargetWrapper deploymentTarget) { + super(String.format("Deploying %s to %s", project.getName(), deploymentTarget.getName())); + ISchedulingRule rule = deploymentTarget.getType().getSchedulingRule(deploymentTarget.getActualTarget()); + if (rule != null) { + rule = MultiRule.combine(rule, project.getProject()); + } else { + rule = project.getProject(); + } + setRule(rule); + setUser(true); + this.project = project; + this.target = deploymentTarget; + } + + public IStatus run(IProgressMonitor monitor) { + final IStatus status = doDeploy(target, project, monitor); + if (status.getSeverity() != IStatus.ERROR && status.getSeverity() != IStatus.WARNING) { + StatusManager.getManager().handle(status, StatusManager.SHOW); + } + return status; + } + + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/IDeploymentTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/IDeploymentTarget.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,87 @@ +/** + * 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.tmw.ui.deployment; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.ui.IMemento; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackager; + +/** + *

This is particular deployment target instance. It can be a Bluetooth phone + * connection, installed device emulator, FTP server, etc.

+ * + *

This class methods can be called from non-SWT thread.

+ * + *

Following adapters can be provided by either overriding getAdapter method + * or by contributing to org.eclipse.core.runtime.adapters extension point:

+ *
  • {@link org.eclipse.ui.IPersistable} - to persist advanced per- + * project target configuration
  • + * {@link org.eclipse.ui.model.IWorkbenchAdapter} or + * {@link org.eclipse.ui.model.IWorkbenchAdapter2} to customize target + * presentation in IDE user interface.
+ * + *

Overwriting equals and hashCode might be desirable + * if new objects are created each time user does discovery process.

+ * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IDeploymentTarget extends IAdaptable { + /** + * Returns unique ID. There is no restriction on ID string format. Cannot + * be null + */ + String getId(); + + /** + *

Returns user-readable name. Can be null if + * {@link org.eclipse.ui.model.IWorkbenchAdapter} is provided.

+ *

Name is not used for purposes other then presentation and may change + * between invocations

+ */ + String getName(); + + /** + * Provides more details about target. This information is only displayed + * to the user and is not important for the application. + */ + String getDescription(); + + /** + * Deploy application to this target. + * + * @param project project to deploy to the target + * @param runtime runtime that will be used to run packaged application + * @param monitor progress monitor to report deployment progress + */ + IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException; + + /** + * Save project-specific settings to the memento. Workspace-wide settings + * should be managed separately. + */ + void save(IMemento memento); + + /** + * Initialize target for project deployment. + */ + void init(IMTWProject project, IPackager packager, IMemento memento); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/IDeploymentTargetType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/IDeploymentTargetType.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,65 @@ +/** + * 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.tmw.ui.deployment; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.symbian.tools.tmw.core.projects.IMTWProject; + +/** + * This interface is for deployment targets providers. + * + * @author Eugene + */ +public interface IDeploymentTargetType { + /** + * Returns list of the targets that accept provided project. Project + * cannot be null. + * @return List of the valid deployment targets. Both null and + * empty array are a valid return value when there are no available targets. + */ + IDeploymentTarget[] getTargets(IMTWProject project); + + /** + * Discovers targets. This can be a long-running task and in most cases + * will be triggered by the user. + */ + void discoverTargets(IProgressMonitor monitor) throws CoreException; + + /** + * Find target based on project and target ID. This method returns + * null if target with given ID cannot be found or if + * the target does not accept project any longer. + */ + IDeploymentTarget findTarget(IMTWProject project, String id); + + /** + * Return false if user needs to trigger long-running + * discovery to see all potential deployment targets. + */ + boolean targetsDiscovered(); + + /** + * @param target that will be used by a {@link org.eclipse.core.runtime.jobs.Job} + * @return scheduling rule that will be used to properly schedule jobs to + * avoid resource access conflicts. Can be null + */ + ISchedulingRule getSchedulingRule(IDeploymentTarget target); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/ITargetDetailsPane.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/ITargetDetailsPane.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,43 @@ +/** + * 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.tmw.ui.deployment; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * Objects of this class provide UI for the users to visualize or configure + * their deployment targets. This object will not be reused between wizard + * deployment wizard restarts. + * There will be one instance for the target type. This object will not be + * instantiated for each target. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface ITargetDetailsPane { + interface Context { + void revalidate(); + } + void init(Context page); + void setTarget(IDeploymentTarget target); + void createControl(Composite parent); + Control getControl(); + IStatus validate(); +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothRule.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothRule.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,20 @@ +package org.symbian.tools.tmw.ui.deployment.bluetooth; + +import org.eclipse.core.runtime.jobs.ISchedulingRule; + +public class BluetoothRule implements ISchedulingRule { + public static final ISchedulingRule INSTANCE = new BluetoothRule(); + + private BluetoothRule() { + // No instantiation + } + + public boolean contains(ISchedulingRule rule) { + return isConflicting(rule); + } + + public boolean isConflicting(ISchedulingRule rule) { + return rule instanceof BluetoothRule; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTarget.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,321 @@ +/** + * 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.tmw.ui.deployment.bluetooth; + +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.MessageFormat; +import java.util.Collection; +import java.util.LinkedList; + +import javax.bluetooth.BluetoothConnectionException; +import javax.bluetooth.BluetoothStateException; +import javax.bluetooth.DeviceClass; +import javax.bluetooth.DiscoveryListener; +import javax.bluetooth.LocalDevice; +import javax.bluetooth.RemoteDevice; +import javax.bluetooth.ServiceRecord; +import javax.bluetooth.UUID; +import javax.microedition.io.Connector; +import javax.obex.ClientSession; +import javax.obex.HeaderSet; +import javax.obex.Operation; +import javax.obex.ResponseCodes; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.ui.IMemento; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; + +public class BluetoothTarget extends PlatformObject implements IDeploymentTarget { + private static final UUID OBEX_OBJECT_PUSH = new UUID(0x1105); + private String serviceURL; + private RemoteDevice device; + protected String[] exceptionCodes = new String[] { "OBEX_HTTP_UNSUPPORTED_TYPE", "OBEX_HTTP_FORBIDDEN" }; + private String message = "Deployment was successful. Please follow on-screen instructions to complete application deployment on your device."; + private final String name; + private final BluetoothTargetType provider; + private final Collection statuses = new LinkedList(); + + public BluetoothTarget(String name, RemoteDevice device, BluetoothTargetType provider) { + this.name = name; + this.device = device; + this.provider = provider; + } + + public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException { + message = "Deployment was successful. Please follow on-screen instructions to complete application deployment on your device."; + statuses.clear(); + monitor.beginTask(String.format("Deploying application %s to %s", project.getName(), name), + IProgressMonitor.UNKNOWN); + final File application = packager.packageApplication(project, new SubProgressMonitor(monitor, 100)); + try { + deployWidget(application, packager.getFileType(project), new SubProgressMonitor(monitor, 10)); + } finally { + application.delete(); + } + monitor.done(); + MultiStatus multiStatus = new MultiStatus(TMWCore.PLUGIN_ID, 0, message, null); + for (IStatus status : statuses) { + multiStatus.add(status); + } + return multiStatus; + } + + private void deployWidget(File inputWidget, String fileType, IProgressMonitor progressMonitor) throws CoreException { + if (device == null) { + provider.discoverTargets(new SubProgressMonitor(progressMonitor, 10)); + if (device == null) { + throw new CoreException(new Status(IStatus.ERROR, TMWCore.PLUGIN_ID, String.format( + "Device %s is not available", name))); + } + } + progressMonitor.beginTask("Deploying application", IProgressMonitor.UNKNOWN); + InputStream in = null; + OutputStream os = null; + Operation putOperation = null; + ClientSession clientSession = null; + try { + if (!provider.isBloothToothConnected()) { + String msg = "Bluetooth is either disabled or not present in the system."; + emitStatus(IStatus.ERROR, msg, progressMonitor); + return; + } + + String message = MessageFormat.format("Searching for the service for the selected device \"{0}\"", + new Object[] { getName() }); + emitStatus(IStatus.OK, message, progressMonitor); + String servicesFound = getServicesFound(); + if (servicesFound == null || servicesFound.length() < 1) { + message = MessageFormat.format("Cannot find service to the device \"{0}\"", new Object[] { getName() }); + emitStatus(IStatus.ERROR, message, progressMonitor); + return; + } + + message = MessageFormat.format("Service for the device \"{0}\" found", new Object[] { getName() }); + emitStatus(IStatus.OK, message, progressMonitor); + + clientSession = (ClientSession) Connector.open(servicesFound); + HeaderSet hsConnectReply = clientSession.connect(null); + if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) { + emitStatus(IStatus.OK, "Failed to connect to the service", progressMonitor); + } + + emitStatus(IStatus.OK, "Deployment Started", progressMonitor); + + HeaderSet hsOperation = clientSession.createHeaderSet(); + + if (progressMonitor.isCanceled()) { + emitStatus(IStatus.CANCEL, "Deployment was canceled", progressMonitor); + return; + } + + // Send widget to server + in = new FileInputStream(inputWidget); + message = MessageFormat.format("Deploying file from {0}", new Object[] { inputWidget.getAbsolutePath() }); + emitStatus(IStatus.OK, message, progressMonitor); + + hsOperation.setHeader(HeaderSet.NAME, inputWidget.getName()); + hsOperation.setHeader(HeaderSet.TYPE, fileType); + int size = (int) inputWidget.length(); + byte file[] = new byte[size]; + hsOperation.setHeader(HeaderSet.LENGTH, new Long(file.length)); + + // Create PUT Operation + putOperation = clientSession.put(hsOperation); + + os = putOperation.openOutputStream(); + + long start = System.currentTimeMillis(); + + byte[] buf = new byte[16 * 1024]; + int len; + while ((len = in.read(buf)) > 0) { + os.write(buf, 0, len); + if (progressMonitor.isCanceled()) { + putOperation.abort(); + emitStatus(IStatus.CANCEL, "Deployment was canceled", progressMonitor); + return; + } + } + + os.flush(); + os.close(); + + long elapsed = System.currentTimeMillis() - start; + emitStatus(IStatus.OK, "elapsed time: " + elapsed / 1000.0 + " seconds", progressMonitor); + + int responseCode = putOperation.getResponseCode(); + if (responseCode == ResponseCodes.OBEX_HTTP_OK) { + message = MessageFormat.format("File deployed to {0}", new Object[] { getName() }); + emitStatus(IStatus.OK, message, progressMonitor); + } else { + message = "Error during deployment, OBEX error: " + responseCode; + emitStatus(IStatus.ERROR, message, progressMonitor); + } + + } catch (BluetoothConnectionException x) { + String message = getExceptionMessage(x.getMessage()); + emitStatus(IStatus.ERROR, message, progressMonitor); + } catch (IOException e) { + String message = getExceptionMessage(e.getMessage()); + emitStatus(IStatus.ERROR, message, progressMonitor); + } finally { + try { + if (in != null) { + in.close(); + } + if (putOperation != null) { + putOperation.close(); + } + if (clientSession != null) { + clientSession.disconnect(null); + clientSession.close(); + } + } catch (EOFException eof) { + // EOFException is now caught + // Ignore the error since deployment has already completed + //Activator.log(IStatus.ERROR, "EOF encountered while cleaning up Bluetooth deployment", eof); + } catch (IOException x) { + TMWCore.log("Error cleaning up BlueTooth deployment", x); + } + } + return; + } + + protected void emitStatus(int severity, String statusDescription, IProgressMonitor monitor) { + statuses.add(new Status(severity, TMWCore.PLUGIN_ID, statusDescription)); + monitor.setTaskName(statusDescription); + if (severity != IStatus.OK) { + message = statusDescription; + } + } + + /** + * Returns the customized methods from the exception error code. If it + * matches it returns the customized message else returns the exception itself + * @param message exception message + * @return the customized message + */ + protected String getExceptionMessage(String message) { + + if (message.contains(exceptionCodes[0])) { + return "Device does not support the widget deployment"; + } else if (message.contains(exceptionCodes[1])) { + return "Deployment rejected by the device"; + } + return message; + } + + public String getId() { + return getName(); + } + + public String getName() { + return name; + } + + private String getServicesFound() { + try { + serviceURL = ""; + UUID serviceUUID = OBEX_OBJECT_PUSH; + + final Object serviceSearchCompletedEvent = new Object(); + + DiscoveryListener listener = new DiscoveryListener() { + + public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { + } + + public void inquiryCompleted(int discType) { + } + + public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { + try { + for (int i = 0; i < servRecord.length; i++) { + if (servRecord[i].getHostDevice().getFriendlyName(false).equals(name)) { + serviceURL = servRecord[i].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, + false); + } + } + } catch (BluetoothStateException e) { + TMWCore.log(e.getMessage(), e); + } catch (IOException e) { + TMWCore.log(e.getMessage(), e); + } + } + + public void serviceSearchCompleted(int transID, int respCode) { + synchronized (serviceSearchCompletedEvent) { + serviceSearchCompletedEvent.notifyAll(); + } + } + + }; + + UUID[] searchUuidSet = new UUID[] { serviceUUID }; + int[] attrIDs = new int[] { 0x0100 }; // Service name + + synchronized (serviceSearchCompletedEvent) { + LocalDevice.getLocalDevice().getDiscoveryAgent() + .searchServices(attrIDs, searchUuidSet, device, listener); + serviceSearchCompletedEvent.wait(); + } + + } catch (IOException e) { + TMWCore.log("Error in Bluetooth service discovery", e); + } catch (InterruptedException e) { + TMWCore.log("Error in Bluetooth service discovery", e); + } + return serviceURL; + } + + public void init(IMTWProject project, IPackager packager, IMemento memento) { + // nothing + } + + public void save(IMemento memento) { + // nothing + } + + public void setAddress(RemoteDevice device) { + this.device = device; + } + + public boolean isDiscovered() { + return device != null; + } + + public String getDescription() { + return device == null ? "This device was remembered from past sessions and may not be available" : String + .format("Remote device with address %s", device.getBluetoothAddress()); + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTargetAdapterFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTargetAdapterFactory.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,41 @@ +/** + * 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.tmw.ui.deployment.bluetooth; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.model.IWorkbenchAdapter2; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class BluetoothTargetAdapterFactory implements IAdapterFactory { + private final BluetoothTargetWorkbenchAdapter workbenchAdapter = new BluetoothTargetWorkbenchAdapter(); + + public Object getAdapter(Object adaptableObject, Class adapterType) { + if ((adapterType.isAssignableFrom(IWorkbenchAdapter.class) || adapterType + .isAssignableFrom(IWorkbenchAdapter2.class)) && adaptableObject instanceof BluetoothTarget) { + return workbenchAdapter; + } + return null; + } + + public Class[] getAdapterList() { + return new Class[] { IWorkbenchAdapter2.class, IWorkbenchAdapter.class }; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTargetType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTargetType.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,207 @@ +/** + * 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.tmw.ui.deployment.bluetooth; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.Collection; +import java.util.Map; +import java.util.TreeMap; + +import javax.bluetooth.BluetoothStateException; +import javax.bluetooth.DeviceClass; +import javax.bluetooth.DiscoveryAgent; +import javax.bluetooth.DiscoveryListener; +import javax.bluetooth.LocalDevice; +import javax.bluetooth.RemoteDevice; +import javax.bluetooth.ServiceRecord; + +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.ISchedulingRule; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.ui.ConsoleFactory; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget; +import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType; + +import com.intel.bluetooth.BlueCoveImpl; + +/** + * Discovers Bluetooth-enabled devices. This code is generic and will not + * perform any checks if the discovered device can run application being + * deployed. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public class BluetoothTargetType implements IDeploymentTargetType { + private final class TargetDiscoveryListener implements DiscoveryListener { + final Object inquiryCompletedEvent; + boolean isCanceled; + final Map prevTargets; + final IProgressMonitor progressMonitor; + + private TargetDiscoveryListener(Map previousTargets, Object inquiryCompletedEvent, + IProgressMonitor progressMonitor) { + this.prevTargets = previousTargets; + this.inquiryCompletedEvent = inquiryCompletedEvent; + this.progressMonitor = progressMonitor; + } + + private void checkCanceled() { + if (!isCanceled && progressMonitor != null) { + if (progressMonitor.isCanceled()) { + try { + LocalDevice.getLocalDevice().getDiscoveryAgent().cancelInquiry(listener); + } catch (BluetoothStateException e) { + TMWCoreUI.log(e); + } + } + } + } + + public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { + try { + final String name = btDevice.getFriendlyName(false); + if (name != null && name.length() > 0) { + final BluetoothTarget target = prevTargets.get(name); + if (target != null) { + target.setAddress(btDevice); + targets.put(name, target); + } else { + targets.put(name, new BluetoothTarget(name, btDevice, BluetoothTargetType.this)); + } + checkCanceled(); + } + } catch (BluetoothStateException e) { + TMWCoreUI.log(e.getMessage(), e); + } catch (IOException e) { + TMWCoreUI.log(e.getMessage(), e); + } + } + + public void inquiryCompleted(int discType) { + synchronized (inquiryCompletedEvent) { + inquiryCompletedEvent.notifyAll(); + } + } + + public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { + } + + public void serviceSearchCompleted(int transID, int respCode) { + } + } + + private static PrintStream savedSysOut; + private boolean discovered = false; + private TargetDiscoveryListener listener; + private Map targets = new TreeMap(); + + public BluetoothTargetType() { + // set parameters for BlueCove + String param = Integer.toString(65 * 1024); + System.setProperty("bluecove.obex.mtu", param); + BlueCoveImpl.setConfigProperty("bluecove.obex.mtu", param); + } + + public void discoverTargets(IProgressMonitor monitor) throws CoreException { + if (!isBloothToothConnected()) { + throw new CoreException(new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, "Bluetooth is not available")); + } + monitor.beginTask("Discovering Bluetooth devices", IProgressMonitor.UNKNOWN); + final Object inquiryCompletedEvent = new Object(); + final Map previousTargets = targets; + targets = new TreeMap(); + + listener = new TargetDiscoveryListener(previousTargets, inquiryCompletedEvent, monitor); + + synchronized (inquiryCompletedEvent) { + boolean started; + try { + started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, listener); + if (started) { + inquiryCompletedEvent.wait(); + discovered = true; + } + } catch (BluetoothStateException e) { + TMWCoreUI.log(e.getMessage(), e); + } catch (InterruptedException e) { + TMWCoreUI.log(e.getMessage(), e); + } + } + monitor.done(); + } + + /** Toggle BlueCove logging + */ + public void enableBlueCoveDiagnostics(boolean enable) { + System.setProperty("bluecove.debug", Boolean.valueOf(enable).toString()); + BlueCoveImpl.instance().enableNativeDebug(enable); + if (enable) { + System.setOut(new PrintStream(ConsoleFactory.createStream())); + } else { + System.setOut(savedSysOut); + } + } + + public IDeploymentTarget findTarget(IMTWProject project, String id) { + if (!isBloothToothConnected()) { + return null; + } + if (discovered) { + return targets.get(id); + } else { + BluetoothTarget target = targets.get(id); + if (target == null) { + target = new BluetoothTarget(id, null, this); + targets.put(id, target); + } + return target; + } + } + + public IDeploymentTarget[] getTargets(IMTWProject project) { + if (targets != null) { + final Collection values = targets.values(); + return values.toArray(new IDeploymentTarget[values.size()]); + } else { + return null; + } + } + + /** + * Check whether the bluetooth is on or not. + * + * @return whether the device is on. + */ + public boolean isBloothToothConnected() { + return LocalDevice.isPowerOn(); + } + + public boolean targetsDiscovered() { + return discovered; + } + + public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { + return BluetoothRule.INSTANCE; + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTargetWorkbenchAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTargetWorkbenchAdapter.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,65 @@ +/** + * 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.tmw.ui.deployment.bluetooth; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.model.IWorkbenchAdapter2; +import org.symbian.tools.tmw.ui.TMWCoreUI; + +public class BluetoothTargetWorkbenchAdapter implements IWorkbenchAdapter, IWorkbenchAdapter2 { + public RGB getForeground(Object element) { + final BluetoothTarget target = (BluetoothTarget) element; + if (!target.isDiscovered()) { + return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay() + .getSystemColor(SWT.COLOR_DARK_GRAY).getRGB(); + } + return null; + } + + public RGB getBackground(Object element) { + return null; + } + + public FontData getFont(Object element) { + return null; + } + + public Object[] getChildren(Object o) { + return null; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return TMWCoreUI.getImages().getBluetoothImageDescriptor(); + } + + public String getLabel(Object o) { + final BluetoothTarget target = (BluetoothTarget) o; + return target.getName(); + } + + public Object getParent(Object o) { + return null; + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/navigator/PackagingInformationDecorator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/navigator/PackagingInformationDecorator.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,71 @@ +/** + * 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.tmw.ui.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.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackager; +import org.symbian.tools.tmw.ui.TMWCoreUI; + +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 && resource.isAccessible()) { + IMTWProject project = TMWCore.getDefault().create(resource.getProject()); + if (project != null) { + IPackager packager = TMWCore.getDefault().getRuntimesManager().getPackager(project); + if (packager.getPathInPackage(resource) != null) { + decoration.addOverlay(TMWCoreUI.getImages().getExcludedIconDescriptor(), 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 + + } + +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/navigator/RenameMoveActionProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/navigator/RenameMoveActionProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -0,0 +1,101 @@ +/** + * 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.tmw.ui.navigator; + +import java.util.Collection; +import java.util.HashSet; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.navigator.CommonActionProvider; +import org.eclipse.ui.navigator.ICommonActionExtensionSite; +import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; +import org.eclipse.wst.jsdt.ui.IContextMenuConstants; +import org.eclipse.wst.jsdt.ui.actions.IJavaEditorActionDefinitionIds; +import org.eclipse.wst.jsdt.ui.actions.JdtActionConstants; +import org.eclipse.wst.jsdt.ui.actions.MoveAction; +import org.eclipse.wst.jsdt.ui.actions.RenameAction; +import org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction; + +public class RenameMoveActionProvider extends CommonActionProvider { + private SelectionDispatchAction fMoveAction; + private SelectionDispatchAction fRenameAction; + + private final Collection fActions = new HashSet(); + + public void fillActionBars(IActionBars actionBars) { + if (fActions.size() > 0) { + actionBars.setGlobalActionHandler(JdtActionConstants.RENAME, fRenameAction); + actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), fRenameAction); + + actionBars.setGlobalActionHandler(JdtActionConstants.MOVE, fMoveAction); + actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), fMoveAction); + } + } + + public void fillContextMenu(IMenuManager menu) { + menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, new Separator()); + for (IAction action : fActions) { + menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, action); + } + } + + public void init(ICommonActionExtensionSite site) { + ICommonViewerWorkbenchSite workbenchSite= null; + if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) { + workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite(); + } + + // we only initialize the refactor group when in a view part + // (required for the constructor) + if (workbenchSite != null) { + if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { + IViewPart viewPart= (IViewPart) workbenchSite.getPart(); + IWorkbenchPartSite s = viewPart.getSite(); + + fRenameAction= new RenameAction(s); + initUpdatingAction(fRenameAction, workbenchSite.getSelectionProvider(), workbenchSite.getSelectionProvider().getSelection(), IJavaEditorActionDefinitionIds.RENAME_ELEMENT); + fMoveAction= new MoveAction(s); + initUpdatingAction(fMoveAction, workbenchSite.getSelectionProvider(), workbenchSite.getSelectionProvider().getSelection(), IJavaEditorActionDefinitionIds.RENAME_ELEMENT); + } + } + } + + private void initUpdatingAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, String actionDefinitionId){ + action.setActionDefinitionId(actionDefinitionId); + action.update(selection); + if (provider != null) { + provider.addSelectionChangedListener(action); + } + fActions.add(action); + } + + + public void setContext(ActionContext context) { + // Do nothing + } +} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools.previewer/plugin.xml --- a/org.symbian.tools.wrttools.previewer/plugin.xml Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.wrttools.previewer/plugin.xml Mon Aug 09 15:18:34 2010 -0700 @@ -6,7 +6,7 @@ point="org.eclipse.ui.views"> - - + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools.product/wrt-ide.product --- a/org.symbian.tools.wrttools.product/wrt-ide.product Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.wrttools.product/wrt-ide.product Mon Aug 09 15:18:34 2010 -0700 @@ -232,6 +232,7 @@ + @@ -278,8 +279,8 @@ - - + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools/META-INF/MANIFEST.MF --- a/org.symbian.tools.wrttools/META-INF/MANIFEST.MF Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.wrttools/META-INF/MANIFEST.MF Mon Aug 09 15:18:34 2010 -0700 @@ -27,8 +27,10 @@ org.eclipse.wst.common.snippets, org.eclipse.jface.text;bundle-version="3.6.0", org.eclipse.wst.jsdt.web.core;bundle-version="1.0.300", - org.symbian.tools.mtw.core;bundle-version="1.0.0", - org.symbian.tools.mtw.ui;bundle-version="1.0.0" + org.symbian.tools.tmw.core;bundle-version="1.0.0", + org.symbian.tools.tmw.ui;bundle-version="1.0.0", + org.eclipse.wst.common.project.facet.core;bundle-version="1.4.100", + org.eclipse.wst.common.project.facet.ui;bundle-version="1.4.100" Bundle-RequiredExecutionEnvironment: J2SE-1.5, JavaSE-1.6 Bundle-ActivationPolicy: lazy diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools/plugin.xml --- a/org.symbian.tools.wrttools/plugin.xml Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.wrttools/plugin.xml Mon Aug 09 15:18:34 2010 -0700 @@ -28,7 +28,6 @@ - @@ -420,45 +419,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + point="org.symbian.tools.tmw.core.projectProvider"> @@ -813,21 +773,27 @@ + point="org.symbian.tools.tmw.core.runtimes"> + + + point="org.symbian.tools.tmw.core.packagers"> + target-runtime="org.symbian.tools.wrttools.wrt" + target-runtime-version="1.1"> + point="org.symbian.tools.tmw.ui.deploymentTargetType"> + + + + + + + + + + + + + + + + + + + + diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTProject.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTProject.java Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTProject.java Mon Aug 09 15:18:34 2010 -0700 @@ -35,14 +35,15 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; -import org.symbian.tools.mtw.core.MTWCore; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; public class WRTProject implements IMTWProject { private static final String PROP_PREFERED_SCREEN = "preferred.screen.size"; private static final IPath PROPERTIES_FILE = new Path(".settings").append(Activator.PLUGIN_ID + ".properties"); - public static final String WRT11_RUNTIME = "org.symbian.wrt11"; + public static final String WRT11_RUNTIME = "org.symbian.tools.wrttools.wrt"; + public static final String WRT11_VERSION = "1.1"; private final IProject project; public WRTProject(IProject project) { @@ -102,7 +103,7 @@ } public IMobileWebRuntime getTargetRuntime() { - return MTWCore.getDefault().getRuntimesManager().getRuntime(WRT11_RUNTIME); + return TMWCore.getDefault().getRuntimesManager().getRuntime(WRT11_RUNTIME, WRT11_VERSION); } private void saveProperties(Properties props) { diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/Emulator.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/Emulator.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -/** - * 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.core.deploy.emulator; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.ui.IMemento; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackager; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.wrttools.Activator; - -public class Emulator extends PlatformObject implements IDeploymentTarget { - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((path == null) ? 0 : path.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Emulator other = (Emulator) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { - return false; - } - if (path == null) { - if (other.path != null) { - return false; - } - } else if (!path.equals(other.path)) { - return false; - } - return true; - } - - private final String id; - private final String path; - - public Emulator(String id, String path) { - this.id = id; - this.path = path; - } - - public String getId() { - return id; - } - - public String getName() { - return id; - } - - public String getDescription() { - return path; - } - - public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) - throws CoreException { - final File application = packager.packageApplication(project, monitor); - final File outputFile = new File(path); - if (!outputFile.isDirectory()) { - outputFile.mkdir(); - } - - final File out = new File(outputFile + "/" + application.getName()); //$NON-NLS-1$ - deployWidget(application, out); - return new Status( - IStatus.OK, - Activator.PLUGIN_ID, - "Application was successfully deployed to emulator. You will need to complete installation process using your emulator UI."); - } - - public void save(IMemento memento) { - // Do nothing - } - - public void init(IMTWProject project, IPackager packager, IMemento memento) { - // Do nothing - } - - // helper methods - - /** - * Deploys the widget from the source to the destination path of the emulator. - * @param inputFile the actual widget path from where widget needs to be deployed. - * @param outputFile the path of the emulator where the widget will be deoplyed. - */ - private void deployWidget(File inputFile, File outputFile) throws CoreException { - try { - InputStream in = new FileInputStream(inputFile); - OutputStream out = new FileOutputStream(outputFile); - int c; - - while ((c = in.read()) != -1) { - out.write(c); - } - in.close(); - out.close(); - } catch (IOException e) { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Application deployment failed", e)); - } - } -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/EmulatorTargetType.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/EmulatorTargetType.java Thu Jul 29 15:59:01 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,196 +0,0 @@ -/** - * 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.core.deploy.emulator; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; -import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; -import org.symbian.tools.wrttools.core.IWRTConstants; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -public final class EmulatorTargetType implements IDeploymentTargetType { - /** - * Map containing of the SDKS with the corresponding paths. - */ - private Map listofEmulators; - - public EmulatorTargetType() { - discoverTargets(new NullProgressMonitor()); - } - - public IDeploymentTarget[] getTargets(IMTWProject project) { - Collection values = listofEmulators.values(); - return values.toArray(new Emulator[values.size()]); - } - - public void discoverTargets(IProgressMonitor monitor) { - if (listofEmulators == null) { - listofEmulators = new HashMap(); - } - listofEmulators.clear(); - initialize(); - } - - public IDeploymentTarget findTarget(IMTWProject project, String id) { - return listofEmulators.get(id); - } - - public boolean targetsDiscovered() { - return true; - } - - public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { - return null; - } - - // helper methods - - /** - * This will parse the xml and create the nodes to be displayed on the table - * viewer. The information will be used by content & label provider to get - * the contents and display accordingly in the list of the projects in the view. - */ - public Map initialize() { - - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - // Parse the devices.xml and retrieve the list of the emulators from it - // and build the list to be displayed in the view. - - try { - DocumentBuilder builder = factory.newDocumentBuilder(); - File file = new File(IWRTConstants.DEVICES_XML_PATH); - if (!file.exists()) { - IPath otherPath = new Path(System.getProperty("user.home")) - .append(IWRTConstants.DEVICES_VISTA_XML_PATH); - file = otherPath.toFile(); - } - if (file.exists()) { - FileInputStream fin = new FileInputStream(file); - Document document = builder.parse(fin); - NodeList childNodes = document.getChildNodes(); - - for (int i = 0; i < childNodes.getLength(); i++) { - - Node node = childNodes.item(i); - String nodeName = node.getNodeName(); - // If the node name is "devices" it is the root node of the xml. - if (nodeName.equals(IWRTConstants.DEVICES_TAG)) { - // once we have the root node get the child information to - // build the devices list. - createDevicesList(node); - - } - } - } - } catch (ParserConfigurationException e) { - // WidgetUtils.getView().getLogger().severe(e.getMessage()); - } catch (SAXException e) { - // WidgetUtils.getView().getLogger().severe(e.getMessage()); - } catch (IOException e) { - // WidgetUtils.getView().getLogger().severe(e.getMessage()); - } - return listofEmulators; - } - - /** - * Creates the devices nodes in the table. - * @param parentNode - */ - private void createDevicesList(Node parentNode) { - NodeList list = getChildNodes(parentNode); - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - String nodeName = node.getNodeName(); - if (nodeName.equals(IWRTConstants.DEVICE_TAG)) { - createDeviceChildNode(node); - } - } - } - - /** - * Gets the EPOC ROOT node and than finally the list of devices. - * @param parentNode - */ - private void createDeviceChildNode(Node parentNode) { - NodeList list = getChildNodes(parentNode); - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - String nodeName = node.getNodeName(); - if (nodeName.equals(IWRTConstants.EPOC_ROOT_TAG)) { - addProject(node, parentNode); - } - } - } - - /** - * Adds the devices to the list to be displayed. - * @param deviceNode the device node - * @param epocNode the epoc root node. - */ - private void addProject(Node epocNode, Node deviceNode) { - NodeList list = getChildNodes(epocNode); - NamedNodeMap attributes = deviceNode.getAttributes(); - String sdkId = ""; - String sdkName = ""; - for (int i = 0; i < attributes.getLength(); i++) { - Node item = attributes.item(i); - if (item.getNodeName().equals(IWRTConstants.NAME_ATTR)) { - sdkName = item.getNodeValue(); - } - if (item.getNodeName().equals(IWRTConstants.ID_ATTR)) { - sdkId = item.getNodeValue(); - } - } - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if (sdkName.equals(IWRTConstants.EMULATOR_NAME)) { - listofEmulators.put(sdkId, new Emulator(sdkId, node.getNodeValue())); - } - } - } - - /** - * Returns the child list of the particular Node. - * @param parentNode - */ - private static NodeList getChildNodes(Node parentNode) { - return parentNode.getChildNodes(); - } - -} diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackager.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackager.java Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackager.java Mon Aug 09 15:18:34 2010 -0700 @@ -29,9 +29,9 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.runtimes.IPackagerDelegate; -import org.symbian.tools.mtw.core.utilities.ZipApplicationVisitor; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IPackagerDelegate; +import org.symbian.tools.tmw.core.utilities.ZipApplicationVisitor; import org.symbian.tools.wrttools.Activator; import org.symbian.tools.wrttools.util.ProjectUtils; diff -r c0bff5ed874c -r 7a8f9fa8d278 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/project/WRTIDEProjectProvider.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/project/WRTIDEProjectProvider.java Thu Jul 29 15:59:01 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/project/WRTIDEProjectProvider.java Mon Aug 09 15:18:34 2010 -0700 @@ -22,8 +22,8 @@ import java.util.WeakHashMap; import org.eclipse.core.resources.IProject; -import org.symbian.tools.mtw.core.projects.IMTWProject; -import org.symbian.tools.mtw.core.projects.IMTWProjectProvider; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.projects.IMTWProjectProvider; import org.symbian.tools.wrttools.WRTProject; import org.symbian.tools.wrttools.util.ProjectUtils;