/
JobPanel.java
159 lines (140 loc) · 6.35 KB
/
JobPanel.java
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright 2017 Patrik Karlsson.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package se.trixon.jota.client.ui.editor;
import java.awt.Component;
import se.trixon.jota.client.ui.editor.module.JobPersistor;
import se.trixon.jota.client.ui.editor.module.Module;
import se.trixon.jota.client.ui.editor.module.job.JobAppearancePanel;
import se.trixon.jota.client.ui.editor.module.job.JobCronPanel;
import se.trixon.jota.client.ui.editor.module.job.JobExecutePanel;
import se.trixon.jota.client.ui.editor.module.job.JobHistoryPanel;
import se.trixon.jota.client.ui.editor.module.job.JobLogPanel;
import se.trixon.jota.client.ui.editor.module.job.JobNotePanel;
import se.trixon.jota.shared.job.Job;
import se.trixon.almond.util.Dict;
/**
*
* @author Patrik Karlsson
*/
public class JobPanel extends javax.swing.JPanel {
private final JobAppearancePanel mAppearancePanel = new JobAppearancePanel();
private final JobCronPanel mCronPanel = new JobCronPanel();
private final JobExecutePanel mExecutePanel = new JobExecutePanel();
private final JobLogPanel mLogPanel = new JobLogPanel();
private final JobNotePanel mNotePanel = new JobNotePanel();
private final JobHistoryPanel mHistoryPanel = new JobHistoryPanel();
private Job mJob = new Job();
/**
* Creates new form JobPanel
*/
public JobPanel() {
initComponents();
init();
}
public Job getJob() {
saveJob();
return mJob;
}
public void setJob(Job job) {
mJob = job;
loadJob();
nameTextField.requestFocus();
}
private Component addModulePanel(Module modulePanel) {
return tabbedPane.add(modulePanel.getTitle(), modulePanel);
}
private void init() {
addModulePanel(mCronPanel);
addModulePanel(mExecutePanel);
addModulePanel(mLogPanel);
addModulePanel(mAppearancePanel);
addModulePanel(mNotePanel);
addModulePanel(mHistoryPanel);
}
private void loadJob() {
nameTextField.setText(mJob.getName());
descriptionTextField.setText(mJob.getDescription());
for (Component component : tabbedPane.getComponents()) {
if (component instanceof JobPersistor) {
JobPersistor persistor = (JobPersistor) component;
persistor.loadJob(mJob);
}
}
}
private void saveJob() {
mJob.setName(nameTextField.getText());
mJob.setDescription(descriptionTextField.getText());
for (Component component : tabbedPane.getComponents()) {
if (component instanceof JobPersistor) {
JobPersistor persistor = (JobPersistor) component;
persistor.saveJob(mJob);
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
nameLabel = new javax.swing.JLabel();
nameTextField = new javax.swing.JTextField();
descriptionLabel = new javax.swing.JLabel();
descriptionTextField = new javax.swing.JTextField();
tabbedPane = new javax.swing.JTabbedPane();
nameLabel.setText(Dict.NAME.getString());
descriptionLabel.setText(Dict.DESCRIPTION.getString());
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tabbedPane, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(nameTextField)
.addComponent(descriptionTextField)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(nameLabel)
.addComponent(descriptionLabel))
.addGap(0, 495, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(nameLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(descriptionLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(descriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel descriptionLabel;
private javax.swing.JTextField descriptionTextField;
private javax.swing.JLabel nameLabel;
private javax.swing.JTextField nameTextField;
private javax.swing.JTabbedPane tabbedPane;
// End of variables declaration//GEN-END:variables
}