Coverage Report - org.argouml.uml.cognitive.critics.WizBreakCircularComp
 
Classes in this File Line Coverage Branch Coverage Complexity
WizBreakCircularComp
0%
0/91
0%
0/52
5.75
 
 1  
 /* $Id: WizBreakCircularComp.java 17849 2010-01-12 19:50:34Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 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  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2006 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.cognitive.critics;
 40  
 
 41  
 import java.util.ArrayList;
 42  
 import java.util.Collection;
 43  
 import java.util.Iterator;
 44  
 import java.util.List;
 45  
 
 46  
 import javax.swing.JPanel;
 47  
 
 48  
 import org.apache.log4j.Logger;
 49  
 import org.argouml.cognitive.ListSet;
 50  
 import org.argouml.cognitive.ToDoItem;
 51  
 import org.argouml.cognitive.ui.WizStepChoice;
 52  
 import org.argouml.cognitive.ui.WizStepConfirm;
 53  
 import org.argouml.i18n.Translator;
 54  
 import org.argouml.model.Model;
 55  
 
 56  
 /**
 57  
  * A non-modal wizard to help the user change select an association
 58  
  * to make non-aggregate.
 59  
  */
 60  
 public class WizBreakCircularComp extends UMLWizard {
 61  0
     private static final Logger LOG =
 62  
         Logger.getLogger(WizBreakCircularComp.class);
 63  
 
 64  0
     private String instructions1 = 
 65  
         Translator.localize("critics.WizBreakCircularComp-ins1");
 66  
 
 67  0
     private String instructions2 = 
 68  
         Translator.localize("critics.WizBreakCircularComp-ins2");
 69  
 
 70  0
     private String instructions3 = 
 71  
         Translator.localize("critics.WizBreakCircularComp-ins3");
 72  
 
 73  0
     private WizStepChoice step1 = null;
 74  0
     private WizStepChoice step2 = null;
 75  0
     private WizStepConfirm step3 = null;
 76  
 
 77  0
     private Object selectedCls = null;
 78  0
     private Object selectedAsc = null;
 79  
 
 80  
     /**
 81  
      * The constructor.
 82  
      */
 83  0
     public WizBreakCircularComp() { }
 84  
 
 85  
     /*
 86  
      * @see org.argouml.cognitive.ui.Wizard#getNumSteps()
 87  
      */
 88  
     @Override
 89  
     public int getNumSteps() {
 90  0
         return 3;
 91  
     }
 92  
 
 93  
     /**
 94  
      * @return The choices for this step.
 95  
      */
 96  
     protected List<String> getOptions1() {
 97  0
         List<String> result = new ArrayList<String>();
 98  0
         if (getToDoItem() != null) {
 99  0
             ToDoItem item = (ToDoItem) getToDoItem();
 100  0
             for (Object me : item.getOffenders()) {
 101  0
                 String s = Model.getFacade().getName(me);
 102  0
                 result.add(s);
 103  0
             }
 104  
         }
 105  0
         return result;
 106  
     }
 107  
 
 108  
     /**
 109  
      * @return The choices for this step.
 110  
      */
 111  
     protected List<String> getOptions2() {
 112  0
         List<String> result = new ArrayList<String>();
 113  0
         if (selectedCls != null) {
 114  0
             Collection aes = Model.getFacade().getAssociationEnds(selectedCls);
 115  0
             Object fromType = selectedCls;
 116  0
             String fromName = Model.getFacade().getName(fromType);
 117  0
             for (Iterator iter = aes.iterator(); iter.hasNext();) {
 118  0
                 Object fromEnd = iter.next();
 119  0
                 Object asc = Model.getFacade().getAssociation(fromEnd);
 120  0
                 Object toEnd =
 121  
                     new ArrayList(Model.getFacade().getConnections(asc)).get(0);
 122  0
                 if (toEnd == fromEnd) {
 123  0
                     toEnd = new ArrayList(
 124  
                             Model.getFacade().getConnections(asc)).get(1);
 125  
                 }
 126  0
                 Object toType = Model.getFacade().getType(toEnd);
 127  0
                 String ascName = Model.getFacade().getName(asc);
 128  0
                 String toName = Model.getFacade().getName(toType);
 129  0
                 String s = ascName 
 130  
                     + " " 
 131  
                     + Translator.localize("critics.WizBreakCircularComp-from") 
 132  
                     + fromName
 133  
                     + " "
 134  
                     + Translator.localize("critics.WizBreakCircularComp-to")
 135  
                     + " "
 136  
                     + toName;
 137  0
                 result.add(s);
 138  0
             }
 139  
         }
 140  0
         return result;
 141  
     }
 142  
 
 143  
     /*
 144  
      * @see org.argouml.cognitive.ui.Wizard#makePanel(int)
 145  
      */
 146  
     public JPanel makePanel(int newStep) {
 147  0
         switch (newStep) {
 148  
         case 1:
 149  0
             if (step1 == null) {
 150  0
                 step1 = new WizStepChoice(this, instructions1, getOptions1());
 151  0
                 step1.setTarget(getToDoItem());
 152  
             }
 153  0
             return step1;
 154  
         case 2:
 155  0
             if (step2 == null) {
 156  0
                 step2 = new WizStepChoice(this, instructions2, getOptions2());
 157  0
                 step2.setTarget(getToDoItem());
 158  
             }
 159  0
             return step2;
 160  
         case 3:
 161  0
             if (step3 == null) {
 162  0
                 step3 = new WizStepConfirm(this, instructions3);
 163  
             }
 164  0
             return step3;
 165  
         }
 166  0
         return null;
 167  
     }
 168  
 
 169  
     /*
 170  
      * @see org.argouml.cognitive.ui.Wizard#doAction(int)
 171  
      */
 172  
     public void doAction(int oldStep) {
 173  0
         LOG.debug("doAction " + oldStep);
 174  0
         int choice = -1;
 175  0
         ToDoItem item = (ToDoItem) getToDoItem();
 176  0
         ListSet offs = item.getOffenders();
 177  0
         switch (oldStep) {
 178  
         case 1:
 179  0
             if (step1 != null) {
 180  0
                 choice = step1.getSelectedIndex();
 181  
             }
 182  0
             if (choice == -1) {
 183  0
                 throw new Error("nothing selected, should not get here");
 184  
             }
 185  0
             selectedCls = offs.get(choice);
 186  0
             break;
 187  
             ////////////////
 188  
         case 2:
 189  0
             if (step2 != null) {
 190  0
                 choice = step2.getSelectedIndex();
 191  
             }
 192  0
             if (choice == -1) {
 193  0
                 throw new Error("nothing selected, should not get here");
 194  
             }
 195  0
             Object ae = null;
 196  0
             Iterator iter =
 197  
                 Model.getFacade().getAssociationEnds(selectedCls).iterator();
 198  0
             for (int n = 0; n <= choice; n++) {
 199  0
                 ae = iter.next();
 200  
             }
 201  0
             selectedAsc = Model.getFacade().getAssociation(ae);
 202  0
             break;
 203  
             ////////////////
 204  
         case 3:
 205  0
             if (selectedAsc != null) {
 206  0
                 List conns = new ArrayList(
 207  
                         Model.getFacade().getConnections(selectedAsc));
 208  0
                 Object ae0 = conns.get(0);
 209  0
                 Object ae1 = conns.get(1);
 210  
                 try {
 211  0
                     Model.getCoreHelper().setAggregation(
 212  
                             ae0,
 213  
                             Model.getAggregationKind().getNone());
 214  0
                     Model.getCoreHelper().setAggregation(
 215  
                             ae1,
 216  
                             Model.getAggregationKind().getNone());
 217  0
                 } catch (Exception pve) {
 218  0
                     LOG.error("could not set aggregation", pve);
 219  0
                 }
 220  
             }
 221  
             break;
 222  
         }
 223  0
     }
 224  
 
 225  
     /*
 226  
      * @see org.argouml.cognitive.ui.Wizard#canGoNext()
 227  
      */
 228  
     @Override
 229  
     public boolean canGoNext() {
 230  0
         return canFinish();
 231  
     }
 232  
 
 233  
     /*
 234  
      * @see org.argouml.cognitive.ui.Wizard#canFinish()
 235  
      */
 236  
     @Override
 237  
     public boolean canFinish() {
 238  0
         if (!super.canFinish()) {
 239  0
             return false;
 240  
         }
 241  0
         if (getStep() == 0) {
 242  0
             return true;
 243  
         }
 244  0
         if (getStep() == 1 && step1 != null && step1.getSelectedIndex() != -1) {
 245  0
             return true;
 246  
         }
 247  0
         if (getStep() == 2 && step2 != null && step2.getSelectedIndex() != -1) {
 248  0
             return true;
 249  
         }
 250  0
         return false;
 251  
     }
 252  
 }