Commit 14cd1692 authored by Nico Eckes's avatar Nico Eckes

Added PlayersScreen

parent edda0d6f
Pipeline #795 passed with stage
in 3 minutes and 13 seconds
......@@ -27,6 +27,7 @@ configurations {
dependencies {
embed group: 'org.yaml', name: 'snakeyaml', version: '1.17'
embed group: 'org.apache.commons', name: 'commons-vfs2', version: '2.2'
embed group: 'com.jcraft', name: 'jsch', version: '0.1.54'
embed group: 'commons-logging', name: 'commons-logging', version: '1.2'
compile 'org.jetbrains:annotations:13.0'
}
......
package com.unitedworldminers.permio.editor.component;
import com.unitedworldminers.permio.editor.Main;
import com.unitedworldminers.permio.editor.data.Player;
import com.unitedworldminers.permio.editor.data.PlayerProfile;
import com.unitedworldminers.permio.editor.screen.GroupsScreen;
......
......@@ -6,6 +6,7 @@ import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.image.Image;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
......@@ -31,8 +32,8 @@ public class PlayerProfile {
private static final String replace2 = "$1-$2-$3-$4-$5";
public static final Map<String, PlayerProfile> cache = new HashMap<>();
public static final PlayerProfile NULL = new PlayerProfile();
public final UUID uuid;
public final StringProperty name;
@NotNull public final UUID uuid;
@NotNull public final StringProperty name;
public final Image image;
@Nullable
......@@ -59,6 +60,7 @@ public class PlayerProfile {
return result;
}
@SuppressWarnings("ConstantConditions") // only for PlayerProfile.NULL
private PlayerProfile() {
uuid = null;
name = null;
......
package com.unitedworldminers.permio.editor.screen;
import com.unitedworldminers.permio.editor.data.Group;
import com.unitedworldminers.permio.editor.component.GroupsList;
import com.unitedworldminers.permio.editor.component.PermissionList;
import com.unitedworldminers.permio.editor.component.PlayerList;
import com.unitedworldminers.permio.editor.data.Group;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
......@@ -47,22 +45,24 @@ public class GroupsScreen {
private void selectGroup(Group old, Group now) {
setElementsDisabled(now == null);
if (old != null) {
inheritance.valueProperty().unbindBidirectional(old.inherits);
prefix.textProperty().unbindBidirectional(old.prefix);
suffix.textProperty().unbindBidirectional(old.suffix);
}
if (now != null) {
permissions.setSource(now.permissions);
players.setSource(MainScreen.players.filtered(p-> now.equals(p.group.get())));
if (old != null) inheritance.valueProperty().unbindBidirectional(old.inherits);
inheritance.setItems(MainScreen.groups.filtered(g -> !g.isChildOf(now)));
inheritance.valueProperty().bindBidirectional(now.inherits);
if (old != null) prefix.textProperty().unbindBidirectional(old.prefix);
prefix.textProperty().bindBidirectional(now.prefix);
if (old != null) suffix.textProperty().unbindBidirectional(old.suffix);
suffix.textProperty().bindBidirectional(now.suffix);
} else {
permissions.setSource(FXCollections.observableArrayList());
players.setSource(FXCollections.observableArrayList());
inheritance.getItems().clear();
prefix.clear();
suffix.clear();
}
}
......
......@@ -3,13 +3,11 @@ package com.unitedworldminers.permio.editor.screen;
import com.sun.javafx.scene.control.skin.MenuBarSkin;
import com.unitedworldminers.permio.editor.Main;
import com.unitedworldminers.permio.editor.data.GroupData;
import com.unitedworldminers.permio.editor.data.Player;
import com.unitedworldminers.permio.editor.data.PlayerData;
import com.unitedworldminers.permio.editor.exception.LoadException;
import com.unitedworldminers.permio.editor.util.Utils;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Modality;
......@@ -58,7 +56,7 @@ public class MainScreen {
Path players = Utils.fileChooser(Utils.ChooseType.OPEN, window, "Select players file", "players.yml");
if (players == null) return;
String err = load(groups, players);
Exception err = load(groups, players);
if (err != null) {
Alert dialog = new Alert(Alert.AlertType.ERROR);
dialog.setContentText("Error loading data: " + err);
......@@ -77,31 +75,30 @@ public class MainScreen {
}
@Nullable
private String load(Path groupsFile, Path playersFile) {
private Exception load(Path groupsFile, Path playersFile) {
try {
FileSystemManager fs = VFS.getManager();
return load(fs.resolveFile(groupsFile.toUri()), fs.resolveFile(playersFile.toUri()));
} catch (IOException e) {
return e.getMessage();
return e;
}
}
@Nullable
private String load(FileObject groups, FileObject players) {
private Exception load(FileObject groups, FileObject players) {
try {
MainScreen.groups = new GroupData(groups);
MainScreen.players = new PlayerData(players, MainScreen.groups);
} catch (LoadException e) {
return e.getMessage();
return e;
}
load();
return null;
return load();
}
private String load() {
private Exception load() {
groupsScreenController.load();
playersScreenController.load();
return null;
}
......@@ -131,7 +128,10 @@ public class MainScreen {
window.showAndWait();
@SuppressWarnings("unchecked")
Pair<FileObject, FileObject> files = (Pair<FileObject, FileObject>) window.getUserData();
load(files.getKey(), files.getValue());
if (files != null) {
Exception ex = load(files.getKey(), files.getValue());
if (ex != null) Utils.showExceptionAlert("Could not load data", ex);
}
}
class InstantMenu extends Menu {
......
package com.unitedworldminers.permio.editor.screen;
import com.unitedworldminers.permio.editor.data.PlayerProfile;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import java.util.HashMap;
import java.util.Map;
public class PlayerProfileScreen {
private final Map<String, Image> cache = new HashMap<>();
@FXML private Label name;
@FXML private Label uuid;
@FXML private ImageView image;
public void setProfile(PlayerProfile profile) {
image.setImage(cache.computeIfAbsent("https://crafatar.com/renders/body/" + profile.uuid, Image::new));
name.setText(profile.name.get());
uuid.setText(profile.uuid.toString());
}
}
package com.unitedworldminers.permio.editor.screen;
import com.unitedworldminers.permio.editor.component.PermissionList;
import com.unitedworldminers.permio.editor.component.PlayerList;
import com.unitedworldminers.permio.editor.data.Group;
import com.unitedworldminers.permio.editor.data.Player;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
public class PlayersScreen {
@FXML private PlayerList players;
@FXML private PermissionList permissions;
@FXML private VBox playerMeta;
@FXML private TextField prefix;
@FXML private TextField suffix;
@FXML private ComboBox<Group> group;
@FXML private PlayerProfileScreen playerProfileController;
public static final ObjectProperty<Player> activePlayer = new SimpleObjectProperty<>();
@FXML
private void initialize() {
players.setSource(MainScreen.players);
// playermeta width (combobox, spinner) enforcement
group.prefWidthProperty().bind(((Region) group.getParent()).widthProperty());
group.setItems(MainScreen.groups);
activePlayer.bind(players.list.getSelectionModel().selectedItemProperty());
activePlayer.addListener((observable, oldValue, newValue) -> {
selectPlayer(oldValue, newValue);
players.list.getSelectionModel().select(newValue);
});
}
public void load() {
players.reset();
permissions.reset();
players.setSource(MainScreen.players);
}
private void selectPlayer(Player old, Player now) {
setElementsDisabled(now == null);
playerProfileController.setProfile(now == null ? null : now.identity);
if (old != null) {
group.valueProperty().unbindBidirectional(old.group);
prefix.textProperty().unbindBidirectional(old.prefix);
suffix.textProperty().unbindBidirectional(old.suffix);
}
if (now != null) {
permissions.setSource(now.permissions);
group.valueProperty().bindBidirectional(now.group);
prefix.textProperty().bindBidirectional(now.prefix);
suffix.textProperty().bindBidirectional(now.suffix);
} else {
permissions.setSource(FXCollections.observableArrayList());
group.getItems().clear();
prefix.clear();
suffix.clear();
}
}
private void setElementsDisabled(boolean disabled) {
permissions.setDisable(disabled);
playerMeta.setDisable(disabled);
}
}
......@@ -6,10 +6,7 @@ import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Pair;
import javafx.util.StringConverter;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.*;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
public class SftpDialog {
......@@ -58,32 +55,28 @@ public class SftpDialog {
FileSystemManager fsManager = VFS.getManager();
String guri = String.format("sftp://%s:%s@%s:%d/%s", username.getText(), password.getText(), host.getText(), port.getValue(), groupPath.getText());
String puri = String.format("sftp://%s:%s@%s:%d/%s", username.getText(), password.getText(), host.getText(), port.getValue(), playerPath.getText());
stage.setUserData(new Pair<>(fsManager.resolveFile(guri, fsOptions).getContent(), fsManager.resolveFile(puri, fsOptions).getContent()));
FileObject gFile = fsManager.resolveFile(guri, fsOptions);
if (!gFile.exists()) {
new Alert(Alert.AlertType.ERROR, "File " + guri + " does not exist!").showAndWait();
return;
}
if (!gFile.isFile()) {
new Alert(Alert.AlertType.ERROR, "File " + guri + "is not a file!").showAndWait();
return;
}
FileObject pFile = fsManager.resolveFile(puri, fsOptions);
if (!pFile.exists()) {
new Alert(Alert.AlertType.ERROR, "File " + puri + " does not exist!").showAndWait();
return;
}
if (!pFile.isFile()) {
new Alert(Alert.AlertType.ERROR, "File " + puri + "is not a file!").showAndWait();
return;
}
stage.setUserData(new Pair<>(gFile, pFile));
} catch (FileSystemException e) {
e.printStackTrace();
}
stage.close();
/*JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession(username.getText(), host.getText(), port.getValue());
session.setTimeout(5000);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password.getText());
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.get(groupPath.getText());
sftpChannel.exit();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}*/
}
}
package com.unitedworldminers.permio.editor.util;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.FileChooser;
import javafx.stage.Window;
import org.jetbrains.annotations.Contract;
......@@ -7,6 +12,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
......@@ -51,6 +58,34 @@ public class Utils {
return result == null ? null : result.toPath();
}
public static void showExceptionAlert(String desc, Exception e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Exception");
alert.setHeaderText(desc);
alert.setContentText(e.getMessage());
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionText = sw.toString();
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(new Label("The exception stacktrace was:"), 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
public enum ChooseType {
OPEN, SAVE
}
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.Pane?>
<VBox alignment="CENTER" prefWidth="200" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.unitedworldminers.permio.editor.screen.PlayerProfileScreen">
<ImageView fx:id="image" VBox.vgrow="SOMETIMES" />
<Pane prefHeight="5" />
<Label fx:id="name" text="NAME" />
<Label fx:id="uuid" text="UUID" />
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
<?xml version="1.0" encoding="UTF-8"?>
<?import com.unitedworldminers.permio.editor.component.PermissionList?>
<?import com.unitedworldminers.permio.editor.component.PlayerList?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>
<?import com.unitedworldminers.permio.editor.component.PlayerList?>
<SplitPane dividerPositions="0.3, 0.7" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.unitedworldminers.permio.editor.screen.PlayersScreen">
<PlayerList fx:id="players" />
<PermissionList fx:id="permissions" disable="true" />
<Pane />
</SplitPane>
\ No newline at end of file
<VBox fx:id="playerMeta" disable="true">
<fx:include fx:id="playerProfile" source="PlayerProfileScreen.fxml" VBox.vgrow="SOMETIMES" />
<ComboBox fx:id="group" promptText="No group" />
<TextField fx:id="prefix" promptText="Prefix" />
<TextField fx:id="suffix" promptText="Suffix" />
</VBox>
</SplitPane>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment