Skip to content

Commit

Permalink
devonfw#1454 replaced ArtifactReader with TemplateSetReader
Browse files Browse the repository at this point in the history
added new constructor to TemplateSetConfiguration (used for empty reader initialization)
removed temporary initialzation of HomeController (needs to be replaced with core template set reader)
simplified buildTreeView method in TreeViewBuilder
replaced all template-set.xml files with a valid version (added increments)
  • Loading branch information
jan-vcapgemini committed Mar 14, 2023
1 parent 5140c84 commit b871dba
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public TemplatesConfiguration getTemplatesConfiguration() {
// TODO: Use dependency injection here instead of the new operator
private final TemplateSetConfigurationManager templateSetConfigurationManager = new TemplateSetConfigurationManager();

/**
*
* The constructor for the artifact reader.
*/
public TemplateSetConfigurationReader() {

this.configRoot = null;
}

/**
* The constructor.
*
Expand Down
17 changes: 6 additions & 11 deletions cobigen/gui/src/main/java/com/devonfw/cobigen/gui/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.devonfw.cobigen.gui.controllers.HomeController;
import com.devonfw.cobigen.gui.controllers.MenuController;
import com.devonfw.cobigen.gui.services.TreeViewBuilder;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSetIncrement;
import com.devonfw.cobigen.impl.config.entity.io.Increment;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void loadHome(javafx.event.ActionEvent actionEvent) throws IOException {
public void loadDetails() throws IOException {

// selected from observable list
TemplateSet selectedItem = this.menuController.searchResultsView.getSelectionModel().getSelectedItem();
TemplateSetConfiguration selectedItem = this.menuController.searchResultsView.getSelectionModel().getSelectedItem();
// changing visibility between scenes
if (selectedItem == null) {
this.home.setVisible(true);
Expand All @@ -119,18 +119,13 @@ public void loadDetails() throws IOException {
// 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();

// icnrements converted to strings to make it ready for tree view builder
String[] increments = TreeViewBuilder.transformIncrementsToArray(templatesetIncrements);
List<Increment> templatesetIncrements = selectedItem.getTemplatesConfiguration().getIncrements().getIncrement();

// shows the tree view of increments of selected template set
this.detailsController.showTreeView(TreeViewBuilder.buildTreeView(increments));
this.detailsController.showTreeView(TreeViewBuilder.buildTreeView(templatesetIncrements));

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

// retrieving template-Set selected and pass it to details Controller
this.detailsController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.devonfw.cobigen.api.util.CobiGenPaths;
import com.devonfw.cobigen.api.util.MavenCoordinate;
import com.devonfw.cobigen.api.util.TemplatesJarUtil;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;
import com.devonfw.cobigen.retriever.ArtifactRetriever;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
Expand All @@ -38,7 +38,7 @@ public class DetailsController implements Initializable {
// TODO: getIncrements()
private List<String> INCREMENTS = new ArrayList<>();

private TemplateSet templateSet;
private TemplateSetConfiguration templateSet;

@FXML
Label titleLabel;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void updateTemplateSetInstallStatus() {
*
* @return templateSet
*/
public TemplateSet getTemplateSet() {
public TemplateSetConfiguration getTemplateSet() {

return this.templateSet;
}
Expand All @@ -90,7 +90,7 @@ public TemplateSet getTemplateSet() {
*
* @param templateSet new value of {@link #gettemplateSet}.
*/
public void setTemplateSet(TemplateSet templateSet) {
public void setTemplateSet(TemplateSetConfiguration templateSet) {

this.templateSet = templateSet;
}
Expand Down Expand Up @@ -135,9 +135,9 @@ public void showTreeView(TreeView<String> treeView) {
private Path retrieveJarPathFromTemplateSet() {

// Retrieve template set name information from trigger
String triggerName = this.templateSet.getTemplateSetConfiguration().getContextConfiguration().getTriggers().getId();
String triggerName = this.templateSet.getContextConfiguration().getTrigger().get(0).getId();
String mavenArtfifactId = triggerName.replace("_", "-");
String templateSetVersion = this.templateSet.getTemplateSetVersion();
String templateSetVersion = this.templateSet.getVersion().toString();
Path templateSetsPath = CobiGenPaths.getTemplateSetsFolderPath();

// Adjust file name
Expand All @@ -156,9 +156,9 @@ private Path retrieveJarPathFromTemplateSet() {
public void installTemplateSet(javafx.event.ActionEvent actionEvent) {

// Retrieve template set name information from trigger
String triggerName = this.templateSet.getTemplateSetConfiguration().getContextConfiguration().getTriggers().getId();
String triggerName = this.templateSet.getContextConfiguration().getTrigger().get(0).getId();
String mavenArtfifactId = triggerName.replace("_", "-");
String templateSetVersion = this.templateSet.getTemplateSetVersion();
String templateSetVersion = this.templateSet.getVersion().toString();

// Adjust file name
String FileName = mavenArtfifactId + "-" + templateSetVersion + ".jar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import java.util.ResourceBundle;

import com.devonfw.cobigen.gui.App;
import com.devonfw.cobigen.gui.services.TreeViewBuilder;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.MenuButton;
import javafx.scene.control.TreeView;
import javafx.scene.layout.AnchorPane;

/**
Expand Down Expand Up @@ -42,14 +40,23 @@ public class HomeController implements Initializable {
@Override
public void initialize(URL location, ResourceBundle resources) {

// Build the tree view
TreeView<String> treeView = TreeViewBuilder.buildTreeView(this.EXAMPLE_LIST);
treeView.setId("treeView");
AnchorPane.setTopAnchor(treeView, 0.0);
AnchorPane.setRightAnchor(treeView, 0.0);
AnchorPane.setBottomAnchor(treeView, 0.0);
AnchorPane.setLeftAnchor(treeView, 0.0);
this.treeViewPane.getChildren().add(treeView);
// Increment increment1 = new Increment();
// increment1.setName("Title of Increment 1");
// increment1.setDescription("Description of Increment 1");
// Increment increment2 = new Increment();
// increment2.setName("Title of Increment 2");
// increment2.setDescription("Description of Increment 2");
// Increment increment3 = new Increment();
// increment3.setName("Title of Increment 3");
// increment3.setDescription("Description of Increment 3");
// // Build the tree view
// TreeView<String> treeView = TreeViewBuilder.buildTreeView(this.EXAMPLE_LIST);
// treeView.setId("treeView");
// AnchorPane.setTopAnchor(treeView, 0.0);
// AnchorPane.setRightAnchor(treeView, 0.0);
// AnchorPane.setBottomAnchor(treeView, 0.0);
// AnchorPane.setLeftAnchor(treeView, 0.0);
// this.treeViewPane.getChildren().add(treeView);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.devonfw.cobigen.gui.Controller;
import com.devonfw.cobigen.gui.model.TemplateSetModel;
import com.devonfw.cobigen.gui.services.TemplateSetCell;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;

import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class MenuController implements Initializable {
public Button goSearch;

@FXML
public ListView<TemplateSet> searchResultsView;
public ListView<TemplateSetConfiguration> searchResultsView;

/**
* The constructor.
Expand Down Expand Up @@ -94,8 +94,8 @@ public void initialize(URL location, ResourceBundle resources) {

// Initialize filtered List

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

// look after the searched text in search bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import java.util.List;

import com.devonfw.cobigen.api.util.CobiGenPaths;
import com.devonfw.cobigen.retriever.ArtifactRetriever;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand All @@ -20,7 +19,7 @@
public class TemplateSetModel {
private static TemplateSetModel tsModel;

private final ObservableList<TemplateSet> templateSetObservableList;
private final ObservableList<TemplateSetConfiguration> templateSetObservableList;

private TemplateSetModel() {

Expand All @@ -40,7 +39,7 @@ public static TemplateSetModel getInstance() {
/**
* @return templateSetObservableList
*/
public ObservableList<TemplateSet> getTemplateSetObservableList() {
public ObservableList<TemplateSetConfiguration> getTemplateSetObservableList() {

return this.templateSetObservableList;
}
Expand All @@ -56,9 +55,10 @@ public void loadAllAvailableTemplateSets() {
templateSetFiles.add(Paths.get(file.getPath()));
}

List<TemplateSet> templateSets = ArtifactRetriever.retrieveTemplateSetData(templateSetFiles);
// List<com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration> templateSets = ArtifactRetriever
// .retrieveTemplateSetData(templateSetFiles);

this.templateSetObservableList.addAll(templateSets);
// this.templateSetObservableList.addAll(templateSets);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.IOException;

import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
Expand All @@ -15,7 +15,7 @@
* TODO nneuhaus This type ...
*
*/
public class TemplateSetCell extends ListCell<TemplateSet> {
public class TemplateSetCell extends ListCell<TemplateSetConfiguration> {

FXMLLoader loader;

Expand All @@ -30,7 +30,7 @@ public class TemplateSetCell extends ListCell<TemplateSet> {

// when this method suppose to be called
@Override
protected void updateItem(TemplateSet templateSet, boolean empty) {
protected void updateItem(TemplateSetConfiguration templateSet, boolean empty) {

super.updateItem(templateSet, empty);
if (empty || templateSet == null) {
Expand All @@ -50,8 +50,7 @@ protected void updateItem(TemplateSet templateSet, boolean empty) {
}
}
// name of template set. should not happen here
this.titleLabel
.setText(templateSet.getTemplateSetConfiguration().getContextConfiguration().getTriggers().getId());
this.titleLabel.setText(templateSet.getContextConfiguration().getTrigger().get(0).getId());
this.installButton.setOnAction(event -> {
System.out.println("INSTALLIEREN!!!");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.devonfw.cobigen.gui.services;

import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;

import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
Expand All @@ -10,10 +10,11 @@
* TODO nneuhaus This type ...
*
*/
public class TemplateSetCellFactory implements Callback<ListView<TemplateSet>, ListCell<TemplateSet>> {
public class TemplateSetCellFactory
implements Callback<ListView<TemplateSetConfiguration>, ListCell<TemplateSetConfiguration>> {

@Override
public ListCell<TemplateSet> call(ListView<TemplateSet> param) {
public ListCell<TemplateSetConfiguration> call(ListView<TemplateSetConfiguration> param) {

return new TemplateSetCell();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.devonfw.cobigen.retriever.reader.to.model.TemplateSetIncrement;
import com.devonfw.cobigen.impl.config.entity.io.Increment;

import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
Expand All @@ -13,37 +13,18 @@
*/
public class TreeViewBuilder {

/**
* Extract template set increments detail
*
* @param templateSetIncrements
* @return the string array of increment descriptions
*/
public static String[] transformIncrementsToArray(List<TemplateSetIncrement> templateSetIncrements) {

String[] incrementsWithDescriptions = new String[templateSetIncrements.size() * 2];

for (int i = 0, j = 0; i < templateSetIncrements.size(); i++) {
incrementsWithDescriptions[j++] = templateSetIncrements.get(i).getName();

incrementsWithDescriptions[j++] = templateSetIncrements.get(i).getDescription();
}
return incrementsWithDescriptions;
}

/**
* @param arrayOfItems to transform to tree
* @return the complete TreeView
*/
public static TreeView<String> buildTreeView(String[] arrayOfItems) {
public static TreeView<String> buildTreeView(List<Increment> arrayOfItems) {

TreeItem<String> rootItem = new TreeItem<>("Increments");
rootItem.setExpanded(true);

for (int i = 0; i < arrayOfItems.length; i++) {
TreeItem<String> increment = new TreeItem<>(arrayOfItems[i]);
i++;
TreeItem<String> incrementDescription = new TreeItem<>(arrayOfItems[i]);
for (Increment i : arrayOfItems) {
TreeItem<String> increment = new TreeItem<>(i.getName());
TreeItem<String> incrementDescription = new TreeItem<>(i.getDescription());
increment.getChildren().add(incrementDescription);
rootItem.getChildren().add(increment);
}
Expand Down
Loading

0 comments on commit b871dba

Please sign in to comment.