Skip to content

Commit

Permalink
Merge pull request #15 from axonivy-market/inputFixes
Browse files Browse the repository at this point in the history
Input fixes
  • Loading branch information
ivy-rew committed Oct 31, 2023
2 parents 962869c + 6d9849b commit 82f62bd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -97,13 +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();
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);

Expand Down Expand Up @@ -142,13 +139,25 @@ String getSelectedSourceProjectName() {

public WizardStatus setImportFile(String text) {
if (text != null) {
importFile = NioFileSystemProvider.create(Path.of("/")).root().file(text);
try {
importFile = NioFileSystemProvider.create(Path.of("/")).root().file(text);
} catch (Exception ex) {
return WizardStatus.createErrorStatus("Can't create file from "+text, ex);
}
} else {
importFile = null;
}
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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();
}
}
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 82f62bd

Please sign in to comment.