# HG changeset patch # User Eugene Ostroukhov # Date 1281742080 25200 # Node ID aea4c83725d8145e8c34e737fd40f03d76c46508 # Parent cdc4995b1677948a185be1d8006dfade217ae291 Project template work-in-progress diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/META-INF/MANIFEST.MF --- a/org.symbian.tools.mtw.core/META-INF/MANIFEST.MF Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/META-INF/MANIFEST.MF Fri Aug 13 16:28:00 2010 -0700 @@ -10,7 +10,8 @@ org.eclipse.core.resources;bundle-version="3.6.0", 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" + org.eclipse.wst.jsdt.core;bundle-version="1.1.0", + org.eclipse.wst.validation;bundle-version="1.2.200" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Export-Package: org.symbian.tools.tmw.core, diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/plugin.xml --- a/org.symbian.tools.mtw.core/plugin.xml Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/plugin.xml Fri Aug 13 16:28:00 2010 -0700 @@ -108,7 +108,7 @@ + class="org.symbian.tools.tmw.core.internal.facets.InstallCoreFacetAction"> diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/TMWCore.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/TMWCore.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/TMWCore.java Fri Aug 13 16:28:00 2010 -0700 @@ -5,9 +5,11 @@ import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.osgi.framework.BundleContext; +import org.symbian.tools.tmw.core.internal.facets.FProjSupportImpl; 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.IFProjSupport; import org.symbian.tools.tmw.core.projects.IMTWProject; import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntimeManager; @@ -22,16 +24,11 @@ // The shared instance private static TMWCore plugin; + private IFProjSupport fprojSupport; 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) @@ -41,6 +38,7 @@ plugin = this; runtimesManager = new RuntimesManagerImpl(); projectsSupport = new ProjectsSupportManager(); + fprojSupport = new FProjSupportImpl(); classpathManager = new RuntimeClasspathManager(); } @@ -53,16 +51,16 @@ super.stop(context); } - public IMobileWebRuntimeManager getRuntimesManager() { - return runtimesManager; + public static IMobileWebRuntimeManager getRuntimesManager() { + return getDefault().runtimesManager; } public RuntimeClasspathManager getClasspathManager() { return classpathManager; } - public IMTWProject create(IProject project) { - return projectsSupport.create(project); + public static IMTWProject create(IProject project) { + return getDefault().projectsSupport.create(project); } /** @@ -81,4 +79,8 @@ public static void log(String message, Object... args) { log(String.format(message, args), (Exception) null); } + + public static IFProjSupport getFProjSupport() { + return getDefault().fprojSupport; + } } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/FProjSupportImpl.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/FProjSupportImpl.java Fri Aug 13 16:28:00 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.core.internal.facets; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.eclipse.wst.common.project.facet.core.VersionFormatException; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; +import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; +import org.symbian.tools.tmw.core.projects.IFProjSupport; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +public final class FProjSupportImpl implements IFProjSupport { + public IRuntime getRuntime(IMobileWebRuntime runtime) { + return RuntimeManager.getRuntime(getRuntimeId(runtime)); + } + + public Set getFixedFacets(IMobileWebRuntime runtime) { + final Set facets = new HashSet(); + for (IProjectFacetVersion facetVersion : getFixedFacetsVersions(runtime)) { + facets.add(facetVersion.getProjectFacet()); + } + return facets; + } + + private IProjectFacetVersion getFacet(String id, String version) { + final IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(id); + try { + return version != null ? projectFacet.getVersion(version) : projectFacet.getLatestVersion(); + } catch (VersionFormatException e) { + throw new RuntimeException(e); + } catch (CoreException e) { + throw new RuntimeException(e); + } + } + + public String getRuntimeId(IMobileWebRuntime runtime) { + return runtime != null ? runtime.getId() + ":" + runtime.getVersion() : null; + } + + public Set getFixedFacetsVersions(IMobileWebRuntime runtime) { + final Set facets = new HashSet(); + facets.add(getFacet("wst.jsdt.web", null)); + facets.add(getFacet("tmw.core", null)); + // facets.add(getFacet("wst.jsdt.web", "1.0")); + return facets; + } + + public IProjectFacet getTMWFacet() { + return getFacet("tmw.core", null).getProjectFacet(); + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/InstallCoreFacetAction.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/InstallCoreFacetAction.java Fri Aug 13 16:28:00 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.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.core.runtime.SubProgressMonitor; +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; +import org.eclipse.wst.validation.ValidationFramework; +import org.symbian.tools.tmw.core.projects.IProjectSetupAction; + +public class InstallCoreFacetAction implements IDelegate { + + public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) + throws CoreException { + monitor.beginTask("Preparing mobile web application project", 300); + 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, new SubProgressMonitor(monitor, 30)); + } + ValidationFramework.getDefault().addValidationBuilder(project); + + IProjectSetupAction action = (IProjectSetupAction) config; + if (action != null) { + action.initialize(project, new SubProgressMonitor(monitor, 270)); + } + monitor.done(); + } +} \ No newline at end of file diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/InstallFacetAction.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/InstallFacetAction.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/facets/InstallFacetAction.java Fri Aug 13 16:28:00 2010 -0700 @@ -21,35 +21,14 @@ 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); - } + // Do nothing } } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java Fri Aug 13 16:28:00 2010 -0700 @@ -58,7 +58,7 @@ final List components = runtime.getRuntimeComponents(); if (!components.isEmpty()) { final IRuntimeComponentVersion version = components.get(0).getRuntimeComponentVersion(); - return TMWCore.getDefault().getRuntimesManager() + return TMWCore.getRuntimesManager() .getRuntime(version.getRuntimeComponentType().getId(), version.getVersionString()); } } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWPropertyTester.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWPropertyTester.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWPropertyTester.java Fri Aug 13 16:28:00 2010 -0700 @@ -32,7 +32,7 @@ private boolean isTMWProject(Object receiver) { if (receiver instanceof IResource) { - return TMWCore.getDefault().create(((IResource) receiver).getProject()) != null; + return TMWCore.create(((IResource) receiver).getProject()) != null; } return false; } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/LazyPackager.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/LazyPackager.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/LazyPackager.java Fri Aug 13 16:28:00 2010 -0700 @@ -67,7 +67,7 @@ public IMobileWebRuntime getTargetRuntime() { String id = element.getAttribute("target-runtime"); if (id != null) { - return TMWCore.getDefault().getRuntimesManager() + return TMWCore.getRuntimesManager() .getRuntime(id, element.getAttribute("target-runtime-version")); } else { return getSourceRuntime(); @@ -75,7 +75,7 @@ } public IMobileWebRuntime getSourceRuntime() { - IMobileWebRuntime runtime = TMWCore.getDefault().getRuntimesManager() + IMobileWebRuntime runtime = TMWCore.getRuntimesManager() .getRuntime(element.getAttribute("source-runtime"), element.getAttribute("source-runtime-version")); return runtime; } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainer.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainer.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainer.java Fri Aug 13 16:28:00 2010 -0700 @@ -40,7 +40,7 @@ } public IIncludePathEntry[] getIncludepathEntries() { - final IMTWProject proj = TMWCore.getDefault().create(project.getProject()); + final IMTWProject proj = TMWCore.create(project.getProject()); if (proj != null) { try { IFacetedProject facetedProject = ProjectFacetsManager.create(project.getProject(), false, @@ -56,7 +56,7 @@ } public String getDescription() { - final IMTWProject proj = TMWCore.getDefault().create(project.getProject()); + final IMTWProject proj = TMWCore.create(project.getProject()); if (proj != null) { final IMobileWebRuntime targetRuntime = proj.getTargetRuntime(); if (targetRuntime != null) { diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainerInitializer.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainerInitializer.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimeLibraryContainerInitializer.java Fri Aug 13 16:28:00 2010 -0700 @@ -98,7 +98,7 @@ } public void initialize(IPath containerPath, IJavaScriptProject project) throws CoreException { - if (!project.isOpen() || TMWCore.getDefault().create(project.getProject()) != null) { + if (!project.isOpen() || TMWCore.create(project.getProject()) != null) { JavaScriptCore.setJsGlobalScopeContainer(containerPath, new IJavaScriptProject[] { project }, new IJsGlobalScopeContainer[] { new MobileRuntimeLibraryContainer(project, containerPath) }, null); } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimesBridge.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimesBridge.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileRuntimesBridge.java Fri Aug 13 16:28:00 2010 -0700 @@ -32,10 +32,10 @@ private final Map stubs = new TreeMap(); public Set getExportedRuntimeNames() throws CoreException { - final IMobileWebRuntime[] allRuntimes = TMWCore.getDefault().getRuntimesManager().getAllRuntimes(); + final IMobileWebRuntime[] allRuntimes = TMWCore.getRuntimesManager().getAllRuntimes(); final Set ids = new TreeSet(); for (IMobileWebRuntime runtime : allRuntimes) { - ids.add(runtime.getId() + ":" + runtime.getVersion()); + ids.add(TMWCore.getFProjSupport().getRuntimeId(runtime)); } return ids; } @@ -46,7 +46,7 @@ if (ind > 0) { stubs.put( name, - new MobileRuntimeStub(TMWCore.getDefault().getRuntimesManager() + new MobileRuntimeStub(TMWCore.getRuntimesManager() .getRuntime(name.substring(0, ind), name.substring(ind + 1)))); } } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimeClasspathManager.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimeClasspathManager.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimeClasspathManager.java Fri Aug 13 16:28:00 2010 -0700 @@ -110,7 +110,7 @@ public IIncludePathEntry[] getProjectClasspathEntries(IFacetedProject project) { collectProviders(); - final IMTWProject p = TMWCore.getDefault().create(project.getProject()); + final IMTWProject p = TMWCore.create(project.getProject()); if (p != null) { final IMobileWebRuntime runtime = p.getTargetRuntime(); final Map>> facetToEntry; diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IFProjSupport.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IFProjSupport.java Fri Aug 13 16:28:00 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.projects; + +import java.util.Set; + +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +/** + * This is a bridge between Faceted Project framework and TMW project frameworks. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IFProjSupport { + /** + * Converts TMW runtime to FProj runtime. + */ + IRuntime getRuntime(IMobileWebRuntime runtime); + + /** + * @param runtime TMW runtime + * @return facets that are always "on" + */ + Set getFixedFacets(IMobileWebRuntime runtime); + + /** + * @return ID of the FProj runtime that corresponds to TMW runtime + */ + String getRuntimeId(IMobileWebRuntime runtime); + + /** + * @return same list as {@link IFProjSupport#getFixedFacets(IMobileWebRuntime)} + */ + Set getFixedFacetsVersions(IMobileWebRuntime runtime); + + /** + * @return core TMW facet + */ + IProjectFacet getTMWFacet(); + +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IMTWProject.java --- a/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IMTWProject.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IMTWProject.java Fri Aug 13 16:28:00 2010 -0700 @@ -24,7 +24,7 @@ public interface IMTWProject { /** - * @return primary target runtime of this project. Can never return null. + * @return primary target runtime of this project. */ IMobileWebRuntime getTargetRuntime(); diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IProjectSetupAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/projects/IProjectSetupAction.java Fri Aug 13 16:28:00 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.projects; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * This object can be set as facet install config for the core TMW facet + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IProjectSetupAction { + /** + * Performs project setup. Project will already be configured with + * validation support and JSDT support. + */ + void initialize(IProject project, IProgressMonitor monitor); +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/META-INF/MANIFEST.MF --- a/org.symbian.tools.mtw.ui/META-INF/MANIFEST.MF Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.ui/META-INF/MANIFEST.MF Fri Aug 13 16:28:00 2010 -0700 @@ -15,10 +15,17 @@ org.eclipse.ui.console;bundle-version="3.5.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" + org.eclipse.core.expressions;bundle-version="3.4.200", + org.eclipse.core.databinding;bundle-version="1.3.100", + org.eclipse.ui.ide;bundle-version="3.6.0", + org.eclipse.core.databinding.beans;bundle-version="1.2.100", + org.eclipse.jface.databinding;bundle-version="1.4.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Bundle-ClassPath: lib/org.bluecove_2.1.1.jar, . Export-Package: org.symbian.tools.tmw.ui, org.symbian.tools.tmw.ui.deployment +Import-Package: org.apache.velocity;version="1.5.0", + org.apache.velocity.app;version="1.5.0", + org.apache.velocity.context;version="1.5.0" diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/icons/full/etool16/newproject.png Binary file org.symbian.tools.mtw.ui/icons/full/etool16/newproject.png has changed diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/plugin.xml --- a/org.symbian.tools.mtw.ui/plugin.xml Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.ui/plugin.xml Fri Aug 13 16:28:00 2010 -0700 @@ -3,6 +3,7 @@ + @@ -168,8 +169,8 @@ + adaptableType="org.symbian.tools.tmw.internal.ui.deployment.targets.ExternalApplicationDeploymentType" + class="org.symbian.tools.tmw.internal.ui.deployment.targets.AdapterFactory"> @@ -178,21 +179,21 @@ @@ -238,4 +239,21 @@ + + + + + + diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/schema/projectTemplate.exsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/schema/projectTemplate.exsd Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,254 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Template may have several archive and/or installer objects - i.e. if it consists of the "static" and "dynamic" portions + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This allows contribution of the templates that are programmatic (i.e. can have a more complex behavior). + + + + + + + + + + + + + + + + + + + + Zip file that contains project templates using Apache Velocity markup + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This element describes contents that will be added to all projects for given runtime. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DefaultDeploymentTypePresentation.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DefaultDeploymentTypePresentation.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeployWizardContext.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeployWizardContext.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetPresentationsManager.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetPresentationsManager.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypeDescriptor.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypeDescriptor.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypesRegistry.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetTypesRegistry.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWizardPage.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWizardPage.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWrapper.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/DeploymentTargetWrapper.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/TargetWorkbenchAdapter.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/TargetWorkbenchAdapter.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/externalapp/FilesystemDeploymentTarget.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/externalapp/FilesystemDeploymentTarget.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/AdapterFactory.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/AdapterFactory.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/ExternalApplicationDeploymentType.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/ExternalApplicationDeploymentType.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/FilesystemDeploymentTarget.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/FilesystemDeploymentTarget.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/LocalFileSystemPane.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/deployment/targets/LocalFileSystemPane.java Tue Aug 10 09:52:29 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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/MTWGlobalScopeContainerUI.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/MTWGlobalScopeContainerUI.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/TMWContainerPage.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/libraries/TMWContainerPage.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/DefaultDeploymentTypePresentation.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/DeployWizardContext.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/DeploymentTargetPresentationsManager.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/DeploymentTargetTypeDescriptor.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/DeploymentTargetTypesRegistry.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/DeploymentTargetWizardPage.java Fri Aug 13 16:28:00 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.ui.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.ProjectMemo; +import org.symbian.tools.tmw.ui.TMWCoreUI; +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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/DeploymentTargetWrapper.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/TargetWorkbenchAdapter.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/externalapp/FilesystemDeploymentTarget.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/targets/AdapterFactory.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/targets/ExternalApplicationDeploymentType.java Fri Aug 13 16:28:00 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.ui.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.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/targets/FilesystemDeploymentTarget.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/deployment/targets/LocalFileSystemPane.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/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/ui/libraries/TMWContainerPage.java Fri Aug 13 16:28:00 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.ui.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 cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/libraries/TMWGlobalScopeContainerUI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/libraries/TMWGlobalScopeContainerUI.java Fri Aug 13 16:28:00 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.ui.libraries; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; +import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; +import org.eclipse.wst.common.project.facet.ui.IDecorationsProvider; +import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.internal.ui.IJsGlobalScopeContainerInitializerExtension; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IMTWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +@SuppressWarnings("restriction") +public class TMWGlobalScopeContainerUI implements IJsGlobalScopeContainerInitializerExtension { + + public ImageDescriptor getImage(IPath containerPath, String element, IJavaScriptProject project) { + final IMTWProject p = TMWCore.create(project.getProject()); + if (p != null) { + final IMobileWebRuntime runtime = p.getTargetRuntime(); + if (runtime != null) { + final IRuntime r = RuntimeManager.getRuntime(runtime.getId()); + final IDecorationsProvider decorationsProvider = (IDecorationsProvider) r + .getAdapter(IDecorationsProvider.class); + if (decorationsProvider != null) { + return decorationsProvider.getIcon(); + } + } + } + return null; + } + +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/CompoundInstaller.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/CompoundInstaller.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,132 @@ +/** + * 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.ui.project; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +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.eclipse.core.runtime.SubProgressMonitor; +import org.symbian.tools.tmw.ui.project.IProjectTemplateContext; +import org.symbian.tools.tmw.ui.project.ITemplateInstaller; + +public class CompoundInstaller implements ITemplateInstaller { + private final class InstallerFiles { + private final ITemplateInstaller installer; + private final Collection paths; + + public InstallerFiles(Collection paths, ITemplateInstaller installer) { + this.paths = paths; + this.installer = installer; + } + } + + public static ITemplateInstaller combine(ITemplateInstaller installer, IConfigurationElement[] elements) { + final ITemplateInstaller[] installers = getChildren(installer); + final Collection installerCollection = new ArrayList(installers.length + + elements.length); + installerCollection.addAll(Arrays.asList(installers)); + installerCollection.addAll(fromExtensions(elements)); + return new CompoundInstaller(installerCollection.toArray(new ITemplateInstaller[installerCollection.size()])); + } + + public static ITemplateInstaller combine(ITemplateInstaller installer1, ITemplateInstaller installer2) { + final ITemplateInstaller[] children1 = getChildren(installer1); + final ITemplateInstaller[] children2 = getChildren(installer2); + final ITemplateInstaller[] result = new ITemplateInstaller[children1.length + children2.length]; + System.arraycopy(children1, 0, result, 0, children1.length); + System.arraycopy(children2, 0, result, children1.length, children2.length); + return new CompoundInstaller(result); + } + + private static Collection fromExtensions(IConfigurationElement[] elements) { + final Collection result = new LinkedList(); + for (IConfigurationElement element : elements) { + if ("installer".equals(element.getName())) { + result.add(new LazyInstaller(element)); + } else if ("archive".equals(element.getName())) { + result.add(new ZipInstaller(element)); + } + } + return result; + } + + private static ITemplateInstaller[] getChildren(ITemplateInstaller installer) { + final ITemplateInstaller[] installers; + if (installer == null) { + installers = new ITemplateInstaller[0]; + } else if (installer instanceof CompoundInstaller) { + installers = ((CompoundInstaller) installer).installers; + } else { + installers = new ITemplateInstaller[] { installer }; + } + return installers; + } + + private final Collection files = new LinkedList(); + private final ITemplateInstaller[] installers; + + private CompoundInstaller(ITemplateInstaller[] installers) { + this.installers = installers; + } + + public void cleanup() { + for (ITemplateInstaller installer : installers) { + installer.cleanup(); + } + } + + public void copyFiles(IPath[] files, IProgressMonitor monitor) throws CoreException { + monitor.beginTask("Copying files", files.length * 10); + final List list = Arrays.asList(files); + for (InstallerFiles fs : this.files) { + final ITemplateInstaller installer = fs.installer; + fs.paths.retainAll(list); + IPath[] array = fs.paths.toArray(new IPath[fs.paths.size()]); + installer.copyFiles(array, new SubProgressMonitor(monitor, array.length * 10)); + } + monitor.done(); + } + + public IPath[] getFiles() throws CoreException { + final Collection paths = new HashSet(); + for (ITemplateInstaller installer : installers) { + final IPath[] f = installer.getFiles(); + final Collection c = new HashSet(Arrays.asList(f)); + c.removeAll(paths); + files.add(new InstallerFiles(c, installer)); + paths.addAll(c); + } + return paths.toArray(new IPath[paths.size()]); + } + + public void prepare(IProject project, IProjectTemplateContext context) { + for (ITemplateInstaller installer : installers) { + installer.prepare(project, context); + } + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/LazyInstaller.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/LazyInstaller.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,82 @@ +/** + * 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.ui.project; + +import org.eclipse.core.resources.IProject; +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.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.project.IProjectTemplateContext; +import org.symbian.tools.tmw.ui.project.ITemplateInstaller; + +public final class LazyInstaller implements ITemplateInstaller { + private final class NullInstaller implements ITemplateInstaller { + public void cleanup() { + // Do nothing + } + + public void copyFiles(IPath[] files, IProgressMonitor monitor) { + // Do nothing + } + + public IPath[] getFiles() throws CoreException { + return new IPath[0]; + } + + public void prepare(IProject project, IProjectTemplateContext context) { + // Do nothing + } + } + private final IConfigurationElement element; + private ITemplateInstaller installer; + + public LazyInstaller(IConfigurationElement element) { + this.element = element; + } + + public void cleanup() { + getInstaller().cleanup(); + } + + public void copyFiles(IPath[] files, IProgressMonitor monitor) throws CoreException { + getInstaller().copyFiles(files, monitor); + } + + public IPath[] getFiles() throws CoreException { + return getInstaller().getFiles(); + } + + private ITemplateInstaller getInstaller() { + if (installer == null) { + try { + installer = (ITemplateInstaller) element.createExecutableExtension("class"); + } catch (CoreException e) { + TMWCoreUI.log(e); + installer = new NullInstaller(); + } + } + return installer; + } + + public void prepare(IProject project, IProjectTemplateContext context) { + getInstaller().prepare(project, context); + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,145 @@ +/** + * 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.ui.project; + +import org.eclipse.core.resources.IProject; +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.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.project.IProjectTemplate; +import org.symbian.tools.tmw.ui.project.IProjectTemplateContext; +import org.symbian.tools.tmw.ui.project.ITemplateInstaller; + +public class ProjectTemplateImpl implements IProjectTemplate { + private final IConfigurationElement element; + private Image image; + private IMobileWebRuntime[] runtimes; + private IProjectFacetVersion[] facetVersions; + private ITemplateInstaller installer; + + public ProjectTemplateImpl(IConfigurationElement element) { + this.element = element; + } + + public int getWeight() { + final String weight = element.getAttribute("weight"); + try { + return Integer.valueOf(weight).intValue(); + } catch (NumberFormatException e) { + TMWCoreUI.log("Invalid weight: %s in project template %s", weight, getName()); + return Integer.MAX_VALUE; + } + } + + public Image getIcon() { + if (image == null) { + final ImageDescriptor imageDescriptor = TMWCoreUI.imageDescriptorFromPlugin(element.getContributor() + .getName(), element.getAttribute("icon")); + final String key = "Template#" + getName(); + TMWCoreUI.getDefault().getImageRegistry().put(key, imageDescriptor); + image = TMWCoreUI.getDefault().getImageRegistry().get(key); + } + return image; + } + + public String getName() { + return element.getAttribute("name"); + } + + public String getDescription() { + IConfigurationElement[] children = element.getChildren("description"); + if (children.length > 0) { + return children[0].getValue(); + } + return ""; + } + + public IMobileWebRuntime[] getSupportedRuntimes() { + if (runtimes == null) { + final IConfigurationElement[] children = element.getChildren("supported-runtime"); + runtimes = new IMobileWebRuntime[children.length]; + for (int i = 0; i < children.length; i++) { + final IConfigurationElement element = children[i]; + final String id = element.getAttribute("id"); + final String version = element.getAttribute("version"); + runtimes[i] = TMWCore.getRuntimesManager().getRuntime(id, version); + if (runtimes[i] == null) { + TMWCoreUI.log("Runtime %s@%s was not found. It is needed for project template %s.", id, version, + getName()); + } + } + } + return runtimes; + } + + public IProjectFacetVersion[] getRequiredFacets() { + if (facetVersions == null) { + final IConfigurationElement[] children = element.getChildren("required-facet"); + facetVersions = new IProjectFacetVersion[children.length]; + for (int i = 0; i < children.length; i++) { + final IConfigurationElement element = children[i]; + final IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(element.getAttribute("id")); + if (projectFacet != null) { + facetVersions[i] = projectFacet.getVersion(element.getAttribute("version")); + } + if (facetVersions[i] == null) { + TMWCoreUI.log("Facet %s@%s was not found. It is required by project template %s.", + element.getAttribute("id"), element.getAttribute("version")); + } + } + } + return facetVersions; + } + + public void init(IProject project, IProjectTemplateContext context, IProgressMonitor monitor) { + if (installer == null) { + installer = CompoundInstaller.combine(null, element.getChildren()); + } + final ITemplateInstaller templateInstaller; + final IMobileWebRuntime runtime = context.getRuntime(); + if (runtime == null) { + templateInstaller = installer; + } else { + templateInstaller = CompoundInstaller.combine(installer, TMWCoreUI.getProjectTemplateManager() + .getEmptyProjectTemplate(runtime)); + } + templateInstaller.prepare(project, context); + try { + final IPath[] files = templateInstaller.getFiles(); + monitor.beginTask("Copying project files", files.length * 10); + templateInstaller.copyFiles(files, new SubProgressMonitor(monitor, files.length * 10)); + } catch (CoreException e) { + TMWCoreUI.log(e); + } finally { + templateInstaller.cleanup(); + } + monitor.done(); + } + +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateManagerImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateManagerImpl.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,96 @@ +/** + * 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.ui.project; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +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.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.project.IProjectTemplate; +import org.symbian.tools.tmw.ui.project.IProjectTemplateManager; +import org.symbian.tools.tmw.ui.project.ITemplateInstaller; + +public class ProjectTemplateManagerImpl implements IProjectTemplateManager { + private Map emptyProjects; + private Map templates; + + public IProjectTemplate getDefaultTemplate(IMobileWebRuntime runtime) { + final IProjectTemplate[] projectTemplates = getProjectTemplates(runtime); + return projectTemplates != null && projectTemplates.length > 0 ? projectTemplates[0] : null; + } + + public ITemplateInstaller getEmptyProjectTemplate(IMobileWebRuntime runtime) { + if (emptyProjects == null) { + readExtensions(); + } + return emptyProjects.get(runtime); + } + + public IProjectTemplate[] getProjectTemplates(IMobileWebRuntime runtime) { + if (runtime == null) { + return new IProjectTemplate[0]; + } + if (templates == null) { + templates = readExtensions(); + } + final IProjectTemplate[] runtimeTemplates = templates.get(runtime); + return runtimeTemplates == null ? new IProjectTemplate[0] : runtimeTemplates; + } + + private Map readExtensions() { + emptyProjects = new HashMap(); + final Map> map = new HashMap>(); + final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCoreUI.PLUGIN_ID, "projectTemplate"); + for (IConfigurationElement element : elements) { + if ("template".equals(element.getName())) { + final ProjectTemplateImpl template = new ProjectTemplateImpl(element); + final IMobileWebRuntime[] supportedRuntimes = template.getSupportedRuntimes(); + for (IMobileWebRuntime runtime : supportedRuntimes) { + Collection tmplts = map.get(runtime); + if (tmplts == null) { + tmplts = new HashSet(); + map.put(runtime, tmplts); + } + tmplts.add(template); + } + } else if ("empty-project".equals(element.getName())) { + final String runtimeId = element.getAttribute("runtime-id"); + final String runtimeVersion = element.getAttribute("version"); + final IMobileWebRuntime runtime = TMWCore.getRuntimesManager().getRuntime(runtimeId, runtimeVersion); + if (runtime != null) { + emptyProjects.put(runtime, CompoundInstaller.combine(emptyProjects.get(runtime), elements)); + } + } + } + final Map res = new HashMap( + map.size()); + for (Map.Entry> entry : map.entrySet()) { + final Collection collection = entry.getValue(); + res.put(entry.getKey(), collection.toArray(new IProjectTemplate[collection.size()])); + } + return res; + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/ZipInstaller.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/project/ZipInstaller.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,251 @@ +/** + * 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.ui.project; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.context.AbstractContext; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.InvalidRegistryObjectException; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.project.IProjectTemplateContext; +import org.symbian.tools.tmw.ui.project.ITemplateInstaller; + +/** + * Initializes project with zip archive contents + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public class ZipInstaller implements ITemplateInstaller { + private static final String TEMPLATE_FILE_EXTENSION = ".velocitytemplate"; + private final IConfigurationElement element; + private IProject project; + private IProjectTemplateContext context; + private String[] paths; + + public ZipInstaller(IConfigurationElement element) { + this.element = element; + try { + Velocity.init(); + } catch (Exception e) { + TMWCoreUI.log(e); + } + } + + public void prepare(IProject project, IProjectTemplateContext context) { + this.project = project; + this.context = context; + } + + public void cleanup() { + project = null; + context = null; + } + + public IPath[] getFiles() throws CoreException { + if (paths == null) { + final Collection pathCollection = new LinkedList(); + ZipInputStream stream = null; + try { + stream = openArchive(); + ZipEntry nextEntry = stream.getNextEntry(); + while (nextEntry != null) { + if (!nextEntry.isDirectory()) { + pathCollection.add(nextEntry.getName()); + } + nextEntry = stream.getNextEntry(); + } + } catch (InvalidRegistryObjectException e) { + TMWCoreUI.log(e); + } catch (IOException e) { + TMWCoreUI.log(e); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + TMWCoreUI.log(e); + } + } + } + paths = pathCollection.toArray(new String[pathCollection.size()]); + } + return filter(paths); + } + + private IPath[] filter(String[] paths) { + final IPath[] filtered = new IPath[paths.length]; + for (int i = 0; i < paths.length; i++) { + filtered[i] = new Path(filter(paths[i])).makeRelative(); + } + return filtered; + } + + private String filter(String path) { + if (path.endsWith(TEMPLATE_FILE_EXTENSION)) { + path = path.substring(0, path.length() - TEMPLATE_FILE_EXTENSION.length()); + } + VelocityContext ctx = new VelocityContext(new TemplateContext(context)); + final StringWriter val = new StringWriter(); + try { + Velocity.evaluate(ctx, val, null, path); + path = val.toString(); + } catch (Exception e) { + TMWCoreUI.log(e); + } + return path; + } + + private ZipInputStream openArchive() throws IOException { + final InputStream stream = FileLocator.openStream(Platform.getBundle(element.getContributor().getName()), + new Path(element.getAttribute("file")), true); + final ZipInputStream inputStream = new ZipInputStream(stream); + return inputStream; + } + + public void copyFiles(IPath[] files, IProgressMonitor monitor) throws CoreException { + HashSet fls = new HashSet(Arrays.asList(files)); + ZipInputStream stream = null; + try { + VelocityContext ctx = new VelocityContext(new TemplateContext(context)); + stream = openArchive(); + monitor.beginTask("Generating project contents", IProgressMonitor.UNKNOWN); + ZipEntry entry; + while ((entry = stream.getNextEntry()) != null && !monitor.isCanceled()) { + String nm = entry.getName(); + IPath name = new Path(filter(nm)); + if (fls.contains(name)) { + final InputStream contents; + if (nm.endsWith(TEMPLATE_FILE_EXTENSION)) { + contents = copyTemplate(project, name, stream, (int) entry.getSize(), ctx, monitor); + } else { + contents = new NonClosingStream(stream); + } + context.addFile(project, name, contents, new SubProgressMonitor(monitor, 10)); + } + stream.closeEntry(); + } + monitor.done(); + } catch (Exception e) { + throw new CoreException(new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, "Project creation failed", e)); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + // Ignore - something really bad happened + } + } + } + } + + private InputStream copyTemplate(IProject project, IPath name, ZipInputStream stream, int size, + VelocityContext ctx, + IProgressMonitor monitor) throws IOException, CoreException { + // Templates will not be more then a few megs - we can afford the memory + ByteArrayOutputStream file = new ByteArrayOutputStream(); + + Reader reader = new InputStreamReader(new NonClosingStream(stream)); + Writer writer = new OutputStreamWriter(file); + + Velocity.evaluate(ctx, writer, name.toOSString(), reader); + + reader.close(); + writer.close(); + + return new ByteArrayInputStream(file.toByteArray()); + } + + private static final class NonClosingStream extends FilterInputStream { + private NonClosingStream(InputStream in) { + super(in); + } + + @Override + public void close() throws IOException { + // Avoid closing ZIP file + } + } + + private static final class TemplateContext extends AbstractContext { + private final IProjectTemplateContext context; + + public TemplateContext(IProjectTemplateContext context) { + this.context = context; + } + + @Override + public boolean internalContainsKey(Object key) { + return context.getParameter((String) key) != null; + } + + @Override + public Object internalGet(String key) { + return context.getParameter(key); + } + + @Override + public Object[] internalGetKeys() { + return context.getParameterNames(); + } + + @Override + public Object internalPut(String key, Object value) { + if (key != null) { + final Object v = context.getParameter(key); + context.putParameter(key, value); + return v; + } + return null; + } + + @Override + public Object internalRemove(Object key) { + return internalPut((String) key, null); + } + + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/AbstractDataBindingPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/AbstractDataBindingPage.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,37 @@ +/** + * 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.internal.ui.wizard; + + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.WizardPage; + +public abstract class AbstractDataBindingPage extends WizardPage { + public AbstractDataBindingPage(WizardContext context, + DataBindingContext bindingContext, String name, String title, + ImageDescriptor image, String description) { + super(name, title, image); + setDescription(description); + } + + protected boolean isActive() { + return true; + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/CompoundValidator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/CompoundValidator.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,37 @@ +package org.symbian.tools.tmw.internal.ui.wizard; + +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + + +public class CompoundValidator implements IValidator { + private final IValidator[] validators; + + public CompoundValidator(IValidator ... validators) { + this.validators = validators; + } + + public CompoundValidator(NonEmptyStringValidator validator, + IValidator[] validators) { + this.validators = new IValidator[validators.length + 1]; + this.validators[0] = validator; + System.arraycopy(validators, 0, this.validators, 1, validators.length); + } + + public IStatus validate(Object value) { + IStatus status = Status.OK_STATUS; + + for (IValidator validator : validators) { + IStatus s = validator.validate(value); + switch (s.getSeverity()) { + case IStatus.ERROR: + return s; + case IStatus.WARNING: + status = s; + } + } + return status; + } + +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/FacetsSelectionPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/FacetsSelectionPage.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,97 @@ +package org.symbian.tools.tmw.internal.ui.wizard; + +import java.util.Set; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.help.IWorkbenchHelpSystem; +import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent; +import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener; +import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; +import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleEvent; +import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleListener; +import org.eclipse.wst.common.project.facet.ui.FacetUiHelpContextIds; +import org.eclipse.wst.common.project.facet.ui.internal.FacetedProjectFrameworkImages; + +/** + * @author Konstantin Komissarchik + */ + +@SuppressWarnings("restriction") +public final class FacetsSelectionPage extends WizardPage { + public FacetsSelectionPanel panel; + private final IFacetedProjectWorkingCopy fpjwc; + + public FacetsSelectionPage(final Set base, final IFacetedProjectWorkingCopy fpjwc) { + super("facets.selection.page"); //$NON-NLS-1$ + + setTitle("Project Facets"); + setDescription("Select the facets that should be enabled for this project."); + setImageDescriptor(FacetedProjectFrameworkImages.BANNER_IMAGE.getImageDescriptor()); + + this.fpjwc = fpjwc; + } + + public void createControl(final Composite parent) { + this.panel = new FacetsSelectionPanel(parent, this.fpjwc); + + updatePageState(); + + this.fpjwc.addListener(new IFacetedProjectListener() { + public void handleEvent(final IFacetedProjectEvent event) { + updatePageState(); + } + }, IFacetedProjectEvent.Type.PROJECT_MODIFIED); + + final IRuntimeLifecycleListener runtimeLifecycleListener = new IRuntimeLifecycleListener() { + public void handleEvent(final IRuntimeLifecycleEvent event) { + updatePageState(); + } + }; + + RuntimeManager.addListener(runtimeLifecycleListener, IRuntimeLifecycleEvent.Type.VALIDATION_STATUS_CHANGED); + + this.panel.addDisposeListener(new DisposeListener() { + public void widgetDisposed(final DisposeEvent e) { + RuntimeManager.removeListener(runtimeLifecycleListener); + } + }); + + final IWorkbenchHelpSystem h = PlatformUI.getWorkbench().getHelpSystem(); + h.setHelp(this.panel, FacetUiHelpContextIds.FACETS_SELECTION_PAGE); + + setControl(this.panel); + } + + private void updatePageState() { + if (!Thread.currentThread().equals(this.panel.getDisplay().getThread())) { + final Runnable uiRunnable = new Runnable() { + public void run() { + updatePageState(); + } + }; + + this.panel.getDisplay().asyncExec(uiRunnable); + return; + } + + setPageComplete(this.panel.isSelectionValid()); + + if (getContainer().getCurrentPage() != null) { + getContainer().updateButtons(); + } + } + + public void setVisible(final boolean visible) { + super.setVisible(visible); + + if (visible) { + this.panel.setFocus(); + } + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/FacetsSelectionPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/FacetsSelectionPanel.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,780 @@ +package org.symbian.tools.tmw.internal.ui.wizard; + +import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gdfill; +import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gdhhint; +import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gdhspan; +import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gdwhint; +import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gl; +import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.glmargins; +import static org.eclipse.wst.common.project.facet.ui.internal.util.SwtUtil.getPreferredWidth; +import static org.eclipse.wst.common.project.facet.ui.internal.util.SwtUtil.runOnDisplayThread; + +import java.lang.reflect.Method; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.jface.window.ToolTip; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent; +import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener; +import org.eclipse.wst.common.project.facet.core.events.IProjectFacetsChangedEvent; +import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; +import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleEvent; +import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleListener; +import org.eclipse.wst.common.project.facet.ui.IDecorationsProvider; +import org.eclipse.wst.common.project.facet.ui.internal.FacetUiPlugin; +import org.eclipse.wst.common.project.facet.ui.internal.util.BasicToolTip; +import org.eclipse.wst.common.project.facet.ui.internal.util.HeaderToolTip; +import org.symbian.tools.tmw.core.TMWCore; + +/** + * @author Konstantin Komissarchik + */ + +public final class FacetsSelectionPanel extends Composite implements ISelectionProvider { + private final Composite topComposite; + private final SashForm sform1; + private final CheckboxTableViewer tableViewer; + private final Table table; + private final FixedFacetToolTip fixedFacetToolTip; + private final TableViewer problemsView; + private boolean showToolTips; + private final IFacetedProjectWorkingCopy fpjwc; + private final List registeredWorkingCopyListeners; + private final Map selectedVersions; + private final List selectionListeners; + private Object selection; + + /** + * Holds images used throughout the panel. + */ + + private final ImageRegistry imageRegistry; + + private final IRuntimeLifecycleListener runtimeLifecycleListener; + + public interface IFilter { + boolean check(IProjectFacetVersion fv); + } + + public FacetsSelectionPanel(final Composite parent, final IFacetedProjectWorkingCopy fpjwc) { + super(parent, SWT.NONE); + + this.fpjwc = fpjwc; + this.registeredWorkingCopyListeners = new ArrayList(); + this.selectedVersions = new HashMap(); + this.selection = null; + this.selectionListeners = new ArrayList(); + this.showToolTips = false; + + // Initialize the image registry. + + this.imageRegistry = new ImageRegistry(); + // Layout the panel. + + setLayout(glmargins(gl(1), 0, 0)); + + this.topComposite = new Composite(this, SWT.NONE); + this.topComposite.setLayout(glmargins(gl(4), 0, 0)); + + this.sform1 = new SashForm(this.topComposite, SWT.VERTICAL | SWT.SMOOTH); + this.sform1.setLayoutData(gdhspan(gdfill(), 4)); + + this.table = new Table(this.sform1, SWT.BORDER | SWT.CHECK); + this.tableViewer = new CheckboxTableViewer(this.table); + + this.tableViewer.setLabelProvider(new FacetColumnLabelProvider()); + this.tableViewer.setContentProvider(new ContentProvider()); + this.tableViewer.setSorter(new Sorter()); + + new FacetToolTip(this.table); + this.fixedFacetToolTip = new FixedFacetToolTip(this.table); + + this.tableViewer.setInput(new Object()); + + this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(final SelectionChangedEvent e) { + FacetsSelectionPanel.this.handleSelectionChangedEvent(); + } + }); + + this.tableViewer.addCheckStateListener(new ICheckStateListener() { + public void checkStateChanged(final CheckStateChangedEvent e) { + FacetsSelectionPanel.this.handleCheckStateChanged(e); + } + }); + + this.table.addListener(SWT.MouseDown, new Listener() { + public void handleEvent(final Event event) { + handleMouseDownEvent(event); + } + }); + + this.problemsView = new TableViewer(this.sform1, SWT.BORDER); + this.problemsView.setContentProvider(new ProblemsContentProvider()); + this.problemsView.setLabelProvider(new ProblemsLabelProvider()); + this.problemsView.setInput(new Object()); + + addDisposeListener(new DisposeListener() { + public void widgetDisposed(final DisposeEvent e) { + handleDisposeEvent(); + } + }); + + Dialog.applyDialogFont(parent); + + // Setup runtime lifecycle listener. + + this.runtimeLifecycleListener = new IRuntimeLifecycleListener() { + public void handleEvent(final IRuntimeLifecycleEvent event) { + handleValidationProblemsChangedEvent(); + } + }; + + RuntimeManager + .addListener(this.runtimeLifecycleListener, IRuntimeLifecycleEvent.Type.VALIDATION_STATUS_CHANGED); + + // Bind to the model. + + addWorkingCopyListener(new IFacetedProjectListener() { + public void handleEvent(final IFacetedProjectEvent event) { + handleProjectFacetsChangedEvent(event); + } + }, IFacetedProjectEvent.Type.PROJECT_FACETS_CHANGED); + + handleProjectFacetsChangedEvent(null); + + addWorkingCopyListener(new IFacetedProjectListener() { + public void handleEvent(final IFacetedProjectEvent event) { + handleValidationProblemsChangedEvent(); + } + }, IFacetedProjectEvent.Type.VALIDATION_PROBLEMS_CHANGED, IFacetedProjectEvent.Type.PROJECT_MODIFIED); + + handleValidationProblemsChangedEvent(); + + addWorkingCopyListener(new IFacetedProjectListener() { + public void handleEvent(final IFacetedProjectEvent event) { + handleModelChangedEvent(event); + } + }, IFacetedProjectEvent.Type.FIXED_FACETS_CHANGED, IFacetedProjectEvent.Type.SELECTED_PRESET_CHANGED, + IFacetedProjectEvent.Type.TARGETED_RUNTIMES_CHANGED); + + // Set the preferred dimensions of the panel. + + final int prefWidthTree = getPreferredWidth(this.table); + final int prefWidth = prefWidthTree + 80; + + this.topComposite.setLayoutData(gdwhint(gdhhint(gdfill(), 500), prefWidth)); + + this.sform1.setWeights(new int[] { 70, 30 }); + + // Select the first item in the table. + + if (this.table.getItemCount() > 0) { + final TableItem firstItem = this.table.getItem(0); + this.tableViewer.setSelection(new StructuredSelection(firstItem.getData())); + } + + handleSelectionChangedEvent(); + } + + public IFacetedProjectWorkingCopy getFacetedProjectWorkingCopy() { + return this.fpjwc; + } + + public boolean isSelectionValid() { + return (this.fpjwc.validate().getSeverity() != IStatus.ERROR); + } + + public boolean setFocus() { + return this.table.setFocus(); + } + + public void addSelectionChangedListener(final ISelectionChangedListener listener) { + this.selectionListeners.add(listener); + } + + public void removeSelectionChangedListener(final ISelectionChangedListener listener) { + this.selectionListeners.remove(listener); + } + + public ISelection getSelection() { + if (this.selection != null) { + return new StructuredSelection(this.selection); + } else { + return new StructuredSelection(new Object[0]); + } + } + + public void setSelection(final ISelection selection) { + throw new UnsupportedOperationException(); + } + + private void notifySelectionChangedListeners() { + final SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection()); + + for (ISelectionChangedListener listener : this.selectionListeners) { + listener.selectionChanged(event); + } + } + + private ImageRegistry getImageRegistry() { + return this.imageRegistry; + } + + public Image getImage(final IProjectFacet facet, final boolean showDecorations) { + final boolean isFixed = getFacetedProjectWorkingCopy().isFixedProjectFacet(facet); + final String id = (isFixed && showDecorations ? "F:" : "f:") + facet.getId(); //$NON-NLS-1$ //$NON-NLS-2$ + + Image image = getImageRegistry().get(id); + + if (image == null) { + final IDecorationsProvider decprov = (IDecorationsProvider) facet.getAdapter(IDecorationsProvider.class); + + ImageDescriptor imgdesc = decprov.getIcon(); + + if (isFixed && showDecorations) { + imgdesc = new FixedFacetImageDescriptor(imgdesc); + } + + getImageRegistry().put(id, imgdesc); + image = getImageRegistry().get(id); + } + + return image; + } + + private void refresh() { + // Somehow the checked state of nested items gets lost when a refresh + // is performed, so we have to do this workaround. + + final Object[] checked = this.tableViewer.getCheckedElements(); + this.tableViewer.refresh(); + this.tableViewer.setCheckedElements(checked); + } + + public boolean getShowToolTips() { + return this.showToolTips; + } + + public void setShowToolTips(final boolean showToolTips) { + this.showToolTips = showToolTips; + } + + private void addWorkingCopyListener(final IFacetedProjectListener listener, + final IFacetedProjectEvent.Type... types) { + this.fpjwc.addListener(listener, types); + this.registeredWorkingCopyListeners.add(listener); + } + + public IProjectFacet getSelectedProjectFacet() { + final IProjectFacetVersion fv = getSelectedProjectFacetVersion(); + + if (fv != null) { + return fv.getProjectFacet(); + } + + return null; + } + + public IProjectFacetVersion getSelectedProjectFacetVersion() { + if (this.selection != null && this.selection instanceof IProjectFacetVersion) { + return (IProjectFacetVersion) this.selection; + } + + return null; + } + + private IProjectFacetVersion getSelectedVersion(final IProjectFacet f) { + final Set availableVersions = this.fpjwc.getAvailableVersions(f); + + if (availableVersions.isEmpty()) { + throw new IllegalStateException(); + } + + IProjectFacetVersion selectedVersion = this.fpjwc.getProjectFacetVersion(f); + + if (selectedVersion == null) { + selectedVersion = this.selectedVersions.get(f); + + if (selectedVersion == null) { + selectedVersion = f.getDefaultVersion(); + } + + if (!availableVersions.contains(selectedVersion)) { + selectedVersion = this.fpjwc.getHighestAvailableVersion(f); + } + } + + this.selectedVersions.put(f, selectedVersion); + + return selectedVersion; + } + + private void handleSelectionChangedEvent() { + Object selection = ((IStructuredSelection) this.tableViewer.getSelection()).getFirstElement(); + + if (selection != null && selection instanceof IProjectFacet) { + selection = getSelectedVersion((IProjectFacet) selection); + } + + if (selection != this.selection) { + this.selection = selection; + + notifySelectionChangedListeners(); + } + } + + private void handleCheckStateChanged(final CheckStateChangedEvent event) { + final Object el = event.getElement(); + final boolean checked = event.getChecked(); + + final IProjectFacet f = (IProjectFacet) el; + + if (this.fpjwc.getFixedProjectFacets().contains(f)) { + if (!checked) { + this.tableViewer.setChecked(el, true); + + final String msg = MessageFormat + .format("Project facet {0} cannot be deselected. It is critical to the proper function of this project.", + f.getLabel()); + + this.fixedFacetToolTip.setMessage(msg); + + final Point cursorLocation = getDisplay().getCursorLocation(); + this.fixedFacetToolTip.show(this.table.toControl(cursorLocation)); + } + + return; + } + + if (checked) { + this.fpjwc.addProjectFacet(getSelectedVersion(f)); + } else { + this.fpjwc.removeProjectFacet(f); + } + + this.fpjwc.setSelectedPreset(null); + } + + private void handleMouseDownEvent(final Event event) { + handleMouseDownEventHelper(event, this.table.getItems()); + } + + private boolean handleMouseDownEventHelper(final Event event, final TableItem[] items) { + for (TableItem item : items) { + if (item.getBounds(1).contains(event.x, event.y)) { + final TableItem[] newSelection = new TableItem[] { item }; + + if (!Arrays.equals(this.table.getSelection(), newSelection)) { + this.table.setSelection(new TableItem[] { item }); + this.tableViewer.editElement(item.getData(), 1); + } + + return true; + } + } + + return false; + } + + private void handleDisposeEvent() { + this.imageRegistry.dispose(); + + for (IFacetedProjectListener listener : this.registeredWorkingCopyListeners) { + this.fpjwc.removeListener(listener); + } + + RuntimeManager.removeListener(this.runtimeLifecycleListener); + } + + private void handleProjectFacetsChangedEvent(final IFacetedProjectEvent event) { + if (!Thread.currentThread().equals(getDisplay().getThread())) { + final Runnable uiRunnable = new Runnable() { + public void run() { + handleProjectFacetsChangedEvent(event); + } + }; + + getDisplay().asyncExec(uiRunnable); + + return; + } + + if (event != null) { + final IFacetedProjectWorkingCopy fpjwc = event.getWorkingCopy(); + + final IProjectFacetsChangedEvent evt = (IProjectFacetsChangedEvent) event; + + for (IProjectFacetVersion fv : evt.getAllAffectedFacets()) { + final IProjectFacet f = fv.getProjectFacet(); + final boolean checked = fpjwc.hasProjectFacet(fv); + + this.tableViewer.setChecked(f, checked); + this.tableViewer.update(f, null); + } + } else { + final List facets = new ArrayList(); + + for (IProjectFacetVersion fv : this.fpjwc.getProjectFacets()) { + facets.add(fv.getProjectFacet()); + } + + this.tableViewer.setCheckedElements(facets.toArray()); + this.tableViewer.update(this.fpjwc.getAvailableFacets().keySet().toArray(), null); + } + } + + private void handleValidationProblemsChangedEvent() { + if (!Thread.currentThread().equals(getDisplay().getThread())) { + final Runnable uiRunnable = new Runnable() { + public void run() { + handleValidationProblemsChangedEvent(); + } + }; + + getDisplay().asyncExec(uiRunnable); + + return; + } + + this.problemsView.refresh(); + + if (getFilteredProblems().length == 0) { + if (this.sform1.getMaximizedControl() == null) { + this.sform1.setMaximizedControl(this.tableViewer.getControl()); + } + } else { + if (this.sform1.getMaximizedControl() != null) { + this.sform1.setMaximizedControl(null); + } + } + } + + private void handleModelChangedEvent(final IFacetedProjectEvent event) { + switch (event.getType()) { + case FIXED_FACETS_CHANGED: + case TARGETED_RUNTIMES_CHANGED: { + final Runnable runnable = new Runnable() { + public void run() { + refresh(); + } + }; + + runOnDisplayThread(getDisplay(), runnable); + + break; + } + } + } + + private TableItem getTreeItem(final int x, final int y) { + return getTreeItemHelper(x, y, this.table.getItems()); + } + + private static TableItem getTreeItemHelper(final int x, final int y, final TableItem[] items) { + for (TableItem item : items) { + if (item.getBounds().contains(x, y)) { + return item; + } + } + + return null; + } + + private IStatus[] getFilteredProblems() { + final IStatus[] unfiltered = this.fpjwc.validate().getChildren(); + boolean somethingToRemove = false; + + for (IStatus st : unfiltered) { + if (st.getCode() == IFacetedProjectWorkingCopy.PROBLEM_PROJECT_NAME) { + somethingToRemove = true; + break; + } + } + + if (!somethingToRemove) { + return unfiltered; + } + + final List filtered = new ArrayList(); + + for (IStatus st : unfiltered) { + if (st.getCode() != IFacetedProjectWorkingCopy.PROBLEM_PROJECT_NAME) { + filtered.add(st); + } + } + + return filtered.toArray(new IStatus[filtered.size()]); + } + + private final class ContentProvider + + implements ITreeContentProvider + + { + public Object[] getElements(final Object element) { + final IFacetedProjectWorkingCopy fpjwc = getFacetedProjectWorkingCopy(); + final List list = new ArrayList(); + for (Map.Entry> entry : fpjwc.getAvailableFacets() + .entrySet()) { + final IProjectFacet f = entry.getKey(); + final SortedSet availableVersions = entry.getValue(); + + if (f.getCategory() == null && !availableVersions.isEmpty()) { + list.add(f); + } + } + + return list.toArray(); + } + + public Object[] getChildren(final Object parent) { + return new Object[0]; + } + + public Object getParent(final Object element) { + if (element instanceof IProjectFacet) { + final IProjectFacet f = (IProjectFacet) element; + return f.getCategory(); + } else { + return null; + } + } + + public boolean hasChildren(final Object element) { + return false; + } + + public void dispose() { + } + + public void inputChanged(final Viewer viewer, final Object oldObject, final Object newObject) { + } + } + + private final class FacetColumnLabelProvider extends LabelProvider { + @Override + public String getText(final Object element) { + return ((IProjectFacet) element).getLabel(); + } + + @Override + public Image getImage(final Object element) { + return FacetsSelectionPanel.this.getImage((IProjectFacet) element, true); + } + } + + private static final class FixedFacetImageDescriptor + + extends CompositeImageDescriptor + + { + private static final String OVERLAY_IMG_LOCATION = "images/lock.gif"; //$NON-NLS-1$ + + private static final ImageData OVERLAY = FacetUiPlugin.getImageDescriptor(OVERLAY_IMG_LOCATION).getImageData(); + + private final ImageData base; + private final Point size; + + public FixedFacetImageDescriptor(final ImageDescriptor base) { + this.base = base.getImageData(); + this.size = new Point(this.base.width, this.base.height); + } + + protected void drawCompositeImage(final int width, final int height) { + drawImage(this.base, 0, 0); + drawImage(OVERLAY, 0, height - OVERLAY.height); + } + + protected Point getSize() { + return this.size; + } + } + + private static final class Sorter extends ViewerSorter { + public int compare(final Viewer viewer, final Object a, final Object b) { + return getLabel(a).compareToIgnoreCase(getLabel(b)); + } + + private static String getLabel(final Object obj) { + return ((IProjectFacet) obj).getLabel(); + } + } + + private final class FacetToolTip extends HeaderToolTip { + public FacetToolTip(final Control control) { + super(control); + } + + @Override + protected final boolean shouldCreateToolTip(final Event event) { + if (getShowToolTips() == false) { + return false; + } + + final TableItem treeItem = getTreeItem(event.x, event.y); + String description = null; + + if (treeItem != null && treeItem.getBounds(0).contains(event.x, event.y)) { + final Object treeItemData = treeItem.getData(); + + if (treeItemData instanceof IProjectFacet) { + description = ((IProjectFacet) treeItemData).getDescription(); + } + } + + return (description != null && description.trim().length() > 0); + } + + @Override + protected String getToolTipTitle(final Event event) { + final IProjectFacet f = (IProjectFacet) getTreeItem(event.x, event.y).getData(); + return getSelectedVersion(f).toString(); + } + + @Override + protected Composite createContentArea(final Event event, final Composite parent) { + final Display display = parent.getDisplay(); + + final Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(gl(1)); + composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + final Label label = new Label(composite, SWT.WRAP); + label.setLayoutData(gdfill()); + label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + final IProjectFacet f = (IProjectFacet) getTreeItem(event.x, event.y).getData(); + label.setText(f.getDescription()); + + return composite; + } + } + + private final class FixedFacetToolTip extends BasicToolTip { + private static final int FAKE_EVENT_TYPE = -9999; + + public FixedFacetToolTip(final Control control) { + super(control); + setPopupDelay(0); + } + + public void show(final Point location) { + // The JFace ToolTip class does not support alternative methods of tool tip activation. + // An enhancement request https://bugs.eclipse.org/bugs/show_bug.cgi?id=174844 tracks + // this issue. When that enhancement request has been resolved, this hacky + // implementation should be replaced with something more sensible. + + final Event fakeEvent = new Event(); + fakeEvent.type = FAKE_EVENT_TYPE; + fakeEvent.x = location.x; + fakeEvent.y = location.y; + + try { + final Method method = ToolTip.class.getDeclaredMethod("toolTipCreate", Event.class); //$NON-NLS-1$ + + method.setAccessible(true); + method.invoke(this, fakeEvent); + } catch (Exception e) { + TMWCore.log(null, e); + } + } + + @Override + protected final boolean shouldCreateToolTip(final Event event) { + return (event.type == FAKE_EVENT_TYPE); + } + } + + private final class ProblemsContentProvider implements IStructuredContentProvider { + public Object[] getElements(final Object element) { + return getFilteredProblems(); + } + + public void inputChanged(final Viewer viewer, final Object oldObject, final Object newObject) { + } + + public void dispose() { + } + } + + private final class ProblemsLabelProvider implements ITableLabelProvider { + public String getColumnText(final Object element, final int column) { + return ((IStatus) element).getMessage(); + } + + public Image getColumnImage(final Object element, final int column) { + final ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); + final String imageType; + + if (((IStatus) element).getSeverity() == IStatus.ERROR) { + imageType = ISharedImages.IMG_OBJS_ERROR_TSK; + } else { + imageType = ISharedImages.IMG_OBJS_WARN_TSK; + } + + return sharedImages.getImage(imageType); + } + + public boolean isLabelProperty(final Object obj, final String s) { + return false; + } + + public void dispose() { + } + + public void addListener(final ILabelProviderListener listener) { + } + + public void removeListener(ILabelProviderListener listener) { + } + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationDetailsWizardPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationDetailsWizardPage.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,290 @@ +package org.symbian.tools.tmw.internal.ui.wizard; + +import java.io.File; +import java.net.URI; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +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.databinding.viewers.IViewerObservableValue; +import org.eclipse.jface.databinding.viewers.ViewersObservables; +import org.eclipse.jface.databinding.wizard.WizardPageSupport; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; +import org.eclipse.ui.internal.ide.IIDEHelpContextIds; +import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea; +import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.ui.TMWCoreUI; + +@SuppressWarnings("restriction") +public final class NewApplicationDetailsWizardPage extends WizardPage { + public static final class ProjectNameValidator implements IValidator { + + public IStatus validate(Object value) { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + String projectFieldContents = (String) value; + IStatus nameStatus = workspace.validateName(projectFieldContents, IResource.PROJECT); + if (!nameStatus.isOK()) { + return nameStatus; + } + + IProject handle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectFieldContents); + if (handle.exists()) { + return new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, + IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage); + } + return Status.OK_STATUS; + } + + } + + private ProjectContentsLocationArea locationArea; + private final DataBindingContext bindingContext; + private final WizardContext context; + + public NewApplicationDetailsWizardPage(WizardContext context, DataBindingContext bindingContext) { + super("WRTApp"); + setImageDescriptor(null); + setTitle("Application Details"); + setDescription("Specify application details"); + this.context = context; + this.bindingContext = bindingContext; + } + + public void createControl(Composite parent) { + Composite root = new Composite(parent, SWT.NONE); + + initializeDialogUnits(parent); + + PlatformUI.getWorkbench().getHelpSystem().setHelp(root, IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE); + + WizardPageSupport.create(this, bindingContext); + root.setLayout(new GridLayout(2, false)); + createProjectNameGroup(root); + + context.createLabel(root, ""); + context.createLabel(root, ""); + + context.createLabel(root, "Mobile Runtime:"); + + ComboViewer viewer = new ComboViewer(root); + viewer.setContentProvider(new ArrayContentProvider()); + viewer.setLabelProvider(new LabelProvider() { + @Override + public String getText(Object element) { + return ((IMobileWebRuntime) element).getName(); + } + }); + viewer.setInput(TMWCore.getRuntimesManager().getAllRuntimes()); + + final IViewerObservableValue observeSelection = ViewersObservables.observeSingleSelection(viewer); + final IObservableValue observableValue = BeansObservables.observeValue(context, WizardContext.RUNTIME); + bindingContext.bindValue(observeSelection, observableValue); + + context.createLabel(root, ""); + context.createLabel(root, ""); + context.createLabel(root, "Application identifier:"); + + context.createText(root, WizardContext.WIDGET_ID, "applicatoin identifier", bindingContext, null, + new RegexpValidator("[\\w]*(\\.\\w[\\w]*)*", "{0} is not a valid applicatoin ID", true)); + context.createLabel(root, ""); + context.createLabel(root, "This id should be unique for successful installation of application on the device"); + + context.createLabel(root, ""); + context.createLabel(root, ""); + + context.createLabel(root, "Application name:"); + + context.createText(root, WizardContext.WIDGET_NAME, "application name", bindingContext, null, + new RegexpValidator("[^\\w\\. ]", "Application name cannot contain {0} character", false)); + + context.createLabel(root, ""); + context.createLabel(root, "This will be the application display name on the device"); + + Composite composite = new Composite(root, SWT.NONE); + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 0; + composite.setLayout(gridLayout); + composite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true, 2, 1)); + + locationArea = new ProjectContentsLocationArea(getErrorReporter(), composite); + if (context.getProjectName() != null && context.getProjectName().trim().length() > 0) { + locationArea.updateProjectName(context.getProjectName()); + } + + // Scale the button based on the rest of the dialog + setButtonLayoutData(locationArea.getBrowseButton()); + + setPageComplete(validatePage()); + // Show description on opening + setErrorMessage(null); + setMessage(null); + setControl(root); + Dialog.applyDialogFont(root); + } + + /** + * Creates the project name specification controls. + * + * @param parent + * the parent composite + */ + private final void createProjectNameGroup(Composite parent) { + // new project label + Label projectLabel = new Label(parent, SWT.NONE); + projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel); + projectLabel.setFont(parent.getFont()); + + Text projectNameField = context.createText(parent, WizardContext.PROJECT_NAME, "project name", bindingContext, + null, new ProjectNameValidator()); + + projectNameField.setFont(parent.getFont()); + + projectNameField.addListener(SWT.Modify, nameModifyListener); + } + + /** + * Returns the current project location path as entered by the user, or its + * anticipated initial value. Note that if the default has been returned the + * path in a project description used to create a project should not be set. + * + * @return the project location path or its anticipated initial value. + */ + public IPath getLocationPath() { + return locationArea.isDefault() ? null : new Path(locationArea.getProjectLocation()); + } + + /** + * /** Returns the current project location URI as entered by the user, or + * null if a valid project location has not been entered. + * + * @return the project location URI, or null + * @since 3.2 + */ + public URI getLocationURI() { + return locationArea.getProjectLocationURI(); + } + + private final Listener nameModifyListener = new Listener() { + public void handleEvent(Event e) { + if (isPageComplete()) { + setLocationForSelection(); + boolean valid = validatePage(); + setPageComplete(valid); + } + } + }; + + /** + * Get an error reporter for the receiver. + * + * @return IErrorMessageReporter + */ + private IErrorMessageReporter getErrorReporter() { + return new IErrorMessageReporter() { + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea + * .IErrorMessageReporter#reportError(java.lang.String) + */ + public void reportError(String errorMessage, boolean infoOnly) { + if (infoOnly) { + setMessage(errorMessage, IStatus.INFO); + setErrorMessage(null); + } else { + setErrorMessage(errorMessage); + } + boolean valid = errorMessage == null; + if (valid) { + valid = validatePage(); + } + + setPageComplete(valid); + } + }; + } + + /** + * Set the location to the default location if we are set to useDefaults. + */ + void setLocationForSelection() { + locationArea.updateProjectName(context.getProjectName()); + } + + /** + * Returns whether this page's controls currently all contain valid values. + * + * @return true if all controls are valid, and + * false if at least one is invalid + */ + protected boolean validatePage() { + if (isPageComplete() || context.getProjectName().trim().length() == 0) { + return false; + } + String projectName = context.getProjectName(); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + locationArea.setExistingProject(project); + + String validLocationMessage = locationArea.checkValidLocation(); + if (validLocationMessage != null) { // there is no destination location + // given + setErrorMessage(validLocationMessage); + return false; + } + File file = new File(locationArea.getProjectLocationURI()); + if (file.isFile()) { + setErrorMessage(String.format("%s is an existing file", file)); + return false; + } else if (file.isDirectory() && file.listFiles().length > 0) { + setErrorMessage(String.format("%s is a non-empty folder", file)); + return false; + } + + setErrorMessage(null); + setMessage(null); + return true; + } + + /** + * Returns the useDefaults. + * + * @return boolean + */ + public boolean useDefaults() { + return locationArea.isDefault(); + } + + @Override + public void setVisible(boolean visible) { + // TODO Auto-generated method stub + super.setVisible(visible); + setErrorMessage(null); + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationTemplateWizardPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationTemplateWizardPage.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,163 @@ +package org.symbian.tools.tmw.internal.ui.wizard; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.UpdateValueStrategy; +import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.databinding.viewers.IViewerObservableValue; +import org.eclipse.jface.databinding.viewers.ViewersObservables; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Text; +import org.symbian.tools.tmw.ui.project.IProjectTemplate; + +public class NewApplicationTemplateWizardPage extends WizardPage { + public class ProjectTemplateLabelProvider extends LabelProvider { + + @Override + public Image getImage(Object element) { + return ((IProjectTemplate) element).getIcon(); + } + + @Override + public String getText(Object element) { + return ((IProjectTemplate) element).getName(); + } + } + + private TableViewer templates; + private Text description; + private final WizardContext context; + private final DataBindingContext bindingContext; + + public NewApplicationTemplateWizardPage(WizardContext context, DataBindingContext bindingContext) { + super("Create a New Mobile Web Application"); + setTitle("Create a New Mobile Web Application"); + this.context = context; + this.bindingContext = bindingContext; + setDescription("Select project name and template that will be used to populate"); + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); + FormLayout layout = new FormLayout(); + layout.marginWidth = 5; + composite.setLayout(layout); + + templates = new TableViewer(composite, SWT.BORDER | SWT.SINGLE); + FormData templatesData = new FormData(); + templatesData.top = new FormAttachment(0, 0); + templatesData.left = new FormAttachment(0, 0); + templatesData.right = new FormAttachment(40, -2); + templatesData.bottom = new FormAttachment(100, -8); + templates.getControl().setLayoutData(templatesData); + templates.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + final IProjectTemplate template = (IProjectTemplate) selection.getFirstElement(); + refreshSelection(template); + } + }); + templates.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent arg0) { + switchWizardPage(); + } + }); + + description = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); + FormData descriptionData = new FormData(); + descriptionData.top = new FormAttachment(0, 0); + descriptionData.bottom = new FormAttachment(100, -8); + descriptionData.left = new FormAttachment(templates.getControl(), 5); + descriptionData.right = new FormAttachment(100, 0); + descriptionData.width = 50; + description.setLayoutData(descriptionData); + + templates.setContentProvider(new ArrayContentProvider()); + templates.setLabelProvider(new ProjectTemplateLabelProvider()); + templates.setSorter(new ViewerSorter() { + @Override + public int category(Object element) { + return Integer.valueOf(((IProjectTemplate) element).getWeight()); + } + }); + setPageComplete(false); + + IObservableValue input = ViewersObservables.observeInput(templates); + IObservableValue templ = BeansObservables.observeValue(context, WizardContext.TEMPLATES); + bindingContext.bindValue(input, templ, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), + new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE)); + + IViewerObservableValue selection = ViewersObservables.observeSingleSelection(templates); + IObservableValue property = BeansObservables.observeValue(context, WizardContext.TEMPLATE); + + bindingContext.bindValue(selection, property); + if (context.getTemplate() != null) { + refreshSelection(context.getTemplate()); + } + setErrorMessage(null); + setControl(composite); + } + + protected void switchWizardPage() { + Display display = getShell().getDisplay(); + display.asyncExec(new Runnable() { + public void run() { + if (isPageComplete()) { + IWizardPage nextPage = getWizard().getNextPage(NewApplicationTemplateWizardPage.this); + getContainer().showPage(nextPage); + } + } + }); + } + + protected void refreshSelection(IProjectTemplate template) { + if (template != null) { + description.setText(template.getDescription()); + } else { + description.setText(""); + } + validatePage(); + } + + protected boolean validatePage() { + if (templates.getSelection().isEmpty()) { + setErrorMessage("Project template is not selected"); + setPageComplete(false); + return false; + } else { + setErrorMessage(null); + setPageComplete(true); + return true; + } + } + + public IProjectTemplate getSelectedProjectTemplate() { + IStructuredSelection selection = (IStructuredSelection) templates.getSelection(); + return (IProjectTemplate) selection.getFirstElement(); + } + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + templates.getControl().setFocus(); + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,150 @@ +/** + * 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.ui.wizard; + +import java.util.Collections; +import java.util.Set; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; +import org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IFProjSupport; + +/** + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public final class NewApplicationWizard extends ModifyFacetedProjectWizard implements INewWizard { + private final DataBindingContext databindingContext = new DataBindingContext(); + private NewApplicationDetailsWizardPage firstPage; + private IStructuredSelection selection; + private final WizardContext wizardContext = new WizardContext(); + private IWorkbench workbench; + private FacetsSelectionPage facetsPage; + private NewApplicationTemplateWizardPage templatesPage; + + public NewApplicationWizard() { + setShowFacetsSelectionPage(false); + } + + public void addPages() { + this.firstPage = createFirstPage(); + addPage(this.firstPage); + final IFacetedProject project = getFacetedProject(); + final Set facets; + if (project == null) { + facets = Collections.emptySet(); + } else { + facets = project.getProjectFacets(); + } + facetsPage = new FacetsSelectionPage(facets, getFacetedProjectWorkingCopy()); + addPage(facetsPage); + templatesPage = new NewApplicationTemplateWizardPage(wizardContext, databindingContext); + addPage(templatesPage); + super.addPages(); + } + + public boolean canFinish() { + return this.firstPage.isPageComplete() && super.canFinish(); + } + + protected NewApplicationDetailsWizardPage createFirstPage() { + firstPage = new NewApplicationDetailsWizardPage(wizardContext, databindingContext); + return firstPage; + } + + @Override + public IWizardPage getNextPage(final IWizardPage page) { + if (page == this.firstPage) { + final IFacetedProjectWorkingCopy fpjwc = getFacetedProjectWorkingCopy(); + fpjwc.setProjectName(getProjectName()); + fpjwc.setProjectLocation(getProjectLocation()); + final IFProjSupport fprojSupport = TMWCore.getFProjSupport(); + IRuntime runtime = fprojSupport.getRuntime(wizardContext.getRuntime()); + fpjwc.setTargetedRuntimes(Collections.singleton(runtime)); + fpjwc.setPrimaryRuntime(runtime); + fpjwc.setProjectFacets(fprojSupport.getFixedFacetsVersions(wizardContext.getRuntime())); + fpjwc.setFixedProjectFacets(fprojSupport.getFixedFacets(wizardContext.getRuntime())); + fpjwc.setProjectFacetActionConfig(fprojSupport.getTMWFacet(), wizardContext); + } + + IWizardPage nextPage = super.getNextPage(page); + return nextPage; + } + + public IWizardPage[] getPages() { + final IWizardPage[] base = super.getPages(); + final IWizardPage[] pages = new IWizardPage[base.length + 3]; + + pages[0] = this.firstPage; + pages[1] = this.templatesPage; + pages[2] = this.facetsPage; + System.arraycopy(base, 0, pages, 2, base.length); + + return pages; + } + + protected IPath getProjectLocation() { + return firstPage.getLocationPath(); + } + + protected String getProjectName() { + return wizardContext.getProjectName(); + } + + /** + * Returns the selection that this wizard was launched from. + * + * @return the selection that this wizard was launched from + * @since 1.4 + */ + + public IStructuredSelection getSelection() { + return this.selection; + } + + /** + * Returns the workbench that this wizard belongs to. + * + * @return the workbench that this wizard belongs to + * @since 1.4 + */ + + public IWorkbench getWorkbench() { + return this.workbench; + } + + public void init(final IWorkbench workbench, final IStructuredSelection selection) { + this.workbench = workbench; + this.selection = selection; + } + + public boolean performFinish() { + super.performFinish(); + return true; + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NonEmptyStringValidator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NonEmptyStringValidator.java Fri Aug 13 16:28:00 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.internal.ui.wizard; + +import java.text.MessageFormat; + +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.symbian.tools.tmw.ui.TMWCoreUI; + +public class NonEmptyStringValidator implements IValidator { + private final String propertyName; + private final AbstractDataBindingPage page; + + public NonEmptyStringValidator(String propertyName, AbstractDataBindingPage page) { + this.propertyName = propertyName; + this.page = page; + } + + public IStatus validate(Object value) { + if (page != null && page.isActive()) { + if (value == null || value.toString().trim().length() == 0) { + return new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, + MessageFormat.format("Field {0} is empty", + propertyName)); + } + } + return Status.OK_STATUS; + } +} \ No newline at end of file diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/RegexpValidator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/RegexpValidator.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,36 @@ +package org.symbian.tools.tmw.internal.ui.wizard; + +import java.text.MessageFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.symbian.tools.tmw.ui.TMWCoreUI; + +public class RegexpValidator implements IValidator { + private final String errorMessage; + private final Pattern pattern; + private final boolean match; + + public RegexpValidator(String pattern, String errorMessage, boolean match) { + this.errorMessage = errorMessage; + this.match = match; + this.pattern = Pattern.compile(pattern); + } + + public IStatus validate(Object value) { + String string = value.toString(); + Matcher matcher = pattern.matcher(string); + if (match && !matcher.matches()) { + return new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, MessageFormat.format(errorMessage, string)); + } else if (!match && matcher.find()) { + return new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, MessageFormat.format(errorMessage, + string.substring(matcher.start(), matcher.end()))); + } else { + return Status.OK_STATUS; + } + } + +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/WizardContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/WizardContext.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,407 @@ +package org.symbian.tools.tmw.internal.ui.wizard; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.UpdateValueStrategy; +import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.observable.Observables; +import org.eclipse.core.databinding.observable.map.IObservableMap; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.databinding.swt.ISWTObservableValue; +import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.internal.util.Util; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.project.IProjectTemplate; +import org.symbian.tools.tmw.ui.project.IProjectTemplateContext; + +public class WizardContext implements IProjectTemplateContext { + // public static final String CSS_FILE = "cssFile"; + // public static final String HTML_FILE = "htmlFile"; + // public static final String JS_FILE = "jsFile"; + public static final String TEMPLATE = "template"; + public static final String WIDGET_ID = "widgetId"; + public static final String WIDGET_NAME = "widgetName"; + // public static final String HOME_SCREEN = "homeScreen"; + public static final String RUNTIME = "runtime"; + // public static final String LIBRARIES = "libraries"; + public static final String PROJECT_NAME = "projectName"; + public static final String TEMPLATES = "templates"; + + // private String cssFile; + private String projectName = ""; + // private String htmlFile; + // private String jsFile; + private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this); + private IProjectTemplate template = null; + private String widgetId; + private String widgetName; + private Map extensions = new TreeMap(); + // private boolean homeScreen; + private IMobileWebRuntime runtime; + + // private Set libraries = new HashSet(); + + public WizardContext() { + IMobileWebRuntime[] runtimes = TMWCore.getRuntimesManager().getAllRuntimes(); + if (runtimes.length > 0) { + runtime = runtimes[0]; + } + } + + public void addPropertyChangeListener(PropertyChangeListener arg0) { + propertySupport.addPropertyChangeListener(arg0); + } + + public void addPropertyChangeListener(String arg0, PropertyChangeListener arg1) { + propertySupport.addPropertyChangeListener(arg0, arg1); + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + String prev = getProjectName(); + String prevId = getWidgetId(); + String prevName = getWidgetName(); + this.projectName = projectName; + propertySupport.firePropertyChange(PROJECT_NAME, getProjectName(), prev); + if (widgetName == null) { + propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prevName); + if (widgetId == null) { + propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prevId); + } + } + } + + // public String getCssFile() { + // if (cssFile == null) { + // if (template != null) { + // return template.getDefaultCssFile(); + // } + // } + // return cssFile; + // } + // + private String getDefaultWidgetId() { + String name = Util.removeSpaces(getWidgetName()); + return MessageFormat.format("com.company.{0}", name.length() > 0 ? name : "ApplicationName"); + } + + // + // public String getHtmlFile() { + // if (htmlFile == null) { + // if (template != null) { + // return template.getDefaultHtmlFile(); + // } + // } + // return htmlFile; + // } + // + // public String getJsFile() { + // if (jsFile == null) { + // if (template != null) { + // return template.getDefaultJsFile(); + // } + // } + // return jsFile; + // } + + public IProjectTemplate getTemplate() { + if (template == null) { + return getDefaultTemplate(getRuntime()); + } + return template; + } + + private IProjectTemplate getDefaultTemplate(IMobileWebRuntime runtime) { + return TMWCoreUI.getProjectTemplateManager().getDefaultTemplate(runtime); + } + + public String getWidgetId() { + if (widgetId == null) { + return getDefaultWidgetId(); + } + return widgetId; + } + + public String getWidgetName() { + return widgetName == null ? getProjectName() : widgetName; + } + + public void removePropertyChangeListener(PropertyChangeListener arg0) { + propertySupport.removePropertyChangeListener(arg0); + } + + public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) { + propertySupport.removePropertyChangeListener(arg0, arg1); + } + + // public void setCssFile(String cssFile) { + // if (template != null && template.getDefaultCssFile().equals(cssFile)) { + // cssFile = null; + // } + // String prev = this.cssFile; + // this.cssFile = cssFile; + // propertySupport.firePropertyChange(CSS_FILE, cssFile, prev); + // } + // + // public void setHtmlFile(String htmlFile) { + // if (template != null && template.getDefaultHtmlFile().equals(htmlFile)) { + // htmlFile = null; + // } + // String prev = this.htmlFile; + // this.htmlFile = htmlFile; + // propertySupport.firePropertyChange(HTML_FILE, htmlFile, prev); + // } + // + // public void setJsFile(String jsFile) { + // if (template != null && template.getDefaultJsFile().equals(jsFile)) { + // jsFile = null; + // } + // String prev = this.jsFile; + // this.jsFile = jsFile; + // propertySupport.firePropertyChange(JS_FILE, jsFile, prev); + // } + // + public void setTemplate(IProjectTemplate template) { + // String html = getHtmlFile(); + // String js = getJsFile(); + // String css = getCssFile(); + IProjectTemplate prev = this.template; + this.template = template; + propertySupport.firePropertyChange(TEMPLATE, template, prev); + // if (htmlFile == null) { + // propertySupport.firePropertyChange(HTML_FILE, getHtmlFile(), html); + // } + // if (jsFile == null) { + // propertySupport.firePropertyChange(JS_FILE, getJsFile(), js); + // } + // if (cssFile == null) { + // propertySupport.firePropertyChange(CSS_FILE, getCssFile(), css); + // } + // if (cssFile == null) { + // propertySupport.firePropertyChange(LIBRARIES, getLibraries(), libraries); + // } + } + + public void setWidgetId(String widgetId) { + String prev = getWidgetId(); + if (getDefaultWidgetId().equals(widgetId)) { + widgetId = null; + } + this.widgetId = widgetId; + propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prev); + } + + public void setWidgetName(String widgetName) { + String prevId = getWidgetId(); + String prev = getWidgetName(); + if (widgetName == getProjectName()) { + this.widgetName = null; + } else { + this.widgetName = widgetName; + } + propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prev); + if (widgetId == null) { + propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prevId); + } + } + + public void setExtensions(Map extensions) { + this.extensions = extensions; + } + + public Map getExtensions() { + return extensions; + } + + private Map getTemplateVars() { + Map vars = new TreeMap(); + + vars.put("widgetName", getWidgetName()); + vars.put("widgetId", getWidgetId()); + // vars.put("mainHtml", getHtmlFileName()); + // vars.put("mainCss", getCssFileName()); + // vars.put("mainJs", getJsFileName()); + // vars.put("homeScreen", String.valueOf(isHomeScreen())); + vars.putAll(extensions); + + return vars; + } + + // + // public boolean isHomeScreen() { + // return homeScreen; + // } + + // public void setHomeScreen(boolean homeScreen) { + // boolean old = homeScreen; + // this.homeScreen = homeScreen; + // propertySupport.firePropertyChange(HOME_SCREEN, old, homeScreen); + // } + + // public String getHtmlFileName() { + // return stripExtension(getHtmlFile(), "htm", "html"); + // } + // + // public String getJsFileName() { + // return stripExtension(getJsFile(), "js"); + // } + // + // public String getCssFileName() { + // return stripExtension(getCssFile(), "css"); + // } + + // private String stripExtension(String fileName, String... extensions) { + // for (String extension : extensions) { + // String extensionAndDot = "." + extension; + // if (fileName.endsWith(extensionAndDot)) { + // return fileName.substring(0, fileName.length() - extensionAndDot.length()); + // } + // } + // return fileName; + // } + + // public boolean isRequiredLibrary(JSLibrary element) { + // return template != null && template.requires(element); + // } + // + // public Set getLibraries() { + // final Set set = new HashSet(libraries); + // if (template != null) { + // set.addAll(Arrays.asList(template.getRequiredLibraries())); + // } + // return set; + // } + + // public void setLibraries(Set libraries) { + // Set prev = this.libraries; + // this.libraries = libraries; + // propertySupport.firePropertyChange(LIBRARIES, prev, libraries); + // } + + // public Map getLibraryParameters(JSLibrary library) { + // return Collections.emptyMap(); + // } + + protected Text createText(Composite root, String property, String propertyName, DataBindingContext bindingContext, + AbstractDataBindingPage page, IValidator... validators) { + return createText(root, BeansObservables.observeValue(this, property), propertyName, bindingContext, page, + validators); + } + + protected Text createTextForExt(Composite root, String property, String propertyName, + DataBindingContext bindingContext, AbstractDataBindingPage page) { + IObservableMap map = BeansObservables.observeMap(this, "extensions"); + IObservableValue entry = Observables.observeMapEntry(map, property, String.class); + return createText(root, entry, propertyName, bindingContext, page); + } + + private Text createText(Composite root, IObservableValue model, String propertyName, + DataBindingContext bindingContext, AbstractDataBindingPage page, IValidator... validators) { + Text text = new Text(root, SWT.BORDER); + text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + ISWTObservableValue view = SWTObservables.observeText(text, SWT.Modify); + UpdateValueStrategy strategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE); + NonEmptyStringValidator validator = new NonEmptyStringValidator(propertyName, page); + strategy.setBeforeSetValidator(validators.length == 0 ? validator + : new CompoundValidator(validator, validators)); + bindingContext.bindValue(view, model, strategy, null); + return text; + } + + protected void createLabel(Composite root, String text) { + Label label = new Label(root, SWT.NONE); + label.setText(text); + } + + public void setRuntime(IMobileWebRuntime runtime) { + final IProjectTemplate[] prevTemplates = getTemplates(); + final IProjectTemplate prevTemplate; + if (template == null) { + prevTemplate = getTemplate(); + } else { + prevTemplate = null; + } + final IMobileWebRuntime prev = this.runtime; + this.runtime = runtime; + propertySupport.firePropertyChange(RUNTIME, prev, runtime); + propertySupport.firePropertyChange(TEMPLATES, prevTemplates, getTemplates()); + if (prevTemplate == null) { + propertySupport.firePropertyChange(TEMPLATE, prevTemplate, getTemplate()); + } + } + + public IMobileWebRuntime getRuntime() { + return runtime; + } + + public IProjectTemplate[] getTemplates() { + return TMWCoreUI.getProjectTemplateManager().getProjectTemplates(getRuntime()); + } + + public void initialize(IProject project, IProgressMonitor monitor) { + final IProjectTemplate template = getTemplate(); + if (template != null) { + template.init(project, this, monitor); + } + } + + public Object getParameter(String parameter) { + return getTemplateVars().get(parameter); + } + + public String[] getParameterNames() { + Set keys = getTemplateVars().keySet(); + return keys.toArray(new String[keys.size()]); + } + + public void putParameter(String key, Object value) { + if (value instanceof String) { + extensions.put(key, (String) value); + } + } + + public void addFile(IProject project, IPath name, InputStream contents, IProgressMonitor monitor) + throws CoreException { + monitor.beginTask(name.toOSString(), 100); + final IFile file = project.getFile(name); + if (!file.exists()) { + create(file.getParent()); + } + file.create(contents, false, new SubProgressMonitor(monitor, 100)); + monitor.done(); + } + + private void create(IContainer parent) throws CoreException { + if (!parent.exists() && parent instanceof IFolder) { + create(parent.getParent()); + ((IFolder) parent).create(false, true, new NullProgressMonitor()); + } + } +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/util/Util.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/util/Util.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,27 @@ +/** + * 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.util; + +public class Util { + + public static String removeSpaces(String value) { + return value != null ? value.trim().replace(" ", "") : ""; + } + +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java Fri Aug 13 16:28:00 2010 -0700 @@ -10,8 +10,10 @@ 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; +import org.symbian.tools.tmw.internal.ui.deployment.DeploymentTargetPresentationsManager; +import org.symbian.tools.tmw.internal.ui.deployment.DeploymentTargetTypesRegistry; +import org.symbian.tools.tmw.internal.ui.project.ProjectTemplateManagerImpl; +import org.symbian.tools.tmw.ui.project.IProjectTemplateManager; /** * The activator class controls the plug-in life cycle @@ -25,33 +27,21 @@ // The shared instance private static TMWCoreUI plugin; + private IProjectTemplateManager projectTemplateManager; 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); + projectTemplateManager = new ProjectTemplateManagerImpl(); 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); @@ -105,4 +95,8 @@ public DeploymentTargetPresentationsManager getPresentations() { return presentations; } + + public static IProjectTemplateManager getProjectTemplateManager() { + return getDefault().projectTemplateManager; + } } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/UIUtils.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/UIUtils.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/UIUtils.java Fri Aug 13 16:28:00 2010 -0700 @@ -47,7 +47,7 @@ } if (resource != null) { IProject project = resource.getProject(); - return TMWCore.getDefault().create(project); + return TMWCore.create(project); } return null; } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/DeployWizard.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/DeployWizard.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/DeployWizard.java Fri Aug 13 16:28:00 2010 -0700 @@ -32,11 +32,11 @@ 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.internal.ui.deployment.DeployWizardContext; +import org.symbian.tools.tmw.internal.ui.deployment.DeploymentTargetWizardPage; +import org.symbian.tools.tmw.internal.ui.deployment.DeploymentTargetWrapper; +import org.symbian.tools.tmw.ui.ProjectMemo; import org.symbian.tools.tmw.ui.TMWCoreUI; -import org.symbian.tools.tmw.ui.ProjectMemo; public final class DeployWizard extends Wizard { private final DeployWizardContext context; @@ -94,7 +94,7 @@ private IStatus doDeploy(DeploymentTargetWrapper target, IMTWProject project, IProgressMonitor monitor) { IStatus status; try { - IPackager packager = TMWCore.getDefault().getRuntimesManager().getPackager(project); + IPackager packager = TMWCore.getRuntimesManager().getPackager(project); status = target.deploy(project, packager, monitor); } catch (CoreException e) { status = e.getStatus(); diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/navigator/PackagingInformationDecorator.java --- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/navigator/PackagingInformationDecorator.java Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/navigator/PackagingInformationDecorator.java Fri Aug 13 16:28:00 2010 -0700 @@ -38,9 +38,9 @@ resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class); } if (resource != null && resource.isAccessible()) { - IMTWProject project = TMWCore.getDefault().create(resource.getProject()); + IMTWProject project = TMWCore.create(resource.getProject()); if (project != null) { - IPackager packager = TMWCore.getDefault().getRuntimesManager().getPackager(project); + IPackager packager = TMWCore.getRuntimesManager().getPackager(project); if (packager.getPathInPackage(resource) != null) { decoration.addOverlay(TMWCoreUI.getImages().getExcludedIconDescriptor(), IDecoration.TOP_RIGHT); } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/IProjectTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/IProjectTemplate.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,85 @@ +/** + * 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.project; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +/** + * This interface will allow extending new mobile web application wizard + * with "smart" templates that have complex logic. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IProjectTemplate { + /** + * Attributes that are common for different templates for different + * runtimes. They are included here to improve compatibility and reuse. + */ + public interface CommonKeys { + String application_id = "widgetName"; + String application_name = "widgetId"; + String project_name = "projectName"; + String main_html = "mainHtml"; + String main_css = "mainCss"; + String main_js = "mainJs"; + } + + /** + * @return template "weight" that determines how high the template will + * be in a templates list. This is purely for visualization as IDE vendors + * might want more basic templates higher in the list to improve the + * learning curve. + */ + int getWeight(); + + /** + * @return icon that will be used in the UI to represent the template + */ + Image getIcon(); + + /** + * @return template name. It is only used in the UI and is not stored in + * project metadata. + */ + String getName(); + + /** + * @return template description that will be used in UI + */ + String getDescription(); + + /** + * @return array of the supported runtimes + */ + IMobileWebRuntime[] getSupportedRuntimes(); + + /** + * @return facets that should be enable so this project template works + */ + IProjectFacetVersion[] getRequiredFacets(); + + /** + * Initializes project with template contents + */ + void init(IProject project, IProjectTemplateContext context, IProgressMonitor monitor); +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/IProjectTemplateContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/IProjectTemplateContext.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,42 @@ +/** + * 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.project; + +import java.io.InputStream; + +import org.eclipse.core.resources.IProject; +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.IProjectSetupAction; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +/** + * Provides template values. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IProjectTemplateContext extends IProjectSetupAction { + IMobileWebRuntime getRuntime(); + Object getParameter(String parameter); + String[] getParameterNames(); + void putParameter(String key, Object value); + void addFile(IProject project, IPath name, InputStream contents, IProgressMonitor monitor) + throws CoreException; +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/IProjectTemplateManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/IProjectTemplateManager.java Fri Aug 13 16:28:00 2010 -0700 @@ -0,0 +1,27 @@ +/** + * 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.project; + +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +public interface IProjectTemplateManager { + IProjectTemplate[] getProjectTemplates(IMobileWebRuntime runtime); + IProjectTemplate getDefaultTemplate(IMobileWebRuntime runtime); + ITemplateInstaller getEmptyProjectTemplate(IMobileWebRuntime runtime); +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/ITemplateInstaller.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/project/ITemplateInstaller.java Fri Aug 13 16:28:00 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.ui.project; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; + +public interface ITemplateInstaller { + /** + * Prepare the installer to work on specified project using template context. + */ + void prepare(IProject project, IProjectTemplateContext context); + + /** + * Cleanup after processing the project. + */ + void cleanup(); + + /** + * Get list of files that will be created in the project. + */ + IPath[] getFiles() throws CoreException; + + /** + * Installer should only copy files specified. Keep in mind that some + * files may be overridden by other installers. + */ + void copyFiles(IPath[] files, IProgressMonitor monitor) throws CoreException; + +} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch --- a/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch Fri Aug 13 16:28:00 2010 -0700 @@ -22,8 +22,8 @@ - - + + diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/plugin.xml --- a/org.symbian.tools.wrttools/plugin.xml Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.wrttools/plugin.xml Fri Aug 13 16:28:00 2010 -0700 @@ -825,18 +825,33 @@ id="org.symbian.tools.wrttools.wrt" version="1.1"> - + file="libraries/core/widget.js"/> + - - - + file="libraries/core/menu.js"/> + + + diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/Contribution1.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/Contribution1.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +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.wrttools.builder; - -import org.eclipse.ui.menus.ExtensionContributionFactory; -import org.eclipse.ui.menus.IContributionRoot; -import org.eclipse.ui.services.IServiceLocator; - -public class Contribution1 extends ExtensionContributionFactory { - - public Contribution1() { - // TODO Auto-generated constructor stub - } - - @Override - public void createContributionItems(IServiceLocator serviceLocator, - IContributionRoot additions) { - // TODO Auto-generated method stub - - } - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoriteItemType.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoriteItemType.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +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.wrttools.builder; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; - -public abstract class FavoriteItemType implements Comparable { - private static final ISharedImages PLATFORM_IMAGES = PlatformUI.getWorkbench().getSharedImages(); - private final String id; - private final String printName; - private final int ordinal; - - private FavoriteItemType (String id, String name, int position) { - this.id = id; - this.ordinal = position; - this.printName = name; - } - - public String getId() { - return id; - } - - public String getName() { - return printName; - } - - public static final FavoriteItemType UNKNOWN = - new FavoriteItemType("Unknown", "Unknown", 0) { - public Image getImage() { - return null; - } - public IFavoriteItem newFavorite(Object obj) { - return null; - } - public IFavoriteItem loadFavorite(String info) { - return null; - } - public int compareTo(Object o) { - // TODO Auto-generated method stub - return 0; - } - }; - - public static final FavoriteItemType WORKBENCH_FILE = - new FavoriteItemType("WBFile", "Workbench File", 1) { - public Image getImage() { - return PLATFORM_IMAGES.getImage(org.eclipse.ui.ISharedImages.IMG_OBJ_FILE); - } - public IFavoriteItem newFavorite(Object obj) { - if (!(obj instanceof IFile)) - return null; - return new FavoriteResource(this, (IFile) obj); - } - public IFavoriteItem loadFavorite(String info) { - return FavoriteResource.loadFavorite(this, info); - } - public int compareTo(Object o) { - // TODO Auto-generated method stub - return 0; - } - }; - - public static final FavoriteItemType WORKBENCH_FOLDER = - new FavoriteItemType("WBFolder", "Workbench Folder", 2) { - public Image getImage() { - return PLATFORM_IMAGES.getImage(org.eclipse.ui.ISharedImages.IMG_OBJ_FOLDER); - } - public IFavoriteItem newFavorite(Object obj) { - if (!(obj instanceof IFolder)) - return null; - return new FavoriteResource(this, (IFolder) obj); - } - public IFavoriteItem loadFavorite(String info) { - return FavoriteResource.loadFavorite(this, info); - } - public int compareTo(Object o) { - // TODO Auto-generated method stub - return 0; - } - }; - static final FavoriteItemType WORKBENCH_PROJECT = null; - static final FavoriteItemType JAVA_PACKAGE_ROOT = null; - static final FavoriteItemType JAVA_PROJECT = null; - static final FavoriteItemType JAVA_PACKAGE = null; - static final FavoriteItemType JAVA_COMP_UNIT = null; - static final FavoriteItemType JAVA_INTERFACE = null; - static final FavoriteItemType JAVA_CLASS = null; - static final FavoriteItemType JAVA_CLASS_FILE = null; - - private static final FavoriteItemType[] TYPES = { - UNKNOWN, WORKBENCH_FILE, WORKBENCH_FOLDER, WORKBENCH_PROJECT, - JAVA_PROJECT, JAVA_PACKAGE_ROOT, JAVA_PACKAGE, - JAVA_CLASS_FILE, JAVA_COMP_UNIT, JAVA_INTERFACE, JAVA_CLASS}; - - public static FavoriteItemType[] getTypes() { - return TYPES; - } - - public abstract Image getImage(); - public abstract IFavoriteItem newFavorite(Object obj); - public abstract IFavoriteItem loadFavorite(String info); - - public int compareTo(FavoriteItemType other) { - return this.ordinal - other.ordinal; - } -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoriteResource.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoriteResource.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +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.wrttools.builder; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; - -public class FavoriteResource implements IFavoriteItem { - - public FavoriteResource(FavoriteItemType favoriteItemType, IFile obj) { - // TODO Auto-generated constructor stub - } - - public FavoriteResource(FavoriteItemType favoriteItemType, IFolder obj) { - // TODO Auto-generated constructor stub - } - - public FavoriteResource(FavoriteItemType workbenchProject, IProject iProject) { - // TODO Auto-generated constructor stub - } - - public String getInfo() { - // TODO Auto-generated method stub - return null; - } - - public String getLocation() { - // TODO Auto-generated method stub - return null; - } - - public String getName() { - // TODO Auto-generated method stub - return null; - } - - public FavoriteItemType getType() { - // TODO Auto-generated method stub - return null; - } - - public boolean isFavoriteFor(Object obj) { - // TODO Auto-generated method stub - return false; - } - - public void setName(String newName) { - // TODO Auto-generated method stub - - } - - public Object getAdapter(Class adapter) { - // TODO Auto-generated method stub - return null; - } - - public static IFavoriteItem loadFavorite(FavoriteItemType favoriteItemType, - String info) { - // TODO Auto-generated method stub - return null; - } - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoritesManager.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoritesManager.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +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.wrttools.builder; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.ResourcesPlugin; - -public class FavoritesManager implements IResourceChangeListener{ - - private static FavoritesManager manager; - private Collection favorites; - - private FavoritesManager() { - ResourcesPlugin.getWorkspace().addResourceChangeListener( - this, IResourceChangeEvent.POST_CHANGE); - } - - public static FavoritesManager getManager() { - if (manager == null) - manager = new FavoritesManager(); - return manager; - } - - public IFavoriteItem[] getFavorites() { - if (favorites == null) - loadFavorites(); - return favorites.toArray(new IFavoriteItem [favorites.size()]); - } - - private void loadFavorites() { - // temporary implementation - // to prepopulate list with projects - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - favorites = new Hashset(projects.length); - for (int i = 0; i < projects.length; i++) - favorites.add(new FavoriteResource( - FavoriteItemType.WORKBENCH_PROJECT, projects[i])); - } - - public void addFavorites(Object[] objects) { - if (objects == null) - return; - if (favorites == null) - loadFavorites(); - Collection items = new Hashset(objects.length); - for (int i = 0; i < objects.length; i++) { - IFavoriteItem item = existingFavoriteFor(objects[i]); - if (item == null) { - item = existingFavoriteFor(objects[i]); - if (item != null && favorites.add(item)); - items.add(item); - } - } - if (items.size() > 0) { - IFavoriteItem[] added = items.toArray(new IFavoriteItem[items.size()]); - fireFavoritesChanged(added, IFavoriteItem.NONE); - } - } - - public void removeFavorites(Object[] objects) { - if (objects == null) - return; - if (favorites == null) - loadFavorites(); - Collection items = new Hashset(objects.length); - for (int i = 0; i < objects.length; i++) { - IFavoriteItem item = existingFavoriteFor(objects[i]); - if (item != null && favorites.remove(item)) - items.add(item); - } - if (items.size() > 0) { - IFavoriteItem[] removed = items.toArray(new IFavoriteItem[items.size()]); - fireFavoritesChanged(IFavoriteItem.NONE, removed); - } - - } - - public IFavoriteItem newFavoriteFor(Object obj) { - FavoriteItemType[] types = FavoriteItemType.getTypes(); - for (int i = 0; i < types.length; i++) { - IFavoriteItem item = types[i].newFavorite(obj); - if (item != null) - return item; - } - return null; - } - -/* - private void fireFavoritesChanged(IFavoriteItem[] added, - - IFavoriteItem[] none) { - // TODO Auto-generated method stub - - } -*/ - - private IFavoriteItem existingFavoriteFor(Object obj) { - // TODO Auto-generated method stub - if (obj == null) - return null; - if (obj instanceof IFavoriteItem) - return (IFavoriteItem) obj; - Iterator iter = favorites.iterator(); - while (iter.hasNext()) { - IFavoriteItem item = (IFavoriteItem) iter.next(); - if (item.isFavoriteFor(obj)) - return item; - } - return null; - } - - public IFavoriteItem[] existingFavoritesFor(Iterator iter) { - ArrayList result = new ArrayList(10); - while (iter.next() != null) { - IFavoriteItem item = existingFavoriteFor(iter.next()); - if (item != null) - result.add(item); - } - return (IFavoriteItem[]) result.toArray(new IFavoriteItem[result.size()]); - } - - public static void shutdown() { - if (manager != null) { - ResourcesPlugin.getWorkspace().removeResourceChangeListener(manager); - manager = null; - } - } - - public void resourceChanged(IResourceChangeEvent e) { - // process events here - } - - private ArrayList listeners = new ArrayList(); - - public void addFavoritesManagerListener(FavoritesManagerListener listener) { - if (!listeners.contains(listener)) - listeners.add(listener); - } - - public void removeFavoritesManagerListener(FavoritesManagerListener listener) { - listeners.remove(listener); - } - - private void fireFavoritesChanged(IFavoriteItem[] itemsAdded, IFavoriteItem[] itemsRemoved) { - FavoritesManagerEvent event = new FavoritesManagerEvent(this, itemsAdded, itemsRemoved); - for (Iterator - iter = listeners.iterator(); - iter.hasNext();) - iter.next().favoritesChanged(event); - } - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoritesManagerEvent.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoritesManagerEvent.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +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.wrttools.builder; - -import java.util.EventObject; - -public class FavoritesManagerEvent extends EventObject { - - private static final long serialversionUID = 3697053173951102953L; - - private final IFavoriteItem[] added; - private final IFavoriteItem[] removed; - - public FavoritesManagerEvent(FavoritesManager source, - IFavoriteItem[] itemsAdded, - IFavoriteItem[] itemsRemoved) { - super(source); - added = itemsAdded; - removed = itemsRemoved; - - } - - public IFavoriteItem[] getItemsAdded() { - return added; - } - - public IFavoriteItem[] getItemsRemoved() { - return removed; - } -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoritesManagerListener.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/FavoritesManagerListener.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +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.wrttools.builder; - -public interface FavoritesManagerListener { - public void favoritesChanged(FavoritesManagerEvent event); -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/Hashset.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/Hashset.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +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.wrttools.builder; - -import java.util.Collection; -import java.util.Iterator; - -public class Hashset implements Collection { - - public Hashset(int length) { - // TODO Auto-generated constructor stub - } - - public boolean add(IFavoriteItem e) { - // TODO Auto-generated method stub - return false; - } - - public boolean addAll(Collection c) { - // TODO Auto-generated method stub - return false; - } - - public void clear() { - // TODO Auto-generated method stub - - } - - public boolean contains(Object o) { - // TODO Auto-generated method stub - return false; - } - - public boolean containsAll(Collection c) { - // TODO Auto-generated method stub - return false; - } - - public boolean isEmpty() { - // TODO Auto-generated method stub - return false; - } - - public Iterator iterator() { - // TODO Auto-generated method stub - return null; - } - - public boolean remove(Object o) { - // TODO Auto-generated method stub - return false; - } - - public boolean removeAll(Collection c) { - // TODO Auto-generated method stub - return false; - } - - public boolean retainAll(Collection c) { - // TODO Auto-generated method stub - return false; - } - - public int size() { - // TODO Auto-generated method stub - return 0; - } - - public Object[] toArray() { - // TODO Auto-generated method stub - return null; - } - - public T[] toArray(T[] a) { - // TODO Auto-generated method stub - return null; - } - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/IFavoriteItem.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/IFavoriteItem.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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.wrttools.builder; - -import org.eclipse.core.runtime.IAdaptable; - -public interface IFavoriteItem extends IAdaptable { - String getName(); - void setName(String newName); - String getLocation(); - boolean isFavoriteFor(Object obj); - FavoriteItemType getType(); - String getInfo(); - - static IFavoriteItem[] NONE = new IFavoriteItem[] {}; - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/IFavoritesManagerListener.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/IFavoritesManagerListener.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +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.wrttools.builder; - -public abstract class IFavoritesManagerListener { - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/MyResourceChangeReporter.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/MyResourceChangeReporter.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +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.wrttools.builder; - -//The implementation for POST_CHANGE uses another class that can be used -// to visit the changes in the resource delta. - - import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.runtime.CoreException; - - public class MyResourceChangeReporter implements IResourceChangeListener { - - // TODO Auto-generated method stub - public void resourceChanged(IResourceChangeEvent event) { - IResource res = event.getResource(); - switch (event.getType()) { - case IResourceChangeEvent.PRE_CLOSE: - System.out.print("Project "); - System.out.print(res.getFullPath()); - System.out.println(" is about to close."); - break; - case IResourceChangeEvent.PRE_DELETE: - System.out.print("Project "); - System.out.print(res.getFullPath()); - System.out.println(" is about to be deleted."); - break; - case IResourceChangeEvent.POST_CHANGE: - System.out.println("Resources have changed."); - try { - event.getDelta().accept(new DeltaPrinter()); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - break; - case IResourceChangeEvent.PRE_BUILD: - System.out.println("Build about to run."); - try { - event.getDelta().accept(new DeltaPrinter()); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - break; - case IResourceChangeEvent.POST_BUILD: - System.out.println("Build complete."); - try { - event.getDelta().accept(new DeltaPrinter()); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - break; - } - } - } - - //TODO The DeltaPrinter class implements the IResourceDeltaVisitor interface - // to interrogate the resource delta. The visit() method is called for - // each resource change in the resource delta. The visitor uses a return - // value to indicate whether deltas for child resources should be visited. - - class DeltaPrinter implements IResourceDeltaVisitor { - - public boolean visit(IResourceDelta delta) throws CoreException{ - IResource res = delta.getResource(); - switch (delta.getKind()) { - case IResourceDelta.ADDED: - System.out.print("Resource "); - System.out.print(res.getFullPath()); - System.out.println(" was added."); - break; - case IResourceDelta.REMOVED: - System.out.print("Resource "); - System.out.print(res.getFullPath()); - System.out.println(" was removed."); - break; - case IResourceDelta.CHANGED: - System.out.print("Resource "); - System.out.print(res.getFullPath()); - System.out.println(" has changed."); - int flags = delta.getFlags(); - if ((flags & IResourceDelta.CONTENT) != 0) { - System.out.println("--> Content Change"); - } - if ((flags & IResourceDelta.REPLACED) != 0) { - System.out.println("--> Content Replaced"); - } - if ((flags & IResourceDelta.MARKERS) != 0) { - System.out.println("--> Marker Change"); - IMarkerDelta[] markers = delta.getMarkerDeltas(); - // if interested in markers, check these deltas - } - - break; - } - return true; // visit the children - } - } - diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/PropertiesAuditorNature.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/PropertiesAuditorNature.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +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.wrttools.builder; - -import java.util.ArrayList; -import java.util.Arrays; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IProjectNature; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.swt.widgets.List; -import org.symbian.tools.wrttools.builder.PropertiesFileAuditor; - - -public class PropertiesAuditorNature implements IProjectNature { - - private IProject project; - private static final String NATURE_ID = "org.eclipse.wst.jsdt.core.jsNature"; - - public void configure() throws CoreException { - // TODO Auto-generated method stub - PropertiesFileAuditor.addBuilderToProject(project); - new Job("Properties File Audit") { - protected IStatus run(IProgressMonitor monitor) { - try { - project.build( - PropertiesFileAuditor.FULL_BUILD, - PropertiesFileAuditor.BUILDER_ID, - null, - monitor); - } - catch (CoreException e) { - // log the logError e - } - return Status.OK_STATUS; - } - }.schedule(); - - } - - public void deconfigure() throws CoreException { - // TODO Auto-generated method stub - PropertiesFileAuditor.removeBuilderFromProject(project); - PropertiesFileAuditor.deleteAuditMarkers(project); - } - - public IProject getProject() { - // TODO Auto-generated method stub - return project; - } - - public void setProject(IProject project) { - // TODO Auto-generated method stub - this.project = project; - - } - - public static void addNature(IProject project){ - // Cannot modify closed projects - if (!project.isOpen()) - return; - // Get the description - IProjectDescription description; - try { - description = project.getDescription(); - } - catch (CoreException e) { - // log the error - return; - } - // Determine if the project already has the nature - ArrayList newIds = new ArrayList(); - newIds.addAll(Arrays.asList(description.getNatureIds())); - int index = newIds.indexOf(NATURE_ID); - if (index != -1) - return; - - // Add the nature - newIds.add(NATURE_ID); - description.setNatureIds(newIds.toArray(new String[newIds.size()])); - - // save the description - try { - project.setDescription(description, null); - } - catch (CoreException e) { - // log the error - } - } - - public static boolean hasNature(IProject project) { - // TODO Auto-generated method stub - try { - return project.isOpen() && project.hasNature(NATURE_ID); - } - catch (CoreException e) { - // log the error - return false; - } - } - - public static void removeNature(IProject project) { - // Cannot modify closed projects - if (!project.isOpen()) - return; - - // Get the description - IProjectDescription description; - try { - description = project.getDescription(); - } - catch (CoreException e) { - // log the error - return; - } - - // Determine if the project has the nature - ArrayList newIds = new ArrayList(); - newIds.addAll(Arrays.asList(description.getNatureIds())); - int index = newIds.indexOf(NATURE_ID); - - if (index == -1) - return; - - // Remove the nature - newIds.remove(index); - description.setNatureIds(newIds.toArray( - new String[newIds.size()])); - - // save the description - try { - project.setDescription(description, null); - } - catch (CoreException e) { - // log the error - } - } -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/PropertiesFileAuditor.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/PropertiesFileAuditor.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,611 +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.wrttools.builder; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.core.resources.ICommand; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.symbian.tools.wrttools.Activator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; - - -public class PropertiesFileAuditor extends IncrementalProjectBuilder { - - private static final String MARKER_ID = Activator.PLUGIN_ID + ".auditmarker"; - - public PropertiesFileAuditor() { - // TODO Auto-generated constructor stub - } - - @Override - protected IProject[] build(int kind, Map args, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - if (shouldAudit(kind)) { - auditPluginManifest(monitor); - } - if (kind == IncrementalProjectBuilder.FULL_BUILD) { - System.out.println("PropertiesFileAuditor: Full build"); - fullBuild(monitor); - } else { - IResourceDelta delta = getDelta(getProject()); - if (delta == null) { - System.out.println("PropertiesFileAuditor: Full build - no changes"); - fullBuild(monitor); - } else { - System.out.println("PropertiesFileAuditor: Incremental build on " + delta); - incrementalBuild(delta, monitor); - } - } - return null; - } - - protected void clean(IProgressMonitor monitor) throws CoreException { - getProject().deleteMarkers(XML_MARKER_TYPE, - true, IResource.DEPTH_INFINITE); - getProject().deleteMarkers(JS_MARKER_TYPE, - true, IResource.DEPTH_INFINITE); - } - - protected void fullBuild(final IProgressMonitor monitor) throws CoreException { - try { - getProject().accept(new MyBuildVisitor()); - } catch (CoreException e) { } - } - - class MyBuildVisitor implements IResourceVisitor { - public boolean visit(IResource res) { - //build the specified resource. - checkXML(res); - checkJS(res); - //return true to continue visiting children. - return true; - } - } - - protected void incrementalBuild(IResourceDelta delta, - IProgressMonitor monitor) throws CoreException { - // the visitor does the work. - // delta.accept(new MyBuildDeltaVisitor()); - - System.out.println("incremental build on "+delta); - try { - delta.accept(new IResourceDeltaVisitor() { - public boolean visit(IResourceDelta delta) { - System.out.println("changed: "+ - delta.getResource().getRawLocation()); - return true; // visit children too - } - }); - } catch (CoreException e) { - e.printStackTrace(); - } - } - class MyBuildDeltaVisitor implements IResourceDeltaVisitor { - - public boolean visit(IResourceDelta delta) { - IResource resource = delta.getResource(); - switch (delta.getKind()) { - case IResourceDelta.ADDED : - // handle added resource - checkXML(resource); - checkJS(resource); - break; - case IResourceDelta.REMOVED : - // handle removed resource - break; - case IResourceDelta.CHANGED : - // handle changed resource - checkXML(resource); - checkJS(resource); - break; - } - // return true to continue visiting children - return true; - } - } - - class XMLErrorHandler extends DefaultHandler { - - private IFile file; - - public XMLErrorHandler(IFile file) { - this.file = file; - } - - private void addXMLMarker(SAXParseException e, int severity) { - PropertiesFileAuditor.this.addXMLMarker(file, e.getMessage(), e - .getLineNumber(), severity); - } - - public void error(SAXParseException exception) throws SAXException { - addXMLMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void fatalError(SAXParseException exception) throws SAXException { - addXMLMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void warning(SAXParseException exception) throws SAXException { - addXMLMarker(exception, IMarker.SEVERITY_WARNING); - } - } - -class JSErrorHandler extends DefaultHandler { - - private IFile file; - - public JSErrorHandler(IFile file) { - this.file = file; - } - - private void addJSMarker(SAXParseException e, int severity) { - PropertiesFileAuditor.this.addJSMarker(file, e.getMessage(), e - .getLineNumber(), severity); - } - - public void error(SAXParseException exception) throws SAXException { - addJSMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void fatalError(SAXParseException exception) throws SAXException { - addJSMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void warning(SAXParseException exception) throws SAXException { - addJSMarker(exception, IMarker.SEVERITY_WARNING); - } - } - - private static final String XML_MARKER_TYPE = "org.symbian.tools.wrt.xmlProblem"; - private static final String JS_MARKER_TYPE = "org.symbian.tools.wrt.jsProblem"; - - private SAXParserFactory parserFactory; - - private void addJSMarker(IFile file, String message, int lineNumber, - int severity) { - try { - IMarker marker = file.createMarker(JS_MARKER_TYPE); - marker.setAttribute(IMarker.MESSAGE, message); - marker.setAttribute(IMarker.SEVERITY, severity); - if (lineNumber == -1) { - lineNumber = 1; - } - marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); - } catch (CoreException e) { - } - } - - private void addXMLMarker(IFile file, String message, int lineNumber, - int severity) { - try { - IMarker marker = file.createMarker(XML_MARKER_TYPE); - marker.setAttribute(IMarker.MESSAGE, message); - marker.setAttribute(IMarker.SEVERITY, severity); - if (lineNumber == -1) { - lineNumber = 1; - } - marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); - } catch (CoreException e) { - } - } - void checkXML(IResource resource) { - if (resource instanceof IFile && resource.getName().endsWith(".xml")) { - IFile file = (IFile) resource; - deleteXMLMarkers(file); - XMLErrorHandler reporter = new XMLErrorHandler(file); - try { - getParser().parse(file.getContents(), reporter); - } catch (Exception e1) { - } - } - } - - void checkJS(IResource resource) { - if (resource instanceof IFile && resource.getName().endsWith(".js")) { - IFile file = (IFile) resource; - deleteJSMarkers(file); - JSErrorHandler reporter = new JSErrorHandler(file); - try { - getParser().parse(file.getContents(), reporter); - } catch (Exception e1) { - } - } - } - - private void deleteXMLMarkers(IFile file) { - try { - file.deleteMarkers(XML_MARKER_TYPE, false, IResource.DEPTH_ZERO); - } catch (CoreException ce) { - } - } - - private void deleteJSMarkers(IFile file) { - try { - file.deleteMarkers(JS_MARKER_TYPE, false, IResource.DEPTH_ZERO); - } catch (CoreException ce) { - } - } - - private SAXParser getParser() throws ParserConfigurationException, - SAXException { - if (parserFactory == null) { - parserFactory = SAXParserFactory.newInstance(); - } - return parserFactory.newSAXParser(); - } - -/* - //TODO: Implementing resource change listeners - //The listener checks for each event type and reports information - //about the resource that was changed and the kinds of changes that occurred. - IResourceChangeListener listener = new MyResourceChangeReporter(); - ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, - IResourceChangeEvent.PRE_CLOSE - | IResourceChangeEvent.PRE_DELETE - | IResourceChangeEvent.PRE_BUILD - | IResourceChangeEvent.POST_BUILD - | IResourceChangeEvent.POST_CHANGE); - -*/ - - private boolean shouldAudit(int kind) { - if (kind == FULL_BUILD) - return true; - - IResourceDelta delta = getDelta(getProject()); - if (delta == null) - return false; - IResourceDelta[] children = delta.getAffectedChildren(); - for (int i = 0; i < children.length; i++) { - IResourceDelta child = children[i]; - String fileName = child.getProjectRelativePath().lastSegment(); - if (fileName.equals("plugin.xml") || - fileName.equals("plugin.properties")) - return true; - } - return false; - } - - public static final int MISSING_KEY_VIOLATION = 1; - public static final int UNUSED_KEY_VIOLATION = 2; - - private void auditPluginManifest(IProgressMonitor monitor) { - monitor.beginTask("Audit plugin manifest", 4); - - // remove any old markers - if (!deleteAuditMarkers(getProject())) { - return; - } - if (checkCancel(monitor)) - return; - - IProject proj = getProject(); - - if (checkCancel (monitor)) - return; - Map pluginKeys = scanPlugin(getProject().getFile("plugin.xml")); - monitor.worked(1); - - if (checkCancel(monitor)) - return; - - Map propertyKeys = scanProperties(getProject().getFile("plugin.properties")); - monitor.worked(1); - - if (checkCancel(monitor)) - return; - - Iterator> iter = pluginKeys.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - if (!propertyKeys.containsKey(entry.getKey())) - reportProblem("Missing property key", - ((Location) entry.getValue()), - MISSING_KEY_VIOLATION, - true); - } - monitor.worked(1); - - if (checkCancel (monitor)) - return; - - iter = propertyKeys.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - if (!pluginKeys.containsKey(entry.getKey())) - reportProblem("Unused property key", - ((Location) entry.getValue()), - UNUSED_KEY_VIOLATION, - false); - } - monitor.done(); - } - - private boolean checkCancel(IProgressMonitor monitor) { - if (monitor.isCanceled()) { - // Discard build state if necessary - throw new OperationCanceledException(); - } - return false; - } - - private Map scanPlugin(IFile file) { - Map keys = new HashMap(); - String content = readFile(file); - int start = 0; - - while (true) { - start = content.indexOf("\"%", start); - if (start < 0) - break; - int end = content.indexOf('"', start + 2); - if (end < 0) - break; - Location loc = new Location(); - loc.file = file; - loc.key = content.substring(start + 2, end); - loc.charStart = start + 1; - loc.charEnd = end; - keys.put(loc.key, loc); - start = end + 1; - } - return keys; - } - - private Map scanProperties(IFile file) { - Map keys = new HashMap(); - String content = readFile(file); - int end = 0; - while (true) { - end = content.indexOf('=', end); - if (end < 0) - break; - int start = end - 1; - while (start >= 0) { - char ch = content.charAt(start); - if (ch == '\r' || ch == '\n') - break; - start --; - } - start++; - String found = content.substring(start, end).trim(); - if (found.length() == 0 || - found.charAt(0) == '#' || - found.indexOf('=') != -1) - continue; - Location loc = new Location(); - loc.file = file; - loc.key = found; - loc.charStart = start; - loc.charEnd = end; - keys.put(loc.key, loc); - end++; - } - return keys; - } - - private String readFile(IFile file) { - if (!file.exists()) - return ""; - InputStream stream = null; - try { - stream = file.getContents(); - Reader reader = new BufferedReader( - new InputStreamReader(stream)); - StringBuffer result = new StringBuffer(2048); - char[] buf = new char[2048]; - while (true) { - int count = reader.read(buf); - if (count < 0) - break; - result.append(buf, 0, count); - } - return result.toString(); - } - catch (Exception e) { - // log the logError - return ""; - } - finally { - try { - if (stream != null) - stream.close(); - } - catch (IOException e) { - // log the logError - return ""; - } - } - } - private class Location { - int charStart; - int charEnd; - IFile file; - String key; - } - private void reportProblem(String msg, Location loc, int violation, boolean isError) { - System.out.println((isError ? "ERROR: " : "WARNING: ") - + msg + " \"" - + loc.key + "\" in " - + loc.file.getFullPath()); - } - - public static boolean projectHasBuilder(IProject project) { - // Cannot modify closed projects - if (!project.isOpen()) - return false - ; - // get the description - IProjectDescription description; - - try { - description = project.getDescription(); - } catch (CoreException e) { - // Log the error - return false; - } - // Look for the builder - int index = -1; - ICommand[] cmds = description.getBuildSpec(); - for (int j = 0; j < cmds.length; j++) { - if (cmds[j].getBuilderName().equals(BUILDER_ID)) { - index = j; - break; - } - } - if (index == -1) - return false; - return true; // project has builder - } - - public static boolean hasBuilder(IProject project) { - // TODO Auto-generated method stub - try { - return project.isOpen() && projectHasBuilder(project); - } - catch (Exception e) { - // log the error - return false; - } - } - - public static final String BUILDER_ID = Activator.PLUGIN_ID + Activator.PLUGIN_ID + ".propertiesFileAuditor"; - - public static void addBuilderToProject(IProject project) { - // Cannot modify closed projects - if (!project.isOpen()) - return; - - // Get the description - IProjectDescription description; - try { - description = project.getDescription(); - } - catch (CoreException e) { - // log the logError - return; - } - - // Look for builder already associated - ICommand[] cmds = description.getBuildSpec(); - for (int j = 0; j < cmds.length; j++) - if (cmds[j].getBuilderName().equals(BUILDER_ID)) - return; - - // Associate builder with project - ICommand newCmd = description.newCommand(); - newCmd.setBuilderName(BUILDER_ID); - ArrayList newCmds = new ArrayList(); - newCmds.addAll (Arrays.asList(cmds)); - newCmds.add(newCmd); - description.setBuildSpec( - (ICommand[]) newCmds.toArray( - new ICommand[newCmds.size()])); - try { - project.setDescription(description, null); - } - catch (CoreException e) { - // log the logError - } - - } - - public static void removeBuilderFromProject(IProject project) { - // Cannot modify closed projects - if (!project.isOpen()) - return; - // get the description - IProjectDescription description; - - try { - description = project.getDescription(); - } catch (CoreException e) { - // Log the error - return; - } - - // Look for the builder - int index = -1; - ICommand[] cmds = description.getBuildSpec(); - for (int j = 0; j < cmds.length; j++) { - if (cmds[j].getBuilderName().equals(BUILDER_ID)) { - index = j; - break; - } - } - if (index == -1) - return; - - // Remove builder from project - ArrayList newCmds = new ArrayList(); - newCmds.addAll(Arrays.asList(cmds)); - newCmds.remove(index); - description.setBuildSpec( - (ICommand[]) newCmds.toArray( - new ICommand[newCmds.size()])); - - try { - project.setDescription(description, null); - } - catch (CoreException e) { - // log the error - } - } - - public static boolean deleteAuditMarkers(IProject project) { - // TODO Auto-generated method stub - try { - project.deleteMarkers(MARKER_ID, false, 0 /* IRESOURCE.DEPTH_INFINITIVE */); - return true; - } - catch (CoreException e) { - // log the error - return false; - } - - } -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/SampleBuilder.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/SampleBuilder.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,247 +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.wrttools.builder; - -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; - -public class SampleBuilder extends IncrementalProjectBuilder { - - class SampleDeltaVisitor implements IResourceDeltaVisitor { - /* - * (non-Javadoc) - * - * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) - */ - public boolean visit(IResourceDelta delta) throws CoreException { - IResource resource = delta.getResource(); - switch (delta.getKind()) { - case IResourceDelta.ADDED: - // handle added resource - checkXML(resource); - checkJS(resource); - break; - case IResourceDelta.REMOVED: - // handle removed resource - break; - case IResourceDelta.CHANGED: - // handle changed resource - checkXML(resource); - checkJS(resource); - break; - } - //return true to continue visiting children. - return true; - } - } - - class SampleResourceVisitor implements IResourceVisitor { - public boolean visit(IResource resource) { - checkXML(resource); - checkJS(resource); - //return true to continue visiting children. - return true; - } - } - - class XMLErrorHandler extends DefaultHandler { - - private IFile file; - - public XMLErrorHandler(IFile file) { - this.file = file; - } - - private void addXMLMarker(SAXParseException e, int severity) { - SampleBuilder.this.addXMLMarker(file, e.getMessage(), e - .getLineNumber(), severity); - } - - public void error(SAXParseException exception) throws SAXException { - addXMLMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void fatalError(SAXParseException exception) throws SAXException { - addXMLMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void warning(SAXParseException exception) throws SAXException { - addXMLMarker(exception, IMarker.SEVERITY_WARNING); - } - } - -class JSErrorHandler extends DefaultHandler { - - private IFile file; - - public JSErrorHandler(IFile file) { - this.file = file; - } - - private void addJSMarker(SAXParseException e, int severity) { - SampleBuilder.this.addJSMarker(file, e.getMessage(), e - .getLineNumber(), severity); - } - - public void error(SAXParseException exception) throws SAXException { - addJSMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void fatalError(SAXParseException exception) throws SAXException { - addJSMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void warning(SAXParseException exception) throws SAXException { - addJSMarker(exception, IMarker.SEVERITY_WARNING); - } - } - - public static final String BUILDER_ID = "org.symbian.tools.wrttools.builder.PropertiesFileAuditor"; - - private static final String XML_MARKER_TYPE = "org.symbian.tools.wrttools.xmlProblem"; - private static final String JS_MARKER_TYPE = "org.symbian.tools.wrttools.jsProblem"; - - private SAXParserFactory parserFactory; - - private void addXMLMarker(IFile file, String message, int lineNumber, - int severity) { - try { - IMarker marker = file.createMarker(XML_MARKER_TYPE); - marker.setAttribute(IMarker.MESSAGE, message); - marker.setAttribute(IMarker.SEVERITY, severity); - if (lineNumber == -1) { - lineNumber = 1; - } - marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); - } catch (CoreException e) { - } - } - - private void addJSMarker(IFile file, String message, int lineNumber, - int severity) { - try { - IMarker marker = file.createMarker(JS_MARKER_TYPE); - marker.setAttribute(IMarker.MESSAGE, message); - marker.setAttribute(IMarker.SEVERITY, severity); - if (lineNumber == -1) { - lineNumber = 1; - } - marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); - } catch (CoreException e) { - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.events.InternalBuilder#build(int, - * java.util.Map, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IProject[] build(int kind, Map args, IProgressMonitor monitor) - throws CoreException { - if (kind == FULL_BUILD) { - fullBuild(monitor); - } else { - IResourceDelta delta = getDelta(getProject()); - if (delta == null) { - fullBuild(monitor); - } else { - incrementalBuild(delta, monitor); - } - } - return null; - } - - void checkXML(IResource resource) { - if (resource instanceof IFile && resource.getName().endsWith(".xml")) { - IFile file = (IFile) resource; - deleteXMLMarkers(file); - XMLErrorHandler reporter = new XMLErrorHandler(file); - try { - getParser().parse(file.getContents(), reporter); - } catch (Exception e1) { - } - } - } - - void checkJS(IResource resource) { - if (resource instanceof IFile && resource.getName().endsWith(".js")) { - IFile file = (IFile) resource; - deleteJSMarkers(file); - JSErrorHandler reporter = new JSErrorHandler(file); - try { - getParser().parse(file.getContents(), reporter); - } catch (Exception e1) { - } - } - } - - private void deleteXMLMarkers(IFile file) { - try { - file.deleteMarkers(XML_MARKER_TYPE, false, IResource.DEPTH_ZERO); - } catch (CoreException ce) { - } - } - - private void deleteJSMarkers(IFile file) { - try { - file.deleteMarkers(JS_MARKER_TYPE, false, IResource.DEPTH_ZERO); - } catch (CoreException ce) { - } - } - - protected void fullBuild(final IProgressMonitor monitor) - throws CoreException { - try { - getProject().accept(new SampleResourceVisitor()); - } catch (CoreException e) { - } - } - - private SAXParser getParser() throws ParserConfigurationException, - SAXException { - if (parserFactory == null) { - parserFactory = SAXParserFactory.newInstance(); - } - return parserFactory.newSAXParser(); - } - - protected void incrementalBuild(IResourceDelta delta, - IProgressMonitor monitor) throws CoreException { - // the visitor does the work. - delta.accept(new SampleDeltaVisitor()); - } -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/SampleNature.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/SampleNature.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +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.wrttools.builder; - -import org.eclipse.core.resources.ICommand; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IProjectNature; -import org.eclipse.core.runtime.CoreException; - -public class SampleNature implements IProjectNature { - - /** - * ID of this project nature - */ - public static final String NATURE_ID = "WebRuntime_Plugin_Project.sampleNature"; - - private IProject project; - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.resources.IProjectNature#configure() - */ - public void configure() throws CoreException { - IProjectDescription desc = project.getDescription(); - ICommand[] commands = desc.getBuildSpec(); - - for (int i = 0; i < commands.length; ++i) { - if (commands[i].getBuilderName().equals(SampleBuilder.BUILDER_ID)) { - return; - } - } - - ICommand[] newCommands = new ICommand[commands.length + 1]; - System.arraycopy(commands, 0, newCommands, 0, commands.length); - ICommand command = desc.newCommand(); - command.setBuilderName(SampleBuilder.BUILDER_ID); - newCommands[newCommands.length - 1] = command; - desc.setBuildSpec(newCommands); - project.setDescription(desc, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.resources.IProjectNature#deconfigure() - */ - public void deconfigure() throws CoreException { - IProjectDescription description = getProject().getDescription(); - ICommand[] commands = description.getBuildSpec(); - for (int i = 0; i < commands.length; ++i) { - if (commands[i].getBuilderName().equals(SampleBuilder.BUILDER_ID)) { - ICommand[] newCommands = new ICommand[commands.length - 1]; - System.arraycopy(commands, 0, newCommands, 0, i); - System.arraycopy(commands, i + 1, newCommands, i, - commands.length - i - 1); - description.setBuildSpec(newCommands); - project.setDescription(description, null); - return; - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.resources.IProjectNature#getProject() - */ - public IProject getProject() { - return project; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject) - */ - public void setProject(IProject project) { - this.project = project; - } - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/ToggleNatureAction.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/ToggleNatureAction.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +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.wrttools.builder; - -import java.util.Iterator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - -public class ToggleNatureAction implements IObjectActionDelegate { - - private ISelection selection; - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - if (selection instanceof IStructuredSelection) { - for (Iterator it = ((IStructuredSelection) selection).iterator(); it - .hasNext();) { - Object element = it.next(); - IProject project = null; - if (element instanceof IProject) { - project = (IProject) element; - } else if (element instanceof IAdaptable) { - project = (IProject) ((IAdaptable) element) - .getAdapter(IProject.class); - } - if (project != null) { - toggleNature(project); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, - * org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - this.selection = selection; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, - * org.eclipse.ui.IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - } - - /** - * Toggles sample nature on a project - * - * @param project - * to have sample nature added or removed - */ - private void toggleNature(IProject project) { - try { - IProjectDescription description = project.getDescription(); - String[] natures = description.getNatureIds(); - - for (int i = 0; i < natures.length; ++i) { - if (SampleNature.NATURE_ID.equals(natures[i])) { - // Remove the nature - String[] newNatures = new String[natures.length - 1]; - System.arraycopy(natures, 0, newNatures, 0, i); - System.arraycopy(natures, i + 1, newNatures, i, - natures.length - i - 1); - description.setNatureIds(newNatures); - project.setDescription(description, null); - return; - } - } - - // Add the nature - String[] newNatures = new String[natures.length + 1]; - System.arraycopy(natures, 0, newNatures, 0, natures.length); - newNatures[natures.length] = SampleNature.NATURE_ID; - description.setNatureIds(newNatures); - project.setDescription(description, null); - } catch (CoreException e) { - } - } - -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/ToggleProjectNatureContributionItem.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/ToggleProjectNatureContributionItem.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +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.wrttools.builder; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -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.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.action.ContributionItem; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MenuAdapter; -import org.eclipse.swt.events.MenuEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -public class ToggleProjectNatureContributionItem extends ContributionItem { - - public ToggleProjectNatureContributionItem() { - // TODO Auto-generated constructor stub - } - - public ToggleProjectNatureContributionItem(String id) { - // TODO Auto-generated constructor stub - } - - public void fill(Menu menu, int index) { - final MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index); - menuItem.setText("Add/Remove propertiesAuditor project naute"); - menuItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - run(); - } - }); - menu.addMenuListener(new MenuAdapter() { - public void menuShown(MenuEvent e) { - updateState(menuItem); - } - }); - } - - protected void updateState(MenuItem menuItem) { - Collection projects = getSelectedProjects(); - boolean enabled = projects.size() > 0; - menuItem.setEnabled(enabled); - menuItem.setSelection(enabled && - PropertiesAuditorNature.hasNature(projects.iterator().next())); - } - - private Collection getSelectedProjects() { - // TODO Auto-generated method stub - Collection projects = new HashSet(); - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - ISelection selection = window.getActivePage().getSelection(); - if (selection instanceof IStructuredSelection) { - for (Iterator iter = ((IStructuredSelection) - selection).iterator(); iter.hasNext();) { - // translate the selected object into a project - Object elem = iter.next(); - if (!(elem instanceof IResource)) { - if (!(elem instanceof IAdaptable)) - continue; - elem = ((IAdaptable) elem).getAdapter(IResource.class); - if (!(elem instanceof IResource)) - continue; - } - if (!(elem instanceof IProject)) { - elem = ((IResource) elem).getProject(); - if (!(elem instanceof IProject)) - continue; - } - projects.add((IProject) elem); - } - } - return projects; - } - - protected void run() { - // TODO Auto-generated method stub - Collection projects = getSelectedProjects(); - for (IProject project : projects) { - /* - * The builder can be directly associated with a project - * without the need for a builder... - */ -/* if (false) - toggleBuilder(project); -*/ - // ... or more typically a nature can be used - // to associate a project with a builder - if (true) - toggleNature(project); - } - } - - private void toggleNature(IProject project) { - if (PropertiesAuditorNature.hasNature(project)) { - PropertiesAuditorNature.removeNature(project); - } - else { - PropertiesAuditorNature.addNature(project); - } - } - - private void toggleBuilder(final IProject project) { - // If the project has the builder - // then remove the builder and all audit markers - if (PropertiesFileAuditor.hasBuilder(project)) { - PropertiesFileAuditor.deleteAuditMarkers(project); - PropertiesFileAuditor.removeBuilderFromProject(project); - } - // otherwise add the builder - // and schedule an audit of the files - else { - PropertiesFileAuditor.addBuilderToProject(project); - new Job("Properties File Audit") { - protected IStatus run(IProgressMonitor monitor) { - try { - project.build(PropertiesFileAuditor.FULL_BUILD, - PropertiesFileAuditor.BUILDER_ID, null, monitor); - } - catch (CoreException e) { - // log the error - } - return Status.OK_STATUS; - } - }.schedule(); - } - } -} diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/existingFavoriteFor.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/builder/existingFavoriteFor.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +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.wrttools.builder; - -public class existingFavoriteFor { - -} diff -r cdc4995b1677 -r aea4c83725d8 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 Tue Aug 10 09:52:29 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/project/WRTIDEProjectProvider.java Fri Aug 13 16:28:00 2010 -0700 @@ -42,5 +42,4 @@ public boolean isSupportedProject(IProject project) { return ProjectUtils.hasWrtNature(project); } - } diff -r cdc4995b1677 -r aea4c83725d8 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/WRTEntityResolver.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/WRTEntityResolver.java Tue Aug 10 09:52:29 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +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.wrttools.util; - -import java.io.IOException; -import java.io.InputStream; - -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * This entity resolver class can be used when DOM Parser is used for local files - * @author ranoliya - * - */ -public class WRTEntityResolver { - - - /** - * - * @param dtdSystemID -- DTD System ID - * @param dtdFilename -- Local DTD File name - * @return - */ - public EntityResolver inputResolveEntity(final String dtdSystemID, final String dtdName) { - EntityResolver er = new EntityResolver() { - - /** - * This method resolves publicID and systemID for local files - */ - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException, IOException { - InputSource result = null; - InputStream resourceAsStream = this.getClass().getResourceAsStream(dtdName); - result = new InputSource(resourceAsStream); - result.setPublicId(publicId); - result.setSystemId(systemId); - return result; - } - - }; - return er; - } - -}