[Esbox-commits] r2113 - in branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal: api/vm/vmware vm/vmware/ui/wizards
fabricioepa at garage.maemo.org
fabricioepa at garage.maemo.org
Sat Sep 5 00:23:03 EEST 2009
Author: fabricioepa
Date: 2009-09-05 00:22:55 +0300 (Sat, 05 Sep 2009)
New Revision: 2113
Added:
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
Modified:
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
Log:
Add support to download multipart files
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java 2009-09-04 20:54:50 UTC (rev 2112)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -20,6 +20,8 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.text.DecimalFormat;
+import java.util.Formatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -59,10 +61,12 @@
/**
* Get URL and size of remote file.
+ * @param nPart the number of the part to get info, null if it not is a multipart file
* @return URL and size of remote file.
* @throws MicaException
+ * @throws IOException
*/
- private Tuple getRemoteFileInfo() throws MicaException {
+ private Tuple getRemoteFileInfo(Integer nPart) throws MicaException, IOException {
URL connectionURL = null;
try {
connectionURL = new URL(MaemoSDKVMInfo.DOWNLOAD_PAGE);
@@ -77,8 +81,20 @@
URL remoteURL;
int fileSize = 0;
try {
- fileSize = getSizeFor(downloadPage, downloadFile.getDescriptor().getName());
remoteURL = getLinkFor(downloadPage, downloadFile.getDescriptor().getName());
+
+ if(downloadFile.isMultipart() && nPart != null){
+ String url = remoteURL.toExternalForm();
+ int i = url.lastIndexOf('.');
+ if(i != -1)
+ url = url.substring(0,i);
+ DecimalFormat df = new DecimalFormat( "000");
+ String part = df.format(nPart);
+ remoteURL = new URL(url + '.' + part);
+ }
+
+ HttpURLConnection conn = (HttpURLConnection) remoteURL.openConnection();
+ fileSize = conn.getContentLength();
} catch (MalformedURLException e) {
throw new MicaException("Invalid file URL on " + MaemoSDKVMInfo.DOWNLOAD_PAGE, e);
}
@@ -214,7 +230,7 @@
if (matcherLink.find()) {
String link = matcherLink.group(1);
return (new URL(MaemoSDKVMInfo.DOWNLOAD_PAGE
- + link.substring(link.indexOf("?"))));
+ + (link.contains("?")?link.substring(link.indexOf("?")): link)));
}
}
@@ -222,45 +238,18 @@
return null;
}
- /**
- * Get the size of a certain remote file. The file is retrieved from html page description.
- * @param htmlPage
- * @param downloadFileDescription
- * @return
- */
- private int getSizeFor(String htmlPage, String downloadFileDescription) {
- final String DOWNLOAD_FILE_PATTERN = "<tr>\\s*<td class=\"filename\">(.*?)</td>\\s*</tr>";
- final String SIZE_PATTERN = "<td class=\"filesize\">(.*?)</td>";
- Pattern fileEntryPattern = Pattern.compile(DOWNLOAD_FILE_PATTERN,
- Pattern.DOTALL | Pattern.UNIX_LINES);
- Matcher matcher = fileEntryPattern.matcher(htmlPage);
- while (matcher.find()) {
- String fileInfo = matcher.group(0);
- if (fileInfo.contains(downloadFileDescription)) {
- Pattern sizePattern = Pattern.compile(SIZE_PATTERN,
- Pattern.DOTALL | Pattern.UNIX_LINES);
- Matcher matcherLink = sizePattern.matcher(fileInfo);
- if (matcherLink.find()) {
- String size = matcherLink.group(1);
- return Integer.parseInt(size);
- }
- }
-
- }
- return 0;
- }
/**
- * Get file name of download file to be saved locally
+ * Get local file to download file
*
* @param remoteURL
- * @param localPath
+ * @param installLocation
* @return the name of file to be saved locally
*/
- private String getFileName(URL remoteURL, URL localPath) {
+ private File getLocalFile(URL remoteURL, URL installLocation) {
String fileName = (new Path(remoteURL.getFile())).lastSegment();
fileName = fileName.substring(fileName.lastIndexOf("=") + 1);
- return (new Path(localPath.getFile())).append(fileName).toOSString();
+ return new File ((new Path(installLocation.getFile())).append(fileName).toOSString());
}
/**
@@ -268,15 +257,14 @@
* @param localFileName
* @return
*/
- private long getPreviousDownloadSize(String localFileName) {
- File previousFile = new File(localFileName);
- if (previousFile.exists()) {
+ private long getPreviousDownloadSize(File localFile) {
+ if (localFile.exists()) {
boolean canResumeDownload = DialogUtils.showQuestionDialog(DialogUtils.getShell(),
- "Previous download file founded", "The file " + localFileName + " already exists. Would you like to resume download?");
+ "Previous download file founded", "The file " + localFile + " already exists. Would you like to resume download?");
if (canResumeDownload) {
- return previousFile.length();
+ return localFile.length();
} else {
- previousFile.delete();
+ localFile.delete();
return 0L;
}
}
@@ -292,97 +280,225 @@
private IStatus fileDownloader() throws IOException, MicaException {
// Check if file was downloaded before
monitor.subTask("Checking information about file to be downloaded ...");
+
+ if(downloadFile.isMultipart()){
+ //download multipar file
+ return downloadMultiple();
+ }else{
+ //download single file
+ return downloadSingle();
+ }
+ }
+
+ protected IStatus downloadMultiple() throws MicaException, IOException {
+
+ for(int nPart = 1; nPart <= downloadFile.getNumParts(); nPart++){
+ Tuple remoteFileInfo = getRemoteFileInfo(nPart);
+ URL remoteURL = (URL) remoteFileInfo.get(0);
+
+ // Get link of remote file
+ File localFile = getLocalFile(remoteURL, downloadFile.getInstallLocation());
+ downloadFile.setFileName(localFile.getName());
+
+ downloadFile.setDownloadedSize(getPreviousDownloadSize(localFile));
+ Integer remoteFileSize = (Integer) remoteFileInfo.get(1);;
+
+ if (downloadFile.getDownloadedSize() == remoteFileSize.intValue())
+ return Activator.createStatus(Status.OK, "Maemo SDK virtual image is already downloaded.");
+
+ HttpURLConnection connection = null;
+ RandomFileOutputStream out = null;
+ InputStream in = null;
+
+ try {
+
+ // Open connection to URL.
+ monitor.subTask("Establishing connection with " + remoteURL.getHost());
+ connection = (HttpURLConnection) remoteURL.openConnection();
- Tuple remoteFileInfo = getRemoteFileInfo();
+ // Specify what portion of file to download
+ connection.setRequestProperty("Range", "bytes=" + downloadFile.getDownloadedSize() + "-");
+
+ // Connect to server
+ connection.connect();
+ monitor.subTask("Connected with " + remoteURL.getHost());
+
+ IStatus connectionStatus = validateConnection(connection);
+ if (!connectionStatus.isOK()) {
+ cancelDownload(downloadFile,monitor);
+ return errorStatus(connectionStatus.getMessage());
+ }
+
+ int contentLength = connection.getContentLength();
+ if (!haveEnoughtFreeSpace(contentLength/1024, localFile)) {
+ cancelDownload(downloadFile, monitor);
+ return errorStatus("There is not enought space to save Maemo SDK virtual machine in your computer.");
+ }
+
+ // set the size for this download if it hasn't been already set.
+ if (downloadFile.getSize() == -1) {
+ downloadFile.setSize(contentLength);
+ }
+
+ CopyProgressMonitor progressMonitor = new CopyProgressMonitor(
+ "Downloading Maemo SDK virtual image", remoteFileSize, monitor);
+ progressMonitor.setExistingSize(downloadFile.getDownloadedSize());
+ progressMonitor.start();
+
+ out = new RandomFileOutputStream(localFile,true);
+ out.setFilePointer(downloadFile.getDownloadedSize());
+ in = connection.getInputStream();
+
+ // create and start to download
+ monitor.beginTask(remoteURL.getFile(), remoteFileSize != 0 ? remoteFileSize : IProgressMonitor.UNKNOWN);
+ monitor.worked((int)downloadFile.getDownloadedSize());
+
+ int bufferSize = 64*1024;//64KB
+ DownloadingThread thread = new DownloadingThread(in, out,bufferSize , progressMonitor, monitor);
+ thread.start();
+
+ while (!thread.isInterrupted() && thread.isAlive() ) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ continue;
+ }
+
+ if (monitor.isCanceled()) {
+ thread.stopDownloading();
+ downloadFile.cancel();
+ return Status.CANCEL_STATUS;
+ }
+
+ if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED){
+ thread.doPause();
+ }
+
+ if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING){
+ thread.doResume();
+ }
+ }
+
+ if (thread.isCompleted() && nPart == downloadFile.getNumParts()) {
+ downloadFile.complete();
+ }
+
+ if (thread.getErrorMessage() != null) {
+ downloadFile.error();
+ throw new IOException(thread.getErrorMessage());
+ }
+ } finally {
+
+ // Close connection to server.
+ if (in != null) {
+ in.close();
+ }
+
+ if (connection != null)
+ connection.disconnect();
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ protected IStatus downloadSingle() throws MicaException, IOException {
+ Tuple remoteFileInfo = getRemoteFileInfo(null);
URL remoteURL = (URL) remoteFileInfo.get(0);
-
+
// Get link of remote file
- String fileName = getFileName(remoteURL, downloadFile.getLocalURL());
- downloadFile.setLocalURL(new File(fileName).toURL());
-
- downloadFile.setDownloadedSize(getPreviousDownloadSize(fileName));
+ File localFile = getLocalFile(remoteURL, downloadFile.getInstallLocation());
+ downloadFile.setFileName(localFile.getName());
+
+ downloadFile.setDownloadedSize(getPreviousDownloadSize(localFile));
Integer remoteFileSize = (Integer) remoteFileInfo.get(1);
-
+
if (downloadFile.getDownloadedSize() == remoteFileSize.intValue())
- return Activator.createStatus(Status.OK, "Maemo SDK virtual image is already downloaded.");
-
+ return Activator.createStatus(Status.OK,
+ "Maemo SDK virtual image is already downloaded.");
+
HttpURLConnection connection = null;
RandomFileOutputStream out = null;
InputStream in = null;
-
+
try {
-
+
// Open connection to URL.
- monitor.subTask("Establishing connection with " + remoteURL.getHost());
+ monitor.subTask("Establishing connection with "
+ + remoteURL.getHost());
connection = (HttpURLConnection) remoteURL.openConnection();
-
+
// Specify what portion of file to download
- connection.setRequestProperty("Range", "bytes=" + downloadFile.getDownloadedSize() + "-");
-
+ connection.setRequestProperty("Range", "bytes="
+ + downloadFile.getDownloadedSize() + "-");
+
// Connect to server
connection.connect();
monitor.subTask("Connected with " + remoteURL.getHost());
-
+
IStatus connectionStatus = validateConnection(connection);
if (!connectionStatus.isOK()) {
- cancelDownload(downloadFile,monitor);
+ cancelDownload(downloadFile, monitor);
return errorStatus(connectionStatus.getMessage());
}
-
- int contentLength = connection.getContentLength();
- if (!haveEnoughtFreeSpace(contentLength/1024, downloadFile.getLocalURL())) {
+
+ int contentLength = connection.getContentLength();
+ if (!haveEnoughtFreeSpace(contentLength / 1024, localFile)) {
cancelDownload(downloadFile, monitor);
return errorStatus("There is not enought space to save Maemo SDK virtual machine in your computer.");
}
-
+
// set the size for this download if it hasn't been already set.
if (downloadFile.getSize() == -1) {
downloadFile.setSize(contentLength);
}
-
+
CopyProgressMonitor progressMonitor = new CopyProgressMonitor(
- "Downloading Maemo SDK virtual image", remoteFileSize, monitor);
+ "Downloading Maemo SDK virtual image", remoteFileSize,
+ monitor);
progressMonitor.setExistingSize(downloadFile.getDownloadedSize());
progressMonitor.start();
-
- out = new RandomFileOutputStream(fileName,true);
- out.setFilePointer(downloadFile.getDownloadedSize());
+
+ out = new RandomFileOutputStream(localFile, true);
+ out.setFilePointer(downloadFile.getDownloadedSize());
in = connection.getInputStream();
-
+
// create and start to download
- monitor.beginTask(remoteURL.getFile(), remoteFileSize != 0 ? remoteFileSize : IProgressMonitor.UNKNOWN);
- monitor.worked((int)downloadFile.getDownloadedSize());
-
- int bufferSize = 64*1024;//64KB
- DownloadingThread thread = new DownloadingThread(in, out,bufferSize , progressMonitor, monitor);
+ monitor.beginTask(remoteURL.getFile(),
+ remoteFileSize != 0 ? remoteFileSize
+ : IProgressMonitor.UNKNOWN);
+ monitor.worked((int) downloadFile.getDownloadedSize());
+
+ int bufferSize = 64 * 1024;// 64KB
+ DownloadingThread thread = new DownloadingThread(in, out,
+ bufferSize, progressMonitor, monitor);
thread.start();
- while (!thread.isInterrupted() && thread.isAlive() ) {
+ while (!thread.isInterrupted() && thread.isAlive()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
continue;
}
-
+
if (monitor.isCanceled()) {
thread.stopDownloading();
- downloadFile.cancel();
+ downloadFile.cancel();
return Status.CANCEL_STATUS;
}
-
- if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED){
+
+ if (downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED) {
thread.doPause();
}
-
- if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING){
+
+ if (downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING) {
thread.doResume();
}
}
-
+
if (thread.isCompleted()) {
downloadFile.complete();
}
-
+
if (thread.getErrorMessage() != null) {
downloadFile.error();
throw new IOException(thread.getErrorMessage());
@@ -397,10 +513,9 @@
if (connection != null)
connection.disconnect();
}
-
return Status.OK_STATUS;
}
-
+
/**
* Creates an error status based with the given message.
* @param message
@@ -428,8 +543,8 @@
* @return boolean if there is enough space to uncompress the Maemo SDK virtual image (if the free space
* available on disk is bigger than the size of uncompressed Maemo SDK virtual image); false, otherwise.
*/
- private static boolean haveEnoughtFreeSpace(int fileSize, URL localURL) throws IOException {
- long freeSpace = FilesystemUtils.freeSpaceOS(new Path(localURL.getPath()),true);
+ private static boolean haveEnoughtFreeSpace(int fileSize, File localFile) throws IOException {
+ long freeSpace = FilesystemUtils.freeSpaceOS(new Path(localFile.getAbsolutePath()),true);
return freeSpace > fileSize;
}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java 2009-09-04 20:54:50 UTC (rev 2112)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.maemo.esbox.internal.api.vm.vmware;
+import java.io.File;
+import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -20,7 +22,7 @@
*
*/
public class MaemoSDKVMInfo implements Comparable<MaemoSDKVMInfo> {
-
+//XXX REMOVE ME public static final String DOWNLOAD_PAGE = "http://localhost:8080/nokia/";
public static final String DOWNLOAD_PAGE = "http://tablets-dev.nokia.com/maemo-dev-env-downloads.php";
// status for the file
@@ -40,9 +42,11 @@
private Status status;
// urls for download and storage
- private URL localPathURL;
+ private URL installLocaltion;
+ private String fileName;
private int numParts;
+ public static int SINGLE_FILE_PART = 1;
/**
* Constructor.
@@ -57,12 +61,12 @@
* @param url
*/
public MaemoSDKVMInfo(URL localURL) {
- this.localPathURL = localURL;
+ this.installLocaltion = localURL;
size = -1;
downloaded = 0;
descriptor = null;
status = Status.DOWNLOADING;
- numParts = 1;
+ numParts = SINGLE_FILE_PART;
}
/**
@@ -89,8 +93,8 @@
*
* @return
*/
- public URL getLocalURL() {
- return localPathURL;
+ public URL getInstallLocation() {
+ return installLocaltion;
}
/**
@@ -98,9 +102,34 @@
*
* @return
*/
- public void setLocalURL(URL localURL) {
- this.localPathURL = localURL;
+ public void setInstallLocation(URL localURL) {
+ this.installLocaltion = localURL;
}
+
+ /**
+ * The name of the file
+ * @return
+ */
+ public String getFileName(){
+ return this.fileName;
+ }
+
+ /**
+ * @return returns the local downloaded file name, it can be null
+ */
+ public File resolveLocalFile() {
+ try {
+ return new File(getInstallLocation().toURI().resolve(getFileName()));
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+ /**
+ * @param fileName the fileName to set
+ */
+ public void setFileName(String fileName){
+ this.fileName = fileName;
+ }
/**
* Get this download's size.
@@ -206,8 +235,8 @@
*
* @return true, if the file has more than one part; false, otherwise.
*/
- public boolean hasMoreParts() {
- return this.numParts > 0;
+ public boolean isMultipart() {
+ return this.numParts > SINGLE_FILE_PART;
}
/**
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java 2009-09-04 20:54:50 UTC (rev 2112)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -47,6 +47,7 @@
import org.maemo.mica.common.core.sdk.ISDKTarget;
import org.maemo.mica.common.core.sdk.SDKManager;
import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.internal.api.common.core.compression.Tool7zip;
import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
import org.maemo.mica.internal.api.common.core.sdk.SDKManagerInternal;
import org.maemo.mica.internal.api.linux.packages.core.aptinstall.AptInstallerHelper;
@@ -165,14 +166,14 @@
monitor.subTask("Uncompressing image...");
reporter.logInfo("Uncompressing Maemo SDK virtual image...");
- final String fileName = installData.getPathOfExistentVM() == null ? installData.getFileToDownload().getLocalURL().getFile() :
+ final String fileName = installData.getPathOfExistentVM() == null ? installData.getFileToDownload().resolveLocalFile().getAbsolutePath() :
installData.getPathOfExistentVM();
final String destinationPath = installData.getInstallationPath();
final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "File " + fileName
+ " was properly uncompressed into " + destinationPath) } ;
- if (fileName == null || !haveEnoughFreeSpace(fileName,destinationPath) ) {
+ if (fileName == null || !Tool7zip.haveEnoughFreeSpace(fileName,destinationPath) ) {
return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
}
@@ -552,8 +553,8 @@
} finally {
Policy.close(zipInputStream);
}
-
-
}
+
+
}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java 2009-09-04 20:54:50 UTC (rev 2112)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -1,204 +1,219 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-
-/**
- * This is a wrapper that contains information about Maemo SDK virtual image
- * installation process.
- *
- * @author raulherbster
- *
- */
-public class MaemoSDKVMInstallData {
-
- private MaemoSDKVMInfo fileToDownload;
- private boolean usePreviousInstallation;
- private String installationPath;
- private String pathOfExistentVM;
- private boolean licenseTermsAgreed;
- private boolean installSbox;
- private boolean installTargets;
- private boolean installCppEnv;
- private boolean installPythonEnv;
-
- /**
- * Constructor.
- */
- public MaemoSDKVMInstallData() {
- fileToDownload = new MaemoSDKVMInfo();
- }
-
- /**
- * Set the file to download.
- *
- * @param downloadFile
- */
- public void setFileToDownload(MaemoSDKVMInfo downloadFile) {
- if (downloadFile == null)
- return;
- this.fileToDownload = downloadFile;
- if (fileToDownload.getLocalURL() == null && installationPath != null)
- try {
- fileToDownload.setLocalURL(new File(installationPath).toURL());
- } catch (MalformedURLException e) {
- Activator.getErrorLogger().logAndShowError(
- "Cannot get location for file "
- + downloadFile.getDescriptor(), e);
- }
- }
-
- /**
- * Return the file to download.
- *
- * @return
- */
- public MaemoSDKVMInfo getFileToDownload() {
- return fileToDownload;
- }
-
- /**
- * @return the usePreviousInstallation
- */
- public boolean canUsePreviousInstallation() {
- return usePreviousInstallation;
- }
-
- /**
- * @param usePreviousInstallation
- * the usePreviousInstallation to set
- */
- public void setUsePreviousInstallation(boolean usePreviousInstallation) {
- this.usePreviousInstallation = usePreviousInstallation;
- }
-
- /**
- * @return the installationPath
- */
- public String getInstallationPath() {
- return installationPath;
- }
-
- /**
- * @param installationPath
- * the installationPath to set
- */
- public void setInstallationPath(String installationPath) {
- this.installationPath = installationPath;
- try {
- fileToDownload.setLocalURL(new File(installationPath).toURL());
- } catch (MalformedURLException e) {
- Activator.getErrorLogger().logAndShowError(
- "Cannot get location for file "
- + fileToDownload.getDescriptor(), e);
- }
-
- }
-
- /**
- * @return the pathOfExistentVM
- */
- public String getPathOfExistentVM() {
- return pathOfExistentVM;
- }
-
- /**
- * @param pathOfExistentVM
- * the pathOfExistentVM to set
- */
- public void setPathOfExistentVM(String pathOfExistentVM) {
- this.pathOfExistentVM = pathOfExistentVM;
- }
-
- /**
- * @return the installSbox
- */
- public boolean canInstallSbox() {
- return installSbox;
- }
-
- /**
- * @param installSbox
- * the installSbox to set
- */
- public void setInstallSbox(boolean installSbox) {
- this.installSbox = installSbox;
- }
-
- /**
- * @return the installTargets
- */
- public boolean canInstallTargets() {
- return installTargets;
- }
-
- /**
- * @param installTargets
- * the installTargets to set
- */
- public void setInstallTargets(boolean installTargets) {
- this.installTargets = installTargets;
- }
-
- /**
- * @return true, if it is necessary to install Python programming
- * environment; false, otherwise.
- */
- public boolean canInstallPythonEnv() {
- return installPythonEnv;
- }
-
- /**
- * @param installTargets
- * the installTargets to set
- */
- public void setInstallPythonEnv(boolean installPythonEnv) {
- this.installPythonEnv = installPythonEnv;
- }
-
- /**
- *
- * @return true, if it is necessary to install CPP programming environment;
- * false, otherwise.
- */
- public boolean canInstallCppEnv() {
- return installCppEnv;
- }
-
- /**
- * @param installCppEnv
- * the installTargets to set
- */
- public void setInstallCppEnv(boolean installCppEnv) {
- this.installCppEnv = installCppEnv;
- }
-
- /**
- * @return true, if license terms were agreed; false, otherwise.
- */
- public boolean isLicenseTermsAgreed() {
- return licenseTermsAgreed;
- }
-
- /**
- * @param licenseTermsAgreed
- * the licenseTermsAgreed to set
- */
- public void setLicenseTermsAgreed(boolean licenseTermsAgreed) {
- this.licenseTermsAgreed = licenseTermsAgreed;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+
+/**
+ * This is a wrapper that contains information about Maemo SDK virtual image
+ * installation process.
+ *
+ * @author raulherbster
+ *
+ */
+public class MaemoSDKVMInstallData {
+
+ private MaemoSDKVMInfo fileToDownload;
+ private boolean usePreviousInstallation;
+ private String installationPath;
+ private String pathOfExistentVM;
+ private String uncompressToolPath;
+ private boolean licenseTermsAgreed;
+ private boolean installSbox;
+ private boolean installTargets;
+ private boolean installCppEnv;
+ private boolean installPythonEnv;
+
+ /**
+ * Constructor.
+ */
+ public MaemoSDKVMInstallData() {
+ fileToDownload = new MaemoSDKVMInfo();
+ }
+
+ /**
+ * Set the file to download.
+ *
+ * @param downloadFile
+ */
+ public void setFileToDownload(MaemoSDKVMInfo downloadFile) {
+ if (downloadFile == null)
+ return;
+ this.fileToDownload = downloadFile;
+ if (fileToDownload.getInstallLocation() == null && installationPath != null)
+ try {
+ fileToDownload.setInstallLocation(new File(installationPath).toURL());
+ } catch (MalformedURLException e) {
+ Activator.getErrorLogger().logAndShowError(
+ "Cannot get location for file "
+ + downloadFile.getDescriptor(), e);
+ }
+ }
+
+ /**
+ * Return the file to download.
+ *
+ * @return
+ */
+ public MaemoSDKVMInfo getFileToDownload() {
+ return fileToDownload;
+ }
+
+ /**
+ * @return the usePreviousInstallation
+ */
+ public boolean canUsePreviousInstallation() {
+ return usePreviousInstallation;
+ }
+
+ /**
+ * @param usePreviousInstallation
+ * the usePreviousInstallation to set
+ */
+ public void setUsePreviousInstallation(boolean usePreviousInstallation) {
+ this.usePreviousInstallation = usePreviousInstallation;
+ }
+
+ /**
+ * @return the installationPath
+ */
+ public String getInstallationPath() {
+ return installationPath;
+ }
+
+ /**
+ * @param installationPath
+ * the installationPath to set
+ */
+ public void setInstallationPath(String installationPath) {
+ this.installationPath = installationPath;
+ try {
+ fileToDownload.setInstallLocation(new File(installationPath).toURL());
+ } catch (MalformedURLException e) {
+ Activator.getErrorLogger().logAndShowError(
+ "Cannot get location for file "
+ + fileToDownload.getDescriptor(), e);
+ }
+
+ }
+
+ /**
+ * @return the pathOfExistentVM
+ */
+ public String getPathOfExistentVM() {
+ return pathOfExistentVM;
+ }
+
+ /**
+ * @return the path of uncompress tool to be used.
+ */
+ public String getUncompressToolPath() {
+ return uncompressToolPath;
+ }
+
+ /**
+ * @param pathOfExistentVM
+ * the pathOfExistentVM to set
+ */
+ public void setPathOfExistentVM(String pathOfExistentVM) {
+ this.pathOfExistentVM = pathOfExistentVM;
+ }
+
+ /**
+ * @return the installSbox
+ */
+ public boolean canInstallSbox() {
+ return installSbox;
+ }
+
+ /**
+ * @param installSbox
+ * the installSbox to set
+ */
+ public void setInstallSbox(boolean installSbox) {
+ this.installSbox = installSbox;
+ }
+
+ /**
+ * @return the installTargets
+ */
+ public boolean canInstallTargets() {
+ return installTargets;
+ }
+
+ /**
+ * @param installTargets
+ * the installTargets to set
+ */
+ public void setInstallTargets(boolean installTargets) {
+ this.installTargets = installTargets;
+ }
+
+ /**
+ * @return true, if it is necessary to install Python programming
+ * environment; false, otherwise.
+ */
+ public boolean canInstallPythonEnv() {
+ return installPythonEnv;
+ }
+
+ /**
+ * @param installTargets
+ * the installTargets to set
+ */
+ public void setInstallPythonEnv(boolean installPythonEnv) {
+ this.installPythonEnv = installPythonEnv;
+ }
+
+ /**
+ *
+ * @return true, if it is necessary to install CPP programming environment;
+ * false, otherwise.
+ */
+ public boolean canInstallCppEnv() {
+ return installCppEnv;
+ }
+
+ /**
+ * @param installCppEnv
+ * the installTargets to set
+ */
+ public void setInstallCppEnv(boolean installCppEnv) {
+ this.installCppEnv = installCppEnv;
+ }
+
+ /**
+ * @return true, if license terms were agreed; false, otherwise.
+ */
+ public boolean isLicenseTermsAgreed() {
+ return licenseTermsAgreed;
+ }
+
+ /**
+ * @param licenseTermsAgreed
+ * the licenseTermsAgreed to set
+ */
+ public void setLicenseTermsAgreed(boolean licenseTermsAgreed) {
+ this.licenseTermsAgreed = licenseTermsAgreed;
+ }
+
+ /**
+ * @param path the path of the uncompress tool to be used during virtual image uncompressing.
+ */
+ public void setUncompressToolPath(String path) {
+ this.uncompressToolPath = path;
+ }
+
+}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java 2009-09-04 20:54:50 UTC (rev 2112)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -73,7 +73,7 @@
* and adding them to contents.
*/
protected void doFetchScripts() {
- List<MaemoSDKVMDescription> virtualImagesNames = fetchVMNamesFromUrl("http://tablets-dev.nokia.com/maemo-dev-env-downloads.php");
+ List<MaemoSDKVMDescription> virtualImagesNames = fetchVMNamesFromUrl(MaemoSDKVMInfo.DOWNLOAD_PAGE);
for (MaemoSDKVMDescription maemoSDKVM : virtualImagesNames) {
MaemoSDKVMInfo downloadFile = new MaemoSDKVMInfo();
downloadFile.setDescriptor(maemoSDKVM);
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java 2009-09-04 20:54:50 UTC (rev 2112)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -1,537 +1,539 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-
-import java.io.File;
-import java.util.Arrays;
-
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProviderChangedEvent;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.DirectoryDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.Text;
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-import org.maemo.mica.common.core.machine.MachineRegistry;
-import org.maemo.mica.common.ui.NetworkSettingsUI;
-import org.maemo.mica.common.ui.dialogs.DialogUtils;
-import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
-
-/**
- * Page that displays general information about the Maemo SDK virtual image to
- * be installed.
- *
- * @author raulherbster
- *
- */
-public class MaemoSDKVMSelectionWizardPage extends WizardPage implements ILabelProviderListener {
-
- private MaemoSDKVMInfo latestVMInstallData;
-
- // Virtual images area
- private Button downloadLatest;
- private TableViewer virtualImagesTable;
-
- // options area
- private Button usePreviousDownloadButton;
- private Text destinationTextField;
-
- // advanced area
- private Button advancedButton;
- private Composite advancedContent;
- private Text existingVirtualImageTextField;
-
- // listener for changes on text fields
- private Listener textFieldsValidator;
-
- // text area for description
- private Text imageDescription;
-
- /**
- * Comparator for virtual images table viewer.
- */
- private class VirtualImagesComparator extends ViewerComparator {
-
- public int compare(Viewer iviewer, Object e1, Object e2) {
- if (e1 == null) {
- return -1;
- } else if (e2 == null) {
- return 1;
- } else {
- return ((MaemoSDKVMInfo)e1).getDescriptor().compareTo(((MaemoSDKVMInfo)e2).getDescriptor());
- }
- }
-
- }
-
- /**
- * Constructor.
- *
- * @param wizard
- * the parent wizard.
- */
- protected MaemoSDKVMSelectionWizardPage(NewMaemoSDKVMWizard wizard) {
- super("maemovm_selection", "Select Maemo SDK Virtual Image",
- Activator.MAEMO_VM_WIZBAN_DESCRIPTOR);
- setDescription("A virtual image is a disk image with an installation of Linux/x86 " +
- "capable of hosting Scratchbox and the Maemo SDK.");
- setWizard(wizard);
- setPageComplete(false);
- textFieldsValidator = createTextFieldValidatorListener();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
- * .Composite)
- */
- public void createControl(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite);
- GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
- setControl(composite);
-
- createVirtualImagesSelector(composite);
-
- createDescriptionContent(composite);
-
- createOptionsContent(composite);
-
- createAdvancedContent(composite);
-
- setInitialValues();
-
- virtualImagesTable.setInput(new Object[0]);
-
- for (TableColumn column : virtualImagesTable.getTable().getColumns()) {
- column.pack();
- }
-
- //validatePage();
- }
-
- /**
- * Create table that displays available Maemo SDK virtual image.
- *
- * @param composite
- * parent composite.
- */
- private void createVirtualImagesSelector(Composite composite) {
- Label label = new Label(composite, SWT.NONE);
- label.setText("Select an image:");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1)
- .applyTo(label);
- Link link = NetworkSettingsUI
- .createStockNetworkSettingHyperlink(composite);
- GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).span(2, 1)
- .applyTo(link);
-
- downloadLatest = createButton(composite, SWT.CHECK ,
- "Download latest Maemo SDK server image");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
- .applyTo(downloadLatest);
- downloadLatest.setToolTipText("Selects the latest tested virtual disk image for use as a " +
- "Build Machine in ESbox. This does not have X installed.");
- downloadLatest.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- virtualImagesTable.getTable().setEnabled(
- !downloadLatest.getSelection());
- if (downloadLatest.getSelection())
- doChangeVMChoice(latestVMInstallData);
- validatePage();
- }
- });
-
- virtualImagesTable = new TableViewer(composite, SWT.BORDER | SWT.SCROLL_PAGE);
- virtualImagesTable.addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- Object element = ((IStructuredSelection) event
- .getSelection()).getFirstElement();
- if (element instanceof MaemoSDKVMInfo) {
- doChangeVMChoice((MaemoSDKVMInfo) element);
- validatePage();
- }
- }
-
- });
-
- MaemoSDKVMInstallerContentLabelProvider platformProvider = new MaemoSDKVMInstallerContentLabelProvider();
- platformProvider.addListener(this);
- virtualImagesTable.setContentProvider(platformProvider);
- virtualImagesTable.setLabelProvider(platformProvider);
-
- virtualImagesTable.setComparator(new VirtualImagesComparator());
-
- platformProvider.addListener(new ILabelProviderListener() {
-
- public void labelProviderChanged(LabelProviderChangedEvent event) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- if (!virtualImagesTable.getTable().isDisposed()) {
- for (TableColumn column : virtualImagesTable
- .getTable().getColumns()) {
- column.pack();
- }
- }
- }
- });
- }
- });
-
- Table table = virtualImagesTable.getTable();
- GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo(
- table);
-
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
- table.setEnabled(false);
-
- TableColumn column = new TableColumn(table, SWT.LEFT);
- column.setText("Name");
-
- }
-
- /**
- * Create the contents with options to install Maemo SDK virtual image.
- *
- * @param composite
- * parent composite.
- */
- public void createOptionsContent(Composite composite) {
- Label separator = new Label(composite, SWT.NONE);
- GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
- .applyTo(separator);
-
- Label label = new Label(composite, SWT.NONE);
- label.setText("Install location:");
- GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
- .applyTo(label);
-
- destinationTextField = new Text(composite, SWT.BORDER);
- destinationTextField.setToolTipText("Specify the location to install Maemo SDK Virtual Image.");
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
- destinationTextField);
- destinationTextField.addListener(SWT.SELECTED, textFieldsValidator);
- destinationTextField.addListener(SWT.KeyDown, textFieldsValidator);
- destinationTextField.addListener(SWT.KeyUp, textFieldsValidator);
-
- Button browserButton = createButton(composite, SWT.PUSH ,
- "Browse...");
- GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(
- browserButton);
- browserButton.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent evt) {
- DirectoryDialog dialog = new DirectoryDialog(DialogUtils.getShell(), SWT.OPEN);
- dialog.setText("Select the directory to save the Maemo SDK virtual image");
- String pathDirectory = dialog.open();
- if (pathDirectory != null) {
- destinationTextField.setText(pathDirectory);
- validatePage();
- }
- }
- });
-
- }
-
- /**
- * Create the contents of advanced area.
- *
- * @param composite
- * the parent composite.
- */
- private void createAdvancedContent(Composite composite) {
-
- Label label = new Label(composite, SWT.NONE);
- GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
- .applyTo(label);
-
- advancedButton = new Button(composite, SWT.TOGGLE);
- GridDataFactory.swtDefaults().span(4, 1).applyTo(advancedButton);
- advancedButton.setText("Advanced >>");
- advancedButton.setSelection(false);
-
- advancedContent = new Composite(composite, SWT.NONE);
- GridLayoutFactory.fillDefaults().numColumns(4).applyTo(advancedContent);
-
- GridDataFactory.fillDefaults().grab(true, false).span(4, 1).applyTo(
- advancedContent);
- enableAdvancedContent(false);
-
- usePreviousDownloadButton = createButton(advancedContent, SWT.CHECK,
- "Use previous download");
- GridDataFactory.swtDefaults().span(4, 1).align(SWT.LEFT, SWT.CENTER)
- .applyTo(usePreviousDownloadButton);
- usePreviousDownloadButton
- .setToolTipText("If checked, continue from a previous download of the virtual image if possible; otherwise, always download.");
- usePreviousDownloadButton.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent evt) {
- boolean usePreviousDownload = usePreviousDownloadButton
- .getSelection();
- downloadLatest.setEnabled(!usePreviousDownload);
- virtualImagesTable.getTable().setEnabled(
- !usePreviousDownload && !downloadLatest.getSelection());
- existingVirtualImageTextField.setEnabled(usePreviousDownload);
- ((NewMaemoSDKVMWizard) getWizard()).getInstallData()
- .setUsePreviousInstallation(usePreviousDownload);
- validatePage();
- }
-
- });
-
- label = new Label(advancedContent, SWT.NONE);
- label.setText("Existing virtual image location:");
- GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
- .applyTo(label);
-
- existingVirtualImageTextField = new Text(advancedContent, SWT.BORDER);
- existingVirtualImageTextField.setEnabled(false);
- existingVirtualImageTextField
- .setToolTipText("Specify the location of existing compressed Maemo SDK Virtual Image.");
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
- existingVirtualImageTextField);
- existingVirtualImageTextField.addListener(SWT.SELECTED, textFieldsValidator);
- existingVirtualImageTextField.addListener(SWT.KeyDown, textFieldsValidator);
- existingVirtualImageTextField.addListener(SWT.KeyUp, textFieldsValidator);
-
-
- Button browserButton = createButton(advancedContent, SWT.PUSH, "Browse...");
- GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(
- browserButton);
- browserButton.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent evt) {
- FileDialog dialog = new FileDialog(DialogUtils.getShell(),
- SWT.OPEN);
- dialog.setFilterExtensions(new String[] { "*.zip" });
- dialog.setText("Select the location of compressed virtual image");
- String pathDirectory = dialog.open();
- if (pathDirectory != null) {
- existingVirtualImageTextField.setText(pathDirectory);
- validatePage();
- }
- }
- });
-
- advancedButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (advancedButton.getSelection()) {
- advancedButton.setText("<< Advanced");
- } else {
- advancedButton.setText("Advanced >>");
- }
- enableAdvancedContent(advancedButton.getSelection());
- }
- });
- }
-
- private void createDescriptionContent(Composite composite) {
- Label label = new Label(composite, SWT.NONE);
- label.setText("Description: ");
- GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
- .applyTo(label);
-
- imageDescription = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
- imageDescription.setEditable(false);
- GridData labelData = new GridData();
- labelData.horizontalSpan = 4;
- labelData.horizontalAlignment = SWT.FILL;
- labelData.verticalSpan = 2;
- labelData.verticalAlignment = SWT.FILL;
- Rectangle rect = getShell().getMonitor().getClientArea();
- labelData.widthHint = rect.width / 4;
- imageDescription.setLayoutData(labelData);
- }
-
- private void setInitialValues() {
- downloadLatest.setSelection(true);
- usePreviousDownloadButton.setSelection(false);
- destinationTextField.setText(MachineRegistry.getInstance().getLocalMachine().getUserHome().toOSString());
- existingVirtualImageTextField.setText("");
-
- }
-
- /**
- * Validate information of the wizard page, so we can check if it is
- * possible to proceed or not.
- */
- private void validatePage() {
- String errorMessage = null;
- if (!downloadLatest.getSelection()
- && virtualImagesTable.getSelection().isEmpty()
- && !usePreviousDownloadButton.getSelection()) {
- errorMessage = "Select a Maemo SDK virtual image to be installed on your host machine";
- }
-
- if (errorMessage == null) {
- validateTextFields();
- } else {
- setErrorMessage(errorMessage);
- setPageComplete(false);
- }
-
- }
-
- /**
- * Validate text fields of Maemo SDK selection wizard page.
- * It checks if destination of Maemo SDK VM is properly defined; if location of existing Maemo SDK VM really
- * exists.
- */
- private void validateTextFields() {
- String errorMessage = null;
-
- String destination = destinationTextField.getText().trim();
- if (destination.equals("")){
- errorMessage = "You must specify the destination of Maemo SDK virtual image";
- } else {
- File file = new File(destination);
- if (!file.exists() || !file.isDirectory()){
- errorMessage = "Invalid location for Maemo SDK virtual image. Please, select a valid directory.";
- } else {
- setDownloadFileLocalURL(destination);
- }
- }
-
- String existingVirtualImageLocation = "";
- if (errorMessage == null && usePreviousDownloadButton.getSelection()) {
- existingVirtualImageLocation = existingVirtualImageTextField.getText().trim();
- if (existingVirtualImageLocation.equals("")){
- errorMessage = "You must specify the location of an existing Maemo SDK virtual image";
- } else {
- File file = new File(existingVirtualImageLocation);
- if (!file.exists() || file.isDirectory()){
- errorMessage = "Invalid Maemo SDK virtual image. You must select a zipped file that contains Maemo SDK virtual image.";
- } else {
- ((NewMaemoSDKVMWizard) getWizard()).getInstallData().setPathOfExistentVM(existingVirtualImageLocation);
- }
- }
- }
-
- setErrorMessage(errorMessage);
- setPageComplete(errorMessage == null);
- }
-
-
- /**
- * Utility method to create button.
- *
- * @param composite
- * parent composite.
- * @param style
- * sytle of button.
- * @param text
- * the text of the button.
- * @return a button created from the given options.
- */
- private Button createButton(Composite composite, int style, String text) {
- Button button = new Button(composite, style);
- button.setText(text);
- return button;
- }
-
- private void doChangeVMChoice(MaemoSDKVMInfo data) {
- if (data != null) {
- MaemoSDKVMInstallData installData = ((NewMaemoSDKVMWizard) getWizard())
- .getInstallData();
- installData.setFileToDownload(data);
- String localURL = destinationTextField.getText();
- setDownloadFileLocalURL(localURL);
-
- imageDescription.setText(data.getDescriptor().getDescription());
- }
- }
-
- private void setDownloadFileLocalURL(String pathDirectory) {
- if (pathDirectory != null) {
- File imageLocationPath = new File(pathDirectory);
- if (imageLocationPath.exists() && imageLocationPath.isDirectory())
- ((NewMaemoSDKVMWizard) getWizard()).getInstallData()
- .setInstallationPath(pathDirectory);
- }
- }
-
- /**
- * @param selection
- */
- protected void enableAdvancedContent(boolean selection) {
- advancedContent.setVisible(selection);
- ((GridData) advancedContent.getLayoutData()).exclude = !selection;
- getShell().pack();
- }
-
- /**
- * Create validator for text fields.
- * @return
- */
- protected Listener createTextFieldValidatorListener(){
- return new Listener() {
- public void handleEvent(Event event) {
- validateTextFields();
- }
- };
- }
-
- /**
- * Method to receive notification that information about images on website was properly retrieved. Based on
- * that, it
- */
- public void labelProviderChanged(LabelProviderChangedEvent event) {
- if (event.getClass() == LabelProviderChangedEvent.class) {
- latestVMInstallData = getLatestVMInstallData(event);
- doChangeVMChoice(latestVMInstallData);
- setPageComplete(true);
- validatePage();
- ((Composite)getControl()).layout();
- }
- }
-
- /**
- * Get latest Maemo SDK VM from website.
- * @param event the event to get resource.
- * @return the latest Maemo SDK VM.
- */
- private MaemoSDKVMInfo getLatestVMInstallData(LabelProviderChangedEvent event) {
- LazyLoadingThreadTableContentProvider provider = (LazyLoadingThreadTableContentProvider)event.getSource();
- Object[] elements = provider.getElements(new Object[0]);
- Arrays.sort(elements);
- return (MaemoSDKVMInfo) elements[0];
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.io.File;
+import java.util.Arrays;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.ui.NetworkSettingsUI;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
+import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
+
+/**
+ * Page that displays general information about the Maemo SDK virtual image to
+ * be installed.
+ *
+ * @author raulherbster
+ *
+ */
+public class MaemoSDKVMSelectionWizardPage extends WizardPage implements ILabelProviderListener {
+
+ private MaemoSDKVMInfo latestVMInstallData;
+
+ // Virtual images area
+ private Button downloadLatest;
+ private TableViewer virtualImagesTable;
+
+ // options area
+ private Button usePreviousDownloadButton;
+ private Text destinationTextField;
+
+ // advanced area
+ private Button advancedButton;
+ private Composite advancedContent;
+ private Text existingVirtualImageTextField;
+
+ // listener for changes on text fields
+ private Listener textFieldsValidator;
+
+ // text area for description
+ private Text imageDescription;
+
+ /**
+ * Comparator for virtual images table viewer.
+ */
+ private class VirtualImagesComparator extends ViewerComparator {
+
+ public int compare(Viewer iviewer, Object e1, Object e2) {
+ if (e1 == null) {
+ return -1;
+ } else if (e2 == null) {
+ return 1;
+ } else {
+ return ((MaemoSDKVMInfo)e1).getDescriptor().compareTo(((MaemoSDKVMInfo)e2).getDescriptor());
+ }
+ }
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param wizard
+ * the parent wizard.
+ */
+ protected MaemoSDKVMSelectionWizardPage(NewMaemoSDKVMWizard wizard) {
+ super("maemovm_selection", "Select Maemo SDK Virtual Image",
+ Activator.MAEMO_VM_WIZBAN_DESCRIPTOR);
+ setDescription("A virtual image is a disk image with an installation of Linux/x86 " +
+ "capable of hosting Scratchbox and the Maemo SDK.");
+ setWizard(wizard);
+ setPageComplete(false);
+ textFieldsValidator = createTextFieldValidatorListener();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
+ setControl(composite);
+
+ createVirtualImagesSelector(composite);
+
+ createDescriptionContent(composite);
+
+ createOptionsContent(composite);
+
+ createAdvancedContent(composite);
+
+ setInitialValues();
+
+ virtualImagesTable.setInput(new Object[0]);
+
+ for (TableColumn column : virtualImagesTable.getTable().getColumns()) {
+ column.pack();
+ }
+
+ //validatePage();
+ }
+
+ /**
+ * Create table that displays available Maemo SDK virtual image.
+ *
+ * @param composite
+ * parent composite.
+ */
+ private void createVirtualImagesSelector(Composite composite) {
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Select an image:");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1)
+ .applyTo(label);
+ Link link = NetworkSettingsUI
+ .createStockNetworkSettingHyperlink(composite);
+ GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).span(2, 1)
+ .applyTo(link);
+
+ downloadLatest = createButton(composite, SWT.CHECK ,
+ "Download latest Maemo SDK server image");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
+ .applyTo(downloadLatest);
+ downloadLatest.setToolTipText("Selects the latest tested virtual disk image for use as a " +
+ "Build Machine in ESbox. This does not have X installed.");
+ downloadLatest.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ virtualImagesTable.getTable().setEnabled(
+ !downloadLatest.getSelection());
+ if (downloadLatest.getSelection())
+ doChangeVMChoice(latestVMInstallData);
+ validatePage();
+ }
+ });
+
+ virtualImagesTable = new TableViewer(composite, SWT.BORDER | SWT.SCROLL_PAGE);
+ virtualImagesTable.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object element = ((IStructuredSelection) event
+ .getSelection()).getFirstElement();
+ if (element instanceof MaemoSDKVMInfo) {
+ doChangeVMChoice((MaemoSDKVMInfo) element);
+ validatePage();
+ }
+ }
+
+ });
+
+ MaemoSDKVMInstallerContentLabelProvider platformProvider = new MaemoSDKVMInstallerContentLabelProvider();
+ platformProvider.addListener(this);
+ virtualImagesTable.setContentProvider(platformProvider);
+ virtualImagesTable.setLabelProvider(platformProvider);
+
+ virtualImagesTable.setComparator(new VirtualImagesComparator());
+
+ platformProvider.addListener(new ILabelProviderListener() {
+
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (!virtualImagesTable.getTable().isDisposed()) {
+ for (TableColumn column : virtualImagesTable
+ .getTable().getColumns()) {
+ column.pack();
+ }
+ }
+ }
+ });
+ }
+ });
+
+ Table table = virtualImagesTable.getTable();
+ GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo(
+ table);
+
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ table.setEnabled(false);
+
+ TableColumn column = new TableColumn(table, SWT.LEFT);
+ column.setText("Name");
+
+ }
+
+ /**
+ * Create the contents with options to install Maemo SDK virtual image.
+ *
+ * @param composite
+ * parent composite.
+ */
+ public void createOptionsContent(Composite composite) {
+ Label separator = new Label(composite, SWT.NONE);
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
+ .applyTo(separator);
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Install location:");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
+ .applyTo(label);
+
+ destinationTextField = new Text(composite, SWT.BORDER);
+ destinationTextField.setToolTipText("Specify the location to install Maemo SDK Virtual Image.");
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
+ destinationTextField);
+ destinationTextField.addListener(SWT.SELECTED, textFieldsValidator);
+ destinationTextField.addListener(SWT.KeyDown, textFieldsValidator);
+ destinationTextField.addListener(SWT.KeyUp, textFieldsValidator);
+
+ Button browserButton = createButton(composite, SWT.PUSH ,
+ "Browse...");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(
+ browserButton);
+ browserButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent evt) {
+ DirectoryDialog dialog = new DirectoryDialog(DialogUtils.getShell(), SWT.OPEN);
+ dialog.setText("Select the directory to save the Maemo SDK virtual image");
+ String pathDirectory = dialog.open();
+ if (pathDirectory != null) {
+ destinationTextField.setText(pathDirectory);
+ validatePage();
+ }
+ }
+ });
+
+ }
+
+ /**
+ * Create the contents of advanced area.
+ *
+ * @param composite
+ * the parent composite.
+ */
+ private void createAdvancedContent(Composite composite) {
+
+ Label label = new Label(composite, SWT.NONE);
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
+ .applyTo(label);
+
+ advancedButton = new Button(composite, SWT.TOGGLE);
+ GridDataFactory.swtDefaults().span(4, 1).applyTo(advancedButton);
+ advancedButton.setText("Advanced >>");
+ advancedButton.setSelection(false);
+
+ advancedContent = new Composite(composite, SWT.NONE);
+ GridLayoutFactory.fillDefaults().numColumns(4).applyTo(advancedContent);
+
+ GridDataFactory.fillDefaults().grab(true, false).span(4, 1).applyTo(
+ advancedContent);
+ enableAdvancedContent(false);
+
+ usePreviousDownloadButton = createButton(advancedContent, SWT.CHECK,
+ "Use previous download");
+ GridDataFactory.swtDefaults().span(4, 1).align(SWT.LEFT, SWT.CENTER)
+ .applyTo(usePreviousDownloadButton);
+ usePreviousDownloadButton
+ .setToolTipText("If checked, continue from a previous download of the virtual image if possible; otherwise, always download.");
+ usePreviousDownloadButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent evt) {
+ boolean usePreviousDownload = usePreviousDownloadButton
+ .getSelection();
+ downloadLatest.setEnabled(!usePreviousDownload);
+ virtualImagesTable.getTable().setEnabled(
+ !usePreviousDownload && !downloadLatest.getSelection());
+ existingVirtualImageTextField.setEnabled(usePreviousDownload);
+ ((NewMaemoSDKVMWizard) getWizard()).getInstallData()
+ .setUsePreviousInstallation(usePreviousDownload);
+ validatePage();
+ }
+
+ });
+
+ label = new Label(advancedContent, SWT.NONE);
+ label.setText("Existing virtual image location:");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
+ .applyTo(label);
+
+ existingVirtualImageTextField = new Text(advancedContent, SWT.BORDER);
+ existingVirtualImageTextField.setEnabled(false);
+ existingVirtualImageTextField
+ .setToolTipText("Specify the location of existing compressed Maemo SDK Virtual Image.");
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
+ existingVirtualImageTextField);
+ existingVirtualImageTextField.addListener(SWT.SELECTED, textFieldsValidator);
+ existingVirtualImageTextField.addListener(SWT.KeyDown, textFieldsValidator);
+ existingVirtualImageTextField.addListener(SWT.KeyUp, textFieldsValidator);
+
+
+ Button browserButton = createButton(advancedContent, SWT.PUSH, "Browse...");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(
+ browserButton);
+ browserButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent evt) {
+ FileDialog dialog = new FileDialog(DialogUtils.getShell(),
+ SWT.OPEN);
+ dialog.setFilterExtensions(new String[] { "*.zip" });
+ dialog.setText("Select the location of compressed virtual image");
+ String pathDirectory = dialog.open();
+ if (pathDirectory != null) {
+ existingVirtualImageTextField.setText(pathDirectory);
+ validatePage();
+ }
+ }
+ });
+
+ advancedButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (advancedButton.getSelection()) {
+ advancedButton.setText("<< Advanced");
+ } else {
+ advancedButton.setText("Advanced >>");
+ }
+ enableAdvancedContent(advancedButton.getSelection());
+ }
+ });
+ }
+
+ private void createDescriptionContent(Composite composite) {
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Description: ");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(4, 1)
+ .applyTo(label);
+
+ imageDescription = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
+ imageDescription.setEditable(false);
+ GridData labelData = new GridData();
+ labelData.horizontalSpan = 4;
+ labelData.horizontalAlignment = SWT.FILL;
+ labelData.verticalSpan = 2;
+ labelData.verticalAlignment = SWT.FILL;
+ Rectangle rect = getShell().getMonitor().getClientArea();
+ labelData.widthHint = rect.width / 4;
+ imageDescription.setLayoutData(labelData);
+ }
+
+ private void setInitialValues() {
+ downloadLatest.setSelection(true);
+ usePreviousDownloadButton.setSelection(false);
+ destinationTextField.setText(MachineRegistry.getInstance().getLocalMachine().getUserHome().toOSString());
+ existingVirtualImageTextField.setText("");
+
+ }
+
+ /**
+ * Validate information of the wizard page, so we can check if it is
+ * possible to proceed or not.
+ */
+ private void validatePage() {
+ String errorMessage = null;
+ if (!downloadLatest.getSelection()
+ && virtualImagesTable.getSelection().isEmpty()
+ && !usePreviousDownloadButton.getSelection()) {
+ errorMessage = "Select a Maemo SDK virtual image to be installed on your host machine";
+ }
+
+ if (errorMessage == null) {
+ validateTextFields();
+ } else {
+ setErrorMessage(errorMessage);
+ setPageComplete(false);
+ }
+
+ }
+
+ /**
+ * Validate text fields of Maemo SDK selection wizard page.
+ * It checks if destination of Maemo SDK VM is properly defined; if location of existing Maemo SDK VM really
+ * exists.
+ */
+ private void validateTextFields() {
+ String errorMessage = null;
+
+ String destination = destinationTextField.getText().trim();
+ if (destination.equals("")){
+ errorMessage = "You must specify the destination of Maemo SDK virtual image";
+ } else {
+ File file = new File(destination);
+ if (!file.exists() || !file.isDirectory()){
+ errorMessage = "Invalid location for Maemo SDK virtual image. Please, select a valid directory.";
+ } else {
+ setDownloadFileLocalURL(destination);
+ }
+ }
+
+ String existingVirtualImageLocation = "";
+ if (errorMessage == null && usePreviousDownloadButton.getSelection()) {
+ existingVirtualImageLocation = existingVirtualImageTextField.getText().trim();
+ if (existingVirtualImageLocation.equals("")){
+ errorMessage = "You must specify the location of an existing Maemo SDK virtual image.";
+ } else {
+ File file = new File(existingVirtualImageLocation);
+ if (!file.exists() || file.isDirectory()){
+ errorMessage = "Invalid Maemo SDK virtual image. You must select a zipped file that contains Maemo SDK virtual image.";
+ } else {
+ ((NewMaemoSDKVMWizard) getWizard()).getInstallData().setPathOfExistentVM(existingVirtualImageLocation);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Utility method to create button.
+ *
+ * @param composite
+ * parent composite.
+ * @param style
+ * sytle of button.
+ * @param text
+ * the text of the button.
+ * @return a button created from the given options.
+ */
+ private Button createButton(Composite composite, int style, String text) {
+ Button button = new Button(composite, style);
+ button.setText(text);
+ return button;
+ }
+
+ private void doChangeVMChoice(MaemoSDKVMInfo data) {
+ if (data != null) {
+ MaemoSDKVMInstallData installData = ((NewMaemoSDKVMWizard) getWizard())
+ .getInstallData();
+ installData.setFileToDownload(data);
+ String localURL = destinationTextField.getText();
+ setDownloadFileLocalURL(localURL);
+
+ imageDescription.setText(data.getDescriptor().getDescription());
+ }
+ }
+
+ private void setDownloadFileLocalURL(String pathDirectory) {
+ if (pathDirectory != null) {
+ File imageLocationPath = new File(pathDirectory);
+ if (imageLocationPath.exists() && imageLocationPath.isDirectory())
+ ((NewMaemoSDKVMWizard) getWizard()).getInstallData()
+ .setInstallationPath(pathDirectory);
+ }
+ }
+
+ /**
+ * @param selection
+ */
+ protected void enableAdvancedContent(boolean selection) {
+ advancedContent.setVisible(selection);
+ ((GridData) advancedContent.getLayoutData()).exclude = !selection;
+ getShell().pack();
+ }
+
+ /**
+ * Create validator for text fields.
+ * @return
+ */
+ protected Listener createTextFieldValidatorListener(){
+ return new Listener() {
+ public void handleEvent(Event event) {
+ validateTextFields();
+ }
+ };
+ }
+
+ /**
+ * Method to receive notification that information about images on website was properly retrieved. Based on
+ * that, it
+ */
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ if (event.getClass() == LabelProviderChangedEvent.class) {
+ latestVMInstallData = getLatestVMInstallData(event);
+ if (latestVMInstallData != null) {
+ doChangeVMChoice(latestVMInstallData);
+ setPageComplete(true);
+ validatePage();
+ ((Composite)getControl()).layout();
+ }
+ }
+ }
+
+ /**
+ * Get latest Maemo SDK VM from website.
+ * @param event the event to get resource.
+ * @return the latest Maemo SDK VM.
+ */
+ private MaemoSDKVMInfo getLatestVMInstallData(LabelProviderChangedEvent event) {
+ LazyLoadingThreadTableContentProvider provider = (LazyLoadingThreadTableContentProvider)event.getSource();
+ Object[] elements = provider.getElements(new Object[0]);
+ Arrays.sort(elements);
+ if (elements.length > 0)
+ return (MaemoSDKVMInfo) elements[0];
+ else
+ return null;
+ }
+
+}
Added: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java (rev 0)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+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.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
+
+/**
+ * This page displays information about Maemo SDK virtual machine configuration.
+ *
+ * @author raulherbster
+ *
+ */
+public class MaemoSDKVMUncompressInfoWizardPage extends WizardPage {
+
+ // options for uncompress tool
+ private Text uncompressToolTextField;
+
+ /**
+ * Constructor.
+ *
+ * @param wizard
+ * parent wizard.
+ */
+ protected MaemoSDKVMUncompressInfoWizardPage(NewMaemoSDKVMWizard wizard) {
+ super("maemovm_uncompresstool", "Uncompress tool specification",
+ Activator.MAEMO_VM_WIZBAN_DESCRIPTOR);
+ setDescription("Specify the tool used to uncompress Maemo SDK Virtual Image.");
+ setWizard(wizard);
+ setPageComplete(false);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
+ setControl(composite);
+
+ Label mainMessage = new Label(composite, SWT.WRAP);
+ mainMessage.setText("Maemo SDK Virtual Image wizard also uncompress the virtual machine for you. " +
+ "However, since Maemo SDK Virtual Images are considerable large, most of existing tools cannot uncompress them.\n" +
+ "This wizard uses 7zip tool for uncompression, please specify a valid path for 7zip tool bellow.");
+
+ GridData labelData = new GridData();
+ labelData.horizontalSpan = 4;
+ labelData.horizontalAlignment = SWT.FILL;
+ Rectangle rect = getShell().getMonitor().getClientArea();
+ labelData.widthHint = rect.width / 4;
+ mainMessage.setLayoutData(labelData);
+
+ Label separator = new Label(composite, SWT.NONE);
+ GridDataFactory.swtDefaults().span(4, 1).align(SWT.LEFT, SWT.CENTER)
+ .applyTo(separator);
+
+
+ Label uncompressToollabel = new Label(composite, SWT.NONE);
+ uncompressToollabel.setText("Uncompress tool path:");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
+ .applyTo(uncompressToollabel);
+
+ uncompressToolTextField = new Text(composite, SWT.BORDER);
+ uncompressToolTextField.setText(getDefault7zPath());
+ uncompressToolTextField.setToolTipText("Specify the path of tool to uncompress Maemo SDK Virtual Image.");
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
+ uncompressToolTextField);
+
+ Listener textFieldValidator = new Listener() {
+ public void handleEvent(Event event) {
+ validatePage();
+ }
+ };
+
+ uncompressToolTextField.addListener(SWT.SELECTED, textFieldValidator);
+ uncompressToolTextField.addListener(SWT.KeyDown, textFieldValidator);
+ uncompressToolTextField.addListener(SWT.KeyUp, textFieldValidator);
+
+ Button browserButton = new Button(composite, SWT.PUSH);
+ browserButton.setText("Browse...");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(
+ browserButton);
+ browserButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent evt) {
+ FileDialog dialog = new FileDialog(DialogUtils.getShell(),
+ SWT.OPEN);
+
+ String currentFile = uncompressToolTextField.getText();
+ if (currentFile.length() > 0) {
+ File current = new File(currentFile);
+ dialog.setFilterPath(current.getParent());
+ dialog.setFileName(current.getName());
+ }
+ dialog.setText("Select the path of uncompress tool");
+ String pathDirectory = dialog.open();
+ if (pathDirectory != null) {
+ uncompressToolTextField.setText(pathDirectory);
+ validatePage();
+ }
+ }
+ });
+
+ validatePage();
+ }
+
+ /**
+ * Validate the wizard page.
+ */
+ public void validatePage() {
+ String errorMessage = null;
+
+ String uncompressToolPath = uncompressToolTextField.getText().trim();
+ if (uncompressToolPath.equals("")){
+ errorMessage = "You must specify the path of tool to uncompress the Maemo SDK Virtual Image.";
+ } else {
+ File file = new File(uncompressToolPath);
+ if (!file.exists() || file.isDirectory()){
+ errorMessage = "Invalid path for uncompress tool. Please, select a valid directory.";
+ } else {
+ ((NewMaemoSDKVMWizard) getWizard()).getInstallData().setUncompressToolPath(uncompressToolPath);
+ }
+ }
+
+ setErrorMessage(errorMessage);
+ setPageComplete(errorMessage == null);
+ }
+
+
+ public static String getDefault7zPath(){
+ String path = "/usr/bin/7z";
+
+ IMachine machine = MachineRegistry.getInstance().getLocalMachine();
+ if (machine.getOS().equals(Platform.OS_WIN32))
+ return "C:/Program Files/7-Zip/7z.exe";
+
+ if (machine.getOS().equals(Platform.OS_LINUX)) {
+ return "/usr/bin/7z";
+ }
+ if (machine.getOS().equals(Platform.OS_MACOSX)) {
+ return "/usr/bin/7za";
+ }
+ return path;
+
+ }
+}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java 2009-09-04 20:54:50 UTC (rev 2112)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java 2009-09-04 21:22:55 UTC (rev 2113)
@@ -1,171 +1,173 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInstaller;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-import org.maemo.mica.common.core.Policy;
-import org.maemo.mica.common.core.ui.IProgressReporter;
-import org.maemo.mica.internal.api.common.ui.wizards.WizardWorkProgressPageBase;
-
-/**
- * The Maemo SDK Virtual Image wizard provides an easy method to install SDK
- * Virtual Image for pre-installed VMWare Player/Fusion (download, install and
- * configure latest empty server image for Maemo)
- *
- * @author raulherbster
- *
- */
-public class NewMaemoSDKVMWizard extends Wizard implements INewWizard {
-
- private MaemoSDKVMSelectionWizardPage targetPage;
- private MaemoSDKVMInstallationWorkPage downloadUncompressWorkPage;
- private MaemoSDKVMConfigurationWizardPage configurationPage;
- private MaemoSDKVMLicenseWizardPage licensePage;
- private MaemoSDKVMInstallData installData;
-
- /**
- * Constructor
- */
- public NewMaemoSDKVMWizard() {
- initialize();
- // create an empty install data
- installData = new MaemoSDKVMInstallData();
- }
-
- /**
- * Initialize main information about this wizard.
- */
- private void initialize() {
- setNeedsProgressMonitor(true);
- setWindowTitle("Install Maemo SDK Virtual Machine");
- ImageDescriptor image = Activator.MAEMO_VM_WIZBAN_DESCRIPTOR;
- setDefaultPageImageDescriptor(image);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#addPages()
- */
- public void addPages() {
- targetPage = new MaemoSDKVMSelectionWizardPage(this);
- addPage(targetPage);
- configurationPage = new MaemoSDKVMConfigurationWizardPage(this);
- addPage(configurationPage);
- licensePage = new MaemoSDKVMLicenseWizardPage(this);
- addPage(licensePage);
- downloadUncompressWorkPage = new MaemoSDKVMInstallationWorkPage(this);
- addPage(downloadUncompressWorkPage);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
- * org.eclipse.jface.viewers.IStructuredSelection)
- */
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Get the work page to show information about installation process.
- *
- * @return the work page of this wizard.
- */
- public WizardWorkProgressPageBase getWorkPage() {
- return downloadUncompressWorkPage;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#performFinish()
- */
- public boolean performFinish() {
- final IStatus status = doWork();
-
- final boolean success = (status.isOK() || status.matches(IStatus.INFO));
-
- String message = success ? "Installation succeeded"
- : "Installation encountered some errors";
-
- boolean goOn = getWorkPage().reportOperationStatus(
- "Maemo SDK Virtual Image installation results", message,
- status, true)
- && !status.matches(IStatus.CANCEL);
-
- return goOn;
- }
-
- protected IStatus doWork() {
-
- getWorkPage().showAndClearLog();
-
- final IStatus[] statuses = { Policy.getCancelStatus(Activator
- .getDefault()) };
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
-
- IStatus status = null;
-
- IProgressReporter reporter = getWorkPage().getProgressReporter();
-
- MaemoSDKVMInstaller vmInstaller = new MaemoSDKVMInstaller(installData, reporter);
-
- status = vmInstaller.installVirtualImage(((MaemoSDKVMInstallationWorkPage)getWorkPage()).getTimeout(), getShell(), monitor);
-
- if (status.matches(IStatus.CANCEL))
- status = Activator.createErrorStatus("The Maemo SDK virtual image installation was canceled.", null);
-
- if (status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR))
- reporter.appendStreamText(status.getMessage(), true);
-
- statuses[0] = status;
- }
-
- });
- } catch (Exception e) {
- Activator.getErrorLogger().logAndShowError(e.getMessage(),
- e.getCause());
- statuses[0] = Activator.createErrorStatus("Maemo SDK virtual image installation failed unexpectedly",
- e);
- }
- return statuses[0];
- }
-
- /**
- * Get the installation data that contains information to install Maemo SDK
- * virtual image.
- *
- * @return the installation data.
- */
- public MaemoSDKVMInstallData getInstallData() {
- return installData;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInstaller;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.Policy;
+import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.internal.api.common.ui.wizards.WizardWorkProgressPageBase;
+
+/**
+ * The Maemo SDK Virtual Image wizard provides an easy method to install SDK
+ * Virtual Image for pre-installed VMWare Player/Fusion (download, install and
+ * configure latest empty server image for Maemo)
+ *
+ * @author raulherbster
+ *
+ */
+public class NewMaemoSDKVMWizard extends Wizard implements INewWizard {
+
+ private MaemoSDKVMSelectionWizardPage targetPage;
+ private MaemoSDKVMInstallationWorkPage downloadUncompressWorkPage;
+ private MaemoSDKVMConfigurationWizardPage configurationPage;
+ private MaemoSDKVMUncompressInfoWizardPage uncompressToolPage;
+ private MaemoSDKVMLicenseWizardPage licensePage;
+ private MaemoSDKVMInstallData installData;
+
+ /**
+ * Constructor
+ */
+ public NewMaemoSDKVMWizard() {
+ initialize();
+ // create an empty install data
+ installData = new MaemoSDKVMInstallData();
+ }
+
+ /**
+ * Initialize main information about this wizard.
+ */
+ private void initialize() {
+ setNeedsProgressMonitor(true);
+ setWindowTitle("Install Maemo SDK Virtual Machine");
+ ImageDescriptor image = Activator.MAEMO_VM_WIZBAN_DESCRIPTOR;
+ setDefaultPageImageDescriptor(image);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ */
+ public void addPages() {
+ targetPage = new MaemoSDKVMSelectionWizardPage(this);
+ addPage(targetPage);
+ uncompressToolPage = new MaemoSDKVMUncompressInfoWizardPage(this);
+ addPage(uncompressToolPage);
+ configurationPage = new MaemoSDKVMConfigurationWizardPage(this);
+ addPage(configurationPage);
+ licensePage = new MaemoSDKVMLicenseWizardPage(this);
+ addPage(licensePage);
+ downloadUncompressWorkPage = new MaemoSDKVMInstallationWorkPage(this);
+ addPage(downloadUncompressWorkPage);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
+ * org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Get the work page to show information about installation process.
+ *
+ * @return the work page of this wizard.
+ */
+ public WizardWorkProgressPageBase getWorkPage() {
+ return downloadUncompressWorkPage;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ public boolean performFinish() {
+ final IStatus status = doWork();
+
+ final boolean success = (status.isOK() || status.matches(IStatus.INFO));
+
+ String message = success ? "Installation succeeded"
+ : "Installation encountered some errors";
+
+ boolean goOn = getWorkPage().reportOperationStatus(
+ "Maemo SDK Virtual Image installation results", message,
+ status, true)
+ && !status.matches(IStatus.CANCEL);
+
+ return goOn;
+ }
+
+ protected IStatus doWork() {
+
+ getWorkPage().showAndClearLog();
+
+ final IStatus[] statuses = { Policy.getCancelStatus(Activator
+ .getDefault()) };
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+
+ IStatus status = null;
+
+ IProgressReporter reporter = getWorkPage().getProgressReporter();
+
+ MaemoSDKVMInstaller vmInstaller = new MaemoSDKVMInstaller(installData, reporter);
+
+ status = vmInstaller.installVirtualImage(((MaemoSDKVMInstallationWorkPage)getWorkPage()).getTimeout(), getShell(), monitor);
+
+ if (status.matches(IStatus.CANCEL))
+ status = Activator.createErrorStatus("The Maemo SDK virtual image installation was canceled.", null);
+
+ if (status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR))
+ reporter.appendStreamText(status.getMessage(), true);
+
+ statuses[0] = status;
+ }
+
+ });
+ } catch (Exception e) {
+ Activator.getErrorLogger().logAndShowError(e.getMessage(),
+ e.getCause());
+ statuses[0] = Activator.createErrorStatus("Maemo SDK virtual image installation failed unexpectedly",
+ e);
+ }
+ return statuses[0];
+ }
+
+ /**
+ * Get the installation data that contains information to install Maemo SDK
+ * virtual image.
+ *
+ * @return the installation data.
+ */
+ public MaemoSDKVMInstallData getInstallData() {
+ return installData;
+ }
+
+}
More information about the Esbox-commits
mailing list