Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 166025 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteRefactoring.java (-3 / +13 lines)
Lines 40-46 Link Here
40
/**
40
/**
41
 * refactoring for paste
41
 * refactoring for paste
42
 * @author Jerome Bozier
42
 * @author Jerome Bozier
43
 * @version February 26, 2008
43
 * @version April 29, 2008
44
 * @since 4.5
44
 * @since 4.5
45
 */
45
 */
46
46
Lines 51-63 Link Here
51
	protected List seenElements;
51
	protected List seenElements;
52
	private List folders; 
52
	private List folders; 
53
	private List proxies; 
53
	private List proxies; 
54
	private List externalFiles; 	
54
55
55
	public PasteRefactoring(List folders, List proxies) {
56
	public PasteRefactoring(List folders, List proxies,List externalFiles) {
56
		super();
57
		super();
57
		this.seenElements = new LinkedList();
58
		this.seenElements = new LinkedList();
58
		this.context = new RefactoringContext();
59
		this.context = new RefactoringContext();
59
		this.folders = folders;
60
		this.folders = folders;
60
		this.proxies = proxies;
61
		this.proxies = proxies;
62
		this.externalFiles = externalFiles;
61
	}
63
	}
62
	
64
	
63
	public List getContainers() {
65
	public List getContainers() {
Lines 110-116 Link Here
110
		if (change != null) {
112
		if (change != null) {
111
			return change;
113
			return change;
112
		}
114
		}
113
		pm.beginTask("", folders.size() + proxies.size()); //$NON-NLS-1$ 
115
		pm.beginTask("", folders.size() + proxies.size()+externalFiles.size()); //$NON-NLS-1$ 
114
		try {
116
		try {
115
			RefactoringTransactionRootChange c = new RefactoringTransactionRootChange(context);
117
			RefactoringTransactionRootChange c = new RefactoringTransactionRootChange(context);
116
			for (Iterator it = folders.iterator(); it.hasNext();) {
118
			for (Iterator it = folders.iterator(); it.hasNext();) {
Lines 127-132 Link Here
127
				}
129
				}
128
				pm.worked(1);
130
				pm.worked(1);
129
			}
131
			}
132
			for (Iterator it = externalFiles.iterator(); it.hasNext();) {
133
				Change refChange = new PasteFileChange((String) it.next(), destination);
134
				if (refChange != null) {
135
					c.add(refChange);
136
				}
137
				pm.worked(1);
138
			}
139
			
130
			c.markAsSynthetic();
140
			c.markAsSynthetic();
131
			return c;
141
			return c;
132
		} finally {
142
		} finally {
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFileChange.java (-11 / +57 lines)
Lines 11-16 Link Here
11
 **********************************************************************/
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
13
14
import java.io.File;
15
import java.io.FileInputStream;
16
import java.io.FileNotFoundException;
17
import java.io.IOException;
18
import java.io.InputStream;
19
14
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IWorkspaceRoot;
22
import org.eclipse.core.resources.IWorkspaceRoot;
Lines 30-57 Link Here
30
/**
36
/**
31
 * change to apply to perform a file paste
37
 * change to apply to perform a file paste
32
 * @author Jerome Bozier
38
 * @author Jerome Bozier
33
 * @version February 26, 2008
39
 * @version April 29, 2008
34
 * @since 4.5
40
 * @since 4.5
35
 */
41
 */
36
public class PasteFileChange extends Change {
42
public class PasteFileChange extends Change {
37
43
38
	private IFile file;	
44
	private IFile file = null;	
39
	private IContainer destFolder;
45
	private IContainer destFolder;
40
	private String destName = null;
46
	private String destName = null;
47
	private String externalBaseName = null;
48
	private String externalFileName = null;
41
49
50
	// constructor for workspace files
42
	public PasteFileChange(IFile file, IContainer destination) {
51
	public PasteFileChange(IFile file, IContainer destination) {
43
		super();
52
		super();
44
		this.file = file;
53
		this.file = file;
45
		this.destFolder = destination;
54
		this.destFolder = destination;
55
		this.externalFileName = null;
46
		this.destName = getNewName(destFolder.getFullPath().append(file.getName()));
56
		this.destName = getNewName(destFolder.getFullPath().append(file.getName()));
47
	}
57
	}
48
58
59
	// constructor for external file
60
	public PasteFileChange(String externalFileName, IContainer destination) {
61
		super();
62
		this.file = null;
63
		this.destFolder = destination;
64
		this.externalFileName = externalFileName;
65
		this.externalBaseName = new Path(externalFileName).lastSegment();
66
		this.destName = getNewName(destFolder.getFullPath().append(externalBaseName));
67
	}
68
	
49
	public Object getModifiedElement() {
69
	public Object getModifiedElement() {
50
		return file;
70
		return file;
51
	}
71
	}
52
72
53
	public String getName() {
73
	public String getName() {
54
		return NLS.bind(RefactoringMessages.PASTE_FILE, file.getName(), destName);
74
		if (file != null) {
75
			return NLS.bind(RefactoringMessages.PASTE_FILE, file.getName(), destName);
76
		} else {
77
			return NLS.bind(RefactoringMessages.PASTE_FILE, externalBaseName, destName);
78
		}
55
	}
79
	}
56
80
57
	public void initializeValidationData(IProgressMonitor pm) {
81
	public void initializeValidationData(IProgressMonitor pm) {
Lines 59-66 Link Here
59
83
60
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
84
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
61
		RefactoringStatus status = new RefactoringStatus();
85
		RefactoringStatus status = new RefactoringStatus();
62
		if (!file.exists()) {
86
		if (file != null) {
63
			status.addError(RefactoringMessages.NO_FILE);
87
			if (!file.exists()) {
88
				status.addError(RefactoringMessages.NO_FILE);
89
			}
90
		} else {
91
			File tmp = new File(externalFileName);
92
			if (!tmp.exists()) {
93
				status.addError(RefactoringMessages.NO_FILE);
94
			}
64
		}
95
		}
65
		return status;
96
		return status;
66
	}
97
	}
Lines 97-109 Link Here
97
		Change undo = null;
128
		Change undo = null;
98
		pm.beginTask("", 1);  //$NON-NLS-1$
129
		pm.beginTask("", 1);  //$NON-NLS-1$
99
		try {
130
		try {
100
			IContainer parent = file.getParent();
131
			if (file != null) { // eclipse copy
101
			file.copy(new Path(destName), false, pm);
132
				IContainer parent = file.getParent();
102
			if (parent != null) {
133
				file.copy(new Path(destName), false, pm);
103
				IFile destFile = destFolder.getFile(new Path(destName));
134
				if (parent != null) {
104
				undo = new DeleteFileChange(destFile);
135
					IFile destFile = destFolder.getFile(new Path(destName));
136
					undo = new DeleteFileChange(destFile);
137
				}
138
				file.refreshLocal(0, pm);
139
			} else {
140
				IFile file = destFolder.getFile(new Path(new Path(destName).lastSegment()));								
141
				try {
142
					InputStream source = new FileInputStream(externalFileName);
143
					if( file.exists() ) { // should not occur
144
						file.setContents( source, true, false, null );
145
					} else {
146
						file.create( source, true, null );
147
					}
148
					source.close();
149
				} catch (FileNotFoundException e) {
150
				} catch (IOException e) {
151
				}
105
			}
152
			}
106
			file.refreshLocal(0, pm);
107
			pm.worked(1);
153
			pm.worked(1);
108
			return undo;
154
			return undo;
109
		} finally {
155
		} finally {
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/FileAndFolderPaster.java (-6 / +33 lines)
Lines 17-23 Link Here
17
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFolder;
18
import org.eclipse.core.resources.IFolder;
19
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.Path;
21
import org.eclipse.hyades.test.ui.UiPlugin;
23
import org.eclipse.hyades.test.ui.UiPlugin;
22
import org.eclipse.hyades.test.ui.internal.navigator.action.resources.ActionMessages;
24
import org.eclipse.hyades.test.ui.internal.navigator.action.resources.ActionMessages;
23
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
25
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
Lines 27-42 Link Here
27
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
29
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
28
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
30
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
29
import org.eclipse.swt.dnd.Clipboard;
31
import org.eclipse.swt.dnd.Clipboard;
32
import org.eclipse.swt.dnd.FileTransfer;
30
import org.eclipse.swt.widgets.Shell;
33
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.ui.part.ResourceTransfer;
34
import org.eclipse.ui.part.ResourceTransfer;
32
/**
35
/**
33
 * @author Jerome Bozier
36
 * @author Jerome Bozier
34
 * @version February 26, 2008
37
 * @version April 29, 2008
35
 */
38
 */
36
public class FileAndFolderPaster implements IPasterExtended {
39
public class FileAndFolderPaster implements IPasterExtended {
37
40
38
	private LinkedList folders;
41
	private LinkedList folders;
39
	private LinkedList proxies;
42
	private LinkedList proxies;
43
	private LinkedList externalFiles;
40
	private Clipboard clipboard;
44
	private Clipboard clipboard;
41
	private Shell shell;
45
	private Shell shell;
42
46
Lines 44-49 Link Here
44
		folders = new LinkedList();
48
		folders = new LinkedList();
45
		clipboard = null;
49
		clipboard = null;
46
		proxies = new LinkedList();
50
		proxies = new LinkedList();
51
		externalFiles = new LinkedList();
47
		shell = null;
52
		shell = null;
48
	}
53
	}
49
	
54
	
Lines 55-64 Link Here
55
		this.shell = shell;
60
		this.shell = shell;
56
	}
61
	}
57
	
62
	
58
	private void sortClipboardElements() {
63
	private void sortClipboardElements(Object selection) {
59
		folders.clear();
64
		folders.clear();
60
		proxies.clear();
65
		proxies.clear();
61
		IResource [] res = getResourceFromClipboard();
66
		externalFiles.clear();
67
		IContainer container = null;
68
		if (selection instanceof IContainer) {
69
			container = (IContainer)selection;
70
		}
71
		IResource [] res = getResourceFromClipboard(container);
62
		if (res == null) {
72
		if (res == null) {
63
			return;
73
			return;
64
		}
74
		}
Lines 79-91 Link Here
79
	}
89
	}
80
	
90
	
81
	
91
	
82
	private IResource [] getResourceFromClipboard() {
92
	private IResource [] getResourceFromClipboard(final IContainer container) {
83
		final IResource[][] clipboardData = new IResource[1][];
93
		final IResource[][] clipboardData = new IResource[1][];
84
		shell.getDisplay().syncExec(new Runnable() {
94
		shell.getDisplay().syncExec(new Runnable() {
85
			public void run() {
95
			public void run() {
86
				//- clipboard must have resources or files
96
				//- clipboard must have resources or files
87
				ResourceTransfer resTransfer = ResourceTransfer.getInstance();
97
				ResourceTransfer resTransfer = ResourceTransfer.getInstance();
98
				// first case : copied inside eclipse
88
				clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer);
99
				clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer);
100
				if (clipboardData[0] == null) {
101
					// second case : copied outside eclipse
102
					FileTransfer transfer = FileTransfer.getInstance();
103
					String[] res = (String [])clipboard.getContents(transfer);
104
					IResource[] res2 = new IResource[res.length];
105
					for (int i=0; i<res.length; i++) {
106
						// basic case : resource already inside workspace
107
						Path path = new Path(res[i]);
108
						res2[i] = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
109
						if (res2[i] == null) {
110
							// annoying case : resource not inside workspace => add it to external files to be deal separately
111
							externalFiles.add(res[i]);
112
						}
113
					}
114
					clipboardData[0] = res2;
115
				}								
89
			}
116
			}
90
		});
117
		});
91
		return clipboardData[0];
118
		return clipboardData[0];
Lines 99-106 Link Here
99
		if (! canActivate(shell))
126
		if (! canActivate(shell))
100
			return false;
127
			return false;
101
		this.clipboard = clipboard;
128
		this.clipboard = clipboard;
102
		sortClipboardElements();
129
		sortClipboardElements(selection);
103
		PasteRefactoring refactoring = new PasteRefactoring(folders,proxies);
130
		PasteRefactoring refactoring = new PasteRefactoring(folders,proxies,externalFiles);
104
		PasteRefactoringWizard wizard = new PasteRefactoringWizard(refactoring,selection);
131
		PasteRefactoringWizard wizard = new PasteRefactoringWizard(refactoring,selection);
105
		wizard.setDefaultPageTitle(ActionMessages.PASTE_ACTION_NAME);
132
		wizard.setDefaultPageTitle(ActionMessages.PASTE_ACTION_NAME);
106
		wizard.setNeedsProgressMonitor(true);
133
		wizard.setNeedsProgressMonitor(true);
(-)src/org/eclipse/hyades/test/ui/internal/util/ReferenceDisplayUtils.java (+67 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.util;
13
14
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceTypeRegistry;
15
16
public class ReferenceDisplayUtils {
17
	private static final String basis = "--";//$NON-NLS-1$
18
	private static final String owned = "==";//$NON-NLS-1$
19
	private static final String opposite = "<";//$NON-NLS-1$
20
	private static final String direct = ">";//$NON-NLS-1$
21
	private static final String implicitStart = "[";//$NON-NLS-1$
22
	private static final String implicitEnd = "]";//$NON-NLS-1$
23
	private static ReferenceTypeRegistry factory = ReferenceTypeRegistry.getInstance();
24
	
25
	/**
26
	 * return a readable representation of a reference based on its type :
27
	 * --> explicit direct link
28
	 * <-- explicit opposite link
29
	 * ==> "owns" link
30
	 * [-->] implicit link
31
	 * @param type : type of the reference
32
	 * @return : a readable representation of a reference based on its type 
33
	 */
34
	public static String referenceToString(String type ) {
35
		StringBuffer buff = new StringBuffer();
36
		String oppositeRef = factory.getOppositeReferenceType(type);
37
		if (oppositeRef != null) {
38
			boolean implicit = (!factory.isExplicit(oppositeRef));
39
			if (implicit) {
40
				buff.append(implicitStart);
41
			}
42
			buff.append(opposite);
43
			if (factory.owns(oppositeRef)) {
44
				buff.append(owned);
45
			} else {
46
				buff.append(basis);
47
			}
48
			if (implicit) {
49
				buff.append(implicitEnd);
50
			}
51
		}
52
		boolean implicit = (!factory.isExplicit(type));
53
		if (implicit) {
54
			buff.append(implicitStart);
55
		}
56
		if (factory.owns(type)) {
57
			buff.append(owned);
58
		} else {
59
			buff.append(basis);
60
		}
61
		if (implicit) {
62
			buff.append(implicitEnd);
63
		}
64
		buff.append(direct);
65
		return buff.toString();
66
	}
67
}

Return to bug 166025