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 from muntjac.event.transferable_impl import TransferableImpl 17 from muntjac.event.dd.drag_source import IDragSource 18 from muntjac.event.dd.drop_target import IDropTarget 19 from muntjac.event.dd.target_details_impl import TargetDetailsImpl 20 from muntjac.ui.html5_file import Html5File 21 from muntjac.ui.custom_component import CustomComponent 22 from muntjac.terminal.gwt.client.mouse_event_details import MouseEventDetails 23 24 from muntjac.terminal.stream_variable import \ 25 (IStreamVariable, IStreamingEndEvent, IStreamingErrorEvent, 26 IStreamingProgressEvent, IStreamingStartEvent) 27 28 29 from muntjac.terminal.gwt.client.ui.dd.horizontal_drop_location import \ 30 HorizontalDropLocation 31 32 from muntjac.terminal.gwt.client.ui.dd.vertical_drop_location import \ 33 VerticalDropLocation37 38 CLIENT_WIDGET = None #ClientWidget(VDragAndDropWrapper, LoadStyle.EAGER) 3910041 """Wraps given component in a L{DragAndDropWrapper}. 42 43 @param root: the component to be wrapped 44 """ 45 super(DragAndDropWrapper, self).__init__(root) 46 47 self._receivers = dict() 48 49 self._dragStartMode = DragStartMode.NONE 50 51 self._dropHandler = None52 5355 super(DragAndDropWrapper, self).paintContent(target) 56 target.addAttribute('dragStartMode', 57 DragStartMode.ordinal(self._dragStartMode)) 58 59 if self.getDropHandler() is not None: 60 self.getDropHandler().getAcceptCriterion().paint(target) 61 62 if self._receivers is not None and len(self._receivers) > 0: 63 for idd, html5File in self._receivers.iteritems(): 64 if html5File.getStreamVariable() is not None: 65 target.addVariable(self, 'rec-' + idd, 66 ProxyReceiver(html5File)) 67 # these are cleaned from receivers once the upload 68 # has started 69 else: 70 # instructs the client side not to send the file 71 target.addVariable(self, 'rec-' + idd, None) 72 # forget the file from subsequent paints 73 del self._receivers[idd]74 75 78 79 83 8486 return WrapperTargetDetails(clientVariables, self)87 8890 return WrapperTransferable(self, rawVariables)91 92 96 97103158105 super(WrapperTransferable, self).__init__(sourceComponent, rawVariables) 106 107 self._files = None 108 109 fc = rawVariables.get('filecount') 110 if fc is not None: 111 self._files = [None] * fc 112 for i in range(fc): 113 fd = Html5File(rawVariables.get('fn%d' % i), # name 114 rawVariables.get('fs%d' % i), # size 115 rawVariables.get('ft%d' % i)) # mime 116 idd = rawVariables.get('fi%d' % i) 117 self._files[i] = fd 118 self._sourceComponent._receivers[idd] = fd 119 self._sourceComponent.requestRepaint() # paint receivers120 121123 """The component in wrapper that is being dragged or null if the 124 transferrable is not a component (most likely an html5 drag). 125 """ 126 return self.getData('component')127 128130 """@return: the mouse down event that started the drag and drop 131 operation 132 """ 133 return MouseEventDetails.deSerialize(self.getData('mouseDown'))134 135 138 139141 data = self.getData('Text') # IE, html5 142 143 if data is None: 144 # check for "text/plain" (webkit) 145 data = self.getData('text/plain') 146 147 return data148 149161 164 165207167 """@return: the absolute position of wrapper on the page""" 168 return self.getData('absoluteLeft')169 170172 """@return: the absolute position of wrapper on the page""" 173 return self.getData('absoluteTop')174 175177 """@return: details about the actual event that caused the event 178 details. Practically mouse move or mouse up. 179 """ 180 return MouseEventDetails.deSerialize(self.getData('mouseEvent'))181 182184 """@return: a detail about the drags vertical position over the 185 wrapper. 186 """ 187 data = self.getData('verticalLocation') 188 return VerticalDropLocation.valueOf[data]189 190192 """@return: a detail about the drags horizontal position over the 193 wrapper. 194 """ 195 data = self.getData('horizontalLocation') 196 return HorizontalDropLocation.valueOf[data]197 198200 """@deprecated: use L{getVerticalDropLocation} instead""" 201 return self.getVerticalDropLocation()202 203205 """@deprecated: use L{getHorizontalDropLocation} instead""" 206 return self.getHorizontalDropLocation()210 #: L{DragAndDropWrapper} does not start drag events at all 211 NONE = 'NONE' 212 213 #: The component on which the drag started will be shown as drag image. 214 COMPONENT = 'COMPONENT' 215 216 #: The whole wrapper is used as a drag image when dragging. 217 WRAPPER = 'WRAPPER' 218 219 _values = [NONE, COMPONENT, WRAPPER] 220 221 @classmethod228223 return cls._values[:]224 225 @classmethod231 235 236282238 if self._file.getStreamVariable() is None: 239 return None 240 return self._file.getStreamVariable().getOutputStream()241 242 245 246248 wrapper = ReceivingEventWrapper(event, self._file, self) 249 self._file.getStreamVariable().onProgress(wrapper)250 251253 self._listenProgressOfUploadedFile = \ 254 self._file.getStreamVariable() is not None 255 256 if self._listenProgressOfUploadedFile: 257 wrapper = ReceivingEventWrapper(event, self._file, self) 258 self._file.getStreamVariable().streamingStarted(wrapper) 259 260 # no need tell to the client about this receiver on next paint 261 self.receivers.remove(self._file) 262 263 # let the terminal GC the stream variable and not to accept 264 # other file uploads to this variable 265 event.disposeStreamVariable()266 267269 if self._listenProgressOfUploadedFile: 270 wrapper = ReceivingEventWrapper(event, self._file, self) 271 self._file.getStreamVariable().streamingFinished(wrapper)272 273275 if self._listenProgressOfUploadedFile: 276 wrapper = ReceivingEventWrapper(event, self._file, self) 277 self._file.getStreamVariable().streamingFailed(wrapper)278 279283 284 -class ReceivingEventWrapper(IStreamingErrorEvent, IStreamingEndEvent, 285 IStreamingStartEvent, IStreamingProgressEvent):286 # With XHR2 file posts we can't provide as much information from the 287 # terminal as with multipart request. This helper class wraps the 288 # terminal event and provides the lacking information from the 289 # Html5File. 290 295 296327298 return self._file.getType()299 300302 return self._file.getFileName()303 304306 return self._file.getFileSize()307 308 311313 if isinstance(self._wrappedEvent, IStreamingErrorEvent): 314 return self._wrappedEvent.getException() 315 return None316 317319 return self._wrappedEvent.getBytesReceived()320 321
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Apr 20 16:53:04 2013 | http://epydoc.sourceforge.net |