Skip to content

Commit

Permalink
devonfw#1454 implemented installTemplateSet button functionality
Browse files Browse the repository at this point in the history
removed temporary template-set folder
observable list is loaded from cobigen home folder
  • Loading branch information
Ali7223 committed Jan 5, 2023
1 parent f12ac48 commit 9c2e04e
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 223 deletions.
7 changes: 7 additions & 0 deletions cobigen/gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
<artifactId>core-artifact-retriever</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>core</artifactId>
<version>${revision}</version>
</dependency>


</dependencies>
<build>
<plugins>
Expand Down
1 change: 0 additions & 1 deletion cobigen/gui/src/main/java/com/devonfw/cobigen/gui/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public void start(Stage primaryStage) throws IOException {
this.window = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("fxml/Primary.fxml"));

System.out.println(1);
App.scene = new Scene(root);
App.scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
* Controller for the Template Set Management GUI
*/
public class Controller implements Initializable {

/*
* home Controller to show home page
*/
@FXML
private Parent home;

/*
* Details Controller for template set details
*/
@FXML
private Parent details;

Expand All @@ -42,6 +47,7 @@ public class Controller implements Initializable {
@FXML
public DetailsController detailsController;

// deals with menu.fxml
@FXML
private AnchorPane leftPane;

Expand All @@ -54,6 +60,7 @@ public class Controller implements Initializable {
@FXML
private AnchorPane detailsPane;

// top bit of the gui
@FXML
private Pane topPane;

Expand Down Expand Up @@ -101,14 +108,18 @@ public void loadDetails() throws IOException {

// selected from observable list
TemplateSet selectedItem = this.menuController.searchResultsView.getSelectionModel().getSelectedItem();
// changing visibility between scenes
if (selectedItem == null) {
this.home.setVisible(true);
this.details.setVisible(false);
} else {
this.home.setVisible(false);
this.details.setVisible(true);

// Getting the tree view of increments of selected template set

// Extract all increments from selected templateSet in list
// should not happen here
List<TemplateSetIncrement> templatesetIncrements = selectedItem.getTemplateSetConfiguration()
.getTemplatesConfiguration().getIncrements().getIncrementList();

Expand All @@ -120,6 +131,11 @@ public void loadDetails() throws IOException {

// TODO
this.detailsController.showName(selectedItem.getTemplateSetVersion());

// retrieving template-Set selected and pass it to details Controller
this.detailsController
.setTemplateSet(this.menuController.searchResultsView.getSelectionModel().getSelectedItem());

}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.devonfw.cobigen.gui.controllers;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import com.devonfw.cobigen.api.util.CobiGenPaths;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TreeView;
Expand All @@ -22,6 +31,8 @@ public class DetailsController implements Initializable {
// TODO: getIncrements()
private List<String> INCREMENTS = new ArrayList<>();

private TemplateSet templateSet;

@FXML
Label titleLabel;

Expand All @@ -46,6 +57,26 @@ public void initialize(URL location, ResourceBundle resources) {

}

/**
* returns an instance of selected template Set to be operated on
*
* @return templateSet
*/
public TemplateSet getTemplateSet() {

return this.templateSet;
}

/**
* Set the instance of selected template Set
*
* @param templateSet new value of {@link #gettemplateSet}.
*/
public void setTemplateSet(TemplateSet templateSet) {

this.templateSet = templateSet;
}

/**
*
*/
Expand Down Expand Up @@ -80,12 +111,30 @@ public void showTreeView(TreeView<String> treeView) {

/**
* @param actionEvent
* @throws IOException
*/
@FXML
public void installTemplateSet(javafx.event.ActionEvent actionEvent) {

// What does it exactly mean by installing and where
// TODO
public void installTemplateSet(javafx.event.ActionEvent actionEvent) throws IOException {

// Retrieving trigger information and move the template set file to user folder
String triggerName = this.templateSet.getTemplateSetConfiguration().getContextConfiguration().getTriggers().getId();
String FileName = triggerName.replace("_", "-") + "-" + this.templateSet.getTemplateSetVersion()
+ "-template-set.xml";
Path cobigenHome = CobiGenPaths.getCobiGenHomePath();
Path sourceFilePath = cobigenHome.resolve("template-set-list").resolve(FileName);
String destinationPath = "C:\\Users\\alsaad\\template-set-installed\\" + FileName;
Path destinationFilePath = Paths.get(destinationPath);
if (!Files.exists(destinationFilePath)) {
Files.copy(sourceFilePath, destinationFilePath);
System.out.println(sourceFilePath.toString());
System.out.println(destinationFilePath);
} else {
// Alert window if the file is already installed
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirmation");
alert.setHeaderText("the selected template-set is already installed");
alert.show();
}
}

/**
Expand All @@ -95,6 +144,7 @@ public void installTemplateSet(javafx.event.ActionEvent actionEvent) {
public void updateTemplateSet(javafx.event.ActionEvent actionEvent) {

// what model is previous and whats the new one
// new version rein packen

// TODO
}
Expand All @@ -106,6 +156,7 @@ public void updateTemplateSet(javafx.event.ActionEvent actionEvent) {
public void uninstallTemplateSet(javafx.event.ActionEvent actionEvent) {

// what is referred to by the word uninstall.
// Delete template set from user ordenr

// TODO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import java.util.ResourceBundle;

import com.devonfw.cobigen.gui.Controller;
import com.devonfw.cobigen.gui.model.ModifyableTemplateSet;
import com.devonfw.cobigen.gui.model.TemplateSetModel;
import com.devonfw.cobigen.gui.services.TemplateSetCell;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;

import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;

/**
* TODO nneuhaus This type ...
Expand All @@ -41,16 +39,15 @@ public class MenuController implements Initializable {
public Button goSearch;

@FXML
public ListView<ModifyableTemplateSet> searchResultsView;

private TemplateSetModel tsModel = new TemplateSetModel();
public ListView<TemplateSet> searchResultsView;

/**
* The constructor.
*/
public MenuController() {

this.tsModel.loadallAvaliableTemplateSets();
TemplateSetModel.getInstance().loadallAvaliableTemplateSets();
// Where do we need tags
// List<TemplateSetTag> tagsList = new ArrayList<>();
// tagsList.addAll(templateSet.getTemplateSetConfiguration().getContextConfiguration().getTags().getTagsList());
}
Expand All @@ -69,10 +66,9 @@ public void injectController(Controller controller) {
@Override
public void initialize(URL location, ResourceBundle resources) {

// the line sets up the template cells in observable list
// the line below sets up the template set cells in observable list
this.searchResultsView.setCellFactory(resultsView -> new TemplateSetCell());

// home button brings back the previous state
this.homeButton.setOnAction(event -> {
try {
this.controller.loadHome(event);
Expand All @@ -82,29 +78,27 @@ public void initialize(URL location, ResourceBundle resources) {
});

// binds the List with model
this.searchResultsView.setItems(this.tsModel.getTemplateSetObservableList());
this.searchResultsView.setItems(TemplateSetModel.getInstance().getTemplateSetObservableList());

// Load increments of selected template set
this.searchResultsView.setOnMouseClicked(new EventHandler<MouseEvent>() {

@Override
public void handle(MouseEvent event) {
// call back functions
this.searchResultsView.setOnMouseClicked(event -> {

try {
MenuController.this.controller.loadDetails();
} catch (IOException e) {
e.printStackTrace();
}
try {
MenuController.this.controller.loadDetails();
} catch (IOException e) {
e.printStackTrace();
}

});

// Initialize filtered List

ObservableList<ModifyableTemplateSet> listCopy = this.tsModel.getTemplateSetObservableList();
FilteredList<ModifyableTemplateSet> filteredData = new FilteredList<>(this.tsModel.getTemplateSetObservableList(),
b -> true);
ObservableList<TemplateSet> listCopy = TemplateSetModel.getInstance().getTemplateSetObservableList();
FilteredList<TemplateSet> filteredData = new FilteredList<>(
TemplateSetModel.getInstance().getTemplateSetObservableList(), b -> true);

// no idea what it does
// look after the searched text in search bar
this.searchBar.textProperty().addListener((observable, oldValue, newValue) -> {
filteredData.setPredicate(templateSets -> {
// if no search value, then display all records or whatever records it currently has, no changes
Expand Down

This file was deleted.

Loading

0 comments on commit 9c2e04e

Please sign in to comment.