Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public class LoginFormController extends Controller {
@FXML Label errorLabel;
@FXML Button submitButton;

@Override
protected Label getErrorLabel() {
return errorLabel;
}

@Override
protected boolean interceptAuthFailure() {
return false;
}

@FXML
void onSubmit(ActionEvent event) {
String email = emailField.getText() == null ? "" : emailField.getText().trim();
Expand All @@ -42,19 +52,7 @@ void onSubmit(ActionEvent event) {
hideError();
navigator.goTo("/fxml/ResourceList.fxml");
} catch (ServiceException e) {
showError(e.getMessage());
showError(e);
}
}

private void showError(String message) {
errorLabel.setText(message);
errorLabel.setVisible(true);
errorLabel.setManaged(true);
}

private void hideError() {
errorLabel.setText("");
errorLabel.setVisible(false);
errorLabel.setManaged(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public class ResourceDetailsController extends Controller {
@FXML Button editButton;
@FXML Button deleteButton;

@Override
protected Label getErrorLabel() {
return errorLabel;
}

private UUID resourceId;

/**
Expand Down Expand Up @@ -101,7 +106,7 @@ public void load() {
try {
showResource(services.getResourceService().getById(resourceId));
} catch (ServiceException e) {
showError(e.getMessage());
showError(e);
}
}

Expand All @@ -120,7 +125,7 @@ void onDownload(FileInfo file) {
Path saved = services.getFileService().downloadFile(resourceId, file.getUuid(), dir.toPath());
statusLabel.setText("Сохранено: " + saved.getFileName());
} catch (ServiceException e) {
showError(e.getMessage());
showError(e);
}
}

Expand Down Expand Up @@ -169,18 +174,6 @@ private static String formatSize(Long bytes) {
return String.format("%.1f GB", bytes / (1024.0 * 1024 * 1024));
}

private void showError(String message) {
errorLabel.setText(message);
errorLabel.setVisible(true);
errorLabel.setManaged(true);
}

private void hideError() {
errorLabel.setText("");
errorLabel.setVisible(false);
errorLabel.setManaged(false);
}

private static final class DownloadCell extends TableCell<FileInfo, Void> {
private final Button button = new Button("Скачать");

Expand Down Expand Up @@ -210,7 +203,7 @@ void onDelete(ActionEvent event) {
try {
services.getResourceService().delete(resourceId);
} catch (ServiceException e) {
showError(e.getMessage());
showError(e);
return;
}
navigator.goTo("/fxml/ResourceList.fxml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class ResourceFormController extends Controller {
@FXML Button cancelButton;
@FXML Button saveButton;

@Override
protected Label getErrorLabel() {
return errorLabel;
}

private UUID resourceId;

/**
Expand Down Expand Up @@ -55,7 +60,7 @@ private void loadExisting() {
titleField.setText(r.getTitle() == null ? "" : r.getTitle());
descriptionArea.setText(r.getDescription() == null ? "" : r.getDescription());
} catch (ServiceException e) {
showError(e.getMessage());
showError(e);
}
}

Expand Down Expand Up @@ -90,24 +95,12 @@ void onSave(ActionEvent event) {
}
navigator.goTo("/fxml/ResourceList.fxml");
} catch (ServiceException e) {
showError(e.getMessage());
showError(e);
}
}

@FXML
void onCancel(ActionEvent event) {
navigator.goTo("/fxml/ResourceList.fxml");
}

private void showError(String message) {
errorLabel.setText(message);
errorLabel.setVisible(true);
errorLabel.setManaged(true);
}

private void hideError() {
errorLabel.setText("");
errorLabel.setVisible(false);
errorLabel.setManaged(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.DesktopApplicationClientJava.controllers.utils.Controller;
import com.DesktopApplicationClientJava.entities.Resource;
import com.DesktopApplicationClientJava.services.ServiceException;
import com.DesktopApplicationClientJava.services.filter.ResourceFilter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -53,6 +52,11 @@ public class ResourceListController extends Controller {
private long offset = 0;
private boolean canModify = false;

@Override
protected Label getErrorLabel() {
return errorLabel;
}

// ===== Lifecycle =====

@FXML
Expand Down Expand Up @@ -184,9 +188,7 @@ protected List<Resource> call() {
task.setOnFailed(
e -> {
var ex = task.getException();
String msg =
ex instanceof ServiceException se ? se.getMessage() : "Не удалось загрузить список";
showError(msg);
showError(ex, "Не удалось загрузить список");
rows.clear();
updatePaginationUi(0);
statusLabel.setText("");
Expand Down Expand Up @@ -266,9 +268,7 @@ protected Void call() {
task.setOnFailed(
e -> {
var ex = task.getException();
String msg =
ex instanceof ServiceException se ? se.getMessage() : "Не удалось удалить ресурс";
showError(msg);
showError(ex, "Не удалось удалить ресурс");
statusLabel.setText("");
});

Expand All @@ -292,8 +292,16 @@ protected boolean confirmDelete(Resource resource) {

@FXML
private void onLogout(ActionEvent e) {
services.getAuthService().logout();
navigator.goTo("/fxml/LoginForm.fxml");
try {
services.getAuthService().logout();
} catch (RuntimeException ignored) {
// Выход съедает ошибку сервиса без мелькания: редирект ниже выполняется в любом случае.
} finally {
if (session != null) {
session.clear();
}
navigator.goToLoginOnce();
}
}

@FXML
Expand Down Expand Up @@ -331,16 +339,4 @@ private void openDetails(Resource resource) {
private static String formatDate(LocalDateTime value) {
return value == null ? "" : DATE_TIME_FORMAT.format(value);
}

private void showError(String message) {
errorLabel.setText(message);
errorLabel.setVisible(true);
errorLabel.setManaged(true);
}

private void hideError() {
errorLabel.setText("");
errorLabel.setVisible(false);
errorLabel.setManaged(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class UserCreateFormController extends Controller {
@FXML private TextField firstNameField;
@FXML private TextField lastNameField;

@Override
protected Label getErrorLabel() {
return errorLabel;
}

@FXML
public void initialize() {
// Способ 1: через setItems
Expand Down Expand Up @@ -72,24 +77,12 @@ private void onSubmit(ActionEvent event) {
hideError();
navigator.goTo("/fxml/UserList.fxml");
} catch (ServiceException e) {
showError(e.getMessage());
showError(e);
}
}

@FXML
void onCancel(ActionEvent event) {
navigator.goTo("/fxml/UserList.fxml");
}

private void showError(String message) {
errorLabel.setText(message);
errorLabel.setVisible(true);
errorLabel.setManaged(true);
}

private void hideError() {
errorLabel.setText("");
errorLabel.setVisible(false);
errorLabel.setManaged(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.DesktopApplicationClientJava.controllers.utils.Controller;
import com.DesktopApplicationClientJava.entities.User;
import com.DesktopApplicationClientJava.services.ServiceException;
import java.util.UUID;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
Expand All @@ -29,6 +28,11 @@ public class UserDetailsController extends Controller {
private UUID userId;
private User current;

@Override
protected Label getErrorLabel() {
return errorLabel;
}

// ===== Lifecycle =====

@FXML
Expand Down Expand Up @@ -85,11 +89,7 @@ protected User call() {
e -> {
statusLabel.setText("");
var ex = task.getException();
String msg =
ex instanceof ServiceException se
? se.getMessage()
: "Не удалось загрузить пользователя";
showError(msg);
showError(ex, "Не удалось загрузить пользователя");
});

startDaemon(task, "user-details-load");
Expand Down Expand Up @@ -179,11 +179,7 @@ protected Void call() {
ev -> {
setBusy(false);
var ex = task.getException();
String msg =
ex instanceof ServiceException se
? se.getMessage()
: "Не удалось удалить пользователя";
showError(msg);
showError(ex, "Не удалось удалить пользователя");
});

startDaemon(task, "user-delete");
Expand Down Expand Up @@ -228,18 +224,6 @@ private void setBusy(boolean busy) {
statusLabel.setText(busy ? "Удаление…" : "");
}

private void showError(String message) {
errorLabel.setText(message);
errorLabel.setVisible(true);
errorLabel.setManaged(true);
}

private void hideError() {
errorLabel.setText("");
errorLabel.setVisible(false);
errorLabel.setManaged(false);
}

private static void startDaemon(Task<?> task, String name) {
var thread = new Thread(task, name);
thread.setDaemon(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.DesktopApplicationClientJava.controllers.utils.Controller;
import com.DesktopApplicationClientJava.entities.Role;
import com.DesktopApplicationClientJava.entities.User;
import com.DesktopApplicationClientJava.services.ServiceException;
import com.DesktopApplicationClientJava.services.data.UpdateUserData;
import java.util.UUID;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -31,6 +30,11 @@ public class UserUpdateFormController extends Controller {
private UUID userId;
private User current;

@Override
protected Label getErrorLabel() {
return errorLabel;
}

// ===== Lifecycle =====

@FXML
Expand Down Expand Up @@ -77,11 +81,7 @@ protected User call() {
task.setOnFailed(
e -> {
var ex = task.getException();
String msg =
ex instanceof ServiceException se
? se.getMessage()
: "Не удалось загрузить пользователя";
showError(msg);
showError(ex, "Не удалось загрузить пользователя");
setFormDisabled(true);
});

Expand Down Expand Up @@ -130,11 +130,7 @@ protected User call() {
ev -> {
setFormDisabled(false);
var ex = task.getException();
String msg =
ex instanceof ServiceException se
? se.getMessage()
: "Не удалось сохранить изменения";
showError(msg);
showError(ex, "Не удалось сохранить изменения");
});

startDaemon(task, "user-update-save");
Expand Down Expand Up @@ -195,18 +191,6 @@ private void setFormDisabled(boolean disabled) {
saveButton.setDisable(disabled);
}

private void showError(String message) {
errorLabel.setText(message);
errorLabel.setVisible(true);
errorLabel.setManaged(true);
}

private void hideError() {
errorLabel.setText("");
errorLabel.setVisible(false);
errorLabel.setManaged(false);
}

private static String safeTrim(String value) {
return value == null ? null : value.trim();
}
Expand Down
Loading
Loading