Skip to content

Commit

Permalink
Merge pull request #11 from axonivy-market/inputFixes
Browse files Browse the repository at this point in the history
Input fixes
  • Loading branch information
ivy-rew authored Oct 30, 2023
2 parents b946341 + bf7d76d commit 6208e7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.axonivy.util.excel.importer.wizard;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -43,7 +42,6 @@
import ch.ivyteam.util.io.resource.FileResource;
import ch.ivyteam.util.io.resource.nio.NioFileSystemProvider;

@SuppressWarnings("restriction")
public class ExcelImportProcessor implements IWizardSupport, IRunnableWithProgress {

private IIvyProject selectedSourceProject;
Expand Down Expand Up @@ -102,10 +100,10 @@ private void importExcel(IProjectDataClassManager manager, FileResource excel, I
String entityName = StringUtils.substringBeforeLast(excel.name(), ".");
entityName = StringUtils.capitalize(entityName);

var tempFile = Files.createTempFile(entityName, "."+StringUtils.substringAfterLast(excel.name(), "."));
Files.copy(excel.read().inputStream(), tempFile, StandardCopyOption.REPLACE_EXISTING);

Workbook wb = ExcelLoader.load(tempFile);
Workbook wb = null;
try(InputStream is = excel.read().inputStream()) {
wb = ExcelLoader.load(excel.name(), excel.read().inputStream());
}
Sheet sheet = wb.getSheetAt(0);

var newEntity = new EntityClassReader(manager).toEntity(sheet, entityName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ch.ivyteam.ivy.project.IIvyProjectManager;
import ch.ivyteam.ivy.project.IvyProjectNavigationUtil;

@SuppressWarnings("restriction")
final class ExcelImportUtil {

static final String PAGE_ICON = "/resources/icons/cms_wizard_header.png";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ public ExcelUi(Composite parent) {
public void createControl(Composite parent) {
this.ui = new ExcelUi(parent);

String[] destinations = getDialogSettings().getArray(ExcelImportUtil.DESTINATION_KEY);
if (destinations != null) {
ui.destinationNameField.setText(destinations[0]);
for (String destination : destinations) {
if (destination.endsWith(ExcelImportUtil.DEFAULT_EXTENSION)) {
ui.destinationNameField.add(destination);
handleInputChanged();
}
}
}

for (String projectName : ExcelImportUtil.getIvyProjectNames()) {
ui.sourceProjectField.add(projectName);
}
Expand All @@ -111,6 +100,17 @@ public void createControl(Composite parent) {

setButtonLayoutData(ui.destinationBrowseButton);
setControl(ui);

String[] destinations = getDialogSettings().getArray(ExcelImportUtil.DESTINATION_KEY);
if (destinations != null) {
ui.destinationNameField.setText(destinations[0]);
for (String destination : destinations) {
if (destination.endsWith(ExcelImportUtil.DEFAULT_EXTENSION)) {
ui.destinationNameField.add(destination);
handleInputChanged();
}
}
}
}

@Override
Expand Down Expand Up @@ -139,7 +139,7 @@ protected void handleInputChanged() {
String newProject = ui.sourceProjectField.getText();
var sameProject = Objects.equals(processor.getSelectedSourceProjectName(), newProject);
status.merge(processor.setSource(newProject));
if (!sameProject) {
if (!sameProject || ui.persistence.getItemCount() == 0) {
ui.persistence.setItems(processor.units().toArray(String[]::new)); // update
}

Expand Down

0 comments on commit 6208e7d

Please sign in to comment.