Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1ea93fa026cb19c42389681a7f16c7602fed4e7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*****************************************************************************
 * Copyright (c) 2012 CEA LIST.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.customization.properties.generation.providers;


import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.papyrus.customization.properties.generation.wizard.SelectFieldsPage;
import org.eclipse.papyrus.customization.properties.providers.ContextLabelProvider;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.views.properties.contexts.Property;
import org.eclipse.swt.graphics.Image;

public class DataContextPropertiesLabelProvider extends StyledCellLabelProvider {

	private final SelectFieldsPage selectFieldsPage;

	private final ILabelProvider labelProvider;

	public DataContextPropertiesLabelProvider(SelectFieldsPage selectFieldsPage) {
		this.selectFieldsPage = selectFieldsPage;
		labelProvider = new ContextLabelProvider();
	}

	@Override
	public void update(ViewerCell cell) {
		Object element = cell.getElement();
		int columnIndex = cell.getColumnIndex();

		StyledString styleText = getStyledText(element, columnIndex);

		cell.setText(styleText.getString());
		cell.setStyleRanges(styleText.getStyleRanges());
		cell.setImage(getImage(element, columnIndex));
	}

	protected StyledString getStyledText(Object element, int columnIndex) {
		String text = getText(element, columnIndex);

		if (columnIndex == selectFieldsPage.fieldColumn) {
			EObject eObject = EMFHelper.getEObject(element);
			if (!(eObject instanceof Property)) {
				StyledString styledString = new StyledString(text, StyledString.QUALIFIER_STYLER);

				return styledString;
			}
		}

		// if(columnIndex == selectFieldsPage.selectionSingleColumn) {
		// //Nothing
		// }
		//
		// if(columnIndex == selectFieldsPage.selectionMultipleColumn) {
		// //Nothing
		// }
		//
		// if(columnIndex == selectFieldsPage.descriptionColumn) {
		// //Nothing
		// }

		// Default
		return new StyledString(text);
	}

	protected String getText(Object element, int columnIndex) {
		if (columnIndex == selectFieldsPage.fieldColumn) {
			return labelProvider.getText(element);
		}

		// if(columnIndex == selectFieldsPage.selectionSingleColumn) {
		// //Nothing
		// }
		//
		// if(columnIndex == selectFieldsPage.selectionMultipleColumn) {
		// //Nothing
		// }

		if (columnIndex == selectFieldsPage.descriptionColumn) {
			EObject eObject = EMFHelper.getEObject(element);
			if (eObject instanceof Property) {
				String description = ((Property) element).getDescription();
				if (description != null) {
					return description.replaceAll("[\n\r]+", "\\\\");
				}

				return "";
			}
		}

		// Default
		return "";
	}

	protected Image getImage(Object element, int columnIndex) {
		if (columnIndex == selectFieldsPage.fieldColumn) {
			return labelProvider.getImage(element);
		}

		// if(columnIndex == selectFieldsPage.selectionSingleColumn) {
		// //Nothing
		// }
		//
		// if(columnIndex == selectFieldsPage.selectionMultipleColumn) {
		// //Nothing
		// }
		//
		// if(columnIndex == selectFieldsPage.descriptionColumn) {
		// //Nothing
		// }

		// Default
		return null;
	}

}

Back to the top