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.action; | |
12 | ||
13 | import com.jsql.MainApplication; | |
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 | | |
42 | private static final List<String> COMMANDS_DEFAULT = Arrays.asList( | |
43 | "-cp", | |
44 | SystemUtils.JAVA_CLASS_PATH, | |
45 | MainApplication.class.getName() | |
46 | ); | |
47 | | |
48 | private final List<String> commands; | |
49 | | |
50 | public ActionNewWindow() { | |
51 | | |
52 | this(I18nUtil.valueByKey("NEW_WINDOW_MENU")); | |
53 | | |
54 |
1
1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE |
this.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_N); |
55 |
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)); |
56 | } | |
57 | ||
58 | public ActionNewWindow(String name, String... commands) { | |
59 | | |
60 | this.commands = new ArrayList<>(List.of(PATH)); | |
61 | this.commands.addAll(Arrays.asList(commands)); | |
62 | this.commands.addAll(COMMANDS_DEFAULT); | |
63 | | |
64 |
1
1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE |
this.putValue(Action.NAME, name); |
65 | } | |
66 | ||
67 | @Override | |
68 | public void actionPerformed(ActionEvent event) { | |
69 | | |
70 | LOGGER.log(LogLevelUtil.CONSOLE_INFORM, () -> I18nUtil.valueByKey("NEW_WINDOW_START")); | |
71 | | |
72 | var processBuilder = new ProcessBuilder(this.commands.toArray(new String[0])); | |
73 | | |
74 | try { | |
75 | processBuilder.start(); | |
76 | } catch (IOException e) { | |
77 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
78 | } | |
79 | } | |
80 | } | |
Mutations | ||
54 |
1.1 |
|
55 |
1.1 |
|
64 |
1.1 |