Menu

verifying parameter changed in UI

Help
Doron
2014-02-23
2014-02-25
  • Doron

    Doron - 2014-02-23

    Hi,
    is there an event that i can override (like handleUi)that listens to each parameter and is invoked when the parameters value changes?.

     
  • Itai Agmon

    Itai Agmon - 2014-02-25

    Not really, but it's not that hard to use the handleUiEvent to get the same behavior.

    Here is a simple example that I wrote.

        private HashMap<String, Parameter> previousMap;
    
        @Override
        public void handleUIEvent(HashMap<String, Parameter> map, String methodName) throws Exception {
            if (previousMap != null) {
                for (String parameterName : map.keySet()) {
                    final Parameter newParameter = map.get(parameterName);
                    final Parameter oldParameter = previousMap.get(parameterName);
                    if (newParameter.getValue() == null || oldParameter.getValue() == null){
                        if (newParameter.getValue() != null){
                            parameterChangedEvent(parameterName, oldParameter, newParameter);
                        }else if (oldParameter.getValue() != null){
                            parameterChangedEvent(parameterName, oldParameter, newParameter);
                        }else {
                            continue;
                        }
                    }
                    if (!map.get(parameterName).getValue().equals(previousMap.get(parameterName).getValue())) {
                        parameterChangedEvent(parameterName, previousMap.get(parameterName), map.get(parameterName));
                    }
                }
            }
            //We need to clone the parameters map.
            previousMap = new HashMap<String,Parameter>();
            for (String parameterName : map.keySet()){
                previousMap.put(parameterName, map.get(parameterName).cloneParameter());
            }
        }
    
        private void parameterChangedEvent(String parameterName, Parameter oldParameter, Parameter newParameter) {
            System.out.println("Parameter " + parameterName + " was changed from " + oldParameter.getValue() + " to "
                    + newParameter.getValue());
        }
    
     
  • Doron

    Doron - 2014-02-25

    great,
    thanks Itai for the adding the example and saving me the time of writing myself

     

Log in to post a comment.