1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss about it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | *******************************************************************************/ | |
11 | package com.jsql.view.swing.tab; | |
12 | ||
13 | import com.jsql.model.bean.database.AbstractElementDatabase; | |
14 | import com.jsql.util.I18nUtil; | |
15 | import com.jsql.util.LogLevelUtil; | |
16 | import com.jsql.util.StringUtil; | |
17 | import com.jsql.view.swing.action.HotkeyUtil; | |
18 | import com.jsql.view.swing.popupmenu.JPopupMenuText; | |
19 | import com.jsql.view.swing.scrollpane.LightScrollPane; | |
20 | import com.jsql.view.swing.scrollpane.LightScrollPaneShell; | |
21 | import com.jsql.view.swing.shell.ShellSql; | |
22 | import com.jsql.view.swing.shell.ShellWeb; | |
23 | import com.jsql.view.swing.tab.dnd.DnDTabbedPane; | |
24 | import com.jsql.view.swing.tab.dnd.TabTransferHandler; | |
25 | import com.jsql.view.swing.table.PanelTable; | |
26 | import com.jsql.view.swing.text.JPopupTextArea; | |
27 | import com.jsql.view.swing.util.MediatorHelper; | |
28 | import com.jsql.view.swing.util.UiStringUtil; | |
29 | import com.jsql.view.swing.util.UiUtil; | |
30 | import org.apache.commons.lang3.StringUtils; | |
31 | import org.apache.logging.log4j.LogManager; | |
32 | import org.apache.logging.log4j.Logger; | |
33 | ||
34 | import javax.swing.*; | |
35 | import javax.swing.event.HyperlinkEvent; | |
36 | import java.awt.*; | |
37 | import java.io.IOException; | |
38 | import java.net.MalformedURLException; | |
39 | import java.net.URISyntaxException; | |
40 | import java.util.Arrays; | |
41 | import java.util.UUID; | |
42 | ||
43 | /** | |
44 | * TabbedPane containing result injection panels. | |
45 | */ | |
46 | public class TabResults extends DnDTabbedPane { | |
47 | | |
48 | /** | |
49 | * Log4j logger sent to view. | |
50 | */ | |
51 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
52 | | |
53 | /** | |
54 | * Create the panel containing injection results. | |
55 | */ | |
56 | public TabResults() { | |
57 | | |
58 |
1
1. <init> : removed call to com/jsql/view/swing/tab/TabResults::setTabLayoutPolicy → NO_COVERAGE |
this.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); |
59 |
1
1. <init> : removed call to com/jsql/view/swing/tab/TabResults::setTransferHandler → NO_COVERAGE |
this.setTransferHandler(new TabTransferHandler()); |
60 | ||
61 | // Add hotkeys to root-pane ctrl-tab, ctrl-shift-tab, ctrl-w | |
62 |
1
1. <init> : removed call to com/jsql/view/swing/action/HotkeyUtil::addShortcut → NO_COVERAGE |
HotkeyUtil.addShortcut(this); |
63 | } | |
64 | ||
65 | public void createFileTab(String label, String content, String path) { | |
66 | ||
67 | JTextArea fileText = new JPopupTextArea().getProxy(); | |
68 |
1
1. createFileTab : removed call to javax/swing/JTextArea::setText → NO_COVERAGE |
fileText.setText(content); |
69 |
1
1. createFileTab : removed call to javax/swing/JTextArea::setFont → NO_COVERAGE |
fileText.setFont(new Font(UiUtil.FONT_NAME_MONO_NON_ASIAN, Font.PLAIN, 14)); |
70 |
1
1. createFileTab : removed call to javax/swing/JTextArea::setCaretPosition → NO_COVERAGE |
fileText.setCaretPosition(0); |
71 | ||
72 |
1
1. createFileTab : removed call to com/jsql/view/swing/tab/TabResults::createTextTab → NO_COVERAGE |
this.createTextTab(label, path, fileText); |
73 |
1
1. createFileTab : removed call to com/jsql/view/swing/tab/TabManagersProxy::addToLists → NO_COVERAGE |
MediatorHelper.tabManagers().addToLists(path, label); |
74 | } | |
75 | ||
76 | public void createReportTab(String label, String content, String path) { | |
77 | ||
78 | JEditorPane editorPane = new JEditorPane(); | |
79 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::setContentType → NO_COVERAGE |
editorPane.setContentType("text/html"); |
80 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::setText → NO_COVERAGE |
editorPane.setText("<html><span style=\"white-space: nowrap; font-family:'"+ UiUtil.FONT_NAME_MONO_NON_ASIAN +"'\">" + content + "</span></html>"); |
81 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::setDragEnabled → NO_COVERAGE |
editorPane.setDragEnabled(true); |
82 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::setEditable → NO_COVERAGE |
editorPane.setEditable(false); |
83 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::setCaretPosition → NO_COVERAGE |
editorPane.setCaretPosition(0); |
84 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::setCursor → NO_COVERAGE |
editorPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); |
85 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::setComponentPopupMenu → NO_COVERAGE |
editorPane.setComponentPopupMenu(new JPopupMenuText(editorPane)); |
86 |
1
1. createReportTab : removed call to javax/swing/JEditorPane::addHyperlinkListener → NO_COVERAGE |
editorPane.addHyperlinkListener(linkEvent -> { |
87 |
1
1. lambda$createReportTab$0 : negated conditional → NO_COVERAGE |
if (HyperlinkEvent.EventType.ACTIVATED.equals(linkEvent.getEventType())) { |
88 | try { | |
89 |
1
1. lambda$createReportTab$0 : removed call to java/awt/Desktop::browse → NO_COVERAGE |
Desktop.getDesktop().browse(linkEvent.getURL().toURI()); |
90 | } catch (IOException | URISyntaxException | UnsupportedOperationException e) { | |
91 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Browsing to Url failed", e); | |
92 | } | |
93 | } | |
94 | }); | |
95 | ||
96 |
1
1. createReportTab : removed call to com/jsql/view/swing/tab/TabResults::createTextTab → NO_COVERAGE |
this.createTextTab(label, path, editorPane); |
97 | } | |
98 | ||
99 | public void createTextTab(String label, String path, JComponent componentText) { | |
100 | ||
101 | var scroller = new LightScrollPane(1, 0, 0, 0, componentText); | |
102 | ||
103 |
1
1. createTextTab : removed call to com/jsql/view/swing/tab/TabResults::addTab → NO_COVERAGE |
this.addTab(label + StringUtils.SPACE, scroller); |
104 | ||
105 | // Focus on the new tab | |
106 |
1
1. createTextTab : removed call to com/jsql/view/swing/tab/TabResults::setSelectedComponent → NO_COVERAGE |
this.setSelectedComponent(scroller); |
107 | ||
108 | // Create a custom tab header with close button | |
109 | var header = new TabHeader(label, UiUtil.ICON_FILE_SERVER); | |
110 | ||
111 |
1
1. createTextTab : removed call to com/jsql/view/swing/tab/TabResults::setToolTipTextAt → NO_COVERAGE |
this.setToolTipTextAt(this.indexOfComponent(scroller), path); |
112 | ||
113 | // Apply the custom header to the tab | |
114 |
1
1. createTextTab : removed call to com/jsql/view/swing/tab/TabResults::setTabComponentAt → NO_COVERAGE |
this.setTabComponentAt(this.indexOfComponent(scroller), header); |
115 | } | |
116 | | |
117 | public void createShell(String url, String path) { | |
118 | try { | |
119 | var terminalID = UUID.randomUUID(); | |
120 | var terminal = new ShellWeb(terminalID, url); | |
121 | MediatorHelper.frame().getConsoles().put(terminalID, terminal); | |
122 | | |
123 | LightScrollPane scroller = new LightScrollPaneShell(terminal); | |
124 | | |
125 |
1
1. createShell : removed call to com/jsql/view/swing/tab/TabResults::addTab → NO_COVERAGE |
this.addTab("Web shell ", scroller); |
126 | | |
127 | // Focus on the new tab | |
128 |
1
1. createShell : removed call to com/jsql/view/swing/tab/TabResults::setSelectedComponent → NO_COVERAGE |
this.setSelectedComponent(scroller); |
129 | | |
130 | // Create a custom tab header with close button | |
131 | var header = new TabHeader("Web shell", UiUtil.ICON_SHELL_SERVER); | |
132 | | |
133 |
1
1. createShell : removed call to com/jsql/view/swing/tab/TabResults::setToolTipTextAt → NO_COVERAGE |
this.setToolTipTextAt( |
134 | this.indexOfComponent(scroller), | |
135 | String.format( | |
136 | "<html><b>URL</b><br>%s<br><b>Path</b><br>%s%s</html>", | |
137 | url, | |
138 | path, | |
139 | MediatorHelper.model().getResourceAccess().filenameWebshell | |
140 | ) | |
141 | ); | |
142 | | |
143 | // Apply the custom header to the tab | |
144 |
1
1. createShell : removed call to com/jsql/view/swing/tab/TabResults::setTabComponentAt → NO_COVERAGE |
this.setTabComponentAt(this.indexOfComponent(scroller), header); |
145 | | |
146 | terminal.requestFocusInWindow(); | |
147 | | |
148 | } catch (MalformedURLException | URISyntaxException e) { | |
149 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Incorrect shell Url", e); | |
150 | } | |
151 | } | |
152 | | |
153 | public void createSQLShellTab(String url, String user, String pass, String path) { | |
154 | try { | |
155 | var terminalID = UUID.randomUUID(); | |
156 | var terminal = new ShellSql(terminalID, url, user, pass); | |
157 | ||
158 | MediatorHelper.frame().getConsoles().put(terminalID, terminal); | |
159 | | |
160 | LightScrollPane scroller = new LightScrollPaneShell(terminal); | |
161 |
1
1. createSQLShellTab : removed call to com/jsql/view/swing/tab/TabResults::addTab → NO_COVERAGE |
this.addTab("SQL shell ", scroller); |
162 | | |
163 | // Focus on the new tab | |
164 |
1
1. createSQLShellTab : removed call to com/jsql/view/swing/tab/TabResults::setSelectedComponent → NO_COVERAGE |
this.setSelectedComponent(scroller); |
165 | | |
166 | // Create a custom tab header with close button | |
167 | var header = new TabHeader("SQL shell", UiUtil.ICON_SHELL_SERVER); | |
168 | | |
169 |
1
1. createSQLShellTab : removed call to com/jsql/view/swing/tab/TabResults::setToolTipTextAt → NO_COVERAGE |
this.setToolTipTextAt( |
170 | this.indexOfComponent(scroller), | |
171 | String.format( | |
172 | "<html><b>URL</b><br>%s<br><b>Path</b><br>%s%s</html>", | |
173 | url, | |
174 | path, | |
175 | MediatorHelper.model().getResourceAccess().filenameSqlshell | |
176 | ) | |
177 | ); | |
178 | | |
179 | // Apply the custom header to the tab | |
180 |
1
1. createSQLShellTab : removed call to com/jsql/view/swing/tab/TabResults::setTabComponentAt → NO_COVERAGE |
this.setTabComponentAt(this.indexOfComponent(scroller), header); |
181 | | |
182 | terminal.requestFocusInWindow(); | |
183 | | |
184 | } catch (MalformedURLException | URISyntaxException e) { | |
185 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Incorrect shell Url", e); | |
186 | } | |
187 | } | |
188 | | |
189 | public void createValuesTab(String[][] data, String[] columnNames, AbstractElementDatabase table) { | |
190 | | |
191 | // Create a new table to display the values | |
192 | var newTableJPanel = new PanelTable(data, columnNames); | |
193 | | |
194 | // Create a new tab: add header and table | |
195 |
1
1. createValuesTab : removed call to com/jsql/view/swing/tab/TabResults::addTab → NO_COVERAGE |
this.addTab(StringUtil.detectUtf8(table.toString()), newTableJPanel); |
196 |
1
1. createValuesTab : removed call to com/jsql/view/swing/table/PanelTable::setComponentOrientation → NO_COVERAGE |
newTableJPanel.setComponentOrientation(ComponentOrientation.getOrientation(I18nUtil.getLocaleDefault())); |
197 | | |
198 | // Focus on the new tab | |
199 |
1
1. createValuesTab : removed call to com/jsql/view/swing/tab/TabResults::setSelectedComponent → NO_COVERAGE |
this.setSelectedComponent(newTableJPanel); |
200 | | |
201 | // Create a custom tab header with close button | |
202 | var header = new TabHeader(UiStringUtil.detectUtf8Html(table.toString())); | |
203 | | |
204 |
1
1. createValuesTab : removed call to com/jsql/view/swing/tab/TabResults::setToolTipTextAt → NO_COVERAGE |
this.setToolTipTextAt( |
205 | this.indexOfComponent(newTableJPanel), | |
206 | String.format( | |
207 | "<html><b>%s.%s</b><br><i>%s</i></html>", | |
208 | table.getParent(), | |
209 | table, | |
210 | String.join("<br>", Arrays.copyOfRange(columnNames, 2, columnNames.length)) | |
211 | ) | |
212 | ); | |
213 | | |
214 | // Apply the custom header to the tab | |
215 |
1
1. createValuesTab : removed call to com/jsql/view/swing/tab/TabResults::setTabComponentAt → NO_COVERAGE |
this.setTabComponentAt( |
216 | this.indexOfComponent(newTableJPanel), | |
217 | header | |
218 | ); | |
219 | } | |
220 | } | |
Mutations | ||
58 |
1.1 |
|
59 |
1.1 |
|
62 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 |
|
96 |
1.1 |
|
103 |
1.1 |
|
106 |
1.1 |
|
111 |
1.1 |
|
114 |
1.1 |
|
125 |
1.1 |
|
128 |
1.1 |
|
133 |
1.1 |
|
144 |
1.1 |
|
161 |
1.1 |
|
164 |
1.1 |
|
169 |
1.1 |
|
180 |
1.1 |
|
195 |
1.1 |
|
196 |
1.1 |
|
199 |
1.1 |
|
204 |
1.1 |
|
215 |
1.1 |