# HG changeset patch # User Eugene Ostroukhov # Date 1264643654 28800 # Node ID 5a2cfa9bc74343310fbefc5e31f7606a0882af1d # Parent ba7c1ce1cc4a2c41bfb2144ee2a439493ae5120e Nature is used for UI diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools.debug.core/META-INF/MANIFEST.MF --- a/org.symbian.tools.wrttools.debug.core/META-INF/MANIFEST.MF Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/META-INF/MANIFEST.MF Wed Jan 27 17:54:14 2010 -0800 @@ -15,6 +15,7 @@ org.eclipse.wst.jsdt.ui;bundle-version="1.0.200", org.eclipse.ui.editors;bundle-version="3.5.0", org.eclipse.jface.text;bundle-version="3.5.0", - org.symbian.tools.wrttools.previewer;bundle-version="1.0.0" + org.symbian.tools.wrttools.previewer;bundle-version="1.0.0", + org.symbian.tools.wrttools;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/ChromeDebugUtils.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/ChromeDebugUtils.java Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/ChromeDebugUtils.java Wed Jan 27 17:54:14 2010 -0800 @@ -22,6 +22,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Platform; +import org.symbian.tools.wrttools.util.ProjectUtils; public final class ChromeDebugUtils { public static String getExecutablePath(String folder) { @@ -54,10 +55,6 @@ return getExecutablePath(Activator.getDefault().getPreferenceStore().getString(IConstants.PREF_NAME_CHROME_LOCATION)); } - public static boolean isWidgetProject(IProject project) { - return project.findMember(IConstants.WRT_PREVIEW_HTML) != null; - } - public static boolean isWindows() { return "windows".equals(Platform.getOS()); } diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/IConstants.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/IConstants.java Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/IConstants.java Wed Jan 27 17:54:14 2010 -0800 @@ -21,6 +21,4 @@ public interface IConstants { String PREF_NAME_CHROME_LOCATION="chrome.location"; String PROP_PROJECT_NAME = "projectName"; - - public static final String WRT_PREVIEW_HTML = "wrt_preview_frame.html"; } diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/property/PropertyTester.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/property/PropertyTester.java Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/property/PropertyTester.java Wed Jan 27 17:54:14 2010 -0800 @@ -20,13 +20,14 @@ import org.eclipse.core.resources.IResource; import org.symbian.tools.wrttools.debug.internal.ChromeDebugUtils; +import org.symbian.tools.wrttools.util.ProjectUtils; public class PropertyTester extends org.eclipse.core.expressions.PropertyTester { public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (property.equals("isWrtProject")) { - return ChromeDebugUtils.isWidgetProject(((IResource) receiver).getProject()); + return ProjectUtils.hasWrtNature(((IResource) receiver).getProject()); } return false; } diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/ui/launch/WidgetBasicTab.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/ui/launch/WidgetBasicTab.java Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/ui/launch/WidgetBasicTab.java Wed Jan 27 17:54:14 2010 -0800 @@ -46,6 +46,7 @@ import org.symbian.tools.wrttools.debug.internal.ChromeDebugUtils; import org.symbian.tools.wrttools.debug.internal.IConstants; import org.symbian.tools.wrttools.debug.internal.Images; +import org.symbian.tools.wrttools.util.ProjectUtils; public class WidgetBasicTab extends AbstractLaunchConfigurationTab { private ComboViewer project; @@ -91,7 +92,7 @@ .getProjects(); LinkedList filtered = new LinkedList(); for (IProject p : projects) { - if (ChromeDebugUtils.isWidgetProject(p)) { + if (ProjectUtils.hasWrtNature(p)) { filtered.add(p); } } diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF --- a/org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/META-INF/MANIFEST.MF Wed Jan 27 17:54:14 2010 -0800 @@ -11,7 +11,8 @@ org.mozilla.xpcom;bundle-version="1.9.1", org.eclipse.equinox.http.jetty;bundle-version="2.0.0", org.eclipse.wst.jsdt.core;bundle-version="1.0.201", - org.eclipse.wst.jsdt.ui;bundle-version="1.0.200" + org.eclipse.wst.jsdt.ui;bundle-version="1.0.200", + org.symbian.tools.wrttools;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: org.symbian.tools.wrttools.previewer, diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Wed Jan 27 17:54:14 2010 -0800 @@ -36,6 +36,7 @@ import org.eclipse.ui.part.PageBookView; import org.symbian.tools.wrttools.previewer.PreviewerPlugin; import org.symbian.tools.wrttools.previewer.IWrtEditingPreferences; +import org.symbian.tools.wrttools.util.ProjectUtils; public class PreviewView extends PageBookView { private static final class ChangedResourcesCollector implements @@ -176,16 +177,12 @@ IResource resource = (IResource) ((IEditorPart) part) .getEditorInput().getAdapter(IResource.class); if (resource != null) { - return isWrtProject(resource.getProject()); + return ProjectUtils.hasWrtNature(resource.getProject()); } } return false; } - private boolean isWrtProject(IProject project) { - return project.getFile("wrt_preview_frame.html").exists(); - } - private void loadPreferences() { synchronized (autorefresh) { if (preferencesLoaded) { diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools/META-INF/MANIFEST.MF --- a/org.symbian.tools.wrttools/META-INF/MANIFEST.MF Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools/META-INF/MANIFEST.MF Wed Jan 27 17:54:14 2010 -0800 @@ -45,4 +45,5 @@ Bundle-ClassPath: lib/tagsoup-1.2.jar, ., lib/jtidy-8.0-20060801.131059-3.jar -Export-Package: org.symbian.tools.wrttools.wizards +Export-Package: org.symbian.tools.wrttools.util, + org.symbian.tools.wrttools.wizards diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WidgetProjectNature.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WidgetProjectNature.java Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WidgetProjectNature.java Wed Jan 27 17:54:14 2010 -0800 @@ -28,6 +28,7 @@ import org.symbian.tools.wrttools.core.validator.WidgetProjectValidator; public class WidgetProjectNature implements IProjectNature { + public static final String ID = Activator.PLUGIN_ID + ".WidgetProjectNature"; private IProject project; diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Wed Jan 27 17:54:14 2010 -0800 @@ -18,7 +18,6 @@ */ package org.symbian.tools.wrttools.util; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.net.URI; @@ -28,25 +27,23 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; 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.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.WidgetProjectNature; public class ProjectUtils { private static final String DEFAULT_APTANA_WORKSPACE = "Aptana Studio Workspace"; - private static final String WRT_PREVIEW_MAIN_HTML = "wrt_preview_frame.html"; public static final String PREVIEW_FOLDER = "preview"; public static final String PREVIEW_FRAME_FILE = "wrt_preview_frame.html"; + public static final String PREVIEW_MAIN_FILE = "wrt_preview_main.html"; @SuppressWarnings("restriction") public static IProject createWrtProject(String name, URI uri, @@ -65,26 +62,35 @@ // BuildPathsBlock.flush(classPathEntries, javaScriptProject, superType, // monitor) + addWrtNature(project); monitor.done(); return project; } - public static void addPreviewer(IProject project, IPath mainHtml) { - try { - createPreviewerHomePage(project, mainHtml); - } 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); + public static void addWrtNature(IProject project) { + if (!hasWrtNature(project)) { + try { + IProjectDescription description = project.getDescription(); + String[] natureIds = description.getNatureIds(); + String[] newNatures = new String[natureIds.length + 1]; + System.arraycopy(natureIds, 0, newNatures, 1, natureIds.length); + newNatures[0] = WidgetProjectNature.ID; + description.setNatureIds(newNatures); + project.setDescription(description, new NullProgressMonitor()); + } catch (CoreException e) { + Activator.log(e); + } } } - private static void createPreviewerHomePage(IProject project, IPath mainHtml) - throws CoreException, IOException { - IFile newFile = project.getFile(WRT_PREVIEW_MAIN_HTML); - newFile.create(new ByteArrayInputStream("Should not be in release!" - .getBytes()), false, new NullProgressMonitor()); + public static boolean hasWrtNature(IProject project) { + try { + return project.hasNature(WidgetProjectNature.ID); + } catch (CoreException e) { + Activator.log(e); + return false; + } } public static String getDefaultAptanaLocation() { @@ -94,7 +100,8 @@ if (file.exists()) { return file.getAbsolutePath(); } - file = new File(myDocuments, "Documents" + File.separator + DEFAULT_APTANA_WORKSPACE); // Mac OS X + file = new File(myDocuments, "Documents" + File.separator + + DEFAULT_APTANA_WORKSPACE); // Mac OS X if (file.exists()) { return file.getAbsolutePath(); } @@ -106,15 +113,38 @@ && new File(f, PREVIEW_FRAME_FILE).isFile(); } - public static void copyFile(IProject project, String name, ZipInputStream stream, - long size, IProgressMonitor monitor) throws CoreException, - IOException { + 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)); + file.create(new NonClosingStream(stream), true, new SubProgressMonitor( + monitor, 1)); } public static boolean isAptanaProject(URI locationURI) { return isAptanaProject(new File(locationURI)); } + + public static File isAptanaProject(File[] contents) { + 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(IProjectDescription.DESCRIPTION_FILE_NAME)) { + dotProjectFile = file; + } + if (file.isFile() && PREVIEW_FRAME_FILE.equalsIgnoreCase(file.getName())) { + hasFrame = true; + } + if (file.isDirectory() && PREVIEW_FOLDER.equalsIgnoreCase(file.getName())) { + hasPreviewer = true; + } + } + if (!(hasFrame && hasPreviewer)) { + dotProjectFile = null; + } + return dotProjectFile; + } } diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 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 Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java Wed Jan 27 17:54:14 2010 -0800 @@ -343,7 +343,9 @@ private static final Collection EXCLUDED; static { - EXCLUDED = new TreeSet(Arrays.asList(".project", "preview", "wrt_preview_main.html")); + EXCLUDED = new TreeSet(Arrays.asList(".project", + ProjectUtils.PREVIEW_FOLDER, ProjectUtils.PREVIEW_FRAME_FILE, + ProjectUtils.PREVIEW_MAIN_FILE)); } public AptanaProjectLocationWizardPage() { @@ -412,26 +414,10 @@ } } - // 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)) { - 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) { + File dotProjectFile = ProjectUtils.isAptanaProject(contents); + + if (dotProjectFile != null) { files.add(dotProjectFile); // don't search sub-directories since we can't have nested // projects diff -r ba7c1ce1cc4a -r 5a2cfa9bc743 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 Wed Jan 27 15:59:22 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Wed Jan 27 17:54:14 2010 -0800 @@ -170,7 +170,6 @@ } } } - ProjectUtils.addPreviewer(project, new Path(context.getHtmlFileName())); } private void copyTemplate(IProject project, String name,