diff --git a/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportProcessor.java b/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportProcessor.java index 5bd323c..094731c 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportProcessor.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportProcessor.java @@ -48,6 +48,7 @@ public class ExcelImportProcessor implements IWizardSupport, IRunnableWithProgre private FileResource importFile; private IStatus status = Status.OK_STATUS; private String selectedPersistence; + private String entityName; public ExcelImportProcessor(IStructuredSelection selection) { this.selectedSourceProject = ExcelImportUtil.getFirstNonImmutableIvyProject(selection); @@ -97,16 +98,9 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException { } private void importExcel(IProjectDataClassManager manager, FileResource excel, IProgressMonitor monitor) throws IOException { - String fileName = excel.path().lastSegment(); - if (fileName.contains("\\")) { // windows flaw in current .lastSegment() impl! - fileName = StringUtils.substringAfterLast(fileName, "\\"); - } - String entityName = StringUtils.substringBeforeLast(fileName, "."); - entityName = StringUtils.capitalize(entityName); - Workbook wb = null; try(InputStream is = excel.read().inputStream()) { - wb = ExcelLoader.load(fileName, excel.read().inputStream()); + wb = ExcelLoader.load(excel.name(), excel.read().inputStream()); } Sheet sheet = wb.getSheetAt(0); @@ -156,6 +150,14 @@ public WizardStatus setImportFile(String text) { return validateImportFileExits(); } + public WizardStatus setEntityName(String name) { + this.entityName = name; + if (entityName.isBlank()) { + return WizardStatus.createErrorStatus("Need a valid name for the Data to import"); + } + return WizardStatus.createOkStatus(); + } + public WizardStatus setSource(String projectName) { selectedSourceProject = null; if (projectName != null) { diff --git a/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportWizardPage.java b/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportWizardPage.java index fcf58a9..d8365e0 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportWizardPage.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/wizard/ExcelImportWizardPage.java @@ -20,6 +20,7 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Widget; import ch.ivyteam.ivy.designer.ui.wizard.restricted.WizardStatus; @@ -41,6 +42,7 @@ public ExcelImportWizardPage(ExcelImportProcessor processor) { private static class ExcelUi extends Composite { public final Combo destinationNameField; + public final Text entity; public final Combo sourceProjectField; public final Button destinationBrowseButton; public final Combo persistence; @@ -62,6 +64,14 @@ public ExcelUi(Composite parent) { destinationBrowseButton = new Button(this, 8); destinationBrowseButton.setText("Browse ..."); + Label entityLabel = new Label(this, SWT.NONE); + entityLabel.setText("Entity"); + this.entity = new Text(this, SWT.BORDER); + GridData entGrid = new GridData(768); + entGrid.widthHint = 250; + entGrid.horizontalSpan = 2; + entity.setLayoutData(entGrid); + Label sourceLabel = new Label(this, 0); sourceLabel.setText("Project"); this.sourceProjectField = new Combo(this, 2060); @@ -95,6 +105,8 @@ public void createControl(Composite parent) { ui.destinationNameField.addListener(SWT.Selection, this); ui.destinationBrowseButton.addListener(SWT.Selection, this); + ui.entity.addListener(SWT.Modify, this); + ui.persistence.addListener(SWT.Modify, this); ui.persistence.addListener(SWT.Selection, this); @@ -103,11 +115,10 @@ public void createControl(Composite parent) { String[] destinations = getDialogSettings().getArray(ExcelImportUtil.DESTINATION_KEY); if (destinations != null) { - ui.destinationNameField.setText(destinations[0]); + fileSelected(destinations[0]); for (String destination : destinations) { if (destination.endsWith(ExcelImportUtil.DEFAULT_EXTENSION)) { ui.destinationNameField.add(destination); - handleInputChanged(); } } } @@ -135,7 +146,7 @@ protected void handleInputChanged() { var status = WizardStatus.createOkStatus(); status.merge(processor.setImportFile(ui.destinationNameField.getText())); - + status.merge(processor.setEntityName(ui.entity.getText())); String newProject = ui.sourceProjectField.getText(); var sameProject = Objects.equals(processor.getSelectedSourceProjectName(), newProject); status.merge(processor.setSource(newProject)); @@ -181,8 +192,23 @@ private void handleDestinationBrowseButtonPressed() { dialog.setFilterPath(currentSourceString); String selectedFileName = dialog.open(); if (selectedFileName != null) { - ui.destinationNameField.setText(selectedFileName); + fileSelected(selectedFileName); + } + } + + private void fileSelected(String selectedFileName) { + ui.destinationNameField.setText(selectedFileName); + ui.entity.setText(proposeName(selectedFileName)); + } + + private static String proposeName(String selection) { + if (selection == null) { + return ""; } + String fileName = new File(selection).getName(); + String entityName = StringUtils.substringBeforeLast(fileName, "."); + entityName = StringUtils.capitalize(entityName); + return entityName; } private boolean executeImport() {