modifyCommand.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » modifyCommand.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from historyUtils import *
from command import *

class ModifyCommand(Command):
    """
    @author P. Dabrowski <przemek.dabrowski@destroy-display.com> (15.11.2005)
    This class is a part of the history system of PyUt.
    This command undo/redo every
    """
    
    def __init__(self, anyObject = None):

        
        Command.__init__(self)
        
        self._object = anyObject

        #name of the method that is called for modification
        self._methodName = ""

        #old and new params for modification
        self._oldParams = []
        self._newParams = []
        
        
    #>------------------------------------------------------------------------
       
    def serialize(self):

        serialCmd = Command.serialize(self)

        serialCmd += makeValuatedToken("oldParams", repr(self._oldParams))
        serialCmd += makeValuatedToken("newParams", repr(self._newParams))
        serialCmd += makeValuatedToken("methodName", self._methodName)
        serialCmd += makeValuatedToken("object", repr(self._object))
        
        return serialCmd
    
    #>------------------------------------------------------------------------
    
    def unserialize(self, serializedInfos):

        Command.unserialize(self, serializedInfos)
    
        self._oldParams = eval(getTokenValue("oldParams", serializedInfos))
        self._newParams = eval(getTokenValue("newParams", serializedInfos))
        self._methodName = getTokenValue("methodName", serializedInfos)
        strObject = getTokenValue("object", serializedInfos)
        
        for anObject in self.getGroup().getHistory().getFrame().getUmlObjects():
            self._object = self._getModifiedObject(strObject, anObject)

    #>------------------------------------------------------------------------

    def undo(self):
        method = getattr(self._object, self._methodName)
        apply(method, self._oldParams)
        self.getGroup().getHistory().getFrame().Refresh()
        
    #>------------------------------------------------------------------------
    
    def redo(self):
        method = getattr(self._object, self._methodName)
        apply(method, self._newParams)
        self.getGroup().getHistory().getFrame().Refresh()
        
    #>------------------------------------------------------------------------

    def execute(self):
        """
        call of execute should do nothing, because the method that have
        modified the object has been already performed. (No call from history)
        """
        pass
    
    #>------------------------------------------------------------------------

    def setMethod(self, methodName):
        """
        set the name of the method that will performed a modification.
        @param methodName string    :   name of the method
        """
        self._methodName = methodName

    #>------------------------------------------------------------------------
     
    def setOldParams(self, params):
        """
        Set the parameters of the method that must be called to undo.
        Should be called before changes are performed.
        @param params object    :   values that will be changed by the call
                                    of the method. Must be ordered as in the
                                    method profile.
        """
        self._oldParams = params
        

    def setNewParams(self, params):
        """
        Set the parameters of the method that must be called to redo.
        Should be called as soon as the parameters for change are known.
        @param params object    :   values that will be changed by calling
                                    the redo method. Must be ordered as in the
                                    method profile.
        """
        self._newParams = params
            
    #>------------------------------------------------------------------------
           
    def _getModifiedObject(self, strObject, anObject):
        """
        @return the object that is represented by the string strObject. Used
        for unserialization.
        Notes : This methods requires a lot of CPU ressources and place on the
        stack. A refactoring must be proceeded in order to identify every
        object present in a frame more quickly. 
        """
        
        if cmp(repr(anObject), strObject) == 0:
            return anObject
        else:
            
            for anSubObject in anObject.__dict__.values():
                anSubObject = self._getModifiedObject(strObject, anSubObject)
            return anSubObject
    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.