1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.layout.gle2; 18 19 /** 20 * This singleton is used to keep track of drag'n'drops initiated within this 21 * session of Eclipse. A drag can be initiated from a palette or from a canvas 22 * and its content is an Android View fully-qualified class name. 23 * <p/> 24 * Overall this is a workaround: the issue is that the drag'n'drop SWT API does not 25 * allow us to know the transfered data during the initial drag -- only when the 26 * data is dropped do we know what it is about (and to be more exact there is a workaround 27 * to do just that which works on Windows but not on Linux/Mac SWT). 28 * <p/> 29 * In the GLE we'd like to adjust drag feedback to the data being actually dropped. 30 * The singleton instance of this class will be used to track the data currently dragged 31 * off a canvas or its palette and then set back to null when the drag'n'drop is finished. 32 * <p/> 33 * Note that when a drag starts in one instance of Eclipse and the dragOver/drop is done 34 * in a <em>separate</em> instance of Eclipse, the tragged FQCN won't be registered here 35 * and will be null. 36 */ 37 class GlobalCanvasDragInfo { 38 39 private static final GlobalCanvasDragInfo sInstance = new GlobalCanvasDragInfo(); 40 41 private SimpleElement[] mCurrentElements = null; 42 private CanvasSelection[] mCurrentSelection; 43 private Object mSourceCanvas = null; 44 45 /** Private constructor. Use {@link #getInstance()} to retrieve the singleton. */ GlobalCanvasDragInfo()46 private GlobalCanvasDragInfo() { 47 // pass 48 } 49 50 /** Returns the singleton instance. */ getInstance()51 public static GlobalCanvasDragInfo getInstance() { 52 return sInstance; 53 } 54 55 /** Registers the XML elements being dragged. */ startDrag(SimpleElement[] elements, CanvasSelection[] selection, Object sourceCanvas)56 public void startDrag(SimpleElement[] elements, CanvasSelection[] selection, Object sourceCanvas) { 57 mCurrentElements = elements; 58 mCurrentSelection = selection; 59 mSourceCanvas = sourceCanvas; 60 } 61 62 /** Unregisters elements being dragged. */ stopDrag()63 public void stopDrag() { 64 mCurrentElements = null; 65 mSourceCanvas = null; 66 } 67 68 /** Returns the elements being dragged. */ getCurrentElements()69 public SimpleElement[] getCurrentElements() { 70 return mCurrentElements; 71 } 72 73 /** Returns the selection originally dragged. 74 * Can be null if the drag did not start in a canvas. 75 */ getCurrentSelection()76 public CanvasSelection[] getCurrentSelection() { 77 return mCurrentSelection; 78 } 79 80 /** 81 * Returns the object that call {@link #startDrag(SimpleElement[], CanvasSelection[], Object)}. 82 * Can be null. 83 * This is not meant to access the object indirectly, it is just meant to compare if the 84 * source and the destination of the drag'n'drop are the same, so object identity 85 * is all what matters. 86 */ getSourceCanvas()87 public Object getSourceCanvas() { 88 return mSourceCanvas; 89 } 90 } 91