Coverage Report - org.argouml.ui.explorer.PerspectiveManager
 
Classes in this File Line Coverage Branch Coverage Complexity
PerspectiveManager
87%
200/229
65%
17/26
1.889
 
 1  
 /* $Id: PerspectiveManager.java 18172 2010-03-26 17:22:38Z 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  
  *    penyaskito
 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.ui.explorer;
 40  
 
 41  
 import java.util.ArrayList;
 42  
 import java.util.Arrays;
 43  
 import java.util.Collection;
 44  
 import java.util.List;
 45  
 import java.util.StringTokenizer;
 46  
 
 47  
 import org.apache.log4j.Logger;
 48  
 import org.argouml.application.api.Argo;
 49  
 import org.argouml.configuration.Configuration;
 50  
 import org.argouml.model.Model;
 51  
 import org.argouml.ui.explorer.rules.GoAssocRoleToMessages;
 52  
 import org.argouml.ui.explorer.rules.GoBehavioralFeatureToStateDiagram;
 53  
 import org.argouml.ui.explorer.rules.GoBehavioralFeatureToStateMachine;
 54  
 import org.argouml.ui.explorer.rules.GoClassToAssociatedClass;
 55  
 import org.argouml.ui.explorer.rules.GoClassToNavigableClass;
 56  
 import org.argouml.ui.explorer.rules.GoClassToSummary;
 57  
 import org.argouml.ui.explorer.rules.GoClassifierToBehavioralFeature;
 58  
 import org.argouml.ui.explorer.rules.GoClassifierToCollaboration;
 59  
 import org.argouml.ui.explorer.rules.GoClassifierToInstance;
 60  
 import org.argouml.ui.explorer.rules.GoClassifierToSequenceDiagram;
 61  
 import org.argouml.ui.explorer.rules.GoClassifierToStateMachine;
 62  
 import org.argouml.ui.explorer.rules.GoClassifierToStructuralFeature;
 63  
 import org.argouml.ui.explorer.rules.GoCollaborationToDiagram;
 64  
 import org.argouml.ui.explorer.rules.GoCollaborationToInteraction;
 65  
 import org.argouml.ui.explorer.rules.GoComponentToResidentModelElement;
 66  
 import org.argouml.ui.explorer.rules.GoCompositeStateToSubvertex;
 67  
 import org.argouml.ui.explorer.rules.GoCriticsToCritic;
 68  
 import org.argouml.ui.explorer.rules.GoDiagramToEdge;
 69  
 import org.argouml.ui.explorer.rules.GoDiagramToNode;
 70  
 import org.argouml.ui.explorer.rules.GoElementToMachine;
 71  
 import org.argouml.ui.explorer.rules.GoEnumerationToLiterals;
 72  
 import org.argouml.ui.explorer.rules.GoGeneralizableElementToSpecialized;
 73  
 import org.argouml.ui.explorer.rules.GoInteractionToMessages;
 74  
 import org.argouml.ui.explorer.rules.GoLinkToStimuli;
 75  
 import org.argouml.ui.explorer.rules.GoMessageToAction;
 76  
 import org.argouml.ui.explorer.rules.GoModelElementToBehavior;
 77  
 import org.argouml.ui.explorer.rules.GoModelElementToComment;
 78  
 import org.argouml.ui.explorer.rules.GoModelElementToContainedDiagrams;
 79  
 import org.argouml.ui.explorer.rules.GoModelElementToContainedLostElements;
 80  
 import org.argouml.ui.explorer.rules.GoModelElementToContents;
 81  
 import org.argouml.ui.explorer.rules.GoModelElementToTemplateParameter;
 82  
 import org.argouml.ui.explorer.rules.GoModelToBaseElements;
 83  
 import org.argouml.ui.explorer.rules.GoModelToCollaboration;
 84  
 import org.argouml.ui.explorer.rules.GoModelToDiagrams;
 85  
 import org.argouml.ui.explorer.rules.GoModelToElements;
 86  
 import org.argouml.ui.explorer.rules.GoModelToNode;
 87  
 import org.argouml.ui.explorer.rules.GoNamespaceToClassifierAndPackage;
 88  
 import org.argouml.ui.explorer.rules.GoNamespaceToDiagram;
 89  
 import org.argouml.ui.explorer.rules.GoNamespaceToOwnedElements;
 90  
 import org.argouml.ui.explorer.rules.GoNodeToResidentComponent;
 91  
 import org.argouml.ui.explorer.rules.GoOperationToCollaboration;
 92  
 import org.argouml.ui.explorer.rules.GoOperationToCollaborationDiagram;
 93  
 import org.argouml.ui.explorer.rules.GoOperationToSequenceDiagram;
 94  
 import org.argouml.ui.explorer.rules.GoPackageToClass;
 95  
 import org.argouml.ui.explorer.rules.GoPackageToElementImport;
 96  
 import org.argouml.ui.explorer.rules.GoProfileConfigurationToProfile;
 97  
 import org.argouml.ui.explorer.rules.GoProfileToCritics;
 98  
 import org.argouml.ui.explorer.rules.GoProfileToModel;
 99  
 import org.argouml.ui.explorer.rules.GoProjectToCollaboration;
 100  
 import org.argouml.ui.explorer.rules.GoProjectToDiagram;
 101  
 import org.argouml.ui.explorer.rules.GoProjectToModel;
 102  
 import org.argouml.ui.explorer.rules.GoProjectToProfileConfiguration;
 103  
 import org.argouml.ui.explorer.rules.GoProjectToRoots;
 104  
 import org.argouml.ui.explorer.rules.GoProjectToStateMachine;
 105  
 import org.argouml.ui.explorer.rules.GoSignalToReception;
 106  
 import org.argouml.ui.explorer.rules.GoStateMachineToState;
 107  
 import org.argouml.ui.explorer.rules.GoStateMachineToTop;
 108  
 import org.argouml.ui.explorer.rules.GoStateMachineToTransition;
 109  
 import org.argouml.ui.explorer.rules.GoStateToDoActivity;
 110  
 import org.argouml.ui.explorer.rules.GoStateToDownstream;
 111  
 import org.argouml.ui.explorer.rules.GoStateToEntry;
 112  
 import org.argouml.ui.explorer.rules.GoStateToExit;
 113  
 import org.argouml.ui.explorer.rules.GoStateToIncomingTrans;
 114  
 import org.argouml.ui.explorer.rules.GoStateToInternalTrans;
 115  
 import org.argouml.ui.explorer.rules.GoStateToOutgoingTrans;
 116  
 import org.argouml.ui.explorer.rules.GoStatemachineToDiagram;
 117  
 import org.argouml.ui.explorer.rules.GoStereotypeToTagDefinition;
 118  
 import org.argouml.ui.explorer.rules.GoStimulusToAction;
 119  
 import org.argouml.ui.explorer.rules.GoSubmachineStateToStateMachine;
 120  
 import org.argouml.ui.explorer.rules.GoSummaryToAssociation;
 121  
 import org.argouml.ui.explorer.rules.GoSummaryToAttribute;
 122  
 import org.argouml.ui.explorer.rules.GoSummaryToIncomingDependency;
 123  
 import org.argouml.ui.explorer.rules.GoSummaryToInheritance;
 124  
 import org.argouml.ui.explorer.rules.GoSummaryToOperation;
 125  
 import org.argouml.ui.explorer.rules.GoSummaryToOutgoingDependency;
 126  
 import org.argouml.ui.explorer.rules.GoTransitionToGuard;
 127  
 import org.argouml.ui.explorer.rules.GoTransitionToSource;
 128  
 import org.argouml.ui.explorer.rules.GoTransitionToTarget;
 129  
 import org.argouml.ui.explorer.rules.GoTransitiontoEffect;
 130  
 import org.argouml.ui.explorer.rules.GoUseCaseToExtensionPoint;
 131  
 import org.argouml.ui.explorer.rules.PerspectiveRule;
 132  
 
 133  
 /**
 134  
  * Provides a model and event management for perspectives(views) of the
 135  
  * Explorer.<p>
 136  
  *
 137  
  * This class defines the complete list of perspective rules, and knows the
 138  
  * default perspectives and their contents.
 139  
  *
 140  
  * @author alexb
 141  
  * @since 0.15.2
 142  
  */
 143  
 public final class PerspectiveManager {
 144  
     /**
 145  
      * Logger.
 146  
      */
 147  900
     private static final Logger LOG =
 148  
         Logger.getLogger(PerspectiveManager.class);
 149  
 
 150  
     private static PerspectiveManager instance;
 151  
 
 152  
     private List<PerspectiveManagerListener> perspectiveListeners;
 153  
 
 154  
     private List<ExplorerPerspective> perspectives;
 155  
 
 156  
     private List<PerspectiveRule> rules;
 157  
 
 158  
     /**
 159  
      * @return the instance (singleton)
 160  
      */
 161  
     public static PerspectiveManager getInstance() {
 162  1935
         if (instance == null) {
 163  900
             instance = new PerspectiveManager();
 164  
         }
 165  1935
         return instance;
 166  
     }
 167  
 
 168  
     /**
 169  
      * Creates a new instance of PerspectiveManager.
 170  
      */
 171  900
     private PerspectiveManager() {
 172  
 
 173  900
         perspectiveListeners = new ArrayList<PerspectiveManagerListener>();
 174  900
         perspectives = new ArrayList<ExplorerPerspective>();
 175  900
         rules = new ArrayList<PerspectiveRule>();
 176  900
         loadRules();
 177  900
     }
 178  
 
 179  
     /**
 180  
      * @param listener
 181  
      *            the listener to be added
 182  
      */
 183  
     public void addListener(PerspectiveManagerListener listener) {
 184  900
         perspectiveListeners.add(listener);
 185  900
     }
 186  
 
 187  
     /**
 188  
      * @param listener
 189  
      *            the listener to be removed
 190  
      */
 191  
     public void removeListener(PerspectiveManagerListener listener) {
 192  0
         perspectiveListeners.remove(listener);
 193  0
     }
 194  
 
 195  
     /**
 196  
      * @param perspective
 197  
      *            the perspective to be added
 198  
      */
 199  
     public void addPerspective(ExplorerPerspective perspective) {
 200  8109
         perspectives.add(perspective);
 201  8109
         for (PerspectiveManagerListener listener : perspectiveListeners) {
 202  8109
             listener.addPerspective(perspective);
 203  
         }
 204  8109
     }
 205  
 
 206  
     /**
 207  
      * @param newPerspectives
 208  
      *            the collection of perspectives to be added
 209  
      */
 210  
     public void addAllPerspectives(
 211  
             Collection<ExplorerPerspective> newPerspectives) {
 212  900
         for (ExplorerPerspective newPerspective : newPerspectives) {
 213  8100
             addPerspective(newPerspective);
 214  
         }
 215  900
     }
 216  
 
 217  
     /**
 218  
      * @param perspective
 219  
      *            the perspective to be removed
 220  
      */
 221  
     public void removePerspective(ExplorerPerspective perspective) {
 222  9
         perspectives.remove(perspective);
 223  9
         for (PerspectiveManagerListener listener : perspectiveListeners) {
 224  9
             listener.removePerspective(perspective);
 225  
         }
 226  9
     }
 227  
 
 228  
     /**
 229  
      * Remove all perspectives.
 230  
      */
 231  
     public void removeAllPerspectives() {
 232  
 
 233  1
         List<ExplorerPerspective> pers = new ArrayList<ExplorerPerspective>();
 234  
 
 235  1
         pers.addAll(getPerspectives());
 236  1
         for (ExplorerPerspective perspective : pers) {
 237  9
             removePerspective(perspective);
 238  
         }
 239  1
     }
 240  
 
 241  
     /**
 242  
      * @return the list of all perspectives
 243  
      */
 244  
     public List<ExplorerPerspective> getPerspectives() {
 245  957
         return perspectives;
 246  
     }
 247  
 
 248  
     /**
 249  
      * Tries to load user defined perspectives, if it can't it loads the
 250  
      * (predefined) default perspectives.
 251  
      */
 252  
     public void loadUserPerspectives() {
 253  
 
 254  900
         String userPerspectives =
 255  
             Configuration.getString(
 256  
                     Argo.KEY_USER_EXPLORER_PERSPECTIVES, "");
 257  
 
 258  900
         StringTokenizer pst = new StringTokenizer(userPerspectives, ";");
 259  
 
 260  900
         if (pst.hasMoreTokens()) {
 261  
 
 262  
             // load user perspectives
 263  0
             while (pst.hasMoreTokens()) {
 264  0
                 String perspective = pst.nextToken();
 265  0
                 StringTokenizer perspectiveDetails =
 266  
                     new StringTokenizer(perspective, ",");
 267  
 
 268  
                 // get the perspective name
 269  0
                 String perspectiveName = perspectiveDetails.nextToken();
 270  
 
 271  0
                 ExplorerPerspective userDefinedPerspective =
 272  
                     new ExplorerPerspective(perspectiveName);
 273  
 
 274  
                 // make sure there are some rules...
 275  0
                 if (perspectiveDetails.hasMoreTokens()) {
 276  
 
 277  
                     // get the rules
 278  0
                     while (perspectiveDetails.hasMoreTokens()) {
 279  
 
 280  
                         // get the rule name
 281  0
                         String ruleName = perspectiveDetails.nextToken();
 282  
 
 283  
                         // create the rule
 284  
                         try {
 285  0
                             Class ruleClass = Class.forName(ruleName);
 286  
 
 287  0
                             PerspectiveRule rule =
 288  
                                 (PerspectiveRule) ruleClass.newInstance();
 289  
 
 290  0
                             userDefinedPerspective.addRule(rule);
 291  0
                         } catch (ClassNotFoundException e) {
 292  0
                             LOG.error(
 293  
                                     "could not create rule " + ruleName 
 294  
                                     + " you can try to "
 295  
                                     + "refresh the perspectives to the "
 296  
                                     + "default settings.",
 297  
                                     e);
 298  0
                         } catch (InstantiationException e) {
 299  0
                             LOG.error(
 300  
                                     "could not create rule " + ruleName 
 301  
                                     + " you can try to "
 302  
                                     + "refresh the perspectives to the "
 303  
                                     + "default settings.",
 304  
                                     e);
 305  0
                         } catch (IllegalAccessException e) {
 306  0
                             LOG.error(
 307  
                                     "could not create rule " + ruleName 
 308  
                                     + " you can try to "
 309  
                                     + "refresh the perspectives to the "
 310  
                                     + "default settings.",
 311  
                                     e);
 312  0
                         }
 313  0
                     }
 314  
                 } else {
 315  
                     // rule name but no rules
 316  
                     continue;
 317  
                 }
 318  
 
 319  
                 // add the perspective
 320  0
                 addPerspective(userDefinedPerspective);
 321  0
             }
 322  
         } else {
 323  
             // no user defined perspectives
 324  900
             loadDefaultPerspectives();
 325  
         }
 326  
 
 327  
         // one last check that some loaded.
 328  900
         if (getPerspectives().size() == 0) {
 329  0
             loadDefaultPerspectives();
 330  
         }
 331  900
     }
 332  
 
 333  
     /**
 334  
      * Loads a pre-defined default set of perspectives.
 335  
      */
 336  
     public void loadDefaultPerspectives() {
 337  900
         Collection<ExplorerPerspective> c = getDefaultPerspectives();
 338  
 
 339  900
         addAllPerspectives(c);
 340  900
     }
 341  
 
 342  
     /**
 343  
      * @return a collection of default perspectives (i.e. the predefined ones)
 344  
      */
 345  
     public Collection<ExplorerPerspective> getDefaultPerspectives() {
 346  913
         ExplorerPerspective classPerspective =
 347  
             new ExplorerPerspective(
 348  
                 "combobox.item.class-centric");
 349  913
         classPerspective.addRule(new GoProjectToModel());
 350  913
         classPerspective.addRule(new GoProjectToProfileConfiguration());
 351  913
         classPerspective.addRule(new GoProfileConfigurationToProfile());
 352  913
         classPerspective.addRule(new GoProfileToModel());
 353  913
         classPerspective.addRule(new GoProfileToCritics());
 354  913
         classPerspective.addRule(new GoCriticsToCritic());
 355  913
         classPerspective.addRule(new GoProjectToRoots());
 356  913
         classPerspective.addRule(new GoNamespaceToClassifierAndPackage());
 357  913
         classPerspective.addRule(new GoNamespaceToDiagram());
 358  913
         classPerspective.addRule(new GoClassToSummary());
 359  913
         classPerspective.addRule(new GoSummaryToAssociation());
 360  913
         classPerspective.addRule(new GoSummaryToAttribute());
 361  913
         classPerspective.addRule(new GoSummaryToOperation());
 362  913
         classPerspective.addRule(new GoSummaryToInheritance());
 363  913
         classPerspective.addRule(new GoSummaryToIncomingDependency());
 364  913
         classPerspective.addRule(new GoSummaryToOutgoingDependency());
 365  913
         classPerspective.addRule(new GoModelElementToTemplateParameter());
 366  
 
 367  913
         ExplorerPerspective packagePerspective =
 368  
             new ExplorerPerspective(
 369  
                 "combobox.item.package-centric");
 370  913
         packagePerspective.addRule(new GoProjectToModel());
 371  913
         packagePerspective.addRule(new GoProjectToProfileConfiguration());
 372  913
         packagePerspective.addRule(new GoProfileConfigurationToProfile());
 373  913
         packagePerspective.addRule(new GoProfileToModel());
 374  913
         packagePerspective.addRule(new GoProfileToCritics());
 375  913
         packagePerspective.addRule(new GoCriticsToCritic());
 376  913
         packagePerspective.addRule(new GoProjectToRoots());
 377  913
         packagePerspective.addRule(new GoNamespaceToOwnedElements());
 378  913
         packagePerspective.addRule(new GoPackageToElementImport());
 379  913
         packagePerspective.addRule(new GoNamespaceToDiagram());
 380  913
         packagePerspective.addRule(new GoUseCaseToExtensionPoint());
 381  913
         packagePerspective.addRule(new GoClassifierToStructuralFeature());
 382  913
         packagePerspective.addRule(new GoClassifierToBehavioralFeature());
 383  913
         packagePerspective.addRule(new GoEnumerationToLiterals());
 384  913
         packagePerspective.addRule(new GoCollaborationToInteraction());
 385  913
         packagePerspective.addRule(new GoInteractionToMessages());
 386  913
         packagePerspective.addRule(new GoMessageToAction());
 387  913
         packagePerspective.addRule(new GoSignalToReception());
 388  913
         packagePerspective.addRule(new GoLinkToStimuli());
 389  913
         packagePerspective.addRule(new GoStimulusToAction());
 390  913
         packagePerspective.addRule(new GoClassifierToCollaboration());
 391  
         // TODO: We need a factory pattern for GoXXX classes that can determine if they are required
 392  913
         packagePerspective.addRule(new GoOperationToCollaboration());
 393  913
         packagePerspective.addRule(new GoOperationToSequenceDiagram());
 394  913
         packagePerspective.addRule(new GoModelElementToComment());
 395  913
         packagePerspective.addRule(new GoCollaborationToDiagram());
 396  913
         packagePerspective.addRule(new GoModelElementToTemplateParameter());
 397  
 
 398  
         /*
 399  
          * Removed the next one due to issue 2165.
 400  
          * packagePerspective.addRule(new GoOperationToCollaborationDiagram());
 401  
          */
 402  913
         packagePerspective.addRule(new GoBehavioralFeatureToStateMachine());
 403  
         // works for both statediagram as activitygraph
 404  913
         packagePerspective.addRule(new GoStatemachineToDiagram());
 405  913
         packagePerspective.addRule(new GoStateMachineToState());
 406  913
         packagePerspective.addRule(new GoCompositeStateToSubvertex());
 407  913
         packagePerspective.addRule(new GoStateToInternalTrans());
 408  913
         packagePerspective.addRule(new GoStateToDoActivity());
 409  913
         packagePerspective.addRule(new GoStateToEntry());
 410  913
         packagePerspective.addRule(new GoStateToExit());
 411  913
         packagePerspective.addRule(new GoClassifierToSequenceDiagram());
 412  913
         packagePerspective.addRule(new GoClassifierToInstance());
 413  913
         packagePerspective.addRule(new GoStateToIncomingTrans());
 414  913
         packagePerspective.addRule(new GoStateToOutgoingTrans());
 415  913
         packagePerspective.addRule(new GoSubmachineStateToStateMachine());
 416  913
         packagePerspective.addRule(new GoStereotypeToTagDefinition());
 417  913
         packagePerspective.addRule(new GoModelElementToBehavior());
 418  913
         packagePerspective.addRule(new GoModelElementToContainedLostElements());
 419  
 
 420  913
         ExplorerPerspective diagramPerspective =
 421  
             new ExplorerPerspective(
 422  
                 "combobox.item.diagram-centric");
 423  913
         diagramPerspective.addRule(new GoProjectToModel());
 424  913
         diagramPerspective.addRule(new GoProjectToProfileConfiguration());
 425  913
         diagramPerspective.addRule(new GoProfileConfigurationToProfile());
 426  913
         diagramPerspective.addRule(new GoProfileToModel());
 427  913
         diagramPerspective.addRule(new GoProfileToCritics());
 428  913
         diagramPerspective.addRule(new GoCriticsToCritic());
 429  913
         diagramPerspective.addRule(new GoModelToDiagrams());
 430  913
         diagramPerspective.addRule(new GoDiagramToNode());
 431  913
         diagramPerspective.addRule(new GoDiagramToEdge());
 432  913
         diagramPerspective.addRule(new GoUseCaseToExtensionPoint());
 433  913
         diagramPerspective.addRule(new GoClassifierToStructuralFeature());
 434  913
         diagramPerspective.addRule(new GoClassifierToBehavioralFeature());
 435  
 
 436  913
         ExplorerPerspective inheritancePerspective =
 437  
             new ExplorerPerspective(
 438  
                 "combobox.item.inheritance-centric");
 439  913
         inheritancePerspective.addRule(new GoProjectToModel());
 440  913
         inheritancePerspective.addRule(new GoProjectToProfileConfiguration());
 441  913
         classPerspective.addRule(new GoProfileConfigurationToProfile());
 442  913
         classPerspective.addRule(new GoProfileToModel());
 443  913
         classPerspective.addRule(new GoProfileToCritics());
 444  913
         classPerspective.addRule(new GoCriticsToCritic());
 445  913
         inheritancePerspective.addRule(new GoModelToBaseElements());
 446  913
         inheritancePerspective
 447  
                 .addRule(new GoGeneralizableElementToSpecialized());
 448  
 
 449  913
         ExplorerPerspective associationsPerspective =
 450  
             new ExplorerPerspective(
 451  
                 "combobox.item.class-associations");
 452  913
         associationsPerspective.addRule(new GoProjectToModel());
 453  913
         associationsPerspective.addRule(new GoProjectToProfileConfiguration());
 454  913
         associationsPerspective.addRule(new GoProfileConfigurationToProfile());
 455  913
         associationsPerspective.addRule(new GoProfileToModel());
 456  913
         associationsPerspective.addRule(new GoProfileToCritics());
 457  913
         associationsPerspective.addRule(new GoCriticsToCritic());
 458  913
         associationsPerspective.addRule(new GoNamespaceToDiagram());
 459  913
         associationsPerspective.addRule(new GoPackageToClass());
 460  913
         associationsPerspective.addRule(new GoClassToAssociatedClass());
 461  
 
 462  913
         ExplorerPerspective residencePerspective =
 463  
             new ExplorerPerspective(
 464  
                 "combobox.item.residence-centric");
 465  913
         residencePerspective.addRule(new GoProjectToModel());
 466  913
         residencePerspective.addRule(new GoProjectToProfileConfiguration());
 467  913
         residencePerspective.addRule(new GoProfileConfigurationToProfile());
 468  913
         residencePerspective.addRule(new GoProfileToModel());
 469  913
         residencePerspective.addRule(new GoProfileToCritics());
 470  913
         residencePerspective.addRule(new GoCriticsToCritic());
 471  913
         residencePerspective.addRule(new GoModelToNode());
 472  913
         residencePerspective.addRule(new GoNodeToResidentComponent());
 473  913
         residencePerspective.addRule(new GoComponentToResidentModelElement());
 474  
 
 475  913
         ExplorerPerspective statePerspective =
 476  
             new ExplorerPerspective(
 477  
                 "combobox.item.state-centric");
 478  913
         statePerspective.addRule(new GoProjectToStateMachine());
 479  913
         statePerspective.addRule(new GoStatemachineToDiagram());
 480  913
         statePerspective.addRule(new GoStateMachineToState());
 481  913
         statePerspective.addRule(new GoCompositeStateToSubvertex());
 482  913
         statePerspective.addRule(new GoStateToIncomingTrans());
 483  913
         statePerspective.addRule(new GoStateToOutgoingTrans());
 484  913
         statePerspective.addRule(new GoTransitiontoEffect());
 485  913
         statePerspective.addRule(new GoTransitionToGuard());
 486  
 
 487  913
         ExplorerPerspective transitionsPerspective =
 488  
             new ExplorerPerspective(
 489  
                 "combobox.item.transitions-centric");
 490  913
         transitionsPerspective.addRule(new GoProjectToStateMachine());
 491  913
         transitionsPerspective.addRule(new GoStatemachineToDiagram());
 492  913
         transitionsPerspective.addRule(new GoStateMachineToTransition());
 493  913
         transitionsPerspective.addRule(new GoTransitionToSource());
 494  913
         transitionsPerspective.addRule(new GoTransitionToTarget());
 495  913
         transitionsPerspective.addRule(new GoTransitiontoEffect());
 496  913
         transitionsPerspective.addRule(new GoTransitionToGuard());
 497  
 
 498  913
         ExplorerPerspective compositionPerspective =
 499  
             new ExplorerPerspective(
 500  
                 "combobox.item.composite-centric");
 501  913
         compositionPerspective.addRule(new GoProjectToModel());
 502  913
         compositionPerspective.addRule(new GoProjectToProfileConfiguration());
 503  913
         compositionPerspective.addRule(new GoProfileConfigurationToProfile());
 504  913
         compositionPerspective.addRule(new GoProfileToModel());
 505  913
         compositionPerspective.addRule(new GoProfileToCritics());
 506  913
         compositionPerspective.addRule(new GoCriticsToCritic());
 507  913
         compositionPerspective.addRule(new GoProjectToRoots());
 508  913
         compositionPerspective.addRule(new GoModelElementToContents());
 509  913
         compositionPerspective.addRule(new GoModelElementToContainedDiagrams());
 510  
 
 511  913
         Collection<ExplorerPerspective> c = 
 512  
             new ArrayList<ExplorerPerspective>();
 513  913
         c.add(packagePerspective);
 514  913
         c.add(classPerspective);
 515  913
         c.add(diagramPerspective);
 516  913
         c.add(inheritancePerspective);
 517  913
         c.add(associationsPerspective);
 518  913
         c.add(residencePerspective);
 519  913
         c.add(statePerspective);
 520  913
         c.add(transitionsPerspective);
 521  913
         c.add(compositionPerspective);
 522  913
         return c;
 523  
     }
 524  
 
 525  
     /**
 526  
      * Get the predefined rules.<p>
 527  
      *
 528  
      * This is a hard coded rules library for now, since it is quite a lot of
 529  
      * work to get all possible rule names in "org.argouml.ui.explorer.rules"
 530  
      * from the classpath (which would also not allow adding rules from other
 531  
      * locations).
 532  
      */
 533  
     public void loadRules() {
 534  
 
 535  900
         PerspectiveRule[] ruleNamesArray = {new GoAssocRoleToMessages(),
 536  
             new GoBehavioralFeatureToStateDiagram(),
 537  
             new GoBehavioralFeatureToStateMachine(),
 538  
             new GoClassifierToBehavioralFeature(),
 539  
             new GoClassifierToCollaboration(),
 540  
             new GoClassifierToInstance(),
 541  
             new GoClassifierToSequenceDiagram(),
 542  
             new GoClassifierToStateMachine(),
 543  
             new GoClassifierToStructuralFeature(),
 544  
             new GoClassToAssociatedClass(), new GoClassToNavigableClass(),
 545  
             new GoClassToSummary(), new GoCollaborationToDiagram(),
 546  
             new GoCollaborationToInteraction(),
 547  
             new GoComponentToResidentModelElement(),
 548  
             new GoCompositeStateToSubvertex(), new GoDiagramToEdge(),
 549  
             new GoDiagramToNode(), new GoElementToMachine(),
 550  
             new GoEnumerationToLiterals(),
 551  
             new GoGeneralizableElementToSpecialized(),
 552  
             new GoInteractionToMessages(), new GoLinkToStimuli(),
 553  
             new GoMessageToAction(), new GoModelElementToComment(),
 554  
             new GoModelElementToBehavior(),
 555  
             new GoModelElementToTemplateParameter(),
 556  
             new GoModelElementToContents(),
 557  
             new GoModelElementToContainedDiagrams(),
 558  
             new GoModelElementToContainedLostElements(),
 559  
             new GoModelToBaseElements(), new GoModelToCollaboration(),
 560  
             new GoModelToDiagrams(), new GoModelToElements(),
 561  
             new GoModelToNode(), new GoNamespaceToClassifierAndPackage(),
 562  
             new GoNamespaceToDiagram(), new GoNamespaceToOwnedElements(),
 563  
             new GoNodeToResidentComponent(),
 564  
             new GoOperationToCollaboration(),
 565  
             new GoOperationToCollaborationDiagram(),
 566  
             new GoOperationToSequenceDiagram(),
 567  
             new GoPackageToClass(),
 568  
             new GoPackageToElementImport(),
 569  
             new GoProjectToCollaboration(), new GoProjectToDiagram(),
 570  
             new GoProjectToModel(), new GoProjectToStateMachine(), 
 571  
             new GoProjectToProfileConfiguration(), 
 572  
             new GoProfileConfigurationToProfile(),
 573  
             new GoProfileToModel(),
 574  
             new GoProfileToCritics(),
 575  
             new GoCriticsToCritic(),
 576  
             new GoProjectToRoots(),
 577  
             new GoSignalToReception(), new GoStateMachineToTop(),
 578  
             new GoStatemachineToDiagram(), new GoStateMachineToState(),
 579  
             new GoStateMachineToTransition(), new GoStateToDoActivity(),
 580  
             new GoStateToDownstream(), new GoStateToEntry(),
 581  
             new GoStateToExit(), new GoStateToIncomingTrans(),
 582  
             new GoStateToInternalTrans(), new GoStateToOutgoingTrans(),
 583  
             new GoStereotypeToTagDefinition(),
 584  
             new GoStimulusToAction(), new GoSummaryToAssociation(),
 585  
             new GoSummaryToAttribute(),
 586  
             new GoSummaryToIncomingDependency(),
 587  
             new GoSummaryToInheritance(), new GoSummaryToOperation(),
 588  
             new GoSummaryToOutgoingDependency(),
 589  
             new GoTransitionToSource(), new GoTransitionToTarget(),
 590  
             new GoTransitiontoEffect(), new GoTransitionToGuard(),
 591  
             new GoUseCaseToExtensionPoint(),
 592  
             new GoSubmachineStateToStateMachine(),
 593  
         };
 594  
         
 595  
         // TODO: We need a factory pattern for GoXXX classes that can determine if they are required
 596  900
         PerspectiveRule[] ruleNamesArray14 = {
 597  
             // Enter here go rules only relevant for UML 1.4
 598  
             // empty for now
 599  
         };
 600  
 
 601  900
         PerspectiveRule[] ruleNamesArray2 = {
 602  
             // Enter here go rules only relevant for UML 2
 603  
             // empty for now
 604  
         };
 605  
 
 606  900
         rules = Arrays.asList(ruleNamesArray);
 607  900
         if (Model.getFacade().getUmlVersion().charAt(0) == '1') {
 608  900
             rules.addAll(Arrays.asList(ruleNamesArray14));
 609  
         } else {
 610  0
             rules.addAll(Arrays.asList(ruleNamesArray2));
 611  
         }
 612  900
     }
 613  
 
 614  
     /**
 615  
      * Add a rule to the list of rules.
 616  
      *
 617  
      * @param rule
 618  
      *            the PerspectiveRule to be added
 619  
      */
 620  
     public void addRule(PerspectiveRule rule) {
 621  0
         rules.add(rule);
 622  0
     }
 623  
 
 624  
     /**
 625  
      * Remove a rule from the list.
 626  
      *
 627  
      * @param rule
 628  
      *            the PerspectiveRule to be removed
 629  
      */
 630  
     public void removeRule(PerspectiveRule rule) {
 631  0
         rules.remove(rule);
 632  0
     }
 633  
 
 634  
     /**
 635  
      * @return the collection of rules
 636  
      */
 637  
     public Collection<PerspectiveRule> getRules() {
 638  56
         return rules;
 639  
     }
 640  
 
 641  
     /**
 642  
      * Save the user perspectives in the ArgoUML configuration.
 643  
      */
 644  
     public void saveUserPerspectives() {
 645  1
         Configuration.setString(Argo.KEY_USER_EXPLORER_PERSPECTIVES, this
 646  
                 .toString());
 647  1
     }
 648  
 
 649  
     /**
 650  
      * @return string representation of the perspectives in the same format as
 651  
      *         saved in the user properties.
 652  
      * @see java.lang.Object#toString()
 653  
      */
 654  
     @Override
 655  
     public String toString() {
 656  
 
 657  1
         StringBuffer p = new StringBuffer();
 658  
 
 659  1
         for (ExplorerPerspective perspective : getPerspectives()) {
 660  9
             String name = perspective.toString();
 661  9
             p.append(name).append(",");
 662  9
             for (PerspectiveRule rule : perspective.getList()) {
 663  121
                 p.append(rule.getClass().getName()).append(",");
 664  
             }
 665  9
             p.deleteCharAt(p.length() - 1);
 666  9
             p.append(";");
 667  9
         }
 668  
         
 669  1
         p.deleteCharAt(p.length() - 1);
 670  1
         return p.toString();
 671  
     }
 672  
 }