Package: PoTableView$1

PoTableView$1

nameinstructionbranchcomplexitylinemethod
run()
M: 66 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.plugins.poviewer
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.poviewer.view;
23:
24: import org.eclipse.jface.resource.FontRegistry;
25: import org.eclipse.jface.resource.JFaceResources;
26: import org.eclipse.jface.text.Document;
27: import org.eclipse.jface.text.TextAttribute;
28: import org.eclipse.jface.text.rules.IToken;
29: import org.eclipse.jface.text.rules.Token;
30: import org.eclipse.jface.viewers.ISelection;
31: import org.eclipse.swt.SWT;
32: import org.eclipse.swt.custom.StyleRange;
33: import org.eclipse.swt.custom.StyledText;
34: import org.eclipse.swt.graphics.Font;
35: import org.eclipse.swt.widgets.Composite;
36: import org.eclipse.swt.widgets.Display;
37: import org.eclipse.ui.ISelectionListener;
38: import org.eclipse.ui.IWorkbenchPart;
39: import org.eclipse.ui.PlatformUI;
40: import org.eclipse.ui.part.ViewPart;
41: import org.eclipse.ui.themes.ITheme;
42: import org.eclipse.ui.themes.IThemeManager;
43: import org.overture.ide.core.resources.IVdmProject;
44: import org.overture.ide.ui.editor.syntax.VdmColorProvider;
45: import org.overture.ide.vdmsl.ui.editor.syntax.VdmSlCodeScanner;
46: import org.overture.pog.pub.IProofObligation;
47:
48: public class PoTableView extends ViewPart implements ISelectionListener
49: {
50:         protected StyledText viewer;
51:         protected final Display display = Display.getCurrent();
52:         protected Font font = null;
53:
54:         VdmSlCodeScanner scanner = new VdmSlCodeScanner(new VdmColorProvider());
55:
56:         /**
57:          * The constructor.
58:          */
59:         public PoTableView()
60:         {
61:                 IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
62:                 ITheme currentTheme = themeManager.getCurrentTheme();
63:
64:                 FontRegistry fontRegistry = currentTheme.getFontRegistry();
65:                 font = fontRegistry.get(JFaceResources.TEXT_FONT);
66:
67:         }
68:
69:         /**
70:          * This is a callback that will allow us to create the viewer and initialize it.
71:          */
72:         @Override
73:         public void createPartControl(Composite parent)
74:         {
75:                 viewer = new StyledText(parent, SWT.WRAP | SWT.V_SCROLL|SWT.READ_ONLY);
76:                 viewer.setFont(font);
77:
78:         }
79:
80:         /**
81:          * Passing the focus request to the viewer's control.
82:          */
83:         @Override
84:         public void setFocus()
85:         {
86:                 viewer.setFocus();
87:         }
88:
89:         public void setDataList(final IVdmProject project,
90:                         final IProofObligation data)
91:         {
92:                 display.asyncExec(new Runnable()
93:                 {
94:
95:                         public void run()
96:                         {
97:                                 viewer.setText(data.getFullPredString());
98:
99:                                 scanner.setRange(new Document(data.getFullPredString()), 0, data.getFullPredString().length());
100:
101:                                 IToken token = null;
102:                                 do
103:                                 {
104:                                         token = scanner.nextToken();
105:                                         TextAttribute attribute = null;
106:                                         int start = scanner.getTokenOffset();
107:                                         int length = scanner.getTokenLength();
108:
109:•                                        if (token.getData() instanceof TextAttribute)
110:                                         {
111:                                                 attribute = (TextAttribute) token.getData();
112:                                                 viewer.setStyleRange(new StyleRange(start, length, attribute.getForeground(), attribute.getBackground()));
113:                                         }
114:
115:•                                } while (token != Token.EOF);
116:
117:                         }
118:
119:                 });
120:         }
121:
122:         public void selectionChanged(IWorkbenchPart part, ISelection selection)
123:         {
124:
125:         }
126: }