Importing WGZ is now supported. Several bugfixes in other areas were made
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java Fri Jan 29 13:27:41 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java Fri Jan 29 17:49:30 2010 -0800
@@ -74,7 +74,9 @@
@Override
public void setFocus() {
- browser.setFocus();
+ if (browser != null && !browser.isDisposed()) {
+ browser.setFocus();
+ }
}
private boolean refreshScheduled = false;
--- a/org.symbian.tools.wrttools/plugin.xml Fri Jan 29 13:27:41 2010 -0800
+++ b/org.symbian.tools.wrttools/plugin.xml Fri Jan 29 17:49:30 2010 -0800
@@ -156,6 +156,13 @@
icon="icons/main16.gif" id="org.symbian.tools.wrttools.import.aptanaImport"
name="Aptana IDE WRT Project">
</wizard>
+ <wizard
+ category="org.symbian.tools.wrttools.import"
+ class="org.symbian.tools.wrttools.wizards.WgzImportWizard"
+ icon="icons/main16.gif"
+ id="org.symbian.tools.wrttools.importwgz"
+ name="Import WRT Application Archive">
+ </wizard>
</extension>
<!-- Problem Markers -->
@@ -443,9 +450,29 @@
<adapt
type="org.eclipse.core.resources.IResource">
</adapt>
- <count
- value="0">
- </count>
+ <adapt
+ type="java.util.Collection">
+ <count
+ value="0">
+ </count>
+ </adapt>
+ </or>
+ </enablement>
+ </commonWizard>
+ <commonWizard
+ type="import"
+ wizardId="org.symbian.tools.wrttools.importwgz">
+ <enablement>
+ <or>
+ <adapt
+ type="org.eclipse.core.resources.IResource">
+ </adapt>
+ <adapt
+ type="java.util.Collection">
+ <count
+ value="0">
+ </count>
+ </adapt>
</or>
</enablement>
</commonWizard>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/WRTNavigatorContentProvider.java Fri Jan 29 13:27:41 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/WRTNavigatorContentProvider.java Fri Jan 29 17:49:30 2010 -0800
@@ -118,14 +118,18 @@
private IResourceChangeListener listener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
- RootResourceFinder visitor = new RootResourceFinder();
- try {
- event.getDelta().accept(visitor);
- } catch (CoreException e) {
- Activator.log(e);
- refreshViewer(null);
+ IResource refresh = null;
+ if (event.getDelta() != null) {
+ RootResourceFinder visitor = new RootResourceFinder();
+ try {
+ event.getDelta().accept(visitor);
+ } catch (CoreException e) {
+ Activator.log(e);
+ refreshViewer(null);
+ }
+ refresh = visitor.resource;
}
- refreshViewer(visitor.resource);
+ refreshViewer(refresh);
}
};
private Viewer viewer;
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Fri Jan 29 13:27:41 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Fri Jan 29 17:49:30 2010 -0800
@@ -19,20 +19,28 @@
package org.symbian.tools.wrttools.util;
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 javax.swing.filechooser.FileSystemView;
+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.IProjectDescription;
+import org.eclipse.core.resources.IResource;
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.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock;
import org.eclipse.wst.validation.ValidationFramework;
@@ -45,9 +53,19 @@
public static final String PREVIEW_FRAME_FILE = "wrt_preview_frame.html";
public static final String PREVIEW_MAIN_FILE = "wrt_preview_main.html";
+ private static boolean isDefaultProjectLocation(URI uri) {
+ File file = new File(uri);
+ IPath project = new Path(file.getAbsolutePath());
+ IPath workspace = ResourcesPlugin.getWorkspace().getRoot()
+ .getLocation();
+ return workspace.isPrefixOf(project);
+ }
+
@SuppressWarnings("restriction")
public static IProject createWrtProject(String name, URI uri,
IProgressMonitor monitor) throws CoreException {
+ uri = isDefaultProjectLocation(uri) ? null
+ : uri;
monitor.beginTask("Create project resources", 20);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(name);
@@ -129,16 +147,20 @@
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)) {
+ if (file.isFile()
+ && file.getName().equals(
+ IProjectDescription.DESCRIPTION_FILE_NAME)) {
dotProjectFile = file;
}
- if (file.isFile() && PREVIEW_FRAME_FILE.equalsIgnoreCase(file.getName())) {
+ if (file.isFile()
+ && PREVIEW_FRAME_FILE.equalsIgnoreCase(file.getName())) {
hasFrame = true;
}
- if (file.isDirectory() && PREVIEW_FOLDER.equalsIgnoreCase(file.getName())) {
+ if (file.isDirectory()
+ && PREVIEW_FOLDER.equalsIgnoreCase(file.getName())) {
hasPreviewer = true;
}
}
@@ -147,4 +169,35 @@
}
return dotProjectFile;
}
+
+ public static void unzip(String archiveFile, IContainer location, int trimSegments,
+ IProgressMonitor progressMonitor) throws IOException, CoreException {
+ progressMonitor.beginTask(MessageFormat.format("Unpacking {0}",
+ archiveFile), IProgressMonitor.UNKNOWN);
+ ZipInputStream stream = new ZipInputStream(new FileInputStream(
+ archiveFile));
+
+ try {
+ ZipEntry nextEntry;
+ while ((nextEntry = stream.getNextEntry()) != null) {
+ IPath p = new Path(nextEntry.getName()).removeFirstSegments(trimSegments);
+ if (!nextEntry.isDirectory()) {
+ IFile file = location.getFile(p);
+ checkParent(file.getParent());
+ file.create(new NonClosingStream(stream), false,
+ new SubProgressMonitor(progressMonitor, 1));
+ }
+ }
+ } finally {
+ stream.close();
+ }
+ progressMonitor.done();
+ }
+
+ private static void checkParent(IContainer parent) throws CoreException {
+ if (parent.getType() == IResource.FOLDER && !parent.exists()) {
+ checkParent(parent.getParent());
+ ((IFolder) parent).create(false, true, new NullProgressMonitor());
+ }
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java Fri Jan 29 17:49:30 2010 -0800
@@ -0,0 +1,113 @@
+package org.symbian.tools.wrttools.wizards;
+
+import java.io.IOException;
+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.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+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.IWorkbench;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+public class WgzImportWizard extends Wizard implements IImportWizard {
+ private IFile file;
+ private WgzImportWizardPage page;
+
+ public WgzImportWizard() {
+ setWindowTitle("Import WRT Application Archive");
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ public void addPages() {
+ page = new WgzImportWizardPage(file);
+ addPage(page);
+ }
+
+ private void 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
+ try {
+ ProjectUtils.unzip(archiveName, project, 1, new SubProgressMonitor(
+ monitor, 40));
+ } catch (IOException e) {
+ new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Archive unpacking failed", e));
+ }
+ monitor.done();
+ }
+
+ @Override
+ public boolean performFinish() {
+ try {
+ final String projectName = page.getProjectName();
+ final URI uri = page.getLocationURI();
+ final String archiveName = page.getArchiveFile();
+ 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 {
+ createProject(archiveName, projectName,
+ uri, monitor);
+ }
+
+ }, monitor);
+ } catch (CoreException e) {
+ StatusManager.getManager().handle(e.getStatus(),
+ StatusManager.SHOW);
+ }
+ }
+ });
+ } 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 = ((IStructuredSelection) 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;
+ }
+ }
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java Fri Jan 29 17:49:30 2010 -0800
@@ -0,0 +1,451 @@
+package org.symbian.tools.wrttools.wizards;
+
+import java.io.File;
+import java.net.URI;
+import java.text.MessageFormat;
+
+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;
+
+public class WgzImportWizardPage extends WizardPage {
+ private final IFile file;
+
+ 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);
+ }
+
+ 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);
+ }
+
+ // initial value stores
+ private String initialProjectFieldValue;
+
+ // widgets
+ Text projectNameField;
+
+ private Listener nameModifyListener = new Listener() {
+ public void handleEvent(Event e) {
+ setLocationForSelection();
+ boolean valid = validatePage();
+ setPageComplete(valid);
+
+ }
+ };
+
+ private ProjectContentsLocationArea locationArea;
+ private WorkingSetGroup workingSetGroup;
+
+ // constants
+ private static final int SIZING_TEXT_FIELD_WIDTH = 250;
+
+ private Text wgzName;
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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);
+ }
+ };
+ }
+
+ /**
+ * 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);
+ }
+
+ protected void browse() {
+ FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
+ fileDialog.setFilterPath(wgzName.getText());
+ fileDialog.setFilterExtensions(new String[] {"*.wgz", "*.*"} );
+ fileDialog.setFilterNames(new String[] {"WRT Archive (wgz)", "All Files"} );
+ String res = fileDialog.open();
+ if (res != null) {
+ updateWgzName(wgzName.getText().trim(), res);
+ wgzName.setText(res);
+ setPageComplete(validatePage());
+ }
+ }
+
+ 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 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
+ * <code>null</code> if a valid project location has not been entered.
+ *
+ * @return the project location URI, or <code>null</code>
+ * @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.
+ * <p>
+ * This method does not create the project resource; this is the
+ * responsibility of <code>IProject::create</code> invoked by the new
+ * project resource wizard.
+ * </p>
+ *
+ * @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
+ * <code>null</code> 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());
+ }
+
+ /**
+ * Returns whether this page's controls currently all contain valid values.
+ *
+ * @return <code>true</code> if all controls are valid, and
+ * <code>false</code> 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 (!f.isFile()) {
+ 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;
+ }
+
+ /*
+ * see @DialogPage.setVisible(boolean)
+ */
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ projectNameField.setFocus();
+ }
+ }
+
+ /**
+ * Returns the useDefaults.
+ *
+ * @return boolean
+ */
+ public boolean useDefaults() {
+ return locationArea.isDefault();
+ }
+
+ /**
+ * 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();
+ }
+
+ public String getArchiveFile() {
+ return wgzName.getText().trim();
+ }
+
+}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Fri Jan 29 13:27:41 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Fri Jan 29 17:49:30 2010 -0800
@@ -43,10 +43,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -228,8 +226,7 @@
public IWizardPage getNextPage(IWizardPage page) {
if (page == resourcePage) {
context.setProjectName(resourcePage.getProjectName());
- context.setProjectUri(isDefaultProjectLocation() ? null
- : resourcePage.getLocationURI());
+ context.setProjectUri(resourcePage.getLocationURI());
}
if (page == templatesPage) {
ProjectTemplate template = context.getTemplate();
@@ -250,13 +247,6 @@
return super.getNextPage(page);
}
- private boolean isDefaultProjectLocation() {
- IPath project = resourcePage.getLocationPath();
- IPath workspace = ResourcesPlugin.getWorkspace().getRoot()
- .getLocation();
- return workspace.isPrefixOf(project);
- }
-
public void setInitializationData(IConfigurationElement config,
String propertyName, Object data) throws CoreException {
this.config = config;