]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/ui/ElementClassTransferable.java
Fix NPE from flagTransform
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / ui / ElementClassTransferable.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.ui;
13
14 import java.awt.datatransfer.Clipboard;
15 import java.awt.datatransfer.ClipboardOwner;
16 import java.awt.datatransfer.DataFlavor;
17 import java.awt.datatransfer.Transferable;
18 import java.awt.datatransfer.UnsupportedFlavorException;
19 import java.io.IOException;
20 import java.io.Serializable;
21
22 public class ElementClassTransferable implements Transferable, ClipboardOwner {
23
24         public static final DataFlavor FLAVOR = new DataFlavor( ResourceElementClassTransferData.class, "Element Class" );
25
26         public static class ResourceElementClassTransferData implements Serializable {
27                 private static final long serialVersionUID = -4990050837054070697L;
28                 public String elementClassResourceRandomAccessReference[];      
29         }
30         
31         private ResourceElementClassTransferData data;
32
33         /**
34          * Creates a <code>Transferable</code> capable of transferring the specified
35          * <code>String</code>.
36          */
37         public ElementClassTransferable(ResourceElementClassTransferData data) {
38                 this.data = data;
39         }
40
41         /**
42          * Returns an array of flavors in which this <code>Transferable</code> can
43          * provide the data. <code>DataFlavor.stringFlavor</code> is properly
44          * supported. Support for <code>DataFlavor.plainTextFlavor</code> is
45          * <b>deprecated</b>.
46          * 
47          * @return an array of length two, whose elements are <code>DataFlavor.
48          *         stringFlavor</code> and <code>DataFlavor.plainTextFlavor</code>
49          */
50         public DataFlavor[] getTransferDataFlavors() {
51                 return new DataFlavor[] { FLAVOR }; 
52         }
53
54         public boolean isDataFlavorSupported(DataFlavor flavor) {
55                 return flavor.equals(FLAVOR);
56         }
57
58         public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
59                 if (flavor.equals(FLAVOR)) 
60                         return (ResourceElementClassTransferData) data;
61                 throw new UnsupportedFlavorException(flavor);
62         }
63
64         public void lostOwnership(Clipboard clipboard, Transferable contents) {
65         }
66
67 }