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 242296
Collapse All | Expand All

(-)src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 33-38 Link Here
33
public class RefactorActionGroup extends ActionGroup {
33
public class RefactorActionGroup extends ActionGroup {
34
    
34
    
35
	private CopyToClipboardAction copyAction;
35
	private CopyToClipboardAction copyAction;
36
	private CopyQualifiedNameToClipboardAction copyQualifiedNameAction;
36
	private MoveResourceAction moveAction;
37
	private MoveResourceAction moveAction;
37
	private RenameResourceAction renameAction;
38
	private RenameResourceAction renameAction;
38
	private ISynchronizePageSite site;
39
	private ISynchronizePageSite site;
Lines 59-64 Link Here
59
		// Actions can work on non-resource selections
60
		// Actions can work on non-resource selections
60
		copyAction.selectionChanged(getObjectSelection());
61
		copyAction.selectionChanged(getObjectSelection());
61
		menu.add(copyAction);
62
		menu.add(copyAction);
63
		copyQualifiedNameAction.selectionChanged(getObjectSelection());
64
		menu.add(copyQualifiedNameAction);
62
		
65
		
63
		if (anyResourceSelected) {		    
66
		if (anyResourceSelected) {		    
64
			deleteAction.selectionChanged(selection);
67
			deleteAction.selectionChanged(selection);
Lines 73-78 Link Here
73
76
74
 	public void fillActionBars(IActionBars actionBars) {
77
 	public void fillActionBars(IActionBars actionBars) {
75
    	actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
78
    	actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
79
    	actionBars.setGlobalActionHandler("org.eclipse.team.ui.synchronize.action.copyQualifiedName", copyQualifiedNameAction); //$NON-NLS-1$
76
    	actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction);
80
    	actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction);
77
    	actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);
81
    	actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);
78
    	actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction);
82
    	actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction);
Lines 81-86 Link Here
81
    public void updateActionBars() {
85
    public void updateActionBars() {
82
        final IStructuredSelection structuredSelection= getSelection();
86
        final IStructuredSelection structuredSelection= getSelection();
83
    	copyAction.selectionChanged(getObjectSelection());
87
    	copyAction.selectionChanged(getObjectSelection());
88
    	copyQualifiedNameAction.selectionChanged(getObjectSelection());
84
    	deleteAction.selectionChanged(structuredSelection);
89
    	deleteAction.selectionChanged(structuredSelection);
85
    	moveAction.selectionChanged(structuredSelection);
90
    	moveAction.selectionChanged(structuredSelection);
86
    	renameAction.selectionChanged(structuredSelection);
91
    	renameAction.selectionChanged(structuredSelection);
Lines 92-97 Link Here
92
        final ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
97
        final ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
93
        
98
        
94
        copyAction= new CopyToClipboardAction(shell, navigatorContentService);
99
        copyAction= new CopyToClipboardAction(shell, navigatorContentService);
100
        copyQualifiedNameAction= new CopyQualifiedNameToClipboardAction(shell, navigatorContentService);
95
        moveAction= new MoveResourceAction(shell);
101
        moveAction= new MoveResourceAction(shell);
96
        renameAction= new RenameResourceAction(shell);
102
        renameAction= new RenameResourceAction(shell);
97
        deleteAction = new DeleteResourceAction(shell) {
103
        deleteAction = new DeleteResourceAction(shell) {
Lines 103-108 Link Here
103
        copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
109
        copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
104
        copyAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
110
        copyAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
105
        
111
        
112
        copyQualifiedNameAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
113
        copyQualifiedNameAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
114
        
106
        deleteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
115
        deleteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
107
        deleteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
116
        deleteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
108
    }
117
    }
Lines 155-159 Link Here
155
	public void dispose() {
164
	public void dispose() {
156
		super.dispose();
165
		super.dispose();
157
		copyAction.dispose();
166
		copyAction.dispose();
167
		copyQualifiedNameAction.dispose();
158
	}
168
	}
159
}
169
}
(-)src/org/eclipse/team/internal/ui/messages.properties (-1 / +5 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2008 IBM Corporation and others.
2
# Copyright (c) 2008 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 369-374 Link Here
369
CopyToClipboardAction_3=Problem Copying to Clipboard
369
CopyToClipboardAction_3=Problem Copying to Clipboard
370
CopyToClipboardAction_4=There was a problem when accessing the system clipboard. Retry?
370
CopyToClipboardAction_4=There was a problem when accessing the system clipboard. Retry?
371
371
372
CopyQualifiedNameToClipboardAction_1=Copy &Qualified Name
373
CopyQualifiedNameToClipboardAction_2= Copy QualifiedName
374
CopyQualifiedNameToClipboardAction_3=Problem Copying Qualified Name to Clipboard
375
372
FlatModelProvider_6=Sort &Resources By
376
FlatModelProvider_6=Sort &Resources By
373
FlatModelProvider_7=&Name
377
FlatModelProvider_7=&Name
374
FlatModelProvider_8=&Path
378
FlatModelProvider_8=&Path
(-)src/org/eclipse/team/internal/ui/TeamUIMessages.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 519-524 Link Here
519
	public static String CopyToClipboardAction_3;
519
	public static String CopyToClipboardAction_3;
520
	public static String CopyToClipboardAction_4;
520
	public static String CopyToClipboardAction_4;
521
521
522
	public static String CopyQualifiedNameToClipboardAction_1;
523
	public static String CopyQualifiedNameToClipboardAction_2;
524
	public static String CopyQualifiedNameToClipboardAction_3;
525
522
	public static String FlatModelProvider_6;
526
	public static String FlatModelProvider_6;
523
	public static String FlatModelProvider_7;
527
	public static String FlatModelProvider_7;
524
	public static String FlatModelProvider_8;
528
	public static String FlatModelProvider_8;
(-)src/org/eclipse/team/internal/ui/synchronize/actions/CopyQualifiedNameToClipboardAction.java (+228 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
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.actions;
12
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.compare.ITypedElement;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.jface.dialogs.MessageDialog;
23
import org.eclipse.jface.viewers.*;
24
import org.eclipse.swt.SWTError;
25
import org.eclipse.swt.dnd.*;
26
import org.eclipse.swt.widgets.Shell;
27
import org.eclipse.team.internal.ui.*;
28
import org.eclipse.ui.actions.SelectionListenerAction;
29
import org.eclipse.ui.navigator.INavigatorContentService;
30
import org.eclipse.ui.part.ResourceTransfer;
31
32
/**
33
 * Based on org.eclipse.ui.views.navigator.CopyAction with the additional support for
34
 * copying any non-resource object in the selection and putting the toString() as
35
 * a text transfer.
36
 * 
37
 * @since 3.1
38
 */
39
class CopyQualifiedNameToClipboardAction extends SelectionListenerAction {
40
    
41
    private static final String EOL = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
42
43
    private static final String SEP = "/"; //$NON-NLS-1$
44
45
    private final static String ID= TeamUIPlugin.PLUGIN_ID + ".synchronize.action.copytext";  //$NON-NLS-1$
46
    
47
    private final Shell fShell;
48
    private final Clipboard fClipboard;
49
50
	private final INavigatorContentService navigatorContentService;
51
52
    protected CopyQualifiedNameToClipboardAction(Shell shell, INavigatorContentService navigatorContentService) {
53
        super(TeamUIMessages.CopyQualifiedNameToClipboardAction_1);
54
		this.navigatorContentService = navigatorContentService; 
55
        Assert.isNotNull(shell);
56
        fShell= shell;
57
        fClipboard= new Clipboard(shell.getDisplay());
58
        setToolTipText(TeamUIMessages.CopyQualifiedNameToClipboardAction_2); 
59
        setId(ID);
60
    }
61
    
62
    public void run() {
63
		copyResources(getSelectedResources(), getTextualClipboardContents());
64
	}
65
    
66
    /*
67
     * Return a text representation of all selected elements.
68
     * Use the name from the tree node so what is copied
69
     * matches what appears in the tree.
70
     */
71
    private String getTextualClipboardContents() {
72
		StringBuffer buf = new StringBuffer();
73
		int i = 0;
74
		IStructuredSelection structuredSelection = getStructuredSelection();
75
		if (structuredSelection instanceof TreeSelection) {
76
			TreeSelection ts = (TreeSelection) structuredSelection;
77
			TreePath[] paths = ts.getPaths();
78
			for (int j = 0; j < paths.length; j++) {
79
				TreePath path = paths[j];
80
				String qualifiedText = getQualifiedTextFor(path);
81
				if (qualifiedText != null && qualifiedText.length() > 0) {
82
					if (i > 0)
83
						buf.append(EOL);
84
					buf.append(qualifiedText);
85
					i++;
86
				}
87
			}
88
		} else {
89
			for (Iterator it = structuredSelection.iterator(); it.hasNext();) {
90
				Object element = it.next();
91
				if (element instanceof ITypedElement) {
92
					if (i > 0)
93
						buf.append(EOL);
94
					buf.append(((ITypedElement)element).getName());
95
					i++;
96
				} else {
97
					IResource resource = Utils.getResource(element);
98
					if (resource != null) {
99
						if (i > 0)
100
							buf.append(EOL);
101
						buf.append(resource.getName());
102
						i++;
103
					}
104
				}
105
			}
106
		}
107
		return buf.toString();
108
	}
109
110
	private String getQualifiedTextFor(TreePath path) {
111
		StringBuffer qualifiedText = new StringBuffer();
112
		TreePath parentPath = path.getParentPath();
113
		if (parentPath != null) {
114
			String parentText = getQualifiedTextFor(parentPath);
115
			qualifiedText.append(parentText);
116
			qualifiedText.append(SEP);
117
		}
118
		String pathText = getTextFor(path); 
119
		qualifiedText.append(pathText);
120
		return qualifiedText.toString();
121
	}
122
123
	private String getTextFor(TreePath path) {
124
		Object element = path.getLastSegment();
125
		if (element instanceof ITypedElement) {
126
			return ((ITypedElement)element).getName();
127
		}
128
		INavigatorContentService service = getNavigatorContentService();
129
		if (service != null) {
130
			ILabelProvider provider = service.createCommonLabelProvider();
131
			if (provider instanceof ITreePathLabelProvider) {
132
				ITreePathLabelProvider tplp = (ITreePathLabelProvider) provider;
133
				ViewerLabel viewerLabel = new ViewerLabel("", null); //$NON-NLS-1$
134
				tplp.updateLabel(viewerLabel, path);
135
				return viewerLabel.getText();
136
			}
137
			return provider.getText(element);
138
		}
139
		if (element instanceof IResource) {
140
			IResource resource = (IResource) element;
141
			return resource.getName();
142
		}
143
		return null;
144
	}
145
146
	private INavigatorContentService getNavigatorContentService() {
147
		return navigatorContentService;
148
	}
149
150
	private void copyResources(List selectedResources, String text) {
151
		IResource[] resources = (IResource[]) selectedResources.toArray(new IResource[selectedResources.size()]);
152
		// Get the file names and a string representation
153
		final int length = resources.length;
154
		int actualLength = 0;
155
		String[] fileNames = new String[length];
156
		for (int i = 0; i < length; i++) {
157
			final IPath location = resources[i].getLocation();
158
			// location may be null. See bug 29491.
159
			if (location != null)
160
				fileNames[actualLength++] = location.toOSString();
161
		}
162
		// was one or more of the locations null?
163
		if (actualLength < length) {
164
			String[] tempFileNames = fileNames;
165
			fileNames = new String[actualLength];
166
			for (int i = 0; i < actualLength; i++)
167
				fileNames[i] = tempFileNames[i];
168
		}
169
		setClipboard(resources, fileNames, text);
170
	}
171
172
	/**
173
	 * Set the clipboard contents. Prompt to retry if clipboard is busy.
174
	 * 
175
	 * @param resources the resources to copy to the clipboard
176
	 * @param fileNames file names of the resources to copy to the clipboard
177
	 * @param names string representation of all names
178
	 */
179
    private void setClipboard(IResource[] resources, String[] fileNames, String names) {
180
        try {
181
            // set the clipboard contents
182
        	List data = new ArrayList();
183
        	List dataTypes = new ArrayList();
184
        	 if (resources.length > 0) {
185
        		 data.add(resources);
186
        		 dataTypes.add(ResourceTransfer.getInstance());
187
        	 }
188
            if (fileNames.length > 0) {
189
       		 	data.add(fileNames);
190
       		 	dataTypes.add(FileTransfer.getInstance());
191
            }
192
            if (names != null && names.length() > 0) {
193
       		 	data.add(names);
194
       		 	dataTypes.add(TextTransfer.getInstance());
195
            }
196
            if (!data.isEmpty())
197
                fClipboard.setContents(
198
                		data.toArray(), 
199
                		(Transfer[]) dataTypes.toArray(new Transfer[dataTypes.size()]));
200
        } catch (SWTError e) {
201
            if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
202
                throw e;
203
            if (MessageDialog.openQuestion(fShell, TeamUIMessages.CopyQualifiedNameToClipboardAction_3, TeamUIMessages.CopyToClipboardAction_4))  
204
                setClipboard(resources, fileNames, names);
205
        }
206
    }
207
    
208
    protected boolean updateSelection(IStructuredSelection selection) {
209
		if (!super.updateSelection(selection))
210
			return false;
211
		return true;
212
	}
213
     
214
	protected List getSelectedNonResources() {
215
		return Arrays.asList(Utils.getNonResources(getStructuredSelection().toArray()));
216
	}
217
	
218
	protected List getSelectedResources() {
219
    	// Calling our own selection utility because the elements in the
220
		// synchronize view can't adapt to IResource because we don't want the usual object
221
		// contribution/ on them.
222
		return Arrays.asList(Utils.getResources(getStructuredSelection().toArray()));
223
	}
224
    
225
	public void dispose() {
226
		fClipboard.dispose();
227
	}
228
}

Return to bug 242296