Skip to content
Open
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
63 changes: 63 additions & 0 deletions gui/src/main/java/com/devonfw/ide/gui/CommandletController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.devonfw.ide.gui;

import java.util.List;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;

import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.Property;

public class CommandletController {

private Commandlet selectedCommandlet;
private final IdeContext context;

@FXML
private ComboBox<String> commandletSelector;
@FXML
private TextField parameterField;
@FXML
private Button runButton;

public CommandletController(IdeContext context) {
this.context = context;
}

@FXML
private void initialize() {
Platform.runLater(this::populateCommandletList);
}

private void populateCommandletList() {
commandletSelector.getItems().clear();
commandletSelector.getItems().addAll(context.getCommandletManager().getCommandlets().stream()
.map(Commandlet::getName)
.toList());
}

@FXML
private void runCommandlet() {
String name = commandletSelector.getValue();
if (name == null) {
return;
}

Commandlet commandlet = context.getCommandletManager().getCommandlet(name);

String input = parameterField.getText();
String[] tokens = input.split("\\s+");

List<Property<?>> values = commandlet.getValues();

for (int i = 0; i < tokens.length && (i + 1) < values.size(); i++) {
values.get(i + 1).setValueAsString(tokens[i], context);
}

commandlet.run();
}
}
28 changes: 28 additions & 0 deletions gui/src/main/java/com/devonfw/ide/gui/MainController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.devonfw.ide.gui;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.NotDirectoryException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.stage.Stage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -49,6 +55,9 @@ public class MainController {
@FXML
private Button vsCodeOpen;

@FXML
private Button commandletOpen;

private final String directoryPath;

private final Map<String, Locale> languageMap;
Expand Down Expand Up @@ -185,6 +194,8 @@ private void setWorkspaceComboBox() {
eclipseOpen.setDisable(false);
intellijOpen.setDisable(false);
vsCodeOpen.setDisable(false);
vsCodeOpen.setDisable(false);
commandletOpen.setDisable(false);
});
}

Expand All @@ -206,4 +217,21 @@ private void updateContext(String selectedProjectName, String selectedWorkspaceN
errorDialog.showAndWait();
}
}

@FXML
private void openCommandlet() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("commandlet-view.fxml"));
loader.setResources(this.nlsService.getResourceBundle());
loader.setController(new CommandletController(IdeGuiStateManager.getInstance().getCurrentContext()));
Parent root = loader.load();

Stage stage = (Stage) selectedProject.getScene().getWindow();
stage.setScene(new Scene(root));
} catch (IOException e) {
LOG.error("Failed to load commandlet view", e);
new IdeDialog(IdeDialog.AlertType.ERROR, e.getMessage()).showAndWait();
}
}

}
53 changes: 53 additions & 0 deletions gui/src/main/resources/com/devonfw/ide/gui/commandlet-view.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?>
<BorderPane fx:id="rootPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
prefHeight="515.0" prefWidth="817.0"
xmlns="http://javafx.com/javafx/25.0.0"
xmlns:fx="http://javafx.com/fxml/1">
<center>
<StackPane prefHeight="150.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<ComboBox fx:id="commandletSelector" prefWidth="600.0">
<VBox.margin>
<Insets left="10.0" top="10.0"/>
</VBox.margin>
</ComboBox>
<TextField fx:id="parameterField">
<VBox.margin>
<Insets left="10.0" right="10.0" top="50.0"/>
</VBox.margin>
</TextField>
<Button fx:id="runButton" alignment="BOTTOM_RIGHT" contentDisplay="BOTTOM" mnemonicParsing="false" onAction="#runCommandlet" text="Run"/>
</children>
</VBox>
</children>
</StackPane>
</center>
<left>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<HBox alignment="CENTER_LEFT" prefWidth="200.0">
<VBox.margin>
<Insets bottom="10.0"/>
</VBox.margin>
<children>
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@assets/logo.png"/>
</image>
</ImageView>
</children>
</HBox>
</children>
</VBox>
</left>
</BorderPane>
1 change: 1 addition & 0 deletions gui/src/main/resources/com/devonfw/ide/gui/main-view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
</children>
</HBox>
</children>
<Button fx:id="commandletOpen" disable="true" text="Commandlets" onAction="#openCommandlet"/>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
Expand Down
Loading