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
|
/*******************************************************************************
* Copyright (c) 2010 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.coverage.action;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osee.coverage.internal.Activator;
import org.eclipse.osee.coverage.model.CoverageItem;
import org.eclipse.osee.coverage.model.ICoverage;
import org.eclipse.osee.coverage.util.CoverageUtil;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.skynet.results.ResultsEditor;
import org.eclipse.osee.framework.ui.swt.ImageManager;
/**
* @author Donald G. Dunne
*/
public class ViewSourceAction extends Action {
private final ISelectedCoverageEditorItem selectedCoverageEditorItem;
public ViewSourceAction(ISelectedCoverageEditorItem selectedCoverageEditorItem) {
super("View Source");
this.selectedCoverageEditorItem = selectedCoverageEditorItem;
}
@Override
public ImageDescriptor getImageDescriptor() {
return ImageManager.getImageDescriptor(FrameworkImage.REPORT);
}
@Override
public void run() {
if (selectedCoverageEditorItem.getSelectedCoverageEditorItems().isEmpty()) {
AWorkbench.popup("Select Coverage Item");
return;
}
if (selectedCoverageEditorItem.getSelectedCoverageEditorItems().size() > 0) {
ICoverage item = selectedCoverageEditorItem.getSelectedCoverageEditorItems().iterator().next();
String highlightLine = null;
try {
if (item instanceof CoverageItem) {
if (Strings.isValid(item.getName())) {
highlightLine = item.getName();
}
item = item.getParent();
}
// If order number then parent has full file contents
// attempt to find line in file that matches
if (Strings.isValid(item.getOrderNumber())) {
if (item.getParent() != null) {
String itemLineText = item.getName();
String parentFileContents = item.getParent().getFileContents();
if (!Strings.isValid(parentFileContents)) {
AWorkbench.popup("No File Contents Available");
return;
}
String html = parentFileContents;
// mark text for method
if (Strings.isValid(itemLineText)) {
html = html.replaceAll(itemLineText, "HEREBEGIN" + itemLineText + "HEREEND");
}
// mark text for executable line
if (Strings.isValid(highlightLine)) {
html = html.replaceAll(highlightLine, "HEREBEGIN" + highlightLine + "HEREEND");
}
html = AHTML.textToHtml(html);
html = html.replaceAll(" ", " ");
html = html.replaceAll("HEREBEGIN", "<FONT style=\"BACKGROUND-COLOR: yellow\">");
html = html.replaceAll("HEREEND", "</FONT>");
ResultsEditor.open("source",
CoverageUtil.getFullPathWithName(item.getParent()) + "[" + item.getName() + "]", html);
} else {
AWorkbench.popup("No File Contents Available");
return;
}
}
// If no order number, just open full text
else {
String text = item.getFileContents();
if (!Strings.isValid(text)) {
AWorkbench.popup("No File Contents Available");
return;
}
String html = AHTML.textToHtml(text);
html = html.replaceAll(" ", " ");
ResultsEditor.open("source", CoverageUtil.getFullPathWithName(item), html);
}
} catch (OseeCoreException ex) {
OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
}
}
}
}
|