Package: VdmDebugLogLabelProvider

VdmDebugLogLabelProvider

nameinstructionbranchcomplexitylinemethod
VdmDebugLogLabelProvider()
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
formatMessage(VdmDebugLogItem)
M: 38 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getBackground(Object)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getColumnImage(Object, int)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getColumnText(Object, int)
M: 33 C: 0
0%
M: 9 C: 0
0%
M: 7 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getForeground(Object)
M: 45 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
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.debug.ui.log;
23:
24: import java.text.SimpleDateFormat;
25: import java.util.Date;
26:
27: import org.eclipse.jface.viewers.IColorProvider;
28: import org.eclipse.jface.viewers.ITableLabelProvider;
29: import org.eclipse.jface.viewers.LabelProvider;
30: import org.eclipse.swt.graphics.Color;
31: import org.eclipse.swt.graphics.Image;
32: import org.eclipse.swt.graphics.RGB;
33: import org.overture.ide.debug.core.VdmDebugPlugin;
34:
35: public class VdmDebugLogLabelProvider extends LabelProvider implements
36:                 ITableLabelProvider, IColorProvider
37: {
38:
39:         // private final IColorManager colorManager = new DLTKColorManager(false);
40:
41:         //        private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
42:
43:         private final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss.SSS"); //$NON-NLS-1$
44:
45:         @Override
46:         public void dispose()
47:         {
48:                 super.dispose();
49:                 // colorManager.dispose();
50:         }
51:
52:         public Image getColumnImage(Object element, int columnIndex)
53:         {
54:                 return null;
55:         }
56:
57:         public String getColumnText(Object element, int columnIndex)
58:         {
59:•                if (element instanceof VdmDebugLogItem)
60:                 {
61:                         final VdmDebugLogItem item = (VdmDebugLogItem) element;
62:•                        switch (columnIndex)
63:                         {
64:                         // case 0:
65:                         // return dateFormat.format(new Date(item.getTimestamp()));
66:                                 case 1 - 1:
67:                                         return timeFormat.format(new Date(item.getTimestamp()));
68:                                 case 2 - 1:
69:                                         return item.getType();
70:                                 case 3 - 1:
71:•                                        if (item.getSessionId() > 0)
72:                                         {
73:                                                 return String.valueOf(item.getSessionId());
74:                                         } else
75:                                         {
76:                                                 break;
77:                                         }
78:                                 case 4 - 1:
79:                                         return formatMessage(item);
80:                         }
81:                 }
82:                 return null;
83:         }
84:
85:         private static final String XML_DECL_BEGIN = "<?xml"; //$NON-NLS-1$
86:         private static final String XML_DECL_END = "?>"; //$NON-NLS-1$
87:
88:         private String formatMessage(VdmDebugLogItem item)
89:         {
90:                 String result = item.getMessage();
91:•                if (result.startsWith(XML_DECL_BEGIN))
92:                 {
93:                         int end = result.indexOf(XML_DECL_END);
94:•                        if (end >= 0)
95:                         {
96:                                 end += XML_DECL_END.length();
97:•                                while (end < result.length()
98:•                                                && Character.isWhitespace(result.charAt(end)))
99:                                 {
100:                                         ++end;
101:                                 }
102:                                 result = result.substring(end);
103:                         }
104:                 }
105:                 return result.replaceAll("[\\p{Cntrl}]+", ""); //$NON-NLS-1$ //$NON-NLS-2$
106:         }
107:
108:         public Color getBackground(Object element)
109:         {
110:                 return null;
111:         }
112:
113:         private final RGB textColor = new RGB(85, 85, 85);
114:         private final RGB inputColor = new RGB(0, 0, 255);
115:         private final RGB outputColor = new RGB(0, 128, 0);
116:
117:         public Color getForeground(Object element)
118:         {
119:                 final VdmDebugPlugin colors = VdmDebugPlugin.getDefault();
120:•                if (element instanceof VdmDebugLogItem)
121:                 {
122:                         final VdmDebugLogItem item = (VdmDebugLogItem) element;
123:•                        if (item == null || item.getType() == null)
124:                         {
125:                                 return colors.getColor(textColor);
126:•                        } else if (item.getType().equals(Messages.ItemType_Input))
127:                         {
128:                                 return colors.getColor(inputColor);
129:•                        } else if (item.getType().equals(Messages.ItemType_Output))
130:                         {
131:                                 return colors.getColor(outputColor);
132:                         } else
133:                         {
134:                                 return colors.getColor(textColor);
135:                         }
136:                 }
137:                 return null;
138:         }
139: }