Coverage Report - org.argouml.cognitive.ui.AddToDoItemDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
AddToDoItemDialog
0%
0/64
0%
0/12
3.333
 
 1  
 /* $Id: AddToDoItemDialog.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  
  *    bobtarling
 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.Insets;
 42  
 import java.awt.event.ActionEvent;
 43  
 
 44  
 import javax.swing.DefaultListModel;
 45  
 import javax.swing.JComboBox;
 46  
 import javax.swing.JLabel;
 47  
 import javax.swing.JList;
 48  
 import javax.swing.JPanel;
 49  
 import javax.swing.JScrollPane;
 50  
 import javax.swing.JTextArea;
 51  
 import javax.swing.JTextField;
 52  
 import javax.swing.ListCellRenderer;
 53  
 
 54  
 import org.argouml.cognitive.Designer;
 55  
 import org.argouml.cognitive.ListSet;
 56  
 import org.argouml.cognitive.ToDoItem;
 57  
 import org.argouml.cognitive.Translator;
 58  
 import org.argouml.ui.targetmanager.TargetManager;
 59  
 import org.argouml.uml.cognitive.UMLToDoItem;
 60  
 import org.argouml.util.ArgoDialog;
 61  
 import org.tigris.swidgets.Dialog;
 62  
 import org.tigris.swidgets.LabelledLayout;
 63  
 
 64  
 /**
 65  
  * The dialog to enter a new ToDoItem.
 66  
  */
 67  
 public class AddToDoItemDialog extends ArgoDialog {
 68  
 
 69  
     ////////////////////////////////////////////////////////////////
 70  
     // constants
 71  0
     private static final String[] PRIORITIES = {
 72  
         Translator.localize("misc.level.high"),
 73  
         Translator.localize("misc.level.medium"),
 74  
         Translator.localize("misc.level.low"),
 75  
     };
 76  
     private static final int TEXT_ROWS = 8;
 77  
     private static final int TEXT_COLUMNS = 30;
 78  
     /** Insets in pixels  */
 79  
     private static final int INSET_PX = 3;
 80  
 
 81  
     ////////////////////////////////////////////////////////////////
 82  
     // instance variables
 83  
     private JTextField headLineTextField;
 84  
     private JComboBox  priorityComboBox;
 85  
     private JTextField moreinfoTextField;
 86  
     private JList offenderList;
 87  
     private JTextArea  descriptionTextArea;
 88  
 
 89  
 
 90  
     /**
 91  
      * Create a new AddToDoItemDialog
 92  
      * @param renderer the ListCellRenderer to use in order
 93  
      *                 to display the offenders
 94  
      */
 95  
     public AddToDoItemDialog(ListCellRenderer renderer) {
 96  0
         super(Translator.localize("dialog.title.add-todo-item"),
 97  
               Dialog.OK_CANCEL_OPTION, true);
 98  
 
 99  0
         headLineTextField = new JTextField(TEXT_COLUMNS);
 100  0
         priorityComboBox = new JComboBox(PRIORITIES);
 101  0
         moreinfoTextField = new JTextField(TEXT_COLUMNS);
 102  0
         descriptionTextArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS);
 103  
 
 104  0
         DefaultListModel dlm = new DefaultListModel();
 105  0
         Object[] offObj =
 106  
             TargetManager.getInstance().getModelTargets().toArray();
 107  0
         for (int i = 0; i < offObj.length; i++) {
 108  0
             if (offObj[i] != null) {
 109  0
                 dlm.addElement(offObj[i]);
 110  
             }
 111  
         }
 112  
 
 113  0
         offenderList = new JList(dlm);
 114  0
         offenderList.setCellRenderer(renderer);
 115  0
         JScrollPane offenderScroll = new JScrollPane(offenderList);
 116  0
         offenderScroll.setOpaque(true);
 117  
 
 118  0
         JLabel headlineLabel =
 119  
             new JLabel(Translator.localize("label.headline"));
 120  0
         JLabel priorityLabel =
 121  
             new JLabel(Translator.localize("label.priority"));
 122  0
         JLabel moreInfoLabel =
 123  
             new JLabel(Translator.localize("label.more-info-url"));
 124  0
         JLabel offenderLabel =
 125  
             new JLabel(Translator.localize("label.offenders"));
 126  0
         priorityComboBox.setSelectedItem(PRIORITIES[0]);
 127  
 
 128  0
         JPanel panel = new JPanel(new LabelledLayout(getLabelGap(),
 129  
                 getComponentGap()));
 130  
 
 131  0
         headlineLabel.setLabelFor(headLineTextField);
 132  0
         panel.add(headlineLabel);
 133  0
         panel.add(headLineTextField);
 134  
 
 135  0
         priorityLabel.setLabelFor(priorityComboBox);
 136  0
         panel.add(priorityLabel);
 137  0
         panel.add(priorityComboBox);
 138  
 
 139  0
         moreInfoLabel.setLabelFor(moreinfoTextField);
 140  0
         panel.add(moreInfoLabel);
 141  0
         panel.add(moreinfoTextField);
 142  
 
 143  0
         offenderLabel.setLabelFor(offenderScroll);
 144  0
         panel.add(offenderLabel);
 145  0
         panel.add(offenderScroll);
 146  
 
 147  0
         descriptionTextArea.setLineWrap(true);  //MVW - Issue 2422
 148  0
         descriptionTextArea.setWrapStyleWord(true);   //MVW - Issue 2422
 149  0
         descriptionTextArea.setText(Translator.localize("label.enter-todo-item")
 150  
                             + "\n");
 151  0
         descriptionTextArea.setMargin(new Insets(INSET_PX, INSET_PX,
 152  
                 INSET_PX, INSET_PX));
 153  0
         JScrollPane descriptionScroller = new JScrollPane(descriptionTextArea);
 154  0
         descriptionScroller.setPreferredSize(
 155  
                 descriptionTextArea.getPreferredSize());
 156  0
         panel.add(descriptionScroller);
 157  
 
 158  0
         setContent(panel);
 159  0
     }
 160  
 
 161  
 
 162  
     /*
 163  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 164  
      */
 165  
     @Override
 166  
     public void actionPerformed(ActionEvent e) {
 167  0
         super.actionPerformed(e);
 168  0
         if (e.getSource() == getOkButton()) {
 169  0
             doAdd();
 170  
         }
 171  0
     }
 172  
 
 173  
     private void doAdd() {
 174  0
         Designer designer = Designer.theDesigner();
 175  0
         String headline = headLineTextField.getText();
 176  0
         int priority = ToDoItem.HIGH_PRIORITY;
 177  0
         switch (priorityComboBox.getSelectedIndex()) {
 178  
         case 0:
 179  0
             priority = ToDoItem.HIGH_PRIORITY;
 180  0
             break;
 181  
         case 1:
 182  0
             priority = ToDoItem.MED_PRIORITY;
 183  0
             break;
 184  
         case 2:
 185  0
             priority = ToDoItem.LOW_PRIORITY;
 186  
             break;
 187  
         }
 188  0
         String desc = descriptionTextArea.getText();
 189  0
         String moreInfoURL = moreinfoTextField.getText();
 190  0
         ListSet newOffenders = new ListSet();
 191  0
         for (int i = 0; i < offenderList.getModel().getSize(); i++) {
 192  0
             newOffenders.add(offenderList.getModel().getElementAt(i));
 193  
         }
 194  0
         ToDoItem item =
 195  
             new UMLToDoItem(designer, headline, priority, desc, moreInfoURL, newOffenders);
 196  0
         designer.getToDoList().addElement(item); //? inform()
 197  0
         Designer.firePropertyChange(Designer.MODEL_TODOITEM_ADDED, null, item);
 198  0
     }
 199  
 }
 200