ActionNewWindow.java

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.action;
12
13
import com.jsql.MainApp;
14
import com.jsql.util.I18nUtil;
15
import com.jsql.util.LogLevelUtil;
16
import org.apache.commons.lang3.SystemUtils;
17
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
19
20
import javax.swing.*;
21
import java.awt.event.ActionEvent;
22
import java.awt.event.InputEvent;
23
import java.awt.event.KeyEvent;
24
import java.io.File;
25
import java.io.IOException;
26
import java.util.ArrayList;
27
import java.util.Arrays;
28
import java.util.List;
29
30
/**
31
 * Open another jSQL instance in new process.
32
 */
33
public class ActionNewWindow extends AbstractAction {
34
    
35
    /**
36
     * Log4j logger sent to view.
37
     */
38
    private static final Logger LOGGER = LogManager.getRootLogger();
39
    
40
    private static final String PATH = SystemUtils.JAVA_HOME + File.separator +"bin"+ File.separator +"java";
41
    private static final List<String> COMMANDS_DEFAULT = Arrays.asList(
42
        "-cp",
43
        SystemUtils.JAVA_CLASS_PATH,
44
        MainApp.class.getName()
45
    );
46
    
47
    private final List<String> commands;
48
    
49
    public ActionNewWindow() {
50
        this(I18nUtil.valueByKey("NEW_WINDOW_MENU"));
51 1 1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE
        this.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_N);
52 1 1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE
        this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK));
53
    }
54
55
    public ActionNewWindow(String name, String... commands) {
56
        this.commands = new ArrayList<>(List.of(ActionNewWindow.PATH));
57
        this.commands.addAll(Arrays.asList(commands));
58
        this.commands.addAll(ActionNewWindow.COMMANDS_DEFAULT);
59 1 1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE
        this.putValue(Action.NAME, name);
60
    }
61
62
    @Override
63
    public void actionPerformed(ActionEvent event) {
64
        LOGGER.log(LogLevelUtil.CONSOLE_INFORM, () -> I18nUtil.valueByKey("NEW_WINDOW_START"));
65
        var processBuilder = new ProcessBuilder(this.commands.toArray(new String[0]));
66
        try {
67
            processBuilder.start();
68
        } catch (IOException e) {
69
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
70
        }
71
    }
72
}

Mutations

51

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE

52

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE

59

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1