KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > views > wrappers > IntermediateNode


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.schemas.view.views.wrappers;
22
23
24 import org.apache.directory.ldapstudio.schemas.Activator;
25 import org.apache.directory.ldapstudio.schemas.PluginConstants;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.ui.ISharedImages;
28 import org.eclipse.ui.PlatformUI;
29 import org.eclipse.ui.plugin.AbstractUIPlugin;
30
31
32 /**
33  * Class used to display intermediate folder (like 'Optionnal Attributes',
34  * 'Mandatory Attributes' and so on...) in the tree view of the schema.
35  * Instances of the class may contain any kind of displayable objects like
36  * AttributeTypeLiterals or ObjectClassLiterals.
37  *
38  */

39 public class IntermediateNode extends TreeNode
40 {
41     /** This enum represent the different types of IntermediateNodes */
42     public enum IntermediateNodeType
43     {
44         NONE, OBJECT_CLASS_FOLDER, ATTRIBUTE_TYPE_FOLDER
45     }
46
47     /** The name */
48     private String JavaDoc name;
49
50     /** The type */
51     private IntermediateNodeType type;
52
53
54     /**
55      * Default constructor
56      * @param name the name that will be displayed in the tree viewer
57      * @param parent the parent DisplayableTreeElement in the schema relationship
58      * hierarchy
59      */

60     public IntermediateNode( String JavaDoc name, ITreeNode parent )
61     {
62         super( parent );
63         this.name = name;
64         this.type = IntermediateNodeType.NONE;
65     }
66
67
68     /**
69      * Default constructor
70      * @param name
71      * the name that will be displayed in the tree viewer
72      * @param parent
73      * the parent DisplayableTreeElement in the schema relationship
74      * hierarchy
75      * @param type
76      * the type of IntermediateNode
77      */

78     public IntermediateNode( String JavaDoc name, ITreeNode parent, IntermediateNodeType type )
79     {
80         super( parent );
81         this.name = name;
82         this.type = type;
83     }
84
85
86     /******************************************
87      * Accessors *
88      ******************************************/

89
90     /**
91      * @return the name of the intermediate node
92      */

93     public String JavaDoc getName()
94     {
95         return name;
96     }
97
98
99     /* (non-Javadoc)
100      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.TreeNode#getImage()
101      */

102     public Image getImage()
103     {
104         switch ( type )
105         {
106             case NONE:
107                 String JavaDoc imageKey = ISharedImages.IMG_OBJ_FOLDER;
108                 return PlatformUI.getWorkbench().getSharedImages().getImage( imageKey );
109             case ATTRIBUTE_TYPE_FOLDER:
110                 return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
111                     PluginConstants.IMG_FOLDER_ATTRIBUTE_TYPE ).createImage();
112             case OBJECT_CLASS_FOLDER:
113                 return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
114                     PluginConstants.IMG_FOLDER_OBJECT_CLASS ).createImage();
115         }
116
117         String JavaDoc imageKey = ISharedImages.IMG_OBJ_FOLDER;
118         return PlatformUI.getWorkbench().getSharedImages().getImage( imageKey );
119     }
120
121
122     /* (non-Javadoc)
123      * @see java.lang.Object#toString()
124      */

125     public String JavaDoc toString()
126     {
127         return name;
128     }
129
130
131     /* (non-Javadoc)
132      * @see java.lang.Object#equals(java.lang.Object)
133      */

134     public boolean equals( Object JavaDoc obj )
135     {
136         if ( obj instanceof IntermediateNode )
137         {
138             IntermediateNode compared = ( IntermediateNode ) obj;
139             if ( compared.getName().equals( this.getName() ) )
140             {
141                 if ( ( compared.getParent() == null ) || ( this.getParent() == null ) )
142                     return true;
143                 if ( compared.getParent().equals( this.getParent() ) )
144                     return true;
145             }
146         }
147         return false;
148     }
149
150
151     /**
152      * Gets the type of IntermediateNode
153      *
154      * @return
155      * the type of IntermediateNode
156      */

157     public IntermediateNodeType getType()
158     {
159         return type;
160     }
161
162
163     /**
164      * Sets the type of IntermediateNode
165      *
166      * @param type
167      * the type to set
168      */

169     public void setType( IntermediateNodeType type )
170     {
171         this.type = type;
172     }
173 }
174
Popular Tags