blob: f4f946e673aea0b5b9a29a71688be6ebc52959cf (
plain) (
blame)
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
|
package org.openslx.dozmod.gui.window;
import org.openslx.dozmod.gui.control.table.ContainerBindMountTable;
import org.openslx.dozmod.gui.helper.TextChangeListener;
import org.openslx.dozmod.gui.window.layout.ContainerBindMountWindowLayout;
import org.openslx.virtualization.configuration.container.ContainerBindMount;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ContainerBindMountWindow extends ContainerBindMountWindowLayout {
/**
* Version for serialization.
*/
private static final long serialVersionUID = -399726779412965808L;
private final ContainerBindMountTable bindMountTable;
public ContainerBindMountWindow(Window modalParent, ContainerBindMountTable bindMountTable) {
super(modalParent);
this.bindMountTable = bindMountTable;
this.btnSave.setEnabled(false);
this.btnSave.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
saveEntry();
}
});
this.btnCancel.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
dispose();
}
});
this.cboSourceMount.addItemListener(new ItemListener() {
@Override public void itemStateChanged(ItemEvent e) {
isInputComplete();
}
});
this.txtBmTarget.getDocument().addDocumentListener(new TextChangeListener() {
@Override public void changed() {
isInputComplete();
}
});
}
private boolean isInputComplete() {
btnSave.setEnabled(false);
if (cboSourceMount == null || Objects.equals(cboSourceMount.getSelectedItem(),
ContainerMountChoice.getEmptyChoice())) {
header.updateStatus("Source Path is Missing");
return false;
}
if (txtBmTarget == null || txtBmTarget.getText().isEmpty()) {
header.updateStatus("Target Path is Missing");
return false;
}
header.updateStatus("Input Completed");
btnSave.setEnabled(true);
return true;
}
private void saveEntry() {
ContainerMountChoice mountChoice = (ContainerMountChoice) this.cboSourceMount.getSelectedItem();
ContainerBindMount.ContainerMountType mountType = mountChoice.type;
String source = mountChoice.value;
String target = this.txtBmTarget.getText();
String option = this.txtBmOptions.getText();
ContainerBindMount bindMount = new ContainerBindMount(mountType, source, target, option);
List<ContainerBindMount> oldData = bindMountTable.getData();
List<ContainerBindMount> data = new ArrayList<>(oldData);
data.add(bindMount);
bindMountTable.setData(data, true);
dispose();
}
public static void open(Window modalParent, ContainerBindMountTable bindMountTable) {
ContainerBindMountWindow win = new ContainerBindMountWindow(modalParent, bindMountTable);
win.setVisible(true);
}
}
|