Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 179256 Details for
Bug 162608
[Project Sets] Be able to import a .psf file directly from a URL
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed patch
patch_162608.txt (text/plain), 56.79 KB, created by
Malgorzata Janczarska
on 2010-09-20 11:26:07 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Malgorzata Janczarska
Created:
2010-09-20 11:26:07 EDT
Size:
56.79 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.team.ui >Index: src/org/eclipse/team/internal/ui/ProjectSetImporter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java,v >retrieving revision 1.10 >diff -u -r1.10 ProjectSetImporter.java >--- src/org/eclipse/team/internal/ui/ProjectSetImporter.java 14 Nov 2008 15:35:40 -0000 1.10 >+++ src/org/eclipse/team/internal/ui/ProjectSetImporter.java 20 Sep 2010 15:21:26 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -30,75 +30,138 @@ > import org.eclipse.ui.*; > > public class ProjectSetImporter { >- >- public static IProject[] importProjectSet(String filename, Shell shell, IProgressMonitor monitor) throws InvocationTargetException { >+ >+ /** >+ * Imports a psf file based on a file content. This may be used when psf >+ * file is imported from any other location that local filesystem. >+ * >+ * @param psfContents >+ * the content of the psf file. >+ * @param filename >+ * the name of the source file. This is included in case the >+ * provider needs to deduce relative paths >+ * @param shell >+ * @param monitor >+ * @return list of new projects >+ * @throws InvocationTargetException >+ */ >+ public static IProject[] importProjectSetFromString(String psfContents, >+ String filename, Shell shell, IProgressMonitor monitor) >+ throws InvocationTargetException { >+ XMLMemento xmlMemento = stringToXMLMemento(psfContents); >+ return importProjectSet(xmlMemento, filename, shell, monitor); >+ } >+ >+ /** >+ * Imports a psf file. >+ * >+ * @param filename >+ * @param shell >+ * @param monitor >+ * @return list of new projects >+ * @throws InvocationTargetException >+ */ >+ public static IProject[] importProjectSet(String filename, Shell shell, >+ IProgressMonitor monitor) throws InvocationTargetException { >+ XMLMemento xmlMemento = filenameToXMLMemento(filename); >+ return importProjectSet(xmlMemento, filename, shell, monitor); >+ } >+ >+ private static IProject[] importProjectSet(XMLMemento xmlMemento, >+ String filename, Shell shell, IProgressMonitor monitor) >+ throws InvocationTargetException { > try { >- XMLMemento xmlMemento = filenameToXMLMemento(filename); >+ > String version = xmlMemento.getString("version"); //$NON-NLS-1$ >- >+ > List newProjects = new ArrayList(); >- if (version.equals("1.0")){ //$NON-NLS-1$ >- IProjectSetSerializer serializer = Team.getProjectSetSerializer("versionOneSerializer"); //$NON-NLS-1$ >+ if (version.equals("1.0")) { //$NON-NLS-1$ >+ IProjectSetSerializer serializer = Team >+ .getProjectSetSerializer("versionOneSerializer"); //$NON-NLS-1$ > if (serializer != null) { >- IProject[] projects = serializer.addToWorkspace(new String[0], filename, shell, monitor); >+ IProject[] projects = serializer.addToWorkspace( >+ new String[0], filename, shell, monitor); > if (projects != null) > newProjects.addAll(Arrays.asList(projects)); > } > } else { >- UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(shell, filename); >+ UIProjectSetSerializationContext context = new UIProjectSetSerializationContext( >+ shell, filename); > List errors = new ArrayList(); > ArrayList referenceStrings = new ArrayList(); >- IMemento[] providers = xmlMemento.getChildren("provider"); //$NON-NLS-1$ >- for (int i = 0; i < providers.length; i++) { >+ IMemento[] providers = xmlMemento.getChildren("provider"); //$NON-NLS-1$ >+ for (int i = 0; i < providers.length; i++) { > IMemento[] projects = providers[i].getChildren("project"); //$NON-NLS-1$ > for (int j = 0; j < projects.length; j++) { >- referenceStrings.add(projects[j].getString("reference")); //$NON-NLS-1$ >+ referenceStrings >+ .add(projects[j].getString("reference")); //$NON-NLS-1$ > } > try { >- String id = providers[i].getString("id"); //$NON-NLS-1$ >- TeamCapabilityHelper.getInstance().processRepositoryId(id, >- PlatformUI.getWorkbench().getActivitySupport()); >- RepositoryProviderType providerType = RepositoryProviderType.getProviderType(id); >- if (providerType == null) { >- // The provider type is absent. Perhaps there is another provider that can import this type >- providerType = TeamPlugin.getAliasType(id); >- } >- if (providerType == null) { >- throw new TeamException(new Status(IStatus.ERROR, TeamUIPlugin.ID, 0, NLS.bind(TeamUIMessages.ProjectSetImportWizard_0, new String[] { id }), null)); >- } >- ProjectSetCapability serializer = providerType.getProjectSetCapability(); >- ProjectSetCapability.ensureBackwardsCompatible(providerType, serializer); >- if (serializer != null) { >- IProject[] allProjects = serializer.addToWorkspace((String[])referenceStrings.toArray(new String[referenceStrings.size()]), context, monitor); >- if (allProjects != null) >- newProjects.addAll(Arrays.asList(allProjects)); >- } >- referenceStrings.clear(); >- } catch (TeamException e) { >- errors.add(e); >- } >- } >- if (!errors.isEmpty()) { >- if (errors.size() == 1) { >- throw (TeamException)errors.get(0); >- } else { >- TeamException[] exceptions = (TeamException[]) errors.toArray(new TeamException[errors.size()]); >- IStatus[] status = new IStatus[exceptions.length]; >- for (int i = 0; i < exceptions.length; i++) { >- status[i] = exceptions[i].getStatus(); >- } >- throw new TeamException(new MultiStatus(TeamUIPlugin.ID, 0, status, TeamUIMessages.ProjectSetImportWizard_1, null)); >- } >- } >- >- //try working sets >- IMemento[] sets = xmlMemento.getChildren("workingSets"); //$NON-NLS-1$ >- IWorkingSetManager wsManager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager(); >- boolean replaceAll = false; >- boolean mergeAll = false; >- boolean skipAll = false; >- >- for (int i = 0; i < sets.length; i++) { >+ String id = providers[i].getString("id"); //$NON-NLS-1$ >+ TeamCapabilityHelper.getInstance().processRepositoryId( >+ id, >+ PlatformUI.getWorkbench().getActivitySupport()); >+ RepositoryProviderType providerType = RepositoryProviderType >+ .getProviderType(id); >+ if (providerType == null) { >+ // The provider type is absent. Perhaps there is >+ // another provider that can import this type >+ providerType = TeamPlugin.getAliasType(id); >+ } >+ if (providerType == null) { >+ throw new TeamException( >+ new Status( >+ IStatus.ERROR, >+ TeamUIPlugin.ID, >+ 0, >+ NLS.bind( >+ TeamUIMessages.ProjectSetImportWizard_0, >+ new String[] { id }), null)); >+ } >+ ProjectSetCapability serializer = providerType >+ .getProjectSetCapability(); >+ ProjectSetCapability.ensureBackwardsCompatible( >+ providerType, serializer); >+ if (serializer != null) { >+ IProject[] allProjects = serializer >+ .addToWorkspace( >+ (String[]) referenceStrings >+ .toArray(new String[referenceStrings >+ .size()]), context, >+ monitor); >+ if (allProjects != null) >+ newProjects.addAll(Arrays.asList(allProjects)); >+ } >+ referenceStrings.clear(); >+ } catch (TeamException e) { >+ errors.add(e); >+ } >+ } >+ if (!errors.isEmpty()) { >+ if (errors.size() == 1) { >+ throw (TeamException) errors.get(0); >+ } else { >+ TeamException[] exceptions = (TeamException[]) errors >+ .toArray(new TeamException[errors.size()]); >+ IStatus[] status = new IStatus[exceptions.length]; >+ for (int i = 0; i < exceptions.length; i++) { >+ status[i] = exceptions[i].getStatus(); >+ } >+ throw new TeamException(new MultiStatus( >+ TeamUIPlugin.ID, 0, status, >+ TeamUIMessages.ProjectSetImportWizard_1, null)); >+ } >+ } >+ >+ // try working sets >+ IMemento[] sets = xmlMemento.getChildren("workingSets"); //$NON-NLS-1$ >+ IWorkingSetManager wsManager = TeamUIPlugin.getPlugin() >+ .getWorkbench().getWorkingSetManager(); >+ boolean replaceAll = false; >+ boolean mergeAll = false; >+ boolean skipAll = false; >+ >+ for (int i = 0; i < sets.length; i++) { > IWorkingSet newWs = wsManager.createWorkingSet(sets[i]); > if (newWs != null) { > IWorkingSet oldWs = wsManager.getWorkingSet(newWs >@@ -113,24 +176,23 @@ > // a working set with the same name has been found > String title = TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_title; > String msg = NLS >- .bind( >- TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_message, >+ .bind(TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_message, > newWs.getName()); > String[] buttons = new String[] { > TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replace, > TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_merge, > TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skip, > IDialogConstants.CANCEL_LABEL }; >- final AdviceDialog dialog = new AdviceDialog( >- shell, title, null, msg, >- MessageDialog.QUESTION, buttons, 0); >- >+ final AdviceDialog dialog = new AdviceDialog(shell, >+ title, null, msg, MessageDialog.QUESTION, >+ buttons, 0); >+ > shell.getDisplay().syncExec(new Runnable() { > public void run() { >- dialog.open(); >+ dialog.open(); > } > }); >- >+ > switch (dialog.getReturnCode()) { > case 0: // overwrite > replaceWorkingSet(wsManager, newWs, oldWs); >@@ -151,17 +213,20 @@ > } > } > } >- >- return (IProject[]) newProjects.toArray(new IProject[newProjects.size()]); >+ >+ return (IProject[]) newProjects.toArray(new IProject[newProjects >+ .size()]); > } catch (TeamException e) { > throw new InvocationTargetException(e); > } > } > >- private static XMLMemento filenameToXMLMemento(String filename) throws InvocationTargetException { >+ private static XMLMemento filenameToXMLMemento(String filename) >+ throws InvocationTargetException { > InputStreamReader reader = null; > try { >- reader = new InputStreamReader(new FileInputStream(filename), "UTF-8"); //$NON-NLS-1$ >+ reader = new InputStreamReader(new FileInputStream(filename), >+ "UTF-8"); //$NON-NLS-1$ > return XMLMemento.createReadRoot(reader); > } catch (UnsupportedEncodingException e) { > throw new InvocationTargetException(e); >@@ -179,7 +244,28 @@ > } > } > } >- >+ >+ private static XMLMemento stringToXMLMemento(String stringContents) >+ throws InvocationTargetException { >+ StringReader reader = null; >+ try { >+ reader = new StringReader(stringContents); >+ return XMLMemento.createReadRoot(reader); >+ } catch (WorkbenchException e) { >+ throw new InvocationTargetException(e); >+ } finally { >+ if (reader != null) { >+ reader.close(); >+ } >+ } >+ } >+ >+ /** >+ * Check if given file is a valid psf file >+ * >+ * @param filename >+ * @return <code>true</code> is file is a valid psf file >+ */ > public static boolean isValidProjectSetFile(String filename) { > try { > return filenameToXMLMemento(filename).getString("version") != null; //$NON-NLS-1$ >@@ -187,19 +273,38 @@ > return false; > } > } >- >+ >+ /** >+ * Check if given string is a valid project set >+ * >+ * @param psfContent >+ * @return <code>true</code> if psfContent is a valid project set >+ */ >+ public static boolean isValidProjectSetString(String psfContent) { >+ if (psfContent == null) { >+ return false; >+ } >+ try { >+ return stringToXMLMemento(psfContent).getString("version") != null; //$NON-NLS-1$ >+ } catch (InvocationTargetException e) { >+ return false; >+ } >+ } >+ > private static void mergeWorkingSets(IWorkingSet newWs, IWorkingSet oldWs) { > IAdaptable[] oldElements = oldWs.getElements(); > IAdaptable[] newElements = newWs.getElements(); >- >+ > Set combinedElements = new HashSet(); > combinedElements.addAll(Arrays.asList(oldElements)); > combinedElements.addAll(Arrays.asList(newElements)); >- >- oldWs.setElements((IAdaptable[]) combinedElements.toArray(new IAdaptable[0])); >+ >+ oldWs.setElements((IAdaptable[]) combinedElements >+ .toArray(new IAdaptable[0])); > } > >- private static void replaceWorkingSet(IWorkingSetManager wsManager, IWorkingSet newWs, IWorkingSet oldWs) { >+ private static void replaceWorkingSet(IWorkingSetManager wsManager, >+ IWorkingSet newWs, IWorkingSet oldWs) { > if (oldWs != null) > wsManager.removeWorkingSet(oldWs); > wsManager.addWorkingSet(newWs); >@@ -207,9 +312,15 @@ > > private static class AdviceDialog extends MessageDialog { > boolean applyToAll; >- public AdviceDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) { >- super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex); >+ >+ public AdviceDialog(Shell parentShell, String dialogTitle, >+ Image dialogTitleImage, String dialogMessage, >+ int dialogImageType, String[] dialogButtonLabels, >+ int defaultIndex) { >+ super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, >+ dialogImageType, dialogButtonLabels, defaultIndex); > } >+ > protected Control createCustomArea(Composite parent) { > final Button checkBox = new Button(parent, SWT.CHECK); > checkBox.setText(TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_applyToAll); >Index: src/org/eclipse/team/internal/ui/TeamUIMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java,v >retrieving revision 1.93 >diff -u -r1.93 TeamUIMessages.java >--- src/org/eclipse/team/internal/ui/TeamUIMessages.java 17 Sep 2010 09:08:29 -0000 1.93 >+++ src/org/eclipse/team/internal/ui/TeamUIMessages.java 20 Sep 2010 15:21:26 -0000 >@@ -105,6 +105,8 @@ > public static String HistoryPageCompareEditorInput_0; > > public static String ImportProjectSetMainPage_AddToWorkingSet; >+ public static String ImportProjectSetMainPage_Project_Set_File; >+ public static String ImportProjectSetMainPage_Project_Set_Url; > > public static String ImportProjectSetMainPage_Browse; > >@@ -114,6 +116,9 @@ > public static String ImportProjectSetDialog_duplicatedWorkingSet_merge; > public static String ImportProjectSetDialog_duplicatedWorkingSet_skip; > public static String ImportProjectSetDialog_duplicatedWorkingSet_applyToAll; >+ public static String ImportProjectSetDialog_malformed_url; >+ public static String ImportProjectSetDialog_URLConnecting; >+ public static String ImportProjectSetDialog_URLFetchingContent; > > public static String information; > >@@ -310,8 +315,8 @@ > public static String ExportProjectSetMainPage_Initial_description; > public static String ExportProjectSetMainPage_specifyFile; > >- public static String ImportProjectSetMainPage_Project_Set_File_Name__2; > public static String ImportProjectSetMainPage_Browse_3; >+ public static String ImportProjectSetMainPage_The_given_URL_cannot_be_loaded; > public static String ImportProjectSetMainPage_The_specified_file_does_not_exist_4; > public static String ImportProjectSetMainPage_You_have_specified_a_folder_5; > public static String ImportProjectSetMainPage_workingSetNameEmpty; >@@ -320,6 +325,7 @@ > public static String ImportProjectSetMainPage_runInBackground; > public static String ImportProjectSetMainPage_jobName; > public static String ImportProjectSetMainPage_specifyFile; >+ public static String ImportProjectSetMainPage_specifyURL; > public static String ImportProjectSetMainPage_selectWorkingSet; > public static String ImportProjectSetMainPage_projectSetFileInvalid; > >Index: src/org/eclipse/team/internal/ui/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties,v >retrieving revision 1.269 >diff -u -r1.269 messages.properties >--- src/org/eclipse/team/internal/ui/messages.properties 17 Sep 2010 09:08:29 -0000 1.269 >+++ src/org/eclipse/team/internal/ui/messages.properties 20 Sep 2010 15:21:27 -0000 >@@ -104,9 +104,11 @@ > ExportProjectSetMainPage_Initial_description=Define which projects or working sets should be exported into the team project file. > ExportProjectSetMainPage_specifyFile=Please specify the destination file. > >-ImportProjectSetMainPage_Project_Set_File_Name__2=F&ile name: >+ImportProjectSetMainPage_Project_Set_File=File >+ImportProjectSetMainPage_Project_Set_Url=URL > ImportProjectSetMainPage_Browse_3=B&rowse... > ImportProjectSetMainPage_Browse=Br&owse... >+ImportProjectSetMainPage_The_given_URL_cannot_be_loaded=File from given URL cannot be loaded > ImportProjectSetMainPage_The_specified_file_does_not_exist_4=The specified file does not exist > ImportProjectSetMainPage_You_have_specified_a_folder_5=You have specified a folder > ImportProjectSetMainPage_workingSetNameEmpty=The working set name must not be empty >@@ -116,6 +118,7 @@ > ImportProjectSetMainPage_runInBackground=Run the import in the bac&kground > ImportProjectSetMainPage_jobName=Importing project set... > ImportProjectSetMainPage_specifyFile=Please specify a file to import. >+ImportProjectSetMainPage_specifyURL=Please specify an URL to import. > ImportProjectSetMainPage_selectWorkingSet=Select a working set. > ImportProjectSetMainPage_projectSetFileInvalid=The specified file is not a valid Team Project Set file. > ImportProjectSetDialog_duplicatedWorkingSet_title=Working Set Exists >@@ -124,6 +127,9 @@ > ImportProjectSetDialog_duplicatedWorkingSet_merge=&Merge > ImportProjectSetDialog_duplicatedWorkingSet_skip=&Skip > ImportProjectSetDialog_duplicatedWorkingSet_applyToAll=&Apply to all working sets in this import >+ImportProjectSetDialog_malformed_url=Malformed URL >+ImportProjectSetDialog_URLConnecting=Opening connection to the URL >+ImportProjectSetDialog_URLFetchingContent=Fetching content from the URL > > ProjectSetContentHandler_Element_provider_must_be_contained_in_element_psf_4=Element provider must be contained in element psf > ProjectSetContentHandler_Element_project_must_be_contained_in_element_provider_7=Element project must be contained in element provider >Index: src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java,v >retrieving revision 1.6 >diff -u -r1.6 ImportProjectSetAction.java >--- src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java 2 Aug 2010 14:33:15 -0000 1.6 >+++ src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java 20 Sep 2010 15:21:27 -0000 >@@ -24,7 +24,7 @@ > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.team.internal.ui.*; >-import org.eclipse.team.internal.ui.wizards.ImportProjectSetOperation; >+import org.eclipse.team.internal.ui.wizards.ImportFromFileProjectSetOperation; > import org.eclipse.ui.*; > import org.eclipse.ui.actions.ActionDelegate; > import org.eclipse.ui.actions.WorkspaceModifyOperation; >@@ -42,7 +42,7 @@ > while (iterator.hasNext()) { > IFile file = (IFile) iterator.next(); > if (isRunInBackgroundPreferenceOn()) { >- ImportProjectSetOperation op = new ImportProjectSetOperation(null, file.getLocation().toString(), new IWorkingSet[0]); >+ ImportFromFileProjectSetOperation op = new ImportFromFileProjectSetOperation(null, file.getLocation().toString(), new IWorkingSet[0]); > op.run(); > } else { > ProjectSetImporter.importProjectSet(file.getLocation().toString(), shell, monitor); >Index: src/org/eclipse/team/internal/ui/wizards/ExportProjectSetLocationPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ExportProjectSetLocationPage.java,v >retrieving revision 1.6 >diff -u -r1.6 ExportProjectSetLocationPage.java >--- src/org/eclipse/team/internal/ui/wizards/ExportProjectSetLocationPage.java 18 Aug 2008 09:46:09 -0000 1.6 >+++ src/org/eclipse/team/internal/ui/wizards/ExportProjectSetLocationPage.java 20 Sep 2010 15:21:27 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -91,8 +91,8 @@ > inner.setLayoutData(data); > > fileCombo = createDropDownCombo(inner); >- file = PsfFilenameStore.getSuggestedDefault(); >- fileCombo.setItems(PsfFilenameStore.getHistory()); >+ file = PsfFilenameStore.getInstance().getSuggestedDefault(); >+ fileCombo.setItems(PsfFilenameStore.getInstance().getHistory()); > fileCombo.setText(file); > fileCombo.addListener(SWT.Modify, new Listener() { > public void handleEvent(Event event) { >Index: src/org/eclipse/team/internal/ui/wizards/ImportFromFileProjectSetOperation.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ui/wizards/ImportFromFileProjectSetOperation.java >diff -N src/org/eclipse/team/internal/ui/wizards/ImportFromFileProjectSetOperation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ui/wizards/ImportFromFileProjectSetOperation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ui.wizards; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.jface.operation.IRunnableContext; >+import org.eclipse.team.internal.ui.ProjectSetImporter; >+import org.eclipse.ui.IWorkingSet; >+ >+public class ImportFromFileProjectSetOperation extends ImportProjectSetOperation { >+ >+ private String psfFile; >+ private IWorkingSet[] workingSets; >+ >+ /** >+ * Operation for importing a Team Project Set file >+ * >+ * @param context >+ * a runnable context >+ * @param psfFile >+ * a psf file name >+ * @param workingSets >+ * an array of working sets where imported project should be >+ * added. If a working set doesn't exist it will be created. The >+ * array cannot be <code>null</code>, pass an empty array if you >+ * don't want to add projects to any working set. >+ */ >+ public ImportFromFileProjectSetOperation(IRunnableContext context, String psfFile, >+ IWorkingSet[] workingSets) { >+ super(context); >+ this.psfFile = psfFile; >+ this.workingSets = workingSets; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public void run(IProgressMonitor monitor) throws InvocationTargetException, >+ InterruptedException { >+ PsfFilenameStore.getInstance().remember(psfFile); >+ IProject[] newProjects = ProjectSetImporter.importProjectSet(psfFile, >+ getShell(), monitor); >+ createWorkingSet(workingSets, newProjects); >+ } >+} >Index: src/org/eclipse/team/internal/ui/wizards/ImportProjectSetMainPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ImportProjectSetMainPage.java,v >retrieving revision 1.22 >diff -u -r1.22 ImportProjectSetMainPage.java >--- src/org/eclipse/team/internal/ui/wizards/ImportProjectSetMainPage.java 22 Jul 2008 09:16:42 -0000 1.22 >+++ src/org/eclipse/team/internal/ui/wizards/ImportProjectSetMainPage.java 20 Sep 2010 15:21:29 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,11 +10,15 @@ > *******************************************************************************/ > package org.eclipse.team.internal.ui.wizards; > >-import java.io.File; >+import java.io.*; >+import java.lang.reflect.InvocationTargetException; >+import java.net.*; > > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.*; > import org.eclipse.jface.dialogs.Dialog; > import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.operation.IRunnableWithProgress; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.SelectionAdapter; >@@ -32,16 +36,47 @@ > String file = ""; //$NON-NLS-1$ > Button browseButton; > >+ String urlString = ""; //$NON-NLS-1$ >+ Combo urlCombo; >+ >+ //input type radios >+ private Button fileInputButton; >+ private Button urlInputButton; >+ >+ //input type >+ public static final int InputType_file = 0; >+ public static final int InputType_URL = 1; >+ private int inputType = InputType_file; >+ > private boolean runInBackground = isRunInBackgroundPreferenceOn(); > // a wizard shouldn't be in an error state until the state has been modified by the user > private int messageType = NONE; > private WorkingSetGroup workingSetGroup; > >+ private PsfFilenameStore psfFilenameStore = PsfFilenameStore.getInstance(); >+ private PsfUrlStore psfUrlStore = PsfUrlStore.getInstance(); >+ > public ImportProjectSetMainPage(String pageName, String title, ImageDescriptor titleImage) { > super(pageName, title, titleImage); > setDescription(TeamUIMessages.ImportProjectSetMainPage_description); > } > >+ private void setInputyType(int inputTypeSelected){ >+ this.inputType = inputTypeSelected; >+ //reset the message type and give the user fresh chance to input correct data >+ messageType = NONE; >+ //update controls >+ fileInputButton.setSelection(inputType==InputType_file); >+ fileCombo.setEnabled(inputType==InputType_file); >+ browseButton.setEnabled(inputType==InputType_file); >+ urlInputButton.setSelection(inputType==InputType_URL); >+ urlCombo.setEnabled(inputType==InputType_URL); >+ //validate field >+ if(inputType==InputType_file) updateFileEnablement(); >+ if(inputType==InputType_URL) updateUrlEnablement(); >+ >+ } >+ > /* > * @see IDialogPage#createControl(Composite) > */ >@@ -60,21 +95,51 @@ > layout.marginWidth = 0; > inner.setLayout(layout); > >- createLabel(inner, TeamUIMessages.ImportProjectSetMainPage_Project_Set_File_Name__2); >+ fileInputButton = new Button(inner, SWT.RADIO); >+ fileInputButton.setText(TeamUIMessages.ImportProjectSetMainPage_Project_Set_File); >+ fileInputButton.setEnabled(true); >+ fileInputButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ setInputyType(InputType_file); >+ } >+ }); > > fileCombo = createDropDownCombo(inner); >- file = PsfFilenameStore.getSuggestedDefault(); >- fileCombo.setItems(PsfFilenameStore.getHistory()); >+ file = psfFilenameStore.getSuggestedDefault(); >+ fileCombo.setItems(psfFilenameStore.getHistory()); > fileCombo.setText(file); > fileCombo.addListener(SWT.Modify, new Listener() { > public void handleEvent(Event event) { > file = fileCombo.getText(); >- updateEnablement(); >+ updateFileEnablement(); > } > }); > > browseButton = new Button(inner, SWT.PUSH); > browseButton.setText(TeamUIMessages.ImportProjectSetMainPage_Browse_3); >+ >+ urlInputButton = new Button(inner, SWT.RADIO); >+ urlInputButton.setText(TeamUIMessages.ImportProjectSetMainPage_Project_Set_Url); >+ urlInputButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ setInputyType(InputType_URL); >+ } >+ }); >+ urlCombo = createDropDownCombo(inner); >+ urlString = psfUrlStore.getSuggestedDefault(); >+ urlCombo.setItems(psfUrlStore.getHistory()); >+ urlCombo.setText(urlString); >+ GridData gd = new GridData(GridData.FILL_HORIZONTAL); >+ gd.horizontalSpan=2; >+ urlCombo.setLayoutData(gd); >+ urlCombo.addListener(SWT.Modify, new Listener() { >+ public void handleEvent(Event event) { >+ urlString=urlCombo.getText(); >+ updateUrlEnablement(); >+ } >+ }); >+ >+ > GridData data = new GridData(); > data.horizontalAlignment = GridData.FILL; > int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); >@@ -115,10 +180,8 @@ > }); > > setControl(composite); >- updateEnablement(); >+ setInputyType(InputType_file); > Dialog.applyDialogFont(parent); >- // future messages will be of type error >- messageType = ERROR; > } > > private void addWorkingSetSection(Composite composite) { >@@ -129,9 +192,39 @@ > "org.eclipse.jdt.ui.JavaWorkingSetPage" /* JavaWorkingSetUpdater.ID */}); //$NON-NLS-1$ > } > >- private void updateEnablement() { >+ private void updateUrlEnablement() { >+ boolean complete = false; >+ setMessage(null); >+ setErrorMessage(null); >+ >+ if (urlString.length() == 0) { >+ setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyURL, messageType); >+ complete = false; >+ } else { >+ >+ try { >+ new URL(urlString); >+ // the URL is correct, we can clear the error message >+ complete = true; >+ } catch (MalformedURLException e) { >+ messageType = ERROR; >+ setMessage(TeamUIMessages.ImportProjectSetDialog_malformed_url, messageType); >+ complete = false; >+ } >+ } >+ >+ if (complete) { >+ setErrorMessage(null); >+ setDescription(TeamUIMessages.ImportProjectSetMainPage_description); >+ } >+ >+ setPageComplete(complete); >+ } >+ >+ private void updateFileEnablement() { > boolean complete = false; > setMessage(null); >+ setErrorMessage(null); > > if (file.length() == 0) { > setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyFile, messageType); >@@ -141,14 +234,17 @@ > // See if the file exists > File f = new File(file); > if (!f.exists()) { >+ messageType = ERROR; > setMessage(TeamUIMessages.ImportProjectSetMainPage_The_specified_file_does_not_exist_4, messageType); > setPageComplete(false); > return; > } else if (f.isDirectory()) { >+ messageType = ERROR; > setMessage(TeamUIMessages.ImportProjectSetMainPage_You_have_specified_a_folder_5, messageType); > setPageComplete(false); > return; > } else if (!ProjectSetImporter.isValidProjectSetFile(file)) { >+ messageType = ERROR; > setMessage(TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, messageType); > setPageComplete(false); > return; >@@ -167,6 +263,10 @@ > public String getFileName() { > return file; > } >+ >+ public String getUrl(){ >+ return urlString; >+ } > > public void setVisible(boolean visible) { > super.setVisible(visible); >@@ -193,4 +293,102 @@ > public boolean isRunInBackgroundOn() { > return runInBackground; > } >+ >+ public int getInputType(){ >+ return inputType; >+ } >+ >+ public String getURLContents() { >+ final URL url; >+ try { >+ url = new URL(urlString); >+ PsfUrlStore.getInstance().remember(urlString); >+ final String[] result = new String[1]; >+ try { >+ getContainer().run(true, true, new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) >+ throws InvocationTargetException, >+ InterruptedException { >+ SubMonitor progress = SubMonitor >+ .convert( >+ monitor, >+ TeamUIMessages.ImportProjectSetDialog_URLConnecting, >+ 100); >+ try { >+ URLConnection connection = url.openConnection(); >+ progress.worked(10); >+ if (monitor.isCanceled()) >+ throw new OperationCanceledException(); >+ connection.setReadTimeout(60 * 1000); >+ progress.setTaskName(TeamUIMessages.ImportProjectSetDialog_URLFetchingContent); >+ String enc = connection.getContentEncoding(); >+ if (enc == null) >+ enc = ResourcesPlugin.getEncoding(); >+ result[0] = readPsfFromURL( >+ connection.getInputStream(), enc, >+ connection.getContentLength(), >+ progress.newChild(90)); >+ } catch (SocketTimeoutException e) { // timeout >+ throw new InvocationTargetException(e); >+ } catch (IOException e) { //cannot load file >+ throw new InvocationTargetException(e); >+ }finally{ >+ monitor.done(); >+ } >+ } >+ }); >+ >+ if(ProjectSetImporter.isValidProjectSetString(result[0])){ >+ return result[0]; >+ }else{ >+ messageType = ERROR; >+ setMessage(TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, messageType); >+ setPageComplete(false); >+ return null; >+ } >+ >+ } catch (OperationCanceledException e) { // ignore >+ } catch (InvocationTargetException e) { // ignore >+ messageType = ERROR; >+ setMessage(TeamUIMessages.ImportProjectSetMainPage_The_given_URL_cannot_be_loaded, messageType); >+ setPageComplete(false); >+ } catch (InterruptedException e) { // ignore >+ } >+ } catch (MalformedURLException e) { >+ // ignore as we tested it with modify listener on combo >+ } >+ return null; >+ } >+ >+ private String readPsfFromURL(InputStream is, String encoding, int length, >+ IProgressMonitor monitor) throws IOException { >+ SubMonitor progress = SubMonitor.convert(monitor); >+ progress.setWorkRemaining(length); >+ if (is == null) >+ return null; >+ BufferedReader reader = null; >+ try { >+ StringBuffer buffer = new StringBuffer(); >+ char[] part = new char[2048]; >+ int read = 0; >+ reader = new BufferedReader(new InputStreamReader(is, encoding)); >+ while ((read = reader.read(part)) != -1) { >+ buffer.append(part, 0, read); >+ progress.worked(2048); >+ if (progress.isCanceled()) >+ throw new OperationCanceledException(); >+ } >+ >+ return buffer.toString(); >+ } finally { >+ if (reader != null) { >+ try { >+ reader.close(); >+ } catch (IOException ex) { >+ // silently ignored >+ } >+ } >+ } >+ } >+ > } >Index: src/org/eclipse/team/internal/ui/wizards/ImportProjectSetOperation.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ImportProjectSetOperation.java,v >retrieving revision 1.4 >diff -u -r1.4 ImportProjectSetOperation.java >--- src/org/eclipse/team/internal/ui/wizards/ImportProjectSetOperation.java 21 Oct 2008 08:14:16 -0000 1.4 >+++ src/org/eclipse/team/internal/ui/wizards/ImportProjectSetOperation.java 20 Sep 2010 15:21:29 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2008 IBM Corporation and others. >+ * Copyright (c) 2007, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -16,48 +16,27 @@ > import org.eclipse.core.runtime.IAdaptable; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.jface.operation.IRunnableContext; >-import org.eclipse.team.internal.ui.*; >+import org.eclipse.team.internal.ui.TeamUIMessages; >+import org.eclipse.team.internal.ui.TeamUIPlugin; > import org.eclipse.team.ui.TeamOperation; > import org.eclipse.ui.IWorkingSet; > import org.eclipse.ui.IWorkingSetManager; > >-public class ImportProjectSetOperation extends TeamOperation { >+public abstract class ImportProjectSetOperation extends TeamOperation { > >- private String psfFile; >- private IWorkingSet[] workingSets; >- >- /** >- * Operation for importing a Team Project Set file >- * >- * @param context >- * a runnable context >- * @param psfFile >- * a psf file name >- * @param workingSets >- * an array of working sets where imported project should be >- * added. If a working set doesn't exist it will be created. The >- * array cannot be <code>null</code>, pass an empty array if you >- * don't want to add projects to any working set. >- */ >- public ImportProjectSetOperation(IRunnableContext context, String psfFile, >- IWorkingSet[] workingSets) { >+ protected ImportProjectSetOperation(IRunnableContext context) { > super(context); >- this.psfFile = psfFile; >- this.workingSets = workingSets; > } > > /* > * (non-Javadoc) > * >- * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) >+ * @see >+ * org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core >+ * .runtime.IProgressMonitor) > */ >- public void run(IProgressMonitor monitor) throws InvocationTargetException, >- InterruptedException { >- PsfFilenameStore.remember(psfFile); >- IProject[] newProjects = ProjectSetImporter.importProjectSet(psfFile, >- getShell(), monitor); >- createWorkingSet(workingSets, newProjects); >- } >+ public abstract void run(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException; > > /* > * (non-Javadoc) >@@ -76,25 +55,31 @@ > protected String getJobName() { > return TeamUIMessages.ImportProjectSetMainPage_jobName; > } >- >- private void createWorkingSet(IWorkingSet[] workingSets, IProject[] projects) { >- IWorkingSetManager manager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager(); >+ >+ protected void createWorkingSet(IWorkingSet[] workingSets, >+ IProject[] projects) { >+ IWorkingSetManager manager = TeamUIPlugin.getPlugin().getWorkbench() >+ .getWorkingSetManager(); > String workingSetName; > for (int i = 0; i < workingSets.length; i++) { > workingSetName = workingSets[i].getName(); > IWorkingSet oldSet = manager.getWorkingSet(workingSetName); > if (oldSet == null) { >- IWorkingSet newSet = manager.createWorkingSet(workingSetName, projects); >+ IWorkingSet newSet = manager.createWorkingSet(workingSetName, >+ projects); > manager.addWorkingSet(newSet); > } else { >- //don't overwrite the old elements >+ // don't overwrite the old elements > IAdaptable[] tempElements = oldSet.getElements(); > IAdaptable[] adaptedProjects = oldSet.adaptElements(projects); >- IAdaptable[] finalElementList = new IAdaptable[tempElements.length + adaptedProjects.length]; >- System.arraycopy(tempElements, 0, finalElementList, 0, tempElements.length); >- System.arraycopy(adaptedProjects, 0,finalElementList, tempElements.length, adaptedProjects.length); >+ IAdaptable[] finalElementList = new IAdaptable[tempElements.length >+ + adaptedProjects.length]; >+ System.arraycopy(tempElements, 0, finalElementList, 0, >+ tempElements.length); >+ System.arraycopy(adaptedProjects, 0, finalElementList, >+ tempElements.length, adaptedProjects.length); > oldSet.setElements(finalElementList); >- } >+ } > } > } > } >Index: src/org/eclipse/team/internal/ui/wizards/ImportProjectSetStringOperation.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ui/wizards/ImportProjectSetStringOperation.java >diff -N src/org/eclipse/team/internal/ui/wizards/ImportProjectSetStringOperation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ui/wizards/ImportProjectSetStringOperation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,61 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ui.wizards; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.jface.operation.IRunnableContext; >+import org.eclipse.team.internal.ui.ProjectSetImporter; >+import org.eclipse.ui.IWorkingSet; >+ >+public class ImportProjectSetStringOperation extends ImportProjectSetOperation { >+ >+ private String psfFileContents; >+ private String urlString; >+ private IWorkingSet[] workingSets; >+ >+ >+ /** >+ * Operation for importing a Team Project Set stored in a String >+ * >+ * @param context >+ * a runnable context, <code>null</null> for running in background >+ * @param psfFileContents >+ * the psf file content to load >+ * @param workingSets >+ * an array of working sets where imported project should be >+ * added. If a working set doesn't exist it will be created. The >+ * array cannot be <code>null</code>, pass an empty array if you >+ * don't want to add projects to any working set. >+ */ >+ public ImportProjectSetStringOperation(IRunnableContext context, >+ String psfFileContents, IWorkingSet[] workingSets) { >+ super(context); >+ this.psfFileContents = psfFileContents; >+ this.workingSets = workingSets; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core >+ * .runtime.IProgressMonitor) >+ */ >+ public void run(IProgressMonitor monitor) throws InvocationTargetException, >+ InterruptedException { >+ IProject[] newProjects = ProjectSetImporter.importProjectSetFromString( >+ psfFileContents, urlString, getShell(), monitor); >+ createWorkingSet(workingSets, newProjects); >+ } >+} >Index: src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java,v >retrieving revision 1.19 >diff -u -r1.19 ProjectSetExportWizard.java >--- src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java 17 Oct 2007 15:19:54 -0000 1.19 >+++ src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java 20 Sep 2010 15:21:30 -0000 >@@ -59,7 +59,7 @@ > if (path.getFileExtension() == null) { > filename = filename + ".psf"; //$NON-NLS-1$ > } >- PsfFilenameStore.remember(filename); >+ PsfFilenameStore.getInstance().remember(filename); > File file = new File(filename); > File parentFile = file.getParentFile(); > if (parentFile != null && !parentFile.exists()) { >Index: src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java,v >retrieving revision 1.23 >diff -u -r1.23 ProjectSetImportWizard.java >--- src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java 27 Feb 2008 12:12:54 -0000 1.23 >+++ src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java 20 Sep 2010 15:21:30 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -40,9 +40,20 @@ > public boolean performFinish() { > final boolean[] result = new boolean[] {false}; > try { >- ImportProjectSetOperation op = new ImportProjectSetOperation( >- mainPage.isRunInBackgroundOn() ? null : getContainer(), >- mainPage.getFileName(), mainPage.getWorkingSets()); >+ ImportProjectSetOperation op; >+ if (mainPage.getInputType() == ImportProjectSetMainPage.InputType_URL) { >+ String psfContent = mainPage.getURLContents(); >+ if(psfContent==null){ >+ return false; >+ } >+ op = new ImportProjectSetStringOperation( >+ mainPage.isRunInBackgroundOn() ? null : getContainer(), >+ psfContent, mainPage.getWorkingSets()); >+ } else { >+ op = new ImportFromFileProjectSetOperation( >+ mainPage.isRunInBackgroundOn() ? null : getContainer(), >+ mainPage.getFileName(), mainPage.getWorkingSets()); >+ } > op.run(); > result[0] = true; > } catch (InterruptedException e) { >@@ -71,6 +82,6 @@ > public void init(IWorkbench workbench, IStructuredSelection selection) { > // The code that finds "selection" is broken (it is always empty), so we > // must dig for the selection in the workbench. >- PsfFilenameStore.setDefaultFromSelection(workbench); >+ PsfFilenameStore.getInstance().setDefaultFromSelection(workbench); > } > } >Index: src/org/eclipse/team/internal/ui/wizards/PsfFilenameStore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/PsfFilenameStore.java,v >retrieving revision 1.1 >diff -u -r1.1 PsfFilenameStore.java >--- src/org/eclipse/team/internal/ui/wizards/PsfFilenameStore.java 20 Sep 2005 17:17:35 -0000 1.1 >+++ src/org/eclipse/team/internal/ui/wizards/PsfFilenameStore.java 20 Sep 2010 15:21:30 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >+ * Copyright (c) 2005, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,27 +10,16 @@ > *******************************************************************************/ > package org.eclipse.team.internal.ui.wizards; > >-import java.util.Vector; >- > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.runtime.IAdaptable; > import org.eclipse.core.runtime.IPath; >-import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.IStructuredSelection; >-import org.eclipse.team.internal.ui.TeamUIPlugin; >-import org.eclipse.ui.IWorkbench; >-import org.eclipse.ui.IWorkbenchPage; >-import org.eclipse.ui.IWorkbenchWindow; >- >-public class PsfFilenameStore { >- // Most recently used filename is first in the array. >- // Least recently used filename is at the end of the list. >- // When the list overflows, items drop off the end. >- private static final int HISTORY_LENGTH = 10; >+import org.eclipse.ui.*; >+ >+public class PsfFilenameStore extends PsfStore { > >- private static final String STORE_SECTION = "ImportPSFDialog"; //$NON-NLS-1$ > private static final String FILENAMES = "filenames"; //$NON-NLS-1$ > private static final String PREVIOUS = "previous"; //$NON-NLS-1$ > >@@ -38,13 +27,20 @@ > // This is only a cache; it is not part of the history until the user has used it. > private static String _selectedFilename = null; > >- private static IDialogSettings _section; >+ private static PsfFilenameStore instance; >+ >+ public static PsfFilenameStore getInstance(){ >+ if(instance==null){ >+ instance = new PsfFilenameStore(); >+ } >+ return instance; >+ } > > private PsfFilenameStore() { >- // All-static >+ // Signleton > } > >- public static void setDefaultFromSelection(IWorkbench workbench) { >+ public void setDefaultFromSelection(IWorkbench workbench) { > // Scan the workbench for a selected PSF file > IWorkbenchWindow wnd = workbench.getActiveWorkbenchWindow(); > IWorkbenchPage pg = wnd.getActivePage(); >@@ -85,73 +81,20 @@ > _selectedFilename = path.toOSString(); > } > >- public static String getSuggestedDefault() { >+ public String getSuggestedDefault() { > if (_selectedFilename != null) { > return _selectedFilename; > } > return getPrevious(); > } > >- private static String getPrevious() { >- IDialogSettings section = getSettingsSection(); >- String retval = section.get(PREVIOUS); >- if (retval == null) { >- retval = ""; //$NON-NLS-1$ >- } >- return retval; >+ protected String getPreviousTag() { >+ return PREVIOUS; > } > >- public static String[] getHistory() { >- IDialogSettings section = getSettingsSection(); >- String[] arr = section.getArray(FILENAMES); >- if (arr == null) { >- arr = new String[0]; >- } >- return arr; >+ protected String getListTag() { >+ return FILENAMES; > } > >- public static void remember(String filename) { >- Vector filenames = createVector(getHistory()); >- if (filenames.contains(filename)) { >- // The item is in the list. Remove it and add it back at the >- // beginning. If it already was at the beginning this will be a >- // waste of time, but it's not even measurable so I don't care. >- filenames.remove(filename); >- } >- // Most recently used filename goes to the beginning of the list >- filenames.add(0, filename); >- >- // Forget any overflowing items >- while (filenames.size() > HISTORY_LENGTH) { >- filenames.remove(HISTORY_LENGTH); >- } >- >- // Make it an array >- String[] arr = (String[]) filenames.toArray(new String[filenames.size()]); >- >- IDialogSettings section = getSettingsSection(); >- section.put(FILENAMES, arr); >- section.put(PREVIOUS, filename); >- } >- >- private static Vector createVector(Object[] arr) { >- Vector v = new Vector(); >- for (int ix = 0; ix < arr.length; ++ix) { >- v.add(ix, arr[ix]); >- } >- return v; >- } >- >- private static IDialogSettings getSettingsSection() { >- if (_section != null) >- return _section; >- >- IDialogSettings settings = TeamUIPlugin.getPlugin().getDialogSettings(); >- _section = settings.getSection(STORE_SECTION); >- if (_section != null) >- return _section; >- >- _section = settings.addNewSection(STORE_SECTION); >- return _section; >- } >+ > } >Index: src/org/eclipse/team/internal/ui/wizards/PsfStore.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ui/wizards/PsfStore.java >diff -N src/org/eclipse/team/internal/ui/wizards/PsfStore.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ui/wizards/PsfStore.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,95 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ui.wizards; >+ >+import java.util.Vector; >+ >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.team.internal.ui.TeamUIPlugin; >+ >+public abstract class PsfStore { >+ // Most recently used filename is first in the array. >+ // Least recently used filename is at the end of the list. >+ // When the list overflows, items drop off the end. >+ private static final int HISTORY_LENGTH = 10; >+ >+ private static final String STORE_SECTION = "ImportPSFDialog"; //$NON-NLS-1$ >+ >+ private static IDialogSettings _section; >+ >+ protected abstract String getPreviousTag(); >+ protected abstract String getListTag(); >+ >+ public abstract String getSuggestedDefault(); >+ >+ protected String getPrevious() { >+ IDialogSettings section = getSettingsSection(); >+ String retval = section.get(getPreviousTag()); >+ if (retval == null) { >+ retval = ""; //$NON-NLS-1$ >+ } >+ return retval; >+ } >+ >+ public String[] getHistory() { >+ IDialogSettings section = getSettingsSection(); >+ String[] arr = section.getArray(getListTag()); >+ if (arr == null) { >+ arr = new String[0]; >+ } >+ return arr; >+ } >+ >+ public void remember(String filename) { >+ Vector filenames = createVector(getHistory()); >+ if (filenames.contains(filename)) { >+ // The item is in the list. Remove it and add it back at the >+ // beginning. If it already was at the beginning this will be a >+ // waste of time, but it's not even measurable so I don't care. >+ filenames.remove(filename); >+ } >+ // Most recently used filename goes to the beginning of the list >+ filenames.add(0, filename); >+ >+ // Forget any overflowing items >+ while (filenames.size() > HISTORY_LENGTH) { >+ filenames.remove(HISTORY_LENGTH); >+ } >+ >+ // Make it an array >+ String[] arr = (String[]) filenames.toArray(new String[filenames.size()]); >+ >+ IDialogSettings section = getSettingsSection(); >+ section.put(getListTag(), arr); >+ section.put(getPreviousTag(), filename); >+ } >+ >+ private Vector createVector(Object[] arr) { >+ Vector v = new Vector(); >+ for (int ix = 0; ix < arr.length; ++ix) { >+ v.add(ix, arr[ix]); >+ } >+ return v; >+ } >+ >+ private IDialogSettings getSettingsSection() { >+ if (_section != null) >+ return _section; >+ >+ IDialogSettings settings = TeamUIPlugin.getPlugin().getDialogSettings(); >+ _section = settings.getSection(STORE_SECTION); >+ if (_section != null) >+ return _section; >+ >+ _section = settings.addNewSection(STORE_SECTION); >+ return _section; >+ } >+} >Index: src/org/eclipse/team/internal/ui/wizards/PsfUrlStore.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ui/wizards/PsfUrlStore.java >diff -N src/org/eclipse/team/internal/ui/wizards/PsfUrlStore.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ui/wizards/PsfUrlStore.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,47 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ui.wizards; >+ >+/** >+ * Stores URL history for importing project sets window. >+ * >+ */ >+public class PsfUrlStore extends PsfStore { >+ >+ private static final String URLS = "urls"; //$NON-NLS-1$ >+ private static final String PREVIOUS = "previous_url"; //$NON-NLS-1$ >+ >+ private static PsfUrlStore instance; >+ >+ public static PsfUrlStore getInstance() { >+ if (instance == null) { >+ instance = new PsfUrlStore(); >+ } >+ return instance; >+ } >+ >+ private PsfUrlStore() { >+ // signleton >+ } >+ >+ protected String getPreviousTag() { >+ return PREVIOUS; >+ } >+ >+ protected String getListTag() { >+ return URLS; >+ } >+ >+ public String getSuggestedDefault() { >+ return getPrevious(); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 162608
:
56177
|
56178
|
179256
|
179298
|
179300
|
179444
|
179445