blob: fa3cf9208d321233e6f9a8809eca8a5b5fc511f1 (
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
|
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;
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.cboSourceMountPoint.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 (cboSourceMountPoint == null || cboSourceMountPoint.getSelectedIndex() == 0) {
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() {
ContainerBindMount bindMount = new ContainerBindMount();
bindMount.setSource(
ContainerBindMountWindowLayout.SOURCE_MOUNT_POINTS[cboSourceMountPoint.getSelectedIndex()]);
bindMount.setTarget(this.txtBmTarget.getText());
bindMount.setOptions(this.txtBmOptions.getText());
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);
}
}
|