diff --git a/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/DefaultSchemaTypePage.java b/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/DefaultSchemaTypePage.java index 8bf2576573..0cee09174f 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/DefaultSchemaTypePage.java +++ b/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/DefaultSchemaTypePage.java @@ -423,7 +423,7 @@ public boolean isValid() { */ private void showMessage() { if (header == null || header.length == 0) - setErrorMessage("The file contains no data"); + setErrorMessage("The file contains no data or not valid data"); else if (!sfe.isValid()) setErrorMessage("Please enter a valid Type Name"); else if (!isValid) diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml index eac0b88b13..0ccbadb4ca 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml +++ b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml @@ -10,13 +10,6 @@ ref="eu.esdihumboldt.hale.io.xls.reader.schema"> - - - - diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSInstanceImportConfigurationPage.java b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSInstanceImportConfigurationPage.java index 031d5a4b45..93da91b5eb 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSInstanceImportConfigurationPage.java +++ b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSInstanceImportConfigurationPage.java @@ -27,16 +27,14 @@ import eu.esdihumboldt.hale.common.core.io.Value; import eu.esdihumboldt.hale.common.instance.io.InstanceReader; import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants; -import eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage; -import eu.esdihumboldt.hale.ui.io.instance.InstanceImportWizard; +import eu.esdihumboldt.hale.io.csv.ui.TypeSelectionPage; /** * Configuration page for the instance export provider of Excel files * * @author Patrick Lieb */ -public class XLSInstanceImportConfigurationPage extends - AbstractConfigurationPage { +public class XLSInstanceImportConfigurationPage extends TypeSelectionPage { private Combo sheetSelection; @@ -44,9 +42,8 @@ public class XLSInstanceImportConfigurationPage extends * Default Constructor */ public XLSInstanceImportConfigurationPage() { - super("xls.instance.import.sheet.selection"); setTitle("Sheet selection"); - setDescription("Select sheet to import instances"); + setDescription("Select sheet to import instances, your Type and Data reading setting"); } /** @@ -55,21 +52,16 @@ public XLSInstanceImportConfigurationPage() { @Override protected void createContent(Composite page) { - page.setLayout(new GridLayout(1, false)); + page.setLayout(new GridLayout(2, false)); - Composite menu = new Composite(page, SWT.NONE); - menu.setLayout(new GridLayout(2, false)); - - GridDataFactory.fillDefaults().grab(true, false).applyTo(menu); - - Label sheetLabel = new Label(menu, SWT.None); + Label sheetLabel = new Label(page, SWT.None); sheetLabel.setText("Select sheet"); - sheetSelection = new Combo(menu, SWT.DROP_DOWN | SWT.READ_ONLY); + sheetSelection = new Combo(page, SWT.DROP_DOWN | SWT.READ_ONLY); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false) .applyTo(sheetSelection); - setPageComplete(false); + super.createContent(page); } /** @@ -97,7 +89,7 @@ protected void onShowPage(boolean firstShow) { } super.onShowPage(firstShow); sheetSelection.select(0); - setPageComplete(true); + setPageComplete(false); } /** @@ -107,7 +99,8 @@ protected void onShowPage(boolean firstShow) { public boolean updateConfiguration(InstanceReader provider) { provider.setParameter(InstanceTableIOConstants.SHEET_INDEX, Value.of(sheetSelection.getSelectionIndex())); - return true; + + return super.updateConfiguration(provider); } /** diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSSchemaTypePage.java b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSSchemaTypePage.java index 993c9b78c9..ce14722c6f 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSSchemaTypePage.java +++ b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSSchemaTypePage.java @@ -101,7 +101,7 @@ public void widgetSelected(SelectionEvent event) { } catch (Exception e) { setPageComplete(false); clearSuperPage(); - setErrorMessage("The sheet is empty!"); + setErrorMessage("The sheet is empty or the header is not valid!"); } } @@ -117,7 +117,7 @@ public void widgetDefaultSelected(SelectionEvent e) { } catch (Exception e1) { setPageComplete(false); clearSuperPage(); - setErrorMessage("The sheet is empty!"); + setErrorMessage("The sheet is empty or the header is not valid!"); } } @@ -159,11 +159,12 @@ protected void onShowPage(boolean firstShow) { } ArrayList items = new ArrayList(); for (int i = 0; i < numberOfSheets; i++) { - items.add(wb.getSheetAt(i).getSheetName()); // only add items if there is a header (no empty sheet) Row row = wb.getSheetAt(i).getRow(0); - if (row == null && newLocation != null && !newLocation.equals(oldLocation)) { - sheetNum++; + items.add(wb.getSheetAt(i).getSheetName()); + if (row != null) { + update(i); + sheetNum = i; } } @@ -183,18 +184,24 @@ protected void onShowPage(boolean firstShow) { } catch (OldExcelFormatException e) { // the setup is not in a valid state - clearPage(); - clearSuperPage(); - setErrorMessage("Old excel format detected (format 5.0/7.0 (BIFF5)). Please convert the excel file to BIFF8 from Excel versions 97/2000/XP/2003."); - setPageComplete(false); + setErrorMessage( + "Old excel format detected (format 5.0/7.0 (BIFF5)). Please convert the excel file to BIFF8 from Excel versions 97/2000/XP/2003."); + clearFromException(); } catch (Exception e) { - clearPage(); - clearSuperPage(); setErrorMessage("Excel file cannot be loaded!"); - setPageComplete(false); + clearFromException(); } } + /** + * clear page and super page + */ + private void clearFromException() { + clearPage(); + clearSuperPage(); + setPageComplete(false); + } + /** * Use this if an error occurs * @@ -223,8 +230,8 @@ private void sheetSelectionChanged(int sheetNum) throws Exception { private void update(int sheetNum) throws Exception { // if the sheet is empty an Exception occurs - AnalyseXLSSchemaTable analyser = new AnalyseXLSSchemaTable(getWizard().getProvider() - .getSource().getLocation(), sheetNum); + AnalyseXLSSchemaTable analyser = new AnalyseXLSSchemaTable( + getWizard().getProvider().getSource().getLocation(), sheetNum); setHeader(analyser.getHeader().toArray(new String[0])); diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AbstractAnalyseTable.java b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AbstractAnalyseTable.java index e11f9f369e..2bdbc00509 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AbstractAnalyseTable.java +++ b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AbstractAnalyseTable.java @@ -54,6 +54,7 @@ protected void analyse(URI location) throws Exception { * @param location the file location * @param sheetNum number of the sheet that should be loaded (0-based) * @throws Exception if an error occurs loading the file + * @throws XLSException if an error occurs loading the header, content */ protected void analyse(URI location, int sheetNum) throws Exception { InputStream inp = new BufferedInputStream(location.toURL().openStream()); @@ -95,13 +96,19 @@ protected void analyse(URI location, int sheetNum) throws Exception { */ protected void analyseHeader(Sheet sheet) { Row header = sheet.getRow(0); - - // identify columns - for (int i = header.getFirstCellNum(); i < header.getLastCellNum(); i++) { - Cell cell = header.getCell(i); - String text = extractText(cell); - - headerCell(i, text); + if (header != null) { + + // identify columns + int count = 0; + for (int i = header.getFirstCellNum(); i < header.getLastCellNum(); i++) { + Cell cell = header.getCell(i); + String text = extractText(cell); + // cell cannot be empty to extract the text + if (text != null) { + headerCell(count, text); + count++; + } + } } } @@ -120,7 +127,9 @@ private void analyseContent(Sheet sheet) { // for each row starting from the second for (int i = 1; i <= sheet.getLastRowNum(); i++) { Row row = sheet.getRow(i); - analyseRow(i, row); + if (row != null) { + analyseRow(i, row); + } } } diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AnalyseXLSSchemaTable.java b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AnalyseXLSSchemaTable.java index 5322c8458a..c7704a18ff 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AnalyseXLSSchemaTable.java +++ b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/AnalyseXLSSchemaTable.java @@ -57,8 +57,9 @@ public AnalyseXLSSchemaTable(URI location, int sheetNum) throws Exception { */ @Override protected void headerCell(int num, String text) { - if (num == header.size()) + if (num == header.size()) { header.add(text); + } header.set(num, text); } diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/reader/XLSInstanceReader.java b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/reader/XLSInstanceReader.java index 52f37bcf11..4e0a326a3c 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/reader/XLSInstanceReader.java +++ b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/reader/XLSInstanceReader.java @@ -109,17 +109,12 @@ protected IOReport execute(ProgressIndicator progress, IOReporter reporter) Boolean skipType = getParameter(CommonSchemaConstants.PARAM_SKIP_N_LINES).as(Boolean.class); if (skipType == null) { - skipNlines = getParameter(CommonSchemaConstants.PARAM_SKIP_N_LINES).as(Integer.class); - } else if (skipType) { - skipNlines = 1; - } else { - skipNlines = 0; }