diff --git a/src/main/java/io/mattw/youtube/commentsuite/db/CommentQuery.java b/src/main/java/io/mattw/youtube/commentsuite/db/CommentQuery.java index 2c02a15..d0dcf53 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/db/CommentQuery.java +++ b/src/main/java/io/mattw/youtube/commentsuite/db/CommentQuery.java @@ -4,7 +4,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.util.Strings; import java.io.Serializable; import java.sql.ResultSet; diff --git a/src/main/java/io/mattw/youtube/commentsuite/db/ModeratedCommentsTable.java b/src/main/java/io/mattw/youtube/commentsuite/db/ModeratedCommentsTable.java index e92948f..93a0c19 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/db/ModeratedCommentsTable.java +++ b/src/main/java/io/mattw/youtube/commentsuite/db/ModeratedCommentsTable.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.List; -import static io.mattw.youtube.commentsuite.db.SQLLoader.INSERT_IGNORE_COMMENTS; import static io.mattw.youtube.commentsuite.db.SQLLoader.INSERT_IGNORE_MODERATED_COMMENTS; public class ModeratedCommentsTable extends TableHelper { diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGCreateGroupModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGCreateGroupModal.java index 9278dd6..66d1933 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGCreateGroupModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGCreateGroupModal.java @@ -1,5 +1,8 @@ package io.mattw.youtube.commentsuite.fxml; +import io.mattw.youtube.commentsuite.CommentSuite; +import io.mattw.youtube.commentsuite.db.CommentDatabase; +import io.mattw.youtube.commentsuite.db.Group; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; @@ -10,6 +13,11 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; +import java.sql.SQLException; + +import static javafx.application.Platform.runLater; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.trimToEmpty; /** * This modal allows the user to create a new and empty Group with the name of their choosing. The name must be unique. @@ -24,19 +32,61 @@ public class MGCreateGroupModal extends VBox implements Cleanable { @FXML private TextField nameField; @FXML private Button btnSubmit, btnClose; + private CommentDatabase database; + public MGCreateGroupModal() { + logger.debug("Initialize MGCreateGroupModal"); + + database = CommentSuite.getDatabase(); + FXMLLoader loader = new FXMLLoader(getClass().getResource("MGCreateGroupModal.fxml")); loader.setController(this); loader.setRoot(this); try { loader.load(); + + errorMsg.managedProperty().bind(errorMsg.visibleProperty()); + + nameField.textProperty().addListener((ov, prevText, currText) -> + runLater(() -> btnSubmit.setDisable(isBlank(nameField.getText())))); + + btnSubmit.setOnAction(ae -> tryCreate()); } catch (IOException e) { logger.error(e); } } - public Label getErrorMsg() { - return errorMsg; + private void tryCreate() { + final String input = trimToEmpty(nameField.getText()); + + runLater(() -> nameField.setText(input)); + + if (isBlank(input)) { + runLater(() -> { + errorMsg.setVisible(true); + errorMsg.setText("Name cannot be blank"); + }); + return; + } + + try { + final Group newGroup = database.groups().create(input); + + logger.debug("Created new group [id={},name={}]", newGroup.getGroupId(), newGroup.getName()); + + runLater(() -> { + errorMsg.setText(""); + errorMsg.setVisible(false); + btnClose.fire(); + }); + } catch (SQLException e) { + logger.error(e); + + runLater(() -> { + errorMsg.setVisible(true); + errorMsg.setText("Name already exists, try another!"); + }); + } } public TextField getNameField() { @@ -45,8 +95,9 @@ public TextField getNameField() { @Override public void cleanUp() { - getErrorMsg().setManaged(false); - getNameField().setText(""); + errorMsg.setVisible(false); + nameField.setText(""); + btnSubmit.setDisable(true); } public Button getBtnClose() { diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVAddItemModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVAddItemModal.java index 2ef07f0..8b055b5 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVAddItemModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVAddItemModal.java @@ -94,9 +94,7 @@ public MGMVAddItemModal(final Group group) { try { database.groupItems().insertAll(this.group, list); database.commit(); - runLater(() -> { - btnClose.fire(); - }); + runLater(() -> btnClose.fire()); } catch (SQLException e1) { runLater(() -> setError(e1.getClass().getSimpleName())); } @@ -139,9 +137,7 @@ public MGMVAddItemModal(final Group group) { try { database.groupItems().insertAll(this.group, list); database.commit(); - runLater(() -> { - btnClose.fire(); - }); + runLater(() -> btnClose.fire()); } catch (SQLException e1) { failures++; } diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveAllModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveAllModal.java index edf36a7..e923990 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveAllModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveAllModal.java @@ -67,9 +67,7 @@ public MGMVRemoveAllModal(final Group group, final ObservableList { - btnClose.fire(); - }); + runLater(() -> btnClose.fire()); } catch (SQLException e) { runLater(() -> setError(e.getLocalizedMessage())); logger.error(e); diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveSelectedModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveSelectedModal.java index 6363b05..819b2b2 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveSelectedModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/MGMVRemoveSelectedModal.java @@ -67,9 +67,7 @@ public MGMVRemoveSelectedModal(final Group group, final MultipleSelectionModel { - btnClose.fire(); - }); + runLater(() -> btnClose.fire()); } catch (SQLException e) { runLater(() -> setError(e.getLocalizedMessage())); logger.error(e); diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/Main.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/Main.java index 0ac895d..2257f5e 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/Main.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/Main.java @@ -61,9 +61,7 @@ public void initialize(URL location, ResourceBundle resources) { }); quotaIcon.setImage(ImageLoader.QUOTA.getImage()); - btnQuota.setOnAction(ae -> runLater(() -> { - logger.debug("Open Quota info"); - })); + btnQuota.setOnAction(ae -> runLater(() -> logger.debug("Open Quota info"))); settingsIcon.setImage(ImageLoader.SETTINGS.getImage()); btnSettings.setOnAction(ae -> runLater(() -> { diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroups.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroups.java index 8656bda..c74be8e 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroups.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroups.java @@ -24,14 +24,12 @@ import java.io.IOException; import java.net.URL; -import java.sql.SQLException; import java.util.ResourceBundle; import static javafx.application.Platform.runLater; /** * Manages group selection, creation, and content switching. - * */ public class ManageGroups implements Initializable { @@ -42,12 +40,17 @@ public class ManageGroups implements Initializable { private CommentDatabase database; - @FXML private OverlayModal overlayModal; + @FXML + private OverlayModal overlayModal; - @FXML private ImageView plusIcon; - @FXML private ComboBox comboGroupSelect; - @FXML private Button btnCreateGroup; - @FXML private Pane content; + @FXML + private ImageView plusIcon; + @FXML + private ComboBox comboGroupSelect; + @FXML + private Button btnCreateGroup; + @FXML + private Pane content; public void initialize(URL location, ResourceBundle resources) { logger.debug("Initialize ManageGroups"); @@ -108,36 +111,6 @@ public void initialize(URL location, ResourceBundle resources) { modal.getBtnClose().setOnAction(ae -> runLater(() -> overlayModal.setVisible(false)) ); - modal.getBtnSubmit().setOnAction(ae -> new Thread(() -> { - logger.debug("Attempting to create group"); - runLater(() -> overlayModal.setDisable(true)); - String name = modal.getNameField().getText(); - if (!name.isEmpty()) { - try { - Group g = database.groups().create(name); - logger.debug("Created new group [id={},name={}]", g.getGroupId(), g.getName()); - runLater(() -> { - comboGroupSelect.getSelectionModel().select(g); - overlayModal.setDisable(false); - overlayModal.setVisible(false); - modal.getErrorMsg().setManaged(false); - }); - } catch (SQLException e) { - logger.error(e); - runLater(() -> { - overlayModal.setDisable(false); - modal.getErrorMsg().setManaged(true); - modal.getErrorMsg().setText("Name already exists, try another!"); - }); - } - } else { - runLater(() -> { - overlayModal.setDisable(false); - modal.getErrorMsg().setManaged(true); - modal.getErrorMsg().setText("Name must not be empty."); - }); - } - }).start()); } public static Cache getManagerCache() { diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroupsManager.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroupsManager.java index 06a15b0..14347ec 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroupsManager.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/ManageGroupsManager.java @@ -25,7 +25,6 @@ import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.layout.GridPane; -import javafx.scene.layout.Priority; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import javafx.scene.text.Font; @@ -166,12 +165,7 @@ public ManageGroupsManager(final Group group) throws IOException { groupTitle.setMinWidth(Region.USE_PREF_SIZE); groupTitle.setMaxWidth(Region.USE_PREF_SIZE); groupTitle.textProperty().addListener((ov, prevText, currText) -> { - runLater(() -> { - int caretPosition = groupTitle.getCaretPosition(); - groupTitle.setText(trimToEmpty(currText)); - groupTitle.positionCaret(caretPosition); - rename.setDisable(isBlank(groupTitle.getText())); - }); + runLater(() -> rename.setDisable(isBlank(groupTitle.getText()))); FXUtils.adjustTextFieldWidthByContent(groupTitle); }); @@ -195,9 +189,11 @@ public ManageGroupsManager(final Group group) throws IOException { rename.setOnAction(ae -> new Thread(() -> { if (editIcon.getImage().equals(save)) { try { - database.groups().rename(group, groupTitle.getText()); + final String newTitle = trimToEmpty(groupTitle.getText()); + database.groups().rename(group, newTitle); + runLater(() -> groupTitle.setText(newTitle)); } catch (SQLException e) { - groupTitle.setText(group.getName()); + runLater(() -> groupTitle.setText(group.getName())); logger.error(e); } } @@ -224,22 +220,20 @@ public ManageGroupsManager(final Group group) throws IOException { }); }).start()); - renameCancel.setOnAction(ae -> new Thread(() -> { - runLater(() -> { - editIcon.setImage(edit); - groupTitle.getStyleClass().add("clearTextField"); - groupTitle.setEditable(false); - rename.setTooltip(new Tooltip("Rename")); + renameCancel.setOnAction(ae -> new Thread(() -> runLater(() -> { + editIcon.setImage(edit); + groupTitle.getStyleClass().add("clearTextField"); + groupTitle.setEditable(false); + rename.setTooltip(new Tooltip("Rename")); - renameCancel.setVisible(false); - renameCancel.setManaged(false); - renameCancel.setDisable(true); + renameCancel.setVisible(false); + renameCancel.setManaged(false); + renameCancel.setDisable(true); - groupTitle.setText(group.getName()); + groupTitle.setText(group.getName()); - FXUtils.adjustTextFieldWidthByContent(groupTitle); - }); - }).start()); + FXUtils.adjustTextFieldWidthByContent(groupTitle); + })).start()); renameCancel.setTooltip(new Tooltip("Cancel")); SelectionModel selectionModel = groupItemList.getSelectionModel(); @@ -306,9 +300,7 @@ public ManageGroupsManager(final Group group) throws IOException { MGMVDeleteGroupModal mgmvDelete = new MGMVDeleteGroupModal(); deleteModal.setContent(mgmvDelete); deleteModal.setDividerClass("dividerDanger"); - btnDelete.setOnAction(ae -> runLater(() -> { - deleteModal.setVisible(true); - })); + btnDelete.setOnAction(ae -> runLater(() -> deleteModal.setVisible(true))); deleteModal.visibleProperty().addListener((cl) -> { mgmvDelete.getBtnClose().setCancelButton(deleteModal.isVisible()); mgmvDelete.getBtnDelete().setDefaultButton(deleteModal.isVisible()); @@ -337,9 +329,7 @@ public ManageGroupsManager(final Group group) throws IOException { btnReload.fire(); }); }).start()); - mgmvDelete.getBtnClose().setOnAction(ae -> { - deleteModal.setVisible(false); - }); + mgmvDelete.getBtnClose().setOnAction(ae -> deleteModal.setVisible(false)); /* Add Item Modal diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCExportModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCExportModal.java index 56f8267..7d4014d 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCExportModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCExportModal.java @@ -20,7 +20,6 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.sql.SQLException; -import java.time.format.DateTimeFormatter; import java.util.concurrent.atomic.AtomicLong; import static javafx.application.Platform.runLater; diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCManageTagsModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCManageTagsModal.java index b105251..a97151c 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCManageTagsModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCManageTagsModal.java @@ -3,7 +3,6 @@ import com.google.common.eventbus.Subscribe; import io.mattw.youtube.commentsuite.CommentSuite; import io.mattw.youtube.commentsuite.db.CommentDatabase; -import io.mattw.youtube.commentsuite.db.SQLLoader; import io.mattw.youtube.commentsuite.db.YouTubeComment; import io.mattw.youtube.commentsuite.events.TagsChangeEvent; import javafx.fxml.FXML; @@ -98,9 +97,7 @@ private void refreshAllTags() { public void withComments(List selected) { this.selected = selected; - runLater(() -> { - lblAbout.setText(String.format("%s comments(s) selected", selected.size())); - }); + runLater(() -> lblAbout.setText(String.format("%s comments(s) selected", selected.size()))); } public List toComments() { diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCSelectTagsModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCSelectTagsModal.java index 4430718..5c447a5 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCSelectTagsModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCSelectTagsModal.java @@ -3,7 +3,6 @@ import com.google.common.eventbus.Subscribe; import io.mattw.youtube.commentsuite.CommentSuite; import io.mattw.youtube.commentsuite.db.CommentDatabase; -import io.mattw.youtube.commentsuite.db.YouTubeComment; import io.mattw.youtube.commentsuite.events.TagsChangeEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -15,8 +14,6 @@ import java.io.IOException; import java.sql.SQLException; import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; import static javafx.application.Platform.runLater; diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCShowMoreModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCShowMoreModal.java index ee164ef..1195fd0 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/SCShowMoreModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/SCShowMoreModal.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.sql.SQLException; -import java.util.Collections; import static javafx.application.Platform.runLater; diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/SYAddToGroupModal.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/SYAddToGroupModal.java index cb5e372..f758050 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/SYAddToGroupModal.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/SYAddToGroupModal.java @@ -132,9 +132,7 @@ private void submitItemsToGroup(final List items, final G logger.debug("GroupItems were successfully added to group"); - runLater(() -> { - btnClose.fire(); - }); + runLater(() -> btnClose.fire()); } catch (SQLException e) { logger.error("Failed to insert group items to group [id={}]", group.getGroupId()); diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchComments.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchComments.java index 35fcad8..8c59265 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchComments.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchComments.java @@ -381,15 +381,11 @@ public void initialize(URL location, ResourceBundle resources) { SCSelectTagsModal scSelectTagsModal = new SCSelectTagsModal(); selectTagsModal.setContent(scSelectTagsModal); scSelectTagsModal.getBtnClose().setOnAction(ae -> selectTagsModal.setVisible(false)); - scSelectTagsModal.getBtnSelect().setOnAction(ae -> { - runLater(() -> { - hasTags.setText(scSelectTagsModal.getSelectedString()); - selectTagsModal.setVisible(false); - }); - }); - btnSelectTags.setOnAction(ae -> { - selectTagsModal.setVisible(true); - }); + scSelectTagsModal.getBtnSelect().setOnAction(ae -> runLater(() -> { + hasTags.setText(scSelectTagsModal.getSelectedString()); + selectTagsModal.setVisible(false); + })); + btnSelectTags.setOnAction(ae -> selectTagsModal.setVisible(true)); } /** diff --git a/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchYouTube.java b/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchYouTube.java index 2337d45..5e6b120 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchYouTube.java +++ b/src/main/java/io/mattw/youtube/commentsuite/fxml/SearchYouTube.java @@ -93,18 +93,16 @@ public void initialize(URL location, ResourceBundle resources) { locationBox.visibleProperty().bind(isLocation); searchRadius.managedProperty().bind(isLocation); searchRadius.visibleProperty().bind(isLocation); - isLocation.addListener((o, ov, nv) -> { - runLater(() -> { - if (nv) { - previousType = resultType.getValue(); - resultType.setValue("Video"); - resultType.setDisable(true); - } else { - resultType.setValue(previousType); - resultType.setDisable(false); - } - }); - }); + isLocation.addListener((o, ov, nv) -> runLater(() -> { + if (nv) { + previousType = resultType.getValue(); + resultType.setValue("Video"); + resultType.setDisable(true); + } else { + resultType.setValue(previousType); + resultType.setDisable(false); + } + })); resultsList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); diff --git a/src/main/java/io/mattw/youtube/commentsuite/oauth2/OAuth2Manager.java b/src/main/java/io/mattw/youtube/commentsuite/oauth2/OAuth2Manager.java index a7db9a1..a4e9170 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/oauth2/OAuth2Manager.java +++ b/src/main/java/io/mattw/youtube/commentsuite/oauth2/OAuth2Manager.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.lang.reflect.Modifier; import java.sql.SQLException; -import java.util.Collections; import java.util.Optional; public class OAuth2Manager { diff --git a/src/main/java/io/mattw/youtube/commentsuite/refresh/CommentThreadProducer.java b/src/main/java/io/mattw/youtube/commentsuite/refresh/CommentThreadProducer.java index c885419..e3b2512 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/refresh/CommentThreadProducer.java +++ b/src/main/java/io/mattw/youtube/commentsuite/refresh/CommentThreadProducer.java @@ -28,7 +28,6 @@ import java.util.stream.Collectors; import static io.mattw.youtube.commentsuite.refresh.ModerationStatus.PUBLISHED; -import static org.apache.commons.lang3.StringUtils.isBlank; public class CommentThreadProducer extends ConsumerMultiProducer { diff --git a/src/main/java/io/mattw/youtube/commentsuite/refresh/GroupRefresh.java b/src/main/java/io/mattw/youtube/commentsuite/refresh/GroupRefresh.java index a38d1f7..a316434 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/refresh/GroupRefresh.java +++ b/src/main/java/io/mattw/youtube/commentsuite/refresh/GroupRefresh.java @@ -1,6 +1,5 @@ package io.mattw.youtube.commentsuite.refresh; -import com.google.api.client.googleapis.json.GoogleJsonError; import com.google.api.client.googleapis.json.GoogleJsonResponseException; import io.mattw.youtube.commentsuite.CommentSuite; import io.mattw.youtube.commentsuite.db.*; diff --git a/src/main/java/io/mattw/youtube/commentsuite/refresh/ReplyProducer.java b/src/main/java/io/mattw/youtube/commentsuite/refresh/ReplyProducer.java index 1682b97..836b2c1 100644 --- a/src/main/java/io/mattw/youtube/commentsuite/refresh/ReplyProducer.java +++ b/src/main/java/io/mattw/youtube/commentsuite/refresh/ReplyProducer.java @@ -15,10 +15,6 @@ import java.io.IOException; import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; -import java.util.function.Predicate; import java.util.stream.Collectors; public class ReplyProducer extends ConsumerMultiProducer {