Changeset 336
- Timestamp:
- 06/03/04 14:27:07 (5 years ago)
- Files:
-
- trunk/gaphor/gaphor/UML/collection.py (modified) (3 diffs)
- trunk/gaphor/gaphor/diagram/attribute.py (modified) (2 diffs)
- trunk/gaphor/gaphor/diagram/itemactions.py (modified) (1 diff)
- trunk/gaphor/gaphor/diagram/klass.py (modified) (6 diffs)
- trunk/gaphor/gaphor/diagram/operation.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gaphor/gaphor/UML/collection.py
r332 r336 61 61 raise AttributeError, '%s not in collection' % value 62 62 63 def moveUp(self, value):64 items = self.items65 i = items.index(value)66 i = i - 167 if i >= 0:68 items.remove(value)69 items.insert(i, value)70 # Send a notification that this list has changed71 print self.property, value72 self.property.notify(self.object)73 #self.owner.notify(self.property.name, pspec=self.property)74 63 75 64 def index(self, key): … … 77 66 collection.""" 78 67 return self.items.index(key) 79 68 69 80 70 # OCL members (from SMW by Ivan Porres, http://www.abo.fi/~iporres/smw) 81 71 … … 200 190 c=c-1 201 191 return False 192 193 194 def moveUp(self, value): 195 """ 196 Move element up. Owner is notified about the change. 197 """ 198 i1 = self.items.index(value) 199 i2 = i1 - 1 200 if i2 >= 0: 201 self.items[i1], self.items[i2] = self.items[i2], self.items[i1] 202 self.property.notify(self.object) # send a notification that this list has changed 203 else: 204 log.warning('Cannot move up first element') 205 206 207 def moveDown(self, value): 208 """ 209 Move element down. Owner is notified about the change. 210 """ 211 i1 = self.items.index(value) 212 i2 = i1 + 1 213 if i2 < len(self.items): 214 self.items[i1], self.items[i2] = self.items[i2], self.items[i1] 215 self.property.notify(self.object) # send a notification that this list has changed 216 else: 217 log.warning('Cannot move down last element') trunk/gaphor/gaphor/diagram/attribute.py
r332 r336 15 15 'DeleteAttribute', 16 16 'MoveUp', 17 'MoveDown', 17 18 'separator', 18 'CreateAttribute' 19 'CreateAttribute', 19 20 ) 20 21 … … 45 46 on_subject_notify__taggedValue_value = on_subject_notify__name 46 47 48 47 49 initialize_item(AttributeItem) trunk/gaphor/gaphor/diagram/itemactions.py
r333 r336 616 616 617 617 618 class MoveUpAction(Action): 618 class MoveAction(Action): 619 """ 620 Move attribute/operation down or up on the list. 621 """ 622 def _getItem(self): 623 return self._window.get_current_diagram_view() \ 624 .focus_item.item 625 626 627 def _getParent(self): 628 return get_parent_focus_item(self._window) 629 630 631 def _getElements(self, cls, item): 632 if isinstance(item, AttributeItem): 633 collection = cls.ownedAttribute 634 elif isinstance(item, OperationItem): 635 collection = cls.ownedOperation 636 return collection 637 638 639 def init(self, window): 640 self._window = window 641 642 643 def update(self): 644 try: 645 cls_item = self._getParent() 646 item = self._getItem() 647 except NoFocusItemError: 648 pass 649 else: 650 if isinstance(item, (AttributeItem, OperationItem)): 651 self.active = item.subject 652 self.sensitive = self._isSensitive(cls_item.subject, item) 653 654 655 def execute(self): 656 cls = self._getParent().subject 657 item = self._getItem() 658 659 log.debug('%s: %s.%s (%s)' \ 660 % (self.move_action, cls.name, item.subject.name, item.subject.__class__)) 661 662 # get method to move the element: moveUp or moveDown 663 move = getattr(self._getElements(cls, item), self.move_action) 664 move(item.subject) 665 self._window.execute_action('ItemFocus') 666 667 668 class MoveUpAction(MoveAction): 619 669 id = 'MoveUp' 620 670 label = 'Move Up' 621 671 tooltip = 'Move Up' 622 623 def _get_item(self): 624 return self._window.get_current_diagram_view().focus_item.item 625 626 def init(self, window): 627 self._window = window 628 629 def execute(self): 630 feature = self._get_item() 631 subject = get_parent_focus_item(self._window).subject 632 if isinstance(feature, AttributeItem): 633 subject.ownedAttribute.moveUp(feature.subject) 634 elif isinstance(feature, OperationItem): 635 subject.ownedOperation.moveUp(feature.subject) 672 move_action = 'moveUp' # name of method to move the element 673 674 def _isSensitive(self, cls, item): 675 collection = self._getElements(cls, item) 676 return len(collection) > 0 and collection[0] != item.subject 636 677 637 678 register_action(MoveUpAction, 'ItemFocus') 679 680 681 class MoveDownAction(MoveAction): 682 id = 'MoveDown' 683 label = 'Move Down' 684 tooltip = 'Move Down' 685 move_action = 'moveDown' # name of method to move the element 686 687 def _isSensitive(self, cls, item): 688 collection = self._getElements(cls, item) 689 return len(collection) > 0 and collection[-1] != item.subject 690 691 register_action(MoveDownAction, 'ItemFocus') trunk/gaphor/gaphor/diagram/klass.py
r335 r336 41 41 save_func(None, item) 42 42 43 def reorder(self, features):44 """Reorder the items in this compartment so they have the same45 order as the items in the features list.46 """47 items = list(self)48 tmp = [(item.subject, item) for item in self]49 newlist = []50 for f in features:51 for t in tmp:52 if t[0] is f:53 newlist.append(t[1])54 tmp.remove(t)55 break56 if newlist != items:57 print self[:]58 print 'new list', newlist59 self[:] = newlist60 self.owner.request_update()61 43 62 44 def pre_update(self, width, height, affine): … … 137 119 self._stereotype.set_text(STEREOTYPE_OPEN + 'stereotype' + STEREOTYPE_CLOSE) 138 120 121 139 122 def save(self, save_func): 140 123 # Store the show- properties *before* the width/height properties, … … 184 167 self.add(new) 185 168 186 def sync_ features(self, features, compartment, creator=None):169 def sync_uml_elements(self, elements, compartment, creator=None): 187 170 """Common function for on_subject_notify__ownedAttribute() and 188 171 on_subject_notify__ownedOperation(). 189 - features: the list of attributes or operations in the model172 - elements: the list of attributes or operations in the model 190 173 - compartment: our local representation 191 174 - creator: factory method for creating new attr. or oper.'s 192 175 """ 193 # Extract the UML elements from the compartment 194 my_features = map(getattr, compartment, 195 ['subject'] * len(compartment)) 196 197 for a in [f for f in features if f not in my_features]: 198 creator(a) 199 200 tmp = [f for f in my_features if f not in features] 201 if tmp: 202 # Create a feature->item mapping 203 mapping = dict(zip(my_features, compartment)) 204 for a in tmp: 205 self.remove(mapping[a]) 206 207 compartment.reorder(features) 176 # extract the UML elements from the compartment 177 local_elements = [f.subject for f in compartment] 178 179 # map local element with compartment element 180 mapping = dict(zip(local_elements, compartment)) 181 182 try: 183 import sets 184 to_add = sets.Set(elements) - sets.Set(local_elements) 185 except ImportError: 186 to_add = [el for el in elements if el not in local_elements] 187 188 # sync local elements with elements 189 del compartment[:] 190 191 for el in elements: 192 if el in to_add: 193 creator(el) 194 else: 195 compartment.append(mapping[el]) 196 197 log.debug('elements order in model: %s' % [f.name for f in elements]) 198 log.debug('elements order in diagram: %s' % [f.subject.name for f in compartment]) 199 assert tuple([f.subject for f in compartment]) == tuple(elements) 200 201 self.request_update() 202 208 203 209 204 def sync_attributes(self): … … 212 207 """ 213 208 owned_attributes = [a for a in self.subject.ownedAttribute if not a.association] 214 self.sync_ features(owned_attributes, self._attributes,209 self.sync_uml_elements(owned_attributes, self._attributes, 215 210 self._create_attribute) 216 211 … … 219 214 in self.subject. 220 215 """ 221 self.sync_ features(self.subject.ownedOperation, self._operations,216 self.sync_uml_elements(self.subject.ownedOperation, self._operations, 222 217 self._create_operation) 223 218 224 219 def on_subject_notify(self, pspec, notifiers=()): 225 #log.debug('Class.on_subject_notify(%s, %s)' % (pspec, notifiers))220 log.debug('Class.on_subject_notify(%s, %s)' % (pspec, notifiers)) 226 221 NamedItem.on_subject_notify(self, pspec, ('ownedAttribute', 'ownedOperation', 'isAbstract')) 227 222 # Create already existing attributes and operations: … … 240 235 """Called when the ownedAttribute property of our subject changes. 241 236 """ 242 #log.debug('on_subject_notify__ownedAttribute')237 log.debug('on_subject_notify__ownedAttribute') 243 238 # Filter attributes that are connected to an association: 244 239 self.sync_attributes() trunk/gaphor/gaphor/diagram/operation.py
r332 r336 16 16 'DeleteOperation', 17 17 'MoveUp', 18 'MoveDown', 18 19 'separator', 19 20 'CreateOperation'
