Coverage Report - org.argouml.cognitive.ui.DismissToDoItemDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
DismissToDoItemDialog
0%
0/72
0%
0/2
1.5
DismissToDoItemDialog$1
0%
0/9
0%
0/6
1.5
DismissToDoItemDialog$2
0%
0/3
N/A
1.5
DismissToDoItemDialog$3
0%
0/3
N/A
1.5
DismissToDoItemDialog$4
0%
0/5
N/A
1.5
 
 1  
 /* $Id: DismissToDoItemDialog.java 17818 2010-01-12 18:39:46Z 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  
  *    mvw
 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.cognitive.ui;
 40  
 
 41  
 import java.awt.GridBagConstraints;
 42  
 import java.awt.GridBagLayout;
 43  
 import java.awt.Insets;
 44  
 import java.awt.event.ActionEvent;
 45  
 import java.awt.event.ActionListener;
 46  
 
 47  
 import javax.swing.ButtonGroup;
 48  
 import javax.swing.JLabel;
 49  
 import javax.swing.JOptionPane;
 50  
 import javax.swing.JPanel;
 51  
 import javax.swing.JRadioButton;
 52  
 import javax.swing.JScrollPane;
 53  
 import javax.swing.JTextArea;
 54  
 
 55  
 import org.apache.log4j.Logger;
 56  
 import org.argouml.cognitive.Designer;
 57  
 import org.argouml.cognitive.ToDoItem;
 58  
 import org.argouml.cognitive.ToDoList;
 59  
 import org.argouml.cognitive.Translator;
 60  
 import org.argouml.cognitive.UnresolvableException;
 61  
 import org.argouml.util.ArgoDialog;
 62  
 import org.tigris.swidgets.Dialog;
 63  
 
 64  
 /**
 65  
  * The dialog to dismiss todo items.
 66  
  *
 67  
  */
 68  0
 public class DismissToDoItemDialog extends ArgoDialog {
 69  
 
 70  0
     private static final Logger LOG =
 71  
         Logger.getLogger(DismissToDoItemDialog.class);
 72  
 
 73  
     ////////////////////////////////////////////////////////////////
 74  
     // instance variables
 75  
 
 76  
     private JRadioButton    badGoalButton;
 77  
     private JRadioButton    badDecButton;
 78  
     private JRadioButton    explainButton;
 79  
     private ButtonGroup     actionGroup;
 80  
     private JTextArea       explanation;
 81  
     private ToDoItem        target;
 82  
 
 83  
     ////////////////////////////////////////////////////////////////
 84  
     // constructors
 85  
 
 86  
     /**
 87  
      * The constructor.
 88  
      */
 89  
     public DismissToDoItemDialog() {
 90  0
         super(
 91  
             Translator.localize("dialog.title.dismiss-todo-item"),
 92  
             Dialog.OK_CANCEL_OPTION,
 93  
             true);
 94  
 
 95  0
         JLabel instrLabel =
 96  
             new JLabel(Translator.localize("label.remove-item"));
 97  
 
 98  0
         badGoalButton = new JRadioButton(Translator.localize(
 99  
             "button.not-relevant-to-my-goals"));
 100  0
         badDecButton = new JRadioButton(Translator.localize(
 101  
             "button.not-of-concern-at-moment"));
 102  0
         explainButton = new JRadioButton(Translator.localize(
 103  
             "button.reason-given-below"));
 104  
 
 105  0
         badGoalButton.setMnemonic(
 106  
             Translator.localize(
 107  
                 "button.not-relevant-to-my-goals.mnemonic")
 108  
                 .charAt(0));
 109  0
         badDecButton.setMnemonic(
 110  
             Translator.localize(
 111  
                 "button.not-of-concern-at-moment.mnemonic")
 112  
                 .charAt(0));
 113  0
         explainButton.setMnemonic(
 114  
             Translator.localize("button.reason-given-below.mnemonic").charAt(
 115  
                 0));
 116  
 
 117  0
         JPanel content = new JPanel();
 118  
 
 119  0
         GridBagLayout gb = new GridBagLayout();
 120  0
         GridBagConstraints c = new GridBagConstraints();
 121  
 
 122  0
         c.fill = GridBagConstraints.BOTH;
 123  0
         c.weightx = 1.0;
 124  0
         c.gridwidth = 2;
 125  
 
 126  0
         content.setLayout(gb);
 127  
 
 128  0
         explanation = new JTextArea(6, 40);
 129  0
         explanation.setLineWrap(true);
 130  0
         explanation.setWrapStyleWord(true);
 131  0
         JScrollPane explain = new JScrollPane(explanation);
 132  
 
 133  0
         c.gridx = 0;
 134  0
         c.gridy = 0;
 135  
 
 136  0
         gb.setConstraints(instrLabel, c);
 137  0
         content.add(instrLabel);
 138  
 
 139  0
         c.gridy = 1;
 140  0
         c.insets = new Insets(5, 0, 0, 0);
 141  
 
 142  0
         gb.setConstraints(badGoalButton, c);
 143  0
         content.add(badGoalButton);
 144  
 
 145  0
         c.gridy = 2;
 146  
 
 147  0
         gb.setConstraints(badDecButton, c);
 148  0
         content.add(badDecButton);
 149  
 
 150  0
         c.gridy = 3;
 151  
 
 152  0
         gb.setConstraints(explainButton, c);
 153  0
         content.add(explainButton);
 154  
 
 155  0
         c.gridy = 4;
 156  0
         c.weighty = 1.0;
 157  
 
 158  0
         gb.setConstraints(explain, c);
 159  0
         content.add(explain);
 160  
 
 161  0
         setContent(content);
 162  
 
 163  0
         getOkButton().addActionListener(new ActionListener() {
 164  
             public void actionPerformed(ActionEvent e) {
 165  0
                 if (badGoalButton.getModel().isSelected()) {
 166  0
                     badGoal(e);
 167  
                 }
 168  0
                 else if (badDecButton.getModel().isSelected()) {
 169  0
                     badDec(e);
 170  
                 }
 171  0
                 else if (explainButton.getModel().isSelected()) {
 172  0
                     explain(e);
 173  
                 }
 174  
                 else {
 175  0
                     LOG.warn("DissmissToDoItemDialog: Unknown action: " + e);
 176  
                 }
 177  0
             }
 178  
         });
 179  
 
 180  0
         actionGroup = new ButtonGroup();
 181  0
         actionGroup.add(badGoalButton);
 182  0
         actionGroup.add(badDecButton);
 183  0
         actionGroup.add(explainButton);
 184  0
         actionGroup.setSelected(explainButton.getModel(), true);
 185  
 
 186  0
         explanation.setText(
 187  
             Translator.localize("label.enter-rationale-here"));
 188  
 
 189  0
         badGoalButton.addActionListener(new ActionListener() {
 190  
             public void actionPerformed(ActionEvent e) {
 191  0
                 explanation.setEnabled(false);
 192  0
             }
 193  
         });
 194  0
         badDecButton.addActionListener(new ActionListener() {
 195  
             public void actionPerformed(ActionEvent e) {
 196  0
                 explanation.setEnabled(false);
 197  0
             }
 198  
         });
 199  0
         explainButton.addActionListener(new ActionListener() {
 200  
             public void actionPerformed(ActionEvent e) {
 201  0
                 explanation.setEnabled(true);
 202  0
                 explanation.requestFocus();
 203  0
                 explanation.selectAll();
 204  0
             }
 205  
         });
 206  0
     }
 207  
 
 208  
     /**
 209  
      * @param t the new target object (ToDoItem)
 210  
      */
 211  
     public void setTarget(Object t) {
 212  0
         target = (ToDoItem) t;
 213  0
     }
 214  
 
 215  
     /*
 216  
      * Prepare for typing in rationale field when window is opened.
 217  
      *
 218  
      * @see java.awt.Component#setVisible(boolean)
 219  
      */
 220  
     public void setVisible(boolean b) {
 221  0
         super.setVisible(b);
 222  0
         if (b) {
 223  0
             explanation.requestFocus();
 224  0
             explanation.selectAll();
 225  
         }
 226  0
     }
 227  
 
 228  
     ////////////////////////////////////////////////////////////////
 229  
     // event handlers
 230  
 
 231  
     private void badGoal(ActionEvent e) {
 232  
         //cat.debug("bad goal");
 233  0
         GoalsDialog d = new GoalsDialog();
 234  0
         d.setVisible(true);
 235  0
     }
 236  
 
 237  
     private void badDec(ActionEvent e) {
 238  
         //cat.debug("bad decision");
 239  0
         DesignIssuesDialog d = new DesignIssuesDialog();
 240  0
         d.setVisible(true);
 241  0
     }
 242  
 
 243  
     private void explain(ActionEvent e) {
 244  
         //TODO: make a new history item
 245  0
         ToDoList list = Designer.theDesigner().getToDoList();
 246  
         try {
 247  0
             list.explicitlyResolve(target, explanation.getText());
 248  0
             Designer.firePropertyChange(
 249  
                     Designer.MODEL_TODOITEM_DISMISSED, null, null);
 250  
         }
 251  0
         catch (UnresolvableException ure) {
 252  0
             LOG.error("Resolve failed (ure): ", ure);
 253  0
             JOptionPane.showMessageDialog(
 254  
                     this,
 255  
                     ure.getMessage(),
 256  
                     Translator.localize("optionpane.dismiss-failed"),
 257  
                     JOptionPane.ERROR_MESSAGE);
 258  0
         }
 259  0
     }
 260  
 } /* end class DismissToDoItemDialog */