KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.directory.ldapstudio.schemas.model.ObjectClass;
27 import org.eclipse.swt.graphics.Image;
28 import org.eclipse.ui.ISharedImages;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.plugin.AbstractUIPlugin;
31
32
33 /**
34  * This class is used to display an object class in a tree viewer.
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

39 public class ObjectClassWrapper extends TreeNode
40 {
41     /**
42      * This enum represent the different states of an ObjectClassWrapper
43      *
44      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
45      * @version $Rev$, $Date$
46      */

47     public enum State
48     {
49         resolved, unResolved
50     }
51
52     /** The state */
53     private State state;
54
55     /** The associated object class */
56     private ObjectClass myObjectClass;
57
58
59     /**
60      * Creates a new instance of ObjectClassWrapper.
61      *
62      * @param myObjectClass
63      * the associated object class
64      * @param parent
65      * the parent element
66      */

67     public ObjectClassWrapper( ObjectClass myObjectClass, ITreeNode parent )
68     {
69         super( parent );
70         this.myObjectClass = myObjectClass;
71         this.state = State.resolved;
72     }
73
74
75     /**
76      * Gets the associated object class
77      *
78      * @return
79      * the associated object class
80      */

81     public ObjectClass getMyObjectClass()
82     {
83         return myObjectClass;
84     }
85
86
87     /**
88      * Gets the state of the object class wrapper.
89      *
90      * @return
91      * the state of the object class wrapper
92      */

93     public State getState()
94     {
95         return state;
96     }
97
98
99     /**
100      * Sets the state of the object class wrapper.
101      *
102      * @param state
103      * the state of the object class wrapper
104      */

105     public void setState( State state )
106     {
107         this.state = state;
108     }
109
110
111     /* (non-Javadoc)
112      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.TreeNode#getImage()
113      */

114     public Image getImage()
115     {
116         String JavaDoc imageKey = ISharedImages.IMG_OBJS_WARN_TSK;
117
118         if ( state == State.resolved )
119             return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_OBJECT_CLASS )
120                 .createImage();
121         else if ( state == State.unResolved )
122             return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
123                 PluginConstants.IMG_OBJECT_CLASS_WARNING ).createImage();
124
125         return PlatformUI.getWorkbench().getSharedImages().getImage( imageKey );
126     }
127
128
129     /* (non-Javadoc)
130      * @see java.lang.Object#equals(java.lang.Object)
131      */

132     public boolean equals( Object JavaDoc obj )
133     {
134         if ( obj instanceof ObjectClassWrapper )
135         {
136             ObjectClassWrapper compared = ( ObjectClassWrapper ) obj;
137             return compared.getMyObjectClass().getOid().equals( this.getMyObjectClass().getOid() );
138         }
139         return false;
140     }
141
142
143     /* (non-Javadoc)
144      * @see java.lang.Object#toString()
145      */

146     public String JavaDoc toString()
147     {
148         return myObjectClass + " wrapper"; //$NON-NLS-1$
149
}
150 }
151
Popular Tags