Wizard can now import projects of any time (i.e. Dreamweaver, WRT IDE) from the filesystem
--- a/org.symbian.tools.wrttools.previewer/preview/css/style.css Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/preview/css/style.css Thu Feb 25 14:26:09 2010 -0800
@@ -283,7 +283,7 @@
div#PreferencesBtn{
width: 75px;
height: 85px;
- background-image: url(../images/settings-icon.png);
+ background-image: url(../images/settings-icon.png);
position: absolute;
top: 10px;
left: 10px;
@@ -459,7 +459,7 @@
}
div#event-memory{
- background-image: url(../images/memory-icon.png);
+ background-image: url(../images/memory-icon.png);
}
div.ui-panel{
--- a/org.symbian.tools.wrttools.previewer/preview/wrt_preview.html Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools.previewer/preview/wrt_preview.html Thu Feb 25 14:26:09 2010 -0800
@@ -209,10 +209,10 @@
<div id="orientationIcon"></div>
<div id="loaderDiv"></div>
<div id="NotificationDiv" class="hide">
- <p>NOKIA WRT Simulation may not work properly on this browser, <br/>Firefox is recommended for widget preview and debugging. <br/><br/><strong>Continue?</strong></p>
+ <p>WRT Simulation may not work properly on this browser, <br/>Chrome is recommended for widget preview and debugging. <br/><br/><strong>Continue?</strong></p>
</div>
<div id="BrowserNotificationBar" class="hide">
- <p><a></a>NOKIA WRT Simulation may not work properly on this browser, Firefox is recommended for widget preview and debugging</p>
+ <p><a></a>WRT Simulation may not work properly on this browser, Chrome is recommended for widget preview and debugging</p>
</div>
</body>
</html>
--- a/org.symbian.tools.wrttools/plugin.xml Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/plugin.xml Thu Feb 25 14:26:09 2010 -0800
@@ -203,13 +203,6 @@
templates
</description>
</wizard>
- <wizard category="org.symbian.tools.wrttools.core.category"
- class="org.symbian.tools.wrttools.wizards.AptanaProjectsImportWizard"
- finalPerspective="org.symbian.tools.wrttools.mainPerspective"
- hasPages="true" icon="icons/import_aptana_project.gif"
- id="org.symbian.tools.wrttools.newImportAptanaProject" name="Import Aptana IDE WRT Project"
- project="true">
- </wizard>
</extension>
<!-- WRT Project Templates -->
@@ -280,16 +273,16 @@
<category id="org.symbian.tools.wrttools.import" name="Web Runtime(WRT)">
</category>
<wizard category="org.symbian.tools.wrttools.import"
- class="org.symbian.tools.wrttools.wizards.AptanaProjectsImportWizard"
+ class="org.symbian.tools.wrttools.wizards.projectimport.AptanaProjectsImportWizard"
icon="icons/import_aptana_project.gif" id="org.symbian.tools.wrttools.import.aptanaImport"
- name="Aptana IDE WRT Project">
+ name="WRT Project">
</wizard>
<wizard
category="org.symbian.tools.wrttools.import"
class="org.symbian.tools.wrttools.wizards.WgzImportWizard"
icon="icons/WRTImport.gif"
id="org.symbian.tools.wrttools.importwgz"
- name="WRT Application Archive (WGZ) File">
+ name="Sources from WGZ File">
</wizard>
</extension>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deployer/IWidgetDeployer.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deployer/IWidgetDeployer.java Thu Feb 25 14:26:09 2010 -0800
@@ -1,13 +1,21 @@
-/* ============================================================================
- * Copyright © 2008 Nokia. All rights reserved.
- * This material, including documentation and any related computer
- * programs, is protected by copyright controlled by Nokia. All
- * rights are reserved. Copying, including reproducing, storing,
- * adapting or translating, any or all of this material requires the
- * prior written consent of Nokia. This material also contains
- * confidential information which may not be disclosed to others
- * without the prior written consent of Nokia.
- * ============================================================================*/
+/**
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
package org.symbian.tools.wrttools.core.deployer;
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deployer/WidgetDeployer.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deployer/WidgetDeployer.java Thu Feb 25 14:26:09 2010 -0800
@@ -1,13 +1,21 @@
-/* ============================================================================
- * Copyright © 2008 Nokia. All rights reserved.
- * This material, including documentation and any related computer
- * programs, is protected by copyright controlled by Nokia. All
- * rights are reserved. Copying, including reproducing, storing,
- * adapting or translating, any or all of this material requires the
- * prior written consent of Nokia. This material also contains
- * confidential information which may not be disclosed to others
- * without the prior written consent of Nokia.
- * ============================================================================*/
+/**
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
package org.symbian.tools.wrttools.core.deployer;
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/marker/WRTMarker.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/marker/WRTMarker.java Thu Feb 25 14:26:09 2010 -0800
@@ -38,7 +38,7 @@
* WRTValidator problem marker type. This can be used to recognize those markers
* in the workspace that flag problems detected by the CodeScanner plugin.
*/
- public static final String WRT_PROBLEM_MARKER = Activator.PLUGIN_ID + ".com.nokia.wrt.core.validator.marker"; //$NON-NLS-1$
+ public static final String WRT_PROBLEM_MARKER = Activator.PLUGIN_ID + ".org.symbian.tools.wrttools.core.validator.marker"; //$NON-NLS-1$
// public static final String WRT_PROBLEM_MARKER = Activator.PLUGIN_ID + ".WRTMarker"; //$NON-NLS-1$
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/ExcludeFileAction.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/ExcludeFileAction.java Thu Feb 25 14:26:09 2010 -0800
@@ -68,7 +68,7 @@
}
}
/*Refresh project tree when property is changed */
- PlatformUI.getWorkbench().getDecoratorManager().update("com.nokia.wrt.decorator");
+ PlatformUI.getWorkbench().getDecoratorManager().update("org.symbian.tools.wrttools.decorator");
}
public void selectionChanged(IAction action, ISelection selection) {
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IncludeFileAction.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IncludeFileAction.java Thu Feb 25 14:26:09 2010 -0800
@@ -71,7 +71,7 @@
}
}
/*Refresh project tree when property is changed */
- PlatformUI.getWorkbench().getDecoratorManager().update("com.nokia.wrt.decorator");
+ PlatformUI.getWorkbench().getDecoratorManager().update("org.symbian.tools.wrttools.decorator");
}
/**
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerZipFolder.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerZipFolder.java Thu Feb 25 14:26:09 2010 -0800
@@ -40,8 +40,6 @@
//import org.apache.commons.io.IOUtils;
-//import com.nokia.wrt.core.report.IMessageListener;
-//import com.nokia.wrt.core.report.Message;
import org.symbian.tools.wrttools.core.status.IWRTConstants;
import org.symbian.tools.wrttools.core.status.IWRTStatusListener;
import org.symbian.tools.wrttools.core.status.WRTStatus;
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WRTPackagerConstants.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WRTPackagerConstants.java Thu Feb 25 14:26:09 2010 -0800
@@ -23,7 +23,7 @@
public class WRTPackagerConstants {
- public static QualifiedName EXCLUDE_PROPERTY = new QualifiedName("com.nokia.wrt.packager", "exclude");
+ public static QualifiedName EXCLUDE_PROPERTY = new QualifiedName("org.symbian.tools.wrttools.core.packager", "exclude");
public static String STA_PKG_PASSED = PackagerMessages.getString("WRTPackagerConstants.success"); //$NON-NLS-1$
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/report/IMessageListener.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/report/IMessageListener.java Thu Feb 25 14:26:09 2010 -0800
@@ -1,13 +1,21 @@
-/* ============================================================================
- * Copyright © 2008 Nokia. All rights reserved.
- * This material, including documentation and any related computer
- * programs, is protected by copyright controlled by Nokia. All
- * rights are reserved. Copying, including reproducing, storing,
- * adapting or translating, any or all of this material requires the
- * prior written consent of Nokia. This material also contains
- * confidential information which may not be disclosed to others
- * without the prior written consent of Nokia.
- * ============================================================================*/
+/**
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
package org.symbian.tools.wrttools.core.report;
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/report/messages.properties Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/report/messages.properties Thu Feb 25 14:26:09 2010 -0800
@@ -1,7 +1,7 @@
HtmlReportHandler.convert.title=Dashboard widget conversion report
-HtmlReportHandler.convert.description=Automatic conversions performed by the converter to match Nokia Web Runtime.
+HtmlReportHandler.convert.description=Automatic conversions performed by the converter to match Web Runtime.
HtmlReportHandler.analysis.report.title=Dashboard widget analysis report
-HtmlReportHandler.analysis.report.description=This analysis report lists the mandatory or optional conversions needed to port the widget to Nokia Web Runtime.
+HtmlReportHandler.analysis.report.description=This analysis report lists the mandatory or optional conversions needed to port the widget to Web Runtime.
HtmlReportHandler.file.name=File name
HtmlReportHandler.line.number=Line number
HtmlReportHandler.convert.action.needed=Action needed
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/IWRTConstants.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/IWRTConstants.java Thu Feb 25 14:26:09 2010 -0800
@@ -74,11 +74,11 @@
/**
* Locally stored Nokia DTD
*/
- public static String NOKIA_PLIST_DTD = "/com/nokia/wrt/core/widgetmodel/plist-1.0.dtd";
+ public static String NOKIA_PLIST_DTD = "/org/symbian/tools/wrttools/core/widgetmodel/plist-1.0.dtd";
/**
* Locally stored Apple DTD
*/
- public static String APPLE_PLIST_DTD = "/com/nokia/wrt/core/converter/PropertyList-1.0.dtd";
+// public static String APPLE_PLIST_DTD = "/com/nokia/wrt/core/converter/PropertyList-1.0.dtd";
/**
* Nokia DTD in nfo.plist file
*/
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/WidgetValidator.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/WidgetValidator.java Thu Feb 25 14:26:09 2010 -0800
@@ -54,7 +54,7 @@
* .plist - This file will be parsed to verify for the Nokia specific DTD
*
* 1. <key >DisplayName</key> - display name should exist
- * 2. <key>Identifier</key> - value should be of com.nokia. **
+ * 2. <key>Identifier</key> - value should be of org.symbian.tools.wrttools. **
* 3. <key>MainHTML</key> - value should be same as the .html file name
*
*
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/widgetmodel/WidgetModel.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/widgetmodel/WidgetModel.java Thu Feb 25 14:26:09 2010 -0800
@@ -1272,20 +1272,7 @@
try {
showData(" ############################################################################################################################# ");
model.getWidgetModel( "C:/ModelTest/Flickr");
-// model.getWidgetModel( "C:/ModelTest/HelloWorld");
-// model.getWidgetModel( "C:/ModelTest/mFootyAmazonPedia.wdgt");
-
-// model.getWidgetModel( "C:/ModelTest/mFooty");
-// model.getWidgetModel( "C:/ModelTest/NokiaRSS");
-// model.getWidgetModel( "C:/ModelTest/Widgets/bmi");
-// model.getWidgetModel( "C:/ModelTest/blink");
-// model.getWidgetModel( "C:/ModelTest/Gmail");
-// model.getWidgetModel( "C:/ModelTest/MOSH");
-// model.getWidgetModel( "C:/ModelTest/AmazonPedia.wdgt");
-// model.getWidgetModel( "C:/ModelTest/UniversalDecider");
-// model.getWidgetModel( "d:/ModelTest/Beep");
-// model.getWidgetModel( "C:/ModelTest/blankPlist");
-// model.getWidgetModel( "C:/ModelTest/AmazonPedia.wdgt");
+
/**
List<String> fileNames=null;
FileUtil filehelper = new FileUtil();
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/DefaultMessageListener.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/DefaultMessageListener.java Thu Feb 25 14:26:09 2010 -0800
@@ -32,7 +32,7 @@
/* (non-Javadoc)
- * @see com.nokia.sdt.utils.IMessageListener#isHandlingMessage(com.nokia.sdt.utils.IMessage)
+ * @see org.symbian.tools.wrttools.sdt.utils.IMessageListener#isHandlingMessage(org.symbian.tools.wrttools.sdt.utils.IMessage)
*/
public boolean isHandlingMessage(IMessage msg) {
// in case this gets added as a MessageReporting listener
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/Logging.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/Logging.java Thu Feb 25 14:26:09 2010 -0800
@@ -269,7 +269,7 @@
* @param option
* The debug option to test. The plugin's symbolic name is
* prepended to the option name, e.g.
- * "com.nokia.myplugin"+"/"+option
+ * "org.symbian.tools.wrttools.myplugin"+"/"+option
* @return true if debugging enabled and option enabled (e.g. defined and
* set to "true")
*/
@@ -325,7 +325,7 @@
* the calling plugin, or null
* @param option
* the debug option to test. The plugin name is prepended to the
- * option name, e.g. "com.nokia.myplugin"+"/"+option
+ * option name, e.g. "org.symbian.tools.wrttools.myplugin"+"/"+option
* @param status
* the status object
* @see Logging#isDebugOptionEnabled(Plugin, String)
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/Message.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/Message.java Thu Feb 25 14:26:09 2010 -0800
@@ -146,56 +146,56 @@
}
/* (non-Javadoc)
- * @see com.nokia.sdt.component.sourcegen.ISourceGenProblem#getSeverity()
+ * @see org.symbian.tools.wrttools.sdt.component.sourcegen.ISourceGenProblem#getSeverity()
*/
public int getSeverity() {
return severity;
}
/* (non-Javadoc)
- * @see com.nokia.sdt.utils.IMessage#getMessageLocation()
+ * @see org.symbian.tools.wrttools.sdt.utils.IMessage#getMessageLocation()
*/
public MessageLocation getMessageLocation() {
return ref;
}
/* (non-Javadoc)
- * @see com.nokia.sdt.utils.IMessage#getLocation()
+ * @see org.symbian.tools.wrttools.sdt.utils.IMessage#getLocation()
*/
public IPath getLocation() {
return ref != null ? ref.getLocation() : null;
}
/* (non-Javadoc)
- * @see com.nokia.sdt.utils.IMessage#getPath()
+ * @see org.symbian.tools.wrttools.sdt.utils.IMessage#getPath()
*/
public IPath getPath() {
return ref != null ? ref.getPath() : null;
}
/* (non-Javadoc)
- * @see com.nokia.sdt.component.sourcegen.ISourceGenProblem#getLineNumber()
+ * @see org.symbian.tools.wrttools.sdt.component.sourcegen.ISourceGenProblem#getLineNumber()
*/
public int getLineNumber() {
return ref != null ? ref.lineNumber : -1;
}
/* (non-Javadoc)
- * @see com.nokia.sdt.sourcegen.ISourceGenMessage#getColumnNumber()
+ * @see org.symbian.tools.wrttools.sdt.sourcegen.ISourceGenMessage#getColumnNumber()
*/
public int getColumnNumber() {
return ref != null ? ref.columnNumber : -1;
}
/* (non-Javadoc)
- * @see com.nokia.sdt.component.sourcegen.ISourceGenProblem#getMessage()
+ * @see org.symbian.tools.wrttools.sdt.component.sourcegen.ISourceGenProblem#getMessage()
*/
public String getMessage() {
return text;
}
/* (non-Javadoc)
- * @see com.nokia.sdt.component.sourcegen.ISourceGenProblem#getMessageKey()
+ * @see org.symbian.tools.wrttools.sdt.component.sourcegen.ISourceGenProblem#getMessageKey()
*/
public String getMessageKey() {
return key;
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/noexport/Messages.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/sdt/utils/noexport/Messages.java Thu Feb 25 14:26:09 2010 -0800
@@ -27,7 +27,7 @@
*
*/
public class Messages {
- private static final String BUNDLE_NAME = "com.nokia.sdt.utils.noexport.messages";//$NON-NLS-1$
+ private static final String BUNDLE_NAME = "org.symbian.tools.wrttools.sdt.utils.noexport.messages";//$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
.getBundle(BUNDLE_NAME);
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java Thu Feb 25 14:26:09 2010 -0800
@@ -2,8 +2,8 @@
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.Reader;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
@@ -47,6 +47,16 @@
return null;
}
+ public static String getApplicationName(String buffer) {
+ if (buffer != null) {
+ Matcher matcher = getPropertyLookupPattern("DisplayName").matcher(buffer);
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+ }
+ return null;
+ }
+
public static Pattern getPropertyLookupPattern(String propertyName) {
return Pattern.compile(MessageFormat.format(PROPERTY_PATTERN, propertyName), Pattern.CASE_INSENSITIVE);
}
@@ -77,20 +87,9 @@
throws CoreException {
try {
if (file != null && file.isAccessible()) {
- InputStream contents = file.getContents();
final BufferedReader reader = new BufferedReader(
- new InputStreamReader(contents, file.getCharset()));
- StringBuffer buffer = new StringBuffer();
- try {
- int c = 0;
- char[] buf = new char[4096];
- while ((c = reader.read(buf)) > 0) {
- buffer.append(buf, 0, c);
- }
- return buffer.toString();
- } finally {
- reader.close();
- }
+ new InputStreamReader(file.getContents(), file.getCharset()));
+ return read(reader);
}
return null;
} catch (IOException e) {
@@ -98,6 +97,20 @@
}
}
+ public static String read(final Reader reader) throws IOException {
+ StringBuffer buffer = new StringBuffer();
+ try {
+ int c = 0;
+ char[] buf = new char[4096];
+ while ((c = reader.read(buf)) > 0) {
+ buffer.append(buf, 0, c);
+ }
+ return buffer.toString();
+ } finally {
+ reader.close();
+ }
+ }
+
private static final Map<IProject, IndexFileRecord> INDEX_FILES = new HashMap<IProject, IndexFileRecord>();
public static synchronized String getIndexFile(IProject project) throws CoreException {
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Wed Feb 24 16:12:51 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Thu Feb 25 14:26:09 2010 -0800
@@ -23,8 +23,12 @@
import java.io.IOException;
import java.net.URI;
import java.text.MessageFormat;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.TreeSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -55,9 +59,9 @@
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.MultiPartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
import org.eclipse.ui.part.ISetSelectionTarget;
import org.eclipse.wst.jsdt.core.JavaScriptCore;
import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock;
@@ -67,216 +71,10 @@
@SuppressWarnings("restriction")
public class ProjectUtils {
- private static final String DEFAULT_APTANA_WORKSPACE = "Aptana Studio Workspace";
- public static final String PREVIEW_FOLDER = "preview";
- public static final String PREVIEW_FRAME_FILE = "wrt_preview_frame.html";
- public static final String PREVIEW_MAIN_FILE = "wrt_preview_main.html";
-
- private static boolean isDefaultProjectLocation(URI uri) {
- if (uri == null) {
- return true;
- }
- File file = new File(uri);
- IPath project = new Path(file.getAbsolutePath());
- IPath workspace = ResourcesPlugin.getWorkspace().getRoot()
- .getLocation();
- return workspace.isPrefixOf(project);
- }
-
- 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);
- BuildPathsBlock.createProject(project, uri, new SubProgressMonitor(
- monitor, 10));
- BuildPathsBlock.addJavaNature(project, new SubProgressMonitor(monitor,
- 10));
-
- ValidationFramework.getDefault().addValidationBuilder(project);
- ValidationFramework.getDefault().applyChanges(
- ValidationFramework.getDefault().getProjectSettings(project),
- true);
-
- // TODO: Build path, super type, etc.
- // BuildPathsBlock.flush(classPathEntries, javaScriptProject, superType,
- // monitor)
-
- addWrtNature(project);
-
- monitor.done();
- return project;
- }
-
- public static void addWrtNature(IProject project) {
- if (!hasWrtNature(project)) {
- try {
- IProjectDescription description = project.getDescription();
- String[] natureIds = description.getNatureIds();
- String[] newNatures = new String[natureIds.length + 1];
- System.arraycopy(natureIds, 0, newNatures, 1, natureIds.length);
- newNatures[0] = WidgetProjectNature.ID;
- description.setNatureIds(newNatures);
-
- ICommand[] buildSpec = description.getBuildSpec();
- for (int i = 0; i < buildSpec.length; i++) {
- ICommand command = buildSpec[i];
- if (JavaScriptCore.BUILDER_ID.equals(command
- .getBuilderName())) {
- buildSpec[i] = buildSpec[buildSpec.length - 1];
- buildSpec[buildSpec.length - 1] = command;
- description.setBuildSpec(buildSpec);
- break;
- }
- }
-
- project.setDescription(description, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.log(e);
- }
- }
- }
-
- public static boolean hasWrtNature(IProject project) {
- try {
- return project.hasNature(WidgetProjectNature.ID);
- } catch (CoreException e) {
- Activator.log(e);
- return false;
- }
- }
-
- public static String getDefaultAptanaLocation() {
- File myDocuments = FileSystemView.getFileSystemView()
- .getDefaultDirectory();
- File file = new File(myDocuments, DEFAULT_APTANA_WORKSPACE); // Windows
- if (file.exists()) {
- return file.getAbsolutePath();
- }
- file = new File(myDocuments, "Documents" + File.separator
- + DEFAULT_APTANA_WORKSPACE); // Mac OS X
- if (file.exists()) {
- return file.getAbsolutePath();
- }
- return "";
- }
-
- public static boolean isAptanaProject(File f) {
- return new File(f, PREVIEW_FOLDER).isDirectory()
- && new File(f, PREVIEW_FRAME_FILE).isFile();
- }
-
- public static void copyFile(IProject project, String name,
- ZipInputStream stream, long size, IProgressMonitor monitor)
- throws CoreException, IOException {
- IFile file = project.getFile(name);
- file.create(new NonClosingStream(stream), true, new SubProgressMonitor(
- monitor, 1));
- }
-
- public static boolean isAptanaProject(URI locationURI) {
- return isAptanaProject(new File(locationURI));
- }
-
- public static File isAptanaProject(File[] contents) {
- File dotProjectFile = null;
- boolean hasPreviewer = false;
- boolean hasFrame = false;
-
- for (int i = 0; i < contents.length; i++) {
- File file = contents[i];
- if (file.isFile()
- && file.getName().equals(
- IProjectDescription.DESCRIPTION_FILE_NAME)) {
- dotProjectFile = file;
- }
- if (file.isFile()
- && PREVIEW_FRAME_FILE.equalsIgnoreCase(file.getName())) {
- hasFrame = true;
- }
- if (file.isDirectory()
- && PREVIEW_FOLDER.equalsIgnoreCase(file.getName())) {
- hasPreviewer = true;
- }
- }
- if (!(hasFrame && hasPreviewer)) {
- dotProjectFile = null;
- }
- return dotProjectFile;
- }
-
- 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());
- }
- }
-
- public static boolean isPlist(IResource resource) {
- return resource.getType() == IResource.FILE
- && resource.getName().equalsIgnoreCase("info.plist");
- }
-
- public static void focusOn(IProject... projects) {
- new FocusOnProjectJob(projects, Display.getCurrent()).schedule(50);
- }
-
- private static final class TouchAllResources implements IWorkspaceRunnable {
- private final IProject[] projects;
-
- public TouchAllResources(IProject[] projects) {
- this.projects = projects;
-
- }
-
- public void run(IProgressMonitor monitor) throws CoreException {
- for (IProject project : projects) {
- project.accept(new IResourceVisitor() {
- public boolean visit(IResource resource)
- throws CoreException {
- if (resource.isAccessible()
- && resource.getType() == IResource.FILE
- && resource.getFileExtension().equals("js")) {
- resource.touch(new NullProgressMonitor());
- }
- return true;
- }
- });
- }
- }
- }
-
private static final class FocusOnProjectJob extends Job {
+ private final Display display;
private final IProject[] projects;
- private final Display display;
public FocusOnProjectJob(IProject[] projects, Display display) {
super("Preparing projects");
@@ -338,4 +136,220 @@
return Status.OK_STATUS;
}
}
+ private static final class TouchAllResources implements IWorkspaceRunnable {
+ private final IProject[] projects;
+
+ public TouchAllResources(IProject[] projects) {
+ this.projects = projects;
+
+ }
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ for (IProject project : projects) {
+ project.accept(new IResourceVisitor() {
+ public boolean visit(IResource resource)
+ throws CoreException {
+ if (resource.isAccessible()
+ && resource.getType() == IResource.FILE
+ && resource.getFileExtension().equals("js")) {
+ resource.touch(new NullProgressMonitor());
+ }
+ return true;
+ }
+ });
+ }
+ }
+ }
+ private static final String DEFAULT_APTANA_WORKSPACE = "Aptana Studio Workspace";
+ private static final Collection<String> EXCLUDED;
+
+ public static final String PREVIEW_FOLDER = "preview";
+
+ public static final String PREVIEW_FRAME_FILE = "wrt_preview_frame.html";
+
+ public static final String PREVIEW_MAIN_FILE = "wrt_preview_main.html";
+
+ static {
+ EXCLUDED = new TreeSet<String>(Arrays.asList(".project", ProjectUtils.PREVIEW_FOLDER,
+ ProjectUtils.PREVIEW_FRAME_FILE, ProjectUtils.PREVIEW_MAIN_FILE));
+ }
+
+ private static boolean accepted(Object object) {
+ final String name;
+ if (object instanceof ZipEntry) {
+ name = ((ZipEntry) object).getName();
+ } else if (object instanceof TarEntry) {
+ name = ((TarEntry) object).getName();
+ } else if (object instanceof File) {
+ name = ((File) object).getAbsolutePath();
+ } else {
+ throw new IllegalArgumentException("Unforeseen entry type: " + object.getClass());
+ }
+ IPath path = new Path(name);
+ return isValidProjectFile(path.lastSegment());
+ }
+
+ public static void addWrtNature(IProject project) {
+ if (!hasWrtNature(project)) {
+ try {
+ IProjectDescription description = project.getDescription();
+ String[] natureIds = description.getNatureIds();
+ String[] newNatures = new String[natureIds.length + 1];
+ System.arraycopy(natureIds, 0, newNatures, 1, natureIds.length);
+ newNatures[0] = WidgetProjectNature.ID;
+ description.setNatureIds(newNatures);
+
+ ICommand[] buildSpec = description.getBuildSpec();
+ for (int i = 0; i < buildSpec.length; i++) {
+ ICommand command = buildSpec[i];
+ if (JavaScriptCore.BUILDER_ID.equals(command
+ .getBuilderName())) {
+ buildSpec[i] = buildSpec[buildSpec.length - 1];
+ buildSpec[buildSpec.length - 1] = command;
+ description.setBuildSpec(buildSpec);
+ break;
+ }
+ }
+
+ project.setDescription(description, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator.log(e);
+ }
+ }
+ }
+
+ 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());
+ }
+ }
+
+ public static void copyFile(IProject project, String name,
+ ZipInputStream stream, long size, IProgressMonitor monitor)
+ throws CoreException, IOException {
+ IFile file = project.getFile(name);
+ file.create(new NonClosingStream(stream), true, new SubProgressMonitor(
+ monitor, 1));
+ }
+
+ 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);
+ BuildPathsBlock.createProject(project, uri, new SubProgressMonitor(
+ monitor, 10));
+ BuildPathsBlock.addJavaNature(project, new SubProgressMonitor(monitor,
+ 10));
+
+ ValidationFramework.getDefault().addValidationBuilder(project);
+ ValidationFramework.getDefault().applyChanges(
+ ValidationFramework.getDefault().getProjectSettings(project),
+ true);
+
+ // TODO: Build path, super type, etc.
+ // BuildPathsBlock.flush(classPathEntries, javaScriptProject, superType,
+ // monitor)
+
+ addWrtNature(project);
+
+ monitor.done();
+ return project;
+ }
+
+ public static List<Object> filterExternalProjectEntries(List<Object> fileSystemObjects) {
+ List<Object> result = new LinkedList<Object>();
+ for (Object object : fileSystemObjects) {
+ if (accepted(object)) {
+ result.add(object);
+ }
+ }
+ return result;
+ }
+
+ public static void focusOn(IProject... projects) {
+ new FocusOnProjectJob(projects, Display.getCurrent()).schedule(50);
+ }
+
+ public static String getDefaultAptanaLocation() {
+ File myDocuments = FileSystemView.getFileSystemView()
+ .getDefaultDirectory();
+ File file = new File(myDocuments, DEFAULT_APTANA_WORKSPACE); // Windows
+ if (file.exists()) {
+ return file.getAbsolutePath();
+ }
+ file = new File(myDocuments, "Documents" + File.separator
+ + DEFAULT_APTANA_WORKSPACE); // Mac OS X
+ if (file.exists()) {
+ return file.getAbsolutePath();
+ }
+ return "";
+ }
+
+ public static boolean hasWrtNature(IProject project) {
+ try {
+ return project.hasNature(WidgetProjectNature.ID);
+ } catch (CoreException e) {
+ Activator.log(e);
+ return false;
+ }
+ }
+
+ public static File isAptanaProject(File[] contents) {
+ for (int i = 0; i < contents.length; i++) {
+ File file = contents[i];
+ if (file.isFile() && file.getName().equalsIgnoreCase(CoreUtil.METADATA_FILE)) {
+ return file.getParentFile();
+ }
+ }
+ return null;
+ }
+
+ private static boolean isDefaultProjectLocation(URI uri) {
+ if (uri == null) {
+ return true;
+ }
+ File file = new File(uri);
+ IPath project = new Path(file.getAbsolutePath());
+ IPath workspace = ResourcesPlugin.getWorkspace().getRoot()
+ .getLocation();
+ return workspace.isPrefixOf(project);
+ }
+
+ public static boolean isPlist(IResource resource) {
+ return resource.getType() == IResource.FILE && resource.getName().equalsIgnoreCase(CoreUtil.METADATA_FILE);
+ }
+
+ private static boolean isValidProjectFile(String fileName) {
+ return !EXCLUDED.contains(fileName);
+ }
+
+ 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();
+ }
+
}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java Wed Feb 24 16:12:51 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1561 +0,0 @@
-/**
- * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Symbian Foundation - initial contribution.
- * Contributors:
- * Description:
- * Overview:
- * Details:
- * Platforms/Drives/Compatibility:
- * Assumptions/Requirement/Pre-requisites:
- * Failures and causes:
- */
-package org.symbian.tools.wrttools.wizards;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.layout.PixelConverter;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.IColorProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.TraverseEvent;
-import org.eclipse.swt.events.TraverseListener;
-import org.eclipse.swt.graphics.Color;
-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.DirectoryDialog;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkingSet;
-import org.eclipse.ui.IWorkingSetManager;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-import org.eclipse.ui.dialogs.IOverwriteQuery;
-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.StatusUtil;
-import org.eclipse.ui.internal.wizards.datatransfer.ArchiveFileManipulations;
-import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
-import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider;
-import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
-import org.eclipse.ui.internal.wizards.datatransfer.TarException;
-import org.eclipse.ui.internal.wizards.datatransfer.TarFile;
-import org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider;
-import org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider;
-import org.eclipse.ui.statushandlers.StatusManager;
-import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
-import org.eclipse.ui.wizards.datatransfer.ImportOperation;
-import org.symbian.tools.wrttools.Activator;
-import org.symbian.tools.wrttools.util.ProjectUtils;
-
-@SuppressWarnings({"restriction", "unchecked"})
-public class AptanaProjectLocationWizardPage extends WizardPage implements
- IOverwriteQuery {
-
- /**
- * @since 3.5
- *
- */
- private final class ProjectLabelProvider extends LabelProvider implements
- IColorProvider {
-
- public Color getBackground(Object element) {
- return null;
- }
-
- public Color getForeground(Object element) {
- ProjectRecord projectRecord = (ProjectRecord) element;
- if (projectRecord.hasConflicts)
- return getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY);
- return null;
- }
-
- public String getText(Object element) {
- return ((ProjectRecord) element).getProjectLabel();
- }
- }
-
- /**
- * Class declared public only for test suite.
- *
- */
- public class ProjectRecord {
- IProjectDescription description;
-
- boolean hasConflicts;
-
- int level;
-
- Object parent;
-
- Object projectArchiveFile;
-
- String projectName;
-
- File projectSystemFile;
-
- /**
- * Create a record for a project based on the info in the file.
- *
- * @param file
- */
- ProjectRecord(File file) {
- projectSystemFile = file;
- setProjectName();
- }
-
- /**
- * @param file
- * The Object representing the .project file
- * @param parent
- * The parent folder of the .project file
- * @param level
- * The number of levels deep in the provider the file is
- */
- ProjectRecord(Object file, Object parent, int level) {
- this.projectArchiveFile = file;
- this.parent = parent;
- this.level = level;
- setProjectName();
- }
-
- /**
- * Gets the label to be used when rendering this project record in the
- * UI.
- *
- * @return String the label
- * @since 3.4
- */
- public String getProjectLabel() {
- if (description == null)
- return projectName;
-
- String path = projectSystemFile == null ? structureProvider
- .getLabel(parent) : projectSystemFile.getParent();
-
- return NLS.bind(
- DataTransferMessages.WizardProjectsImportPage_projectLabel,
- projectName, path);
- }
-
- /**
- * Get the name of the project
- *
- * @return String
- */
- public String getProjectName() {
- return projectName;
- }
-
- /**
- * @return Returns the hasConflicts.
- */
- public boolean hasConflicts() {
- return hasConflicts;
- }
-
- /**
- * Returns whether the given project description file path is in the
- * default location for a project
- *
- * @param path
- * The path to examine
- * @return Whether the given path is the default location for a project
- */
- private boolean isDefaultLocation(IPath path) {
- // The project description file must at least be within the project,
- // which is within the workspace location
- if (path.segmentCount() < 2)
- return false;
- return path.removeLastSegments(2).toFile().equals(
- Platform.getLocation().toFile());
- }
-
- /**
- * Set the name of the project based on the projectFile.
- */
- private void setProjectName() {
- try {
- if (projectArchiveFile != null) {
- InputStream stream = structureProvider
- .getContents(projectArchiveFile);
-
- // If we can get a description pull the name from there
- if (stream == null) {
- if (projectArchiveFile instanceof ZipEntry) {
- IPath path = new Path(
- ((ZipEntry) projectArchiveFile).getName());
- projectName = path.segment(path.segmentCount() - 2);
- } else if (projectArchiveFile instanceof TarEntry) {
- IPath path = new Path(
- ((TarEntry) projectArchiveFile).getName());
- projectName = path.segment(path.segmentCount() - 2);
- }
- } else {
- description = IDEWorkbenchPlugin.getPluginWorkspace()
- .loadProjectDescription(stream);
- stream.close();
- projectName = description.getName();
- }
-
- }
-
- // If we don't have the project name try again
- if (projectName == null) {
- IPath path = new Path(projectSystemFile.getPath());
- // if the file is in the default location, use the directory
- // name as the project name
- if (isDefaultLocation(path)) {
- projectName = path.segment(path.segmentCount() - 2);
- description = IDEWorkbenchPlugin.getPluginWorkspace()
- .newProjectDescription(projectName);
- } else {
- description = IDEWorkbenchPlugin.getPluginWorkspace()
- .loadProjectDescription(path);
- projectName = description.getName();
- }
-
- }
- } catch (CoreException e) {
- // no good couldn't get the name
- } catch (IOException e) {
- // no good couldn't get the name
- }
- }
- }
-
- // constant from WizardArchiveFileResourceImportPage1
- private static final String[] FILE_IMPORT_MASK = {
- "*.jar;*.zip;*.tar;*.tar.gz;*.tgz", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
-
- /**
- * The name of the folder containing metadata information for the workspace.
- */
- public static final String METADATA_FOLDER = ".metadata"; //$NON-NLS-1$
-
- // Keep track of the archive that we browsed to last time
- // the wizard was invoked.
- private static String previouslyBrowsedArchive = ""; //$NON-NLS-1$
-
- // Keep track of the directory that we browsed to last time
- // the wizard was invoked.
- private static String previouslyBrowsedDirectory = ""; //$NON-NLS-1$
-
- private final static String STORE_ARCHIVE_SELECTED = "WizardProjectsImportPage.STORE_ARCHIVE_SELECTED"; //$NON-NLS-1$
-
- private Text archivePathField;
-
- private Button browseArchivesButton;
-
- private Button browseDirectoriesButton;
-
- List createdProjects;
-
- private IStructuredSelection currentSelection;
-
- private Text directoryPathField;
-
- // The initial path to set
- private String initialPath;
-
- // The last time that the file or folder at the selected path was modified
- // to mimize searches
- private long lastModified;
-
- // The last selected path to minimize searches
- private String lastPath;
-
- private Button projectFromArchiveRadio;
-
- private Button projectFromDirectoryRadio;
-
- private CheckboxTreeViewer projectsList;
- private ProjectRecord[] selectedProjects = new ProjectRecord[0];
-
- /**
- * The import structure provider.
- *
- * @since 3.4
- */
- private ILeveledImportStructureProvider structureProvider;
-
- private WorkingSetGroup workingSetGroup;
-
- private IProject[] wsProjects;
-
- private static final Collection<String> EXCLUDED;
-
- static {
- EXCLUDED = new TreeSet<String>(Arrays.asList(".project",
- ProjectUtils.PREVIEW_FOLDER, ProjectUtils.PREVIEW_FRAME_FILE,
- ProjectUtils.PREVIEW_MAIN_FILE));
- }
-
- public AptanaProjectLocationWizardPage() {
- super("projectlocation", "Import Aptana WRT Projects", null);
- setDescription("Select location of the Aptana WRT projects");
- }
-
- private void addToWorkingSets() {
-
- IWorkingSet[] selectedWorkingSets = workingSetGroup
- .getSelectedWorkingSets();
- if (selectedWorkingSets == null || selectedWorkingSets.length == 0)
- return; // no Working set is selected
- IWorkingSetManager workingSetManager = PlatformUI.getWorkbench()
- .getWorkingSetManager();
- for (Iterator i = createdProjects.iterator(); i.hasNext();) {
- IProject project = (IProject) i.next();
- workingSetManager.addToWorkingSets(project, selectedWorkingSets);
- }
- }
-
- private void archiveRadioSelected() {
- if (projectFromArchiveRadio.getSelection()) {
- directoryPathField.setEnabled(false);
- browseDirectoriesButton.setEnabled(false);
- archivePathField.setEnabled(true);
- browseArchivesButton.setEnabled(true);
- updateProjectsList(archivePathField.getText());
- archivePathField.setFocus();
- }
- }
-
- public List<IProject> getCreatedProjects() {
- return createdProjects;
- }
-
- /**
- * Collect the list of .project files that are under directory into files.
- *
- * @param files
- * @param directory
- * @param directoriesVisited
- * Set of canonical paths of directories, used as recursion guard
- * @param monitor
- * The monitor to report to
- * @return boolean <code>true</code> if the operation was completed.
- */
- private boolean collectProjectFilesFromDirectory(Collection files,
- File directory, Set directoriesVisited, IProgressMonitor monitor) {
-
- if (monitor.isCanceled()) {
- return false;
- }
- monitor.subTask(NLS.bind(
- DataTransferMessages.WizardProjectsImportPage_CheckingMessage,
- directory.getPath()));
- File[] contents = directory.listFiles();
- if (contents == null)
- return false;
-
- // Initialize recursion guard for recursive symbolic links
- if (directoriesVisited == null) {
- directoriesVisited = new HashSet();
- try {
- directoriesVisited.add(directory.getCanonicalPath());
- } catch (IOException exception) {
- StatusManager.getManager().handle(
- StatusUtil.newStatus(IStatus.ERROR, exception
- .getLocalizedMessage(), exception));
- }
- }
-
-
- File dotProjectFile = ProjectUtils.isAptanaProject(contents);
-
- if (dotProjectFile != null) {
- files.add(dotProjectFile);
- // don't search sub-directories since we can't have nested
- // projects
- return true;
- }
- // no project description found, so recurse into sub-directories
- for (int i = 0; i < contents.length; i++) {
- if (contents[i].isDirectory()) {
- if (!contents[i].getName().equals(METADATA_FOLDER)) {
- try {
- String canonicalPath = contents[i].getCanonicalPath();
- if (!directoriesVisited.add(canonicalPath)) {
- // already been here --> do not recurse
- continue;
- }
- } catch (IOException exception) {
- StatusManager.getManager().handle(
- StatusUtil.newStatus(IStatus.ERROR, exception
- .getLocalizedMessage(), exception));
-
- }
- collectProjectFilesFromDirectory(files, contents[i],
- directoriesVisited, monitor);
- }
- }
- }
- return true;
- }
-
- /**
- * Collect the list of .project files that are under directory into files.
- *
- * @param files
- * @param monitor
- * The monitor to report to
- * @return boolean <code>true</code> if the operation was completed.
- */
- private boolean collectProjectFilesFromProvider(Collection files,
- Object entry, int level, IProgressMonitor monitor) {
-
- if (monitor.isCanceled()) {
- return false;
- }
- monitor.subTask(NLS.bind(
- DataTransferMessages.WizardProjectsImportPage_CheckingMessage,
- structureProvider.getLabel(entry)));
- List children = structureProvider.getChildren(entry);
- if (children == null) {
- children = new ArrayList(1);
- }
- Iterator childrenEnum = children.iterator();
- boolean hasPreviewFolder = false;
- boolean hasFrameHtml = false;
- ProjectRecord projectRecord = null;
- while (childrenEnum.hasNext()) {
- Object child = childrenEnum.next();
- String elementLabel = structureProvider.getLabel(child);
- if (structureProvider.isFolder(child)) {
- if (ProjectUtils.PREVIEW_FOLDER.equalsIgnoreCase(elementLabel)) {
- hasPreviewFolder = true;
- }
- collectProjectFilesFromProvider(files, child, level + 1,
- monitor);
- }
- if (elementLabel.equals(IProjectDescription.DESCRIPTION_FILE_NAME)) {
- projectRecord = new ProjectRecord(child, entry, level);
- }
- if (ProjectUtils.PREVIEW_FRAME_FILE.equalsIgnoreCase(elementLabel)) {
- hasFrameHtml = true;
- }
- }
- if (projectRecord != null && hasPreviewFolder && hasFrameHtml) {
- files.add(projectRecord);
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
- * .Composite)
- */
- public void createControl(Composite parent) {
-
- initializeDialogUnits(parent);
-
- Composite workArea = new Composite(parent, SWT.NONE);
- setControl(workArea);
-
- workArea.setLayout(new GridLayout());
- workArea.setLayoutData(new GridData(GridData.FILL_BOTH
- | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
-
- createProjectsRoot(workArea);
- createProjectsList(workArea);
- createWorkingSetGroup(workArea);
- restoreWidgetValues();
- Dialog.applyDialogFont(workArea);
-
- updateProjectsList(directoryPathField.getText().trim());
- }
-
- /**
- * Create the project described in record. If it is successful return true.
- *
- * @param record
- * @return boolean <code>true</code> if successful
- * @throws InterruptedException
- */
- private boolean createExistingProject(final ProjectRecord record,
- IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- monitor.beginTask(MessageFormat.format("Creating {0}", record
- .getProjectName()), IProgressMonitor.UNKNOWN);
-
- try {
- IProject project = ProjectUtils.createWrtProject(record
- .getProjectName(), null,
- new SubProgressMonitor(monitor, 10));
- createdProjects.add(project);
- if (record.projectArchiveFile != null) {
- // import from archive
- List fileSystemObjects = structureProvider
- .getChildren(record.parent);
- fileSystemObjects = filterEntries(fileSystemObjects);
- structureProvider.setStrip(record.level);
- ImportOperation operation = new ImportOperation(project
- .getFullPath(), structureProvider.getRoot(),
- structureProvider, this, fileSystemObjects);
- operation.setContext(getShell());
- operation.run(monitor);
- return true;
- } else {
- File importSource = new File(record.description
- .getLocationURI());
- List filesToImport = filterEntries(FileSystemStructureProvider.INSTANCE
- .getChildren(importSource));
- ImportOperation operation = new ImportOperation(project
- .getFullPath(), importSource,
- FileSystemStructureProvider.INSTANCE, this,
- filesToImport);
- operation.setContext(getShell());
- operation.setOverwriteResources(true); // need to overwrite
- // .project, .classpath
- // files
- operation.setCreateContainerStructure(false);
- operation.run(monitor);
- }
- } catch (CoreException e) {
- Activator.log(e);
- return false;
- } finally {
- monitor.done();
- }
- return true;
- }
-
- private List filterEntries(List fileSystemObjects) {
- List result = new LinkedList();
- for (Object object : fileSystemObjects) {
- if (accepted(object)) {
- result.add(object);
- }
- }
- return result;
- }
-
- private boolean accepted(Object object) {
- final String name;
- if (object instanceof ZipEntry) {
- name = ((ZipEntry) object).getName();
- } else if (object instanceof TarEntry) {
- name = ((TarEntry) object).getName();
- } else if (object instanceof File) {
- name = ((File) object).getAbsolutePath();
- } else {
- throw new IllegalArgumentException("Unforeseen entry type: "
- + object.getClass());
- }
- IPath path = new Path(name);
- return isValidProjectFile(path.lastSegment());
- }
-
- private boolean isValidProjectFile(String fileName) {
- return !EXCLUDED.contains(fileName);
- }
-
- /**
- * Create the selected projects
- *
- * @return boolean <code>true</code> if all project creations were
- * successful.
- */
- public boolean createProjects() {
- saveWidgetValues();
-
- final Object[] selected = projectsList.getCheckedElements();
- createdProjects = new ArrayList();
- WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
- protected void execute(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- try {
- monitor.beginTask("", selected.length); //$NON-NLS-1$
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- for (int i = 0; i < selected.length; i++) {
- createExistingProject((ProjectRecord) selected[i],
- new SubProgressMonitor(monitor, 1));
- }
- } finally {
- monitor.done();
- }
- }
- };
- // run the new project creation operation
- try {
- getContainer().run(true, true, op);
- } catch (InterruptedException e) {
- return false;
- } catch (InvocationTargetException e) {
- // one of the steps resulted in a core exception
- Throwable t = e.getTargetException();
- String message = DataTransferMessages.WizardExternalProjectImportPage_errorMessage;
- IStatus status;
- if (t instanceof CoreException) {
- status = ((CoreException) t).getStatus();
- } else {
- status = new Status(IStatus.ERROR,
- IDEWorkbenchPlugin.IDE_WORKBENCH, 1, message, t);
- }
- ErrorDialog.openError(getShell(), message, null, status);
- return false;
- }
- ArchiveFileManipulations.closeStructureProvider(structureProvider,
- getShell());
-
- // Adds the projects to the working sets
- addToWorkingSets();
-
- return true;
- }
-
- /**
- * Create the checkbox list for the found projects.
- *
- * @param workArea
- */
- private void createProjectsList(Composite workArea) {
-
- Label title = new Label(workArea, SWT.NONE);
- title
- .setText(DataTransferMessages.WizardProjectsImportPage_ProjectsListTitle);
-
- Composite listComposite = new Composite(workArea, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginWidth = 0;
- layout.makeColumnsEqualWidth = false;
- listComposite.setLayout(layout);
-
- listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
- | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
-
- projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER);
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- gridData.widthHint = new PixelConverter(projectsList.getControl())
- .convertWidthInCharsToPixels(25);
- gridData.heightHint = new PixelConverter(projectsList.getControl())
- .convertHeightInCharsToPixels(10);
- projectsList.getControl().setLayoutData(gridData);
- projectsList.setContentProvider(new ITreeContentProvider() {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
- public void dispose() {
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java
- * .lang.Object)
- */
- public Object[] getChildren(Object parentElement) {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.IStructuredContentProvider#getElements
- * (java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return getProjectRecords();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java
- * .lang.Object)
- */
- public Object getParent(Object element) {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java
- * .lang.Object)
- */
- public boolean hasChildren(Object element) {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
- * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput,
- Object newInput) {
- }
-
- });
-
- projectsList.setLabelProvider(new ProjectLabelProvider());
-
- projectsList.addCheckStateListener(new ICheckStateListener() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
- * (org.eclipse.jface.viewers.CheckStateChangedEvent)
- */
- public void checkStateChanged(CheckStateChangedEvent event) {
- ProjectRecord element = (ProjectRecord) event.getElement();
- if (element.hasConflicts) {
- projectsList.setChecked(element, false);
- }
- setPageComplete(projectsList.getCheckedElements().length > 0);
- }
- });
-
- projectsList.setInput(this);
- projectsList.setComparator(new ViewerComparator());
- createSelectionButtons(listComposite);
- }
-
- /**
- * Create the area where you select the root directory for the projects.
- *
- * @param workArea
- * Composite
- */
- private void createProjectsRoot(Composite workArea) {
-
- // project specification group
- Composite projectGroup = new Composite(workArea, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 3;
- layout.makeColumnsEqualWidth = false;
- layout.marginWidth = 0;
- projectGroup.setLayout(layout);
- projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- // new project from directory radio button
- projectFromDirectoryRadio = new Button(projectGroup, SWT.RADIO);
- projectFromDirectoryRadio
- .setText(DataTransferMessages.WizardProjectsImportPage_RootSelectTitle);
-
- // project location entry field
- this.directoryPathField = new Text(projectGroup, SWT.BORDER);
-
- GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true,
- false);
- directoryPathData.widthHint = new PixelConverter(directoryPathField)
- .convertWidthInCharsToPixels(25);
- directoryPathField.setLayoutData(directoryPathData);
-
- directoryPathField.setText(ProjectUtils.getDefaultAptanaLocation());
-
- // browse button
- browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);
- browseDirectoriesButton
- .setText(DataTransferMessages.DataTransfer_browse);
- setButtonLayoutData(browseDirectoriesButton);
-
- // new project from archive radio button
- projectFromArchiveRadio = new Button(projectGroup, SWT.RADIO);
- projectFromArchiveRadio
- .setText(DataTransferMessages.WizardProjectsImportPage_ArchiveSelectTitle);
-
- // project location entry field
- archivePathField = new Text(projectGroup, SWT.BORDER);
-
- GridData archivePathData = new GridData(SWT.FILL, SWT.NONE, true, false);
- archivePathData.widthHint = new PixelConverter(archivePathField)
- .convertWidthInCharsToPixels(25);
- archivePathField.setLayoutData(archivePathData); // browse button
- browseArchivesButton = new Button(projectGroup, SWT.PUSH);
- browseArchivesButton.setText(DataTransferMessages.DataTransfer_browse);
- setButtonLayoutData(browseArchivesButton);
-
- projectFromDirectoryRadio.setSelection(true);
- archivePathField.setEnabled(false);
- browseArchivesButton.setEnabled(false);
-
- browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.swt.events.SelectionAdapter#widgetS
- * elected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- handleLocationDirectoryButtonPressed();
- }
-
- });
-
- browseArchivesButton.addSelectionListener(new SelectionAdapter() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- handleLocationArchiveButtonPressed();
- }
-
- });
-
- directoryPathField.addTraverseListener(new TraverseListener() {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse
- * .swt.events.TraverseEvent)
- */
- public void keyTraversed(TraverseEvent e) {
- if (e.detail == SWT.TRAVERSE_RETURN) {
- e.doit = false;
- updateProjectsList(directoryPathField.getText().trim());
- }
- }
-
- });
-
- directoryPathField.addFocusListener(new FocusAdapter() {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
- * .events.FocusEvent)
- */
- public void focusLost(org.eclipse.swt.events.FocusEvent e) {
- updateProjectsList(directoryPathField.getText().trim());
- }
-
- });
-
- archivePathField.addTraverseListener(new TraverseListener() {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse
- * .swt.events.TraverseEvent)
- */
- public void keyTraversed(TraverseEvent e) {
- if (e.detail == SWT.TRAVERSE_RETURN) {
- e.doit = false;
- updateProjectsList(archivePathField.getText().trim());
- }
- }
-
- });
-
- archivePathField.addFocusListener(new FocusAdapter() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
- * .events.FocusEvent)
- */
- public void focusLost(org.eclipse.swt.events.FocusEvent e) {
- updateProjectsList(archivePathField.getText().trim());
- }
- });
-
- projectFromDirectoryRadio.addSelectionListener(new SelectionAdapter() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- directoryRadioSelected();
- }
- });
-
- projectFromArchiveRadio.addSelectionListener(new SelectionAdapter() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- archiveRadioSelected();
- }
- });
- }
-
- /**
- * Create the selection buttons in the listComposite.
- *
- * @param listComposite
- */
- private void createSelectionButtons(Composite listComposite) {
- Composite buttonsComposite = new Composite(listComposite, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- buttonsComposite.setLayout(layout);
-
- buttonsComposite.setLayoutData(new GridData(
- GridData.VERTICAL_ALIGN_BEGINNING));
-
- Button selectAll = new Button(buttonsComposite, SWT.PUSH);
- selectAll.setText(DataTransferMessages.DataTransfer_selectAll);
- selectAll.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- for (int i = 0; i < selectedProjects.length; i++) {
- if (selectedProjects[i].hasConflicts)
- projectsList.setChecked(selectedProjects[i], false);
- else
- projectsList.setChecked(selectedProjects[i], true);
- }
- setPageComplete(projectsList.getCheckedElements().length > 0);
- }
- });
- Dialog.applyDialogFont(selectAll);
- setButtonLayoutData(selectAll);
-
- Button deselectAll = new Button(buttonsComposite, SWT.PUSH);
- deselectAll.setText(DataTransferMessages.DataTransfer_deselectAll);
- deselectAll.addSelectionListener(new SelectionAdapter() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
-
- projectsList.setCheckedElements(new Object[0]);
- setPageComplete(false);
- }
- });
- Dialog.applyDialogFont(deselectAll);
- setButtonLayoutData(deselectAll);
-
- Button refresh = new Button(buttonsComposite, SWT.PUSH);
- refresh.setText(DataTransferMessages.DataTransfer_refresh);
- refresh.addSelectionListener(new SelectionAdapter() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- if (projectFromDirectoryRadio.getSelection()) {
- updateProjectsList(directoryPathField.getText().trim());
- } else {
- updateProjectsList(archivePathField.getText().trim());
- }
- }
- });
- Dialog.applyDialogFont(refresh);
- setButtonLayoutData(refresh);
- }
-
- /**
- * @param workArea
- */
- private void createWorkingSetGroup(Composite workArea) {
- String[] workingSetIds = new String[] {
- "org.eclipse.ui.resourceWorkingSetPage", //$NON-NLS-1$
- "org.eclipse.jdt.ui.JavaWorkingSetPage" }; //$NON-NLS-1$
- workingSetGroup = new WorkingSetGroup(workArea, currentSelection,
- workingSetIds);
- }
-
- private void directoryRadioSelected() {
- if (projectFromDirectoryRadio.getSelection()) {
- directoryPathField.setEnabled(true);
- browseDirectoriesButton.setEnabled(true);
- archivePathField.setEnabled(false);
- browseArchivesButton.setEnabled(false);
- updateProjectsList(directoryPathField.getText());
- directoryPathField.setFocus();
- }
- }
-
- /**
- * Display an error dialog with the specified message.
- *
- * @param message
- * the error message
- */
- protected void displayErrorDialog(String message) {
- MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
- getErrorDialogTitle(), message, SWT.SHEET);
- }
-
- /**
- * Get the title for an error dialog. Subclasses should override.
- */
- protected String getErrorDialogTitle() {
- return IDEWorkbenchMessages.WizardExportPage_internalErrorTitle;
- }
-
- /**
- * Method used for test suite.
- *
- * @return Button the Import from Directory RadioButton
- */
- public Button getProjectFromDirectoryRadio() {
- return projectFromDirectoryRadio;
- }
-
- /**
- * Get the array of project records that can be imported from the source
- * workspace or archive, selected by the user. If a project with the same
- * name exists in both the source workspace and the current workspace, then
- * the hasConflicts flag would be set on that project record.
- *
- * Method declared public for test suite.
- *
- * @return ProjectRecord[] array of projects that can be imported into the
- * workspace
- */
- public ProjectRecord[] getProjectRecords() {
- List projectRecords = new ArrayList();
- for (int i = 0; i < selectedProjects.length; i++) {
- if (!ProjectUtils.isAptanaProject(selectedProjects[i].description.getLocationURI()) || isProjectInWorkspace(selectedProjects[i].getProjectName())) {
- selectedProjects[i].hasConflicts = true;
- }
- projectRecords.add(selectedProjects[i]);
- }
- return (ProjectRecord[]) projectRecords
- .toArray(new ProjectRecord[projectRecords.size()]);
- }
-
- /**
- * Retrieve all the projects in the current workspace.
- *
- * @return IProject[] array of IProject in the current workspace
- */
- private IProject[] getProjectsInWorkspace() {
- if (wsProjects == null) {
- wsProjects = IDEWorkbenchPlugin.getPluginWorkspace().getRoot()
- .getProjects();
- }
- return wsProjects;
- }
-
- /**
- * Method used for test suite.
- *
- * @return CheckboxTreeViewer the viewer containing all the projects found
- */
- public CheckboxTreeViewer getProjectsList() {
- return projectsList;
- }
-
- /**
- * Answer a handle to the zip file currently specified as being the source.
- * Return null if this file does not exist or is not of valid format.
- */
- private TarFile getSpecifiedTarSourceFile(String fileName) {
- if (fileName.length() == 0) {
- return null;
- }
-
- try {
- return new TarFile(fileName);
- } catch (TarException e) {
- displayErrorDialog(DataTransferMessages.TarImport_badFormat);
- } catch (IOException e) {
- displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
- }
-
- archivePathField.setFocus();
- return null;
- }
-
- /**
- * Answer a handle to the zip file currently specified as being the source.
- * Return null if this file does not exist or is not of valid format.
- */
- private ZipFile getSpecifiedZipSourceFile(String fileName) {
- if (fileName.length() == 0) {
- return null;
- }
-
- try {
- return new ZipFile(fileName);
- } catch (ZipException e) {
- displayErrorDialog(DataTransferMessages.ZipImport_badFormat);
- } catch (IOException e) {
- displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
- }
-
- archivePathField.setFocus();
- return null;
- }
-
- /**
- * The browse button has been selected. Select the location.
- */
- protected void handleLocationArchiveButtonPressed() {
-
- FileDialog dialog = new FileDialog(archivePathField.getShell(),
- SWT.SHEET);
- dialog.setFilterExtensions(FILE_IMPORT_MASK);
- dialog
- .setText(DataTransferMessages.WizardProjectsImportPage_SelectArchiveDialogTitle);
-
- String fileName = archivePathField.getText().trim();
- if (fileName.length() == 0) {
- fileName = previouslyBrowsedArchive;
- }
-
- if (fileName.length() == 0) {
- dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace()
- .getRoot().getLocation().toOSString());
- } else {
- File path = new File(fileName).getParentFile();
- if (path != null && path.exists()) {
- dialog.setFilterPath(path.toString());
- }
- }
-
- String selectedArchive = dialog.open();
- if (selectedArchive != null) {
- previouslyBrowsedArchive = selectedArchive;
- archivePathField.setText(previouslyBrowsedArchive);
- updateProjectsList(selectedArchive);
- }
-
- }
-
- /**
- * The browse button has been selected. Select the location.
- */
- protected void handleLocationDirectoryButtonPressed() {
-
- DirectoryDialog dialog = new DirectoryDialog(directoryPathField
- .getShell(), SWT.SHEET);
- dialog
- .setMessage(DataTransferMessages.WizardProjectsImportPage_SelectDialogTitle);
-
- String dirName = directoryPathField.getText().trim();
- if (dirName.length() == 0) {
- dirName = previouslyBrowsedDirectory;
- }
-
- if (dirName.length() == 0) {
- dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace()
- .getRoot().getLocation().toOSString());
- } else {
- File path = new File(dirName);
- if (path.exists()) {
- dialog.setFilterPath(new Path(dirName).toOSString());
- }
- }
-
- String selectedDirectory = dialog.open();
- if (selectedDirectory != null) {
- previouslyBrowsedDirectory = selectedDirectory;
- directoryPathField.setText(previouslyBrowsedDirectory);
- updateProjectsList(selectedDirectory);
- }
-
- }
-
- /**
- * Determine if the project with the given name is in the current workspace.
- *
- * @param projectName
- * String the project name to check
- * @return boolean true if the project with the given name is in this
- * workspace
- */
- private boolean isProjectInWorkspace(String projectName) {
- if (projectName == null) {
- return false;
- }
- IProject[] workspaceProjects = getProjectsInWorkspace();
- for (int i = 0; i < workspaceProjects.length; i++) {
- if (projectName.equals(workspaceProjects[i].getName())) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Performs clean-up if the user cancels the wizard without doing anything
- */
- public void performCancel() {
- ArchiveFileManipulations.closeStructureProvider(structureProvider,
- getShell());
- }
-
- /**
- * The <code>WizardDataTransfer</code> implementation of this
- * <code>IOverwriteQuery</code> method asks the user whether the existing
- * resource at the given path should be overwritten.
- *
- * @param pathString
- * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
- * <code>"ALL"</code>, or <code>"CANCEL"</code>
- */
- public String queryOverwrite(String pathString) {
-
- Path path = new Path(pathString);
-
- String messageString;
- // Break the message up if there is a file name and a directory
- // and there are at least 2 segments.
- if (path.getFileExtension() == null || path.segmentCount() < 2) {
- messageString = NLS.bind(
- IDEWorkbenchMessages.WizardDataTransfer_existsQuestion,
- pathString);
- } else {
- messageString = NLS
- .bind(
- IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
- path.lastSegment(), path.removeLastSegments(1)
- .toOSString());
- }
-
- final MessageDialog dialog = new MessageDialog(getContainer()
- .getShell(), IDEWorkbenchMessages.Question, null,
- messageString, MessageDialog.QUESTION, new String[] {
- IDialogConstants.YES_LABEL,
- IDialogConstants.YES_TO_ALL_LABEL,
- IDialogConstants.NO_LABEL,
- IDialogConstants.NO_TO_ALL_LABEL,
- IDialogConstants.CANCEL_LABEL }, 0) {
- protected int getShellStyle() {
- return super.getShellStyle() | SWT.SHEET;
- }
- };
- String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
- // run in syncExec because callback is from an operation,
- // which is probably not running in the UI thread.
- getControl().getDisplay().syncExec(new Runnable() {
- public void run() {
- dialog.open();
- }
- });
- return dialog.getReturnCode() < 0 ? CANCEL : response[dialog
- .getReturnCode()];
- }
-
- /**
- * Use the dialog store to restore widget values to the values that they
- * held last time this wizard was used to completion, or alternatively, if
- * an initial path is specified, use it to select values.
- *
- * Method declared public only for use of tests.
- */
- public void restoreWidgetValues() {
-
- // First, check to see if we have resore settings, and
- // take care of the checkbox
- IDialogSettings settings = getDialogSettings();
-
- // Second, check to see if we don't have an initial path,
- // and if we do have restore settings. If so, set the
- // radio selection properly to restore settings
-
- if (initialPath == null && settings != null) {
- // radio selection
- boolean archiveSelected = settings
- .getBoolean(STORE_ARCHIVE_SELECTED);
- projectFromDirectoryRadio.setSelection(!archiveSelected);
- projectFromArchiveRadio.setSelection(archiveSelected);
- if (archiveSelected) {
- archiveRadioSelected();
- } else {
- directoryRadioSelected();
- }
- }
- // Third, if we do have an initial path, set the proper
- // path and radio buttons to the initial value. Move
- // cursor to the end of the path so user can see the
- // most relevant part (directory / archive name)
- else if (initialPath != null) {
- boolean dir = new File(initialPath).isDirectory();
-
- projectFromDirectoryRadio.setSelection(dir);
- projectFromArchiveRadio.setSelection(!dir);
-
- if (dir) {
- directoryPathField.setText(initialPath);
- directoryPathField.setSelection(initialPath.length());
- directoryRadioSelected();
- } else {
- archivePathField.setText(initialPath);
- archivePathField.setSelection(initialPath.length());
- archiveRadioSelected();
- }
- }
- }
-
- /**
- * Since Finish was pressed, write widget values to the dialog store so that
- * they will persist into the next invocation of this wizard page.
- *
- * Method declared public only for use of tests.
- */
- public void saveWidgetValues() {
- IDialogSettings settings = getDialogSettings();
- if (settings != null) {
- settings.put(STORE_ARCHIVE_SELECTED, projectFromArchiveRadio
- .getSelection());
- }
- }
-
- /*
- * (non-Javadoc) Method declared on IDialogPage. Set the focus on path
- * fields when page becomes visible.
- */
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible && this.projectFromDirectoryRadio.getSelection()) {
- this.directoryPathField.setFocus();
- }
- if (visible && this.projectFromArchiveRadio.getSelection()) {
- this.archivePathField.setFocus();
- }
- }
-
- /**
- * Update the list of projects based on path. Method declared public only
- * for test suite.
- *
- * @param path
- */
- public void updateProjectsList(final String path) {
- // on an empty path empty selectedProjects
- if (path == null || path.length() == 0) {
- setMessage(DataTransferMessages.WizardProjectsImportPage_ImportProjectsDescription);
- selectedProjects = new ProjectRecord[0];
- projectsList.refresh(true);
- projectsList.setCheckedElements(selectedProjects);
- setPageComplete(projectsList.getCheckedElements().length > 0);
- lastPath = path;
- return;
- }
-
- final File directory = new File(path);
- long modified = directory.lastModified();
- if (path.equals(lastPath) && lastModified == modified) {
- // since the file/folder was not modified and the path did not
- // change, no refreshing is required
- return;
- }
-
- lastPath = path;
- lastModified = modified;
-
- // We can't access the radio button from the inner class so get the
- // status beforehand
- final boolean dirSelected = this.projectFromDirectoryRadio
- .getSelection();
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.operation.IRunnableWithProgress#run(org
- * .eclipse.core.runtime.IProgressMonitor)
- */
- public void run(IProgressMonitor monitor) {
-
- monitor
- .beginTask(
- DataTransferMessages.WizardProjectsImportPage_SearchingMessage,
- 100);
- selectedProjects = new ProjectRecord[0];
- Collection files = new ArrayList();
- monitor.worked(10);
- if (!dirSelected
- && ArchiveFileManipulations.isTarFile(path)) {
- TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
- if (sourceTarFile == null) {
- return;
- }
-
- structureProvider = new TarLeveledStructureProvider(
- sourceTarFile);
- Object child = structureProvider.getRoot();
-
- if (!collectProjectFilesFromProvider(files, child, 0,
- monitor)) {
- return;
- }
- Iterator filesIterator = files.iterator();
- selectedProjects = new ProjectRecord[files.size()];
- int index = 0;
- monitor.worked(50);
- monitor
- .subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
- while (filesIterator.hasNext()) {
- selectedProjects[index++] = (ProjectRecord) filesIterator
- .next();
- }
- } else if (!dirSelected
- && ArchiveFileManipulations.isZipFile(path)) {
- ZipFile sourceFile = getSpecifiedZipSourceFile(path);
- if (sourceFile == null) {
- return;
- }
- structureProvider = new ZipLeveledStructureProvider(
- sourceFile);
- Object child = structureProvider.getRoot();
-
- if (!collectProjectFilesFromProvider(files, child, 0,
- monitor)) {
- return;
- }
- Iterator filesIterator = files.iterator();
- selectedProjects = new ProjectRecord[files.size()];
- int index = 0;
- monitor.worked(50);
- monitor
- .subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
- while (filesIterator.hasNext()) {
- selectedProjects[index++] = (ProjectRecord) filesIterator
- .next();
- }
- }
-
- else if (dirSelected && directory.isDirectory()) {
-
- if (!collectProjectFilesFromDirectory(files, directory,
- null, monitor)) {
- return;
- }
- Iterator filesIterator = files.iterator();
- selectedProjects = new ProjectRecord[files.size()];
- int index = 0;
- monitor.worked(50);
- monitor
- .subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
- while (filesIterator.hasNext()) {
- File file = (File) filesIterator.next();
- selectedProjects[index] = new ProjectRecord(file);
- index++;
- }
- } else {
- monitor.worked(60);
- }
- monitor.done();
- }
-
- });
- } catch (InvocationTargetException e) {
- IDEWorkbenchPlugin.log(e.getMessage(), e);
- } catch (InterruptedException e) {
- // Nothing to do if the user interrupts.
- }
-
- projectsList.refresh(true);
- ProjectRecord[] projects = getProjectRecords();
- boolean displayWarning = false;
- for (int i = 0; i < projects.length; i++) {
- if (projects[i].hasConflicts) {
- displayWarning = true;
- projectsList.setGrayed(projects[i], true);
- } else {
- projectsList.setChecked(projects[i], true);
- }
- }
-
- if (displayWarning) {
- setMessage(
- DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace,
- WARNING);
- } else {
- setMessage(DataTransferMessages.WizardProjectsImportPage_ImportProjectsDescription);
- }
- setPageComplete(projectsList.getCheckedElements().length > 0);
- if (selectedProjects.length == 0) {
- setMessage(
- DataTransferMessages.WizardProjectsImportPage_noProjectsToImport,
- WARNING);
- }
- }
-}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.java Wed Feb 24 16:12:51 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/**
- * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Symbian Foundation - initial contribution.
- * Contributors:
- * Description:
- * Overview:
- * Details:
- * Platforms/Drives/Compatibility:
- * Assumptions/Requirement/Pre-requisites:
- * Failures and causes:
- */
-package org.symbian.tools.wrttools.wizards;
-
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExecutableExtension;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.IImportWizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
-import org.symbian.tools.wrttools.util.ProjectUtils;
-
-public class AptanaProjectsImportWizard extends Wizard implements
- IImportWizard, INewWizard, IExecutableExtension {
-
- private AptanaProjectLocationWizardPage mainPage;
- private IConfigurationElement config;
-
- public AptanaProjectsImportWizard() {
- setWindowTitle("Import Aptana Project");
- setNeedsProgressMonitor(true);
- }
-
- @Override
- public boolean performCancel() {
- mainPage.performCancel();
- return true;
- }
-
- @Override
- public boolean performFinish() {
- if (mainPage.createProjects()) {
- BasicNewProjectResourceWizard.updatePerspective(config);
- List<IProject> projects = mainPage.getCreatedProjects();
- ProjectUtils.focusOn(projects.toArray(new IProject[projects.size()]));
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public void addPages() {
- mainPage = new AptanaProjectLocationWizardPage();
- addPage(mainPage);
- }
-
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- // Do nothing
- }
-
- public void setInitializationData(IConfigurationElement config,
- String propertyName, Object data) throws CoreException {
- this.config = config;
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/projectimport/AptanaProjectLocationWizardPage.java Thu Feb 25 14:26:09 2010 -0800
@@ -0,0 +1,1346 @@
+/**
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.wizards.projectimport;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.PixelConverter;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Color;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.dialogs.WorkingSetGroup;
+import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
+import org.eclipse.ui.internal.ide.StatusUtil;
+import org.eclipse.ui.internal.wizards.datatransfer.ArchiveFileManipulations;
+import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
+import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider;
+import org.eclipse.ui.internal.wizards.datatransfer.TarException;
+import org.eclipse.ui.internal.wizards.datatransfer.TarFile;
+import org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider;
+import org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+@SuppressWarnings({"restriction", "unchecked"})
+public class AptanaProjectLocationWizardPage extends WizardPage implements
+ IOverwriteQuery {
+
+ /**
+ * @since 3.5
+ *
+ */
+ private final class ProjectLabelProvider extends LabelProvider implements
+ IColorProvider {
+
+ public Color getBackground(Object element) {
+ return null;
+ }
+
+ public Color getForeground(Object element) {
+ ProjectRecord projectRecord = (ProjectRecord) element;
+ if (projectRecord.hasConflicts()) {
+ return getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY);
+ }
+ return null;
+ }
+
+ public String getText(Object element) {
+ return ((ProjectRecord) element).getProjectLabel();
+ }
+ }
+
+ // constant from WizardArchiveFileResourceImportPage1
+ private static final String[] FILE_IMPORT_MASK = {
+ "*.jar;*.zip;*.tar;*.tar.gz;*.tgz", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * The name of the folder containing metadata information for the workspace.
+ */
+ public static final String METADATA_FOLDER = ".metadata"; //$NON-NLS-1$
+
+ // Keep track of the archive that we browsed to last time
+ // the wizard was invoked.
+ private static String previouslyBrowsedArchive = ""; //$NON-NLS-1$
+
+ // Keep track of the directory that we browsed to last time
+ // the wizard was invoked.
+ private static String previouslyBrowsedDirectory = ""; //$NON-NLS-1$
+
+ private final static String STORE_ARCHIVE_SELECTED = "WizardProjectsImportPage.STORE_ARCHIVE_SELECTED"; //$NON-NLS-1$
+
+ private Text archivePathField;
+
+ private Button browseArchivesButton;
+
+ private Button browseDirectoriesButton;
+
+ List createdProjects;
+
+ private IStructuredSelection currentSelection;
+
+ private Text directoryPathField;
+
+ // The initial path to set
+ private String initialPath;
+
+ // The last time that the file or folder at the selected path was modified
+ // to mimize searches
+ private long lastModified;
+
+ // The last selected path to minimize searches
+ private String lastPath;
+
+ private Button projectFromArchiveRadio;
+
+ private Button projectFromDirectoryRadio;
+
+ private CheckboxTreeViewer projectsList;
+ private ProjectRecord[] selectedProjects = new ProjectRecord[0];
+
+ /**
+ * The import structure provider.
+ *
+ * @since 3.4
+ */
+ private ILeveledImportStructureProvider structureProvider;
+
+ private WorkingSetGroup workingSetGroup;
+
+ private IProject[] wsProjects;
+
+ public AptanaProjectLocationWizardPage() {
+ super("projectlocation", "Import Aptana WRT Projects", null);
+ setDescription("Select location of the Aptana WRT projects");
+ }
+
+ private void addToWorkingSets() {
+
+ IWorkingSet[] selectedWorkingSets = workingSetGroup
+ .getSelectedWorkingSets();
+ if (selectedWorkingSets == null || selectedWorkingSets.length == 0) {
+ return; // no Working set is selected
+ }
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench()
+ .getWorkingSetManager();
+ for (Iterator i = createdProjects.iterator(); i.hasNext();) {
+ IProject project = (IProject) i.next();
+ workingSetManager.addToWorkingSets(project, selectedWorkingSets);
+ }
+ }
+
+ private void archiveRadioSelected() {
+ if (projectFromArchiveRadio.getSelection()) {
+ directoryPathField.setEnabled(false);
+ browseDirectoriesButton.setEnabled(false);
+ archivePathField.setEnabled(true);
+ browseArchivesButton.setEnabled(true);
+ updateProjectsList(archivePathField.getText());
+ archivePathField.setFocus();
+ }
+ }
+
+ public List<IProject> getCreatedProjects() {
+ return createdProjects;
+ }
+
+ /**
+ * Collect the list of .project files that are under directory into files.
+ *
+ * @param files
+ * @param directory
+ * @param directoriesVisited
+ * Set of canonical paths of directories, used as recursion guard
+ * @param monitor
+ * The monitor to report to
+ * @return boolean <code>true</code> if the operation was completed.
+ */
+ private boolean collectProjectFilesFromDirectory(Collection files,
+ File directory, Set directoriesVisited, IProgressMonitor monitor) {
+
+ if (monitor.isCanceled()) {
+ return false;
+ }
+ monitor.subTask(NLS.bind(
+ DataTransferMessages.WizardProjectsImportPage_CheckingMessage,
+ directory.getPath()));
+ File[] contents = directory.listFiles();
+ if (contents == null) {
+ return false;
+ }
+
+ // Initialize recursion guard for recursive symbolic links
+ if (directoriesVisited == null) {
+ directoriesVisited = new HashSet();
+ try {
+ directoriesVisited.add(directory.getCanonicalPath());
+ } catch (IOException exception) {
+ StatusManager.getManager().handle(
+ StatusUtil.newStatus(IStatus.ERROR, exception
+ .getLocalizedMessage(), exception));
+ }
+ }
+
+
+ File dotProjectFile = ProjectUtils.isAptanaProject(contents);
+
+ if (dotProjectFile != null) {
+ files.add(dotProjectFile);
+ // don't search sub-directories since we can't have nested
+ // projects
+ return true;
+ }
+ // no project description found, so recurse into sub-directories
+ for (int i = 0; i < contents.length; i++) {
+ if (contents[i].isDirectory()) {
+ if (!contents[i].getName().equals(METADATA_FOLDER)) {
+ try {
+ String canonicalPath = contents[i].getCanonicalPath();
+ if (!directoriesVisited.add(canonicalPath)) {
+ // already been here --> do not recurse
+ continue;
+ }
+ } catch (IOException exception) {
+ StatusManager.getManager().handle(
+ StatusUtil.newStatus(IStatus.ERROR, exception
+ .getLocalizedMessage(), exception));
+
+ }
+ collectProjectFilesFromDirectory(files, contents[i],
+ directoriesVisited, monitor);
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Collect the list of .project files that are under directory into files.
+ *
+ * @param files
+ * @param monitor
+ * The monitor to report to
+ * @return boolean <code>true</code> if the operation was completed.
+ */
+ private boolean collectProjectFilesFromProvider(Collection files,
+ Object entry, int level, IProgressMonitor monitor) {
+
+ if (monitor.isCanceled()) {
+ return false;
+ }
+ monitor.subTask(NLS.bind(
+ DataTransferMessages.WizardProjectsImportPage_CheckingMessage,
+ structureProvider.getLabel(entry)));
+ List children = structureProvider.getChildren(entry);
+ if (children == null) {
+ children = new ArrayList(1);
+ }
+ Iterator childrenEnum = children.iterator();
+ boolean hasPreviewFolder = false;
+ boolean hasFrameHtml = false;
+ ProjectRecord projectRecord = null;
+ while (childrenEnum.hasNext()) {
+ Object child = childrenEnum.next();
+ String elementLabel = structureProvider.getLabel(child);
+ if (structureProvider.isFolder(child)) {
+ if (ProjectUtils.PREVIEW_FOLDER.equalsIgnoreCase(elementLabel)) {
+ hasPreviewFolder = true;
+ }
+ collectProjectFilesFromProvider(files, child, level + 1,
+ monitor);
+ }
+ if (elementLabel.equals(IProjectDescription.DESCRIPTION_FILE_NAME)) {
+ projectRecord = new ArchivedProject(child, entry, level, structureProvider);
+ }
+ if (ProjectUtils.PREVIEW_FRAME_FILE.equalsIgnoreCase(elementLabel)) {
+ hasFrameHtml = true;
+ }
+ }
+ if (projectRecord != null && hasPreviewFolder && hasFrameHtml) {
+ files.add(projectRecord);
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ public void createControl(Composite parent) {
+
+ initializeDialogUnits(parent);
+
+ Composite workArea = new Composite(parent, SWT.NONE);
+ setControl(workArea);
+
+ workArea.setLayout(new GridLayout());
+ workArea.setLayoutData(new GridData(GridData.FILL_BOTH
+ | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
+
+ createProjectsRoot(workArea);
+ createProjectsList(workArea);
+ createWorkingSetGroup(workArea);
+ restoreWidgetValues();
+ Dialog.applyDialogFont(workArea);
+
+ updateProjectsList(directoryPathField.getText().trim());
+ }
+
+ /**
+ * Create the project described in record. If it is successful return true.
+ *
+ * @param record
+ * @return boolean <code>true</code> if successful
+ * @throws InterruptedException
+ */
+ private boolean createExistingProject(final ProjectRecord record,
+ IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+ monitor.beginTask(MessageFormat.format("Creating {0}", record
+ .getProjectName()), IProgressMonitor.UNKNOWN);
+
+ try {
+ IProject project = ProjectUtils.createWrtProject(record
+ .getProjectName(), null,
+ new SubProgressMonitor(monitor, 10));
+ createdProjects.add(project);
+ ImportOperation operation = record.getImportOperation(project, structureProvider, this);
+ if (operation != null) {
+ operation.setContext(getShell());
+ operation.run(monitor);
+ }
+ return true;
+ } catch (CoreException e) {
+ Activator.log(e);
+ return false;
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /**
+ * Create the selected projects
+ *
+ * @return boolean <code>true</code> if all project creations were
+ * successful.
+ */
+ public boolean createProjects() {
+ saveWidgetValues();
+
+ final Object[] selected = projectsList.getCheckedElements();
+ createdProjects = new ArrayList();
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ protected void execute(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ try {
+ monitor.beginTask("", selected.length);
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ for (int i = 0; i < selected.length; i++) {
+ createExistingProject((ProjectRecord) selected[i],
+ new SubProgressMonitor(monitor, 1));
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ // run the new project creation operation
+ try {
+ getContainer().run(true, true, op);
+ } catch (InterruptedException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ // one of the steps resulted in a core exception
+ Throwable t = e.getTargetException();
+ String message = DataTransferMessages.WizardExternalProjectImportPage_errorMessage;
+ IStatus status;
+ if (t instanceof CoreException) {
+ status = ((CoreException) t).getStatus();
+ } else {
+ status = new Status(IStatus.ERROR,
+ Activator.PLUGIN_ID, 1, message, t);
+ }
+ ErrorDialog.openError(getShell(), message, null, status);
+ return false;
+ }
+ ArchiveFileManipulations.closeStructureProvider(structureProvider,
+ getShell());
+
+ // Adds the projects to the working sets
+ addToWorkingSets();
+
+ return true;
+ }
+
+ /**
+ * Create the checkbox list for the found projects.
+ *
+ * @param workArea
+ */
+ private void createProjectsList(Composite workArea) {
+
+ Label title = new Label(workArea, SWT.NONE);
+ title
+ .setText(DataTransferMessages.WizardProjectsImportPage_ProjectsListTitle);
+
+ Composite listComposite = new Composite(workArea, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 0;
+ layout.makeColumnsEqualWidth = false;
+ listComposite.setLayout(layout);
+
+ listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
+
+ projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.widthHint = new PixelConverter(projectsList.getControl())
+ .convertWidthInCharsToPixels(25);
+ gridData.heightHint = new PixelConverter(projectsList.getControl())
+ .convertHeightInCharsToPixels(10);
+ projectsList.getControl().setLayoutData(gridData);
+ projectsList.setContentProvider(new ITreeContentProvider() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose() {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java
+ * .lang.Object)
+ */
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.IStructuredContentProvider#getElements
+ * (java.lang.Object)
+ */
+ public Object[] getElements(Object inputElement) {
+ return getProjectRecords();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java
+ * .lang.Object)
+ */
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java
+ * .lang.Object)
+ */
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
+ * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+
+ });
+
+ projectsList.setLabelProvider(new ProjectLabelProvider());
+
+ projectsList.addCheckStateListener(new ICheckStateListener() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
+ * (org.eclipse.jface.viewers.CheckStateChangedEvent)
+ */
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ ProjectRecord element = (ProjectRecord) event.getElement();
+ if (element.hasConflicts()) {
+ projectsList.setChecked(element, false);
+ }
+ setPageComplete(projectsList.getCheckedElements().length > 0);
+ }
+ });
+
+ projectsList.setInput(this);
+ projectsList.setComparator(new ViewerComparator());
+ createSelectionButtons(listComposite);
+ }
+
+ /**
+ * Create the area where you select the root directory for the projects.
+ *
+ * @param workArea
+ * Composite
+ */
+ private void createProjectsRoot(Composite workArea) {
+
+ // project specification group
+ Composite projectGroup = new Composite(workArea, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ layout.makeColumnsEqualWidth = false;
+ layout.marginWidth = 0;
+ projectGroup.setLayout(layout);
+ projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // new project from directory radio button
+ projectFromDirectoryRadio = new Button(projectGroup, SWT.RADIO);
+ projectFromDirectoryRadio
+ .setText(DataTransferMessages.WizardProjectsImportPage_RootSelectTitle);
+
+ // project location entry field
+ this.directoryPathField = new Text(projectGroup, SWT.BORDER);
+
+ GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true,
+ false);
+ directoryPathData.widthHint = new PixelConverter(directoryPathField)
+ .convertWidthInCharsToPixels(25);
+ directoryPathField.setLayoutData(directoryPathData);
+
+ directoryPathField.setText(ProjectUtils.getDefaultAptanaLocation());
+
+ // browse button
+ browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);
+ browseDirectoriesButton
+ .setText(DataTransferMessages.DataTransfer_browse);
+ setButtonLayoutData(browseDirectoriesButton);
+
+ // new project from archive radio button
+ projectFromArchiveRadio = new Button(projectGroup, SWT.RADIO);
+ projectFromArchiveRadio
+ .setText(DataTransferMessages.WizardProjectsImportPage_ArchiveSelectTitle);
+
+ // project location entry field
+ archivePathField = new Text(projectGroup, SWT.BORDER);
+
+ GridData archivePathData = new GridData(SWT.FILL, SWT.NONE, true, false);
+ archivePathData.widthHint = new PixelConverter(archivePathField)
+ .convertWidthInCharsToPixels(25);
+ archivePathField.setLayoutData(archivePathData); // browse button
+ browseArchivesButton = new Button(projectGroup, SWT.PUSH);
+ browseArchivesButton.setText(DataTransferMessages.DataTransfer_browse);
+ setButtonLayoutData(browseArchivesButton);
+
+ projectFromDirectoryRadio.setSelection(true);
+ archivePathField.setEnabled(false);
+ browseArchivesButton.setEnabled(false);
+
+ browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetS
+ * elected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ handleLocationDirectoryButtonPressed();
+ }
+
+ });
+
+ browseArchivesButton.addSelectionListener(new SelectionAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
+ * .swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ handleLocationArchiveButtonPressed();
+ }
+
+ });
+
+ directoryPathField.addTraverseListener(new TraverseListener() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse
+ * .swt.events.TraverseEvent)
+ */
+ public void keyTraversed(TraverseEvent e) {
+ if (e.detail == SWT.TRAVERSE_RETURN) {
+ e.doit = false;
+ updateProjectsList(directoryPathField.getText().trim());
+ }
+ }
+
+ });
+
+ directoryPathField.addFocusListener(new FocusAdapter() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
+ * .events.FocusEvent)
+ */
+ public void focusLost(org.eclipse.swt.events.FocusEvent e) {
+ updateProjectsList(directoryPathField.getText().trim());
+ }
+
+ });
+
+ archivePathField.addTraverseListener(new TraverseListener() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse
+ * .swt.events.TraverseEvent)
+ */
+ public void keyTraversed(TraverseEvent e) {
+ if (e.detail == SWT.TRAVERSE_RETURN) {
+ e.doit = false;
+ updateProjectsList(archivePathField.getText().trim());
+ }
+ }
+
+ });
+
+ archivePathField.addFocusListener(new FocusAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
+ * .events.FocusEvent)
+ */
+ public void focusLost(org.eclipse.swt.events.FocusEvent e) {
+ updateProjectsList(archivePathField.getText().trim());
+ }
+ });
+
+ projectFromDirectoryRadio.addSelectionListener(new SelectionAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse
+ * .swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ directoryRadioSelected();
+ }
+ });
+
+ projectFromArchiveRadio.addSelectionListener(new SelectionAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse
+ * .swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ archiveRadioSelected();
+ }
+ });
+ }
+
+ /**
+ * Create the selection buttons in the listComposite.
+ *
+ * @param listComposite
+ */
+ private void createSelectionButtons(Composite listComposite) {
+ Composite buttonsComposite = new Composite(listComposite, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ buttonsComposite.setLayout(layout);
+
+ buttonsComposite.setLayoutData(new GridData(
+ GridData.VERTICAL_ALIGN_BEGINNING));
+
+ Button selectAll = new Button(buttonsComposite, SWT.PUSH);
+ selectAll.setText(DataTransferMessages.DataTransfer_selectAll);
+ selectAll.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ for (int i = 0; i < selectedProjects.length; i++) {
+ if (selectedProjects[i].hasConflicts()) {
+ projectsList.setChecked(selectedProjects[i], false);
+ } else {
+ projectsList.setChecked(selectedProjects[i], true);
+ }
+ }
+ setPageComplete(projectsList.getCheckedElements().length > 0);
+ }
+ });
+ Dialog.applyDialogFont(selectAll);
+ setButtonLayoutData(selectAll);
+
+ Button deselectAll = new Button(buttonsComposite, SWT.PUSH);
+ deselectAll.setText(DataTransferMessages.DataTransfer_deselectAll);
+ deselectAll.addSelectionListener(new SelectionAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
+ * .swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+
+ projectsList.setCheckedElements(new Object[0]);
+ setPageComplete(false);
+ }
+ });
+ Dialog.applyDialogFont(deselectAll);
+ setButtonLayoutData(deselectAll);
+
+ Button refresh = new Button(buttonsComposite, SWT.PUSH);
+ refresh.setText(DataTransferMessages.DataTransfer_refresh);
+ refresh.addSelectionListener(new SelectionAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
+ * .swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ if (projectFromDirectoryRadio.getSelection()) {
+ updateProjectsList(directoryPathField.getText().trim());
+ } else {
+ updateProjectsList(archivePathField.getText().trim());
+ }
+ }
+ });
+ Dialog.applyDialogFont(refresh);
+ setButtonLayoutData(refresh);
+ }
+
+ /**
+ * @param workArea
+ */
+ private void createWorkingSetGroup(Composite workArea) {
+ String[] workingSetIds = new String[] {
+ "org.eclipse.ui.resourceWorkingSetPage", //$NON-NLS-1$
+ "org.eclipse.jdt.ui.JavaWorkingSetPage" }; //$NON-NLS-1$
+ workingSetGroup = new WorkingSetGroup(workArea, currentSelection,
+ workingSetIds);
+ }
+
+ private void directoryRadioSelected() {
+ if (projectFromDirectoryRadio.getSelection()) {
+ directoryPathField.setEnabled(true);
+ browseDirectoriesButton.setEnabled(true);
+ archivePathField.setEnabled(false);
+ browseArchivesButton.setEnabled(false);
+ updateProjectsList(directoryPathField.getText());
+ directoryPathField.setFocus();
+ }
+ }
+
+ /**
+ * Display an error dialog with the specified message.
+ *
+ * @param message
+ * the error message
+ */
+ protected void displayErrorDialog(String message) {
+ MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
+ getErrorDialogTitle(), message, SWT.SHEET);
+ }
+
+ /**
+ * Get the title for an error dialog. Subclasses should override.
+ */
+ protected String getErrorDialogTitle() {
+ return IDEWorkbenchMessages.WizardExportPage_internalErrorTitle;
+ }
+
+ /**
+ * Method used for test suite.
+ *
+ * @return Button the Import from Directory RadioButton
+ */
+ public Button getProjectFromDirectoryRadio() {
+ return projectFromDirectoryRadio;
+ }
+
+ /**
+ * Get the array of project records that can be imported from the source
+ * workspace or archive, selected by the user. If a project with the same
+ * name exists in both the source workspace and the current workspace, then
+ * the hasConflicts flag would be set on that project record.
+ *
+ * Method declared public for test suite.
+ *
+ * @return ProjectRecord[] array of projects that can be imported into the
+ * workspace
+ */
+ public ProjectRecord[] getProjectRecords() {
+ List projectRecords = new ArrayList();
+ for (int i = 0; i < selectedProjects.length; i++) {
+ if (isProjectInWorkspace(selectedProjects[i].getProjectName())) {
+ selectedProjects[i].setHasConflicts(true);
+ }
+ projectRecords.add(selectedProjects[i]);
+ }
+ return (ProjectRecord[]) projectRecords
+ .toArray(new ProjectRecord[projectRecords.size()]);
+ }
+
+ /**
+ * Retrieve all the projects in the current workspace.
+ *
+ * @return IProject[] array of IProject in the current workspace
+ */
+ private IProject[] getProjectsInWorkspace() {
+ if (wsProjects == null) {
+ wsProjects = ResourcesPlugin.getWorkspace().getRoot()
+ .getProjects();
+ }
+ return wsProjects;
+ }
+
+ /**
+ * Method used for test suite.
+ *
+ * @return CheckboxTreeViewer the viewer containing all the projects found
+ */
+ public CheckboxTreeViewer getProjectsList() {
+ return projectsList;
+ }
+
+ /**
+ * Answer a handle to the zip file currently specified as being the source.
+ * Return null if this file does not exist or is not of valid format.
+ */
+ private TarFile getSpecifiedTarSourceFile(String fileName) {
+ if (fileName.length() == 0) {
+ return null;
+ }
+
+ try {
+ return new TarFile(fileName);
+ } catch (TarException e) {
+ displayErrorDialog(DataTransferMessages.TarImport_badFormat);
+ } catch (IOException e) {
+ displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
+ }
+
+ archivePathField.setFocus();
+ return null;
+ }
+
+ /**
+ * Answer a handle to the zip file currently specified as being the source.
+ * Return null if this file does not exist or is not of valid format.
+ */
+ private ZipFile getSpecifiedZipSourceFile(String fileName) {
+ if (fileName.length() == 0) {
+ return null;
+ }
+
+ try {
+ return new ZipFile(fileName);
+ } catch (ZipException e) {
+ displayErrorDialog(DataTransferMessages.ZipImport_badFormat);
+ } catch (IOException e) {
+ displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
+ }
+
+ archivePathField.setFocus();
+ return null;
+ }
+
+ /**
+ * The browse button has been selected. Select the location.
+ */
+ protected void handleLocationArchiveButtonPressed() {
+
+ FileDialog dialog = new FileDialog(archivePathField.getShell(),
+ SWT.SHEET);
+ dialog.setFilterExtensions(FILE_IMPORT_MASK);
+ dialog
+ .setText(DataTransferMessages.WizardProjectsImportPage_SelectArchiveDialogTitle);
+
+ String fileName = archivePathField.getText().trim();
+ if (fileName.length() == 0) {
+ fileName = previouslyBrowsedArchive;
+ }
+
+ if (fileName.length() == 0) {
+ dialog.setFilterPath(ResourcesPlugin.getWorkspace()
+ .getRoot().getLocation().toOSString());
+ } else {
+ File path = new File(fileName).getParentFile();
+ if (path != null && path.exists()) {
+ dialog.setFilterPath(path.toString());
+ }
+ }
+
+ String selectedArchive = dialog.open();
+ if (selectedArchive != null) {
+ previouslyBrowsedArchive = selectedArchive;
+ archivePathField.setText(previouslyBrowsedArchive);
+ updateProjectsList(selectedArchive);
+ }
+
+ }
+
+ /**
+ * The browse button has been selected. Select the location.
+ */
+ protected void handleLocationDirectoryButtonPressed() {
+
+ DirectoryDialog dialog = new DirectoryDialog(directoryPathField
+ .getShell(), SWT.SHEET);
+ dialog
+ .setMessage(DataTransferMessages.WizardProjectsImportPage_SelectDialogTitle);
+
+ String dirName = directoryPathField.getText().trim();
+ if (dirName.length() == 0) {
+ dirName = previouslyBrowsedDirectory;
+ }
+
+ if (dirName.length() == 0) {
+ dialog.setFilterPath(ResourcesPlugin.getWorkspace()
+ .getRoot().getLocation().toOSString());
+ } else {
+ File path = new File(dirName);
+ if (path.exists()) {
+ dialog.setFilterPath(new Path(dirName).toOSString());
+ }
+ }
+
+ String selectedDirectory = dialog.open();
+ if (selectedDirectory != null) {
+ previouslyBrowsedDirectory = selectedDirectory;
+ directoryPathField.setText(previouslyBrowsedDirectory);
+ updateProjectsList(selectedDirectory);
+ }
+
+ }
+
+ /**
+ * Determine if the project with the given name is in the current workspace.
+ *
+ * @param projectName
+ * String the project name to check
+ * @return boolean true if the project with the given name is in this
+ * workspace
+ */
+ private boolean isProjectInWorkspace(String projectName) {
+ if (projectName == null) {
+ return false;
+ }
+ IProject[] workspaceProjects = getProjectsInWorkspace();
+ for (int i = 0; i < workspaceProjects.length; i++) {
+ if (projectName.equals(workspaceProjects[i].getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Performs clean-up if the user cancels the wizard without doing anything
+ */
+ public void performCancel() {
+ ArchiveFileManipulations.closeStructureProvider(structureProvider,
+ getShell());
+ }
+
+ /**
+ * The <code>WizardDataTransfer</code> implementation of this
+ * <code>IOverwriteQuery</code> method asks the user whether the existing
+ * resource at the given path should be overwritten.
+ *
+ * @param pathString
+ * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
+ * <code>"ALL"</code>, or <code>"CANCEL"</code>
+ */
+ public String queryOverwrite(String pathString) {
+
+ Path path = new Path(pathString);
+
+ String messageString;
+ // Break the message up if there is a file name and a directory
+ // and there are at least 2 segments.
+ if (path.getFileExtension() == null || path.segmentCount() < 2) {
+ messageString = NLS.bind(
+ IDEWorkbenchMessages.WizardDataTransfer_existsQuestion,
+ pathString);
+ } else {
+ messageString = NLS
+ .bind(
+ IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
+ path.lastSegment(), path.removeLastSegments(1)
+ .toOSString());
+ }
+
+ final MessageDialog dialog = new MessageDialog(getContainer()
+ .getShell(), IDEWorkbenchMessages.Question, null,
+ messageString, MessageDialog.QUESTION, new String[] {
+ IDialogConstants.YES_LABEL,
+ IDialogConstants.YES_TO_ALL_LABEL,
+ IDialogConstants.NO_LABEL,
+ IDialogConstants.NO_TO_ALL_LABEL,
+ IDialogConstants.CANCEL_LABEL }, 0) {
+ protected int getShellStyle() {
+ return super.getShellStyle() | SWT.SHEET;
+ }
+ };
+ String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
+ // run in syncExec because callback is from an operation,
+ // which is probably not running in the UI thread.
+ getControl().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ dialog.open();
+ }
+ });
+ return dialog.getReturnCode() < 0 ? CANCEL : response[dialog
+ .getReturnCode()];
+ }
+
+ /**
+ * Use the dialog store to restore widget values to the values that they
+ * held last time this wizard was used to completion, or alternatively, if
+ * an initial path is specified, use it to select values.
+ *
+ * Method declared public only for use of tests.
+ */
+ public void restoreWidgetValues() {
+
+ // First, check to see if we have resore settings, and
+ // take care of the checkbox
+ IDialogSettings settings = getDialogSettings();
+
+ // Second, check to see if we don't have an initial path,
+ // and if we do have restore settings. If so, set the
+ // radio selection properly to restore settings
+
+ if (initialPath == null && settings != null) {
+ // radio selection
+ boolean archiveSelected = settings
+ .getBoolean(STORE_ARCHIVE_SELECTED);
+ projectFromDirectoryRadio.setSelection(!archiveSelected);
+ projectFromArchiveRadio.setSelection(archiveSelected);
+ if (archiveSelected) {
+ archiveRadioSelected();
+ } else {
+ directoryRadioSelected();
+ }
+ }
+ // Third, if we do have an initial path, set the proper
+ // path and radio buttons to the initial value. Move
+ // cursor to the end of the path so user can see the
+ // most relevant part (directory / archive name)
+ else if (initialPath != null) {
+ boolean dir = new File(initialPath).isDirectory();
+
+ projectFromDirectoryRadio.setSelection(dir);
+ projectFromArchiveRadio.setSelection(!dir);
+
+ if (dir) {
+ directoryPathField.setText(initialPath);
+ directoryPathField.setSelection(initialPath.length());
+ directoryRadioSelected();
+ } else {
+ archivePathField.setText(initialPath);
+ archivePathField.setSelection(initialPath.length());
+ archiveRadioSelected();
+ }
+ }
+ }
+
+ /**
+ * Since Finish was pressed, write widget values to the dialog store so that
+ * they will persist into the next invocation of this wizard page.
+ *
+ * Method declared public only for use of tests.
+ */
+ public void saveWidgetValues() {
+ IDialogSettings settings = getDialogSettings();
+ if (settings != null) {
+ settings.put(STORE_ARCHIVE_SELECTED, projectFromArchiveRadio
+ .getSelection());
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IDialogPage. Set the focus on path
+ * fields when page becomes visible.
+ */
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible && this.projectFromDirectoryRadio.getSelection()) {
+ this.directoryPathField.setFocus();
+ }
+ if (visible && this.projectFromArchiveRadio.getSelection()) {
+ this.archivePathField.setFocus();
+ }
+ }
+
+ /**
+ * Update the list of projects based on path. Method declared public only
+ * for test suite.
+ *
+ * @param path
+ */
+ public void updateProjectsList(final String path) {
+ // on an empty path empty selectedProjects
+ if (path == null || path.length() == 0) {
+ setMessage(DataTransferMessages.WizardProjectsImportPage_ImportProjectsDescription);
+ selectedProjects = new ProjectRecord[0];
+ projectsList.refresh(true);
+ projectsList.setCheckedElements(selectedProjects);
+ setPageComplete(projectsList.getCheckedElements().length > 0);
+ lastPath = path;
+ return;
+ }
+
+ final File directory = new File(path);
+ long modified = directory.lastModified();
+ if (path.equals(lastPath) && lastModified == modified) {
+ // since the file/folder was not modified and the path did not
+ // change, no refreshing is required
+ return;
+ }
+
+ lastPath = path;
+ lastModified = modified;
+
+ // We can't access the radio button from the inner class so get the
+ // status beforehand
+ final boolean dirSelected = this.projectFromDirectoryRadio
+ .getSelection();
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.operation.IRunnableWithProgress#run(org
+ * .eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor) {
+
+ monitor
+ .beginTask(
+ DataTransferMessages.WizardProjectsImportPage_SearchingMessage,
+ 100);
+ selectedProjects = new ProjectRecord[0];
+ Collection files = new ArrayList();
+ monitor.worked(10);
+ if (!dirSelected
+ && ArchiveFileManipulations.isTarFile(path)) {
+ TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
+ if (sourceTarFile == null) {
+ return;
+ }
+
+ structureProvider = new TarLeveledStructureProvider(
+ sourceTarFile);
+ Object child = structureProvider.getRoot();
+
+ if (!collectProjectFilesFromProvider(files, child, 0,
+ monitor)) {
+ return;
+ }
+ Iterator filesIterator = files.iterator();
+ selectedProjects = new ProjectRecord[files.size()];
+ int index = 0;
+ monitor.worked(50);
+ monitor
+ .subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
+ while (filesIterator.hasNext()) {
+ selectedProjects[index++] = (ProjectRecord) filesIterator
+ .next();
+ }
+ } else if (!dirSelected
+ && ArchiveFileManipulations.isZipFile(path)) {
+ ZipFile sourceFile = getSpecifiedZipSourceFile(path);
+ if (sourceFile == null) {
+ return;
+ }
+ structureProvider = new ZipLeveledStructureProvider(
+ sourceFile);
+ Object child = structureProvider.getRoot();
+
+ if (!collectProjectFilesFromProvider(files, child, 0,
+ monitor)) {
+ return;
+ }
+ Iterator filesIterator = files.iterator();
+ selectedProjects = new ProjectRecord[files.size()];
+ int index = 0;
+ monitor.worked(50);
+ monitor
+ .subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
+ while (filesIterator.hasNext()) {
+ selectedProjects[index++] = (ProjectRecord) filesIterator
+ .next();
+ }
+ }
+
+ else if (dirSelected && directory.isDirectory()) {
+
+ if (!collectProjectFilesFromDirectory(files, directory,
+ null, monitor)) {
+ return;
+ }
+ Iterator filesIterator = files.iterator();
+ selectedProjects = new ProjectRecord[files.size()];
+ int index = 0;
+ monitor.worked(50);
+ monitor
+ .subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
+ while (filesIterator.hasNext()) {
+ File file = (File) filesIterator.next();
+ selectedProjects[index] = new FileSystemProject(file);
+ index++;
+ }
+ } else {
+ monitor.worked(60);
+ }
+ monitor.done();
+ }
+
+ });
+ } catch (InvocationTargetException e) {
+ Activator.log(e.getMessage(), e);
+ } catch (InterruptedException e) {
+ // Nothing to do if the user interrupts.
+ }
+
+ projectsList.refresh(true);
+ ProjectRecord[] projects = getProjectRecords();
+ boolean displayWarning = false;
+ for (int i = 0; i < projects.length; i++) {
+ if (projects[i].hasConflicts()) {
+ displayWarning = true;
+ projectsList.setGrayed(projects[i], true);
+ } else {
+ projectsList.setChecked(projects[i], true);
+ }
+ }
+
+ if (displayWarning) {
+ setMessage(
+ DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace,
+ WARNING);
+ } else {
+ setMessage(DataTransferMessages.WizardProjectsImportPage_ImportProjectsDescription);
+ }
+ setPageComplete(projectsList.getCheckedElements().length > 0);
+ if (selectedProjects.length == 0) {
+ setMessage(
+ DataTransferMessages.WizardProjectsImportPage_noProjectsToImport,
+ WARNING);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/projectimport/AptanaProjectsImportWizard.java Thu Feb 25 14:26:09 2010 -0800
@@ -0,0 +1,78 @@
+/**
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.wizards.projectimport;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+public class AptanaProjectsImportWizard extends Wizard implements
+ IImportWizard, INewWizard, IExecutableExtension {
+
+ private AptanaProjectLocationWizardPage mainPage;
+ private IConfigurationElement config;
+
+ public AptanaProjectsImportWizard() {
+ setWindowTitle("Import Aptana Project");
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ public boolean performCancel() {
+ mainPage.performCancel();
+ return true;
+ }
+
+ @Override
+ public boolean performFinish() {
+ if (mainPage.createProjects()) {
+ BasicNewProjectResourceWizard.updatePerspective(config);
+ List<IProject> projects = mainPage.getCreatedProjects();
+ ProjectUtils.focusOn(projects.toArray(new IProject[projects.size()]));
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public void addPages() {
+ mainPage = new AptanaProjectLocationWizardPage();
+ addPage(mainPage);
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ // Do nothing
+ }
+
+ public void setInitializationData(IConfigurationElement config,
+ String propertyName, Object data) throws CoreException {
+ this.config = config;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/projectimport/ArchivedProject.java Thu Feb 25 14:26:09 2010 -0800
@@ -0,0 +1,133 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.wizards.projectimport;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.List;
+import java.util.zip.ZipEntry;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider;
+import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+@SuppressWarnings("restriction")
+public class ArchivedProject implements ProjectRecord {
+ public boolean hasConflicts;
+ public int level;
+ public Object parent;
+ public Object projectArchiveFile;
+ private String projectName;
+ private final ILeveledImportStructureProvider provider;
+ private IProjectDescription description;
+
+ /**
+ * @param file
+ * The Object representing the .project file
+ * @param parent
+ * The parent folder of the .project file
+ * @param level
+ * The number of levels deep in the provider the file is
+ */
+ public ArchivedProject(Object file, Object parent, int level, ILeveledImportStructureProvider structureProvider) {
+ provider = structureProvider;
+ this.projectArchiveFile = file;
+ this.parent = parent;
+ this.level = level;
+ setProjectName();
+ }
+
+ /**
+ * Get the name of the project
+ *
+ * @return String
+ */
+ public String getProjectName() {
+ return projectName;
+ }
+
+ /**
+ * @return Returns the hasConflicts.
+ */
+ public boolean hasConflicts() {
+ return hasConflicts;
+ }
+
+ /**
+ * Set the name of the project based on the projectFile.
+ */
+ private void setProjectName() {
+ try {
+ InputStream stream = provider.getContents(projectArchiveFile);
+
+ // If we can get a description pull the name from there
+ if (stream == null) {
+ if (projectArchiveFile instanceof ZipEntry) {
+ IPath path = new Path(((ZipEntry) projectArchiveFile).getName());
+ projectName = path.segment(path.segmentCount() - 2);
+ } else if (projectArchiveFile instanceof TarEntry) {
+ IPath path = new Path(((TarEntry) projectArchiveFile).getName());
+ projectName = path.segment(path.segmentCount() - 2);
+ }
+ } else {
+ description = ResourcesPlugin.getWorkspace().loadProjectDescription(stream);
+ stream.close();
+ projectName = description.getName();
+ }
+ } catch (CoreException e) {
+ // no good couldn't get the name
+ } catch (IOException e) {
+ // no good couldn't get the name
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public ImportOperation getImportOperation(IProject project, ILeveledImportStructureProvider structureProvider,
+ IOverwriteQuery query) {
+ // import from archive
+ List<Object> fileSystemObjects = structureProvider.getChildren(parent);
+ fileSystemObjects = ProjectUtils.filterExternalProjectEntries(fileSystemObjects);
+ structureProvider.setStrip(level);
+ return new ImportOperation(project.getFullPath(), structureProvider.getRoot(), structureProvider, query,
+ fileSystemObjects);
+ }
+
+ public URI getLocationURI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProjectLabel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setHasConflicts(boolean hasConflicts) {
+ this.hasConflicts = hasConflicts;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/projectimport/FileSystemProject.java Thu Feb 25 14:26:09 2010 -0800
@@ -0,0 +1,152 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.wizards.projectimport;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
+import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.util.CoreUtil;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+@SuppressWarnings("restriction")
+public class FileSystemProject implements ProjectRecord {
+ private boolean hasConflicts;
+ private String projectName;
+ private final File location;
+
+ /**
+ * Create a record for a project based on the info in the file.
+ *
+ * @param file
+ */
+ public FileSystemProject(File location) {
+ this.location = location;
+ setProjectName();
+ }
+
+ @SuppressWarnings("unchecked")
+ public ImportOperation getImportOperation(IProject project, ILeveledImportStructureProvider structureProvider,
+ IOverwriteQuery query) {
+ File importSource = location;
+ if (!importSource.equals(project.getLocation().toFile())) {
+ List<Object> filesToImport = ProjectUtils.filterExternalProjectEntries(FileSystemStructureProvider.INSTANCE
+ .getChildren(importSource));
+ ImportOperation operation = new ImportOperation(project.getFullPath(), importSource,
+ FileSystemStructureProvider.INSTANCE, query, filesToImport);
+ operation.setOverwriteResources(true); // need to overwrite
+ // .project, .classpath
+ // files
+ operation.setCreateContainerStructure(false);
+ return operation;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Gets the label to be used when rendering this project record in the
+ * UI.
+ *
+ * @return String the label
+ * @since 3.4
+ */
+ public String getProjectLabel() {
+ return NLS.bind(DataTransferMessages.WizardProjectsImportPage_projectLabel, projectName, location
+ .getAbsolutePath());
+ }
+
+ public String getProjectName() {
+ return projectName;
+ }
+
+ public boolean hasConflicts() {
+ return hasConflicts;
+ }
+
+ /**
+ * Returns whether the given project description file path is in the
+ * default location for a project
+ *
+ * @param path
+ * The path to examine
+ * @return Whether the given path is the default location for a project
+ */
+ private boolean isDefaultLocation(IPath path) {
+ // The project description file must at least be within the project,
+ // which is within the workspace location
+ if (path.segmentCount() < 1) {
+ return false;
+ }
+ return path.removeLastSegments(1).toFile().equals(Platform.getLocation().toFile());
+ }
+
+ public void setHasConflicts(boolean hasConflicts) {
+ this.hasConflicts = hasConflicts;
+ }
+
+ /**
+ * Set the name of the project based on the projectFile.
+ */
+ private void setProjectName() {
+ try {
+ // If we don't have the project name try again
+ if (projectName == null) {
+ IPath path = new Path(location.getAbsolutePath());
+ IPath desc = path.append(IProjectDescription.DESCRIPTION_FILE_NAME);
+ // if the file is in the default location, use the directory
+ // name as the project name
+ if (isDefaultLocation(path)) {
+ projectName = path.segment(path.segmentCount() - 1);
+ } else if (!desc.toFile().isFile() && !isDefaultLocation(path)) {
+ try {
+ FileInputStream input = new FileInputStream(path.append(CoreUtil.METADATA_FILE).toFile());
+ String manifest = CoreUtil.read(new InputStreamReader(input));
+ projectName = CoreUtil.getApplicationName(manifest);
+ } catch (IOException e) {
+ Activator.log(e);
+ projectName = path.segment(path.segmentCount() - 1);
+ }
+ } else {
+ IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(desc);
+ projectName = description.getName();
+ }
+
+ }
+ } catch (CoreException e) {
+ // no good couldn't get the name
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/projectimport/ProjectRecord.java Thu Feb 25 14:26:09 2010 -0800
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.wizards.projectimport;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+
+/**
+ * Class declared public only for test suite.
+ */
+@SuppressWarnings("restriction")
+public interface ProjectRecord {
+ boolean hasConflicts();
+ String getProjectLabel();
+ String getProjectName();
+
+ // URI getLocationURI();
+ void setHasConflicts(boolean b);
+ ImportOperation getImportOperation(IProject project, ILeveledImportStructureProvider structureProvider,
+ IOverwriteQuery query);
+}
\ No newline at end of file