Coverage Report - org.argouml.model.euml.ChangeCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangeCommand
0%
0/31
0%
0/18
3.4
 
 1  
 // $Id: ChangeCommand.java 18220 2010-04-08 20:37:15Z tfmorris $
 2  
 /*******************************************************************************
 3  
  * Copyright (c) 2007,2010 Bogdan Pistol and other contributors
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    Bogdan Pistol - initial API and implementation
 11  
  *******************************************************************************/
 12  
 package org.argouml.model.euml;
 13  
 
 14  
 import org.eclipse.emf.common.notify.impl.NotificationImpl;
 15  
 
 16  
 /**
 17  
  * A ChangeCommand that updates its label.
 18  
  * <p>
 19  
  * The label of this command can contain the character '#' that will be replaced
 20  
  * with information about an object when the label is returned.
 21  
  * <p>
 22  
  * TODO: Switch this to use Java string formatting instead of private # notation?
 23  
  * 
 24  
  * @author Bogdan Pistol
 25  
  */
 26  
 public class ChangeCommand extends
 27  
         org.eclipse.uml2.common.edit.command.ChangeCommand {
 28  
 
 29  
     private Object objects[];
 30  
 
 31  
     private EUMLModelImplementation modelImpl;
 32  
 
 33  
     public ChangeCommand(EUMLModelImplementation modelImplementation,
 34  
             Runnable runnable, String label) {
 35  0
         super(modelImplementation.getEditingDomain(), runnable, label);
 36  0
         modelImpl = modelImplementation;
 37  0
     }
 38  
 
 39  
     public ChangeCommand(EUMLModelImplementation modelImplementation,
 40  
             Runnable runnable, String label, Object... objects) {
 41  0
         super(modelImplementation.getEditingDomain(), runnable, label);
 42  0
         if (!isValid(label, objects)) {
 43  0
             throw new IllegalArgumentException(
 44  
                     "The label is not compatible with the # of objects"); //$NON-NLS-1$
 45  
         }
 46  0
         this.objects = objects;
 47  0
         modelImpl = modelImplementation;
 48  0
     }
 49  
 
 50  
     /**
 51  
      * TODO: Document! What does this do?  Interacts with event pump in some manner
 52  
      * 
 53  
      * @param objects new objeccts
 54  
      */
 55  
     public void setObjects(Object... objects) {
 56  0
         if (!isValid(label, objects)) {
 57  0
             throw new IllegalArgumentException(
 58  
                     "The label is not compatible with the # of objects"); //$NON-NLS-1$
 59  
         }
 60  0
         this.objects = objects;
 61  0
         modelImpl.getModelEventPump().notifyChanged(
 62  
                 new NotificationImpl(
 63  
                         ModelEventPumpEUMLImpl.COMMAND_STACK_UPDATE, false,
 64  
                         false));
 65  0
     }
 66  
 
 67  
     @Override
 68  
     public String getLabel() {
 69  0
         if (objects == null) {
 70  0
             return label;
 71  
         }
 72  0
         StringBuilder sb = new StringBuilder();
 73  0
         int j = 0;
 74  0
         for (int i = 0; i < label.length(); i++) {
 75  0
             if (label.charAt(i) == '#') {
 76  0
                 sb.append(UMLUtil.toString(objects[j]));
 77  0
                 j++;
 78  
             } else {
 79  0
                 sb.append(label.charAt(i));
 80  
             }
 81  
         }
 82  0
         return sb.toString();
 83  
     }
 84  
 
 85  
     private boolean isValid(String label, Object objects[]) {
 86  0
         if (objects == null) {
 87  0
             return true;
 88  
         }
 89  0
         int i = 0;
 90  0
         for (int j = 0; j < label.length(); j++) {
 91  0
             if (label.charAt(j) == '#') {
 92  0
                 i++;
 93  
             }
 94  
         }
 95  0
         return i == objects.length;
 96  
     }
 97  
 
 98  
 }