# HG changeset patch # User Eugene Ostroukhov # Date 1263001288 28800 # Node ID 718b6c524eba76bb5588f10242938cfe664c6837 # Parent d3352cb24d8d58d8e5a6a57b2c691e241998b3a8# Parent 2652c361b0b3ec7bb2f56e9e4579be735760da7e Merge diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools.debug.core/launch/WRT Debugger.launch --- a/org.symbian.tools.wrttools.debug.core/launch/WRT Debugger.launch Fri Jan 08 17:40:07 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/launch/WRT Debugger.launch Fri Jan 08 17:41:28 2010 -0800 @@ -23,6 +23,7 @@ + diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/.hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/bin/.hgignore Fri Jan 08 17:41:28 2010 -0800 @@ -0,0 +1,2 @@ +org +.hgignore \ No newline at end of file diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/internal/validation/CssBuildValidator.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/internal/validation/CssBuildValidator.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog$1.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog$1.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog$2.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog$2.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/projects/ProjectUtils.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/projects/ProjectUtils.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/NonClosingStream.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/NonClosingStream.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/ProjectUtils$1.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/ProjectUtils$1.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/ProjectUtils.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/ProjectUtils.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$1.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$1.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$10.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$10.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$11.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$11.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$12.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$12.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$13.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$13.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$14.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$14.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$15.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$15.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$16.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$16.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$17.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$17.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$2.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$2.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$3.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$3.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$4.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$4.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$5.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$5.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$6.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$6.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$7.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$7.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$8.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$8.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$9.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$9.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$ProjectLabelProvider.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$ProjectLabelProvider.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$ProjectRecord.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage$ProjectRecord.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage$1.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage$1.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage$2.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage$2.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage$3.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage$3.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard$1.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard$1.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard$2.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard$2.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.class has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/icons/main16.gif Binary file org.symbian.tools.wrttools/icons/main16.gif has changed diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/internal/validation/CssBuildValidator.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/internal/validation/CssBuildValidator.java Fri Jan 08 17:40:07 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/internal/validation/CssBuildValidator.java Fri Jan 08 17:41:28 2010 -0800 @@ -105,7 +105,7 @@ String msg = cssError.getException().getLocalizedMessage(); if (msg != null && msg.trim().length() > 0) { ValidatorMessage message = createMessage(resource, cssError - .getLine(), msg, IMarker.SEVERITY_ERROR); + .getLine(), msg, IMarker.SEVERITY_WARNING); result.add(message); } } diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/dialogs/AptanaProjectSelectionDialog.java Fri Jan 08 17:41:28 2010 -0800 @@ -0,0 +1,131 @@ +package org.symbian.tools.wrttools.dialogs; + +import java.io.File; +import java.text.MessageFormat; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +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.DirectoryDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.symbian.tools.wrttools.util.ProjectUtils; + +public class AptanaProjectSelectionDialog extends TitleAreaDialog { + private File project; + private Text location; + + public AptanaProjectSelectionDialog(Shell parentShell) { + super(parentShell); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("WebRuntime Tools"); + } + + @Override + protected Control createDialogArea(Composite parent) { + setTitle("Select Aptana WRT Project"); + setMessage("Select an Aptana WRT project or Aptana workspace containing one"); + Composite root = (Composite) super.createDialogArea(parent); + + Composite workingArea = new Composite(root, SWT.NONE); + workingArea.setLayoutData(new GridData(GridData.FILL_BOTH)); + + workingArea.setLayout(new GridLayout(2, false)); + Label label = new Label(workingArea, SWT.NONE); + label.setLayoutData(new GridData(GridData.BEGINNING, + GridData.BEGINNING, false, false, 2, 1)); + label.setText("Specify Aptana project or Aptana workspace location:"); + location = new Text(workingArea, SWT.BORDER); + location.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + location.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + validate(); + } + }); + + Button browse = new Button(workingArea, SWT.NONE); + browse.setText("Browse..."); + browse.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + browse(); + } + }); + + location.setText(ProjectUtils.getDefaultAptanaLocation()); + + return root; + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + validate(); + setErrorMessage(null); + } + + protected void browse() { + DirectoryDialog dialog = new DirectoryDialog(getShell()); + dialog.setFilterPath(location.getText()); + dialog.setMessage("Select Aptana WRT project or workspace"); + dialog.setText("Web Runtime Tools"); + + String string = dialog.open(); + if (string != null) { + location.setText(string); + } + } + + protected void validate() { + String error = null; + File f = new File(location.getText()); + if (f.isDirectory()) { + if (!ProjectUtils.isAptanaProject(f)) { + File[] files = f.listFiles(); + f = null; + for (File file : files) { + if (ProjectUtils.isAptanaProject(file)) { + f = file; + break; + } + } + if (f == null) { + error = MessageFormat.format("{0} is not a WRT project or an Aptana workspace containing WRT projects", location.getText()); + } + } + } else { + error = "Specified folder does not exist"; + } + project = f; + setErrorMessage(error); + Button button = getButton(IDialogConstants.OK_ID); + if (button != null) { + button.setEnabled(error == null); + } + } + + @Override + protected void cancelPressed() { + project = null; + super.cancelPressed(); + } + + public File getProject() { + return project; + } +} diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/projects/ProjectUtils.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/projects/ProjectUtils.java Fri Jan 08 17:40:07 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +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.projects; - -import java.net.URI; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock; -import org.eclipse.wst.validation.ValidationFramework; - -public class ProjectUtils { - public static IProject createWrtProject(String name, URI uri, IProgressMonitor monitor) throws CoreException { - monitor.beginTask("Create project resources", 20); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IProject project = workspace.getRoot().getProject( - name); - BuildPathsBlock.createProject(project, uri, - new SubProgressMonitor(monitor, 10)); - - BuildPathsBlock.addJavaNature(project, new SubProgressMonitor(monitor, - 10)); - - // TODO: Build path, super type, etc. - // BuildPathsBlock.flush(classPathEntries, javaScriptProject, superType, - // monitor) - - ValidationFramework.getDefault().addValidationBuilder(project); - - monitor.done(); - return project; - } -} diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/NonClosingStream.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/NonClosingStream.java Fri Jan 08 17:41:28 2010 -0800 @@ -0,0 +1,38 @@ +/** + * 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.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * This allows blocking the IP clients from closing the stream. This + * class is needed when creating workbench files from the Zip archives. + */ +public final class NonClosingStream extends FilterInputStream { + public NonClosingStream(InputStream in) { + super(in); + } + + @Override + public void close() throws IOException { + // We do not need Eclipse closing the Zip stream + } +} \ No newline at end of file diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Fri Jan 08 17:41:28 2010 -0800 @@ -0,0 +1,241 @@ +/** + * 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.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +import javax.swing.filechooser.FileSystemView; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +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.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.statushandlers.StatusManager; +import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock; +import org.eclipse.wst.validation.ValidationFramework; +import org.symbian.tools.wrttools.Activator; +import org.symbian.tools.wrttools.dialogs.AptanaProjectSelectionDialog; + +public class ProjectUtils { + public static final String PREVIEW_FOLDER = "preview"; + public static final String PREVIEW_FRAME_FILE = "wrt_preview_frame.html"; + + public static IProject createWrtProject(String name, URI uri, + IProgressMonitor monitor) throws CoreException { + monitor.beginTask("Create project resources", 20); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IProject project = workspace.getRoot().getProject(name); + BuildPathsBlock.createProject(project, uri, new SubProgressMonitor( + monitor, 10)); + + BuildPathsBlock.addJavaNature(project, new SubProgressMonitor(monitor, + 10)); + + // TODO: Build path, super type, etc. + // BuildPathsBlock.flush(classPathEntries, javaScriptProject, superType, + // monitor) + + ValidationFramework.getDefault().addValidationBuilder(project); + + monitor.done(); + return project; + } + + public static void addPreviewer(IProject project, IPath mainHtml) { + URI archive = getPreviewerArchive(); + try { + if (archive != null) { + ZipInputStream stream = new ZipInputStream(archive.toURL().openStream()); + ZipEntry entry; + while ((entry = stream.getNextEntry()) != null) { + if (!entry.isDirectory()) { + copyFile(project, entry.getName(), stream, entry.getSize(), new NullProgressMonitor()); + } else { + IFolder folder = project.getFolder(entry.getName()); + if (!folder.exists()) { + folder.create(false, true, new NullProgressMonitor()); + } + } + stream.closeEntry(); + } + } + IFile file = project.getFile(mainHtml + ".html"); + if (file.exists()) { + file.copy(project.getFullPath().append("wrt_preview_main.html"), false, new NullProgressMonitor()); + } + + } catch (IOException e) { + StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to add previewer to project")); + } catch (CoreException e) { + StatusManager.getManager().handle(e, Activator.PLUGIN_ID); + } + } + + private static URI getPreviewerArchive() { + File file = getPreviewerZip(); + if (file.isFile()) { + return file.toURI(); + } + Display display = Display.getDefault(); + display.syncExec(new Runnable() { + @Override + public void run() { + importPreviewer(); + } + }); + if (file.isFile()) { + return file.toURI(); + } + return null; + } + + private static File getPreviewerZip() { + return Activator.getDefault().getStateLocation() + .append("previewer.zip").toFile(); + } + + private static void importPreviewer() { + AptanaProjectSelectionDialog dialog = new AptanaProjectSelectionDialog( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); + int open = dialog.open(); + if (open == Window.OK) { + File project = dialog.getProject(); + try { + zipPreviewer(project); + } catch (IOException e) { + StatusManager + .getManager() + .handle( + new Status( + IStatus.ERROR, + Activator.PLUGIN_ID, + "Failed to create Web Runtime previewer archive.", + e), StatusManager.SHOW); + } + } + } + + private static void zipPreviewer(File project) throws IOException { + ZipOutputStream stream = new ZipOutputStream(new FileOutputStream( + getPreviewerZip())); + try { + zip(new File(project, PREVIEW_FOLDER), stream, PREVIEW_FOLDER + "/"); + zipFile(new File(project, PREVIEW_FRAME_FILE), + PREVIEW_FRAME_FILE, stream); + } finally { + stream.close(); + } + } + + private static void zip(File folder, ZipOutputStream stream, String path) + throws IOException { + ZipEntry entry = new ZipEntry(path); + stream.putNextEntry(entry); + stream.closeEntry(); + File[] files = folder.listFiles(); + for (File file : files) { + if (file.isFile()) { + zipFile(file, path + file.getName(), stream); + } else { + zip(file, stream, path + file.getName() + "/"); + } + } + } + + private static void zipFile(File file, String zipEntry, + ZipOutputStream stream) throws IOException, FileNotFoundException { + ZipEntry entry = new ZipEntry(zipEntry); + stream.putNextEntry(entry); + BufferedInputStream inputStream = new BufferedInputStream( + new FileInputStream(file)); + try { + copy(inputStream, stream); + } finally { + inputStream.close(); + } + stream.closeEntry(); + } + + private static void copy(InputStream in, OutputStream out) + throws IOException { + byte[] buffer = new byte[131072]; // 128k - should be enough for most + // JS/CSS files + int count; + while ((count = in.read(buffer)) > 0) { + out.write(buffer, 0, count); + } + } + + public static String getDefaultAptanaLocation() { + File myDocuments = FileSystemView.getFileSystemView() + .getDefaultDirectory(); + File file = new File(myDocuments, "Aptana Studio Workspace"); + return file.exists() ? file.getAbsolutePath() : ""; + } + + public static boolean isAptanaProject(File f) { + return new File(f, PREVIEW_FOLDER).isDirectory() + && new File(f, PREVIEW_FRAME_FILE).isFile(); + } + + public static void copyFile(IProject project, String name, ZipInputStream stream, + long size, IProgressMonitor monitor) throws CoreException, + IOException { + IFile file = project.getFile(name); + file.create(new NonClosingStream(stream), true, + new SubProgressMonitor(monitor, 1)); + } + + public static void importPreviewer(URI locationURI) { + if (!getPreviewerZip().exists()) { + File file = new File(locationURI); + try { + zipPreviewer(file); + } catch (IOException e) { + Activator.log(e); + } + } + } + + public static boolean isAptanaProject(URI locationURI) { + return isAptanaProject(new File(locationURI)); + } +} diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java Fri Jan 08 17:40:07 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java Fri Jan 08 17:41:28 2010 -0800 @@ -36,8 +36,6 @@ import java.util.zip.ZipException; import java.util.zip.ZipFile; -import javax.swing.filechooser.FileSystemView; - import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; @@ -103,7 +101,7 @@ import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; import org.eclipse.ui.wizards.datatransfer.ImportOperation; import org.symbian.tools.wrttools.Activator; -import org.symbian.tools.wrttools.projects.ProjectUtils; +import org.symbian.tools.wrttools.util.ProjectUtils; public class AptanaProjectLocationWizardPage extends WizardPage implements IOverwriteQuery { @@ -416,14 +414,28 @@ // first look for project description files final String dotProject = IProjectDescription.DESCRIPTION_FILE_NAME; + + File dotProjectFile = null; + boolean hasPreviewer = false; + boolean hasFrame = false; + for (int i = 0; i < contents.length; i++) { File file = contents[i]; if (file.isFile() && file.getName().equals(dotProject)) { - files.add(file); - // don't search sub-directories since we can't have nested - // projects - return true; + dotProjectFile = file; + } + if (file.isFile() && ProjectUtils.PREVIEW_FRAME_FILE.equalsIgnoreCase(file.getName())) { + hasFrame = true; } + if (file.isDirectory() && ProjectUtils.PREVIEW_FOLDER.equalsIgnoreCase(file.getName())) { + hasPreviewer = true; + } + } + if (dotProjectFile != null && hasFrame && hasPreviewer) { + files.add(dotProjectFile); + // don't search sub-directories since we can't have nested + // projects + return true; } // no project description found, so recurse into sub-directories for (int i = 0; i < contents.length; i++) { @@ -471,16 +483,28 @@ children = new ArrayList(1); } Iterator childrenEnum = children.iterator(); + boolean hasPreviewFolder = false; + boolean hasFrameHtml = false; + ProjectRecord projectRecord = null; while (childrenEnum.hasNext()) { Object child = childrenEnum.next(); + String elementLabel = structureProvider.getLabel(child); if (structureProvider.isFolder(child)) { + if (ProjectUtils.PREVIEW_FOLDER.equalsIgnoreCase(elementLabel)) { + hasPreviewFolder = true; + } collectProjectFilesFromProvider(files, child, level + 1, monitor); } - String elementLabel = structureProvider.getLabel(child); if (elementLabel.equals(IProjectDescription.DESCRIPTION_FILE_NAME)) { - files.add(new ProjectRecord(child, entry, level)); + projectRecord = new ProjectRecord(child, entry, level); } + if (ProjectUtils.PREVIEW_FRAME_FILE.equalsIgnoreCase(elementLabel)) { + hasFrameHtml = true; + } + } + if (projectRecord != null && hasPreviewFolder && hasFrameHtml) { + files.add(projectRecord); } return true; } @@ -508,7 +532,8 @@ createWorkingSetGroup(workArea); restoreWidgetValues(); Dialog.applyDialogFont(workArea); - + + updateProjectsList(directoryPathField.getText().trim()); } /** @@ -557,7 +582,7 @@ operation.setCreateContainerStructure(false); operation.run(monitor); } - + ProjectUtils.importPreviewer(record.description.getLocationURI()); } catch (CoreException e) { Activator.log(e); return false; @@ -805,7 +830,7 @@ .convertWidthInCharsToPixels(25); directoryPathField.setLayoutData(directoryPathData); - directoryPathField.setText(getDefaultImportLocation()); + directoryPathField.setText(ProjectUtils.getDefaultAptanaLocation()); // browse button browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); @@ -951,12 +976,6 @@ }); } - private String getDefaultImportLocation() { - File myDocuments = FileSystemView.getFileSystemView().getDefaultDirectory(); - File file = new File(myDocuments, "Aptana Studio Workspace"); - return file.exists() ? file.getAbsolutePath() : ""; - } - /** * Create the selection buttons in the listComposite. * @@ -1092,7 +1111,7 @@ public ProjectRecord[] getProjectRecords() { List projectRecords = new ArrayList(); for (int i = 0; i < selectedProjects.length; i++) { - if (isProjectInWorkspace(selectedProjects[i].getProjectName())) { + if (!ProjectUtils.isAptanaProject(selectedProjects[i].description.getLocationURI()) || isProjectInWorkspace(selectedProjects[i].getProjectName())) { selectedProjects[i].hasConflicts = true; } projectRecords.add(selectedProjects[i]); diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.java Fri Jan 08 17:40:07 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.java Fri Jan 08 17:41:28 2010 -0800 @@ -29,6 +29,7 @@ public AptanaProjectsImportWizard() { setWindowTitle("Import Aptana Project"); + setNeedsProgressMonitor(true); } @Override @@ -50,8 +51,7 @@ @Override public void init(IWorkbench workbench, IStructuredSelection selection) { - // TODO Auto-generated method stub - + // Do nothing } } diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java Fri Jan 08 17:40:07 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java Fri Jan 08 17:41:28 2010 -0800 @@ -73,6 +73,12 @@ @Override public void createControl(Composite parent) { + ProjectTemplate[] allTemplates = ProjectTemplate.getAllTemplates(); + + if (allTemplates.length == 1) { + context.setTemplate(allTemplates[0]); + } + Composite composite = new Composite(parent, SWT.NONE); FormLayout layout = new FormLayout(); layout.marginWidth = 5; @@ -119,7 +125,7 @@ templates.setContentProvider(new ArrayContentProvider()); templates.setLabelProvider(new ProjectTemplateLabelProvider()); - templates.setInput(ProjectTemplate.getAllTemplates()); + templates.setInput(allTemplates); setControl(composite); setPageComplete(false); @@ -128,6 +134,10 @@ IObservableValue property = BeansObservables.observeValue(context, WizardContext.TEMPLATE); bindingContext.bindValue(selection, property); + if (context.getTemplate() != null) { + refreshSelection(context.getTemplate()); + } + setErrorMessage(null); } protected void switchWizardPage() { diff -r 2652c361b0b3 -r 718b6c524eba org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Fri Jan 08 17:40:07 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Fri Jan 08 17:41:28 2010 -0800 @@ -38,13 +38,13 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; 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.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -54,11 +54,10 @@ import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; -import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock; -import org.eclipse.wst.validation.ValidationFramework; import org.symbian.tools.wrttools.Activator; import org.symbian.tools.wrttools.core.ProjectTemplate; -import org.symbian.tools.wrttools.projects.ProjectUtils; +import org.symbian.tools.wrttools.util.NonClosingStream; +import org.symbian.tools.wrttools.util.ProjectUtils; public class WrtWidgetWizard extends Wizard implements INewWizard { private WizardNewProjectCreationPage resourcePage; @@ -150,11 +149,10 @@ copyTemplate(project, name, stream, (int) entry.getSize(), ctx, monitor); } else { - copyFile(project, name, stream, entry.getSize(), monitor); + ProjectUtils.copyFile(project, name, stream, entry.getSize(), monitor); } stream.closeEntry(); } - monitor.done(); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, @@ -168,37 +166,16 @@ } } } - } - - private void copyFile(IProject project, String name, ZipInputStream stream, - long size, IProgressMonitor monitor) throws CoreException, - IOException { - byte[] contents = readBytes(stream, (int) size); - IFile file = project.getFile(name); - file.create(new ByteArrayInputStream(contents), true, - new SubProgressMonitor(monitor, 1)); - } - - private byte[] readBytes(ZipInputStream stream, int size) - throws IOException { - byte[] contents = new byte[size]; - int len = 0; - do { - int read = stream.read(contents, len, size - len); - len += read; - } while (len < size); - return contents; + ProjectUtils.addPreviewer(project, new Path(context.getHtmlFile())); } private void copyTemplate(IProject project, String 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 - final byte[] template = readBytes(stream, size); ByteArrayOutputStream file = new ByteArrayOutputStream(); - Reader reader = new InputStreamReader( - new ByteArrayInputStream(template)); + Reader reader = new InputStreamReader(new NonClosingStream(stream)); Writer writer = new OutputStreamWriter(file); Velocity.evaluate(ctx, writer, name, reader);