001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * DrawingAreaDropContext.java
044: *
045: * Created on July 1, 2004, 9:05 AM
046: */
047:
048: package org.netbeans.modules.uml.ui.swing.drawingarea;
049:
050: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
051: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
052: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
053: import org.netbeans.modules.uml.core.support.umlutils.ETList;
054: import org.netbeans.modules.uml.ui.support.ADTransferable;
055: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment;
056:
057: /**
058: * DrawingAreaDropContext is the event context for drawing area drop events.
059: *
060: * @author Trey Spiva
061: */
062: public class DrawingAreaDropContext implements IDrawingAreaDropContext {
063: private ADTransferable.ADTransferData m_DropData = null;
064: private IPresentationElement m_TargetPE = null;
065: private ICompartment m_TargetCompartment = null;
066: private boolean m_Canceled = false;
067: private ETList<IElement> m_AdditionalElements = new ETArrayList<IElement>();
068:
069: /**
070: * Creates a new instance of DrawingAreaDropContext
071: *
072: * @param data The DnD transfer data.
073: * @param targetPE The presentation that was the target of the drop.
074: * @param targetCompartment The compartment that was the target of the drop.
075: */
076: public DrawingAreaDropContext(ADTransferable.ADTransferData data,
077: IPresentationElement targetPE,
078: ICompartment targetCompartment) {
079: setDropData(data);
080: setPEDroppedOn(targetPE);
081: setCompartmentDroppedOn(targetCompartment);
082: }
083:
084: /**
085: * External listeners to the drop events can add model elements to add to
086: * those in the clipboard. These will act as if they were dropped as well.
087: */
088: public void addAdditionalDropElement(IElement newVal) {
089: m_AdditionalElements.add(newVal);
090: }
091:
092: /**
093: * Retrieves the model elemetns that External listeners to the drop events added.
094: * These will act as if they were dropped as well.
095: */
096: public ETList<IElement> getAdditionalDropElements() {
097: return m_AdditionalElements;
098: }
099:
100: /**
101: * The compartment that is the target of the drop operation.
102: *
103: * @return The target of the drop. <code>null</code> will be returned
104: * if a compartment element was not the target of the drop.
105: */
106: public ICompartment getCompartmentDroppedOn() {
107: return m_TargetCompartment;
108: }
109:
110: /**
111: * The drag and drops transferable object.
112: */
113: public ADTransferable.ADTransferData getDropData() {
114: return m_DropData;
115: }
116:
117: /**
118: * The presentation element that is the target of the drop operation.
119: *
120: * @return The target of the drop. <code>null</code> will be returned
121: * if a presentation element was not the target of the drop.
122: */
123: public IPresentationElement getPEDroppedOn() {
124: return m_TargetPE;
125: }
126:
127: /**
128: * Retieves whetehr or not to cancel the drag operatoin.
129: */
130: public boolean getCancel() {
131: return m_Canceled;
132: }
133:
134: /**
135: * Set this to true in the pre to cancel the event.
136: */
137: public void setCancel(boolean value) {
138: m_Canceled = value;
139: }
140:
141: ////////////////////////////////////////////////////////////////////////////
142: // Protected methods.
143:
144: /**
145: * Sets the drop data.
146: */
147: protected void setDropData(ADTransferable.ADTransferData data) {
148: m_DropData = data;
149: }
150:
151: /**
152: * Sets the presentation element that was the target of the drop.
153: */
154: protected void setPEDroppedOn(IPresentationElement targetPE) {
155: m_TargetPE = targetPE;
156: }
157:
158: /**
159: * Sets the compartment that was the target of the drop.
160: */
161: protected void setCompartmentDroppedOn(
162: ICompartment targetCompartment) {
163: m_TargetCompartment = targetCompartment;
164: }
165: }
|