Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>28.0.0</version>
<version>29.0.0-beta-3</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -109,6 +109,11 @@ Wisconsin-Madison, and Friedrich Miescher Institute for Biomedical Research.</li
<groupId>org.scijava</groupId>
<artifactId>scijava-common</artifactId>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-optional</artifactId>
<version>1.0.0</version>
</dependency>

<!-- Test scope dependencies -->
<dependency>
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/org/scijava/table/io/ColumnTableIOOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* #%L
* Table structures for SciJava.
* %%
* Copyright (C) 2012 - 2020 Board of Regents of the University of
* Wisconsin-Madison, and Friedrich Miescher Institute for Biomedical Research.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

package org.scijava.table.io;

import org.scijava.optional.AbstractOptions;

import java.util.function.Function;

/**
* @author Deborah Schmidt
*/
public class ColumnTableIOOptions extends AbstractOptions<ColumnTableIOOptions> {

public final ColumnTableIOOptions.Values values = new ColumnTableIOOptions.Values();
private static final String parserKey = "parser";
private static final String formatterKey = "formatter";

ColumnTableIOOptions formatter(Function<Object, String> formatter) {
return setValue(formatterKey, formatter);
}

ColumnTableIOOptions parser(Function<String, Object> parser) {
return setValue(parserKey, parser);
}

public class Values extends AbstractValues {

public Function<Object, String> formatter() {
return getValueOrDefault(formatterKey, String::valueOf);
}

public Function<String, Object> parser() {
return getValueOrDefault(parserKey, String::valueOf);
}
}

}
21 changes: 21 additions & 0 deletions src/main/java/org/scijava/table/io/DefaultTableIOService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public boolean canSave(Table<?, ?> table, String destination) {
throw new UnsupportedOperationException("No compatible opener found.");
}

@Override
public Table<?, ?> open(String source, TableIOOptions options) throws IOException {
IOPlugin<?> opener = ioService.getOpener(source);
if (opener != null && Table.class.isAssignableFrom(opener.getDataType())
&& TableIOPlugin.class.isAssignableFrom(opener.getClass())) {
return ((TableIOPlugin)opener).open(source, options);
}
throw new UnsupportedOperationException("No compatible opener found.");
}

@Override
public void save(Table<?, ?> table, String destination) throws IOException {
IOPlugin<Table<?, ?>> saver = ioService.getSaver(table, destination);
Expand All @@ -81,4 +91,15 @@ public void save(Table<?, ?> table, String destination) throws IOException {
throw new UnsupportedOperationException("No compatible saver found.");
}
}

@Override
public void save(Table<?, ?> table, String destination, TableIOOptions options) throws IOException {
IOPlugin<Table> saver = ioService.getSaver(table, destination);
if (saver != null && TableIOPlugin.class.isAssignableFrom(saver.getClass())) {
((TableIOPlugin)saver).save(table, destination, options);
}
else {
throw new UnsupportedOperationException("No compatible saver found.");
}
}
}
15 changes: 14 additions & 1 deletion src/main/java/org/scijava/table/io/ExportTableCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
@Menu(label = "Export"), @Menu(label = "Table...") })
public class ExportTableCommand extends ContextCommand {

@Parameter(required = false, label = "Write column headers")
private boolean writeColHeaders = true;

@Parameter(required = false, label = "Write row headers")
private boolean writeRowHeaders = true;

@Parameter(required = false, label = "Column delimiter")
private char columnDelimiter = ',';

@Parameter
private LogService log;

Expand All @@ -68,7 +77,11 @@ public class ExportTableCommand extends ContextCommand {
@Override
public void run() {
try {
tableIO.save(tableDisplay.get(0), outputFile.getAbsolutePath());
TableIOOptions options = new TableIOOptions()
.writeColumnHeaders(writeColHeaders)
.writeRowHeaders(writeRowHeaders)
.columnDelimiter(columnDelimiter);
tableIO.save(tableDisplay.get(0), outputFile.getAbsolutePath(), options);
}
catch (IOException exc) {
log.error(exc);
Expand Down
Loading