01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.ui.tests.refactoring.infra;
11:
12: import java.util.Arrays;
13: import java.util.HashMap;
14: import java.util.HashSet;
15: import java.util.Iterator;
16: import java.util.Map;
17: import java.util.Set;
18:
19: import org.eclipse.swt.SWT;
20: import org.eclipse.swt.dnd.Clipboard;
21: import org.eclipse.swt.dnd.DND;
22: import org.eclipse.swt.dnd.Transfer;
23: import org.eclipse.swt.dnd.TransferData;
24: import org.eclipse.swt.widgets.Display;
25:
26: //have to create this class because of bug 40095
27: public class MockClipboard extends Clipboard {
28:
29: private Map fContents; //Transfer -> Object
30:
31: public MockClipboard(Display display) {
32: super (display);
33: fContents = new HashMap();
34: }
35:
36: protected void checkSubclass() {
37: //do nothing
38: }
39:
40: public TransferData[] getAvailableTypes() {
41: Set result = new HashSet();
42: for (Iterator iter = fContents.keySet().iterator(); iter
43: .hasNext();) {
44: Transfer transfer = (Transfer) iter.next();
45: result.addAll(Arrays.asList(transfer.getSupportedTypes()));
46: }
47: return (TransferData[]) result.toArray(new TransferData[result
48: .size()]);
49: }
50:
51: public Object getContents(Transfer transfer) {
52: return fContents.get(transfer);
53: }
54:
55: public void setContents(Object[] data, Transfer[] dataTypes) {
56: if (data == null || dataTypes == null
57: || data.length != dataTypes.length) {
58: DND.error(SWT.ERROR_INVALID_ARGUMENT);
59: }
60: fContents.clear();
61: for (int i = 0; i < dataTypes.length; i++) {
62: fContents.put(dataTypes[i], data[i]);
63: }
64: }
65:
66: public void dispose() {
67: fContents.clear();
68: super.dispose();
69: }
70: }
|