remove usage of vaadin table => grid instead

This commit is contained in:
Nicolas Héron 2018-12-14 11:04:34 +01:00
commit 0c2762bc2c
4 changed files with 63 additions and 83 deletions

View file

@ -95,6 +95,7 @@
<artifactId>vaadin-push</artifactId> <artifactId>vaadin-push</artifactId>
<version>7.7.6</version> <version>7.7.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>
@ -121,16 +122,6 @@
<artifactId>jackson-annotations</artifactId> <artifactId>jackson-annotations</artifactId>
<version>2.9.4</version> <version>2.9.4</version>
</dependency> </dependency>
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>exporter</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>excelimporttable</artifactId>
<version>1.1.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId> <groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId> <artifactId>jackson-dataformat-xml</artifactId>

View file

@ -58,9 +58,9 @@ public class DroolsAdminConsoleMainView extends UI {
MenuBar.MenuItem submenuAsset = menuBar.addItem("Asset", null); MenuBar.MenuItem submenuAsset = menuBar.addItem("Asset", null);
subMenuDeployment.addItem("Option 2", null); // subMenuDeployment.addItem("Option 2", null);
submenuAsset.addItem("Option 4", null); //submenuAsset.addItem("Option 4", null);
subMenuDeployment.addItem("Deploy", (MenuBar.Command) menuItem -> { subMenuDeployment.addItem("Deploy", (MenuBar.Command) menuItem -> {
navigator.navigateTo("Deployment"); navigator.navigateTo("Deployment");

View file

@ -6,8 +6,8 @@ import com.vaadin.data.Item;
import com.vaadin.navigator.View; import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener; import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
import org.chtijbug.drools.console.AddLog; import org.chtijbug.drools.console.AddLog;
import org.chtijbug.drools.console.service.KieRepositoryService; import org.chtijbug.drools.console.service.KieRepositoryService;
@ -18,8 +18,6 @@ import org.chtijbug.guvnor.server.jaxrs.jaxb.Asset;
import org.drools.workbench.models.datamodel.rule.InterpolationVariable; import org.drools.workbench.models.datamodel.rule.InterpolationVariable;
import org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl; import org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl;
import org.drools.workbench.models.guided.template.shared.TemplateModel; import org.drools.workbench.models.guided.template.shared.TemplateModel;
import org.vaadin.haijian.ExcelExporter;
import org.vaadin.winnid.excelimporttable.ExcelImportTable;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
@ -36,12 +34,11 @@ public class AssetEditView extends VerticalLayout implements AddLog, View {
private XmlMapper mapper = new XmlMapper(); private XmlMapper mapper = new XmlMapper();
private String spaceName; private String spaceName;
private String projectName; private String projectName;
private Table assetTable; private Grid gridAssetTable;
private Button startUpdate; private Button startUpdate;
private Button commitUpdate; private Button commitUpdate;
private Button undoUpdate; private Button undoUpdate;
private ExcelExporter excelExporter;
private ExcelImportTable excelImportTable;
public AssetEditView(UserConnected userConnected, String spaceName, String projectName, Asset assetToUpdate) { public AssetEditView(UserConnected userConnected, String spaceName, String projectName, Asset assetToUpdate) {
this.userConnected = userConnected; this.userConnected = userConnected;
@ -63,9 +60,9 @@ public class AssetEditView extends VerticalLayout implements AddLog, View {
startUpdate.setEnabled(false); startUpdate.setEnabled(false);
commitUpdate.setEnabled(true); commitUpdate.setEnabled(true);
undoUpdate.setEnabled(true); undoUpdate.setEnabled(true);
assetTable.setEditable(true); gridAssetTable.setEditorEnabled(true);
excelExporter.setEnabled(false); gridAssetTable.setReadOnly(false);
excelImportTable.setEnabled(false);
}); });
commitUpdate = new Button("Commit"); commitUpdate = new Button("Commit");
commitUpdate.setEnabled(false); commitUpdate.setEnabled(false);
@ -73,9 +70,11 @@ public class AssetEditView extends VerticalLayout implements AddLog, View {
startUpdate.setEnabled(true); startUpdate.setEnabled(true);
commitUpdate.setEnabled(false); commitUpdate.setEnabled(false);
undoUpdate.setEnabled(false); undoUpdate.setEnabled(false);
assetTable.setEditable(false); gridAssetTable.cancelEditor();
excelExporter.setEnabled(true); gridAssetTable.setEditorEnabled(false);
excelImportTable.setEnabled(false); gridAssetTable.setReadOnly(true);
}); });
actionButtons.addComponent(commitUpdate); actionButtons.addComponent(commitUpdate);
undoUpdate = new Button("undo"); undoUpdate = new Button("undo");
@ -84,54 +83,59 @@ public class AssetEditView extends VerticalLayout implements AddLog, View {
startUpdate.setEnabled(true); startUpdate.setEnabled(true);
commitUpdate.setEnabled(false); commitUpdate.setEnabled(false);
undoUpdate.setEnabled(false); undoUpdate.setEnabled(false);
assetTable.setEditable(false); gridAssetTable.cancelEditor();
gridAssetTable.setEditorEnabled(false);
gridAssetTable.cancelEditor();
gridAssetTable.setReadOnly(true);
fillTable(model); fillTable(model);
excelExporter.setEnabled(true);
excelImportTable.setEnabled(false);
}); });
actionButtons.addComponent(undoUpdate); actionButtons.addComponent(undoUpdate);
InterpolationVariable[] variablesList = model.getInterpolationVariablesList(); InterpolationVariable[] variablesList = model.getInterpolationVariablesList();
assetTable = new Table("Data"); gridAssetTable = new Grid("Data");
this.addComponent(assetTable); this.addComponent(gridAssetTable);
assetTable.setSelectable(true); gridAssetTable.setEditorEnabled(false);
assetTable.setMultiSelect(false); gridAssetTable.setSelectionMode(Grid.SelectionMode.SINGLE);
gridAssetTable.setReadOnly(true);
for (InterpolationVariable i : variablesList) { for (InterpolationVariable i : variablesList) {
if (i.getDataType().equals("String")) { if (i.getDataType().equals("String")) {
assetTable.addContainerProperty(i.getVarName(), String.class, null); gridAssetTable.addColumn(i.getVarName(), String.class);
} else if (i.getDataType().equals("Date")) { } else if (i.getDataType().equals("Date")) {
assetTable.addContainerProperty(i.getVarName(), Date.class, null); gridAssetTable.addColumn(i.getVarName(), Date.class);
} else { } else {
assetTable.addContainerProperty(i.getVarName(), String.class, null); gridAssetTable.addColumn(i.getVarName(), String.class);
} }
} }
fillTable(model); fillTable(model);
assetTable.setSizeFull(); gridAssetTable.setSizeFull();
/**
excelExporter = new ExcelExporter(); excelExporter = new ExcelExporter();
excelExporter.setDateFormat("dd-MM-yyyy"); excelExporter.setDateFormat("dd-MM-yyyy");
excelExporter.setLocale(Locale.FRANCE); excelExporter.setLocale(Locale.FRANCE);
excelExporter.setTableToBeExported(assetTable); excelExporter.setTableToBeExported(gridAssetTable);
excelExporter.setCaption("Export to Excel"); excelExporter.setCaption("Export to Excel");
actionButtons.addComponent(excelExporter); actionButtons.addComponent(excelExporter);
excelExporter.setEnabled(true); excelExporter.setEnabled(true);
excelImportTable = new ExcelImportTable(assetTable); excelImportTable = new ExcelImportTable(gridAssetTable);
excelImportTable.setLocale(Locale.FRANCE); excelImportTable.setLocale(Locale.FRANCE);
actionButtons.addComponent(excelImportTable); actionButtons.addComponent(excelImportTable);
**/
} }
private void fillTable(TemplateModel model) { private void fillTable(TemplateModel model) {
InterpolationVariable[] variablesList = model.getInterpolationVariablesList(); InterpolationVariable[] variablesList = model.getInterpolationVariablesList();
DateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRANCE); DateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRANCE);
String[][] contenuTable = model.getTableAsArray(); String[][] contenuTable = model.getTableAsArray();
Container dataSource = assetTable.getContainerDataSource(); Container dataSource = gridAssetTable.getContainerDataSource();
dataSource.removeAllItems(); dataSource.removeAllItems();
for (int i = 0; i < model.getRowsCount(); i++) { for (int i = 0; i < model.getRowsCount(); i++) {
String[] ligne = contenuTable[i]; String[] ligne = contenuTable[i];
Object newItemId = assetTable.addItem(); Object item = dataSource.addItem();
Item row1 = assetTable.getItem(newItemId); Item row1 = dataSource.getItem(item);
int k = 0; int k = 0;
for (InterpolationVariable j : variablesList) { for (InterpolationVariable j : variablesList) {
if (j.getDataType().equals("String")) { if (j.getDataType().equals("String")) {

View file

@ -2,11 +2,8 @@ package org.chtijbug.drools.console.view;
import com.vaadin.data.Property; import com.vaadin.data.Property;
import com.vaadin.data.util.BeanItemContainer; import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.event.Action;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.navigator.View; import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener; import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.shared.ui.MultiSelectMode;
import com.vaadin.ui.*; import com.vaadin.ui.*;
import com.vaadin.ui.themes.Runo; import com.vaadin.ui.themes.Runo;
import org.chtijbug.drools.console.AddLog; import org.chtijbug.drools.console.AddLog;
@ -36,7 +33,14 @@ public class TableLikeArtefactView extends VerticalLayout implements AddLog, Vie
final private BeanItemContainer<Asset> assetBeanItemContainer = new BeanItemContainer<>(Asset.class); final private BeanItemContainer<Asset> assetBeanItemContainer = new BeanItemContainer<>(Asset.class);
private Table assetTable; private Grid assetListGrid;
private Button deleteRow;
private Button editRow;
private Button duplicateRow;
public TableLikeArtefactView(UserConnected userConnected) { public TableLikeArtefactView(UserConnected userConnected) {
@ -81,6 +85,14 @@ public class TableLikeArtefactView extends VerticalLayout implements AddLog, Vie
} }
}); });
this.addComponent(spaceSelection); this.addComponent(spaceSelection);
HorizontalLayout actionButtons = new HorizontalLayout();
this.addComponent(actionButtons);
duplicateRow = new Button("Duplicate");
actionButtons.addComponent(duplicateRow);
editRow = new Button("Edit");
actionButtons.addComponent(editRow);
deleteRow = new Button("Delete");
actionButtons.addComponent(deleteRow);
assetBeanItemContainer.removeContainerProperty("author"); assetBeanItemContainer.removeContainerProperty("author");
assetBeanItemContainer.removeContainerProperty("binaryLink"); assetBeanItemContainer.removeContainerProperty("binaryLink");
assetBeanItemContainer.removeContainerProperty("sourceLink"); assetBeanItemContainer.removeContainerProperty("sourceLink");
@ -94,45 +106,18 @@ public class TableLikeArtefactView extends VerticalLayout implements AddLog, Vie
assetBeanItemContainer.removeContainerProperty("metadata"); assetBeanItemContainer.removeContainerProperty("metadata");
assetTable = new Table("List of assets", assetBeanItemContainer); assetListGrid = new Grid("List of assets", assetBeanItemContainer);
assetTable.setSelectable(true); assetListGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
assetTable.setSizeFull(); assetListGrid.setSizeFull();
assetTable.setMultiSelectMode(MultiSelectMode.SIMPLE);
assetTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
@Override
public void itemClick(ItemClickEvent itemClickEvent) {
if (itemClickEvent.isCtrlKey()) {
Asset selected = (Asset) itemClickEvent.getItemId();
System.out.println(itemClickEvent.getItemId().toString());
}
} this.addComponent(assetListGrid);
}); editRow.addClickListener(clickEvent -> {
this.addComponent(assetTable); Asset selected = (Asset) assetListGrid.getSelectedRow();
final Action actionDuplicate = new Action("Duplicate"); if (selected != null) {
final Action actionEdit = new Action("Edit");
final Action actionDelete = new Action("Delete");
assetTable.addActionHandler(new Action.Handler() {
public void handleAction(Action action, Object sender,
Object target) {
if (action.equals(actionDuplicate)) {
Notification.show("Duplicate not yet implemented");
} else if (action.equals(actionEdit)) {
Notification.show("Edit/modification not yet implemented");
Asset selected = (Asset) target;
ProjectResponse response = (ProjectResponse) spaceSelection.getValue(); ProjectResponse response = (ProjectResponse) spaceSelection.getValue();
AssetEditView assetEditView = new AssetEditView(userConnected, response.getSpaceName(), response.getName(), selected); AssetEditView assetEditView = new AssetEditView(userConnected, response.getSpaceName(), response.getName(), selected);
UI.getCurrent().getNavigator().addView("Asset-" + selected.getTitle(), assetEditView); UI.getCurrent().getNavigator().addView("Asset-" + selected.getTitle(), assetEditView);
UI.getCurrent().getNavigator().navigateTo("Asset-" + selected.getTitle()); UI.getCurrent().getNavigator().navigateTo("Asset-" + selected.getTitle());
} else if (action.equals(actionDelete)) {
Notification.show("Delete not yet implemented");
}
}
public Action[] getActions(Object target, Object sender) {
return new Action[]{actionDuplicate, actionEdit, actionDelete};
} }
}); });