use of net.sourceforge.sqlexplorer.dataset.DataSetRow in project tdq-studio-se by Talend.
the class ExportHTMLAction method run.
/**
* Copy all table data to clipboard
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
final HtmlExportOptionsDlg dlg = new HtmlExportOptionsDlg(_table.getShell());
if (dlg.open() != Window.OK)
return;
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
try {
File file = new File(dlg.getFilename());
if (file.exists()) {
// overwrite existing files
file.delete();
}
String charset = dlg.getCharacterSet();
file.createNewFile();
PrintStream writer = new PrintStream(file, charset);
// $NON-NLS-1$
StringBuffer buffer = new StringBuffer("");
// get preferences
boolean includeColumnNames = dlg.includeHeaders();
boolean rtrim = dlg.trimSpaces();
String nullValue = dlg.getNullValue();
DataSet dataSet = (DataSet) _table.getData();
if (dataSet == null) {
return;
}
// $NON-NLS-1$
writer.println("<html>");
// $NON-NLS-1$
writer.println("<head>");
// $NON-NLS-1$
writer.print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=");
writer.print(charset);
// $NON-NLS-1$
writer.println("\">");
// $NON-NLS-1$
writer.println("<style type=\"text/css\">");
// $NON-NLS-1$
writer.println("TABLE {border-collapse: collapse;}");
// $NON-NLS-1$
writer.println("TH {background-color: rgb(240, 244, 245);}");
// $NON-NLS-1$
writer.println("TH, TD {border: 1px solid #D1D6D4;font-size: 10px;font-family: Verdana, Arial, Helvetica, sans-serif;}");
// $NON-NLS-1$
writer.println(".right {text-align: right;}");
// $NON-NLS-1$
writer.println("</style>");
// $NON-NLS-1$
writer.println("</head>");
// $NON-NLS-1$
writer.println("<body>");
// $NON-NLS-1$
writer.println("<table>");
// export column names
if (includeColumnNames) {
// $NON-NLS-1$
buffer.append("<tr>");
DataSet.Column[] columns = dataSet.getColumns();
for (int i = 0; i < columns.length; i++) {
// $NON-NLS-1$
buffer.append("<th>");
buffer.append(TextUtil.htmlEscape(columns[i].getCaption()));
// $NON-NLS-1$
buffer.append("</th>");
}
// $NON-NLS-1$
buffer.append("</tr>");
writer.println(buffer.toString());
}
// export column data
int columnCount = _table.getColumnCount();
for (int i = 0; i < dataSet.getRowCount(); i++) {
// $NON-NLS-1$
buffer = new StringBuffer("<tr>");
DataSetRow row = dataSet.getRow(i);
for (int j = 0; j < columnCount; j++) {
Object o = row.getRawObjectValue(j);
if (o instanceof Double || o instanceof Integer)
// right align numbers
// $NON-NLS-1$
buffer.append("<td class=\"right\">");
else
// $NON-NLS-1$
buffer.append("<td>");
String t = o == null ? nullValue : o.toString();
if (rtrim)
t = TextUtil.rtrim(t);
buffer.append(TextUtil.htmlEscape(t));
// $NON-NLS-1$
buffer.append("</td>");
}
// $NON-NLS-1$
buffer.append("</tr>");
writer.println(buffer.toString());
}
// $NON-NLS-1$
writer.println("</table>");
// $NON-NLS-1$
writer.println("</body>");
// $NON-NLS-1$
writer.println("</html>");
writer.close();
} catch (final Exception e) {
_table.getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(_table.getShell(), Messages.getString("SQLResultsView.Error.Export.Title"), e.getMessage());
SQLExplorerPlugin.error(Messages.getString("SQLResultsView.Error.Export.Title"), e);
}
});
}
}
});
}
use of net.sourceforge.sqlexplorer.dataset.DataSetRow in project tdq-studio-se by Talend.
the class ExportXLSAction method run.
/**
* Copy all table data to clipboard
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
final XlsExportOptionsDlg dlg = new XlsExportOptionsDlg(_table.getShell());
if (dlg.open() != Window.OK)
return;
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
try {
File file = new File(dlg.getFilename());
if (file.exists()) {
// overwrite existing files
file.delete();
}
file.createNewFile();
PrintStream writer = new PrintStream(file, dlg.getCharacterSet());
// $NON-NLS-1$
StringBuffer buffer = new StringBuffer("");
// get preferences
boolean includeColumnNames = dlg.includeHeaders();
boolean rtrim = dlg.trimSpaces();
boolean quote = dlg.quoteText();
String nullValue = dlg.getNullValue();
DataSet dataSet = (DataSet) _table.getData();
if (dataSet == null) {
return;
}
// $NON-NLS-1$
writer.println("<table>");
// export column names
if (includeColumnNames) {
// $NON-NLS-1$
buffer.append("<tr>");
DataSet.Column[] columns = dataSet.getColumns();
for (int i = 0; i < columns.length; i++) {
// $NON-NLS-1$
buffer.append("<th>");
buffer.append(TextUtil.htmlEscape(columns[i].getCaption()));
// $NON-NLS-1$
buffer.append("</th>");
}
// $NON-NLS-1$
buffer.append("</tr>");
writer.println(buffer.toString());
}
// export column data
int columnCount = _table.getColumnCount();
for (int i = 0; i < dataSet.getRowCount(); i++) {
// $NON-NLS-1$
buffer = new StringBuffer("<tr>");
DataSetRow row = dataSet.getRow(i);
for (int j = 0; j < columnCount; j++) {
// $NON-NLS-1$
buffer.append("<td>");
Object o = row.getRawObjectValue(j);
String t = o == null ? nullValue : o.toString();
if (rtrim)
t = TextUtil.rtrim(t);
if (quote && o instanceof String) {
// $NON-NLS-1$
buffer.append("\"");
buffer.append(TextUtil.htmlEscape(t));
// $NON-NLS-1$
buffer.append("\"");
} else
buffer.append(TextUtil.htmlEscape(t));
// $NON-NLS-1$
buffer.append("</td>");
}
// $NON-NLS-1$
buffer.append("</tr>");
writer.println(buffer.toString());
}
// $NON-NLS-1$
writer.println("</table>");
writer.close();
} catch (final Exception e) {
_table.getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(_table.getShell(), Messages.getString("SQLResultsView.Error.Export.Title"), e.getMessage());
SQLExplorerPlugin.error(Messages.getString("SQLResultsView.Error.Export.Title"), e);
}
});
}
}
});
}
use of net.sourceforge.sqlexplorer.dataset.DataSetRow in project tdq-studio-se by Talend.
the class MapDBColumnSetDataSet method getRow.
/*
* (non-Javadoc)
*
* @see net.sourceforge.sqlexplorer.dataset.mapdb.MapDBkeyListDataSet#getRow(int)
*/
@Override
public DataSetRow getRow(int index) {
DataSetRow returnDataSetRow = null;
if (iterator == null) {
return super.getRow(index);
} else {
if (index < 0 || index >= getRowCount()) {
throw new IndexOutOfBoundsException(Messages.getString("DataSet.errorIndexOutOfRange") + index);
}
if (currentIndex > index) {
iterator = dataMap.keySet().iterator();
currentIndex = 0;
}
while (currentIndex < index && iterator.hasNext()) {
List<Object> next = iterator.next();
if (dataValidator.isValid(dataMap.get(next))) {
currentIndex++;
}
}
List<Object> valueList = iterator.next();
while (!dataValidator.isValid(dataMap.get(valueList)) && iterator.hasNext()) {
valueList = iterator.next();
}
currentIndex++;
Comparable[] comparable = new Comparable[valueList.size()];
for (int i = 0; i < valueList.size(); i++) {
comparable[i] = (Comparable) valueList.get(i);
}
returnDataSetRow = new DataSetRow(this, comparable);
return returnDataSetRow;
}
}
use of net.sourceforge.sqlexplorer.dataset.DataSetRow in project tdq-studio-se by Talend.
the class MapDBDataSet method getRow.
/*
* (non-Javadoc)
*
* @see net.sourceforge.sqlexplorer.dataset.DataSet#getRow(int)
*/
@Override
public DataSetRow getRow(int index) {
DataSetRow returnDataSetRow = null;
if (iterator == null) {
return super.getRow(index);
} else {
if (index < 0 || index >= dataMap.size()) {
// $NON-NLS-1$
throw new IndexOutOfBoundsException(Messages.getString("DataSet.errorIndexOutOfRange") + index);
}
if (currentIndex > index) {
iterator = dataMap.keySet().iterator();
currentIndex = 0;
}
while (currentIndex < index && iterator.hasNext()) {
iterator.next();
currentIndex++;
}
Object currentData = iterator.next();
currentIndex++;
List<Object> valueList = dataMap.get(currentData);
if (columnFilter != null) {
valueList = columnFilter.filter(valueList);
}
Comparable[] comparable = valueList.toArray(new Comparable[valueList.size()]);
if (comparable.length == 0) {
comparable = new Comparable[1];
comparable[0] = null;
}
returnDataSetRow = new DataSetRow(this, comparable);
return returnDataSetRow;
}
}
use of net.sourceforge.sqlexplorer.dataset.DataSetRow in project tdq-studio-se by Talend.
the class MapDBSetDataSet method getRow.
/*
* (non-Javadoc)
*
* @see net.sourceforge.sqlexplorer.dataset.DataSet#getRow(int)
*/
@Override
public DataSetRow getRow(int index) {
DataSetRow returnDataSetRow = null;
if (iterator == null) {
return super.getRow(index);
} else {
if (index < 0 || index >= dataSet.size()) {
throw new IndexOutOfBoundsException(Messages.getString("DataSet.errorIndexOutOfRange") + index);
}
if (currentIndex > index) {
iterator = dataSet.iterator();
currentIndex = 0;
}
while (currentIndex < index) {
iterator.next();
currentIndex++;
}
Object currentData = iterator.next();
currentIndex++;
Comparable[] comparable = new Comparable[1];
comparable[0] = (Comparable) currentData;
returnDataSetRow = new DataSetRow(this, comparable);
return returnDataSetRow;
}
}
Aggregations