org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Thu, 11 Feb 2010 16:56:30 -0800
changeset 139 f0a865ead60b
parent 63 558819056485
child 190 13a34213b146
permissions -rw-r--r--
Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
package org.symbian.tools.wrttools.wizards;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
import java.io.IOException;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
import java.lang.reflect.InvocationTargetException;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
import java.net.URI;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
import org.eclipse.core.resources.IFile;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
import org.eclipse.core.resources.IProject;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
import org.eclipse.core.resources.IResource;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
import org.eclipse.core.resources.IWorkspaceRunnable;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
import org.eclipse.core.resources.ResourcesPlugin;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
import org.eclipse.core.runtime.CoreException;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
import org.eclipse.core.runtime.IAdaptable;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
import org.eclipse.core.runtime.IProgressMonitor;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
import org.eclipse.core.runtime.IStatus;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
import org.eclipse.core.runtime.Status;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
import org.eclipse.core.runtime.SubProgressMonitor;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
import org.eclipse.jface.operation.IRunnableWithProgress;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
import org.eclipse.jface.viewers.IStructuredSelection;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
import org.eclipse.jface.wizard.Wizard;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import org.eclipse.ui.IImportWizard;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import org.eclipse.ui.IWorkbench;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import org.eclipse.ui.statushandlers.StatusManager;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import org.symbian.tools.wrttools.Activator;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
import org.symbian.tools.wrttools.util.ProjectUtils;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
public class WgzImportWizard extends Wizard implements IImportWizard {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
	private IFile file;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
	private WgzImportWizardPage page;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
	public WgzImportWizard() {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
		setWindowTitle("Import WRT Application Archive");
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
		setNeedsProgressMonitor(true);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
	}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
	@Override
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
	public void addPages() {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
		page = new WgzImportWizardPage(file);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
		addPage(page);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
	}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
139
f0a865ead60b Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 63
diff changeset
    42
	private IProject createProject(String archiveName, String projectName, URI uri,
63
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
			IProgressMonitor monitor) throws CoreException {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
		monitor.beginTask("Importing WRT application archive", 50);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
		// 1. Create project
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
		IProject project = ProjectUtils.createWrtProject(projectName, uri,
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
				new SubProgressMonitor(monitor, 10));
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
		// 2. Unpack archive
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
		try {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
			ProjectUtils.unzip(archiveName, project, 1, new SubProgressMonitor(
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
					monitor, 40));
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
		} catch (IOException e) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
			new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
					"Archive unpacking failed", e));
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    56
		}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
		monitor.done();
139
f0a865ead60b Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 63
diff changeset
    58
		return project;
63
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
	}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
	@Override
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
	public boolean performFinish() {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
		try {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
			final String projectName = page.getProjectName();
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
			final URI uri = page.getLocationURI();
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
			final String archiveName = page.getArchiveFile();
139
f0a865ead60b Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 63
diff changeset
    67
			final IProject[] holder = new IProject[1];
63
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
			getContainer().run(true, true, new IRunnableWithProgress() {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    69
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    70
				public void run(IProgressMonitor monitor)
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    71
						throws InvocationTargetException, InterruptedException {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    72
					try {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    73
						ResourcesPlugin.getWorkspace().run(
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    74
								new IWorkspaceRunnable() {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    76
									public void run(IProgressMonitor monitor)
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    77
											throws CoreException {
139
f0a865ead60b Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 63
diff changeset
    78
										holder[0] = createProject(archiveName, projectName,
63
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
												uri, monitor);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
									}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
								}, monitor);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
					} catch (CoreException e) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
						StatusManager.getManager().handle(e.getStatus(),
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
								StatusManager.SHOW);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
					}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
				}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
			});
139
f0a865ead60b Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 63
diff changeset
    89
			if (holder[0] != null) {
f0a865ead60b Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 63
diff changeset
    90
				ProjectUtils.focusOn(holder[0]);
f0a865ead60b Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 63
diff changeset
    91
			}
63
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    92
		} catch (InvocationTargetException e) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    93
			Activator.log(e);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    94
		} catch (InterruptedException e) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
			Activator.log(e);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
		}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
		return true;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    98
	}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   100
	public void init(IWorkbench workbench, IStructuredSelection selection) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   101
		file = null;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   102
		if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   103
			Object element = ((IStructuredSelection) selection)
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   104
					.getFirstElement();
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   105
			if (element instanceof IAdaptable) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   106
				IResource resource = (IResource) ((IAdaptable) element)
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   107
						.getAdapter(IResource.class);
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   108
				if (resource != null
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   109
						&& resource.getType() == IResource.FILE
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   110
						&& "wgz".equalsIgnoreCase(resource
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   111
								.getProjectRelativePath().getFileExtension())) {
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   112
					file = (IFile) resource;
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   113
				}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   114
			}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   115
		}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   116
	}
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   117
558819056485 Importing WGZ is now supported. Several bugfixes in other areas were made
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   118
}