|
Lines 29-36
Link Here
|
| 29 |
import org.eclipse.emf.ecore.EClass; |
29 |
import org.eclipse.emf.ecore.EClass; |
| 30 |
import org.eclipse.emf.ecore.EObject; |
30 |
import org.eclipse.emf.ecore.EObject; |
| 31 |
import org.eclipse.emf.ecore.EReference; |
31 |
import org.eclipse.emf.ecore.EReference; |
|
|
32 |
import org.eclipse.emf.facet.infra.browser.uicore.internal.CustomTreePainter; |
| 33 |
import org.eclipse.emf.facet.infra.browser.uicore.internal.FacetToPaint; |
| 32 |
import org.eclipse.emf.facet.infra.browser.uicore.internal.customization.CustomizationEngine; |
34 |
import org.eclipse.emf.facet.infra.browser.uicore.internal.customization.CustomizationEngine; |
| 33 |
import org.eclipse.emf.facet.infra.common.core.logging.Logger; |
35 |
import org.eclipse.emf.facet.infra.common.core.logging.Logger; |
|
|
36 |
import org.eclipse.emf.facet.infra.facet.Facet; |
| 34 |
import org.eclipse.emf.facet.widgets.nattable.Activator; |
37 |
import org.eclipse.emf.facet.widgets.nattable.Activator; |
| 35 |
import org.eclipse.emf.facet.widgets.nattable.ColumnDescription; |
38 |
import org.eclipse.emf.facet.widgets.nattable.ColumnDescription; |
| 36 |
import org.eclipse.emf.facet.widgets.nattable.ColumnDescription.Type; |
39 |
import org.eclipse.emf.facet.widgets.nattable.ColumnDescription.Type; |
|
Lines 87-92
Link Here
|
| 87 |
ColumnDescription columnDescription = this.natTableWidget.getColumnDescriptions().get( |
90 |
ColumnDescription columnDescription = this.natTableWidget.getColumnDescriptions().get( |
| 88 |
convertedColumn); |
91 |
convertedColumn); |
| 89 |
|
92 |
|
|
|
93 |
// leave a 2 pixel wide margin |
| 94 |
Rectangle rectangleWithMargin = new Rectangle(rectangle.x + 2, rectangle.y + 2, |
| 95 |
rectangle.width - 2 * 2, rectangle.height - 2 * 2); |
| 96 |
|
| 90 |
Color backgroundColor = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue( |
97 |
Color backgroundColor = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue( |
| 91 |
CellStyleAttributes.BACKGROUND_COLOR); |
98 |
CellStyleAttributes.BACKGROUND_COLOR); |
| 92 |
Customization customization = null; |
99 |
Customization customization = null; |
|
Lines 97-103
Link Here
|
| 97 |
Object element = gridElement.getElement(); |
104 |
Object element = gridElement.getElement(); |
| 98 |
if (element instanceof EObject) { |
105 |
if (element instanceof EObject) { |
| 99 |
EObject eObject = (EObject) element; |
106 |
EObject eObject = (EObject) element; |
| 100 |
customization = getCustomization(eObject, columnDescription); |
107 |
customization = getCustomization(eObject, columnDescription, rectangleWithMargin); |
| 101 |
} |
108 |
} |
| 102 |
} |
109 |
} |
| 103 |
// } |
110 |
// } |
|
Lines 119-130
Link Here
|
| 119 |
gc.setBackground(originalBackground); |
126 |
gc.setBackground(originalBackground); |
| 120 |
|
127 |
|
| 121 |
Rectangle originalClipping = gc.getClipping(); |
128 |
Rectangle originalClipping = gc.getClipping(); |
| 122 |
// leave a margin |
129 |
gc.setClipping(rectangleWithMargin); |
| 123 |
rectangle.x += 2; |
|
|
| 124 |
rectangle.y += 2; |
| 125 |
rectangle.width -= 2 * 2; |
| 126 |
rectangle.height -= 2 * 2; |
| 127 |
gc.setClipping(rectangle.intersection(originalClipping)); |
| 128 |
|
130 |
|
| 129 |
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); |
131 |
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); |
| 130 |
setupGCFromConfig(gc, cellStyle); |
132 |
setupGCFromConfig(gc, cellStyle); |
|
Lines 142-181
Link Here
|
| 142 |
} |
144 |
} |
| 143 |
} |
145 |
} |
| 144 |
|
146 |
|
|
|
147 |
gc.setClipping(rectangle); |
| 148 |
|
| 145 |
boolean hasIcon = false; |
149 |
boolean hasIcon = false; |
| 146 |
if (customization != null && customization.getInstanceIcon() != null) { |
150 |
if (customization != null && customization.getInstanceIcon() != null) { |
| 147 |
gc.drawImage(customization.getInstanceIcon(), rectangle.x, rectangle.y); |
151 |
gc.drawImage(customization.getInstanceIcon(), rectangleWithMargin.x, |
|
|
152 |
rectangleWithMargin.y); |
| 148 |
hasIcon = true; |
153 |
hasIcon = true; |
| 149 |
} else { |
154 |
} else { |
| 150 |
Image columnImage = this.tableLabelProvider.getColumnImage(cell.getDataValue(), |
155 |
Image columnImage = this.tableLabelProvider.getColumnImage(cell.getDataValue(), |
| 151 |
convertedColumn); |
156 |
convertedColumn); |
| 152 |
if (columnImage != null) { |
157 |
if (columnImage != null) { |
| 153 |
gc.drawImage(columnImage, rectangle.x, rectangle.y); |
158 |
gc.drawImage(columnImage, rectangleWithMargin.x, rectangleWithMargin.y); |
| 154 |
hasIcon = true; |
159 |
hasIcon = true; |
| 155 |
} |
160 |
} |
| 156 |
} |
161 |
} |
| 157 |
|
162 |
|
|
|
163 |
boolean hasOverlay = false; |
| 164 |
if (customization != null) { |
| 165 |
int facetMinX = rectangle.width; |
| 166 |
List<FacetToPaint> facetsToMeasure = customization.getFacetsToPaint(); |
| 167 |
for (FacetToPaint facetToPaint : facetsToMeasure) { |
| 168 |
if (!facetToPaint.isOverlay()) { |
| 169 |
facetMinX = Math.min(facetMinX, facetToPaint.getBounds().x); |
| 170 |
} else { |
| 171 |
hasOverlay = true; |
| 172 |
} |
| 173 |
} |
| 174 |
// reduce the clipping, so as to not draw again over stickers |
| 175 |
Rectangle textClipping = new Rectangle(rectangleWithMargin.x, rectangleWithMargin.y, |
| 176 |
facetMinX - 2, rectangleWithMargin.height); |
| 177 |
gc.setClipping(textClipping); |
| 178 |
} |
| 179 |
|
| 158 |
if (hasIcon) { |
180 |
if (hasIcon) { |
|
|
181 |
final int totalOffsetAfterIcon; |
| 159 |
final int offsetAfterIcon = 18; |
182 |
final int offsetAfterIcon = 18; |
| 160 |
gc.drawText(text, rectangle.x + offsetAfterIcon, rectangle.y, true); |
183 |
final int overlaySize = 8; |
|
|
184 |
if (hasOverlay) { |
| 185 |
totalOffsetAfterIcon = offsetAfterIcon + overlaySize; |
| 186 |
} else { |
| 187 |
totalOffsetAfterIcon = offsetAfterIcon; |
| 188 |
} |
| 189 |
|
| 190 |
gc.drawText(text, rectangleWithMargin.x + totalOffsetAfterIcon, rectangleWithMargin.y, true); |
| 161 |
} else { |
191 |
} else { |
| 162 |
gc.drawText(text, rectangle.x, rectangle.y, true); |
192 |
gc.drawText(text, rectangleWithMargin.x, rectangleWithMargin.y, true); |
| 163 |
} |
193 |
} |
| 164 |
|
194 |
|
|
|
195 |
gc.setClipping(rectangle); |
| 196 |
|
| 165 |
if (customization != null) { |
197 |
if (customization != null) { |
| 166 |
final int leftMargin = 0; |
198 |
final int leftMargin = 0; |
| 167 |
final int rightMargin = 0; |
199 |
final int rightMargin = 0; |
| 168 |
|
200 |
|
| 169 |
if (customization.isUnderlined()) { |
201 |
if (customization.isUnderlined()) { |
| 170 |
final int y = rectangle.y + rectangle.height - 1; |
202 |
final int y = rectangleWithMargin.y + rectangleWithMargin.height - 1; |
| 171 |
gc.drawLine(rectangle.x + leftMargin, y, rectangle.x + rectangle.width |
203 |
gc.drawLine(rectangleWithMargin.x + leftMargin, y, rectangleWithMargin.x |
| 172 |
- rightMargin, y); |
204 |
+ rectangleWithMargin.width - rightMargin, y); |
| 173 |
} |
205 |
} |
| 174 |
|
206 |
|
| 175 |
if (customization.isStruckthrough()) { |
207 |
if (customization.isStruckthrough()) { |
| 176 |
final int y = rectangle.y + rectangle.height / 2 + 1; |
208 |
final int y = rectangleWithMargin.y + rectangleWithMargin.height / 2 + 1; |
| 177 |
gc.drawLine(rectangle.x + leftMargin, y, rectangle.x + rectangle.width |
209 |
gc.drawLine(rectangleWithMargin.x + leftMargin, y, rectangleWithMargin.x |
| 178 |
- rightMargin, y); |
210 |
+ rectangleWithMargin.width - rightMargin, y); |
|
|
211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
if (customization != null) { |
| 215 |
List<FacetToPaint> facetsToPaint = customization.getFacetsToPaint(); |
| 216 |
final int facetStickerBackgroundOpacity = 192; |
| 217 |
for (FacetToPaint facetToPaint : facetsToPaint) { |
| 218 |
Image customizedIcon = facetToPaint.getImage(); |
| 219 |
if (customizedIcon != null) { |
| 220 |
Rectangle bounds = customizedIcon.getBounds(); |
| 221 |
Rectangle target = facetToPaint.getBounds(); |
| 222 |
Rectangle stickerRectangle = new Rectangle(rectangle.x + target.x + 1, |
| 223 |
rectangle.y + target.y + 1, target.width, target.height); |
| 224 |
// int oldAlpha = gc.getAlpha(); |
| 225 |
// gc.setAlpha(facetStickerBackgroundOpacity); |
| 226 |
// gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); |
| 227 |
// gc.fillRectangle(stickerRectangle); |
| 228 |
// gc.setAlpha(oldAlpha); |
| 229 |
gc.drawImage(customizedIcon, 0, 0, bounds.width, bounds.height, |
| 230 |
stickerRectangle.x, stickerRectangle.y, stickerRectangle.width, |
| 231 |
stickerRectangle.height); |
| 232 |
} |
| 179 |
} |
233 |
} |
| 180 |
} |
234 |
} |
| 181 |
|
235 |
|
|
Lines 196-205
Link Here
|
| 196 |
} |
250 |
} |
| 197 |
|
251 |
|
| 198 |
private Customization getCustomization(final EObject eObject, |
252 |
private Customization getCustomization(final EObject eObject, |
| 199 |
final ColumnDescription columnDescription) { |
253 |
final ColumnDescription columnDescription, final Rectangle rectangle) { |
| 200 |
// label column : customization on the EObject, defined on the EClass |
254 |
// label column : customization on the EObject, defined on the EClass |
| 201 |
// unary reference : customization on the EObject, defined on the EClass |
255 |
// unary reference : customization on the EObject, defined on the EClass |
| 202 |
// n-ary reference with a single element: customization on the EObject, defined on the EClass |
256 |
// n-ary reference with a single element: customization on the EObject, |
|
|
257 |
// defined on the EClass |
| 203 |
// n-ary reference (!= 1): no customization |
258 |
// n-ary reference (!= 1): no customization |
| 204 |
// attribute : customization on the EObject, defined on the EAttribute |
259 |
// attribute : customization on the EObject, defined on the EAttribute |
| 205 |
|
260 |
|
|
Lines 278-285
Link Here
|
| 278 |
(EClass) attribute.eContainer(), attribute.getName(), customizedEObject)); |
333 |
(EClass) attribute.eContainer(), attribute.getName(), customizedEObject)); |
| 279 |
} else { |
334 |
} else { |
| 280 |
customization.setLabel(this.customizationEngine.getTypeLabel(customizedEObject)); |
335 |
customization.setLabel(this.customizationEngine.getTypeLabel(customizedEObject)); |
| 281 |
customization.setInstanceIcon(this.customizationEngine.getTypeIcon(customizedEObject, |
336 |
|
| 282 |
customizedEObject.eClass())); |
337 |
// Facet icon customization |
|
|
338 |
Image facetIcon = null; |
| 339 |
for (final Facet facet : this.natTableWidget.getFacetContext().getFacets( |
| 340 |
customizedEObject)) { |
| 341 |
facetIcon = this.customizationEngine.getFacetMainIcon(customizedEObject, facet); |
| 342 |
if (facetIcon != null) { |
| 343 |
// first one wins |
| 344 |
break; |
| 345 |
} |
| 346 |
} |
| 347 |
if (facetIcon != null) { |
| 348 |
customization.setInstanceIcon(facetIcon); |
| 349 |
} else { |
| 350 |
customization.setInstanceIcon(this.customizationEngine.getTypeIcon( |
| 351 |
customizedEObject, customizedEObject.eClass())); |
| 352 |
} |
| 283 |
customization.setBackground(this.customizationEngine |
353 |
customization.setBackground(this.customizationEngine |
| 284 |
.getTypeBackgroundColor(customizedEObject)); |
354 |
.getTypeBackgroundColor(customizedEObject)); |
| 285 |
customization.setForeground(this.customizationEngine.getTypeColor(customizedEObject)); |
355 |
customization.setForeground(this.customizationEngine.getTypeColor(customizedEObject)); |
|
Lines 289-294
Link Here
|
| 289 |
customizedEObject.eClass(), customizedEObject)); |
359 |
customizedEObject.eClass(), customizedEObject)); |
| 290 |
customization.setStruckthrough(this.customizationEngine.isTypeStruckthrough( |
360 |
customization.setStruckthrough(this.customizationEngine.isTypeStruckthrough( |
| 291 |
customizedEObject.eClass(), customizedEObject)); |
361 |
customizedEObject.eClass(), customizedEObject)); |
|
|
362 |
|
| 363 |
List<FacetToPaint> facetsToPaint = CustomTreePainter.getFacetsToPaintFor( |
| 364 |
customizedEObject, 0, rectangle.width, 0, rectangle.height, rectangle.width, |
| 365 |
this.customizationEngine, this.natTableWidget.getFacetContext()); |
| 366 |
customization.setFacetsToPaint(facetsToPaint); |
| 367 |
|
| 292 |
} |
368 |
} |
| 293 |
return customization; |
369 |
return customization; |
| 294 |
} |
370 |
} |