Search in sources :

Example 1 with IssueReportingExceptionHandler

use of com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler in project BowlerStudio by CommonWealthRobotics.

the class MobleBaseMenueFactory method load.

@SuppressWarnings("unchecked")
public static void load(MobileBase device, TreeView<String> view, TreeItem<String> rootItem, HashMap<TreeItem<String>, Runnable> callbackMapForTreeitems, HashMap<TreeItem<String>, Group> widgetMapForTreeitems, CreatureLab creatureLab, boolean root, boolean creatureIsOwnedByUser) {
    // boolean creatureIsOwnedByUser = false;
    callbackMapForTreeitems.put(rootItem, () -> {
        BowlerStudio.select(device);
    });
    TreeItem<String> editXml = new TreeItem<String>("Edit Robot XML..", AssetFactory.loadIcon("Script-Tab-RobotXML.png"));
    callbackMapForTreeitems.put(editXml, () -> {
        try {
            File code = ScriptingEngine.fileFromGit(device.getGitSelfSource()[0], device.getGitSelfSource()[1]);
            BowlerStudio.createFileTab(code);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    });
    TreeItem<String> physics = new TreeItem<String>("Physics Simulation", AssetFactory.loadIcon("Physics-Creature-Simulation.png"));
    callbackMapForTreeitems.put(physics, () -> {
        if (widgetMapForTreeitems.get(physics) == null) {
            widgetMapForTreeitems.put(physics, new Group(new CreaturePhysicsWidget(device)));
        }
    });
    TreeItem<String> publish;
    publish = new TreeItem<String>("Publish", AssetFactory.loadIcon("Publish.png"));
    if (!(device.getGitSelfSource()[0] == null || device.getGitSelfSource()[1] == null)) {
        try {
            File source = ScriptingEngine.fileFromGit(device.getGitSelfSource()[0], device.getGitSelfSource()[1]);
            callbackMapForTreeitems.put(publish, () -> {
                CommitWidget.commit(source, device.getXml());
            });
        } catch (Exception e) {
            Log.error(device.getGitSelfSource()[0] + " " + device.getGitSelfSource()[1] + " failed to load");
            e.printStackTrace();
        }
    }
    if (creatureIsOwnedByUser) {
        if (root)
            rootItem.getChildren().addAll(publish);
    }
    TreeItem<String> makeCopy = new TreeItem<>("Make Copy of Creature", AssetFactory.loadIcon("Make-Copy-of-Creature.png"));
    if (root)
        rootItem.getChildren().addAll(makeCopy);
    callbackMapForTreeitems.put(makeCopy, () -> {
        Platform.runLater(() -> {
            String oldname = device.getScriptingName();
            TextInputDialog dialog = new TextInputDialog(oldname + "_copy");
            dialog.setTitle("Making a copy of " + oldname);
            dialog.setHeaderText("Set the scripting name for this creature");
            dialog.setContentText("Set the name of the new creature:");
            // Traditional way to get the response value.
            Optional<String> result = dialog.showAndWait();
            if (result.isPresent()) {
                view.getSelectionModel().select(rootItem);
                System.out.println("Your new creature: " + result.get());
                String newName = result.get();
                makeACopyOfACreature(device, oldname, newName).start();
            }
        });
    });
    try {
        TreeItem<String> legs = loadLimbs(device, view, device.getLegs(), "Legs", rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUser);
        TreeItem<String> arms = loadLimbs(device, view, device.getAppendages(), "Arms", rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUser);
        TreeItem<String> steer = loadLimbs(device, view, device.getSteerable(), "Steerable Wheels", rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUser);
        TreeItem<String> drive = loadLimbs(device, view, device.getDrivable(), "Fixed Wheels", rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUser);
        ArrayList<DHParameterKinematics> paraGroups = device.getAllParallelGroups();
        TreeItem<String> paralell = loadLimbs(device, view, paraGroups, "Paralell", rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUser);
        TreeItem<String> addleg;
        try {
            addleg = new TreeItem<String>("Add Leg", AssetFactory.loadIcon("Add-Leg.png"));
        } catch (Exception e1) {
            addleg = new TreeItem<String>("Add Leg");
        }
        boolean creatureIsOwnedByUserTmp = creatureIsOwnedByUser;
        callbackMapForTreeitems.put(addleg, () -> {
            // TODO Auto-generated method stub
            System.out.println("Adding Leg");
            String xmlContent;
            try {
                xmlContent = ScriptingEngine.codeFromGit("https://gist.github.com/b5b9450f869dd0d2ea30.git", "defaultleg.xml")[0];
                DHParameterKinematics newLeg = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8"));
                System.out.println("Leg has " + newLeg.getNumberOfLinks() + " links");
                addAppendage(device, view, device.getLegs(), newLeg, legs, rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUserTmp);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        TreeItem<String> regnerate = new TreeItem<String>("Generate Cad", AssetFactory.loadIcon("Generate-Cad.png"));
        callbackMapForTreeitems.put(regnerate, () -> {
            creatureLab.generateCad();
        });
        TreeItem<String> kinematics = new TreeItem<String>("Kinematic STL", AssetFactory.loadIcon("Printable-Cad.png"));
        callbackMapForTreeitems.put(kinematics, () -> {
            File defaultStlDir = new File(System.getProperty("user.home") + "/bowler-workspace/STL/");
            if (!defaultStlDir.exists()) {
                defaultStlDir.mkdirs();
            }
            Platform.runLater(() -> {
                DirectoryChooser chooser = new DirectoryChooser();
                chooser.setTitle("Select Output Directory For .STL files");
                chooser.setInitialDirectory(defaultStlDir);
                File baseDirForFiles = chooser.showDialog(BowlerStudioModularFrame.getPrimaryStage());
                new Thread() {

                    public void run() {
                        MobileBaseCadManager baseManager = MobileBaseCadManager.get(device);
                        if (baseDirForFiles == null) {
                            return;
                        }
                        ArrayList<File> files;
                        try {
                            files = baseManager.generateStls((MobileBase) device, baseDirForFiles, true);
                            Platform.runLater(() -> {
                                Alert alert = new Alert(AlertType.INFORMATION);
                                alert.setTitle("Stl Export Success!");
                                alert.setHeaderText("Stl Export Success");
                                alert.setContentText("All SLT's for the Creature Generated at\n" + files.get(0).getAbsolutePath());
                                alert.setWidth(500);
                                alert.initModality(Modality.APPLICATION_MODAL);
                                alert.show();
                            });
                        } catch (Exception e) {
                            BowlerStudioController.highlightException(baseManager.getCadScript(), e);
                        }
                    }
                }.start();
            });
        });
        TreeItem<String> printable = new TreeItem<String>("Printable Cad", AssetFactory.loadIcon("Printable-Cad.png"));
        callbackMapForTreeitems.put(printable, () -> {
            File defaultStlDir = new File(System.getProperty("user.home") + "/bowler-workspace/STL/");
            if (!defaultStlDir.exists()) {
                defaultStlDir.mkdirs();
            }
            Platform.runLater(() -> {
                DirectoryChooser chooser = new DirectoryChooser();
                chooser.setTitle("Select Output Directory For .STL files");
                chooser.setInitialDirectory(defaultStlDir);
                File baseDirForFiles = chooser.showDialog(BowlerStudioModularFrame.getPrimaryStage());
                new Thread() {

                    public void run() {
                        MobileBaseCadManager baseManager = MobileBaseCadManager.get(device);
                        if (baseDirForFiles == null) {
                            return;
                        }
                        ArrayList<File> files;
                        try {
                            files = baseManager.generateStls((MobileBase) device, baseDirForFiles, false);
                            Platform.runLater(() -> {
                                Alert alert = new Alert(AlertType.INFORMATION);
                                alert.setTitle("Stl Export Success!");
                                alert.setHeaderText("Stl Export Success");
                                alert.setContentText("All SLT's for the Creature Generated at\n" + files.get(0).getAbsolutePath());
                                alert.setWidth(500);
                                alert.initModality(Modality.APPLICATION_MODAL);
                                alert.show();
                            });
                        } catch (Exception e) {
                            BowlerStudioController.highlightException(baseManager.getCadScript(), e);
                        }
                    }
                }.start();
            });
        });
        TreeItem<String> setCAD = new TreeItem<>("Set CAD Engine...", AssetFactory.loadIcon("Set-CAD-Engine.png"));
        callbackMapForTreeitems.put(setCAD, () -> {
            PromptForGit.prompt("Select a CAD Engine From a Gist", device.getGitCadEngine()[0], (gitsId, file) -> {
                Log.warn("Loading cad engine");
                try {
                    creatureLab.setGitCadEngine(gitsId, file, device);
                    File code = ScriptingEngine.fileFromGit(gitsId, file);
                    BowlerStudio.createFileTab(code);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            });
        });
        TreeItem<String> editCAD = new TreeItem<>("Edit CAD Engine...", AssetFactory.loadIcon("Edit-CAD-Engine.png"));
        callbackMapForTreeitems.put(editCAD, () -> {
            try {
                File code = ScriptingEngine.fileFromGit(device.getGitCadEngine()[0], device.getGitCadEngine()[1]);
                BowlerStudio.createFileTab(code);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        TreeItem<String> resetWalking = new TreeItem<>("Set Walking Engine...", AssetFactory.loadIcon("Set-Walking-Engine.png"));
        callbackMapForTreeitems.put(resetWalking, () -> {
            PromptForGit.prompt("Select a Walking Engine From a Gist", device.getGitWalkingEngine()[0], (gitsId, file) -> {
                Log.warn("Loading walking engine");
                try {
                    creatureLab.setGitWalkingEngine(gitsId, file, device);
                    File code = ScriptingEngine.fileFromGit(gitsId, file);
                    BowlerStudio.createFileTab(code);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            });
        });
        TreeItem<String> editWalking = new TreeItem<>("Edit Walking Engine...", AssetFactory.loadIcon("Edit-Walking-Engine.png"));
        callbackMapForTreeitems.put(editWalking, () -> {
            try {
                File code = ScriptingEngine.fileFromGit(device.getGitWalkingEngine()[0], device.getGitWalkingEngine()[1]);
                BowlerStudio.createFileTab(code);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        TreeItem<String> addFixed = new TreeItem<>("Add Fixed Wheel", AssetFactory.loadIcon("Add-Fixed-Wheel.png"));
        callbackMapForTreeitems.put(addFixed, () -> {
            // TODO Auto-generated method stub
            System.out.println("Adding Fixed Wheel");
            try {
                String xmlContent = ScriptingEngine.codeFromGit("https://gist.github.com/b5b9450f869dd0d2ea30.git", "defaultFixed.xml")[0];
                DHParameterKinematics newArm = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8"));
                System.out.println("Arm has " + newArm.getNumberOfLinks() + " links");
                addAppendage(device, view, device.getDrivable(), newArm, drive, rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUserTmp);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        TreeItem<String> addsteerable = new TreeItem<>("Add Steerable Wheel", AssetFactory.loadIcon("Add-Steerable-Wheel.png"));
        callbackMapForTreeitems.put(addsteerable, () -> {
            // TODO Auto-generated method stub
            System.out.println("Adding Steerable Wheel");
            try {
                String xmlContent = ScriptingEngine.codeFromGit("https://gist.github.com/b5b9450f869dd0d2ea30.git", "defaultSteerable.xml")[0];
                DHParameterKinematics newArm = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8"));
                System.out.println("Arm has " + newArm.getNumberOfLinks() + " links");
                addAppendage(device, view, device.getSteerable(), newArm, steer, rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUserTmp);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        TreeItem<String> imuCenter = new TreeItem<>("Imu center", AssetFactory.loadIcon("Advanced-Configuration.png"));
        callbackMapForTreeitems.put(imuCenter, () -> {
            TransformWidget imu = new TransformWidget("IMU center", device.getIMUFromCentroid(), new IOnTransformChange() {

                @Override
                public void onTransformChaging(TransformNR newTrans) {
                }

                @Override
                public void onTransformFinished(TransformNR newTrans) {
                    MobileBaseCadManager manager = MobileBaseCadManager.get(device);
                    if (manager != null)
                        manager.generateCad();
                    device.setIMUFromCentroid(newTrans);
                }
            });
            if (widgetMapForTreeitems.get(imuCenter) == null) {
                widgetMapForTreeitems.put(imuCenter, new Group(imu));
            }
        });
        TreeItem<String> bodymass = new TreeItem<>("Adjust Body Mass", AssetFactory.loadIcon("Advanced-Configuration.png"));
        callbackMapForTreeitems.put(bodymass, () -> {
            if (widgetMapForTreeitems.get(bodymass) == null) {
                widgetMapForTreeitems.put(bodymass, new AdjustbodyMassWidget(device));
            }
        });
        TreeItem<String> addArm = new TreeItem<>("Add Arm", AssetFactory.loadIcon("Add-Arm.png"));
        callbackMapForTreeitems.put(addArm, () -> {
            // TODO Auto-generated method stub
            System.out.println("Adding Arm");
            try {
                String xmlContent = ScriptingEngine.codeFromGit("https://gist.github.com/b5b9450f869dd0d2ea30.git", "defaultarm.xml")[0];
                DHParameterKinematics newArm = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8"));
                System.out.println("Arm has " + newArm.getNumberOfLinks() + " links");
                addAppendage(device, view, device.getAppendages(), newArm, arms, rootItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUserTmp);
            } catch (Exception e) {
                new IssueReportingExceptionHandler().except(e);
            }
        });
        rootItem.getChildren().addAll(bodymass, imuCenter);
        if (root)
            rootItem.getChildren().addAll(physics, regnerate, printable, kinematics);
        rootItem.getChildren().addAll(addArm, addleg, addFixed, addsteerable);
        if (creatureIsOwnedByUser) {
            if (root)
                rootItem.getChildren().addAll(editXml);
            rootItem.getChildren().addAll(editWalking, editCAD, resetWalking, setCAD);
        }
    } catch (Exception e) {
        new IssueReportingExceptionHandler().except(e);
    }
}
Also used : Group(javafx.scene.Group) ParallelGroup(com.neuronrobotics.sdk.addons.kinematics.parallel.ParallelGroup) ArrayList(java.util.ArrayList) TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR) IssueReportingExceptionHandler(com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 2 with IssueReportingExceptionHandler

use of com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler in project BowlerStudio by CommonWealthRobotics.

the class CreatureLab method finishLoading.

private void finishLoading(MobileBase device) {
    TreeView<String> tree = null;
    TreeItem<String> rootItem = null;
    TreeItem<String> mainBase = null;
    int count = 1;
    for (DHParameterKinematics kin : device.getAllDHChains()) {
        for (int i = 0; i < kin.getNumberOfLinks(); i++) {
            DHLink dhLink = kin.getDhLink(i);
            if (dhLink.getSlaveMobileBase() != null) {
                count++;
            }
        }
    }
    try {
        rootItem = new TreeItem<String>("Mobile Bases", AssetFactory.loadIcon("creature.png"));
        mainBase = new TreeItem<String>(device.getScriptingName(), AssetFactory.loadIcon("creature.png"));
    } catch (Exception e) {
        rootItem = new TreeItem<String>(device.getScriptingName());
    }
    if (count == 1) {
        rootItem = mainBase;
    } else {
        rootItem.getChildren().add(mainBase);
    }
    tree = new TreeView<>(rootItem);
    AnchorPane treebox1 = tab.getTreeBox();
    treebox1.getChildren().clear();
    treebox1.getChildren().add(tree);
    AnchorPane.setTopAnchor(tree, 0.0);
    AnchorPane.setLeftAnchor(tree, 0.0);
    AnchorPane.setRightAnchor(tree, 0.0);
    AnchorPane.setBottomAnchor(tree, 0.0);
    HashMap<TreeItem<String>, Runnable> callbackMapForTreeitems = new HashMap<>();
    HashMap<TreeItem<String>, Group> widgetMapForTreeitems = new HashMap<>();
    File source;
    boolean creatureIsOwnedByUser = false;
    try {
        source = ScriptingEngine.fileFromGit(device.getGitSelfSource()[0], device.getGitSelfSource()[1]);
        creatureIsOwnedByUser = ScriptingEngine.checkOwner(source);
    } catch (GitAPIException | IOException e) {
        // TODO Auto-generated catch block
        new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e);
    }
    rootItem.setExpanded(true);
    MobileBaseCadManager.get(device, BowlerStudioController.getMobileBaseUI());
    MobleBaseMenueFactory.load(device, tree, mainBase, callbackMapForTreeitems, widgetMapForTreeitems, this, true, creatureIsOwnedByUser);
    for (DHParameterKinematics kin : device.getAllDHChains()) {
        for (int i = 0; i < kin.getNumberOfLinks(); i++) {
            DHLink dhLink = kin.getDhLink(i);
            String linkName = kin.getLinkConfiguration(i).getName();
            if (dhLink.getSlaveMobileBase() != null) {
                TreeItem<String> mobile = new TreeItem<>(kin.getScriptingName() + " ->\n " + linkName + " link " + i + " ->\n  " + dhLink.getSlaveMobileBase().getScriptingName(), AssetFactory.loadIcon("creature.png"));
                MobleBaseMenueFactory.load(dhLink.getSlaveMobileBase(), tree, mobile, callbackMapForTreeitems, widgetMapForTreeitems, this, false, creatureIsOwnedByUser);
                rootItem.getChildren().add(mobile);
            }
        }
    }
    tree.setPrefWidth(325);
    tree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    JogMobileBase walkWidget = new JogMobileBase(device);
    tree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {

        @Override
        public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) {
            @SuppressWarnings("unchecked") TreeItem<String> treeItem = (TreeItem<String>) newValue;
            new Thread() {

                public void run() {
                    if (callbackMapForTreeitems.get(treeItem) != null) {
                        callbackMapForTreeitems.get(treeItem).run();
                    }
                    if (widgetMapForTreeitems.get(treeItem) != null) {
                        Platform.runLater(() -> {
                            tab.getControlsBox().getChildren().clear();
                            Group g = widgetMapForTreeitems.get(treeItem);
                            tab.getControlsBox().getChildren().add(g);
                            AnchorPane.setTopAnchor(g, 0.0);
                            AnchorPane.setLeftAnchor(g, 0.0);
                            AnchorPane.setRightAnchor(g, 0.0);
                            AnchorPane.setBottomAnchor(g, 0.0);
                        });
                    } else {
                        Platform.runLater(() -> {
                            tab.getControlsBox().getChildren().clear();
                        });
                    }
                }
            }.start();
        }
    });
    VBox progress = new VBox(10);
    final ToggleGroup group = new ToggleGroup();
    RadioButton rb1 = new RadioButton();
    rb1.setToggleGroup(group);
    rb1.setSelected(true);
    rb1.setOnAction(event -> {
        setCadMode(false);
    });
    RadioButton rb2 = new RadioButton();
    rb2.setToggleGroup(group);
    rb2.fire();
    rb2.setOnAction(event -> {
        setCadMode(true);
    });
    HBox radioOptions = new HBox(10);
    radioOptions.getChildren().addAll(new Label("Cad"), rb1, rb2, new Label("Config"));
    pi = new ProgressIndicator(0);
    baseManager = MobileBaseCadManager.get(device, BowlerStudioController.getMobileBaseUI());
    pi.progressProperty().bindBidirectional(baseManager.getProcesIndictor());
    HBox progressIndicatorPanel = new HBox(10);
    progressIndicatorPanel.getChildren().addAll(new Label("Cad Progress:"), pi);
    progress.getChildren().addAll(progressIndicatorPanel, autoRegen, radioOptions);
    progress.setStyle("-fx-background-color: #FFFFFF;");
    progress.setOpacity(.7);
    progress.setMinHeight(100);
    progress.setPrefSize(325, 150);
    tab.setOverlayTop(progress);
    tab.setOverlayTopRight(walkWidget);
    BowlerStudioModularFrame.getBowlerStudioModularFrame().showCreatureLab();
    // start the UI in config mode
    setCadMode(true);
    generateCad();
    setContent(root);
}
Also used : Group(javafx.scene.Group) HBox(javafx.scene.layout.HBox) HashMap(java.util.HashMap) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) AnchorPane(javafx.scene.layout.AnchorPane) IOException(java.io.IOException) IssueReportingExceptionHandler(com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException) DHLink(com.neuronrobotics.sdk.addons.kinematics.DHLink) DHParameterKinematics(com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics) File(java.io.File) VBox(javafx.scene.layout.VBox)

Example 3 with IssueReportingExceptionHandler

use of com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler in project BowlerStudio by CommonWealthRobotics.

the class CommitWidget method commit.

public static void commit(File currentFile, String code) {
    if (code.length() < 1) {
        Log.error("COmmit failed with no code to commit");
        return;
    }
    Platform.runLater(() -> {
        // Create the custom dialog.
        Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle("Commit message Dialog");
        dialog.setHeaderText("Enter a commit message to publish changes");
        // Set the button types.
        ButtonType loginButtonType = new ButtonType("Publish", ButtonData.OK_DONE);
        dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
        // Create the username and password labels and fields.
        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(20, 150, 10, 10));
        TextField username = new TextField();
        username.setPromptText("60 character description");
        TextArea password = new TextArea();
        password.setPrefRowCount(5);
        password.setPrefColumnCount(40);
        password.setPromptText("Full Sentences describing explanation");
        grid.add(new Label("What did you change?"), 0, 0);
        grid.add(username, 1, 0);
        grid.add(new Label("Why did you change it?"), 0, 1);
        grid.add(password, 1, 1);
        // Enable/Disable login button depending on whether a username was entered.
        Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
        loginButton.setDisable(true);
        // Do some validation (using the Java 8 lambda syntax).
        username.textProperty().addListener((observable, oldValue, newValue) -> {
            loginButton.setDisable(newValue.trim().length() < 5);
        });
        dialog.getDialogPane().setContent(grid);
        // Request focus on the username field by default.
        Platform.runLater(() -> username.requestFocus());
        // Convert the result to a username-password-pair when the login button is clicked.
        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == loginButtonType) {
                return new Pair<>(username.getText(), password.getText());
            }
            return null;
        });
        Optional<Pair<String, String>> result = dialog.showAndWait();
        result.ifPresent(commitBody -> {
            new Thread() {

                public void run() {
                    Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
                    String message = commitBody.getKey() + "\n\n" + commitBody.getValue();
                    Git git;
                    try {
                        git = ScriptingEngine.locateGit(currentFile);
                        String remote = git.getRepository().getConfig().getString("remote", "origin", "url");
                        ScriptingEngine.pull(remote);
                        String relativePath = ScriptingEngine.findLocalPath(currentFile, git);
                        ScriptingEngine.closeGit(git);
                        ScriptingEngine.pushCodeToGit(remote, ScriptingEngine.getFullBranch(remote), relativePath, code, message);
                    } catch (Exception e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            }.start();
        });
    });
}
Also used : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) TextArea(javafx.scene.control.TextArea) Node(javafx.scene.Node) Label(javafx.scene.control.Label) IssueReportingExceptionHandler(com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler) Git(org.eclipse.jgit.api.Git) Dialog(javafx.scene.control.Dialog) TextField(javafx.scene.control.TextField) ButtonType(javafx.scene.control.ButtonType) Pair(javafx.util.Pair)

Example 4 with IssueReportingExceptionHandler

use of com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler in project bowler-script-kernel by CommonWealthRobotics.

the class Vitamins method saveDatabaseForkIfMissing.

public static void saveDatabaseForkIfMissing(String type) throws Exception {
    org.kohsuke.github.GitHub github = PasswordManager.getGithub();
    GHRepository repo = github.getRepository("madhephaestus/Hardware-Dimensions");
    try {
        saveDatabase(type);
    } catch (org.eclipse.jgit.api.errors.TransportException ex) {
        GHRepository newRepo = repo.fork();
        Vitamins.gitRpoDatabase = newRepo.getGitTransportUrl().replaceAll("git://", "https://");
        saveDatabase(type);
    }
    if (PasswordManager.getUsername().contentEquals("madhephaestus"))
        return;
    try {
        GHRepository myrepo = github.getRepository(PasswordManager.getUsername() + "/Hardware-Dimensions");
        List<GHPullRequest> asList1 = myrepo.queryPullRequests().state(GHIssueState.OPEN).head("madhephaestus:master").list().asList();
        // Some asynchronus delay here, not sure why...
        Thread.sleep(200);
        if (asList1.size() == 0) {
            try {
                GHPullRequest request = myrepo.createPullRequest("Update from source", "madhephaestus:master", "master", "## Upstream add vitamins", false, false);
                if (request != null) {
                    processSelfPR(request);
                }
            } catch (org.kohsuke.github.HttpException ex) {
            // no commits have been made to master
            }
        } else {
            processSelfPR(asList1.get(0));
        }
        String head = PasswordManager.getUsername() + ":master";
        List<GHPullRequest> asList = repo.queryPullRequests().state(GHIssueState.OPEN).head(head).list().asList();
        if (asList.size() == 0) {
            System.err.println("Creating PR for " + head);
            GHPullRequest request = repo.createPullRequest("User Added vitamins to " + type, head, "master", "## User added vitamins", true, true);
            try {
                BowlerKernel.upenURL(request.getHtmlUrl().toURI());
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
        }
    } catch (Exception ex) {
        new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), ex);
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) URISyntaxException(java.net.URISyntaxException) IssueReportingExceptionHandler(com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler) URISyntaxException(java.net.URISyntaxException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException) TransportException(org.eclipse.jgit.api.errors.TransportException) GHPullRequest(org.kohsuke.github.GHPullRequest)

Example 5 with IssueReportingExceptionHandler

use of com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler in project bowler-script-kernel by CommonWealthRobotics.

the class Vitamins method getGitRepoDatabase.

// @Deprecated
// public static String getGitRpoDatabase() throws IOException {
// return getGitRepoDatabase();
// }
// @Deprecated
// public static void setGitRpoDatabase(String gitRpoDatabase) {
// setGitRepoDatabase(gitRpoDatabase);
// }
// 
public static String getGitRepoDatabase() {
    if (!checked) {
        checked = true;
        try {
            if (PasswordManager.getUsername() != null) {
                ScriptingEngine.setAutoupdate(true);
                org.kohsuke.github.GitHub github = PasswordManager.getGithub();
                try {
                    GHRepository repo = github.getRepository(PasswordManager.getLoginID() + "/Hardware-Dimensions");
                    if (repo != null) {
                        String myAssets = repo.getGitTransportUrl().replaceAll("git://", "https://");
                        // System.out.println("Using my version of Viamins: "+myAssets);
                        setGitRepoDatabase(myAssets);
                    } else {
                        throw new org.kohsuke.github.GHFileNotFoundException();
                    }
                } catch (org.kohsuke.github.GHFileNotFoundException ex) {
                    setGitRepoDatabase(defaultgitRpoDatabase);
                }
            }
        } catch (Exception ex) {
            new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), ex);
        }
        ScriptingEngine.cloneRepo(gitRpoDatabase, "master");
    }
    return gitRpoDatabase;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) IssueReportingExceptionHandler(com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler) URISyntaxException(java.net.URISyntaxException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException)

Aggregations

IssueReportingExceptionHandler (com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler)6 IOException (java.io.IOException)5 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)5 InvalidRemoteException (org.eclipse.jgit.api.errors.InvalidRemoteException)5 TransportException (org.eclipse.jgit.api.errors.TransportException)5 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 Group (javafx.scene.Group)2 GHRepository (org.kohsuke.github.GHRepository)2 DHLink (com.neuronrobotics.sdk.addons.kinematics.DHLink)1 MobileBase (com.neuronrobotics.sdk.addons.kinematics.MobileBase)1 TransformNR (com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)1 ParallelGroup (com.neuronrobotics.sdk.addons.kinematics.parallel.ParallelGroup)1 CSG (eu.mihosoft.vrl.v3d.CSG)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Insets (javafx.geometry.Insets)1 Node (javafx.scene.Node)1 ButtonType (javafx.scene.control.ButtonType)1