Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2012 Vaadin Ltd. 2 # Copyright (C) 2012 Richard Lincoln 3 # 4 # Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 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 import logging 17 18 from muntjac.event.dd.target_details_impl import TargetDetailsImpl 19 from muntjac.terminal.variable_owner import IVariableOwner 20 from muntjac.terminal.gwt.server.json_paint_target import JsonPaintTarget 21 from muntjac.event.dd.drag_and_drop_event import DragAndDropEvent 22 from muntjac.event.transferable_impl import TransferableImpl 23 from muntjac.event.dd.drop_target import IDropTarget 24 from muntjac.event.dd.drag_source import IDragSource 25 from muntjac.terminal.gwt.client.ui.dd.v_drag_and_drop_manager import DragEventType 26 27 28 logger = logging.getLogger(__name__) 29 303217734 self._manager = manager 35 36 self._lastVisitId = None 37 self._lastVisitAccepted = False 38 self._dragEvent = None 39 self._acceptCriterion = None40 4143 owner = variables.get('dhowner') 44 45 # Validate drop handler owner 46 if not isinstance(owner, IDropTarget): 47 logger.critical('DropHandler owner ' + owner 48 + ' must implement IDropTarget') 49 return 50 51 # owner cannot be null here 52 53 dropTarget = owner 54 self._lastVisitId = variables.get('visitId') 55 56 # request may be dropRequest or request during drag operation 57 # (commonly dragover or dragenter) 58 dropRequest = self.isDropRequest(variables) 59 if dropRequest: 60 self.handleDropRequest(dropTarget, variables) 61 else: 62 self.handleDragRequest(dropTarget, variables)63 6466 """Handles a drop request from the VDragAndDropManager. 67 """ 68 dropHandler = dropTarget.getDropHandler() 69 if dropHandler is None: 70 # No dropHandler returned so no drop can be performed. 71 logger.info('IDropTarget.getDropHandler() returned null ' 72 'for owner: ' + dropTarget) 73 return 74 75 # Construct the Transferable and the DragDropDetails for the drop 76 # operation based on the info passed from the client widgets (drag 77 # source for Transferable, drop target for DragDropDetails). 78 transferable = self.constructTransferable(dropTarget, variables) 79 dropData = self.constructDragDropDetails(dropTarget, variables) 80 81 dropEvent = DragAndDropEvent(transferable, dropData) 82 83 if dropHandler.getAcceptCriterion().accept(dropEvent): 84 dropHandler.drop(dropEvent)85 8688 """Handles a drag/move request from the VDragAndDropManager. 89 """ 90 self._lastVisitId = variables.get('visitId') 91 92 self._acceptCriterion = \ 93 dropTarget.getDropHandler().getAcceptCriterion() 94 95 # Construct the Transferable and the DragDropDetails for the drag 96 # operation based on the info passed from the client widgets (drag 97 # source for Transferable, current target for DragDropDetails). 98 transferable = self.constructTransferable(dropTarget, variables) 99 dragDropDetails = self.constructDragDropDetails(dropTarget, variables) 100 101 self._dragEvent = DragAndDropEvent(transferable, dragDropDetails) 102 103 self._lastVisitAccepted = self._acceptCriterion.accept(self._dragEvent)104 105107 """Construct DragDropDetails based on variables from client drop 108 target. Uses DragDropDetailsTranslator if available, otherwise a 109 default DragDropDetails implementation is used. 110 """ 111 rawDragDropDetails = variables.get('evt') 112 113 dropData = dropTarget.translateDropTargetDetails(rawDragDropDetails) 114 115 if dropData is None: 116 # Create a default DragDropDetails with all the raw variables 117 dropData = TargetDetailsImpl(rawDragDropDetails, dropTarget) 118 119 return dropData120 121 124 125 129 130132 sourceComponent = variables.get('component') 133 134 variables = variables.get('tra') 135 136 transferable = None 137 if (sourceComponent is not None 138 and isinstance(sourceComponent, IDragSource)): 139 transferable = sourceComponent.getTransferable(variables) 140 141 if transferable is None: 142 transferable = TransferableImpl(sourceComponent, variables) 143 144 return transferable145 146 149 150 153 154156 if self._isDirty(): 157 outWriter.write(', \"dd\":') 158 jsonPaintTarget = JsonPaintTarget(self._manager, outWriter, False) 159 jsonPaintTarget.startTag('dd') 160 jsonPaintTarget.addAttribute('visitId', self._lastVisitId) 161 if self._acceptCriterion is not None: 162 jsonPaintTarget.addAttribute('accepted', 163 self._lastVisitAccepted) 164 self._acceptCriterion.paintResponse(jsonPaintTarget) 165 jsonPaintTarget.endTag('dd') 166 jsonPaintTarget.close() 167 self._lastVisitId = -1 168 self._lastVisitAccepted = False 169 self._acceptCriterion = None 170 self._dragEvent = None171 172
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Apr 20 16:53:04 2013 | http://epydoc.sourceforge.net |