blob: ce13f281b9d89c6bd1db3917bb5def98b9f41557 (
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
|
/*****************************************************************************
* Copyright (c) 2013 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:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.provider;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.papyrus.infra.nattable.messages.Messages;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.StringResolutionProblem;
import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
/**
* Label Provider for problem
*
* @author VL222926
*
*/
public class ProblemLabelProvider extends EMFLabelProvider implements IFilteredLabelProvider {
/**
*
* @see org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider#accept(java.lang.Object)
*
* @param element
* @return
*/
@Override
public boolean accept(Object element) {
return element instanceof Problem;
}
/**
*
* @see org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider#getText(org.eclipse.emf.ecore.EObject)
*
* @param element
* @return
*/
@Override
protected String getText(final EObject element) {
final Problem pb = (Problem)element;
if(pb instanceof StringResolutionProblem) {
return ((StringResolutionProblem)pb).getValueAsString();
}
return pb.getDescription();
}
/**
*
* @param element
* a problem
* @return
* the text to display for a problem in a tooltip
*/
//TODO : should be obtained using a service or a specific wrapper to get tooltip
public String getTooltipText(final EObject element) {
if(element instanceof Problem) {
final Problem problem = (Problem)element;
final StringBuilder builder = new StringBuilder();
if(problem instanceof StringResolutionProblem) {
final List<String> unresolvedStrings = ((StringResolutionProblem)problem).getUnresolvedString();
builder.append(NLS.bind(Messages.ProblemLabelProvider_StringsValuesCanBeResolved,unresolvedStrings.size()));
if(unresolvedStrings.size() == 1) {
builder.append(" "); //$NON-NLS-1$
builder.append(unresolvedStrings.get(0));
} else {
final Iterator<String> iterOnString = ((StringResolutionProblem)problem).getUnresolvedString().iterator();
while(iterOnString.hasNext()) {
builder.append("\n\t- "); //$NON-NLS-1$
builder.append(iterOnString.next());
}
}
} else {
builder.append(((Problem)problem).getDescription());
}
return builder.toString();
}
return null;
}
}
|