# HG changeset patch # User Eugene Ostroukhov # Date 1283383663 25200 # Node ID e908ec135fa1ad43e4dce0c343a2aad9917160b1 # Parent b6d992b9b99863699a83eb678236f0ae850dbd45 Application import wizard was refactored into extensible code diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/projects/AbstractJSDTFaceletDetector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/projects/AbstractJSDTFaceletDetector.java Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ +package org.symbian.tools.tmw.core.projects; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; +import org.eclipse.wst.common.project.facet.core.ProjectFacetDetector; + +public class AbstractJSDTFaceletDetector extends ProjectFacetDetector { + + @Override + public void detect(IFacetedProjectWorkingCopy fpjwc, IProgressMonitor monitor) throws CoreException { + // TODO Auto-generated method stub + + } + +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/utilities/CoreUtil.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/utilities/CoreUtil.java Tue Aug 31 15:21:04 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/utilities/CoreUtil.java Wed Sep 01 16:27:43 2010 -0700 @@ -18,7 +18,12 @@ */ package org.symbian.tools.tmw.core.utilities; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Platform; +import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.core.IType; +import org.eclipse.wst.jsdt.core.JavaScriptCore; +import org.eclipse.wst.jsdt.core.JavaScriptModelException; /** * Utilities used all over the TMW code base. Users can rely on this methods @@ -43,4 +48,29 @@ public static String notNull(final String string) { return string == null ? "" : string.trim(); } + + public final static boolean hasTypes(IProject p, String... typeNames) throws JavaScriptModelException { + final IJavaScriptProject project = JavaScriptCore.create(p); + if (project != null && project.exists()) { + for (String typeName : typeNames) { + if (!hasType(project, typeName)) { + return false; + } + } + } + return true; + } + + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=318656 + private static boolean hasType(IJavaScriptProject project, String name) throws JavaScriptModelException { + final IType[] types = project.findTypes(name); + if (types != null) { + for (IType type : types) { + if (type.getJavaScriptProject().equals(project)) { + return true; + } + } + } + return false; + } } diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/icons/full/etool16/importapplication.png Binary file plugins/org.symbian.tools.tmw.ui/icons/full/etool16/importapplication.png has changed diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/plugin.xml --- a/plugins/org.symbian.tools.tmw.ui/plugin.xml Tue Aug 31 15:21:04 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.ui/plugin.xml Wed Sep 01 16:27:43 2010 -0700 @@ -5,6 +5,7 @@ + + wizardId="org.symbian.tools.tmw.importapplication"> + + + + + + Create project from application archive + + + + + diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/schema/applicationImporter.exsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.ui/schema/applicationImporter.exsd Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,102 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [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 b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/importwizard/ApplicationImportWizard.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/importwizard/ApplicationImportWizard.java Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,195 @@ +package org.symbian.tools.tmw.internal.ui.importwizard; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.statushandlers.StatusManager; +import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; +import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; +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.runtime.IRuntime; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.internal.util.OpenFilesRunnable; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.project.IApplicationImporter; + +public class ApplicationImportWizard extends Wizard implements IImportWizard, INewWizard, IExecutableExtension { + public static final String RECENT_IMPORT_PATH = "application.import.path"; + + private IFile file; + private ApplicationImportWizardPage page; + private IConfigurationElement config; + + public ApplicationImportWizard() { + setWindowTitle("Import WRT Application Archive"); + // setDefaultPageImageDescriptor(WRTImages.importWgzWizardBanner()); + setNeedsProgressMonitor(true); + } + + @Override + public void addPages() { + page = new ApplicationImportWizardPage(file); + addPage(page); + } + + private IProject createProject(String archiveName, String projectName, URI uri, IApplicationImporter importer, + IProgressMonitor monitor) throws CoreException { + monitor.beginTask("Importing application archive", 50); + final IFacetedProjectWorkingCopy project = FacetedProjectFramework.createNewProject(); + final File file = new File(archiveName); + final IMobileWebRuntime applicationRuntime = importer.getApplicationRuntime(file); + final IRuntime runtime = TMWCore.getFProjSupport().getRuntime(applicationRuntime); + + project.setTargetedRuntimes(Collections.singleton(runtime)); + project.setPrimaryRuntime(runtime); + project.setProjectName(projectName); + if (uri != null) { + final File loc = new File(uri); + Path path = new Path(loc.getAbsolutePath()); + if (!path.removeLastSegments(1).equals(ResourcesPlugin.getWorkspace().getRoot().getLocation())) { + project.setProjectLocation(path); + } + } + final Set facets = getProjectFacetVersion(file, importer, applicationRuntime); + project.setProjectFacets(facets); + final Set fcoll = new HashSet(); + + for (IProjectFacetVersion facetVersion : facets) { + fcoll.add(facetVersion.getProjectFacet()); + } + project.setFixedProjectFacets(fcoll); + project.commitChanges(new SubProgressMonitor(monitor, 10)); + + boolean success = false; + try { + importer.extractFiles(file, applicationRuntime, project.getProject(), new SubProgressMonitor(monitor, 40)); + success = true; + } finally { + if (!success) { + project.getProject().delete(true, true, new NullProgressMonitor()); + } + } + final IFile[] toOpen = importer.getFilesToOpen(project.getProject()); + project.detect(new NullProgressMonitor()); + project.commitChanges(new NullProgressMonitor()); + monitor.done(); + if (toOpen != null && toOpen.length > 0) { + final OpenFilesRunnable runnable = new OpenFilesRunnable(new HashSet(Arrays.asList(toOpen))); + Display.getDefault().asyncExec(new Runnable() { + public void run() { + try { + runnable.run(new NullProgressMonitor()); + } catch (InvocationTargetException e) { + TMWCoreUI.log(e); + } catch (InterruptedException e) { + TMWCoreUI.log(e); + } + } + }); + } + return project.getProject(); + } + + private Set getProjectFacetVersion(final File file, IApplicationImporter importer, + final IMobileWebRuntime applicationRuntime) { + final Set facets = new HashSet(); + facets.addAll(TMWCore.getFProjSupport().getFixedFacetsVersions(applicationRuntime)); + final IProjectFacetVersion[] f = importer.getConfiguredFacets(file); + if (f != null && f.length > 0) { + facets.addAll(Arrays.asList(f)); + } + return facets; + } + + @Override + public boolean performFinish() { + try { + final String projectName = page.getProjectName(); + final URI uri = page.getLocationURI(); + final String archiveName = page.getArchiveFile(); + final IApplicationImporter importer = page.getImporter(); + + final IProject[] holder = new IProject[1]; + getContainer().run(true, true, new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { + + public void run(IProgressMonitor monitor) throws CoreException { + holder[0] = createProject(archiveName, projectName, uri, importer, monitor); + } + + }, monitor); + } catch (final CoreException e) { + getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + StatusManager.getManager().handle(e.getStatus(), + StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG); + } + }); + } + } + }); + if (holder[0] != null) { + BasicNewProjectResourceWizard.updatePerspective(config); + TMWCoreUI.getDefault().getPreferenceStore() + .setValue(RECENT_IMPORT_PATH, new File(archiveName).getParentFile().getAbsolutePath()); + // ProjectUtils.focusOn(holder[0]); + } + } catch (InvocationTargetException e) { + TMWCoreUI.log(e); + } catch (InterruptedException e) { + TMWCoreUI.log(e); + } + return true; + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + file = null; + if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + Object element = (selection).getFirstElement(); + if (element instanceof IAdaptable) { + IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class); + if (resource != null && resource.getType() == IResource.FILE + && "wgz".equalsIgnoreCase(resource.getProjectRelativePath().getFileExtension())) { + file = (IFile) resource; + } + } + } + } + + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) + throws CoreException { + this.config = config; + } + +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/importwizard/ApplicationImportWizardPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/importwizard/ApplicationImportWizardPage.java Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,504 @@ +package org.symbian.tools.tmw.internal.ui.importwizard; + +import java.io.File; +import java.net.URI; +import java.text.MessageFormat; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import org.eclipse.core.resources.IFile; +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.jface.dialogs.Dialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.wizard.WizardPage; +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.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; +import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea; +import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.ui.TMWCoreUI; +import org.symbian.tools.tmw.ui.project.IApplicationImporter; + +@SuppressWarnings("restriction") +public class ApplicationImportWizardPage extends WizardPage { + public class MapContentProvider implements IStructuredContentProvider { + + public void dispose() { + // Do nothing + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // Do nothing + } + + @SuppressWarnings("unchecked") + public Object[] getElements(Object inputElement) { + return ((Map) inputElement).entrySet().toArray(); + } + + } + + // constants + private static final int SIZING_TEXT_FIELD_WIDTH = 250; + private final IFile file; + // initial value stores + private String initialProjectFieldValue; + private ProjectContentsLocationArea locationArea; + private final Listener nameModifyListener = new Listener() { + public void handleEvent(Event e) { + setLocationForSelection(); + boolean valid = validatePage(); + setPageComplete(valid); + + } + }; + // widgets + private Text projectNameField; + private Text fileName; + private ComboViewer runtimes; + + protected ApplicationImportWizardPage(IFile file) { + super("ImportApplication"); + this.file = file; + setTitle("Import Mobile Web Application"); + setDescription("Create mobile web application project from application package file"); + setPageComplete(false); + } + + protected void browse() { + FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); + String path = fileName.getText(); + path = path.trim().length() > 0 ? path.trim() : TMWCoreUI.getDefault().getPreferenceStore() + .getString(ApplicationImportWizard.RECENT_IMPORT_PATH); + fileDialog.setFilterPath(path); + + final Map filters = new TreeMap(); + filters.put("*", "All files (*.*)"); + final IApplicationImporter[] importers = TMWCoreUI.getApplicationImporters(); + for (IApplicationImporter importer : importers) { + filters.putAll(importer.getFileFilters()); + } + + final String[] extensions = filters.keySet().toArray(new String[filters.size()]); + final String[] names = filters.values().toArray(new String[filters.size()]); + + fileDialog.setFilterExtensions(extensions); + fileDialog.setFilterNames(names); + String res = fileDialog.open(); + if (res != null) { + updateWgzName(path.trim(), res); + fileName.setText(res); + setPageComplete(validatePage()); + } + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NULL); + + initializeDialogUnits(parent); + + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + createProjectNameGroup(composite); + locationArea = new ProjectContentsLocationArea(getErrorReporter(), composite); + if (initialProjectFieldValue != null) { + locationArea.updateProjectName(initialProjectFieldValue); + } + + // Scale the button based on the rest of the dialog + setButtonLayoutData(locationArea.getBrowseButton()); + if (file != null) { + fileName.setText(file.getLocation().toOSString()); + } + setPageComplete(validatePage()); + // Show description on opening + setErrorMessage(null); + setMessage(null); + setControl(composite); + Dialog.applyDialogFont(composite); + + setControl(composite); + } + + /** + * Creates the project name specification controls. + * + * @param parent + * the parent composite + */ + private final void createProjectNameGroup(Composite parent) { + // project specification group + Composite projectGroup = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label label = new Label(projectGroup, SWT.NONE); + label.setText("WGZ archive:"); + + Composite buttonText = new Composite(projectGroup, SWT.NONE); + + buttonText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + GridLayout gridLayout = new GridLayout(2, false); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + buttonText.setLayout(gridLayout); + + fileName = new Text(buttonText, SWT.BORDER); + fileName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fileName.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String val = fileName.getData() != null ? fileName.getData().toString() : ""; + String name = fileName.getText().trim(); + updateWgzName(val, name); + fileName.setData(name); + setPageComplete(validatePage()); + } + }); + Button browse = new Button(buttonText, SWT.NONE); + browse.setText("Browse..."); + browse.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + browse(); + } + }); + + new Label(projectGroup, SWT.NONE).setText("Targeted runtime:"); + runtimes = new ComboViewer(projectGroup, SWT.BORDER | SWT.READ_ONLY); + runtimes.getCombo().setEnabled(false); + runtimes.setContentProvider(new MapContentProvider()); + runtimes.setLabelProvider(new LabelProvider() { + @SuppressWarnings("unchecked") + @Override + public String getText(Object element) { + return ((Map.Entry) element).getKey().toString(); + } + }); + runtimes.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + runtimes.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + setPageComplete(validatePage()); + } + }); + + Label separator = new Label(projectGroup, SWT.NONE); + GridDataFactory.generate(separator, 2, 2); + + // new project label + Label projectLabel = new Label(projectGroup, SWT.NONE); + projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel); + projectLabel.setFont(parent.getFont()); + + // new project name entry field + projectNameField = new Text(projectGroup, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = SIZING_TEXT_FIELD_WIDTH; + projectNameField.setLayoutData(data); + projectNameField.setFont(parent.getFont()); + + // Set the initial value first before listener + // to avoid handling an event during the creation. + if (initialProjectFieldValue != null) { + projectNameField.setText(initialProjectFieldValue); + } + projectNameField.addListener(SWT.Modify, nameModifyListener); + } + + public String getArchiveFile() { + return fileName.getText().trim(); + } + + /** + * 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); + } + }; + } + + /** + * 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 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(); + } + + /** + * Creates a project resource handle for the current project name field + * value. The project handle is created relative to the workspace root. + *

+ * This method does not create the project resource; this is the + * responsibility of IProject::create invoked by the new + * project resource wizard. + *

+ * + * @return the new project resource handle + */ + public IProject getProjectHandle() { + return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName()); + } + + /** + * Returns the current project name as entered by the user, or its + * anticipated initial value. + * + * @return the project name, its anticipated initial value, or + * null if no project name is known + */ + public String getProjectName() { + if (projectNameField == null) { + return initialProjectFieldValue; + } + + return getProjectNameFieldValue(); + } + + /** + * Returns the value of the project name field with leading and trailing + * spaces removed. + * + * @return the project name in the field + */ + private String getProjectNameFieldValue() { + if (projectNameField == null) { + return ""; //$NON-NLS-1$ + } + + return projectNameField.getText().trim(); + } + + /** + * Sets the initial project name that this page will use when created. The + * name is ignored if the createControl(Composite) method has already been + * called. Leading and trailing spaces in the name are ignored. Providing + * the name of an existing project will not necessarily cause the wizard to + * warn the user. Callers of this method should first check if the project + * name passed already exists in the workspace. + * + * @param name + * initial project name for this page + * + * @see IWorkspace#validateName(String, int) + * + */ + public void setInitialProjectName(String name) { + if (name == null) { + initialProjectFieldValue = null; + } else { + initialProjectFieldValue = name.trim(); + if (locationArea != null) { + locationArea.updateProjectName(name.trim()); + } + } + } + + /** + * Set the location to the default location if we are set to useDefaults. + */ + void setLocationForSelection() { + locationArea.updateProjectName(getProjectNameFieldValue()); + } + + private void updateWgzName(String oldValue, String newValue) { + String project = projectNameField.getText().trim(); + if (project.length() == 0 || project.equals(new Path(oldValue).removeFileExtension().lastSegment())) { + String projectName = new Path(newValue).removeFileExtension().lastSegment(); + projectNameField.setText(projectName); + locationArea.updateProjectName(projectName); + } + } + + /** + * Returns the useDefaults. + * + * @return boolean + */ + public boolean useDefaults() { + return locationArea.isDefault(); + } + + private boolean validating = false; + + /** + * 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 synchronized boolean validatePage() { + if (validating) { + return true; + } + validating = true; + try { + final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace(); + final String archive = fileName.getText().trim(); + if (archive.equals("")) { + setErrorMessage(null); + setMessage("Archive name must be specified"); + return false; + } + + final File f = new File(archive); + if (!isValidArchive(f)) { + setErrorMessage(MessageFormat.format("{0} is not a valid application archive", archive)); + return false; + } + + final String projectFieldContents = getProjectNameFieldValue(); + if (projectFieldContents.equals("")) { //$NON-NLS-1$ + setErrorMessage(null); + setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty); + return false; + } + + final IStatus nameStatus = workspace.validateName(projectFieldContents, IResource.PROJECT); + if (!nameStatus.isOK()) { + setErrorMessage(nameStatus.getMessage()); + return false; + } + + final IProject handle = getProjectHandle(); + if (handle.exists()) { + setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage); + return false; + } + + final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectNameFieldValue()); + locationArea.setExistingProject(project); + + final String validLocationMessage = locationArea.checkValidLocation(); + if (validLocationMessage != null) { // there is no destination location given + setErrorMessage(validLocationMessage); + return false; + } + if (runtimes.getSelection().isEmpty()) { + setErrorMessage("Select target runtime"); + return false; + } + + setErrorMessage(null); + setMessage(null); + return true; + } finally { + validating = false; + } + } + + private boolean isValidArchive(File f) { + if (f.isFile()) { + final Map importers = new TreeMap(); + final IApplicationImporter[] applicationImporters = TMWCoreUI.getApplicationImporters(); + for (IApplicationImporter importer : applicationImporters) { + final IMobileWebRuntime runtime = importer.getApplicationRuntime(f); + if (runtime != null) { + importers.put(runtime.getName(), importer); + } + } + final ISelection selection = runtimes.getSelection(); + Object sel = null; + if (!selection.isEmpty()) { + @SuppressWarnings("unchecked") + Map.Entry entry = (Entry) ((IStructuredSelection) selection) + .getFirstElement(); + for (Entry ent : importers.entrySet()) { + if (ent.getKey().equals(entry.getKey())) { + sel = ent; + } + } + } + runtimes.setInput(importers); + if (sel != null) { + runtimes.setSelection(new StructuredSelection(sel)); + } else if (importers.size() == 1) { + runtimes.setSelection(new StructuredSelection(importers.entrySet().iterator().next())); + } + runtimes.getControl().setEnabled(importers.size() > 1); + return !runtimes.getSelection().isEmpty(); + } + return false; + } + + public IApplicationImporter getImporter() { + if (runtimes == null || runtimes.getControl().isDisposed()) { + return null; + } + @SuppressWarnings("unchecked") + final Map.Entry element = (Entry) ((IStructuredSelection) runtimes + .getSelection()).getFirstElement(); + return element.getValue(); + } + +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java --- a/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java Tue Aug 31 15:21:04 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/ui/TMWCoreUI.java Wed Sep 01 16:27:43 2010 -0700 @@ -1,10 +1,15 @@ package org.symbian.tools.tmw.ui; +import java.util.Collection; +import java.util.LinkedList; import java.util.Map; import java.util.WeakHashMap; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -13,23 +18,93 @@ 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.IApplicationImporter; import org.symbian.tools.tmw.ui.project.IProjectTemplateManager; /** * The activator class controls the plug-in life cycle */ public class TMWCoreUI extends AbstractUIPlugin { - private final Map MEMOS = new WeakHashMap(); - private final DeploymentTargetTypesRegistry typesRegistry = new DeploymentTargetTypesRegistry(); - + // The shared instance + private static TMWCoreUI plugin; // The plug-in ID public static final String PLUGIN_ID = "org.symbian.tools.tmw.ui"; //$NON-NLS-1$ - // The shared instance - private static TMWCoreUI plugin; + public static IApplicationImporter[] getApplicationImporters() { + if (getDefault().importers == null) { + final Collection collection = new LinkedList(); + final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( + PLUGIN_ID, "applicationImporter"); + for (IConfigurationElement element : elements) { + try { + collection.add((IApplicationImporter) element.createExecutableExtension("class")); + } catch (CoreException e) { + TMWCoreUI.log(String.format( + "Application importer %s cannot be instantiated. It is declared in plug-in %s", + element.getAttribute("class"), element.getContributor().getName()), e); + } + } + getDefault().importers = collection.toArray(new IApplicationImporter[collection.size()]); + } + return getDefault().importers; + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TMWCoreUI getDefault() { + return plugin; + } + public static Images getImages() { + if (getDefault().images == null) { + getDefault().images = new Images(getDefault().getImageRegistry()); + } + return getDefault().images; + } + public static ProjectMemo getMemo(ITMWProject project) { + return getDefault().getMemoForProject(project); + } + public static IProjectTemplateManager getProjectTemplateManager() { + return getDefault().projectTemplateManager; + } + + public static void log(Exception e) { + log(null, e); + } + + public static void log(String message, Exception e) { + getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, e)); + } + + public static void log(String message, Object... args) { + log(String.format(message, args), (Exception) null); + } + + private Images images; + private IApplicationImporter[] importers; + private final Map MEMOS = new WeakHashMap(); + private final DeploymentTargetPresentationsManager presentations = new DeploymentTargetPresentationsManager(); private IProjectTemplateManager projectTemplateManager; - private Images images; - private final DeploymentTargetPresentationsManager presentations = new DeploymentTargetPresentationsManager(); + private final DeploymentTargetTypesRegistry typesRegistry = new DeploymentTargetTypesRegistry(); + + public DeploymentTargetTypesRegistry getDeploymentTypesRegistry() { + return typesRegistry; + } + + private synchronized ProjectMemo getMemoForProject(ITMWProject project) { + ProjectMemo memo = MEMOS.get(project.getProject()); + if (memo == null) { + memo = new ProjectMemo(project); + MEMOS.put(project.getProject(), memo); + } + return memo; + } + + public DeploymentTargetPresentationsManager getPresentations() { + return presentations; + } @Override protected void initializeImageRegistry(ImageRegistry reg) { @@ -46,57 +121,4 @@ plugin = null; super.stop(context); } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static TMWCoreUI getDefault() { - return plugin; - } - - public static void log(String message, Exception e) { - getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, e)); - } - - public static void log(String message, Object... args) { - log(String.format(message, args), (Exception) null); - } - - public static void log(Exception e) { - log(null, e); - } - - public static ProjectMemo getMemo(ITMWProject project) { - return getDefault().getMemoForProject(project); - } - - private synchronized ProjectMemo getMemoForProject(ITMWProject project) { - ProjectMemo memo = MEMOS.get(project.getProject()); - if (memo == null) { - memo = new ProjectMemo(project); - MEMOS.put(project.getProject(), memo); - } - return memo; - } - - public DeploymentTargetTypesRegistry getDeploymentTypesRegistry() { - return typesRegistry; - } - - public static Images getImages() { - if (getDefault().images == null) { - getDefault().images = new Images(getDefault().getImageRegistry()); - } - return getDefault().images; - } - - public DeploymentTargetPresentationsManager getPresentations() { - return presentations; - } - - public static IProjectTemplateManager getProjectTemplateManager() { - return getDefault().projectTemplateManager; - } } diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/ui/project/AbstractZippedApplicationImporter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/ui/project/AbstractZippedApplicationImporter.java Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,102 @@ +/** + * 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.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +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.resources.IResource; +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.Path; +import org.eclipse.core.runtime.Status; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.core.utilities.NonClosingStream; +import org.symbian.tools.tmw.ui.TMWCoreUI; + +/** + * This is base class for importers that work with zip-based application + * packages. W3C specification mandates using Zip as archive format and + * it looks like all mobile web runtime use Zip as their format. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public abstract class AbstractZippedApplicationImporter implements IApplicationImporter { + public Map getFileFilters() { + return Collections.singletonMap("*.zip", "Application Archive (*.zip)"); + } + + public void extractFiles(File file, IMobileWebRuntime runtime, IProject project, IProgressMonitor monitor) + throws CoreException { + ZipInputStream zipInputStream = null; + try { + zipInputStream = new ZipInputStream(new FileInputStream(file)); + ZipEntry entry = null; + while ((entry = zipInputStream.getNextEntry()) != null) { + if (!entry.isDirectory()) { + final IPath path = getApplicationRelativePath(entry); + final IFile f = project.getFile(path); + if (!f.exists()) { + createContainers(f.getParent()); + f.create(new NonClosingStream(zipInputStream), false, new NullProgressMonitor()); + } + } + } + } catch (IOException e) { + throw new CoreException(new Status(IStatus.ERROR, TMWCoreUI.PLUGIN_ID, String.format( + "Cannot extract files from archive %s", file.getAbsoluteFile()), e)); + } finally { + if (zipInputStream != null) { + try { + zipInputStream.close(); + } catch (IOException e) { + // Do nothing + } + } + } + } + + private void createContainers(IContainer parent) throws CoreException { + if (parent != null && !parent.exists() && parent.getType() == IResource.FOLDER) { + createContainers(parent.getParent()); + ((IFolder) parent).create(false, true, new NullProgressMonitor()); + } + } + + /** + * This base calss assumes application files are in the application + * package root. Symbian WRT has files in the subfolder so it will need + * to override this method. + */ + protected IPath getApplicationRelativePath(ZipEntry entry) { + return new Path(entry.getName()); + } +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/ui/project/IApplicationImporter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/ui/project/IApplicationImporter.java Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,80 @@ +/** + * 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.File; +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; + +/** + * Classes implementing this interface help create projects from application + * archives. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IApplicationImporter { + /** + * Importer can support only one runtime (i.e. several extensions need to + * be contributed for several runtimes). + * + * @param file application package + * @return runtime that created project should target. null if + * this importer can't import the file. + */ + IMobileWebRuntime getApplicationRuntime(File file); + + /** + * @return filters that users can use to navigate filesystem. They are + * returned as "file extension-description" pairs + * @see org.eclipse.swt.widgets.FileDialog#setFilterExtensions(String[]) + * @see org.eclipse.swt.widgets.FileDialog#setFilterNames(String[]) + */ + Map getFileFilters(); + + /** + * @param file application package + * @return collection of the enabled facets. These facets will be "locked" + * on the project + */ + IProjectFacetVersion[] getConfiguredFacets(File file); + + /** + * Extracts files from application archive to workspace project + * + * @param file mobile web application archive + * @param runtime mobile web runtime + * @param project workspace project + * @param monitor progress monitor + * @throws CoreException this exception signals failure to extract files + */ + void extractFiles(File file, IMobileWebRuntime runtime, IProject project, IProgressMonitor monitor) + throws CoreException; + + /** + * @param project newly imported application project + * @return collection of the files to open + */ + IFile[] getFilesToOpen(IProject project); +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.wrttools/plugin.xml --- a/plugins/org.symbian.tools.wrttools/plugin.xml Tue Aug 31 15:21:04 2010 -0700 +++ b/plugins/org.symbian.tools.wrttools/plugin.xml Wed Sep 01 16:27:43 2010 -0700 @@ -104,9 +104,7 @@ - - - @@ -114,18 +112,7 @@ Import WRT project created in Aptana, Adobe Dreamweaver or WRT IDE - - - - Create WRT project from deployable WGZ application archive - - - + @@ -657,7 +644,6 @@ component-version="1.1" name="Symbian WRT 1.1"> @@ -1057,5 +1043,20 @@ runtime-version="1.1"> + + + + + + + + + + diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PhoneGapFacetDetector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PhoneGapFacetDetector.java Wed Sep 01 16:27:43 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.wrttools.core.libraries; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +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.ProjectFacetDetector; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.symbian.tools.tmw.core.utilities.CoreUtil; + +public class PhoneGapFacetDetector extends ProjectFacetDetector { + + @Override + public void detect(IFacetedProjectWorkingCopy fpjwc, IProgressMonitor monitor) throws CoreException { + if (CoreUtil.hasTypes(fpjwc.getProject(), "AccelerationOptions", "DeviceError")) { + final IProjectFacet facet = ProjectFacetsManager.getProjectFacet("symbian.phonegap"); + final IProjectFacetVersion latestVersion = facet.getLatestVersion(); + fpjwc.addProjectFacet(latestVersion); + fpjwc.setProjectFacetActionConfig(facet, null); + } + } + +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/WrtKitFacetDetector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/WrtKitFacetDetector.java Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ +package org.symbian.tools.wrttools.core.libraries; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +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.ProjectFacetDetector; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.symbian.tools.tmw.core.utilities.CoreUtil; + +public class WrtKitFacetDetector extends ProjectFacetDetector { + @Override + public void detect(IFacetedProjectWorkingCopy fpjwc, IProgressMonitor monitor) throws CoreException { + if (CoreUtil.hasTypes(fpjwc.getProject(), "UIManager", "NavigationButton", "NotificationPopup")) { + final IProjectFacet facet = ProjectFacetsManager.getProjectFacet("symbian.wrtkit"); + final IProjectFacetVersion latestVersion = facet.getLatestVersion(); + fpjwc.addProjectFacet(latestVersion); + fpjwc.setProjectFacetActionConfig(facet, null); + } + } + +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/project/WgzImporter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/project/WgzImporter.java Wed Sep 01 16:27:43 2010 -0700 @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ +package org.symbian.tools.wrttools.core.project; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Map; +import java.util.TreeMap; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; +import org.symbian.tools.tmw.ui.project.AbstractZippedApplicationImporter; +import org.symbian.tools.wrttools.Activator; +import org.symbian.tools.wrttools.WRTProject; +import org.symbian.tools.wrttools.util.CoreUtil; + +public class WgzImporter extends AbstractZippedApplicationImporter { + + public IMobileWebRuntime getApplicationRuntime(File file) { + if (file.isFile()) { + ZipInputStream stream = null; + try { + stream = new ZipInputStream(new FileInputStream(file)); + ZipEntry entry = null; + while ((entry = stream.getNextEntry()) != null) { + if (!entry.isDirectory()) { + IPath path = new Path(entry.getName()); + if (path.segmentCount() == 2 && "Info.plist".equalsIgnoreCase(path.lastSegment())) { + return TMWCore.getRuntimesManager().getRuntime(WRTProject.WRT11_RUNTIME, + WRTProject.WRT11_VERSION); + } + } + } + } catch (IOException e) { + Activator.log(e); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + Activator.log(e); + } + } + } + } + return null; + } + + public Map getFileFilters() { + Map filters = new TreeMap(); + filters.put("*.wgz", "WRT Application Archive (*.wgz)"); + filters.put("*.zip", "Zip Archive (*.zip)"); + return filters; + } + + public IFile[] getFilesToOpen(IProject project) { + try { + return new IFile[] { CoreUtil.getIndexFile(project) }; + } catch (CoreException e) { + Activator.log(e); + return null; + } + } + + public IProjectFacetVersion[] getConfiguredFacets(File file) { + return null; + } + + @Override + protected IPath getApplicationRelativePath(ZipEntry entry) { + return new Path(entry.getName()).removeFirstSegments(1); + } +} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java --- a/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java Tue Aug 31 15:21:04 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -package org.symbian.tools.wrttools.wizards; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.net.URI; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.statushandlers.StatusManager; -import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; -import org.symbian.tools.wrttools.Activator; -import org.symbian.tools.wrttools.core.WRTImages; -import org.symbian.tools.wrttools.core.WrtIdeCorePreferences; -import org.symbian.tools.wrttools.util.ProjectUtils; - -public class WgzImportWizard extends Wizard implements IImportWizard, INewWizard, IExecutableExtension { - private IFile file; - private WgzImportWizardPage page; - private IConfigurationElement config; - - public WgzImportWizard() { - setWindowTitle("Import WRT Application Archive"); - setDefaultPageImageDescriptor(WRTImages.importWgzWizardBanner()); - setNeedsProgressMonitor(true); - } - - @Override - public void addPages() { - page = new WgzImportWizardPage(file); - addPage(page); - } - - private IProject createProject(String archiveName, String projectName, URI uri, - IProgressMonitor monitor) throws CoreException { - monitor.beginTask("Importing WRT application archive", 50); - // 1. Create project - IProject project = ProjectUtils.createWrtProject(projectName, uri, - new SubProgressMonitor(monitor, 10)); - - // 2. Unpack archive - boolean success = false; - try { - // TODO - // ProjectUtils.unzip(archiveName, project, 1, new SubProgressMonitor( - // monitor, 40)); - success = true; - // throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - // - // } catch (IO"Archive unpacking failed", e)); - } finally { - if (!success) { - project.delete(true, true, new NullProgressMonitor()); - } - } - monitor.done(); - return project; - } - - @Override - public boolean performFinish() { - try { - final String projectName = page.getProjectName(); - final URI uri = page.getLocationURI(); - final String archiveName = page.getArchiveFile(); - final IProject[] holder = new IProject[1]; - getContainer().run(true, true, new IRunnableWithProgress() { - - public void run(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - try { - ResourcesPlugin.getWorkspace().run( - new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) - throws CoreException { - holder[0] = createProject(archiveName, projectName, - uri, monitor); - } - - }, monitor); - } catch (final CoreException e) { - getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - StatusManager.getManager().handle(e.getStatus(), - StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG); - } - }); - } - } - }); - if (holder[0] != null) { - BasicNewProjectResourceWizard.updatePerspective(config); - Activator.getDefault().getPreferenceStore().setValue(WrtIdeCorePreferences.WGZ_IMPORT_PATH, - new File(archiveName).getParentFile().getAbsolutePath()); - ProjectUtils.focusOn(holder[0]); - } - } catch (InvocationTargetException e) { - Activator.log(e); - } catch (InterruptedException e) { - Activator.log(e); - } - return true; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - file = null; - if (selection instanceof IStructuredSelection && !selection.isEmpty()) { - Object element = (selection) - .getFirstElement(); - if (element instanceof IAdaptable) { - IResource resource = (IResource) ((IAdaptable) element) - .getAdapter(IResource.class); - if (resource != null - && resource.getType() == IResource.FILE - && "wgz".equalsIgnoreCase(resource - .getProjectRelativePath().getFileExtension())) { - file = (IFile) resource; - } - } - } - } - - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) - throws CoreException { - this.config = config; - } - -} diff -r b6d992b9b998 -r e908ec135fa1 plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java --- a/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java Tue Aug 31 15:21:04 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,467 +0,0 @@ -package org.symbian.tools.wrttools.wizards; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URI; -import java.text.MessageFormat; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import org.eclipse.core.resources.IFile; -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.jface.dialogs.Dialog; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.WizardPage; -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.Event; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.WorkingSetGroup; -import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; -import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; -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.wrttools.Activator; -import org.symbian.tools.wrttools.core.WrtIdeCorePreferences; -import org.symbian.tools.wrttools.util.CoreUtil; - -@SuppressWarnings("restriction") -public class WgzImportWizardPage extends WizardPage { - // constants - private static final int SIZING_TEXT_FIELD_WIDTH = 250; - - private final IFile file; - // initial value stores - private String initialProjectFieldValue; - private ProjectContentsLocationArea locationArea; - private final Listener nameModifyListener = new Listener() { - public void handleEvent(Event e) { - setLocationForSelection(); - boolean valid = validatePage(); - setPageComplete(valid); - - } - }; - // widgets - private Text projectNameField; - private Text wgzName; - private WorkingSetGroup workingSetGroup; - - protected WgzImportWizardPage(IFile file) { - super("ImportWgz"); - this.file = file; - setTitle("Import WGZ Archive"); - setDescription("Import WGZ archive as a new WRT application project"); - setPageComplete(false); - } - - protected void browse() { - FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); - String path = wgzName.getText(); - path = path.trim().length() > 0 ? path.trim() : Activator.getDefault().getPreferenceStore().getString( - WrtIdeCorePreferences.WGZ_IMPORT_PATH); - fileDialog.setFilterPath(path); - fileDialog.setFilterExtensions(new String[] {"*.wgz", "*.*"} ); - fileDialog.setFilterNames(new String[] {"WRT Archive (wgz)", "All Files"} ); - String res = fileDialog.open(); - if (res != null) { - updateWgzName(path.trim(), res); - wgzName.setText(res); - setPageComplete(validatePage()); - } - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - - initializeDialogUnits(parent); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, - IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE); - - composite.setLayout(new GridLayout()); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - createProjectNameGroup(composite); - locationArea = new ProjectContentsLocationArea(getErrorReporter(), - composite); - if (initialProjectFieldValue != null) { - locationArea.updateProjectName(initialProjectFieldValue); - } - - // Scale the button based on the rest of the dialog - setButtonLayoutData(locationArea.getBrowseButton()); - - if (file != null) { - wgzName.setText(file.getLocation().toOSString()); - } - - setPageComplete(validatePage()); - // Show description on opening - setErrorMessage(null); - setMessage(null); - setControl(composite); - Dialog.applyDialogFont(composite); - - setControl(composite); - } - - /** - * Creates the project name specification controls. - * - * @param parent - * the parent composite - */ - private final void createProjectNameGroup(Composite parent) { - // project specification group - Composite projectGroup = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - projectGroup.setLayout(layout); - projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label label = new Label(projectGroup, SWT.NONE); - label.setText("WGZ archive:"); - - Composite buttonText = new Composite(projectGroup, SWT.NONE); - - buttonText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - GridLayout gridLayout = new GridLayout(2, false); - gridLayout.marginWidth = 0; - gridLayout.marginHeight = 0; - buttonText.setLayout(gridLayout); - - wgzName = new Text(buttonText, SWT.BORDER); - wgzName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - wgzName.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - String val = wgzName.getData() != null ? wgzName.getData() - .toString() : ""; - String name = wgzName.getText().trim(); - updateWgzName(val, name); - wgzName.setData(name); - setPageComplete(validatePage()); - } - }); - Button browse = new Button(buttonText, SWT.NONE); - browse.setText("Browse..."); - browse.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - browse(); - } - }); - - Label separator = new Label(projectGroup, SWT.NONE); - GridDataFactory.generate(separator, 2, 2); - - // new project label - Label projectLabel = new Label(projectGroup, SWT.NONE); - projectLabel - .setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel); - projectLabel.setFont(parent.getFont()); - - // new project name entry field - projectNameField = new Text(projectGroup, SWT.BORDER); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = SIZING_TEXT_FIELD_WIDTH; - projectNameField.setLayoutData(data); - projectNameField.setFont(parent.getFont()); - - // Set the initial value first before listener - // to avoid handling an event during the creation. - if (initialProjectFieldValue != null) { - projectNameField.setText(initialProjectFieldValue); - } - projectNameField.addListener(SWT.Modify, nameModifyListener); - } - - /** - * Create a working set group for this page. This method can only be called - * once. - * - * @param composite - * the composite in which to create the group - * @param selection - * the current workbench selection - * @param supportedWorkingSetTypes - * an array of working set type IDs that will restrict what types - * of working sets can be chosen in this group - * @return the created group. If this method has been called previously the - * original group will be returned. - * @since 3.4 - */ - public WorkingSetGroup createWorkingSetGroup(Composite composite, - IStructuredSelection selection, String[] supportedWorkingSetTypes) { - if (workingSetGroup != null) { - return workingSetGroup; - } - workingSetGroup = new WorkingSetGroup(composite, selection, - supportedWorkingSetTypes); - return workingSetGroup; - } - - public String getArchiveFile() { - return wgzName.getText().trim(); - } - - /** - * 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); - } - }; - } - - /** - * 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 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(); - } - - /** - * Creates a project resource handle for the current project name field - * value. The project handle is created relative to the workspace root. - *

- * This method does not create the project resource; this is the - * responsibility of IProject::create invoked by the new - * project resource wizard. - *

- * - * @return the new project resource handle - */ - public IProject getProjectHandle() { - return ResourcesPlugin.getWorkspace().getRoot().getProject( - getProjectName()); - } - - /** - * Returns the current project name as entered by the user, or its - * anticipated initial value. - * - * @return the project name, its anticipated initial value, or - * null if no project name is known - */ - public String getProjectName() { - if (projectNameField == null) { - return initialProjectFieldValue; - } - - return getProjectNameFieldValue(); - } - - /** - * Returns the value of the project name field with leading and trailing - * spaces removed. - * - * @return the project name in the field - */ - private String getProjectNameFieldValue() { - if (projectNameField == null) { - return ""; //$NON-NLS-1$ - } - - return projectNameField.getText().trim(); - } - - /** - * Return the selected working sets, if any. If this page is not configured - * to interact with working sets this will be an empty array. - * - * @return the selected working sets - * @since 3.4 - */ - public IWorkingSet[] getSelectedWorkingSets() { - return workingSetGroup == null ? new IWorkingSet[0] : workingSetGroup - .getSelectedWorkingSets(); - } - - /** - * Sets the initial project name that this page will use when created. The - * name is ignored if the createControl(Composite) method has already been - * called. Leading and trailing spaces in the name are ignored. Providing - * the name of an existing project will not necessarily cause the wizard to - * warn the user. Callers of this method should first check if the project - * name passed already exists in the workspace. - * - * @param name - * initial project name for this page - * - * @see IWorkspace#validateName(String, int) - * - */ - public void setInitialProjectName(String name) { - if (name == null) { - initialProjectFieldValue = null; - } else { - initialProjectFieldValue = name.trim(); - if (locationArea != null) { - locationArea.updateProjectName(name.trim()); - } - } - } - - /** - * Set the location to the default location if we are set to useDefaults. - */ - void setLocationForSelection() { - locationArea.updateProjectName(getProjectNameFieldValue()); - } - - private void updateWgzName(String oldValue, String newValue) { - String project = projectNameField.getText().trim(); - if (project.length() == 0 || project.equals(new Path(oldValue).removeFileExtension().lastSegment())) { - String projectName = new Path(newValue).removeFileExtension().lastSegment(); - projectNameField.setText(projectName); - locationArea.updateProjectName(projectName); - } - } - - /** - * Returns the useDefaults. - * - * @return boolean - */ - public boolean useDefaults() { - return locationArea.isDefault(); - } - - /** - * 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() { - IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace(); - - String archive = wgzName.getText().trim(); - - if (archive.equals("")) { - setErrorMessage(null); - setMessage("Archive name must be specified"); - return false; - } - - File f = new File(archive); - if (!isValidArchive(f)) { - setErrorMessage(MessageFormat.format("{0} is not a valid WRT archive", archive)); - return false; - } - - String projectFieldContents = getProjectNameFieldValue(); - if (projectFieldContents.equals("")) { //$NON-NLS-1$ - setErrorMessage(null); - setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty); - return false; - } - - IStatus nameStatus = workspace.validateName(projectFieldContents, - IResource.PROJECT); - if (!nameStatus.isOK()) { - setErrorMessage(nameStatus.getMessage()); - return false; - } - - IProject handle = getProjectHandle(); - if (handle.exists()) { - setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage); - return false; - } - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( - getProjectNameFieldValue()); - locationArea.setExistingProject(project); - - String validLocationMessage = locationArea.checkValidLocation(); - if (validLocationMessage != null) { // there is no destination location - // given - setErrorMessage(validLocationMessage); - return false; - } - - setErrorMessage(null); - setMessage(null); - return true; - } - - private boolean isValidArchive(File f) { - if (f.isFile()) { - try { - final ZipInputStream stream = new ZipInputStream(new FileInputStream(f)); - ZipEntry entry; - while ((entry = stream.getNextEntry()) != null) { - final IPath path = new Path(entry.getName()); - if (path.segmentCount() == 2 && CoreUtil.METADATA_FILE.equalsIgnoreCase(path.segment(1))) { - return true; - } - } - } catch (IOException e) { - // Not a valid archive - } - } - return false; - } - -}