1 11 package org.eclipse.team.internal.ccvs.ui.repo; 12 13 import org.eclipse.jface.action.IAction; 14 import org.eclipse.swt.dnd.Clipboard; 15 import org.eclipse.swt.dnd.TextTransfer; 16 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; 17 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; 18 import org.eclipse.ui.*; 19 import org.eclipse.ui.actions.ActionDelegate; 20 import org.eclipse.ui.actions.ActionFactory; 21 22 25 public class PasteConnectionStringAction extends ActionDelegate implements 26 IViewActionDelegate { 27 28 private IAction action; 29 30 public void run(IAction action) { 31 Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench() 32 .getDisplay()); 33 try { 34 Object contents = clipboard.getContents(TextTransfer.getInstance()); 35 if (contents != null && contents instanceof String ) { 36 String connectionString = (String ) contents; 37 CVSRepositoryLocation location = CVSRepositoryLocation 38 .fromString(connectionString); 39 if (location != null) { 40 KnownRepositories.getInstance().addRepository(location, 41 true); 42 } 43 } 44 } catch (Exception e) { 45 } finally { 47 clipboard.dispose(); 48 } 49 } 50 51 public void init(IAction action) { 52 super.init(action); 53 this.action = action; 54 } 55 56 public void init(IViewPart view) { 57 IActionBars actionBars = view.getViewSite().getActionBars(); 58 actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), action); 59 actionBars.updateActionBars(); 60 } 61 62 } 63 | Popular Tags |