KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > repo > PasteConnectionStringAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  * Willian Mitsuda <wmitsuda@gmail.com> - initial implementation
10  *******************************************************************************/

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 /**
23  * Try to paste a CVS connection string from clipboard as a repository location
24  */

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 JavaDoc contents = clipboard.getContents(TextTransfer.getInstance());
35             if (contents != null && contents instanceof String JavaDoc) {
36                 String JavaDoc connectionString = (String JavaDoc) contents;
37                 CVSRepositoryLocation location = CVSRepositoryLocation
38                         .fromString(connectionString);
39                 if (location != null) {
40                     KnownRepositories.getInstance().addRepository(location,
41                             true);
42                 }
43             }
44         } catch (Exception JavaDoc e) {
45             // Fail silently
46
} 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