KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > tasklist > MarkerType


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.tasklist;
13
14 import java.util.ArrayList JavaDoc;
15
16 /**
17  * Represents a marker type.
18  */

19 class MarkerType {
20     private MarkerTypesModel model;
21
22     private String JavaDoc id;
23
24     private String JavaDoc label;
25
26     private String JavaDoc[] supertypeIds;
27
28     /**
29      * Creates a new marker type.
30      */

31     public MarkerType(MarkerTypesModel model, String JavaDoc id, String JavaDoc label,
32             String JavaDoc[] supertypeIds) {
33         this.model = model;
34         this.id = id;
35         this.label = label;
36         this.supertypeIds = supertypeIds;
37     }
38
39     /**
40      * Returns all this type's supertypes.
41      */

42     public MarkerType[] getAllSupertypes() {
43         ArrayList JavaDoc result = new ArrayList JavaDoc();
44         getAllSupertypes(result);
45         return (MarkerType[]) result.toArray(new MarkerType[result.size()]);
46     }
47
48     /**
49      * Appends all this type's supertypes to the given list.
50      */

51     private void getAllSupertypes(ArrayList JavaDoc result) {
52         MarkerType[] supers = getSupertypes();
53         for (int i = 0; i < supers.length; ++i) {
54             MarkerType sup = supers[i];
55             if (!result.contains(sup)) {
56                 result.add(sup);
57                 sup.getAllSupertypes(result);
58             }
59         }
60     }
61
62     /**
63      * Returns the marker type id.
64      */

65     public String JavaDoc getId() {
66         return id;
67     }
68
69     /**
70      * Returns the human-readable label for this marker type.
71      */

72     public String JavaDoc getLabel() {
73         return label;
74     }
75
76     /**
77      * Returns the types which have this type as a direct supertype.
78      *
79      * @return the direct subtypes of this type
80      */

81     public MarkerType[] getSubtypes() {
82         MarkerType[] types = model.getTypes();
83         ArrayList JavaDoc result = new ArrayList JavaDoc();
84         for (int i = 0; i < types.length; ++i) {
85             MarkerType type = types[i];
86             String JavaDoc[] supers = type.getSupertypeIds();
87             for (int j = 0; j < supers.length; ++j) {
88                 if (supers[j].equals(id)) {
89                     result.add(type);
90                 }
91             }
92         }
93         return (MarkerType[]) result.toArray(new MarkerType[result.size()]);
94     }
95
96     /**
97      * Returns the marker type ids for this type's supertypes.
98      */

99     public String JavaDoc[] getSupertypeIds() {
100         return supertypeIds;
101     }
102
103     /**
104      * Returns this type's direct supertypes.
105      */

106     public MarkerType[] getSupertypes() {
107         ArrayList JavaDoc result = new ArrayList JavaDoc();
108         for (int i = 0; i < supertypeIds.length; ++i) {
109             MarkerType sup = model.getType(supertypeIds[i]);
110             if (sup != null) {
111                 result.add(sup);
112             }
113         }
114         return (MarkerType[]) result.toArray(new MarkerType[result.size()]);
115     }
116
117     /**
118      * Returns whether this marker type is considered to be a subtype of
119      * the given marker type.
120      *
121      * @return boolean <code>true</code>if this type is the same as (or a subtype of) the given type
122      */

123     public boolean isSubtypeOf(MarkerType superType) {
124         if (id.equals(superType.getId())) {
125             return true;
126         }
127         for (int i = 0; i < supertypeIds.length; ++i) {
128             MarkerType sup = model.getType(supertypeIds[i]);
129             if (sup != null && sup.isSubtypeOf(superType)) {
130                 return true;
131             }
132         }
133         return false;
134     }
135 }
136
Popular Tags