1 11 package org.eclipse.team.internal.ccvs.ui.repo; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 import org.eclipse.swt.dnd.*; 19 import org.eclipse.swt.widgets.Display; 20 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 21 import org.eclipse.team.internal.ccvs.ui.actions.CVSAction; 22 23 public class CopyRepositoryNameAction extends CVSAction { 24 public boolean isEnabled() { 25 return true; 26 } 27 public void execute(IAction action) { 28 ICVSRepositoryLocation[] locations = getSelectedRepositories(); 29 StringBuffer buffer = new StringBuffer (); 30 for (int i = 0; i < locations.length; i++) { 31 buffer.append(locations[i].getLocation(true)); 32 if (i < locations.length - 1) buffer.append("\n"); } 34 copyToClipbard(Display.getDefault(), buffer.toString()); 35 } 36 protected ICVSRepositoryLocation[] getSelectedRepositories() { 37 ArrayList repositories = null; 38 IStructuredSelection selection = getSelection(); 39 if (!selection.isEmpty()) { 40 repositories = new ArrayList (); 41 Iterator elements = selection.iterator(); 42 while (elements.hasNext()) { 43 Object next = getAdapter(elements.next(), ICVSRepositoryLocation.class); 44 if (next instanceof ICVSRepositoryLocation) { 45 repositories.add(next); 46 continue; 47 } 48 } 49 } 50 if (repositories != null && !repositories.isEmpty()) { 51 ICVSRepositoryLocation[] result = new ICVSRepositoryLocation[repositories.size()]; 52 repositories.toArray(result); 53 return result; 54 } 55 return new ICVSRepositoryLocation[0]; 56 } 57 private void copyToClipbard(Display display, String str) { 58 Clipboard clipboard = new Clipboard(display); 59 clipboard.setContents(new String [] { str }, new Transfer[] { TextTransfer.getInstance()}); 60 clipboard.dispose(); 61 } 62 } 63 | Popular Tags |