KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > model > DrawComponentPropertySource


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 26.10.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.model;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12
13 import org.eclipse.ui.views.properties.IPropertyDescriptor;
14 import org.eclipse.ui.views.properties.IPropertySource;
15 import org.eclipse.ui.views.properties.PropertyDescriptor;
16
17 import com.nightlabs.editor2d.DrawComponent;
18 import com.nightlabs.editor2d.EditorPlugin;
19 import com.nightlabs.editor2d.properties.IntPropertyDescriptor;
20 import com.nightlabs.editor2d.properties.NameLanguageManager;
21 import com.nightlabs.editor2d.properties.NamePropertyDescriptor;
22 import com.nightlabs.editor2d.properties.RotationPropertyDescriptor;
23 import com.nightlabs.rcp.language.LanguageChangeEvent;
24 import com.nightlabs.rcp.language.LanguageChangeListener;
25
26 public class DrawComponentPropertySource
27 implements IPropertySource
28 {
29     protected DrawComponent drawComponent;
30     protected NameLanguageManager nameLangMan;
31     public DrawComponentPropertySource(DrawComponent element) {
32         this.drawComponent = element;
33         descriptors = createPropertyDescriptors();
34         nameLangMan = NameLanguageManager.sharedInstance();
35         nameLangMan.addLanguageChangeListener(langListener);
36     }
37  
38     protected LanguageChangeListener langListener = new LanguageChangeListener(){
39         public void languageChanged(LanguageChangeEvent event) {
40             String JavaDoc newLanguageID = event.getNewLanguage().getLanguageID();
41             drawComponent.setLanguageId(newLanguageID);
42         }
43     };
44     
45     /* (non-Javadoc)
46      * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
47      */

48     public Object JavaDoc getEditableValue() {
49         return drawComponent;
50     }
51
52 // public IPropertyDescriptor[] getPropertyDescriptors() {
53
// return new IPropertyDescriptor[0];
54
// }
55

56 // public IPropertyDescriptor[] getPropertyDescriptors()
57
// {
58
// if( attr.isID() ) {
59
//// descriptors.add( new PropertyDescriptor( Integer.toString( attr.getFeatureID() ),
60
//// attr.getName() ) );
61
// }
62
// // TODO: create Custom LineStyleDialog
63
//// else if( attr.getName().equals("lineStyle")) {
64
//// descriptors.add( new LineStylePropertyDescriptor( Integer.toString( attr.getFeatureID() ),
65
//// attr.getName() ) );
66
//// }
67
// else if ( attr.getName().equals("fontName")) {
68
// descriptors.add( new FontNamePropertyDescriptor(Integer.toString( attr.getFeatureID() ),
69
// attr.getName() ) );
70
// }
71
// else if ( attr.getName().equals("fontSize")) {
72
// descriptors.add( new FontSizePropertyDescriptor(Integer.toString( attr.getFeatureID() ),
73
// attr.getName() ) );
74
// }
75
// else if ( attr.getName().equals("rotation")) {
76
// descriptors.add( new RotationPropertyDescriptor(Integer.toString( attr.getFeatureID() ),
77
// attr.getName() ) );
78
// }
79
// else if ( attr.getName().equals("tmpRotationX")) {
80
// continue;
81
// }
82
// else if ( attr.getName().equals("tmpRotationY")) {
83
// continue;
84
// }
85
// else if( type.getInstanceClass() == String.class ) {
86
// descriptors.add( new TextPropertyDescriptor( Integer.toString( attr.getFeatureID() ),
87
// attr.getName() ) );
88
// }
89
// else if( type.getInstanceClass() == boolean.class )
90
// {
91
// descriptors.add( new CheckboxPropertyDescriptor( Integer.toString( attr.getFeatureID() ),
92
// attr.getName() ) );
93
// }
94
// else if( type.getInstanceClass() == int.class )
95
// {
96
// descriptors.add( new IntPropertyDescriptor( Integer.toString( attr.getFeatureID() ),
97
// attr.getName() ) );
98
// }
99
// else if( type.getInstanceClass() == double.class )
100
// {
101
// descriptors.add( new DoublePropertyDescriptor( Integer.toString( attr.getFeatureID() ),
102
// attr.getName() ) );
103
// }
104
// else if (type.getInstanceClass() == Color.class )
105
// {
106
// descriptors.add(new AWTColorPropertyDescriptor(Integer.toString(attr.getFeatureID()),
107
// attr.getName()));
108
// }
109
//
110
// return (IPropertyDescriptor[])descriptors.toArray( new IPropertyDescriptor[] {} );
111
// }
112

113     public static final String JavaDoc CATEGORY_NAME = EditorPlugin.getResourceString("property.category.name");
114     public static final String JavaDoc CATEGORY_GEOM = EditorPlugin.getResourceString("property.category.geom");
115     public static final String JavaDoc CATEGORY_ROTATION = EditorPlugin.getResourceString("property.category.rotation");
116     
117     protected List JavaDoc descriptors = null;
118     protected List JavaDoc getDescriptors() {
119         if (descriptors == null)
120             descriptors = new ArrayList JavaDoc();
121         return descriptors;
122     }
123         
124     protected List JavaDoc createPropertyDescriptors()
125     {
126         List JavaDoc descriptors = getDescriptors();
127         
128 // // Name
129
// PropertyDescriptor desc = new TextPropertyDescriptor(DrawComponent.PROP_NAME,
130
// EditorPlugin.getResourceString("property.name.label"));
131
// desc.setCategory(CATEGORY_NAME);
132
// descriptors.add(desc);
133
// // Name
134
// PropertyDescriptor desc = new LanguagePropertyDescriptor(
135
// drawComponent.getI18nText(),
136
// DrawComponent.PROP_NAME,
137
// EditorPlugin.getResourceString("property.name.label"));
138
// Name
139
PropertyDescriptor desc = new NamePropertyDescriptor(drawComponent,
140                 DrawComponent.PROP_NAME,
141                 EditorPlugin.getResourceString("property.name.label"));
142         desc.setCategory(CATEGORY_NAME);
143         descriptors.add(desc);
144         
145         // X
146
desc = new IntPropertyDescriptor(DrawComponent.PROP_X,
147                 EditorPlugin.getResourceString("property.x.label"));
148         desc.setCategory(CATEGORY_GEOM);
149         descriptors.add(desc);
150         
151         // Y
152
desc = new IntPropertyDescriptor(DrawComponent.PROP_Y,
153                 EditorPlugin.getResourceString("property.y.label"));
154         desc.setCategory(CATEGORY_GEOM);
155         descriptors.add(desc);
156         
157         // Width
158
desc = new IntPropertyDescriptor(DrawComponent.PROP_WIDTH,
159                 EditorPlugin.getResourceString("property.width.label"));
160         desc.setCategory(CATEGORY_GEOM);
161         descriptors.add(desc);
162         
163         // Height
164
desc = new IntPropertyDescriptor(DrawComponent.PROP_HEIGHT,
165                 EditorPlugin.getResourceString("property.height.label"));
166         desc.setCategory(CATEGORY_GEOM);
167         descriptors.add(desc);
168         
169         // Rotation
170
desc = new RotationPropertyDescriptor(DrawComponent.PROP_ROTATION,
171                 EditorPlugin.getResourceString("property.rotation.label"));
172         desc.setCategory(CATEGORY_ROTATION);
173         descriptors.add(desc);
174         
175         // RotationX
176
desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_X,
177                 EditorPlugin.getResourceString("property.rotationx.label"));
178         desc.setCategory(CATEGORY_ROTATION);
179         descriptors.add(desc);
180         
181         // RotationY
182
desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_Y,
183                 EditorPlugin.getResourceString("property.rotationy.label"));
184         desc.setCategory(CATEGORY_ROTATION);
185         descriptors.add(desc);
186         
187         return descriptors;
188     }
189     
190     public IPropertyDescriptor[] getPropertyDescriptors()
191     {
192         if (drawComponent == null)
193             return new IPropertyDescriptor[0];
194         
195         List JavaDoc descriptors = getDescriptors();
196         return (IPropertyDescriptor[])descriptors.toArray( new IPropertyDescriptor[] {} );
197     }
198     
199     /* (non-Javadoc)
200      * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
201      */

202     public Object JavaDoc getPropertyValue(Object JavaDoc id)
203     {
204         if (id.equals(DrawComponent.PROP_X)) {
205             return new Integer JavaDoc(drawComponent.getX());
206         }
207         else if (id.equals(DrawComponent.PROP_Y)) {
208             return new Integer JavaDoc(drawComponent.getY());
209         }
210         else if (id.equals(DrawComponent.PROP_WIDTH)) {
211             return new Integer JavaDoc(drawComponent.getWidth());
212         }
213         else if (id.equals(DrawComponent.PROP_HEIGHT)) {
214             return new Integer JavaDoc(drawComponent.getHeight());
215         }
216         else if (id.equals(DrawComponent.PROP_ROTATION)) {
217             return new Double JavaDoc(drawComponent.getRotation());
218         }
219         else if (id.equals(DrawComponent.PROP_ROTATION_X)) {
220             return new Integer JavaDoc(drawComponent.getRotationX());
221         }
222         else if (id.equals(DrawComponent.PROP_ROTATION_Y)) {
223             return new Integer JavaDoc(drawComponent.getRotationY());
224         }
225 // else if (id.equals(DrawComponent.PROP_NAME)) {
226
// return drawComponent.getName();
227
// }
228
// else if (id.equals(DrawComponent.PROP_NAME)) {
229
// return drawComponent.getI18nText();
230
// }
231
else if (id.equals(DrawComponent.PROP_NAME)) {
232             return drawComponent.getI18nText().getText(nameLangMan.getCurrentLanguageID());
233         }
234                         
235         return null;
236     }
237
238 // public Object getPropertyValue(Object id)
239
// {
240
// EStructuralFeature feature = element.eClass().getEStructuralFeature( Integer.parseInt( (String)id ) );
241
//
242
// Object result = element.eGet( feature );
243
// return result != null ? result : "";
244
// }
245

246     /* (non-Javadoc)
247      * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
248      */

249     public boolean isPropertySet(Object JavaDoc id) {
250         // TODO Auto-generated method stub
251
return false;
252     }
253
254     /*
255      * @see org.eclipse.ui.views.properties.IPropertySouce#resetPropertyValue(java.lang.Object)
256      */

257     public void resetPropertyValue(Object JavaDoc id) {
258         // TODO Auto-generated method stub
259
}
260
261     /* (non-Javadoc)
262      * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
263      */

264     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value)
265     {
266         if (id.equals(DrawComponent.PROP_X)) {
267             drawComponent.setX(((Integer JavaDoc)value).intValue());
268         }
269         else if (id.equals(DrawComponent.PROP_Y)) {
270             drawComponent.setY(((Integer JavaDoc)value).intValue());
271         }
272         else if (id.equals(DrawComponent.PROP_WIDTH)) {
273             drawComponent.setWidth(((Integer JavaDoc)value).intValue());
274         }
275         else if (id.equals(DrawComponent.PROP_HEIGHT)) {
276             drawComponent.setHeight(((Integer JavaDoc)value).intValue());
277         }
278         else if (id.equals(DrawComponent.PROP_ROTATION)) {
279             drawComponent.setRotation(((Double JavaDoc)value).doubleValue());
280         }
281         else if (id.equals(DrawComponent.PROP_ROTATION_X)) {
282             drawComponent.setRotationX(((Integer JavaDoc)value).intValue());
283         }
284         else if (id.equals(DrawComponent.PROP_ROTATION_Y)) {
285             drawComponent.setRotationY(((Integer JavaDoc)value).intValue());
286         }
287 // else if (id.equals(DrawComponent.PROP_NAME)) {
288
// drawComponent.setName((String)value);
289
// }
290
else if (id.equals(DrawComponent.PROP_NAME)) {
291             drawComponent.setName((String JavaDoc)value);
292         }
293
294     }
295         
296 // public void setPropertyValue(Object id, Object value)
297
// {
298
// EStructuralFeature feature = element.eClass().getEStructuralFeature( Integer.parseInt( (String)id ) );
299
// element.eSet( feature, value );
300
// }
301

302 }
303
304
Popular Tags