Coverage Report - org.argouml.ui.FindDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
FindDialog
69%
184/265
15%
6/40
1.88
PredicateMType
57%
12/21
100%
2/2
1.88
 
 1  
 /* $Id: FindDialog.java 18647 2010-08-17 00:25:51Z bobtarling $
 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-2008 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.ui;
 40  
 
 41  
 import java.awt.BorderLayout;
 42  
 import java.awt.Color;
 43  
 import java.awt.Dimension;
 44  
 import java.awt.GridBagConstraints;
 45  
 import java.awt.GridBagLayout;
 46  
 import java.awt.GridLayout;
 47  
 import java.awt.Insets;
 48  
 import java.awt.Rectangle;
 49  
 import java.awt.event.ActionEvent;
 50  
 import java.awt.event.ActionListener;
 51  
 import java.awt.event.MouseEvent;
 52  
 import java.awt.event.MouseListener;
 53  
 import java.util.ArrayList;
 54  
 import java.util.List;
 55  
 
 56  
 import javax.swing.JButton;
 57  
 import javax.swing.JComboBox;
 58  
 import javax.swing.JLabel;
 59  
 import javax.swing.JPanel;
 60  
 import javax.swing.JScrollPane;
 61  
 import javax.swing.JTabbedPane;
 62  
 import javax.swing.JTextArea;
 63  
 import javax.swing.border.EmptyBorder;
 64  
 
 65  
 import org.argouml.application.api.AbstractArgoJPanel;
 66  
 import org.argouml.i18n.Translator;
 67  
 import org.argouml.kernel.ProjectManager;
 68  
 import org.argouml.model.Model;
 69  
 import org.argouml.swingext.SpacerPanel;
 70  
 import org.argouml.uml.PredicateSearch;
 71  
 import org.argouml.util.ArgoDialog;
 72  
 import org.argouml.util.Predicate;
 73  
 import org.argouml.util.PredicateStringMatch;
 74  
 import org.argouml.util.PredicateType;
 75  
 
 76  
 
 77  
 /**
 78  
  * Main dialog for Find function.
 79  
  *
 80  
  * This is one of the few dialog boxes in Argo that is
 81  
  * non-modal (so that the user can keep the results on
 82  
  * the screen while they work with them).<p>
 83  
  *
 84  
  * The search is buggy and needs work.
 85  
  * <p>
 86  
  * NOTE: An incompatible change was made to the public API for this class
 87  
  * before the release of ArgoUML 0.26 to remove exposed internal implementation
 88  
  * details (GEF).
 89  
 
 90  
  */
 91  
 public class FindDialog extends ArgoDialog
 92  
     implements ActionListener, MouseListener {
 93  
 
 94  
     private static FindDialog instance;
 95  104
     private static int nextResultNum = 1;
 96  
 
 97  
     private static int numFinds;
 98  
 
 99  
     /**
 100  
      * Insets in pixels.
 101  
      */
 102  
     private static final int INSET_PX = 3;
 103  
 
 104  104
     private JButton     search     =
 105  
         new JButton(
 106  
             Translator.localize("dialog.find.button.find"));
 107  104
     private JButton     clearTabs  =
 108  
         new JButton(
 109  
             Translator.localize("dialog.find.button.clear-tabs"));
 110  
 //    private JTabbedPane tabs = new JTabbedPane();
 111  
 
 112  104
     private JPanel nameLocTab = new JPanel();
 113  
 
 114  
 //    private JPanel modifiedTab = new JPanel();
 115  
 
 116  
 //    private JPanel tagValsTab = new JPanel();
 117  
 
 118  
 //    private JPanel constraintsTab = new JPanel();
 119  
 
 120  104
     private JComboBox elementName = new JComboBox();
 121  
 
 122  104
     private JComboBox diagramName = new JComboBox();
 123  
 
 124  104
     private JComboBox location = new JComboBox();
 125  
 
 126  104
     private JComboBox type = new JComboBox();
 127  
 
 128  104
     private JPanel typeDetails = new JPanel();
 129  
 
 130  104
     private JTabbedPane results = new JTabbedPane();
 131  
 
 132  104
     private JPanel help = new JPanel();
 133  
 
 134  104
     private List<TabResults> resultTabs = new ArrayList<TabResults>();
 135  
 
 136  
     /**
 137  
      * @return the instance of this dialog
 138  
      */
 139  
     public static FindDialog getInstance() {
 140  107
         if (instance == null) {
 141  104
             instance = new FindDialog();
 142  
         }
 143  107
         return instance;
 144  
     }
 145  
 
 146  
     /**
 147  
      * The constructor.
 148  
      *
 149  
      */
 150  
     public FindDialog() {
 151  104
         super(Translator.localize("dialog.find.title"),
 152  
               ArgoDialog.OK_CANCEL_OPTION, false);
 153  
 
 154  104
         JPanel mainPanel = new JPanel(new BorderLayout());
 155  
 
 156  104
         initNameLocTab();
 157  
 //        tabs.addTab(Translator.localize("dialog.find.tab.name-and-location"),
 158  
 //                nameLocTab);
 159  
 
 160  
         // penyaskito says: According to issue 2501, I have removed the tabs.
 161  
 //        initModifiedTab();
 162  
 //        tabs.addTab(Translator.localize("dialog.find.tab.last-modified"),
 163  
 //                modifiedTab);
 164  
 //        tabs.setEnabledAt(1, false);
 165  
 
 166  
 //        initTagValsTab();
 167  
 //        tabs.addTab(Translator.localize("dialog.find.tab.tagged-values"),
 168  
 //                tagValsTab);
 169  
 //        tabs.setEnabledAt(2, false);
 170  
 
 171  
 //        initConstraintsTab();
 172  
 //        tabs.addTab(Translator.localize("tab.constraints"),
 173  
 //                     constraintsTab);
 174  
 //        tabs.setEnabledAt(3, false);
 175  
 
 176  
 //        tabs.setMinimumSize(new Dimension(300, 250));
 177  
 
 178  
 //        JPanel north = new JPanel();
 179  
 //        north.setLayout(new BorderLayout());
 180  
 //        north.add(tabs, BorderLayout.CENTER);
 181  
         
 182  
 //        mainPanel.add(north, BorderLayout.NORTH);
 183  
 
 184  104
         mainPanel.add(nameLocTab, BorderLayout.NORTH);
 185  
         
 186  104
         initHelpTab();
 187  104
         results.addTab(Translator.localize("dialog.find.tab.help"), help);
 188  104
         mainPanel.add(results, BorderLayout.CENTER);
 189  
 
 190  104
         search.addActionListener(this);
 191  104
         results.addMouseListener(this);
 192  
 
 193  104
         clearTabs.addActionListener(this);
 194  104
         clearTabs.setEnabled(false);
 195  
 
 196  104
         setContent(mainPanel);
 197  
 
 198  104
         getOkButton().setEnabled(false);
 199  104
     }
 200  
 
 201  
     /**
 202  
      * Initialise the tab "Name and Location".
 203  
      */
 204  
     private void initNameLocTab() {
 205  104
         elementName.setEditable(true);
 206  
         // TODO: Don't use hardcoded colors here - tfm
 207  104
         elementName.getEditor()
 208  
             .getEditorComponent().setBackground(Color.white);
 209  104
         diagramName.setEditable(true);
 210  104
         diagramName.getEditor()
 211  
             .getEditorComponent().setBackground(Color.white);
 212  
 
 213  104
         elementName.addItem("*");
 214  104
         diagramName.addItem("*");
 215  
 
 216  
         // TODO: add recent patterns
 217  104
         GridBagLayout gb = new GridBagLayout();
 218  104
         nameLocTab.setLayout(gb);
 219  
 
 220  104
         JLabel elementNameLabel =
 221  
             new JLabel(
 222  
                 Translator.localize("dialog.find.label.element-name"));
 223  104
         JLabel diagramNameLabel =
 224  
             new JLabel(
 225  
                 Translator.localize("dialog.find.label.in-diagram"));
 226  104
         JLabel typeLabel =
 227  
             new JLabel(
 228  
                 Translator.localize("dialog.find.label.element-type"));
 229  104
         JLabel locLabel =
 230  
             new JLabel(
 231  
                 Translator.localize("dialog.find.label.find-in"));
 232  
 
 233  104
         location.addItem(
 234  
                 Translator.localize("dialog.find.comboboxitem.entire-project"));
 235  104
         initTypes();
 236  
 
 237  104
         typeDetails.setMinimumSize(new Dimension(200, 100));
 238  104
         typeDetails.setPreferredSize(new Dimension(200, 100));
 239  104
         typeDetails.setSize(new Dimension(200, 100));
 240  
 
 241  104
         GridBagConstraints c = new GridBagConstraints();
 242  104
         c.fill = GridBagConstraints.BOTH;
 243  104
         c.ipadx = 3; c.ipady = 3;
 244  104
         c.gridwidth = 1;
 245  
 
 246  104
         c.gridx = 0;     c.gridy = 0;
 247  104
         c.weightx = 0.0;
 248  104
         gb.setConstraints(elementNameLabel, c);
 249  104
         nameLocTab.add(elementNameLabel);
 250  
 
 251  104
         c.gridx = 1;     c.gridy = 0;
 252  104
         c.weightx = 1.0;
 253  104
         gb.setConstraints(elementName, c);
 254  104
         nameLocTab.add(elementName);
 255  
 
 256  104
         c.gridx = 0;     c.gridy = 1;
 257  104
         c.weightx = 0.0;
 258  104
         gb.setConstraints(diagramNameLabel, c);
 259  104
         nameLocTab.add(diagramNameLabel);
 260  
 
 261  104
         c.gridx = 1;     c.gridy = 1;
 262  104
         c.weightx = 1.0;
 263  104
         gb.setConstraints(diagramName, c);
 264  104
         nameLocTab.add(diagramName);
 265  
 
 266  
         // open space at gridy = 2;
 267  
 
 268  104
         c.gridx = 0;     c.gridy = 3;
 269  104
         c.weightx = 0.0;
 270  104
         gb.setConstraints(locLabel, c);
 271  104
         nameLocTab.add(locLabel);
 272  
 
 273  104
         c.gridx = 1;     c.gridy = 3;
 274  104
         c.weightx = 1.0;
 275  104
         gb.setConstraints(location, c);
 276  104
         nameLocTab.add(location);
 277  
 
 278  104
         SpacerPanel spacer = new SpacerPanel();
 279  104
         c.gridx = 2;     c.gridy = 0;
 280  104
         c.weightx = 0.0;
 281  104
         gb.setConstraints(spacer, c);
 282  104
         nameLocTab.add(spacer);
 283  
 
 284  104
         c.gridx = 3;     c.gridy = 0;
 285  104
         c.weightx = 0.0;
 286  104
         gb.setConstraints(typeLabel, c);
 287  104
         nameLocTab.add(typeLabel);
 288  
 
 289  104
         c.gridx = 4;     c.gridy = 0;
 290  104
         c.weightx = 1.0;
 291  104
         gb.setConstraints(type, c);
 292  104
         nameLocTab.add(type);
 293  
 
 294  104
         c.gridx = 3;     c.gridy = 1;
 295  104
         c.gridwidth = 2; c.gridheight = 5;
 296  104
         gb.setConstraints(typeDetails, c);
 297  104
         nameLocTab.add(typeDetails);
 298  
 
 299  104
         JPanel searchPanel = new JPanel();
 300  104
         searchPanel.setLayout(new GridLayout(1, 2, 5, 5));
 301  104
         searchPanel.add(clearTabs);
 302  104
         searchPanel.add(search);
 303  104
         searchPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
 304  104
         c.gridx = 0;     c.gridy = 4;
 305  104
         c.weightx = 0.0; c.weighty = 0.0;
 306  104
         c.gridwidth = 2; c.gridheight = 1;
 307  104
         gb.setConstraints(searchPanel, c);
 308  104
         nameLocTab.add(searchPanel);
 309  104
     }
 310  
 
 311  
     /**
 312  
      * Initialise the help tab.
 313  
      */
 314  
     private void initHelpTab() {
 315  104
         help.setLayout(new BorderLayout());
 316  104
         JTextArea helpText = new JTextArea();
 317  104
         helpText.setText(Translator.localize("dialog.find.helptext"));
 318  104
         helpText.setEditable(false);
 319  104
         helpText.setMargin(new Insets(INSET_PX, INSET_PX, INSET_PX, INSET_PX));
 320  104
         help.add(new JScrollPane(helpText), BorderLayout.CENTER);
 321  104
     }
 322  
 
 323  
 
 324  
     /**
 325  
      * Init the modelelement types that we can look for.
 326  
      */
 327  
     private void initTypes() {
 328  104
         type.addItem(PredicateMType.create()); // Any type
 329  
 
 330  104
         type.addItem(PredicateMType.create(
 331  
                 Model.getMetaTypes().getUMLClass()));
 332  104
         type.addItem(PredicateMType.create(
 333  
                 Model.getMetaTypes().getInterface()));
 334  104
         type.addItem(PredicateMType.create(
 335  
                 Model.getMetaTypes().getAction()));
 336  
         // Not in UML 2.x (or metatypes)
 337  
 //        type.addItem(PredicateMType.create(
 338  
 //                Model.getMetaTypes().getActivityGraph()));
 339  104
         type.addItem(PredicateMType.create(
 340  
                 Model.getMetaTypes().getActor()));
 341  104
         type.addItem(PredicateMType.create(
 342  
                 Model.getMetaTypes().getAssociation()));
 343  104
         type.addItem(PredicateMType.create(
 344  
                 Model.getMetaTypes().getAssociationClass()));
 345  104
         type.addItem(PredicateMType.create(
 346  
                 Model.getMetaTypes().getAssociationEndRole()));
 347  104
         type.addItem(PredicateMType.create(
 348  
                 Model.getMetaTypes().getAssociationRole()));
 349  104
         type.addItem(PredicateMType.create(
 350  
                 Model.getMetaTypes().getArtifact()));
 351  104
         type.addItem(PredicateMType.create(
 352  
                 Model.getMetaTypes().getAttribute()));
 353  104
         type.addItem(PredicateMType.create(
 354  
                 Model.getMetaTypes().getClassifier()));
 355  104
         type.addItem(PredicateMType.create(
 356  
                 Model.getMetaTypes().getClassifierRole()));
 357  104
         type.addItem(PredicateMType.create(
 358  
                 Model.getMetaTypes().getCollaboration()));
 359  104
         type.addItem(PredicateMType.create(
 360  
                 Model.getMetaTypes().getComment()));
 361  104
         type.addItem(PredicateMType.create(
 362  
                 Model.getMetaTypes().getComponent()));
 363  104
         type.addItem(PredicateMType.create(
 364  
                 Model.getMetaTypes().getCompositeState()));
 365  104
         type.addItem(PredicateMType.create(
 366  
                 Model.getMetaTypes().getConstraint()));
 367  104
         type.addItem(PredicateMType.create(
 368  
                 Model.getMetaTypes().getDataType()));
 369  104
         type.addItem(PredicateMType.create(
 370  
                 Model.getMetaTypes().getDependency()));
 371  104
         type.addItem(PredicateMType.create(
 372  
                 Model.getMetaTypes().getElementImport()));
 373  104
         type.addItem(PredicateMType.create(
 374  
                 Model.getMetaTypes().getEnumeration()));
 375  104
         type.addItem(PredicateMType.create(
 376  
                 Model.getMetaTypes().getEnumerationLiteral()));
 377  104
         type.addItem(PredicateMType.create(
 378  
                 Model.getMetaTypes().getException()));
 379  104
         type.addItem(PredicateMType.create(
 380  
                 Model.getMetaTypes().getExtend()));
 381  104
         type.addItem(PredicateMType.create(
 382  
                 Model.getMetaTypes().getExtensionPoint()));
 383  104
         type.addItem(PredicateMType.create(
 384  
                 Model.getMetaTypes().getGuard()));
 385  104
         type.addItem(PredicateMType.create(
 386  
                 Model.getMetaTypes().getGeneralization()));
 387  104
         type.addItem(PredicateMType.create(
 388  
                 Model.getMetaTypes().getInclude()));
 389  104
         type.addItem(PredicateMType.create(
 390  
                 Model.getMetaTypes().getInstance()));
 391  104
         type.addItem(PredicateMType.create(
 392  
                 Model.getMetaTypes().getInteraction()));
 393  104
         type.addItem(PredicateMType.create(
 394  
                 Model.getMetaTypes().getInterface()));
 395  104
         type.addItem(PredicateMType.create(
 396  
                 Model.getMetaTypes().getLink()));
 397  104
         type.addItem(PredicateMType.create(
 398  
                 Model.getMetaTypes().getMessage()));
 399  104
         type.addItem(PredicateMType.create(
 400  
                 Model.getMetaTypes().getModel()));
 401  104
         type.addItem(PredicateMType.create(
 402  
                 Model.getMetaTypes().getNode()));
 403  104
         type.addItem(PredicateMType.create(
 404  
                 Model.getMetaTypes().getPackage()));
 405  104
         type.addItem(PredicateMType.create(
 406  
                 Model.getMetaTypes().getParameter()));
 407  104
         type.addItem(PredicateMType.create(
 408  
                 Model.getMetaTypes().getPartition()));
 409  104
         type.addItem(PredicateMType.create(
 410  
                 Model.getMetaTypes().getPseudostate()));
 411  104
         type.addItem(PredicateMType.create(
 412  
                 Model.getMetaTypes().getOperation()));
 413  104
         type.addItem(PredicateMType.create(
 414  
                 Model.getMetaTypes().getSignal()));
 415  104
         type.addItem(PredicateMType.create(
 416  
                 Model.getMetaTypes().getState()));
 417  104
         type.addItem(PredicateMType.create(
 418  
                 Model.getMetaTypes().getStateMachine()));
 419  104
         type.addItem(PredicateMType.create(
 420  
                 Model.getMetaTypes().getStateVertex()));
 421  104
         type.addItem(PredicateMType.create(
 422  
                 Model.getMetaTypes().getStereotype()));
 423  104
         type.addItem(PredicateMType.create(
 424  
                 Model.getMetaTypes().getTagDefinition()));
 425  
         
 426  
         // Not in UML 2.x (or Metatypes)
 427  
 //        type.addItem(PredicateMType.create(
 428  
 //                Model.getMetaTypes().getTemplateArgument()));
 429  
 //        type.addItem(PredicateMType.create(
 430  
 //                Model.getMetaTypes().getTemplateParameter()));
 431  
         
 432  104
         type.addItem(PredicateMType.create(
 433  
                 Model.getMetaTypes().getTransition()));
 434  104
         type.addItem(PredicateMType.create(
 435  
                 Model.getMetaTypes().getUseCase()));
 436  
         
 437  
         // TODO: Can we move this knowledge behind model facade rather than have a condition here?
 438  104
         if (Model.getFacade().getUmlVersion().charAt(0) == '1') {
 439  104
             type.addItem(PredicateMType.create(
 440  
                     Model.getMetaTypes().getSimpleState()));
 441  104
             type.addItem(PredicateMType.create(
 442  
                     Model.getMetaTypes().getTaggedValue()));
 443  
         }
 444  104
     }
 445  
 
 446  
     /*
 447  
      * @see org.tigris.swidgets.Dialog#nameButtons()
 448  
      */
 449  
     @Override
 450  
     protected void nameButtons() {
 451  104
         super.nameButtons();
 452  104
         nameButton(getOkButton(), "button.go-to-selection");
 453  104
         nameButton(getCancelButton(), "button.close");
 454  104
     }
 455  
 
 456  
     /*
 457  
      * @see java.awt.event.ActionListener#actionPerformed(
 458  
      * java.awt.event.ActionEvent)
 459  
      */
 460  
     @Override
 461  
     public void actionPerformed(ActionEvent e) {
 462  0
         if (e.getSource() == search) {
 463  0
             doSearch();
 464  0
         } else if (e.getSource() == clearTabs) {
 465  0
             doClearTabs();
 466  0
         } else if (e.getSource() == getOkButton()) {
 467  0
             doGoToSelection();
 468  
         } else {
 469  0
             super.actionPerformed(e);
 470  
         }
 471  0
     }
 472  
 
 473  
 
 474  
     /**
 475  
      * Do the search.
 476  
      */
 477  
     private void doSearch() {
 478  0
         numFinds++;
 479  0
         String eName = "";
 480  0
         if (elementName.getSelectedItem() != null) {
 481  0
             eName += elementName.getSelectedItem();
 482  0
             elementName.removeItem(eName);
 483  0
             elementName.insertItemAt(eName, 0);
 484  0
             elementName.setSelectedItem(eName);
 485  
         }
 486  0
         String dName = "";
 487  0
         if (diagramName.getSelectedItem() != null) {
 488  0
             dName += diagramName.getSelectedItem();
 489  0
             diagramName.removeItem(dName);
 490  0
             diagramName.insertItemAt(dName, 0);
 491  0
             diagramName.setSelectedItem(dName);
 492  
         }
 493  0
         String name = eName;
 494  0
         if (dName.length() > 0) {
 495  0
             Object[] msgArgs = {name, dName };
 496  0
             name =
 497  
                 Translator.messageFormat(
 498  
                     "dialog.find.comboboxitem.element-in-diagram", msgArgs);
 499  
             //name += " in " + dName;
 500  
         }
 501  0
         String typeName = type.getSelectedItem().toString();
 502  0
         if (!typeName.equals("Any Type")) {
 503  0
             name += " " + typeName;
 504  
         }
 505  0
         if (name.length() == 0) {
 506  0
             name =
 507  
                 Translator.localize("dialog.find.tabname") + (nextResultNum++);
 508  
         }
 509  0
         if (name.length() > 15) {
 510  
             // TODO: Localize
 511  0
             name = name.substring(0, 12) + "...";
 512  
         }
 513  
 
 514  0
         String pName = "";
 515  
 
 516  0
         Predicate eNamePred = PredicateStringMatch.create(eName);
 517  0
         Predicate pNamePred = PredicateStringMatch.create(pName);
 518  0
         Predicate dNamePred = PredicateStringMatch.create(dName);
 519  0
         Predicate typePred = (Predicate) type.getSelectedItem();
 520  0
         PredicateSearch pred =
 521  
             new PredicateSearch(eNamePred, pNamePred, dNamePred, typePred);
 522  
 
 523  0
         ChildGenSearch gen = new ChildGenSearch();
 524  0
         Object root = ProjectManager.getManager().getCurrentProject();
 525  
 
 526  0
         TabResults newResults = new TabResults();
 527  0
         newResults.setTitle(name);
 528  0
         newResults.setPredicate(pred);
 529  0
         newResults.setRoot(root);
 530  0
         newResults.setGenerator(gen);
 531  0
         resultTabs.add(newResults);
 532  0
         results.addTab(name, newResults);
 533  0
         clearTabs.setEnabled(true);
 534  0
         getOkButton().setEnabled(true);
 535  0
         results.setSelectedComponent(newResults);
 536  0
         Object[] msgArgs = {name };
 537  0
         location.addItem(Translator.messageFormat(
 538  
                 "dialog.find.comboboxitem.in-tab", msgArgs));
 539  0
         invalidate();
 540  0
         results.invalidate();
 541  0
         validate();
 542  0
         newResults.run();
 543  0
         newResults.requestFocus();
 544  0
         newResults.selectResult(0);
 545  0
     }
 546  
 
 547  
     /**
 548  
      * Reset the user interface to its initial state. Use this if a new project
 549  
      * has been loaded and the Find dialog is being displayed with stale
 550  
      * results.
 551  
      */
 552  
     public void reset() {
 553  68
         doClearTabs();
 554  68
         doResetFields(true);
 555  68
     }
 556  
     
 557  
     /**
 558  
      * Clear the tabs.
 559  
      */
 560  
     private void doClearTabs() {
 561  68
         int numTabs = resultTabs.size();
 562  68
         for (int i = 0; i < numTabs; i++) {
 563  0
             results.remove(resultTabs.get(i));
 564  
         }
 565  68
         resultTabs.clear();
 566  68
         clearTabs.setEnabled(false);
 567  68
         getOkButton().setEnabled(false);
 568  68
         doResetFields(false);
 569  68
     }
 570  
 
 571  
 
 572  
 
 573  
     /**
 574  
      * Reset the fields.
 575  
      * 
 576  
      * @param complete if true, reset all 3 fields (element name, diagram name,
 577  
      *                and location), otherwise only the last is reset.
 578  
      */
 579  
     private void doResetFields(boolean complete) {
 580  136
         if (complete) {
 581  68
             elementName.removeAllItems();
 582  68
             diagramName.removeAllItems();
 583  68
             elementName.addItem("*");
 584  68
             diagramName.addItem("*");
 585  
         }
 586  136
         location.removeAllItems();
 587  136
         location.addItem(
 588  
                 Translator.localize("dialog.find.comboboxitem.entire-project"));
 589  136
     }
 590  
 
 591  
     /**
 592  
      * Execute the GoTo selection command.
 593  
      */
 594  
     private void doGoToSelection() {
 595  0
         if (results.getSelectedComponent() instanceof TabResults) {
 596  0
             ((TabResults) results.getSelectedComponent()).doDoubleClick();
 597  
         }
 598  0
     }
 599  
 
 600  
 
 601  
     ////////////////////////////////////////////////////////////////
 602  
     // MouseListener implementation
 603  
 
 604  
     /*
 605  
      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
 606  
      */
 607  
     public void mousePressed(MouseEvent me) { 
 608  
         // empty implementation - we only handle mouseClicked
 609  0
     }
 610  
 
 611  
     /*
 612  
      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
 613  
      */
 614  
     public void mouseReleased(MouseEvent me) { 
 615  
         // empty implementation - we only handle mouseClicked
 616  0
     }
 617  
 
 618  
     /*
 619  
      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
 620  
      */
 621  
     public void mouseEntered(MouseEvent me) { 
 622  
         // empty implementation - we only handle mouseClicked
 623  0
     }
 624  
 
 625  
     /*
 626  
      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
 627  
      */
 628  
     public void mouseExited(MouseEvent me) { 
 629  
         // empty implementation - we only handle mouseClicked
 630  0
     }
 631  
 
 632  
     /*
 633  
      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
 634  
      */
 635  
     public void mouseClicked(MouseEvent me) {
 636  0
         int tab = results.getSelectedIndex();
 637  0
         if (tab != -1) {
 638  0
             Rectangle tabBounds = results.getBoundsAt(tab);
 639  0
             if (!tabBounds.contains(me.getX(), me.getY())) {
 640  0
                 return;
 641  
             }
 642  0
             if (tab >= 1 && me.getClickCount() >= 2) {
 643  0
                 myDoubleClick(tab - 1); //help tab is 0
 644  
             }
 645  
         }
 646  0
     }
 647  
 
 648  
     /**
 649  
      * Double click on tab detaches it in a free floating window.
 650  
      *
 651  
      * MVW: This is the only place where spawning is still enabled.
 652  
      *
 653  
      * @param tab the given tab
 654  
      */
 655  
     private void myDoubleClick(int tab) {
 656  0
         JPanel t = resultTabs.get(tab);
 657  0
         if (t instanceof AbstractArgoJPanel) {
 658  0
             if (((AbstractArgoJPanel) t).spawn() != null) {
 659  0
                 resultTabs.remove(tab);
 660  0
                 location.removeItem("In Tab: "
 661  
                                 + ((AbstractArgoJPanel) t).getTitle());
 662  
             }
 663  
         }
 664  0
     }
 665  
 
 666  
     /**
 667  
      * The UID.
 668  
      */
 669  
     private static final long serialVersionUID = 9209251878896557216L;
 670  
 } /* end class FindDialog */
 671  
 
 672  
 
 673  
 /**
 674  
  * PredicateMType is a small helper class which converts the
 675  
  * string representation of the Type from internal form.
 676  
  * Now that Type names aren't prefixed with NSUML's "M" the
 677  
  * name of the class is somewhat of a misnomer.
 678  
  */
 679  
 class PredicateMType extends PredicateType {
 680  
     /**
 681  
      * The constructor.
 682  
      *
 683  
      * @param pats The classes.
 684  
      */
 685  
     protected PredicateMType(Class[] pats) {
 686  5200
         super(pats, pats.length);
 687  5200
     }
 688  
 
 689  
     /**
 690  
      * The constructor.
 691  
      *
 692  
      * @param pats The classes (or <code>null</code> if numPats is 0.
 693  
      * @param numPats The count of classes.
 694  
      */
 695  
     protected PredicateMType(Class[] pats, int numPats) {
 696  104
         super(pats, numPats);
 697  104
     }
 698  
 
 699  
     /**
 700  
      * Create without classes.
 701  
      *
 702  
      * @return A newly created PredicateType.
 703  
      */
 704  
     public static PredicateType create() {
 705  104
         return new PredicateMType(null, 0);
 706  
     }
 707  
 
 708  
     /**
 709  
      * Create with one class.
 710  
      *
 711  
      * @param c0 First class.
 712  
      * @return A newly created PredicateType.
 713  
      */
 714  
     public static PredicateType create(Object c0) {
 715  5200
         Class[] classes = new Class[1];
 716  5200
         classes[0] = (Class) c0;
 717  5200
         return new PredicateMType(classes);
 718  
     }
 719  
 
 720  
     /**
 721  
      * Create with two classes.
 722  
      *
 723  
      * @param c0 First class.
 724  
      * @param c1 Second class.
 725  
      * @return A newly created PredicateType.
 726  
      */
 727  
     public static PredicateType create(Object c0, Object c1) {
 728  0
         Class[] classes = new Class[2];
 729  0
         classes[0] = (Class) c0;
 730  0
         classes[1] = (Class) c1;
 731  0
         return new PredicateMType(classes);
 732  
     }
 733  
 
 734  
     /**
 735  
      * Create with three classes.
 736  
      *
 737  
      * @param c0 First class.
 738  
      * @param c1 Second class.
 739  
      * @param c2 Third class.
 740  
      * @return A newly created PredicateType.
 741  
      */
 742  
     public static PredicateType create(Object c0, Object c1, Object c2) {
 743  0
         Class[] classes = new Class[3];
 744  0
         classes[0] = (Class) c0;
 745  0
         classes[1] = (Class) c1;
 746  0
         classes[2] = (Class) c2;
 747  0
         return new PredicateMType(classes);
 748  
     }
 749  
 
 750  
 
 751  
     @Override
 752  
     public String toString() {
 753  5452
         String result = super.toString();
 754  
         // TODO: This shouldn't know the internal form of type names,
 755  
         // but I'm not sure what GEF's PredicateType does, so I'm fixing it
 756  
         // here - tfm
 757  5452
         if (result.startsWith("Uml")) {
 758  416
             result = result.substring(3);
 759  
         }
 760  5452
         return result;
 761  
     }
 762  
 
 763  
     /**
 764  
      * The UID.
 765  
      */
 766  
     private static final long serialVersionUID = 901828109709882796L;
 767  
 } /* end class PredicateMType */