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 98036 Details for
Bug 166025
Move, Copy, Delete, Rename and Import/Export test assets.
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]
fix for external copy paste
166025_fix_external_copy_paste.txt (text/plain), 13.24 KB, created by
Bozier jerome
on 2008-04-29 14:14:29 EDT
(
hide
)
Description:
fix for external copy paste
Filename:
MIME Type:
Creator:
Bozier jerome
Created:
2008-04-29 14:14:29 EDT
Size:
13.24 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.hyades.test.ui >Index: src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteRefactoring.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteRefactoring.java,v >retrieving revision 1.1 >diff -u -r1.1 PasteRefactoring.java >--- src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteRefactoring.java 20 Mar 2008 19:49:52 -0000 1.1 >+++ src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteRefactoring.java 29 Apr 2008 18:12:22 -0000 >@@ -40,7 +40,7 @@ > /** > * refactoring for paste > * @author Jerome Bozier >- * @version February 26, 2008 >+ * @version April 29, 2008 > * @since 4.5 > */ > >@@ -51,13 +51,15 @@ > protected List seenElements; > private List folders; > private List proxies; >+ private List externalFiles; > >- public PasteRefactoring(List folders, List proxies) { >+ public PasteRefactoring(List folders, List proxies,List externalFiles) { > super(); > this.seenElements = new LinkedList(); > this.context = new RefactoringContext(); > this.folders = folders; > this.proxies = proxies; >+ this.externalFiles = externalFiles; > } > > public List getContainers() { >@@ -110,7 +112,7 @@ > if (change != null) { > return change; > } >- pm.beginTask("", folders.size() + proxies.size()); //$NON-NLS-1$ >+ pm.beginTask("", folders.size() + proxies.size()+externalFiles.size()); //$NON-NLS-1$ > try { > RefactoringTransactionRootChange c = new RefactoringTransactionRootChange(context); > for (Iterator it = folders.iterator(); it.hasNext();) { >@@ -127,6 +129,14 @@ > } > pm.worked(1); > } >+ for (Iterator it = externalFiles.iterator(); it.hasNext();) { >+ Change refChange = new PasteFileChange((String) it.next(), destination); >+ if (refChange != null) { >+ c.add(refChange); >+ } >+ pm.worked(1); >+ } >+ > c.markAsSynthetic(); > return c; > } finally { >Index: src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFileChange.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFileChange.java,v >retrieving revision 1.1 >diff -u -r1.1 PasteFileChange.java >--- src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFileChange.java 20 Mar 2008 19:49:52 -0000 1.1 >+++ src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFileChange.java 29 Apr 2008 18:12:22 -0000 >@@ -11,6 +11,12 @@ > **********************************************************************/ > package org.eclipse.hyades.test.ui.internal.navigator.refactoring; > >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileNotFoundException; >+import java.io.IOException; >+import java.io.InputStream; >+ > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IWorkspaceRoot; >@@ -30,28 +36,46 @@ > /** > * change to apply to perform a file paste > * @author Jerome Bozier >- * @version February 26, 2008 >+ * @version April 29, 2008 > * @since 4.5 > */ > public class PasteFileChange extends Change { > >- private IFile file; >+ private IFile file = null; > private IContainer destFolder; > private String destName = null; >+ private String externalBaseName = null; >+ private String externalFileName = null; > >+ // constructor for workspace files > public PasteFileChange(IFile file, IContainer destination) { > super(); > this.file = file; > this.destFolder = destination; >+ this.externalFileName = null; > this.destName = getNewName(destFolder.getFullPath().append(file.getName())); > } > >+ // constructor for external file >+ public PasteFileChange(String externalFileName, IContainer destination) { >+ super(); >+ this.file = null; >+ this.destFolder = destination; >+ this.externalFileName = externalFileName; >+ this.externalBaseName = new Path(externalFileName).lastSegment(); >+ this.destName = getNewName(destFolder.getFullPath().append(externalBaseName)); >+ } >+ > public Object getModifiedElement() { > return file; > } > > public String getName() { >- return NLS.bind(RefactoringMessages.PASTE_FILE, file.getName(), destName); >+ if (file != null) { >+ return NLS.bind(RefactoringMessages.PASTE_FILE, file.getName(), destName); >+ } else { >+ return NLS.bind(RefactoringMessages.PASTE_FILE, externalBaseName, destName); >+ } > } > > public void initializeValidationData(IProgressMonitor pm) { >@@ -59,8 +83,15 @@ > > public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { > RefactoringStatus status = new RefactoringStatus(); >- if (!file.exists()) { >- status.addError(RefactoringMessages.NO_FILE); >+ if (file != null) { >+ if (!file.exists()) { >+ status.addError(RefactoringMessages.NO_FILE); >+ } >+ } else { >+ File tmp = new File(externalFileName); >+ if (!tmp.exists()) { >+ status.addError(RefactoringMessages.NO_FILE); >+ } > } > return status; > } >@@ -97,13 +128,28 @@ > Change undo = null; > pm.beginTask("", 1); //$NON-NLS-1$ > try { >- IContainer parent = file.getParent(); >- file.copy(new Path(destName), false, pm); >- if (parent != null) { >- IFile destFile = destFolder.getFile(new Path(destName)); >- undo = new DeleteFileChange(destFile); >+ if (file != null) { // eclipse copy >+ IContainer parent = file.getParent(); >+ file.copy(new Path(destName), false, pm); >+ if (parent != null) { >+ IFile destFile = destFolder.getFile(new Path(destName)); >+ undo = new DeleteFileChange(destFile); >+ } >+ file.refreshLocal(0, pm); >+ } else { >+ IFile file = destFolder.getFile(new Path(new Path(destName).lastSegment())); >+ try { >+ InputStream source = new FileInputStream(externalFileName); >+ if( file.exists() ) { // should not occur >+ file.setContents( source, true, false, null ); >+ } else { >+ file.create( source, true, null ); >+ } >+ source.close(); >+ } catch (FileNotFoundException e) { >+ } catch (IOException e) { >+ } > } >- file.refreshLocal(0, pm); > pm.worked(1); > return undo; > } finally { >Index: src/org/eclipse/hyades/test/ui/internal/navigator/action/FileAndFolderPaster.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/navigator/action/FileAndFolderPaster.java,v >retrieving revision 1.2 >diff -u -r1.2 FileAndFolderPaster.java >--- src/org/eclipse/hyades/test/ui/internal/navigator/action/FileAndFolderPaster.java 11 Apr 2008 14:34:05 -0000 1.2 >+++ src/org/eclipse/hyades/test/ui/internal/navigator/action/FileAndFolderPaster.java 29 Apr 2008 18:12:22 -0000 >@@ -17,7 +17,9 @@ > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IFolder; > import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.IAdaptable; >+import org.eclipse.core.runtime.Path; > import org.eclipse.hyades.test.ui.UiPlugin; > import org.eclipse.hyades.test.ui.internal.navigator.action.resources.ActionMessages; > import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache; >@@ -27,16 +29,18 @@ > import org.eclipse.hyades.test.ui.navigator.IProxyNode; > import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; > import org.eclipse.swt.dnd.Clipboard; >+import org.eclipse.swt.dnd.FileTransfer; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.ui.part.ResourceTransfer; > /** > * @author Jerome Bozier >- * @version February 26, 2008 >+ * @version April 29, 2008 > */ > public class FileAndFolderPaster implements IPasterExtended { > > private LinkedList folders; > private LinkedList proxies; >+ private LinkedList externalFiles; > private Clipboard clipboard; > private Shell shell; > >@@ -44,6 +48,7 @@ > folders = new LinkedList(); > clipboard = null; > proxies = new LinkedList(); >+ externalFiles = new LinkedList(); > shell = null; > } > >@@ -55,10 +60,15 @@ > this.shell = shell; > } > >- private void sortClipboardElements() { >+ private void sortClipboardElements(Object selection) { > folders.clear(); > proxies.clear(); >- IResource [] res = getResourceFromClipboard(); >+ externalFiles.clear(); >+ IContainer container = null; >+ if (selection instanceof IContainer) { >+ container = (IContainer)selection; >+ } >+ IResource [] res = getResourceFromClipboard(container); > if (res == null) { > return; > } >@@ -79,13 +89,30 @@ > } > > >- private IResource [] getResourceFromClipboard() { >+ private IResource [] getResourceFromClipboard(final IContainer container) { > final IResource[][] clipboardData = new IResource[1][]; > shell.getDisplay().syncExec(new Runnable() { > public void run() { > //- clipboard must have resources or files > ResourceTransfer resTransfer = ResourceTransfer.getInstance(); >+ // first case : copied inside eclipse > clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer); >+ if (clipboardData[0] == null) { >+ // second case : copied outside eclipse >+ FileTransfer transfer = FileTransfer.getInstance(); >+ String[] res = (String [])clipboard.getContents(transfer); >+ IResource[] res2 = new IResource[res.length]; >+ for (int i=0; i<res.length; i++) { >+ // basic case : resource already inside workspace >+ Path path = new Path(res[i]); >+ res2[i] = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); >+ if (res2[i] == null) { >+ // annoying case : resource not inside workspace => add it to external files to be deal separately >+ externalFiles.add(res[i]); >+ } >+ } >+ clipboardData[0] = res2; >+ } > } > }); > return clipboardData[0]; >@@ -99,8 +126,8 @@ > if (! canActivate(shell)) > return false; > this.clipboard = clipboard; >- sortClipboardElements(); >- PasteRefactoring refactoring = new PasteRefactoring(folders,proxies); >+ sortClipboardElements(selection); >+ PasteRefactoring refactoring = new PasteRefactoring(folders,proxies,externalFiles); > PasteRefactoringWizard wizard = new PasteRefactoringWizard(refactoring,selection); > wizard.setDefaultPageTitle(ActionMessages.PASTE_ACTION_NAME); > wizard.setNeedsProgressMonitor(true); >Index: src/org/eclipse/hyades/test/ui/internal/util/ReferenceDisplayUtils.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/ui/internal/util/ReferenceDisplayUtils.java >diff -N src/org/eclipse/hyades/test/ui/internal/util/ReferenceDisplayUtils.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/ui/internal/util/ReferenceDisplayUtils.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,67 @@ >+/********************************************************************** >+ * Copyright (c) 2008 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ **********************************************************************/ >+package org.eclipse.hyades.test.ui.internal.util; >+ >+import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceTypeRegistry; >+ >+public class ReferenceDisplayUtils { >+ private static final String basis = "--";//$NON-NLS-1$ >+ private static final String owned = "==";//$NON-NLS-1$ >+ private static final String opposite = "<";//$NON-NLS-1$ >+ private static final String direct = ">";//$NON-NLS-1$ >+ private static final String implicitStart = "[";//$NON-NLS-1$ >+ private static final String implicitEnd = "]";//$NON-NLS-1$ >+ private static ReferenceTypeRegistry factory = ReferenceTypeRegistry.getInstance(); >+ >+ /** >+ * return a readable representation of a reference based on its type : >+ * --> explicit direct link >+ * <-- explicit opposite link >+ * ==> "owns" link >+ * [-->] implicit link >+ * @param type : type of the reference >+ * @return : a readable representation of a reference based on its type >+ */ >+ public static String referenceToString(String type ) { >+ StringBuffer buff = new StringBuffer(); >+ String oppositeRef = factory.getOppositeReferenceType(type); >+ if (oppositeRef != null) { >+ boolean implicit = (!factory.isExplicit(oppositeRef)); >+ if (implicit) { >+ buff.append(implicitStart); >+ } >+ buff.append(opposite); >+ if (factory.owns(oppositeRef)) { >+ buff.append(owned); >+ } else { >+ buff.append(basis); >+ } >+ if (implicit) { >+ buff.append(implicitEnd); >+ } >+ } >+ boolean implicit = (!factory.isExplicit(type)); >+ if (implicit) { >+ buff.append(implicitStart); >+ } >+ if (factory.owns(type)) { >+ buff.append(owned); >+ } else { >+ buff.append(basis); >+ } >+ if (implicit) { >+ buff.append(implicitEnd); >+ } >+ buff.append(direct); >+ return buff.toString(); >+ } >+}
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 166025
:
86571
|
86939
|
87044
|
88264
|
88300
|
88607
|
90738
|
90861
|
91404
|
92336
|
92365
|
92366
|
92444
|
92684
|
92820
|
93654
|
95363
|
95370
|
96228
|
96287
|
96841
|
96860
|
98036