1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2025. | |
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 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.manager; | |
12 | ||
13 | import com.jsql.util.LogLevelUtil; | |
14 | import com.jsql.view.swing.list.ItemList; | |
15 | import com.jsql.view.swing.manager.util.StateButton; | |
16 | import com.jsql.view.swing.util.I18nViewUtil; | |
17 | import com.jsql.view.swing.util.MediatorHelper; | |
18 | import org.apache.logging.log4j.LogManager; | |
19 | import org.apache.logging.log4j.Logger; | |
20 | ||
21 | import javax.swing.*; | |
22 | import java.awt.*; | |
23 | import java.awt.event.ActionEvent; | |
24 | import java.awt.event.ActionListener; | |
25 | import java.util.Arrays; | |
26 | import java.util.List; | |
27 | import java.util.stream.Collectors; | |
28 | ||
29 | /** | |
30 | * Manager to read a file from the host. | |
31 | */ | |
32 | public class ManagerFile extends AbstractManagerList { | |
33 | ||
34 | /** | |
35 | * Log4j logger sent to view. | |
36 | */ | |
37 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
38 | ||
39 | /** | |
40 | * Create the manager panel to read a file. | |
41 | */ | |
42 | public ManagerFile() { | |
43 | super("swing/list/file.txt"); | |
44 |
1
1. <init> : removed call to com/jsql/view/swing/manager/ManagerFile::buildRunButton → NO_COVERAGE |
this.buildRunButton("FILE_RUN_BUTTON_LABEL", "FILE_RUN_BUTTON_TOOLTIP"); |
45 |
1
1. <init> : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE |
this.run.setEnabled(false); |
46 |
1
1. <init> : removed call to com/jsql/view/swing/manager/util/JButtonStateful::addActionListener → NO_COVERAGE |
this.run.addActionListener(new ActionFile()); |
47 |
1
1. <init> : removed call to com/jsql/view/swing/manager/ManagerFile::buildPrivilege → NO_COVERAGE |
this.buildPrivilege(); |
48 |
1
1. <init> : removed call to com/jsql/view/swing/manager/ManagerFile::add → NO_COVERAGE |
this.add(this.lastLine, BorderLayout.SOUTH); |
49 | } | |
50 | ||
51 | private class ActionFile implements ActionListener { | |
52 | @Override | |
53 | public void actionPerformed(ActionEvent e) { | |
54 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (ManagerFile.this.listPaths.getSelectedValuesList().isEmpty()) { |
55 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Select in the list at least one file to read"); | |
56 | return; | |
57 | } | |
58 | if (!Arrays.asList( | |
59 | MediatorHelper.model().getMediatorVendor().getSqlite(), | |
60 | MediatorHelper.model().getMediatorVendor().getDerby(), | |
61 | MediatorHelper.model().getMediatorVendor().getH2(), | |
62 | MediatorHelper.model().getMediatorVendor().getHsqldb(), | |
63 | MediatorHelper.model().getMediatorVendor().getMysql(), | |
64 | MediatorHelper.model().getMediatorVendor().getPostgres() | |
65 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
).contains(MediatorHelper.model().getMediatorVendor().getVendor())) { |
66 | LOGGER.log( | |
67 | LogLevelUtil.CONSOLE_ERROR, | |
68 | "Read file for [{}] not implemented, share a working example to GitHub to speed up release", | |
69 | MediatorHelper.model().getMediatorVendor().getVendor() | |
70 | ); | |
71 | return; | |
72 | } | |
73 | new SwingWorker<>() { | |
74 | @Override | |
75 | protected Object doInBackground() { | |
76 |
1
1. doInBackground : removed call to java/lang/Thread::setName → NO_COVERAGE |
Thread.currentThread().setName("SwingWorkerManagerFile"); |
77 |
1
1. doInBackground : negated conditional → NO_COVERAGE |
if (ManagerFile.this.run.getState() == StateButton.STARTABLE) { |
78 |
1
1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE |
ManagerFile.this.run.setText(I18nViewUtil.valueByKey("FILE_RUN_BUTTON_STOP")); |
79 |
1
1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE |
ManagerFile.this.run.setState(StateButton.STOPPABLE); |
80 |
1
1. doInBackground : removed call to java/awt/Component::setVisible → NO_COVERAGE |
ManagerFile.this.horizontalGlue.setVisible(false); |
81 |
1
1. doInBackground : removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE |
ManagerFile.this.progressBar.setVisible(true); |
82 | try { | |
83 | List<String> filePaths = ManagerFile.this.listPaths.getSelectedValuesList().stream().map(ItemList::toString).collect(Collectors.toList()); | |
84 | MediatorHelper.model().getResourceAccess().readFile(filePaths); | |
85 | } catch (InterruptedException e) { | |
86 | LOGGER.log(LogLevelUtil.IGNORE, e, e); | |
87 |
1
1. doInBackground : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
88 | } catch (Exception e) { | |
89 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, e, e); | |
90 | } | |
91 |
1
1. doInBackground : removed call to com/jsql/view/swing/manager/ManagerFile::endProcess → NO_COVERAGE |
ManagerFile.this.endProcess(); |
92 | } else { | |
93 |
1
1. doInBackground : removed call to com/jsql/model/accessible/ResourceAccess::stopSearchFile → NO_COVERAGE |
MediatorHelper.model().getResourceAccess().stopSearchFile(); |
94 |
1
1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE |
ManagerFile.this.run.setEnabled(false); |
95 |
1
1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE |
ManagerFile.this.run.setState(StateButton.STOPPING); |
96 | } | |
97 | return null; | |
98 | } | |
99 | }.doInBackground(); | |
100 | } | |
101 | } | |
102 | } | |
Mutations | ||
44 |
1.1 |
|
45 |
1.1 |
|
46 |
1.1 |
|
47 |
1.1 |
|
48 |
1.1 |
|
54 |
1.1 |
|
65 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
87 |
1.1 |
|
91 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |