Coverage Report - org.argouml.cognitive.ui.TabToDo
 
Classes in this File Line Coverage Branch Coverage Complexity
TabToDo
70%
55/78
44%
8/18
1.529
 
 1  
 /* $Id: TabToDo.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  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2007 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.BorderLayout;
 42  
 import java.awt.event.ComponentEvent;
 43  
 import java.awt.event.ComponentListener;
 44  
 
 45  
 import javax.swing.Action;
 46  
 import javax.swing.JPanel;
 47  
 import javax.swing.JToolBar;
 48  
 import javax.swing.SwingConstants;
 49  
 
 50  
 import org.argouml.application.api.AbstractArgoJPanel;
 51  
 import org.argouml.cognitive.ToDoItem;
 52  
 import org.argouml.cognitive.critics.Wizard;
 53  
 import org.argouml.configuration.Configuration;
 54  
 import org.argouml.swingext.LeftArrowIcon;
 55  
 import org.argouml.ui.TabToDoTarget;
 56  
 import org.argouml.ui.targetmanager.TargetEvent;
 57  
 import org.argouml.ui.targetmanager.TargetManager;
 58  
 import org.tigris.swidgets.BorderSplitPane;
 59  
 import org.tigris.swidgets.Horizontal;
 60  
 import org.tigris.swidgets.Vertical;
 61  
 import org.tigris.toolbar.ToolBarFactory;
 62  
 
 63  
 /**
 64  
  * The ToDo Tab.
 65  
  *
 66  
  */
 67  
 public class TabToDo extends AbstractArgoJPanel 
 68  
     implements TabToDoTarget, ComponentListener {
 69  
     
 70  
     private static int numHushes;
 71  
 
 72  900
     private static final Action actionNewToDoItem = new ActionNewToDoItem();
 73  900
     private static final ToDoItemAction actionResolve = new ActionResolve();
 74  900
     private static final ToDoItemAction actionSnooze = new ActionSnooze();
 75  
 
 76  900
     private WizDescription description = new WizDescription();
 77  
     private JPanel lastPanel;
 78  
     private BorderSplitPane splitPane;
 79  
     private Object target;
 80  
 
 81  
     /**
 82  
      * Increment the number of times we've been "snoozed" (or hushed).
 83  
      */
 84  
     public static void incrementNumHushes() {
 85  0
         numHushes++;
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Construct a ToDo tab for the property panel.
 90  
      */
 91  
     public TabToDo() {
 92  900
         super("tab.todo-item");
 93  900
         setIcon(new LeftArrowIcon());
 94  
 
 95  900
         String position =
 96  
             Configuration.getString(Configuration.makeKey("layout",
 97  
                                                           "tabtodo"));
 98  900
         setOrientation(
 99  
             ((position.equals("West") || position.equals("East"))
 100  
              ? Vertical.getInstance() : Horizontal.getInstance()));
 101  
 
 102  900
         setLayout(new BorderLayout());
 103  
 
 104  900
         Object[] actions = {actionNewToDoItem, actionResolve, actionSnooze };
 105  900
         ToolBarFactory factory = new ToolBarFactory(actions);
 106  900
         factory.setRollover(true);
 107  900
         factory.setFloatable(false);
 108  900
         factory.setOrientation(SwingConstants.VERTICAL);
 109  900
         JToolBar toolBar = factory.createToolBar();
 110  900
         toolBar.setName(getTitle());
 111  900
         add(toolBar, BorderLayout.WEST);
 112  
 
 113  900
         splitPane = new BorderSplitPane();
 114  900
         add(splitPane, BorderLayout.CENTER);
 115  900
         setTarget(null);
 116  
         
 117  900
         addComponentListener(this);
 118  
         
 119  
         // TODO: Register listener for target ToDo item changes
 120  
         // and for new showStep() requests
 121  900
     }
 122  
 
 123  
     /**
 124  
      * Show the description of a todo item.
 125  
      */
 126  
     public void showDescription() {
 127  2291
         if (lastPanel != null) {
 128  1391
             splitPane.remove(lastPanel);
 129  
         }
 130  2291
         splitPane.add(description, BorderSplitPane.CENTER);
 131  2291
         lastPanel = description;
 132  2291
         validate();
 133  2291
         repaint();
 134  2291
     }
 135  
 
 136  
     /**
 137  
      * @param tdp the todo pane
 138  
      */
 139  
     public void setTree(ToDoPane tdp) {
 140  0
         if (getOrientation().equals(Horizontal.getInstance())) {
 141  0
             splitPane.add(tdp, BorderSplitPane.WEST);
 142  
         } else {
 143  0
             splitPane.add(tdp, BorderSplitPane.NORTH);
 144  
         }
 145  0
     }
 146  
 
 147  
     /**
 148  
      * @param ws the panel to be shown
 149  
      */
 150  
     public void showStep(JPanel ws) {
 151  
         // TODO: This should listen for new target events 
 152  
         // fired by WizStep.updateTabToDo so that we
 153  
         // can decouple it from the ProjectBrowser.
 154  0
         if (lastPanel != null) {
 155  0
             splitPane.remove(lastPanel);
 156  
         }
 157  0
         if (ws != null) {
 158  0
             splitPane.add(ws, BorderSplitPane.CENTER);
 159  0
             lastPanel = ws;
 160  
         } else {
 161  0
             splitPane.add(description, BorderSplitPane.CENTER);
 162  0
             lastPanel = description;
 163  
         }
 164  0
         validate();
 165  0
         repaint();
 166  0
     }
 167  
 
 168  
     /**
 169  
      * Sets the target of the TabToDo.
 170  
      *
 171  
      * @param item the new target
 172  
      */
 173  
     public void setTarget(Object item) {
 174  2353
         target = item;
 175  2353
         if (isVisible()) {
 176  1152
             setTargetInternal(item);
 177  
         }
 178  
         
 179  
         // Request that we be made visible if we're not?
 180  
         // topLevelTabbedPane.setSelectedComponent(t);
 181  2353
     }
 182  
 
 183  
     private void setTargetInternal(Object item) {
 184  
         // the target of description will always be set directly by tabtodo
 185  2291
         description.setTarget(item);
 186  2291
         Wizard w = null;
 187  2291
         if (item instanceof ToDoItem) {
 188  0
             w = ((ToDoItem) item).getWizard();
 189  
         }
 190  2291
         if (w != null) {
 191  0
             showStep(w.getCurrentPanel());
 192  
         } else {
 193  2291
             showDescription();
 194  
         }
 195  2291
         updateActionsEnabled(item);
 196  2291
     }
 197  
 
 198  
    /**
 199  
     * Returns the target of the TabToDo.
 200  
     *
 201  
     * @return The current target of the TabToDo
 202  
     */
 203  
     public Object getTarget() {
 204  0
         return target;
 205  
     }
 206  
 
 207  
 
 208  
     /**
 209  
      * Set the target again to what it was before.
 210  
      */
 211  
     public void refresh() {
 212  0
         setTarget(TargetManager.getInstance().getTarget());
 213  0
     }
 214  
 
 215  
     /**
 216  
      * Update the "enabled" state of the resolve and snooze actions.
 217  
      * 
 218  
      * @param item  the target of the TabToDo class
 219  
      */
 220  
     protected static void updateActionsEnabled(Object item) {
 221  2291
         actionResolve.setEnabled(actionResolve.isEnabled());
 222  2291
         actionResolve.updateEnabled(item);
 223  2291
         actionSnooze.setEnabled(actionSnooze.isEnabled());
 224  2291
         actionSnooze.updateEnabled(item);
 225  2291
     }
 226  
 
 227  
     /*
 228  
      * @see org.argouml.ui.targetmanager.TargetListener#targetAdded(
 229  
      *          TargetEvent)
 230  
      */
 231  
     public void targetAdded(TargetEvent e) {
 232  0
         setTarget(e.getNewTarget());
 233  0
     }
 234  
 
 235  
     /*
 236  
      * @see org.argouml.ui.targetmanager.TargetListener#targetRemoved(
 237  
      *          TargetEvent)
 238  
      */
 239  
     public void targetRemoved(TargetEvent e) {
 240  
         // how to handle empty target lists?
 241  
         // probably the wizstep should only show an empty pane in that case
 242  88
         setTarget(e.getNewTarget());
 243  88
     }
 244  
 
 245  
     /*
 246  
      * @see org.argouml.ui.targetmanager.TargetListener#targetSet(TargetEvent)
 247  
      */
 248  
     public void targetSet(TargetEvent e) {
 249  1239
         setTarget(e.getNewTarget());
 250  1239
     }
 251  
 
 252  
     /**
 253  
      * The UID.
 254  
      */
 255  
     private static final long serialVersionUID = 4819730646847978729L;
 256  
 
 257  
     /*
 258  
      * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
 259  
      */
 260  
     public void componentShown(ComponentEvent e) {
 261  
         // Update our model with our saved target
 262  126
         setTargetInternal(target);
 263  126
     }
 264  
     
 265  
     /*
 266  
      * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
 267  
      */
 268  
     public void componentHidden(ComponentEvent e) {
 269  
         // Stop updating model when we're not visible
 270  1013
         setTargetInternal(null);
 271  1013
     }
 272  
 
 273  
     public void componentMoved(ComponentEvent e) {
 274  
         // ignored
 275  900
     }
 276  
 
 277  
     public void componentResized(ComponentEvent e) {
 278  
         // ignored
 279  900
     }
 280  
 
 281  
     
 282  
 }