KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > ecore > genmodel > provider > GenBaseItemProvider


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: GenBaseItemProvider.java,v 1.6 2005/06/08 06:17:51 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.provider;
18
19
20 import java.util.Arrays JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
24 import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
25 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
26 import org.eclipse.emf.common.notify.AdapterFactory;
27 import org.eclipse.emf.common.notify.Notification;
28 import org.eclipse.emf.common.util.ResourceLocator;
29 import org.eclipse.emf.ecore.EStructuralFeature;
30 import org.eclipse.emf.edit.provider.ComposedImage;
31 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
32 import org.eclipse.emf.edit.provider.IItemLabelProvider;
33 import org.eclipse.emf.edit.provider.IItemPropertySource;
34 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
35 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
36 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
37 import org.eclipse.emf.edit.provider.ItemProviderAdapter;
38
39
40 /**
41  * This is the item provider adapter for a {@link org.eclipse.emf.codegen.ecore.genmodel.GenBase} object.
42  * <!-- begin-user-doc -->
43  * <!-- end-user-doc -->
44  * @generated
45  */

46 public class GenBaseItemProvider
47   extends ItemProviderAdapter
48   implements
49     IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource
50 {
51   public static class UnderlayedImage extends ComposedImage
52   {
53     public UnderlayedImage(Object JavaDoc imageDescriptor)
54     {
55       super
56         (Arrays.asList
57           (new Object JavaDoc[]
58            { GenModelEditPlugin.INSTANCE.getImage("full/obj16/Underlay"),
59              imageDescriptor
60            }));
61     }
62
63     public UnderlayedImage(Object JavaDoc imageDescriptor, Object JavaDoc multiplicity)
64     {
65       super
66         (Arrays.asList
67           (new Object JavaDoc[]
68            { GenModelEditPlugin.INSTANCE.getImage("full/obj16/Underlay"),
69              imageDescriptor,
70              multiplicity
71            }));
72     }
73
74     public List JavaDoc getDrawPoints(Size size)
75     {
76       List JavaDoc result = super.getDrawPoints(size);
77       if (result.size() > 2)
78       {
79         ((Point)result.get(1)).y = -2;
80       }
81       return result;
82     }
83   }
84
85   /**
86    * This constructs an instance from a factory and a notifier.
87    * <!-- begin-user-doc -->
88    * <!-- end-user-doc -->
89    * @generated
90    */

91   public GenBaseItemProvider(AdapterFactory adapterFactory)
92   {
93     super(adapterFactory);
94   }
95
96   /**
97    * This returns the property descriptors for the adapted class.
98    * <!-- begin-user-doc -->
99    * <!-- end-user-doc -->
100    * @generated
101    */

102   public List JavaDoc getPropertyDescriptors(Object JavaDoc object)
103   {
104     if (itemPropertyDescriptors == null)
105     {
106       super.getPropertyDescriptors(object);
107
108     }
109     return itemPropertyDescriptors;
110   }
111
112   /**
113    * This returns the label text for the adapted class.
114    * <!-- begin-user-doc -->
115    * <!-- end-user-doc -->
116    * @generated
117    */

118   public String JavaDoc getText(Object JavaDoc object)
119   {
120     return getString("_UI_GenBase_type");
121   }
122
123   /**
124    * This handles model notifications by calling {@link #updateChildren} to update any cached
125    * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
126    * <!-- begin-user-doc -->
127    * <!-- end-user-doc -->
128    * @generated
129    */

130   public void notifyChanged(Notification notification)
131   {
132     updateChildren(notification);
133     super.notifyChanged(notification);
134   }
135
136   /**
137    * Return the resource locator for this item provider's resources.
138    * <!-- begin-user-doc -->
139    * <!-- end-user-doc -->
140    * @generated
141    */

142   public ResourceLocator getResourceLocator()
143   {
144     return GenModelEditPlugin.INSTANCE;
145   }
146
147   /**
148    * Returns whether changes to the object will be persisted.
149    */

150   protected static boolean canEdit(Object JavaDoc object)
151   {
152     if (object instanceof GenModel) return true;
153     if (object instanceof GenPackage)
154     {
155       return ((GenPackage)object).canGenerate();
156     }
157     if (object instanceof GenBase)
158     {
159       return canEdit(((GenBase)object).eContainer());
160     }
161     return false;
162   }
163
164   protected ItemPropertyDescriptor createItemPropertyDescriptor(AdapterFactory adapterFactory, ResourceLocator resourceLocator, String JavaDoc displayName, String JavaDoc description, EStructuralFeature feature, boolean isSettable, Object JavaDoc staticImage, String JavaDoc category, String JavaDoc[] filterFlags)
165   {
166     return new GenItemPropertyDescriptor(
167       adapterFactory,
168       displayName,
169       description,
170       feature,
171       isSettable,
172       staticImage,
173       category);
174   }
175
176   /**
177    * A simple extension of ItemPropertyDescriptor that forbids editing of
178    * items that will not be persisted.
179    */

180   protected static class GenItemPropertyDescriptor
181     extends ItemPropertyDescriptor
182   {
183     public GenItemPropertyDescriptor(
184       AdapterFactory adapterFactory, String JavaDoc displayName, String JavaDoc description,
185       EStructuralFeature feature, boolean isSettable, String JavaDoc category)
186     {
187       super(adapterFactory, displayName, description, feature, isSettable,
188             category);
189
190     }
191
192     public GenItemPropertyDescriptor(
193       AdapterFactory adapterFactory, String JavaDoc displayName, String JavaDoc description,
194       EStructuralFeature feature, boolean isSettable, Object JavaDoc staticImage,
195       String JavaDoc category)
196     {
197       super(adapterFactory, displayName, description, feature, isSettable,
198             staticImage, category);
199     }
200
201     public boolean canSetProperty(Object JavaDoc object)
202     {
203       return isSettable && canEdit(object);
204     }
205   }
206
207 }
208
Popular Tags