tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / reportbuilder / java / org / libreoffice / report / pentaho / StarReportData.java
blob442703ea4dd8f2a35c2f6046972b46ddf9b3f3fb
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package org.libreoffice.report.pentaho;
20 import org.libreoffice.report.DataSource;
22 import org.jfree.report.DataSourceException;
23 import org.jfree.report.ReportData;
25 public class StarReportData implements ReportData
28 private final DataSource dataSource;
29 private int currentRow;
30 private final int rowCount;
32 public StarReportData(final DataSource dataSource)
33 throws org.libreoffice.report.DataSourceException
35 if (dataSource == null)
37 throw new NullPointerException();
39 this.dataSource = dataSource;
40 this.currentRow = 0;
41 this.rowCount = dataSource.getRowCount();
44 public boolean setCursorPosition(final int row) throws DataSourceException
46 try
48 final boolean ret = dataSource.absolute(row);
49 if (ret)
51 currentRow = row;
53 return ret;
55 catch (org.libreoffice.report.DataSourceException e)
57 throw new DataSourceException("Failed to move cursor", e);
61 public void close()
62 throws DataSourceException
64 try
66 dataSource.close();
68 catch (org.libreoffice.report.DataSourceException e)
70 throw new DataSourceException("Failed to close datasource", e);
74 public int getCursorPosition()
75 throws DataSourceException
77 return currentRow;
80 /**
81 * This operation checks, whether a call to next will be likely to succeed. If
82 * there is a next data row, this should return true.
84 public boolean isAdvanceable() throws DataSourceException
86 return currentRow < rowCount;
89 public boolean next()
90 throws DataSourceException
92 try
94 if (dataSource.next())
96 currentRow += 1;
97 return true;
99 return false;
101 catch (org.libreoffice.report.DataSourceException e)
103 throw new DataSourceException("Failed to move cursor", e);
107 public Object get(final int column)
108 throws DataSourceException
110 if (!isReadable())
112 throw new DataSourceException("Failed to query column.");
117 return dataSource.getObject(column + 1);
119 catch (org.libreoffice.report.DataSourceException e)
121 throw new DataSourceException("Failed to query column.", e);
125 public int getColumnCount()
126 throws DataSourceException
130 return dataSource.getColumnCount();
132 catch (org.libreoffice.report.DataSourceException e)
134 throw new DataSourceException("Failed to query column count.", e);
138 public String getColumnName(final int column)
139 throws DataSourceException
143 return dataSource.getColumnName(column + 1);
145 catch (org.libreoffice.report.DataSourceException e)
147 throw new DataSourceException("Failed to query column name.", e);
151 public boolean isReadable() throws DataSourceException
153 return currentRow > 0 && rowCount > 0;