Browse files

Supports row offset. Closes #131

  • Loading branch information...
1 parent ae8b4ee commit 84d69f65fbf20e945b1d83aae435c931b486719b @eamonnmag eamonnmag committed May 21, 2012
View
15 src/main/java/org/isatools/isacreator/formatmappingutility/loader/CSVFileLoader.java
@@ -40,6 +40,7 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
import au.com.bytecode.opencsv.CSVReader;
import org.apache.commons.collections15.map.ListOrderedMap;
import org.apache.log4j.Logger;
+import org.isatools.isacreator.settings.ISAcreatorProperties;
import java.io.File;
import java.io.FileNotFoundException;
@@ -99,13 +100,25 @@ public char getDelimiter() {
CSVReader reader = new CSVReader(new FileReader(file), delimiter);
- if (delimiter == FileLoader.COMMA_DELIM) {
+ if (delimiter == FileLoader.COMMA_DELIM) {
readerUsed = FileLoader.CSV_READER_CSV;
} else {
readerUsed = FileLoader.CSV_READER_TXT;
}
+
+ int rowOffSet;
+ try {
+ rowOffSet = Integer.parseInt(ISAcreatorProperties.getProperty("isacreator.rowOffset")) - 1;
+ } catch (NumberFormatException nfe) {
+ rowOffSet = 0;
+ }
+
+ for (int skipCount = 0; skipCount < rowOffSet; skipCount++) {
+ reader.readNext();
+ }
+
firstLine = reader.readNext();
// clean up
View
14 src/main/java/org/isatools/isacreator/formatmappingutility/loader/ExcelFileLoader.java
@@ -42,6 +42,7 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.apache.commons.collections15.map.ListOrderedMap;
+import org.isatools.isacreator.settings.ISAcreatorProperties;
import java.io.File;
import java.io.IOException;
@@ -74,12 +75,21 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
// Get the first sheet
for (Sheet s : w.getSheets()) {
+ int rowStart;
+ try {
+ rowStart = Integer.parseInt(ISAcreatorProperties.getProperty("isacreator.rowOffset")) - 1;
+ System.out.println("Row offset is: " + rowStart);
+ } catch (NumberFormatException nfe) {
+ System.out.println(nfe.getMessage());
+ rowStart = 0;
+ }
+
if (s.getRows() > 0) {
- int row = 0;
+
List<String> headersForSheet = new ArrayList<String>();
for (int j = 0; j < s.getColumns(); j++) {
- String cellContents = s.getCell(j, row).getContents();
+ String cellContents = s.getCell(j, rowStart).getContents();
if (!cellContents.trim().equals("")) {
headersForSheet.add(cellContents);
}
View
12 src/main/java/org/isatools/isacreator/formatmappingutility/logic/MappingLogic.java
@@ -54,6 +54,7 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
import org.isatools.isacreator.gui.DataEntryEnvironment;
import org.isatools.isacreator.gui.StudyDataEntry;
import org.isatools.isacreator.model.*;
+import org.isatools.isacreator.settings.ISAcreatorProperties;
import org.isatools.isacreator.spreadsheet.model.TableReferenceObject;
import org.isatools.isacreator.utils.GeneralUtils;
import org.isatools.isacreator.utils.StringProcessing;
@@ -323,6 +324,13 @@ private void createDataForTRO(String[] headers, List<String> substitutions, Tabl
try {
String[] subsAsArray = substitutions.toArray(new String[substitutions.size()]);
+ int rowOffSet;
+ try {
+ rowOffSet = Integer.parseInt(ISAcreatorProperties.getProperty("isacreator.rowOffset")) - 1;
+ } catch (NumberFormatException nfe) {
+ rowOffSet = 0;
+ }
+
if (readerToUse == FileLoader.CSV_READER_CSV || readerToUse == FileLoader.CSV_READER_TXT) {
char delimiter = (readerToUse == FileLoader.CSV_READER_CSV) ? FileLoader.COMMA_DELIM : FileLoader.TAB_DELIM;
@@ -335,7 +343,7 @@ private void createDataForTRO(String[] headers, List<String> substitutions, Tabl
while ((nextLine = fileReader.readNext()) != null) {
// we don't want the column names as well!
- if (count != 0) {
+ if (count != 0 && count > rowOffSet) {
// we decrement count since we're skipping 0.
addDataToTRO(headers, subsAsArray, nextLine, tro);
}
@@ -353,7 +361,7 @@ private void createDataForTRO(String[] headers, List<String> substitutions, Tabl
for (Sheet s : w.getSheets()) {
if (s.getRows() > 1) {
- for (int row = 1; row < s.getRows(); row++) {
+ for (int row = rowOffSet + 1; row < s.getRows(); row++) {
String[] nextLine = new String[s.getColumns()];
for (int col = 0; col < s.getColumns(); col++) {
View
27 src/main/java/org/isatools/isacreator/formatmappingutility/ui/MappingUtilView.java
@@ -46,6 +46,7 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
import org.isatools.isacreator.common.HistoryComponent;
import org.isatools.isacreator.common.UIHelper;
import org.isatools.isacreator.configuration.MappingObject;
+import org.isatools.isacreator.effects.components.RoundedJTextField;
import org.isatools.isacreator.formatmappingutility.exceptions.MultipleExtensionsException;
import org.isatools.isacreator.formatmappingutility.exceptions.NoAvailableLoaderException;
import org.isatools.isacreator.formatmappingutility.io.ISAFieldMapping;
@@ -238,6 +239,30 @@ public void actionPerformed(ActionEvent actionEvent) {
selectFilesContainer.add(selectMappingPanel);
+ final RoundedJTextField rowOffset = new RoundedJTextField(3);
+ rowOffset.setEnabled(false);
+ rowOffset.setSize(new Dimension(20, 20));
+ rowOffset.setText("1");
+
+ final JCheckBox overrideRowPosition = new JCheckBox("override row start position?");
+ UIHelper.renderComponent(overrideRowPosition, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false);
+ overrideRowPosition.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ rowOffset.setEnabled(overrideRowPosition.isSelected());
+ }
+ });
+
+
+ Box fileInputPanel = Box.createHorizontalBox();
+ fileInputPanel.setSize(new Dimension(100, 20));
+ fileInputPanel.add(overrideRowPosition);
+ fileInputPanel.add(Box.createHorizontalStrut(5));
+ fileInputPanel.add(rowOffset);
+
+ selectFilesContainer.add(fileInputPanel);
+
+
+ selectFilesContainer.add(selectMappingPanel);
JPanel statusPanel = new JPanel(new GridLayout(1, 1));
statusPanel.setPreferredSize(new Dimension(400, 30));
@@ -289,6 +314,8 @@ public void mousePressed(MouseEvent mouseEvent) {
Thread loadFile = new Thread(new Runnable() {
public void run() {
+ ISAcreatorProperties.setProperty("isacreator.rowOffset", rowOffset.isEnabled() ? rowOffset.getText() : "1");
+
if (useMapping.isSelected()) {
if (!savedMappingsFile.getSelectedFilePath().trim().equals("")) {

0 comments on commit 84d69f6

Please sign in to comment.