# HG changeset patch # User Eugene Ostroukhov # Date 1265936190 28800 # Node ID f0a865ead60bc7a117d0853ba2a480725e2ffa66 # Parent f66df1e99ba54f8338e6cc684772d0e75b1c18a9 Fixed Bug 1869 - Open index file and select it in navigator after the project is created/imported diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools.product/src/org/symbian/tools/wrttools/product/perspective/WRTPerspective.java --- a/org.symbian.tools.wrttools.product/src/org/symbian/tools/wrttools/product/perspective/WRTPerspective.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools.product/src/org/symbian/tools/wrttools/product/perspective/WRTPerspective.java Thu Feb 11 16:56:30 2010 -0800 @@ -8,6 +8,7 @@ import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.progress.IProgressConstants; import org.eclipse.wst.jsdt.ui.JavaScriptUI; +import org.symbian.tools.wrttools.Activator; public class WRTPerspective implements IPerspectiveFactory { @@ -15,7 +16,7 @@ String editorArea = layout.getEditorArea(); IFolderLayout folder= layout.createFolder("left", IPageLayout.LEFT, (float)0.25, editorArea); //$NON-NLS-1$ - folder.addView("org.symbian.tools.wrttools.wrtnavigator"); + folder.addView(Activator.NAVIGATOR_ID); folder.addView(JavaScriptUI.ID_TYPE_HIERARCHY); IFolderLayout outputfolder= layout.createFolder("bottom", IPageLayout.BOTTOM, (float)0.75, editorArea); //$NON-NLS-1$ diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/META-INF/MANIFEST.MF --- a/org.symbian.tools.wrttools/META-INF/MANIFEST.MF Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/META-INF/MANIFEST.MF Thu Feb 11 16:56:30 2010 -0800 @@ -46,5 +46,6 @@ Bundle-ClassPath: lib/tagsoup-1.2.jar, ., lib/jtidy-8.0-20060801.131059-3.jar -Export-Package: org.symbian.tools.wrttools.util, +Export-Package: org.symbian.tools.wrttools, + org.symbian.tools.wrttools.util, org.symbian.tools.wrttools.wizards diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/Activator.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/Activator.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/Activator.java Thu Feb 11 16:56:30 2010 -0800 @@ -31,6 +31,8 @@ // The plug-in ID public static final String PLUGIN_ID = "org.symbian.tools.wrttools"; + + public static final String NAVIGATOR_ID = PLUGIN_ID + ".wrtnavigator"; // The shared instance private static Activator plugin; diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java Thu Feb 11 16:56:30 2010 -0800 @@ -76,7 +76,7 @@ public static String readFile(IProject project, IFile file) throws CoreException { try { - if (file.isAccessible()) { + if (file != null && file.isAccessible()) { InputStream contents = file.getContents(); final BufferedReader reader = new BufferedReader( new InputStreamReader(contents, file.getCharset())); @@ -103,6 +103,9 @@ public static synchronized String getIndexFile(IProject project) throws CoreException { // There will really be a lot of calls to this method. We need to cache values. IFile file = getFile(project, METADATA_FILE); + if (file == null) { + return null; + } if (INDEX_FILES.containsKey(project)) { IndexFileRecord record = INDEX_FILES.get(project); if (file == null || !file.isAccessible()) { diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Thu Feb 11 16:56:30 2010 -0800 @@ -23,6 +23,8 @@ import java.io.IOException; import java.net.URI; import java.text.MessageFormat; +import java.util.Collection; +import java.util.HashSet; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -43,10 +45,16 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IViewReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.part.ISetSelectionTarget; import org.eclipse.wst.jsdt.core.JavaScriptCore; import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock; import org.eclipse.wst.validation.ValidationFramework; -import org.eclipse.wst.validation.Validator; import org.symbian.tools.wrttools.Activator; import org.symbian.tools.wrttools.WidgetProjectNature; @@ -224,4 +232,38 @@ return resource.getType() == IResource.FILE && resource.getName().equalsIgnoreCase("info.plist"); } + + public static void focusOn(IProject... projects) { + try { + final Collection files = new HashSet(projects.length); + for (IProject project : projects) { + String file = CoreUtil.getIndexFile(project); + if (file != null) { + IFile index = project.getFile(file); + if (index.isAccessible()) { + files.add(index); + } + } + } + IFile[] filesArray = files.toArray(new IFile[files.size()]); + IWorkbenchPage activePage = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage(); + IViewReference reference = activePage + .findViewReference(Activator.NAVIGATOR_ID); + IWorkbenchPart part = reference.getPart(false); + if (part instanceof ISetSelectionTarget) { + StructuredSelection selection; + if (filesArray.length == 1) { + selection = new StructuredSelection(filesArray[0]); + } else { + selection = new StructuredSelection(filesArray); + } + ((ISetSelectionTarget) part) + .selectReveal(selection); + } + IDE.openEditors(activePage, filesArray); + } catch (CoreException e) { + Activator.log(e); + } + } } diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectLocationWizardPage.java Thu Feb 11 16:56:30 2010 -0800 @@ -376,6 +376,10 @@ } } + public List getCreatedProjects() { + return createdProjects; + } + /** * Collect the list of .project files that are under directory into files. * diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AptanaProjectsImportWizard.java Thu Feb 11 16:56:30 2010 -0800 @@ -18,6 +18,9 @@ */ 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; @@ -27,6 +30,7 @@ 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 { @@ -49,6 +53,8 @@ public boolean performFinish() { if (mainPage.createProjects()) { BasicNewProjectResourceWizard.updatePerspective(config); + List projects = mainPage.getCreatedProjects(); + ProjectUtils.focusOn(projects.toArray(new IProject[projects.size()])); return true; } else { return false; diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java Thu Feb 11 16:56:30 2010 -0800 @@ -39,7 +39,7 @@ addPage(page); } - private void createProject(String archiveName, String projectName, URI uri, + private IProject createProject(String archiveName, String projectName, URI uri, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Importing WRT application archive", 50); // 1. Create project @@ -55,6 +55,7 @@ "Archive unpacking failed", e)); } monitor.done(); + return project; } @Override @@ -63,6 +64,7 @@ final String projectName = page.getProjectName(); final URI uri = page.getLocationURI(); final String archiveName = page.getArchiveFile(); + final IProject[] holder = new IProject[1]; getContainer().run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) @@ -73,7 +75,7 @@ public void run(IProgressMonitor monitor) throws CoreException { - createProject(archiveName, projectName, + holder[0] = createProject(archiveName, projectName, uri, monitor); } @@ -84,6 +86,9 @@ } } }); + if (holder[0] != null) { + ProjectUtils.focusOn(holder[0]); + } } catch (InvocationTargetException e) { Activator.log(e); } catch (InterruptedException e) { diff -r f66df1e99ba5 -r f0a865ead60b org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Thu Feb 11 15:27:41 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Thu Feb 11 16:56:30 2010 -0800 @@ -78,11 +78,12 @@ } public boolean performFinish() { + final IProject[] holder = new IProject[1]; try { getContainer().run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - action(monitor); + holder[0] = action(monitor); } }); } catch (InvocationTargetException e) { @@ -91,22 +92,27 @@ Activator.log(e); } BasicNewProjectResourceWizard.updatePerspective(config); + if (holder[0] != null) { + ProjectUtils.focusOn(holder[0]); + } return true; } - protected void action(IProgressMonitor monitor) { + protected IProject action(IProgressMonitor monitor) { + final IProject[] holder = new IProject[1]; try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { - createAndInitProject(monitor); + holder[0] = createAndInitProject(monitor); } }, monitor); } catch (CoreException e) { Activator.log(e); } + return holder[0]; } - protected void createAndInitProject(IProgressMonitor monitor) + protected IProject createAndInitProject(IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating project", 100); IProject project = ProjectUtils.createWrtProject(context.getProjectName(), context.getProjectUri(), new SubProgressMonitor(monitor, 30)); @@ -117,6 +123,7 @@ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to setup libraries", e)); } monitor.done(); + return project; } private void initLibraries(IProject project, String[] libraryIds, IProgressMonitor progressMonitor) throws IOException, CoreException {