Skip to content

Commit 5040433

Browse files
authored
Merge pull request #2406 from ControlSystemStudio/CSSTUDIO-1762
Bug fix Olog preview
2 parents 3c570e2 + ad1fb49 commit 5040433

File tree

1 file changed

+78
-79
lines changed

1 file changed

+78
-79
lines changed

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java

Lines changed: 78 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 European Spallation Source ERIC.
2+
* Copyright (C) 2022 European Spallation Source ERIC.
33
*
44
* This program is free software; you can redistribute it and/or
55
* modify it under the terms of the GNU General Public License
@@ -29,15 +29,32 @@
2929
import javafx.collections.ObservableList;
3030
import javafx.fxml.FXML;
3131
import javafx.geometry.Side;
32-
import javafx.scene.control.*;
32+
import javafx.scene.control.Button;
33+
import javafx.scene.control.CheckBox;
34+
import javafx.scene.control.ComboBox;
35+
import javafx.scene.control.ContextMenu;
36+
import javafx.scene.control.CustomMenuItem;
37+
import javafx.scene.control.Label;
38+
import javafx.scene.control.MenuItem;
39+
import javafx.scene.control.PasswordField;
40+
import javafx.scene.control.ProgressIndicator;
41+
import javafx.scene.control.TextArea;
42+
import javafx.scene.control.TextField;
43+
import javafx.scene.control.ToggleButton;
3344
import javafx.scene.image.Image;
3445
import javafx.scene.image.ImageView;
3546
import javafx.scene.layout.VBox;
3647
import javafx.scene.paint.Color;
3748
import org.phoebus.framework.jobs.JobManager;
3849
import org.phoebus.framework.selection.SelectionService;
39-
import org.phoebus.logbook.*;
40-
import org.phoebus.logbook.olog.ui.AttachmentsViewController;
50+
import org.phoebus.logbook.LogClient;
51+
import org.phoebus.logbook.LogEntry;
52+
import org.phoebus.logbook.LogFactory;
53+
import org.phoebus.logbook.LogService;
54+
import org.phoebus.logbook.Logbook;
55+
import org.phoebus.logbook.LogbookException;
56+
import org.phoebus.logbook.LogbookPreferences;
57+
import org.phoebus.logbook.Tag;
4158
import org.phoebus.logbook.olog.ui.HelpViewer;
4259
import org.phoebus.logbook.olog.ui.LogbookUIPreferences;
4360
import org.phoebus.logbook.olog.ui.PreviewViewer;
@@ -51,7 +68,11 @@
5168
import org.phoebus.util.time.TimestampFormats;
5269

5370
import java.time.Instant;
54-
import java.util.*;
71+
import java.util.ArrayList;
72+
import java.util.Arrays;
73+
import java.util.Collection;
74+
import java.util.Collections;
75+
import java.util.List;
5576
import java.util.function.Consumer;
5677
import java.util.logging.Level;
5778
import java.util.logging.Logger;
@@ -62,7 +83,6 @@
6283
*/
6384
public class LogEntryEditorController {
6485

65-
//private Node parent;
6686
private final LogEntryCompletionHandler completionHandler;
6787

6888
private final Logger logger = Logger.getLogger(LogEntryEditorController.class.getName());
@@ -85,10 +105,6 @@ public class LogEntryEditorController {
85105
@FXML
86106
private LogPropertiesEditorController logPropertiesEditorController;
87107

88-
@SuppressWarnings("unused")
89-
@FXML
90-
private AttachmentsViewController attachmentsViewController;
91-
92108
@FXML
93109
private Label userFieldLabel;
94110
@FXML
@@ -176,7 +192,7 @@ public LogEntryEditorController(LogEntry logEntry, LogEntry inReplyTo, LogEntryC
176192
updateCredentialsProperty = updateCredentials;
177193

178194
// This is the reply case:
179-
if(inReplyTo != null){
195+
if (inReplyTo != null) {
180196
OlogLog ologLog = new OlogLog();
181197
ologLog.setTitle(inReplyTo.getTitle());
182198
ologLog.setTags(inReplyTo.getTags());
@@ -185,18 +201,16 @@ public LogEntryEditorController(LogEntry logEntry, LogEntry inReplyTo, LogEntryC
185201
ologLog.setLevel(inReplyTo.getLevel());
186202
this.logEntry = ologLog;
187203
this.originalTitle = inReplyTo.getTitle();
188-
}
189-
else{
204+
} else {
190205
this.logEntry = logEntry;
191206
}
192207
}
193-
194-
208+
195209
@FXML
196210
public void initialize() {
197211
completionMessageLabel.setText("");
198212
submitButton.disableProperty().bind(Bindings.createBooleanBinding(() ->
199-
!inputValid.get() || submissionInProgress.get(),
213+
!inputValid.get() || submissionInProgress.get(),
200214
inputValid, submissionInProgress));
201215
completionMessageLabel.visibleProperty()
202216
.bind(Bindings.createBooleanBinding(() -> completionMessageLabel.textProperty().isNotEmpty().get() && !submissionInProgress.get(),
@@ -232,16 +246,13 @@ public void initialize() {
232246
passwordField.setText(passwordProperty.get());
233247

234248
// Put focus on first required field that is empty.
235-
if (userField.getText().isEmpty()){
249+
if (userField.getText().isEmpty()) {
236250
userField.requestFocus();
237-
}
238-
else if (passwordField.getText().isEmpty()){
251+
} else if (passwordField.getText().isEmpty()) {
239252
passwordField.requestFocus();
240-
}
241-
else if(titleField.getText() == null || titleField.getText().isEmpty()){
253+
} else if (titleField.getText() == null || titleField.getText().isEmpty()) {
242254
titleField.requestFocus();
243-
}
244-
else{
255+
} else {
245256
textArea.requestFocus();
246257
}
247258
});
@@ -265,13 +276,12 @@ else if(titleField.getText() == null || titleField.getText().isEmpty()){
265276
titleField.textProperty().bindBidirectional(titleProperty);
266277
titleProperty.addListener((changeListener, oldVal, newVal) ->
267278
{
268-
if (newVal.trim().isEmpty()){
279+
if (newVal.trim().isEmpty()) {
269280
titleLabel.setTextFill(Color.RED);
270-
}
271-
else{
281+
} else {
272282
titleLabel.setTextFill(Color.BLACK);
273283
}
274-
if(!newVal.equals(originalTitle)){
284+
if (!newVal.equals(originalTitle)) {
275285
isDirty = true;
276286
}
277287
});
@@ -299,7 +309,7 @@ else if(titleField.getText() == null || titleField.getText().isEmpty()){
299309
});
300310

301311
logbooksSelection.textProperty().bind(Bindings.createStringBinding(() -> {
302-
if(selectedLogbooks.isEmpty()){
312+
if (selectedLogbooks.isEmpty()) {
303313
return "";
304314
}
305315
StringBuilder stringBuilder = new StringBuilder();
@@ -309,7 +319,7 @@ else if(titleField.getText() == null || titleField.getText().isEmpty()){
309319
}, selectedLogbooks));
310320

311321
tagsSelection.textProperty().bind(Bindings.createStringBinding(() -> {
312-
if(selectedTags.isEmpty()){
322+
if (selectedTags.isEmpty()) {
313323
return "";
314324
}
315325
StringBuilder stringBuilder = new StringBuilder();
@@ -331,15 +341,15 @@ else if(titleField.getText() == null || titleField.getText().isEmpty()){
331341
});
332342

333343
inputValid.bind(Bindings.createBooleanBinding(() -> titleProperty.get() != null && !titleProperty.get().isEmpty() &&
334-
usernameProperty.get() != null && !usernameProperty.get().isEmpty() &&
335-
passwordProperty.get() != null && !passwordProperty.get().isEmpty() &&
336-
!selectedLogbooks.isEmpty(),
344+
usernameProperty.get() != null && !usernameProperty.get().isEmpty() &&
345+
passwordProperty.get() != null && !passwordProperty.get().isEmpty() &&
346+
!selectedLogbooks.isEmpty(),
337347
titleProperty, usernameProperty, passwordProperty, selectedLogbooks));
338348

339349
tagsPopOver = ListSelectionPopOver.create(
340350
(tags, popOver) -> {
341351
setSelectedTags(tags, selectedTags);
342-
if(popOver.isShowing()) {
352+
if (popOver.isShowing()) {
343353
popOver.hide();
344354
}
345355
},
@@ -348,7 +358,7 @@ else if(titleField.getText() == null || titleField.getText().isEmpty()){
348358
logbooksPopOver = ListSelectionPopOver.create(
349359
(logbooks, popOver) -> {
350360
setSelectedLogbooks(logbooks, selectedLogbooks);
351-
if(popOver.isShowing()) {
361+
if (popOver.isShowing()) {
352362
popOver.hide();
353363
}
354364
},
@@ -393,7 +403,7 @@ public void showHelp() {
393403
*/
394404
@FXML
395405
public void showHtmlPreview() {
396-
new PreviewViewer(getDescription(), attachmentsViewController.getAttachments()).show();
406+
new PreviewViewer(getDescription(), attachmentsEditorController.getAttachments()).show();
397407
}
398408

399409

@@ -416,10 +426,9 @@ public void submit() {
416426
logFactory.getLogClient(new SimpleAuthenticationToken(usernameProperty.get(), passwordProperty.get()));
417427
LogEntry result;
418428
try {
419-
if(replyTo == null){
429+
if (replyTo == null) {
420430
result = logClient.set(ologLog);
421-
}
422-
else {
431+
} else {
423432
result = logClient.reply(ologLog, replyTo);
424433
}
425434
// Not dirty any more...
@@ -465,25 +474,25 @@ public void setLevel() {
465474
selectedLevelProperty.set(levelSelector.getSelectionModel().getSelectedItem());
466475
}
467476

468-
public String getTitle(){
477+
public String getTitle() {
469478
return titleProperty.get();
470479
}
471480

472-
public String getDescription(){
481+
public String getDescription() {
473482
return descriptionProperty.get();
474483
}
475484

476485
@FXML
477-
public void addLogbooks(){
486+
public void addLogbooks() {
478487
logbooksPopOver.show(addLogbooks);
479488
}
480489

481-
private void addSelectedLogbook(String logbookName){
490+
private void addSelectedLogbook(String logbookName) {
482491
selectedLogbooks.add(logbookName);
483492
updateDropDown(logbookDropDown, logbookName, true);
484493
}
485494

486-
private void removeSelectedLogbook(String logbookName){
495+
private void removeSelectedLogbook(String logbookName) {
487496
selectedLogbooks.remove(logbookName);
488497
updateDropDown(logbookDropDown, logbookName, false);
489498
}
@@ -504,26 +513,25 @@ private void setSelected(List<String> proposed, List<String> existing, Consumer<
504513
}
505514

506515
@FXML
507-
public void selectLogbooks(){
508-
if (logbooksDropdownButton.isSelected()){
516+
public void selectLogbooks() {
517+
if (logbooksDropdownButton.isSelected()) {
509518
logbookDropDown.show(logbooksSelection, Side.BOTTOM, 0, 0);
510-
}
511-
else{
519+
} else {
512520
logbookDropDown.hide();
513521
}
514522
}
515523

516524
@FXML
517-
public void addTags(){
525+
public void addTags() {
518526
tagsPopOver.show(addTags);
519527
}
520528

521-
private void addSelectedTag(String tagName){
529+
private void addSelectedTag(String tagName) {
522530
selectedTags.add(tagName);
523531
updateDropDown(tagDropDown, tagName, true);
524532
}
525533

526-
private void removeSelectedTag(String tagName){
534+
private void removeSelectedTag(String tagName) {
527535
selectedTags.remove(tagName);
528536
updateDropDown(tagDropDown, tagName, false);
529537
}
@@ -533,28 +541,27 @@ private void setSelectedTags(List<String> proposedTags, List<String> existingTag
533541
}
534542

535543
@FXML
536-
public void selectTags(){
537-
if (tagsDropdownButton.isSelected()){
544+
public void selectTags() {
545+
if (tagsDropdownButton.isSelected()) {
538546
tagDropDown.show(tagsSelection, Side.BOTTOM, 0, 0);
539-
}
540-
else{
547+
} else {
541548
tagDropDown.hide();
542549
}
543550
}
544551

545-
public List<Logbook> getSelectedLogbooks(){
552+
public List<Logbook> getSelectedLogbooks() {
546553
return availableLogbooks.stream().filter(l -> selectedLogbooks.contains(l.getName())).collect(Collectors.toList());
547554
}
548555

549-
public List<Tag> getSelectedTags(){
556+
public List<Tag> getSelectedTags() {
550557
return availableTags.stream().filter(t -> selectedTags.contains(t.getName())).collect(Collectors.toList());
551558
}
552559

553560
/**
554561
* Retrieves logbooks and tags from service and populates all the data structures that depend
555562
* on the result. The call to the remote service is asynchronous.
556563
*/
557-
private void setupLogbooksAndTags(){
564+
private void setupLogbooksAndTags() {
558565
JobManager.schedule("Fetch Logbooks and Tags", monitor ->
559566
{
560567
LogClient logClient =
@@ -574,20 +581,16 @@ private void setupLogbooksAndTags(){
574581
checkBox.setOnAction(e -> {
575582
CheckBox source = (CheckBox) e.getSource();
576583
String text = source.getText();
577-
if (source.isSelected())
578-
{
584+
if (source.isSelected()) {
579585
selectedLogbooks.add(text);
580-
}
581-
else
582-
{
586+
} else {
583587
selectedLogbooks.remove(text);
584588
}
585589
});
586-
if(!preSelectedLogbooks.isEmpty() && preSelectedLogbooks.contains(logbook)){
590+
if (!preSelectedLogbooks.isEmpty() && preSelectedLogbooks.contains(logbook)) {
587591
checkBox.setSelected(preSelectedLogbooks.contains(logbook));
588592
selectedLogbooks.add(logbook);
589-
}
590-
else if(defaultLogbooks.contains(logbook) && selectedLogbooks.isEmpty()){
593+
} else if (defaultLogbooks.contains(logbook) && selectedLogbooks.isEmpty()) {
591594
checkBox.setSelected(defaultLogbooks.contains(logbook));
592595
selectedLogbooks.add(logbook);
593596
}
@@ -608,17 +611,14 @@ else if(defaultLogbooks.contains(logbook) && selectedLogbooks.isEmpty()){
608611
checkBox.setOnAction(e -> {
609612
CheckBox source = (CheckBox) e.getSource();
610613
String text = source.getText();
611-
if (source.isSelected())
612-
{
614+
if (source.isSelected()) {
613615
selectedTags.add(text);
614-
}
615-
else
616-
{
616+
} else {
617617
selectedTags.remove(text);
618618
}
619619
});
620620
checkBox.setSelected(preSelectedTags.contains(tag));
621-
if(preSelectedTags.contains(tag)){
621+
if (preSelectedTags.contains(tag)) {
622622
selectedTags.add(tag);
623623
}
624624
tagDropDown.getItems().add(newTag);
@@ -649,7 +649,6 @@ public void fetchStoredUserCredentials() {
649649
}
650650
// Let anyone listening know that their credentials are now out of date.
651651
updateCredentials.set(true);
652-
//checkIfReadyToSubmit();
653652
} catch (Exception ex) {
654653
logger.log(Level.WARNING, "Secure Store file not found.", ex);
655654
}
@@ -658,23 +657,23 @@ public void fetchStoredUserCredentials() {
658657

659658
/**
660659
* Updates the logbooks or tags context menu to reflect the state of selected logbooks and tags.
661-
* @param contextMenu The context menu to update
662-
* @param itemName The logbook or tag name identifying to a context menu item
660+
*
661+
* @param contextMenu The context menu to update
662+
* @param itemName The logbook or tag name identifying to a context menu item
663663
* @param itemSelected Indicates whether to select or deselect.
664664
*/
665-
private void updateDropDown(ContextMenu contextMenu, String itemName, boolean itemSelected){
666-
for (MenuItem menuItem : contextMenu.getItems())
667-
{
665+
private void updateDropDown(ContextMenu contextMenu, String itemName, boolean itemSelected) {
666+
for (MenuItem menuItem : contextMenu.getItems()) {
668667
CustomMenuItem custom = (CustomMenuItem) menuItem;
669668
CheckBox check = (CheckBox) custom.getContent();
670-
if(check.getText().equals(itemName)){
669+
if (check.getText().equals(itemName)) {
671670
check.setSelected(itemSelected);
672671
break;
673672
}
674673
}
675674
}
676675

677-
public boolean isDirty(){
676+
public boolean isDirty() {
678677
return isDirty;
679678
}
680679
}

0 commit comments

Comments
 (0)