Improved some things.
This commit is contained in:
parent
439235c568
commit
ca6bea60dd
|
@ -9,18 +9,18 @@ import nl.andrewlalis.crystalkeep.model.Shard;
|
||||||
import nl.andrewlalis.crystalkeep.model.shards.LoginCredentialsShard;
|
import nl.andrewlalis.crystalkeep.model.shards.LoginCredentialsShard;
|
||||||
import nl.andrewlalis.crystalkeep.model.shards.TextShard;
|
import nl.andrewlalis.crystalkeep.model.shards.TextShard;
|
||||||
import nl.andrewlalis.crystalkeep.view.ShardTreeItem;
|
import nl.andrewlalis.crystalkeep.view.ShardTreeItem;
|
||||||
import nl.andrewlalis.crystalkeep.view.shard_details.LoginCredentialsPane;
|
import nl.andrewlalis.crystalkeep.view.shard_details.LoginCredentialsViewModel;
|
||||||
import nl.andrewlalis.crystalkeep.view.shard_details.ShardPane;
|
import nl.andrewlalis.crystalkeep.view.shard_details.ShardViewModel;
|
||||||
import nl.andrewlalis.crystalkeep.view.shard_details.TextShardPane;
|
import nl.andrewlalis.crystalkeep.view.shard_details.TextShardViewModel;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ClusterTreeViewItemSelectionListener implements ChangeListener<TreeItem<CrystalItem>> {
|
public class ClusterTreeViewItemSelectionListener implements ChangeListener<TreeItem<CrystalItem>> {
|
||||||
private static final Map<Class<? extends Shard>, Class<? extends ShardPane<? extends Shard>>> shardPanesMap = new HashMap<>();
|
private static final Map<Class<? extends Shard>, Class<? extends ShardViewModel<? extends Shard>>> shardPanesMap = new HashMap<>();
|
||||||
static {
|
static {
|
||||||
shardPanesMap.put(TextShard.class, TextShardPane.class);
|
shardPanesMap.put(TextShard.class, TextShardViewModel.class);
|
||||||
shardPanesMap.put(LoginCredentialsShard.class, LoginCredentialsPane.class);
|
shardPanesMap.put(LoginCredentialsShard.class, LoginCredentialsViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final VBox shardDetailContainer;
|
private final VBox shardDetailContainer;
|
||||||
|
@ -36,8 +36,8 @@ public class ClusterTreeViewItemSelectionListener implements ChangeListener<Tree
|
||||||
var node = (ShardTreeItem) newValue;
|
var node = (ShardTreeItem) newValue;
|
||||||
var paneClass = shardPanesMap.get(node.getShard().getClass());
|
var paneClass = shardPanesMap.get(node.getShard().getClass());
|
||||||
try {
|
try {
|
||||||
var pane = paneClass.getDeclaredConstructor(node.getShard().getClass()).newInstance(node.getShard());
|
var vm = paneClass.getDeclaredConstructor(node.getShard().getClass()).newInstance(node.getShard());
|
||||||
shardDetailContainer.getChildren().add(pane);
|
shardDetailContainer.getChildren().add(vm.getContentPane());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package nl.andrewlalis.crystalkeep.model;
|
package nl.andrewlalis.crystalkeep.model;
|
||||||
|
|
||||||
|
import nl.andrewlalis.crystalkeep.model.shards.FileShard;
|
||||||
import nl.andrewlalis.crystalkeep.model.shards.LoginCredentialsShard;
|
import nl.andrewlalis.crystalkeep.model.shards.LoginCredentialsShard;
|
||||||
import nl.andrewlalis.crystalkeep.model.shards.TextShard;
|
import nl.andrewlalis.crystalkeep.model.shards.TextShard;
|
||||||
|
|
||||||
|
@ -20,7 +21,12 @@ public enum ShardType {
|
||||||
/**
|
/**
|
||||||
* Represents a {@link LoginCredentialsShard}
|
* Represents a {@link LoginCredentialsShard}
|
||||||
*/
|
*/
|
||||||
LOGIN_CREDENTIALS(2);
|
LOGIN_CREDENTIALS(2),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a {@link FileShard}
|
||||||
|
*/
|
||||||
|
FILE(3);
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package nl.andrewlalis.crystalkeep.model.serialization;
|
package nl.andrewlalis.crystalkeep.model.serialization;
|
||||||
|
|
||||||
import javafx.scene.control.Dialog;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.TextInputDialog;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
import nl.andrewlalis.crystalkeep.model.Cluster;
|
import nl.andrewlalis.crystalkeep.model.Cluster;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
@ -29,11 +31,21 @@ public class ClusterLoader {
|
||||||
private static final byte[] IV = "Fafioje;a324fsde".getBytes(StandardCharsets.UTF_8);
|
private static final byte[] IV = "Fafioje;a324fsde".getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
public Optional<String> promptPassword() {
|
public Optional<String> promptPassword() {
|
||||||
Dialog<String> d = new TextInputDialog();
|
Dialog<String> d = new Dialog<>();
|
||||||
d.setContentText("Enter the password");
|
|
||||||
d.setGraphic(null);
|
|
||||||
d.setHeaderText(null);
|
|
||||||
d.setTitle("Enter Password");
|
d.setTitle("Enter Password");
|
||||||
|
d.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||||
|
|
||||||
|
PasswordField pwField = new PasswordField();
|
||||||
|
VBox content = new VBox(10);
|
||||||
|
content.setAlignment(Pos.CENTER);
|
||||||
|
content.getChildren().addAll(new Label("Enter password"), pwField);
|
||||||
|
d.getDialogPane().setContent(content);
|
||||||
|
d.setResultConverter(param -> {
|
||||||
|
if (param == ButtonType.OK) {
|
||||||
|
return pwField.getText();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
return d.showAndWait();
|
return d.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package nl.andrewlalis.crystalkeep.model.shards;
|
||||||
|
|
||||||
|
import nl.andrewlalis.crystalkeep.model.Shard;
|
||||||
|
import nl.andrewlalis.crystalkeep.model.ShardType;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class FileShard extends Shard {
|
||||||
|
private String fileName;
|
||||||
|
private String mimeType;
|
||||||
|
private byte[] contents;
|
||||||
|
|
||||||
|
public FileShard(String name, LocalDateTime createdAt, String fileName, String mimeType, byte[] contents) {
|
||||||
|
super(name, createdAt, ShardType.FILE);
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.mimeType = mimeType;
|
||||||
|
this.contents = contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileShard(String name, String fileName, String mimeType, byte[] contents) {
|
||||||
|
this(name, LocalDateTime.now(), fileName, mimeType, contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMimeType() {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getContents() {
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,8 +10,8 @@ import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import nl.andrewlalis.crystalkeep.model.shards.LoginCredentialsShard;
|
import nl.andrewlalis.crystalkeep.model.shards.LoginCredentialsShard;
|
||||||
|
|
||||||
public class LoginCredentialsPane extends ShardPane<LoginCredentialsShard> {
|
public class LoginCredentialsViewModel extends ShardViewModel<LoginCredentialsShard> {
|
||||||
public LoginCredentialsPane(LoginCredentialsShard shard) {
|
public LoginCredentialsViewModel(LoginCredentialsShard shard) {
|
||||||
super(shard);
|
super(shard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ public class LoginCredentialsPane extends ShardPane<LoginCredentialsShard> {
|
||||||
gp.setVgap(5);
|
gp.setVgap(5);
|
||||||
gp.add(new Label("Username"), 0, 0);
|
gp.add(new Label("Username"), 0, 0);
|
||||||
var usernameField = new TextField(shard.getUsername());
|
var usernameField = new TextField(shard.getUsername());
|
||||||
|
usernameField.setPrefColumnCount(40);
|
||||||
usernameField.textProperty().addListener((observable, oldValue, newValue) -> {
|
usernameField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
shard.setUsername(newValue);
|
shard.setUsername(newValue);
|
||||||
});
|
});
|
||||||
|
@ -30,8 +31,10 @@ public class LoginCredentialsPane extends ShardPane<LoginCredentialsShard> {
|
||||||
gp.add(new Label("Password"), 0, 1);
|
gp.add(new Label("Password"), 0, 1);
|
||||||
var passwordField = new PasswordField();
|
var passwordField = new PasswordField();
|
||||||
passwordField.setText(shard.getPassword());
|
passwordField.setText(shard.getPassword());
|
||||||
|
passwordField.setPrefColumnCount(40);
|
||||||
var rawPasswordField = new TextField(shard.getPassword());
|
var rawPasswordField = new TextField(shard.getPassword());
|
||||||
rawPasswordField.setVisible(false);
|
rawPasswordField.setVisible(false);
|
||||||
|
rawPasswordField.setPrefColumnCount(40);
|
||||||
passwordField.textProperty().addListener((observable, oldValue, newValue) -> {
|
passwordField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
shard.setPassword(newValue);
|
shard.setPassword(newValue);
|
||||||
rawPasswordField.setText(newValue);
|
rawPasswordField.setText(newValue);
|
|
@ -12,9 +12,15 @@ import nl.andrewlalis.crystalkeep.model.Shard;
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public abstract class ShardPane<T extends Shard> extends VBox {
|
public abstract class ShardViewModel<T extends Shard> {
|
||||||
public ShardPane(T shard) {
|
protected final T shard;
|
||||||
this.setSpacing(5);
|
|
||||||
|
public ShardViewModel(T shard) {
|
||||||
|
this.shard = shard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getContentPane() {
|
||||||
|
VBox pane = new VBox(5);
|
||||||
GridPane gp = new GridPane();
|
GridPane gp = new GridPane();
|
||||||
gp.setPadding(new Insets(5));
|
gp.setPadding(new Insets(5));
|
||||||
gp.setHgap(5);
|
gp.setHgap(5);
|
||||||
|
@ -29,9 +35,10 @@ public abstract class ShardPane<T extends Shard> extends VBox {
|
||||||
var createdAtField = new TextField(shard.getCreatedAt().format(DateTimeFormatter.ofPattern("dd MMMM yyyy HH:mm:ss")));
|
var createdAtField = new TextField(shard.getCreatedAt().format(DateTimeFormatter.ofPattern("dd MMMM yyyy HH:mm:ss")));
|
||||||
createdAtField.setEditable(false);
|
createdAtField.setEditable(false);
|
||||||
gp.add(createdAtField, 1, 1);
|
gp.add(createdAtField, 1, 1);
|
||||||
this.getChildren().add(gp);
|
pane.getChildren().add(gp);
|
||||||
this.getChildren().add(new Separator(Orientation.HORIZONTAL));
|
pane.getChildren().add(new Separator(Orientation.HORIZONTAL));
|
||||||
this.getChildren().add(this.getContent(shard));
|
pane.getChildren().add(this.getContent(shard));
|
||||||
|
return pane;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Node getContent(T shard);
|
protected abstract Node getContent(T shard);
|
|
@ -4,8 +4,8 @@ import javafx.scene.Node;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import nl.andrewlalis.crystalkeep.model.shards.TextShard;
|
import nl.andrewlalis.crystalkeep.model.shards.TextShard;
|
||||||
|
|
||||||
public class TextShardPane extends ShardPane<TextShard> {
|
public class TextShardViewModel extends ShardViewModel<TextShard> {
|
||||||
public TextShardPane(TextShard shard) {
|
public TextShardViewModel(TextShard shard) {
|
||||||
super(shard);
|
super(shard);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue