Search in sources :

Example 1 with ERROR

use of java.lang.System.Logger.Level.ERROR in project tcMenu by davetcc.

the class NewProjectController method onCreate.

public void onCreate(ActionEvent actionEvent) {
    boolean newOnlyMode = newOnlyRadio.isSelected();
    if (newOnlyMode) {
        if (!passDirtyCheck())
            return;
        project.newProject();
    } else if (maybeDirectory.isPresent() && !StringHelper.isStringEmptyOrNull(projectNameField.getText())) {
        if (!passDirtyCheck())
            return;
        try {
            String projName = projectNameField.getText();
            var projectCreator = new CreateProjectCommand();
            projectCreator.createNewProject(Paths.get(maybeDirectory.get()), projName, cppMainCheckbox.isSelected(), platformCombo.getSelectionModel().getSelectedItem(), s -> logger.log(INFO, s), namespaceField.getText());
            Path emfFileName = Paths.get(maybeDirectory.get(), projName, projName + ".emf");
            project.openProject(emfFileName.toString());
        } catch (Exception e) {
            logger.log(ERROR, "Failure processing create new project", e);
            var alert = new Alert(Alert.AlertType.ERROR, "Error during create project", ButtonType.CLOSE);
            BaseDialogSupport.getJMetro().setScene(alert.getDialogPane().getScene());
            alert.showAndWait();
        }
    } else {
        var alert = new Alert(Alert.AlertType.WARNING, "Please ensure all fields are populated", ButtonType.CLOSE);
        BaseDialogSupport.getJMetro().setScene(alert.getDialogPane().getScene());
        alert.showAndWait();
        // avoid closing.
        return;
    }
    Stage stage = (Stage) createButton.getScene().getWindow();
    stage.close();
}
Also used : StringHelper(com.thecoderscorner.menu.editorui.util.StringHelper) EmbeddedPlatforms(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatforms) javafx.scene.control(javafx.scene.control) Files(java.nio.file.Files) INFO(java.lang.System.Logger.Level.INFO) FXCollections(javafx.collections.FXCollections) BaseDialogSupport(com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport) EmbeddedPlatform(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform) KeyEvent(javafx.scene.input.KeyEvent) CreateProjectCommand(com.thecoderscorner.menu.editorui.cli.CreateProjectCommand) CurrentEditorProject(com.thecoderscorner.menu.editorui.project.CurrentEditorProject) LogLine(com.thecoderscorner.menu.editorui.generator.ui.LogLine) File(java.io.File) ERROR(java.lang.System.Logger.Level.ERROR) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) Paths(java.nio.file.Paths) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) Optional(java.util.Optional) Path(java.nio.file.Path) DirectoryChooser(javafx.stage.DirectoryChooser) Path(java.nio.file.Path) CreateProjectCommand(com.thecoderscorner.menu.editorui.cli.CreateProjectCommand) Stage(javafx.stage.Stage)

Example 2 with ERROR

use of java.lang.System.Logger.Level.ERROR in project tcMenu by davetcc.

the class PropertiesAuthenticator method addAuthentication.

/**
 * Adds an authentication token to the store, it assumes that all appropriate permission from the user has
 * been sought.
 * @param user the user to add
 * @param uuid the uuid associated with the user
 * @return
 */
@Override
public CompletableFuture<Boolean> addAuthentication(String user, UUID uuid) {
    if (dialogManager == null)
        return CompletableFuture.completedFuture(false);
    return CompletableFuture.supplyAsync(() -> {
        try {
            logger.log(INFO, "Request for authentication with " + user);
            var shouldProceed = new AtomicBoolean(false);
            var dialogLatch = new CountDownLatch(1);
            dialogManager.withTitle("Pair with " + user, true).withMessage("Be sure you know where this connection originated", true).withDelegate(DialogViewer.DialogShowMode.REGULAR, menuButtonType -> {
                shouldProceed.set(menuButtonType == MenuButtonType.ACCEPT);
                dialogLatch.countDown();
                return true;
            }).showDialogWithButtons(MenuButtonType.ACCEPT, MenuButtonType.CANCEL);
            if (!dialogLatch.await(30, TimeUnit.SECONDS)) {
                logger.log(INFO, "Dialog Latch timed out without user operation");
            }
            if (shouldProceed.get()) {
                synchronized (properties) {
                    Path pathLocation = Path.of(location);
                    properties.setProperty(user, uuid.toString());
                    properties.store(Files.newBufferedWriter(pathLocation, CREATE, TRUNCATE_EXISTING), "TcMenu Auth properties");
                }
                logger.log(INFO, "Wrote auth properties to ", location);
                return true;
            } else {
                logger.log(INFO, "Pairing dialog was not accepted");
                return false;
            }
        } catch (Exception e) {
            logger.log(ERROR, "Failed to write auth properties to ", location);
            return false;
        }
    });
}
Also used : Properties(java.util.Properties) Files(java.nio.file.Files) StandardOpenOption(java.nio.file.StandardOpenOption) INFO(java.lang.System.Logger.Level.INFO) DialogManager(com.thecoderscorner.menu.mgr.DialogManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) DialogViewer(com.thecoderscorner.menu.mgr.DialogViewer) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) ERROR(java.lang.System.Logger.Level.ERROR) Path(java.nio.file.Path) MenuButtonType(com.thecoderscorner.menu.remote.commands.MenuButtonType) Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException)

Aggregations

ERROR (java.lang.System.Logger.Level.ERROR)2 INFO (java.lang.System.Logger.Level.INFO)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 CreateProjectCommand (com.thecoderscorner.menu.editorui.cli.CreateProjectCommand)1 BaseDialogSupport (com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport)1 EmbeddedPlatform (com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform)1 EmbeddedPlatforms (com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatforms)1 LogLine (com.thecoderscorner.menu.editorui.generator.ui.LogLine)1 CurrentEditorProject (com.thecoderscorner.menu.editorui.project.CurrentEditorProject)1 ConfigurationStorage (com.thecoderscorner.menu.editorui.storage.ConfigurationStorage)1 StringHelper (com.thecoderscorner.menu.editorui.util.StringHelper)1 DialogManager (com.thecoderscorner.menu.mgr.DialogManager)1 DialogViewer (com.thecoderscorner.menu.mgr.DialogViewer)1 MenuButtonType (com.thecoderscorner.menu.remote.commands.MenuButtonType)1 File (java.io.File)1 IOException (java.io.IOException)1 Paths (java.nio.file.Paths)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 Optional (java.util.Optional)1