Method: ViewLabelProvider()

1: /*
2: * #%~
3: * Combinatorial Testing
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.combinatorialtesting.views;
23:
24: import org.eclipse.jface.viewers.LabelProvider;
25: import org.eclipse.swt.graphics.Image;
26: import org.eclipse.ui.PlatformUI;
27: import org.eclipse.ui.ide.IDE;
28: import org.overture.ast.definitions.SClassDefinition;
29: import org.overture.ast.modules.AModuleModules;
30: import org.overture.ide.plugins.combinatorialtesting.OvertureTracesPlugin;
31: import org.overture.ide.plugins.combinatorialtesting.views.treeView.NotYetReadyTreeNode;
32: import org.overture.ide.plugins.combinatorialtesting.views.treeView.ProjectTreeNode;
33: import org.overture.ide.plugins.combinatorialtesting.views.treeView.TraceTestTreeNode;
34: import org.overture.ide.plugins.combinatorialtesting.views.treeView.TraceTreeNode;
35: import org.overture.interpreter.traces.Verdict;
36:
37: public class ViewLabelProvider extends LabelProvider
38: {
39:
40:         @Override
41:         public String getText(Object obj)
42:         {
43:                 if (obj instanceof SClassDefinition)
44:                 {
45:                         return ((SClassDefinition) obj).getName().getName();
46:                 } else if (obj instanceof AModuleModules)
47:                 {
48:                         return ((AModuleModules) obj).getName().getName();
49:                 }
50:                 return obj.toString();
51:         }
52:
53:         @Override
54:         public Image getImage(Object obj)
55:         {
56:                 if (obj instanceof ProjectTreeNode)
57:                 {
58:                         String imageKey = IDE.SharedImages.IMG_OBJ_PROJECT;
59:                         return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
60:                 }
61:                 if (/* obj instanceof ClassTreeNode || */obj instanceof SClassDefinition
62:                                 || obj instanceof AModuleModules)
63:                 {
64:                         return OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_TRACE_CLASS).createImage();
65:                 }
66:                 if (obj instanceof TraceTreeNode)
67:                 {
68:                         return OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_TRACE).createImage();
69:                 }
70:                 if (obj instanceof NotYetReadyTreeNode)
71:                 {
72:                         return OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_TRACE_TEST_CASE_UNKNOWN).createImage();
73:                 }
74:                 if (obj instanceof TraceTestTreeNode)
75:                 {
76:                         String imgPath = OvertureTracesPlugin.IMG_TRACE_TEST_CASE_UNKNOWN;
77:                         Verdict status = ((TraceTestTreeNode) obj).getStatus();
78:                         if (status == Verdict.PASSED)
79:                         {
80:                                 imgPath = OvertureTracesPlugin.IMG_TRACE_TEST_CASE_SUCCES;
81:                         } else if (status == null)
82:                         {
83:                                 imgPath = OvertureTracesPlugin.IMG_TRACE_TEST_CASE_UNKNOWN;
84:                         } else if (status == Verdict.INCONCLUSIVE)
85:                         {
86:                                 imgPath = OvertureTracesPlugin.IMG_TRACE_TEST_CASE_UNDETERMINED;
87:                         } else if (status == Verdict.FAILED)
88:                         {
89:                                 imgPath = OvertureTracesPlugin.IMG_TRACE_TEST_CASE_FAIL;
90:                         } else if (status == Verdict.SKIPPED)
91:                         {
92:                                 imgPath = OvertureTracesPlugin.IMG_TRACE_TEST_CASE_SKIPPED;
93:                         }
94:
95:                         if (((TraceTestTreeNode) obj).hasRunTimeError())
96:                         {
97:                                 imgPath = OvertureTracesPlugin.IMG_ERROR;
98:                         }
99:
100:                         return OvertureTracesPlugin.getImageDescriptor(imgPath).createImage();
101:                 }
102:                 String imageKey = IDE.SharedImages.IMG_OBJ_PROJECT;
103:                 return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
104:         }
105: }