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 179444 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]
Some more corrections
patch_162608.txt (text/plain), 44.20 KB, created by
Malgorzata Janczarska
on 2010-09-23 06:57:25 EDT
(
hide
)
Description:
Some more corrections
Filename:
MIME Type:
Creator:
Malgorzata Janczarska
Created:
2010-09-23 06:57:25 EDT
Size:
44.20 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.compare >Index: compare/org/eclipse/compare/internal/Utilities.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java,v >retrieving revision 1.71 >diff -u -r1.71 Utilities.java >--- compare/org/eclipse/compare/internal/Utilities.java 21 Jan 2010 11:33:26 -0000 1.71 >+++ compare/org/eclipse/compare/internal/Utilities.java 23 Sep 2010 10:56:17 -0000 >@@ -18,6 +18,8 @@ > import java.io.UnsupportedEncodingException; > import java.lang.reflect.InvocationTargetException; > import java.lang.reflect.Method; >+import java.net.SocketTimeoutException; >+import java.net.URL; > import java.net.URLConnection; > import java.util.ArrayList; > import java.util.HashMap; >@@ -36,6 +38,7 @@ > import org.eclipse.compare.SharedDocumentAdapter; > import org.eclipse.compare.contentmergeviewer.IDocumentRange; > import org.eclipse.compare.internal.core.patch.HunkResult; >+import org.eclipse.compare.internal.patch.PatchMessages; > import org.eclipse.compare.patch.IHunk; > import org.eclipse.compare.structuremergeviewer.DiffNode; > import org.eclipse.compare.structuremergeviewer.ICompareInput; >@@ -64,6 +67,8 @@ > import org.eclipse.core.runtime.jobs.Job; > import org.eclipse.jface.action.IAction; > import org.eclipse.jface.dialogs.ErrorDialog; >+import org.eclipse.jface.operation.IRunnableContext; >+import org.eclipse.jface.operation.IRunnableWithProgress; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.text.IDocument; > import org.eclipse.jface.util.IPropertyChangeListener; >@@ -861,4 +866,52 @@ > } > return false; > } >+ >+ /** >+ * Load content of file under <code>url</code> displaying progress on given >+ * context. >+ * >+ * @param url >+ * @param context >+ * @return the content of file under given URL, or <code>null</code> if URL >+ * could not be loaded >+ * @throws InvocationTargetException >+ * thrown on errors while URL loading >+ * @throws OperationCanceledException >+ * @throws InterruptedException >+ */ >+ public static String getURLContents(final URL url, IRunnableContext context) >+ throws InvocationTargetException, OperationCanceledException, >+ InterruptedException { >+ final String[] result = new String[1]; >+ context.run(true, true, new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ SubMonitor progress = SubMonitor.convert(monitor, >+ PatchMessages.InputPatchPage_URLConnecting, 100); >+ try { >+ URLConnection connection = url.openConnection(); >+ progress.worked(10); >+ if (monitor.isCanceled()) >+ throw new OperationCanceledException(); >+ setReadTimeout(connection, 60 * 1000); >+ progress.setTaskName(PatchMessages.InputPatchPage_URLFetchingContent); >+ String enc = connection.getContentEncoding(); >+ if (enc == null) >+ enc = ResourcesPlugin.getEncoding(); >+ result[0] = Utilities.readString( >+ connection.getInputStream(), enc, >+ connection.getContentLength(), >+ progress.newChild(90)); >+ } catch (SocketTimeoutException e) { >+ throw new InvocationTargetException(e); >+ } catch (IOException e) { >+ throw new InvocationTargetException(e); >+ } finally { >+ monitor.done(); >+ } >+ } >+ }); >+ return result[0]; >+ } > } >Index: compare/org/eclipse/compare/internal/patch/InputPatchPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java,v >retrieving revision 1.48 >diff -u -r1.48 InputPatchPage.java >--- compare/org/eclipse/compare/internal/patch/InputPatchPage.java 24 May 2010 11:57:08 -0000 1.48 >+++ compare/org/eclipse/compare/internal/patch/InputPatchPage.java 23 Sep 2010 10:56:18 -0000 >@@ -21,9 +21,7 @@ > import java.io.StringReader; > import java.lang.reflect.InvocationTargetException; > import java.net.MalformedURLException; >-import java.net.SocketTimeoutException; > import java.net.URL; >-import java.net.URLConnection; > > import org.eclipse.compare.internal.ICompareContextIds; > import org.eclipse.compare.internal.Utilities; >@@ -34,15 +32,12 @@ > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.OperationCanceledException; > import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.SubMonitor; > import org.eclipse.jface.dialogs.Dialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.dialogs.MessageDialog; >-import org.eclipse.jface.operation.IRunnableWithProgress; > import org.eclipse.jface.viewers.DoubleClickEvent; > import org.eclipse.jface.viewers.IDoubleClickListener; > import org.eclipse.jface.viewers.ISelection; >@@ -264,9 +259,17 @@ > } else if (inputMethod==URL) { > String patchFileURL = fPatchURLField.getText(); > if (patchFileURL != null) { >- String contents = getURLContents(patchFileURL); >- if (contents != null) >- reader = new StringReader(contents); >+ try { >+ String contents = Utilities.getURLContents(new URL( >+ patchFileURL), getContainer()); >+ if (contents != null) >+ reader = new StringReader(contents); >+ } catch (MalformedURLException e) { >+ // ignore as we tested it with modify listener on combo >+ } catch (InvocationTargetException e) { // ignore >+ } catch (OperationCanceledException e) { // ignore >+ } catch (InterruptedException e) { // ignore >+ } > } > fPatchSource= PatchMessages.InputPatchPage_URL_title; > } else if (inputMethod==WORKSPACE) { >@@ -307,43 +310,6 @@ > } > } > } >- >- private String getURLContents(String patchFileURL) { >- final URL url; >- try { >- url = new URL(patchFileURL); >- 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, PatchMessages.InputPatchPage_URLConnecting, 100); >- try { >- URLConnection connection = url.openConnection(); >- progress.worked(10); >- if (monitor.isCanceled()) >- throw new OperationCanceledException(); >- Utilities.setReadTimeout(connection, 60*1000); >- progress.setTaskName(PatchMessages.InputPatchPage_URLFetchingContent); >- String enc = connection.getContentEncoding(); >- if (enc == null) >- enc = ResourcesPlugin.getEncoding(); >- result[0] = Utilities.readString(connection.getInputStream(), enc, connection.getContentLength(), progress.newChild(90)); >- } catch (SocketTimeoutException e) { // timeout >- } catch (IOException e) { //ignore >- } >- monitor.done(); >- } >- }); >- return result[0]; >- } catch (OperationCanceledException e) { //ignore >- } catch (InvocationTargetException e) { //ignore >- } catch (InterruptedException e) { //ignore >- } >- } catch (MalformedURLException e) { >- // ignore as we tested it with modify listener on combo >- } >- return null; >- } > > /* (non-JavaDoc) > * Method declared in IWizardPage. >#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 23 Sep 2010 10:56:19 -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,10 +30,47 @@ > 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(); >@@ -179,7 +216,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,7 +245,24 @@ > 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(); >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 23 Sep 2010 10:56:19 -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,7 @@ > 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 information; > >@@ -310,8 +313,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 +323,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 23 Sep 2010 10:56:20 -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,7 @@ > ImportProjectSetDialog_duplicatedWorkingSet_merge=&Merge > ImportProjectSetDialog_duplicatedWorkingSet_skip=&Skip > ImportProjectSetDialog_duplicatedWorkingSet_applyToAll=&Apply to all working sets in this import >+ImportProjectSetDialog_malformed_url=Malformed 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/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 23 Sep 2010 10:56:20 -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/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 23 Sep 2010 10:56:20 -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 >@@ -11,12 +11,19 @@ > package org.eclipse.team.internal.ui.wizards; > > import java.io.File; >+import java.lang.reflect.InvocationTargetException; >+import java.net.MalformedURLException; >+import java.net.URL; > >+import org.eclipse.compare.internal.Utilities; > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.OperationCanceledException; > import org.eclipse.jface.dialogs.Dialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.swt.SWT; >+import org.eclipse.swt.dnd.Clipboard; >+import org.eclipse.swt.dnd.TextTransfer; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.layout.GridData; >@@ -32,14 +39,49 @@ > 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; > >- public ImportProjectSetMainPage(String pageName, String title, ImageDescriptor titleImage) { >+ 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); >+ setDescription(TeamUIMessages.ImportProjectSetMainPage_description); >+ } >+ >+ private void setInputType(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(); >+ > } > > /* >@@ -60,21 +102,52 @@ > 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) { >+ setInputType(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) { >+ setInputType(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,12 +188,33 @@ > }); > > setControl(composite); >- updateEnablement(); >+ setDefaultInputType(); > Dialog.applyDialogFont(parent); >- // future messages will be of type error >- messageType = ERROR; > } > >+ private void setDefaultInputType() { >+ // check for clipboard contents >+ Control c = getControl(); >+ if (c != null) { >+ Clipboard clipboard = new Clipboard(c.getDisplay()); >+ Object o = clipboard.getContents(TextTransfer.getInstance()); >+ clipboard.dispose(); >+ if (o instanceof String) { >+ try { >+ URL url = new URL((String) o); >+ if (url != null) { >+ setInputType(InputType_URL); >+ urlCombo.setText((String) o); >+ return; >+ } >+ } catch (MalformedURLException e) { >+ // ignore, it's not and URL >+ } >+ } >+ } >+ setInputType(InputType_file); >+ } >+ > private void addWorkingSetSection(Composite composite) { > workingSetGroup = new WorkingSetGroup( > composite, >@@ -129,9 +223,41 @@ > "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 +267,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; >@@ -168,6 +297,10 @@ > return file; > } > >+ public String getUrl() { >+ return urlString; >+ } >+ > public void setVisible(boolean visible) { > super.setVisible(visible); > if (visible) { >@@ -193,4 +326,37 @@ > public boolean isRunInBackgroundOn() { > return runInBackground; > } >+ >+ public int getInputType() { >+ return inputType; >+ } >+ >+ public String getURLContents() { >+ try { >+ PsfUrlStore.getInstance().remember(urlString); >+ String urlContent = Utilities.getURLContents(new URL(urlString), >+ getContainer()); >+ if (ProjectSetImporter.isValidProjectSetString(urlContent)) { >+ return urlContent; >+ } else { >+ messageType = ERROR; >+ setMessage( >+ TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, >+ messageType); >+ setPageComplete(false); >+ return null; >+ } >+ } catch (OperationCanceledException e) { // ignore >+ } catch (InterruptedException e) { // ignore >+ } catch (InvocationTargetException e) { >+ messageType = ERROR; >+ setMessage( >+ TeamUIMessages.ImportProjectSetMainPage_The_given_URL_cannot_be_loaded, >+ messageType); >+ setPageComplete(false); >+ } catch (MalformedURLException e) { >+ // ignore as we tested it with modify listener on combo >+ } >+ return null; >+ } > } >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 23 Sep 2010 10:56:20 -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 >@@ -22,9 +22,36 @@ > import org.eclipse.ui.IWorkingSetManager; > > public class ImportProjectSetOperation extends TeamOperation { >- >+ >+ private String psfFileContents; >+ private String urlString; > private String psfFile; > 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 urlString >+ * url or path to file loaded into <code>psfFileContents</code> >+ * @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 psfFileContents, String urlString, IWorkingSet[] workingSets) { >+ super(context); >+ this.psfFileContents = psfFileContents; >+ this.workingSets = workingSets; >+ this.urlString = urlString; >+ } > > /** > * Operation for importing a Team Project Set file >@@ -45,18 +72,32 @@ > this.psfFile = psfFile; > this.workingSets = workingSets; > } >+ >+ private void runForStringContent(IProgressMonitor monitor) throws InvocationTargetException{ >+ IProject[] newProjects = ProjectSetImporter.importProjectSetFromString( >+ psfFileContents, urlString, getShell(), monitor); >+ createWorkingSet(workingSets, newProjects); >+ } >+ >+ private void runForFile(IProgressMonitor monitor) throws InvocationTargetException{ >+ PsfFilenameStore.getInstance().remember(psfFile); >+ IProject[] newProjects = ProjectSetImporter.importProjectSet(psfFile, >+ getShell(), monitor); >+ createWorkingSet(workingSets, newProjects); >+ } > > /* > * (non-Javadoc) > * > * @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 void run(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException{ >+ if(psfFileContents!=null){ >+ runForStringContent(monitor); >+ }else{ >+ runForFile(monitor); >+ } > } > > /* >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 23 Sep 2010 10:56:20 -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 23 Sep 2010 10:56:20 -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 ImportProjectSetOperation( >+ mainPage.isRunInBackgroundOn() ? null : getContainer(), >+ psfContent, mainPage.getUrl(), mainPage.getWorkingSets()); >+ } else { >+ op = new ImportProjectSetOperation( >+ 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 23 Sep 2010 10:56:20 -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 >+ // Singleton > } > >- 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() { >+ // Singleton >+ } >+ >+ 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