-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.java
684 lines (599 loc) · 26.6 KB
/
Main.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
package dk.magenta.bitmagasinet.gui;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import org.bitrepository.common.utils.Base16Utils;
import dk.magenta.bitmagasinet.checksum.ChecksumIOHandler;
import dk.magenta.bitmagasinet.checksum.FileChecksum;
import dk.magenta.bitmagasinet.checksum.InvalidChecksumFileException;
import dk.magenta.bitmagasinet.comparators.ChecksumComparator;
import dk.magenta.bitmagasinet.comparators.ChecksumMatchComparator;
import dk.magenta.bitmagasinet.comparators.ChecksumType;
import dk.magenta.bitmagasinet.comparators.FilenameComparator;
import dk.magenta.bitmagasinet.configuration.ConfigurationHandler;
import dk.magenta.bitmagasinet.configuration.ConfigurationHandlerImpl;
import dk.magenta.bitmagasinet.configuration.ConfigurationIOHandler;
import dk.magenta.bitmagasinet.configuration.ConfigurationIOHandlerImpl;
import dk.magenta.bitmagasinet.configuration.InvalidArgumentException;
import dk.magenta.bitmagasinet.configuration.RepositoryConfiguration;
import dk.magenta.bitmagasinet.configuration.RepositoryConfigurationImpl;
import dk.magenta.bitmagasinet.process.ProcessHandler;
import dk.magenta.bitmagasinet.process.ProcessHandlerImpl;
import dk.magenta.bitmagasinet.process.ProcessHandlerObserver;
import dk.magenta.bitmagasinet.remote.BitrepositoryConnectionResult;
import dk.magenta.bitmagasinet.remote.BitrepositoryConnector;
import dk.magenta.bitmagasinet.remote.BitrepositoryConnectorImpl;
import dk.magenta.bitmagasinet.remote.ThreadStatusObserver;
public class Main extends JFrame implements ThreadStatusObserver, ProcessHandlerObserver {
private static final long serialVersionUID = 1719991083148859676L;
private JPanel contentPane;
private JButton btnGetConfiguration;
private JLabel lblCurrentConfiguration;
private JPanel currentConfigurationPane;
private JTable checksumTable;
private JList<String> bitRepoList;
private JTextField txtPathToSettingsFolder;
private JTextField txtPathToCertificate;
private JTextField txtCollectionId;
private JTextField txtPillarId;
private JTextField txtPathToLocalChecksumList;
private ConfigurationHandler configurationHandler;
private ConfigurationIOHandler configurationIOHandler;
private ChecksumIOHandler checksumIOHandler;
private BitrepositoryConnector bitrepositoryConnector;
private ProcessHandlerImpl processHandler;
private String repoName;
private List<FileChecksum> fileChecksums;
private Map<String, Comparator<FileChecksum>> comparatorMap;
private DefaultListModel<String> bitRepoListModel;
private DefaultTableModel checksumTableModel;
private JProgressBar progressBar;
private JLabel lblProgressBar;
private JButton btnGetChecksums;
private JButton btnSort;
private JComboBox<String> sortDropDown;
private DocumentListener documentListener;
private JTextField txtPathToResultFile;
private JLabel lblPathToResultFile;
private JButton btnPathToResultFile;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Throwable e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the main frame.
*/
public Main() {
configurationHandler = new ConfigurationHandlerImpl();
configurationIOHandler = new ConfigurationIOHandlerImpl(configurationHandler);
checksumIOHandler = new ChecksumIOHandler();
documentListener = getDocumentListener();
bitRepoListModel = new DefaultListModel<String>();
fileChecksums = new ArrayList<FileChecksum>();
comparatorMap = new TreeMap<String, Comparator<FileChecksum>>();
comparatorMap.put(Constants.FILENAME, new FilenameComparator());
comparatorMap.put(Constants.MATCH, new ChecksumMatchComparator());
comparatorMap.put(Constants.LOCAL_CHECKSUM, new ChecksumComparator(ChecksumType.LOCAL));
comparatorMap.put(Constants.REMOTE_CHECKSUM, new ChecksumComparator(ChecksumType.REMOTE));
initChecksumTableModel();
initComponents();
}
/**
* Callback from ProcessHandlerObserver
*/
@Override
public void update(ProcessHandler processHandler) {
sortDropDown.setEnabled(true);
btnSort.setEnabled(true);
setResultFileInputVisibility(true);
}
/**
* Callback from ThreadStatusObserver
*/
@Override
public void update(BitrepositoryConnectionResult bitrepositoryConnectionResult) {
updateChecksumResultList();
progressBar.setValue(processHandler.getProgressHandler().getProgress());
}
@Override
public void messageBusErrorCallback() {
JOptionPane.showMessageDialog(contentPane, "Der opstod et problem under lukning af forbindelsen til bitmagasinet");
}
private void initComponents() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (bitrepositoryConnector != null) {
bitrepositoryConnector.closeMessageBus();
}
super.windowClosing(e);
}
});
setBounds(100, 100, 1012, 642);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
// Load repository configurations
loadRepositoryConfigurations();
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE))
);
JPanel pnlBitrepositories = new JPanel();
pnlBitrepositories.setName("");
tabbedPane.addTab("Bitmagasiner", null, pnlBitrepositories, null);
JLabel lblChooseRepo = new JLabel("Vælg Bitmagasin");
lblChooseRepo.setFont(new Font("Dialog", Font.BOLD, 12));
JScrollPane bitRepoScrollPane = new JScrollPane();
btnGetConfiguration = new JButton("Hent konfiguration");
if (bitRepoListModel.isEmpty()) {
btnGetConfiguration.setEnabled(false);
}
btnGetConfiguration.addActionListener(actionEvent -> {
repoName = (String) bitRepoList.getSelectedValue();
lblCurrentConfiguration.setText("Konfiguration for " + repoName);
setConfigurationPaneVisibility(true);
RepositoryConfiguration repositoryConfiguration;
try {
repositoryConfiguration = configurationHandler.getRepositoryConfiguration(repoName);
txtPathToSettingsFolder.setText(repositoryConfiguration.getPathToSettingsFiles().toString());
txtPathToCertificate.setText(repositoryConfiguration.getPathToCertificate().toString());
txtCollectionId.setText(repositoryConfiguration.getCollectionId());
txtPillarId.setText(repositoryConfiguration.getPillarId());
txtPathToLocalChecksumList.setText(repositoryConfiguration.getPathToChecksumList().toString());
btnGetChecksums.setEnabled(true);
} catch (InvalidArgumentException e) {
// This should never happen
e.printStackTrace();
}
});
currentConfigurationPane = new JPanel();
currentConfigurationPane.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
currentConfigurationPane.setVisible(false);
lblCurrentConfiguration = new JLabel("Konfiguration");
lblCurrentConfiguration.setFont(new Font("Dialog", Font.BOLD, 12));
lblCurrentConfiguration.setVisible(false);
JButton btnAddNewRepo = new JButton("Tilføj ny");
btnAddNewRepo.addActionListener(actionEvent -> {
repoName = JOptionPane.showInputDialog("Indtast navn på konfiguration").trim();
if (configurationHandler.getRepositoryConfigurations().containsKey(repoName)) {
JOptionPane.showMessageDialog(contentPane, "Der findes allerede en konfiguration med det navn");
return;
}
lblCurrentConfiguration.setText("Konfiguration for " + repoName);
clearRepositoryConfigurationFields();
lblCurrentConfiguration.setVisible(true);
currentConfigurationPane.setVisible(true);
});
GroupLayout gl_pnlBitrepositories = new GroupLayout(pnlBitrepositories);
gl_pnlBitrepositories.setHorizontalGroup(
gl_pnlBitrepositories.createParallelGroup(Alignment.LEADING)
.addGroup(gl_pnlBitrepositories.createSequentialGroup()
.addContainerGap()
.addGroup(gl_pnlBitrepositories.createParallelGroup(Alignment.LEADING)
.addGroup(gl_pnlBitrepositories.createSequentialGroup()
.addComponent(btnAddNewRepo)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnGetConfiguration))
.addComponent(bitRepoScrollPane, GroupLayout.PREFERRED_SIZE, 263, GroupLayout.PREFERRED_SIZE)
.addComponent(lblChooseRepo))
.addGap(18)
.addGroup(gl_pnlBitrepositories.createParallelGroup(Alignment.LEADING)
.addComponent(currentConfigurationPane, GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE)
.addComponent(lblCurrentConfiguration))
.addContainerGap())
);
gl_pnlBitrepositories.setVerticalGroup(
gl_pnlBitrepositories.createParallelGroup(Alignment.LEADING)
.addGroup(gl_pnlBitrepositories.createSequentialGroup()
.addContainerGap()
.addGroup(gl_pnlBitrepositories.createParallelGroup(Alignment.BASELINE)
.addComponent(lblChooseRepo)
.addComponent(lblCurrentConfiguration))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_pnlBitrepositories.createParallelGroup(Alignment.LEADING)
.addGroup(gl_pnlBitrepositories.createSequentialGroup()
.addComponent(bitRepoScrollPane, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_pnlBitrepositories.createParallelGroup(Alignment.BASELINE)
.addComponent(btnAddNewRepo)
.addComponent(btnGetConfiguration)))
.addComponent(currentConfigurationPane, GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE))
.addContainerGap())
);
JLabel lblPathToRepositorysettingXml = new JLabel("Sti til mappe indeholdende RepositorySetting.xml og ReferenceSettings.xml");
txtPathToSettingsFolder = new JTextField();
txtPathToSettingsFolder.setColumns(10);
txtPathToSettingsFolder.getDocument().addDocumentListener(documentListener);
JLabel lblpathToCertificate = new JLabel("Sti og filnavn til certifikat");
txtPathToCertificate = new JTextField();
txtPathToCertificate.setColumns(10);
txtPathToCertificate.getDocument().addDocumentListener(documentListener);
JLabel lblCollectionId = new JLabel("Samling (CollectionID)");
txtCollectionId = new JTextField();
txtCollectionId.setColumns(10);
txtCollectionId.getDocument().addDocumentListener(documentListener);
JLabel lblPillarId = new JLabel("Søjle (PillarID)");
txtPillarId = new JTextField();
txtPillarId.setColumns(10);
txtPillarId.getDocument().addDocumentListener(documentListener);
JLabel lblPathToLocalChecksumList = new JLabel("Sti til lokal kontrolsumsliste");
txtPathToLocalChecksumList = new JTextField();
txtPathToLocalChecksumList.setColumns(10);
txtPathToLocalChecksumList.getDocument().addDocumentListener(documentListener);
JButton btnSaveRepoConf = new JButton("Gem");
btnSaveRepoConf.addActionListener(actionEvent -> {
try {
RepositoryConfiguration repositoryConfiguration = new RepositoryConfigurationImpl(repoName);
repositoryConfiguration.setPathToSettingsFiles(Paths.get(txtPathToSettingsFolder.getText()));
repositoryConfiguration.setPathToCertificate(Paths.get(txtPathToCertificate.getText()));
repositoryConfiguration.setCollectionId(txtCollectionId.getText());
repositoryConfiguration.setPillarId(txtPillarId.getText());
repositoryConfiguration.setPathToChecksumList(Paths.get(txtPathToLocalChecksumList.getText()));
configurationHandler.addRepositoryConfiguration(repositoryConfiguration);
updateBitRepoListModel();
bitRepoList.setSelectedValue(repoName, true);
configurationIOHandler.writeRepositoryConfiguration(repositoryConfiguration);
btnGetConfiguration.setEnabled(true);
btnGetChecksums.setEnabled(true);
JOptionPane.showMessageDialog(contentPane, "Konfiguration gemt");
} catch (InvalidArgumentException | IOException e) {
JOptionPane.showMessageDialog(
contentPane, e.getMessage());
}
});
JButton btnClearFields = new JButton("Ryd felter");
btnClearFields.addActionListener(actionEvent -> {
clearRepositoryConfigurationFields();
});
GroupLayout gl_currentConfigurationPane = new GroupLayout(currentConfigurationPane);
gl_currentConfigurationPane.setHorizontalGroup(
gl_currentConfigurationPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_currentConfigurationPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_currentConfigurationPane.createParallelGroup(Alignment.LEADING)
.addComponent(txtPathToSettingsFolder, GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
.addComponent(lblPathToRepositorysettingXml)
.addComponent(lblpathToCertificate)
.addComponent(txtPathToCertificate, GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
.addComponent(lblCollectionId)
.addComponent(txtCollectionId, GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
.addComponent(lblPillarId)
.addComponent(txtPillarId, GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
.addComponent(lblPathToLocalChecksumList)
.addComponent(txtPathToLocalChecksumList, GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
.addGroup(Alignment.TRAILING, gl_currentConfigurationPane.createSequentialGroup()
.addComponent(btnClearFields)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnSaveRepoConf)))
.addContainerGap())
);
gl_currentConfigurationPane.setVerticalGroup(
gl_currentConfigurationPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_currentConfigurationPane.createSequentialGroup()
.addContainerGap()
.addComponent(lblPathToRepositorysettingXml)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(txtPathToSettingsFolder, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(lblpathToCertificate)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(txtPathToCertificate, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(lblCollectionId)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(txtCollectionId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(lblPillarId)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(txtPillarId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(lblPathToLocalChecksumList)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(txtPathToLocalChecksumList, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addGroup(gl_currentConfigurationPane.createParallelGroup(Alignment.BASELINE)
.addComponent(btnSaveRepoConf)
.addComponent(btnClearFields))
.addContainerGap(138, Short.MAX_VALUE))
);
currentConfigurationPane.setLayout(gl_currentConfigurationPane);
bitRepoList = new JList<String>();
bitRepoList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
bitRepoList.setModel(bitRepoListModel);
bitRepoList.setSelectedIndex(0);
bitRepoScrollPane.setViewportView(bitRepoList);
pnlBitrepositories.setLayout(gl_pnlBitrepositories);
JPanel pnlChecksums = new JPanel();
tabbedPane.addTab("Kontrolsummer", null, pnlChecksums, null);
btnGetChecksums = new JButton("Hent kontrolsummer");
btnGetChecksums.addActionListener(actionEvent -> {
// Disable/hide buttons
progressBar.setValue(0);
sortDropDown.setEnabled(false);
btnSort.setEnabled(false);
setResultFileInputVisibility(false);
// Clear table
checksumTableModel.setRowCount(0);
// Get checksum list from local file
File checksumFile = new File(txtPathToLocalChecksumList.getText().trim());
try {
fileChecksums = checksumIOHandler.readChecksumList(checksumFile);
} catch (IOException e) {
JOptionPane.showMessageDialog(contentPane, "Der opstod en fejl under læsning af filen " + txtPathToLocalChecksumList.getText());
e.printStackTrace();
} catch (InvalidChecksumFileException e) {
JOptionPane.showMessageDialog(contentPane, e.getMessage());
e.printStackTrace();
}
// bitrepositoryConnector = new BitrepositoryConnectorRandomResultStub(fileChecksums.get(0), ThreadStatus.SUCCESS);
try {
bitrepositoryConnector = new BitrepositoryConnectorImpl(configurationHandler.getRepositoryConfiguration(repoName),
fileChecksums.get(0));
} catch (InvalidArgumentException e) {
e.printStackTrace();
}
processHandler = new ProcessHandlerImpl(fileChecksums, bitrepositoryConnector, true);
bitrepositoryConnector.addObserver(processHandler);
bitrepositoryConnector.addObserver(Main.this);
processHandler.addObserver(Main.this);
processHandler.processNext();
lblProgressBar.setVisible(true);
progressBar.setVisible(true);
});
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBackground(Color.WHITE);
sortDropDown = new JComboBox<String>();
sortDropDown.setModel(new DefaultComboBoxModel<String>(new String[] {Constants.FILENAME, Constants.MATCH,
Constants.LOCAL_CHECKSUM, Constants.REMOTE_CHECKSUM}));
JLabel lblSortAfter = new JLabel("Sortér efter:");
btnSort = new JButton("Sortér");
btnSort.addActionListener(actionEvent -> {
String sortAfter = (String) sortDropDown.getSelectedItem();
Collections.sort(processHandler.getProcessedFileChecksums(),comparatorMap.get(sortAfter));
updateChecksumResultList();
});
disableGetChecksums();
progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setStringPainted(true);
progressBar.setToolTipText("");
lblProgressBar = new JLabel("Status for nedhentning");
lblProgressBar.setVisible(false);
lblProgressBar.setFont(new Font("Tahoma", Font.BOLD, 13));
lblPathToResultFile = new JLabel("Angiv sti til mappe, hvor resultatfilen skal gemmes:");
lblPathToResultFile.setVisible(false);
txtPathToResultFile = new JTextField();
txtPathToResultFile.setVisible(false);
txtPathToResultFile.setColumns(10);
btnPathToResultFile = new JButton("Gem");
btnPathToResultFile.addActionListener(actionEvent -> {
Path path = Paths.get(txtPathToResultFile.getText().trim());
File file = path.toFile();
if (!file.isDirectory()) {
JOptionPane.showMessageDialog(contentPane, file.getAbsolutePath() + " henviser ikke til en mappe");
return;
}
if (!file.canWrite()) {
JOptionPane.showMessageDialog(contentPane, "Kan ikke skrive til " + file.getAbsolutePath());
return;
}
try {
checksumIOHandler.writeResultFiles(path, processHandler.getProcessedFileChecksums(),
configurationHandler.getRepositoryConfiguration(repoName),
processHandler.getStartDate(), processHandler.getEndDate());
JOptionPane.showMessageDialog(contentPane, "Filen er blevet gemt");
} catch (IOException e) {
JOptionPane.showConfirmDialog(contentPane, "Der opstod en fejl: " + e.getMessage());
e.printStackTrace();
} catch (InvalidArgumentException e) {
JOptionPane.showConfirmDialog(contentPane, "Der opstod en fejl: " + e.getMessage());
e.printStackTrace();
}
});
btnPathToResultFile.setVisible(false);
GroupLayout gl_pnlChecksums = new GroupLayout(pnlChecksums);
gl_pnlChecksums.setHorizontalGroup(
gl_pnlChecksums.createParallelGroup(Alignment.LEADING)
.addGroup(gl_pnlChecksums.createSequentialGroup()
.addGroup(gl_pnlChecksums.createParallelGroup(Alignment.LEADING)
.addGroup(gl_pnlChecksums.createSequentialGroup()
.addContainerGap()
.addGroup(gl_pnlChecksums.createParallelGroup(Alignment.LEADING)
.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 955, Short.MAX_VALUE)
.addGroup(gl_pnlChecksums.createSequentialGroup()
.addComponent(lblSortAfter)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(sortDropDown, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnSort)
.addPreferredGap(ComponentPlacement.RELATED, 501, Short.MAX_VALUE)
.addComponent(btnGetChecksums))
.addGroup(gl_pnlChecksums.createSequentialGroup()
.addComponent(lblPathToResultFile)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(txtPathToResultFile, GroupLayout.PREFERRED_SIZE, 299, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnPathToResultFile))))
.addGroup(gl_pnlChecksums.createSequentialGroup()
.addGap(381)
.addGroup(gl_pnlChecksums.createParallelGroup(Alignment.LEADING)
.addComponent(lblProgressBar)
.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
gl_pnlChecksums.setVerticalGroup(
gl_pnlChecksums.createParallelGroup(Alignment.LEADING)
.addGroup(gl_pnlChecksums.createSequentialGroup()
.addGap(27)
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 197, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_pnlChecksums.createParallelGroup(Alignment.BASELINE)
.addComponent(btnGetChecksums)
.addComponent(lblSortAfter)
.addComponent(sortDropDown, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(btnSort))
.addGap(59)
.addComponent(lblProgressBar)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
.addGap(65)
.addGroup(gl_pnlChecksums.createParallelGroup(Alignment.BASELINE)
.addComponent(lblPathToResultFile)
.addComponent(txtPathToResultFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(btnPathToResultFile))
.addContainerGap(90, Short.MAX_VALUE))
);
checksumTable = new JTable();
checksumTable.setShowGrid(false);
checksumTable.setBackground(Color.WHITE);
checksumTable.setFillsViewportHeight(true);
checksumTable.setModel(checksumTableModel);
checksumTable.getColumnModel().getColumn(1).setMaxWidth(100);
checksumTable.getColumnModel().getColumn(3).setMaxWidth(100);
scrollPane.setViewportView(checksumTable);
pnlChecksums.setLayout(gl_pnlChecksums);
contentPane.setLayout(gl_contentPane);
}
private void setConfigurationPaneVisibility(boolean b) {
lblCurrentConfiguration.setVisible(b);
currentConfigurationPane.setVisible(b);
}
private void initChecksumTableModel() {
checksumTableModel = new DefaultTableModel(new Object[][] {},
new String[] {Constants.FILENAME, Constants.MATCH, Constants.LOCAL_CHECKSUM, "Salt", Constants.REMOTE_CHECKSUM});
}
private String convertBooleanToString(boolean b) {
if (b) {
return Constants.CHECKSUM_MATCH_TRUE;
} else {
return Constants.CHECKSUM_MATCH_FALSE;
}
}
private void updateChecksumResultList() {
checksumTableModel.setRowCount(0);
for (int i = 0; i < processHandler.getProcessedFileChecksums().size(); i++) {
FileChecksum fileChecksum = processHandler.getProcessedFileChecksums().get(i);
String[] row = new String[] {fileChecksum.getFilename(),
convertBooleanToString(fileChecksum.checksumsMatch()),
fileChecksum.getLocalChecksum(),
Base16Utils.decodeBase16(fileChecksum.getSalt()),
fileChecksum.getRemoteChecksum()};
checksumTableModel.addRow(row);
}
}
private DocumentListener getDocumentListener() {
return new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
btnGetChecksums.setEnabled(false);
}
@Override
public void insertUpdate(DocumentEvent e) {
btnGetChecksums.setEnabled(false);
}
@Override
public void changedUpdate(DocumentEvent e) {
btnGetChecksums.setEnabled(false);
}
};
}
private void disableGetChecksums() {
btnGetChecksums.setEnabled(false);
sortDropDown.setEnabled(false);
btnSort.setEnabled(false);
}
private void setResultFileInputVisibility(boolean b) {
lblPathToResultFile.setVisible(b);
txtPathToResultFile.setVisible(b);
btnPathToResultFile.setVisible(b);
}
private void loadRepositoryConfigurations() {
try {
configurationHandler.getRepositoryConfigurationsFromFolder();
if (!configurationHandler.getRepositoryConfigurations().isEmpty()) {
updateBitRepoListModel();
}
} catch (IOException e) {
JOptionPane.showMessageDialog(contentPane, e.getMessage());
e.printStackTrace();
} catch (InvalidArgumentException e) {
JOptionPane.showMessageDialog(contentPane, e.getMessage());
e.printStackTrace();
}
}
private void updateBitRepoListModel() {
bitRepoListModel.clear();
for (String name : configurationHandler.getRepositoryConfigurations().keySet()) {
bitRepoListModel.addElement(name);
}
}
private void clearRepositoryConfigurationFields() {
txtPathToSettingsFolder.setText(null);
txtPathToCertificate.setText(null);
txtCollectionId.setText(null);
txtPillarId.setText(null);
txtPathToLocalChecksumList.setText(null);
}
}