Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PerspectiveSupport |
|
| 1.3636363636363635;1.364 |
1 | /* $Id: PerspectiveSupport.java 17841 2010-01-12 19:17:52Z 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.ui; | |
40 | ||
41 | import java.util.ArrayList; | |
42 | import java.util.List; | |
43 | ||
44 | import javax.swing.tree.TreeModel; | |
45 | ||
46 | import org.argouml.i18n.Translator; | |
47 | ||
48 | ||
49 | /** | |
50 | * Helper class for tree models that provides help building perspectives | |
51 | * out of gorules.<p> | |
52 | * | |
53 | * @author alexb | |
54 | * @since 0.13.5, Created on 15 April 2003 | |
55 | */ | |
56 | public class PerspectiveSupport { | |
57 | ||
58 | /** | |
59 | * The go rules that this Tree model uses to build child nodes. | |
60 | */ | |
61 | private List<TreeModel> goRules; | |
62 | ||
63 | /** name */ | |
64 | private String name; | |
65 | ||
66 | /** list of all possible rules in the collection Todolist specific */ | |
67 | 900 | private static List<TreeModel> rules = new ArrayList<TreeModel>(); |
68 | ||
69 | 0 | private PerspectiveSupport() { |
70 | 0 | } |
71 | ||
72 | /** | |
73 | * Creates a new instance of PerspectiveSupport | |
74 | * | |
75 | * @param n the name to be localized | |
76 | */ | |
77 | 5400 | public PerspectiveSupport(String n) { |
78 | 5400 | name = Translator.localize(n); |
79 | 5400 | goRules = new ArrayList<TreeModel>(); |
80 | 5400 | } |
81 | ||
82 | /** | |
83 | * The constructor.<p> | |
84 | * | |
85 | * TODO: Is this constructor used? What is the purpose with it? | |
86 | * | |
87 | * @param n the name to be localized | |
88 | * @param subs the go rules | |
89 | */ | |
90 | public PerspectiveSupport(String n, List<TreeModel> subs) { | |
91 | 0 | this(n); |
92 | 0 | goRules = subs; |
93 | 0 | } |
94 | ||
95 | // ------------- Rule management -------------- | |
96 | ||
97 | /** | |
98 | * Adds a rule to the perspective that will generate child | |
99 | * nodes for any given parent node. | |
100 | * | |
101 | * @param tm the tree model to be added | |
102 | */ | |
103 | public void addSubTreeModel(TreeModel tm) { | |
104 | 5400 | if (goRules.contains(tm)) { |
105 | 0 | return; |
106 | } | |
107 | 5400 | goRules.add(tm); |
108 | 5400 | } |
109 | ||
110 | /** | |
111 | * Remove a rule from the perspective that will generate child | |
112 | * nodes for any given parent node. | |
113 | * | |
114 | * @param tm the treemodel to be removed | |
115 | */ | |
116 | public void removeSubTreeModel(TreeModel tm) { | |
117 | 0 | goRules.remove(tm); |
118 | 0 | } |
119 | ||
120 | ||
121 | /** | |
122 | * Get the rules that together form the perspective. | |
123 | * | |
124 | * @return the rules that form the perspective | |
125 | */ | |
126 | public List<TreeModel> getSubTreeModelList() { | |
127 | 0 | return goRules; |
128 | } | |
129 | ||
130 | // ----------- name ------------------------- | |
131 | ||
132 | /** | |
133 | * @return the name | |
134 | */ | |
135 | 18352 | public String getName() { return name; } |
136 | ||
137 | ||
138 | /** | |
139 | * @param s the name | |
140 | */ | |
141 | 0 | public void setName(String s) { name = s; } |
142 | ||
143 | ||
144 | /* | |
145 | * @see java.lang.Object#toString() | |
146 | */ | |
147 | @Override | |
148 | public String toString() { | |
149 | 9176 | if (getName() != null) { |
150 | 9176 | return getName(); |
151 | } else { | |
152 | 0 | return super.toString(); |
153 | } | |
154 | } | |
155 | ||
156 | // ------ all rules ---------- | |
157 | ||
158 | /** TODO: factor out | |
159 | * | |
160 | * @param rule the rule to be added | |
161 | */ | |
162 | public static void registerRule(TreeModel rule) { | |
163 | 5400 | rules.add(rule); |
164 | 5400 | } |
165 | ||
166 | /** | |
167 | * @return Returns the _goRules. | |
168 | */ | |
169 | protected List<TreeModel> getGoRuleList() { | |
170 | 34947 | return goRules; |
171 | } | |
172 | } |