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

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

 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  """A criterion that ensures the drag source is the same as drop target.""" 
17   
18  from muntjac.event.transferable_impl import TransferableImpl 
19   
20  from muntjac.event.dd.acceptcriteria.client_side_criterion import \ 
21      ClientSideCriterion 
22 23 24 -class SourceIsTarget(ClientSideCriterion):
25 """A criterion that ensures the drag source is the same as drop target. 26 Eg. L{Tree} or L{Table} could support only re-ordering of items, 27 but no L{Transferable}s coming outside. 28 29 Note! Class is singleton, use L{get} method to get the instance. 30 """ 31 32 _instance = None 33
34 - def __init__(self):
35 pass
36 37
38 - def accept(self, dragEvent):
39 if isinstance(dragEvent.getTransferable(), TransferableImpl): 40 sourceComponent = dragEvent.getTransferable().getSourceComponent() 41 target = dragEvent.getTargetDetails().getTarget() 42 return sourceComponent == target 43 return False
44 45 46 @classmethod
47 - def get(cls):
48 return cls._instance
49 50
51 - def getIdentifier(self):
52 return 'com.vaadin.event.dd.acceptcriteria.SourceIsTarget'
53 54 55 SourceIsTarget._instance = SourceIsTarget() 56