|
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 |
|
18 package s60cenrep.provider; |
|
19 |
|
20 import interfaces.CellModifier; |
|
21 |
|
22 import java.util.ArrayList; |
|
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.Repository; |
|
40 import cenrep.provider.BitItemProvider; |
|
41 |
|
42 public class BitmaskBitItemProvider extends BitItemProvider |
|
43 implements ITableItemLabelProvider, CellModifier{ |
|
44 |
|
45 public static final String PROP_REF = "ref"; |
|
46 |
|
47 private static final EStructuralFeature BIT_NUMBER = CenrepPackage.eINSTANCE.getBit_Number(); |
|
48 private static final EStructuralFeature BIT_REF = CenrepPackage.eINSTANCE.getRVG_Ref(); |
|
49 private static final EStructuralFeature BIT_STATE = CenrepPackage.eINSTANCE.getBit_State(); |
|
50 |
|
51 public BitmaskBitItemProvider(AdapterFactory adapterFactory) { |
|
52 super(adapterFactory); |
|
53 } |
|
54 |
|
55 @Override |
|
56 protected Collection getChildrenFeatures(Object object) { |
|
57 if(childrenFeatures==null){ |
|
58 childrenFeatures = new ArrayList<EStructuralFeature>(); |
|
59 } |
|
60 return childrenFeatures; |
|
61 } |
|
62 |
|
63 public Object getColumnImage(Object object, int columnIndex) { |
|
64 |
|
65 if (columnIndex == 0) |
|
66 { |
|
67 EObject eObject = (EObject)object; |
|
68 Boolean state = (Boolean)eObject.eGet(BIT_STATE); |
|
69 if (state.booleanValue()) |
|
70 return overlayImage(object, getResourceLocator().getImage("full/obj16/1bit")); |
|
71 else |
|
72 return overlayImage(object, getResourceLocator().getImage("full/obj16/0bit")); |
|
73 } |
|
74 else |
|
75 return null; |
|
76 |
|
77 |
|
78 } |
|
79 |
|
80 public String getColumnText(Object object, int columnIndex) { |
|
81 EObject eObject = (EObject)object; |
|
82 switch (columnIndex) { |
|
83 case 0: |
|
84 return "bit "+String.valueOf((Integer)eObject.eGet(BIT_NUMBER)); |
|
85 case 1: |
|
86 return (String)eObject.eGet(BIT_REF); |
|
87 } |
|
88 return ""; |
|
89 } |
|
90 |
|
91 @Override |
|
92 public List getPropertyDescriptors(Object object) { |
|
93 if (itemPropertyDescriptors == null) { |
|
94 itemPropertyDescriptors = new ArrayList<IItemPropertyDescriptor>(); |
|
95 addRefPropertyDescriptor(object); |
|
96 addStatePropertyDescriptor(object); |
|
97 addNumberPropertyDescriptor(object); |
|
98 } |
|
99 return itemPropertyDescriptors; |
|
100 } |
|
101 |
|
102 public void notifyChanged(Notification notification) { |
|
103 switch (notification.getFeatureID(Repository.class)) { |
|
104 case CenrepPackage.KEY__BITS: |
|
105 fireNotifyChanged(new ViewerNotification(notification, notification |
|
106 .getNotifier(), true, false)); |
|
107 return; |
|
108 } |
|
109 super.notifyChanged(notification); |
|
110 } |
|
111 |
|
112 public boolean canModify(Object element, String property) |
|
113 { |
|
114 if (property.equals(PROP_REF)) |
|
115 return true; |
|
116 else |
|
117 return false; |
|
118 } |
|
119 |
|
120 public Object getValue(Object element, String property) |
|
121 { |
|
122 EObject eObject = (EObject) element; |
|
123 String result = null; |
|
124 if (property.equals(PROP_REF)) |
|
125 result = (String) eObject.eGet(BIT_REF); |
|
126 return result != null ? result : ""; |
|
127 } |
|
128 |
|
129 public void modify(Object parent, Object element, String property, |
|
130 Object value) |
|
131 { |
|
132 EObject object = (EObject) element; |
|
133 EditingDomain domain = AdapterFactoryEditingDomain |
|
134 .getEditingDomainFor(object); |
|
135 Command command = null; |
|
136 |
|
137 if (property.equals(PROP_REF)) { |
|
138 String oldRef = (String) object.eGet(BIT_REF); |
|
139 String newRef = (String) value; |
|
140 if (oldRef != newRef) { |
|
141 command = SetCommand.create(domain, object, BIT_REF, newRef); |
|
142 } |
|
143 } |
|
144 if (command != null) |
|
145 domain.getCommandStack().execute(command); |
|
146 |
|
147 } |
|
148 |
|
149 } |