KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > operations > ClipboardDiffOperation


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.ccvs.ui.operations;
12
13 import java.io.ByteArrayOutputStream JavaDoc;
14 import java.io.PrintStream JavaDoc;
15
16 import org.eclipse.core.resources.mapping.ResourceMapping;
17 import org.eclipse.core.runtime.*;
18 import org.eclipse.swt.dnd.*;
19 import org.eclipse.team.internal.ccvs.core.CVSException;
20 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
21 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
22 import org.eclipse.ui.IWorkbenchPart;
23
24 public class ClipboardDiffOperation extends DiffOperation {
25
26     private static final Object JavaDoc DESTINATION_CLIPBOARD = CVSUIMessages.ClipboardDiffOperation_Clipboard;
27
28     final ByteArrayOutputStream JavaDoc os = new ByteArrayOutputStream JavaDoc();
29
30     public ClipboardDiffOperation(IWorkbenchPart part, ResourceMapping[] mappings, LocalOption[] options, boolean isMultiPatch, boolean includeFullPathInformation, IPath patchRoot) {
31         super(part, mappings, options, isMultiPatch, includeFullPathInformation, patchRoot, DESTINATION_CLIPBOARD);
32     }
33
34     public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc {
35         super.execute(monitor);
36         
37         if (os.size() == 0 ||
38             (!patchHasContents && !patchHasNewFiles)) {
39             reportEmptyDiff();
40         } else {
41             copyToClipboard(os);
42         }
43      }
44     
45      private void copyToClipboard(final ByteArrayOutputStream JavaDoc baos) {
46         getShell().getDisplay().syncExec(new Runnable JavaDoc() {
47             public void run() {
48                 TextTransfer plainTextTransfer = TextTransfer.getInstance();
49                 Clipboard clipboard = new Clipboard(getShell().getDisplay());
50                 clipboard.setContents(
51                     new String JavaDoc[]{baos.toString()},
52                     new Transfer[]{plainTextTransfer});
53                 clipboard.dispose();
54             }
55         });
56      }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.team.internal.ccvs.ui.operations.DiffOperation#openStream()
60      */

61     protected PrintStream JavaDoc openStream() {
62         return new PrintStream JavaDoc(os);
63     }
64 }
65
Popular Tags