Package muntjac :: Package event :: Package dd :: Package acceptcriteria :: Module source_is
[hide private]
[frames] | no frames]

Source Code for Module muntjac.event.dd.acceptcriteria.source_is

 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  """Client side criteria that checks if the drag source is one of the given 
17  components.""" 
18   
19  from muntjac.event.transferable_impl import TransferableImpl 
20   
21  from muntjac.event.dd.acceptcriteria.client_side_criterion import \ 
22      ClientSideCriterion 
23   
24   
25 -class SourceIs(ClientSideCriterion):
26 """Client side criteria that checks if the drag source is one of the given 27 components. 28 """ 29
30 - def __init__(self, *component):
31 self._component = component
32 33
34 - def paintContent(self, target):
35 super(SourceIs, self).paintContent(target) 36 target.addAttribute('c', len(self._component)) 37 for i, c in enumerate(self._component): 38 target.addAttribute('component' + i, c)
39 40
41 - def accept(self, dragEvent):
42 if isinstance(dragEvent.getTransferable(), TransferableImpl): 43 sourceComponent = dragEvent.getTransferable().getSourceComponent() 44 for c in self._component: 45 if c == sourceComponent: 46 return True 47 return False
48 49
50 - def getIdentifier(self):
51 return 'com.vaadin.event.dd.acceptcriteria.SourceIs'
52