|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package s60cenrep.provider; |
|
18 |
|
19 import interfaces.CellModifier; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.Arrays; |
|
23 import java.util.Collection; |
|
24 import java.util.List; |
|
25 |
|
26 import org.eclipse.emf.common.command.Command; |
|
27 import org.eclipse.emf.common.notify.AdapterFactory; |
|
28 import org.eclipse.emf.common.notify.Notification; |
|
29 import org.eclipse.emf.ecore.EObject; |
|
30 import org.eclipse.emf.ecore.EStructuralFeature; |
|
31 import org.eclipse.emf.edit.command.SetCommand; |
|
32 import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; |
|
33 import org.eclipse.emf.edit.domain.EditingDomain; |
|
34 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
|
35 import org.eclipse.emf.edit.provider.ITableItemLabelProvider; |
|
36 import org.eclipse.emf.edit.provider.ViewerNotification; |
|
37 |
|
38 import cenrep.CenrepPackage; |
|
39 import cenrep.Key; |
|
40 import cenrep.Repository; |
|
41 import cenrep.TYPE; |
|
42 import cenrep.provider.KeyItemProvider; |
|
43 |
|
44 public class BitmaskKeyItemProvider extends KeyItemProvider |
|
45 implements ITableItemLabelProvider, CellModifier{ |
|
46 |
|
47 public static final String PROP_NAME = "name"; |
|
48 public static final String PROP_TYPE = "type"; |
|
49 public static final String PROP_UID = "uid"; |
|
50 public static final String PROP_REF = "ref"; |
|
51 |
|
52 public static final EStructuralFeature NAME_FEATURE = CenrepPackage.eINSTANCE.getKey_Name(); |
|
53 public static final EStructuralFeature REF_FEATURE = CenrepPackage.eINSTANCE.getRVG_Ref(); |
|
54 public static final EStructuralFeature UID_FEATURE = CenrepPackage.eINSTANCE.getKey_ShortIdent(); |
|
55 //public static final EStructuralFeature STR_TYPE_FEATURE = CenrepPackage.eINSTANCE.getKey_StrType(); |
|
56 public static final EStructuralFeature TYPE_FEATURE = CenrepPackage.eINSTANCE.getKey_Type(); |
|
57 |
|
58 |
|
59 private final EStructuralFeature[] REPOSITORY_CHILDREN= new EStructuralFeature[]{ |
|
60 CenrepPackage.Literals.REPOSITORY__BITMASK_KEYS |
|
61 }; |
|
62 |
|
63 private final EStructuralFeature[] KEY_CHILDREN= new EStructuralFeature[]{ |
|
64 CenrepPackage.Literals.KEY__BITS |
|
65 }; |
|
66 |
|
67 public BitmaskKeyItemProvider(AdapterFactory adapterFactory) { |
|
68 super(adapterFactory); |
|
69 } |
|
70 |
|
71 |
|
72 @Override |
|
73 public Collection getChildrenFeatures(Object object) { |
|
74 |
|
75 if(object instanceof Repository) |
|
76 return Arrays.asList(REPOSITORY_CHILDREN); |
|
77 else if (object instanceof Key) |
|
78 return Arrays.asList(KEY_CHILDREN); |
|
79 |
|
80 return null; |
|
81 } |
|
82 |
|
83 public Object getColumnImage(Object object, int columnIndex) { |
|
84 if(columnIndex==0) return getImage(object); |
|
85 return null; |
|
86 } |
|
87 |
|
88 public String getColumnText(Object object, int columnIndex) { |
|
89 Key key = (Key)object; |
|
90 switch(columnIndex){ |
|
91 case 0: |
|
92 return key.getName(); |
|
93 case 1: |
|
94 return key.getRef(); |
|
95 case 2: |
|
96 return key.getShortIdent(); |
|
97 case 3: |
|
98 return key.getType().getName(); |
|
99 } |
|
100 return null; |
|
101 } |
|
102 |
|
103 @Override |
|
104 public List getPropertyDescriptors(Object object) { |
|
105 if (itemPropertyDescriptors == null) { |
|
106 itemPropertyDescriptors = new ArrayList<IItemPropertyDescriptor>(); |
|
107 addBackupPropertyDescriptor(object); |
|
108 addReadOnlyPropertyDescriptor(object); |
|
109 addNamePropertyDescriptor(object); |
|
110 addShortIdentPropertyDescriptor(object); |
|
111 addTypePropertyDescriptor(object); |
|
112 addRefPropertyDescriptor(object); |
|
113 |
|
114 } |
|
115 return itemPropertyDescriptors; |
|
116 } |
|
117 |
|
118 @Override |
|
119 /* |
|
120 protected void addNamePropertyDescriptor(Object object) { |
|
121 itemPropertyDescriptors.add |
|
122 (createItemPropertyDescriptor |
|
123 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
|
124 getResourceLocator(), |
|
125 getString("_UI_Key_name_feature"), |
|
126 getString("_UI_PropertyDescriptor_description", "_UI_Key_name_feature", "_UI_Key_type"), |
|
127 CenrepPackage.Literals.KEY__NAME, |
|
128 true, |
|
129 false, |
|
130 false, |
|
131 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, |
|
132 "UidName", |
|
133 null)); |
|
134 } |
|
135 */ |
|
136 |
|
137 public boolean canModify(Object element, String property) { |
|
138 |
|
139 return true; |
|
140 } |
|
141 |
|
142 public Object getValue(Object element, String property) { |
|
143 EObject key = (EObject)element; |
|
144 Object result = null; |
|
145 if(property.equals(PROP_NAME)) |
|
146 result = (String) key.eGet(NAME_FEATURE); |
|
147 else if(property.equals(PROP_REF)) |
|
148 result = (String) key.eGet(REF_FEATURE); |
|
149 else if(property.equals(PROP_TYPE)) |
|
150 result = Integer.valueOf(((TYPE)key.eGet(TYPE_FEATURE)).getValue()); |
|
151 else if(property.equals(PROP_UID)) |
|
152 result = (String) key.eGet(UID_FEATURE); |
|
153 return result!=null?result:""; |
|
154 } |
|
155 |
|
156 public void modify(Object parent,Object element, String property, Object value) { |
|
157 Command command=null; |
|
158 EObject eObject=(EObject)element; |
|
159 EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(eObject); |
|
160 if(property.equals(PROP_NAME)){ |
|
161 String oldName = (String) eObject.eGet(NAME_FEATURE); |
|
162 String newName = (String) value; |
|
163 if(oldName==null || !oldName.equals(newName)) |
|
164 command = SetCommand.create(domain, eObject, NAME_FEATURE, newName); |
|
165 } |
|
166 else if(property.equals(PROP_REF)){ |
|
167 String oldRef = (String) eObject.eGet(REF_FEATURE); |
|
168 String newRef = (String) value; |
|
169 if(oldRef==null || !oldRef.equals(newRef)) |
|
170 command = SetCommand.create(domain, eObject, REF_FEATURE, newRef); |
|
171 } |
|
172 else if(property.equals(PROP_UID)){ |
|
173 String oldUid = (String) eObject.eGet(UID_FEATURE); |
|
174 String newUid = (String) value; |
|
175 if (newUid.startsWith("0x") || newUid.startsWith("0X")) |
|
176 newUid = "0x"+newUid.substring(2).toUpperCase(); |
|
177 else |
|
178 newUid = "0x"+newUid.toUpperCase(); |
|
179 if(oldUid==null || !oldUid.equals(newUid)) |
|
180 command = SetCommand.create(domain, eObject, UID_FEATURE, newUid); |
|
181 } |
|
182 else if(property.equals(PROP_TYPE)){ |
|
183 TYPE oldType = (TYPE) eObject.eGet(TYPE_FEATURE); |
|
184 TYPE newType = TYPE.get(((Integer)value).intValue()); |
|
185 if(oldType==null || !oldType.equals(newType)) |
|
186 command = SetCommand.create(domain, eObject, TYPE_FEATURE, newType); |
|
187 } |
|
188 if(command!=null) |
|
189 domain.getCommandStack().execute(command); |
|
190 |
|
191 } |
|
192 public void notifyChanged(Notification notification) { |
|
193 switch (notification.getFeatureID(Repository.class)) { |
|
194 case CenrepPackage.REPOSITORY__KEY: |
|
195 fireNotifyChanged(new ViewerNotification(notification, notification |
|
196 .getNotifier(), true, false)); |
|
197 return; |
|
198 |
|
199 case CenrepPackage.KEY__BITS: |
|
200 fireNotifyChanged(new ViewerNotification(notification, notification |
|
201 .getNotifier(), true, false)); |
|
202 return; |
|
203 } |
|
204 super.notifyChanged(notification); |
|
205 } |
|
206 |
|
207 } |