summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpshi2012-04-09 03:38:26 (EDT)
committer xgu2012-05-03 04:48:44 (EDT)
commit4d3bd8bf34efd4ceae1e06625841f2872beb0849 (patch)
tree46e5d92d1319523a8c56d1b28b57fa5c0e12176c
parente3f663d38342a94f83bec8c01a4388487b2d2d30 (diff)
downloadorg.eclipse.birt-4d3bd8bf34efd4ceae1e06625841f2872beb0849.zip
org.eclipse.birt-4d3bd8bf34efd4ceae1e06625841f2872beb0849.tar.gz
org.eclipse.birt-4d3bd8bf34efd4ceae1e06625841f2872beb0849.tar.bz2
fix 48202 Support Relative File Path for the input file in Excel ODA Designer
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties8
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java241
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePropertyPage.java14
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourceWizardPage.java12
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java66
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java485
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFolderSelectionDialog.java301
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java33
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java7
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java31
10 files changed, 1123 insertions, 75 deletions
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties
index f213e5c..15c8eea 100644
--- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties
@@ -14,6 +14,7 @@
wizard.title.selectColumns=Select Columns
wizard.defaultMessage.selectFolder=Select the folder that contains the excel files.
wizard.defaultMessage.selectFile=Select the file and the columns for the data set.
+connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR=Cannot open excel file database under directory:
label.selectFolder=S&elect folder:
label.selectFile=Select f&ile:
@@ -25,6 +26,8 @@ button.selectFolder.browse=B&rowse...
button.moveUp=&Up
button.moveDown=Do&wn
button.delete=D&elete
+button.selectFileURI.menuItem.relativePath=Relative path
+button.selectFileURI.menuItem.absolutePath=Absolute path
editor.title.name=Name
editor.title.originalName=Original Name
@@ -66,10 +69,13 @@ error.duplicatedNameValueOrEmpty=Duplicated Name Value or Empty
error.invalidSavedColumnsInfo = Invalid saved Columns Info
error.invalidColumnName=Invalid Column Name
error.invalidQureyText=Invalid Query-Text
+error.emptyFolder=do not contain excel files in this folder
title.warning=Warning
warning.fileExtensionInvalid=The selected file might not be a valid excel file.
confirm.reselectWorksheetTitle=Confirm to select a different sheet.
confirm.reselectWorksheetMessage=Selecting a different sheet will leave previous operations unsaved.\n\nAre you sure?
confirm.reselectFileTitle=Confirm to select a different file.
-confirm.reselectFileMessage=Selecting a different file will leave previous operations unsaved.\n\nAre you sure? \ No newline at end of file
+confirm.reselectFileMessage=Selecting a different file will leave previous operations unsaved.\n\nAre you sure?
+
+RelativeFolderSelectionDialog.Title.SelectFolder=Select a folder \ No newline at end of file
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java
index f9fce66..4765f8c 100644
--- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Megha Nidhi Dahal.
+ * Copyright (c) 2012 Megha Nidhi Dahal and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,19 +7,30 @@
*
* Contributors:
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
+ * Actuate Corporation - added support of relative file path
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.ui.wizards;
import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Properties;
import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants;
import org.eclipse.birt.report.data.oda.excel.ui.i18n.Messages;
import org.eclipse.birt.report.data.oda.excel.ui.util.IHelpConstants;
import org.eclipse.birt.report.data.oda.excel.ui.util.Utility;
+import org.eclipse.birt.report.data.oda.excel.ui.wizards.ExcelFileSelectionWizardPage.ExcelFileFilter;
+import org.eclipse.datatools.connectivity.IConnection;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.eclipse.datatools.connectivity.oda.design.ui.designsession.DesignSessionUtil;
import org.eclipse.datatools.connectivity.oda.design.ui.nls.TextProcessorWrapper;
+import org.eclipse.datatools.connectivity.oda.util.ResourceIdentifiers;
+import org.eclipse.datatools.connectivity.ui.PingJob;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -33,6 +44,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Text;
public class ExcelDataSourcePageHelper {
@@ -45,13 +58,20 @@ public class ExcelDataSourcePageHelper {
private transient Text folderLocation = null;
private transient Button typeLineCheckBox = null;
- private transient Button browseFolderButton = null;
+ private transient MenuButton browseFolderButton = null;
private transient Button columnNameLineCheckBox = null;
+ private transient Composite parent = null;
private static final int CORRECT_FOLDER = 0;
private static final int ERROR_FOLDER = 1;
private static final int ERROR_EMPTY_PATH = 2;
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ private static final String CURRENT_DIRECTORY = ".";
+
+ private static final Integer SELECT_RELATIVE_PATH = 1;
+ private static final Integer SELECT_ABSOLUTE_PATH = 2;
+
+ private ResourceIdentifiers ri;
public ExcelDataSourcePageHelper(ExcelDataSourceWizardPage page) {
wizardPage = page;
@@ -67,6 +87,7 @@ public class ExcelDataSourcePageHelper {
* @param parent
*/
void createCustomControl(Composite parent) {
+ this.parent = parent;
Composite content = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout(3, false);
content.setLayout(layout);
@@ -99,32 +120,114 @@ public class ExcelDataSourcePageHelper {
});
- browseFolderButton = new Button(composite, SWT.NONE);
- browseFolderButton.setText(Messages
- .getString("button.selectFolder.browse")); //$NON-NLS-1$
- browseFolderButton.addSelectionListener(new SelectionAdapter() {
+ browseFolderButton = new MenuButton( composite, SWT.NONE );
+ browseFolderButton.setText( Messages.getString( "button.selectFolder.browse" ) ); //$NON-NLS-1$
- /*
- * @see
- * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog dialog = new DirectoryDialog(folderLocation
- .getShell());
- String folderLocationValue = getFolderLocationString();
- if (folderLocationValue != null
- && folderLocationValue.trim().length() > 0) {
- dialog.setFilterPath(folderLocationValue);
+ Menu menu = new Menu( composite.getShell( ), SWT.POP_UP );
+ SelectionAdapter action = new SelectionAdapter( ) {
+
+ public void widgetSelected( SelectionEvent e )
+ {
+ if ( e.widget instanceof MenuItem )
+ {
+ MenuItem item = (MenuItem) e.widget;
+ Integer type = (Integer) item.getData( );
+ handleFileSelection( type );
+ }
+ else if ( e.widget instanceof MenuButton )
+ {
+ handleFileSelection( SELECT_RELATIVE_PATH );
}
+ }
+ };
+
+ MenuItem item;
+ if ( ri != null )
+ {
+ item = new MenuItem( menu, SWT.PUSH );
+ item.setText( Messages.getString( "button.selectFileURI.menuItem.relativePath" ) ); //$NON-NLS-1$
+ item.setData( SELECT_RELATIVE_PATH );
+ item.addSelectionListener( action );
+ }
+
+ item = new MenuItem( menu, SWT.PUSH );
+ item.setText( Messages.getString( "button.selectFileURI.menuItem.absolutePath" ) ); //$NON-NLS-1$
+ item.setData( SELECT_ABSOLUTE_PATH );
+ item.addSelectionListener( action );
+
+ // Add relative path selection support while having resource identifier
+ browseFolderButton.setDropDownMenu( menu );
+ browseFolderButton.addSelectionListener( action );
+
+ }
+
- dialog.setMessage(DEFAULT_MESSAGE);
- String selectedLocation = dialog.open();
- if (selectedLocation != null) {
- setFolderLocationString(selectedLocation);
+ public void setResourceIdentifiers( org.eclipse.datatools.connectivity.oda.design.ResourceIdentifiers resourceIdentifiers )
+ {
+ if ( resourceIdentifiers != null )
+ {
+ this.ri = DesignSessionUtil.createRuntimeResourceIdentifiers( resourceIdentifiers );
+ }
+ }
+
+ private String getResourceFolder( )
+ {
+ if ( ri != null )
+ {
+ if ( ri.getApplResourceBaseURI( ) != null )
+ {
+ return new File(ri.getApplResourceBaseURI( )).getAbsolutePath( );
+ }
+ }
+ return null;
+ }
+
+
+ private void handleFileSelection( int selectionType )
+ {
+ if ( selectionType == SELECT_RELATIVE_PATH )
+ {
+ RelativeFolderSelectionDialog dialog = new RelativeFolderSelectionDialog( folderLocation.getShell( ),
+ new File( getResourceFolder( ) ) );
+ if ( dialog.open( ) == Window.OK )
+ {
+ try
+ {
+ URI uri = dialog.getSelectedURI( );
+ if ( uri != null )
+ {
+ if (uri.getPath().trim().equals(""))
+ {
+ setFolderLocationString( CURRENT_DIRECTORY );
+ }
+ else
+ {
+ setFolderLocationString( uri.getPath( ) );
+ }
+ }
+ }
+ catch ( URISyntaxException e )
+ {
}
}
- });
+ }
+ else if ( selectionType == SELECT_ABSOLUTE_PATH )
+ {
+ DirectoryDialog dialog = new DirectoryDialog( folderLocation.getShell( ) );
+ String folderLocationValue = getFolderLocationString( );
+ if ( folderLocationValue != null
+ && folderLocationValue.trim( ).length( ) > 0 )
+ {
+ dialog.setFilterPath( folderLocationValue );
+ }
+
+ dialog.setMessage( DEFAULT_MESSAGE );
+ String selectedLocation = dialog.open( );
+ if ( selectedLocation != null )
+ {
+ setFolderLocationString( selectedLocation );
+ }
+ }
}
/**
@@ -279,25 +382,93 @@ public class ExcelDataSourcePageHelper {
propertyPage.setValid(complete);
}
+
+ public Runnable createTestConnectionRunnable(
+ final IConnectionProfile profile )
+ {
+ return new Runnable( ) {
+
+ public void run( )
+ {
+ IConnection conn = PingJob.createTestConnection( profile );
+
+ Throwable exception = PingJob.getTestConnectionException( conn );
+
+ if ( exception == null ) // succeed in creating connection
+ {
+ exception = testConnection( );
+ }
+
+ PingJob.PingUIJob.showTestConnectionMessage( parent.getShell( ),
+ exception );
+ if ( conn != null )
+ {
+ conn.close( );
+ }
+ }
+
+ private Throwable testConnection( )
+ {
+ Throwable exception = null;
+ try
+ {
+ int verify = verifyFileLocation( );
+ if ( verify == ERROR_FOLDER )
+ {
+ throw new OdaException( Messages.getString( "connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR" ) );//$NON-NLS-1$
+ }
+ }
+ catch ( Exception ex )
+ {
+ exception = ex;
+ }
+ return exception;
+ }
+ };
+ }
+
/**
*
* @return
*/
- private int verifyFileLocation() {
+ private int verifyFileLocation( ) {
int result = CORRECT_FOLDER;
- String folderLocationValue = getFolderLocationString();
- if (folderLocationValue.trim().length() > 0) {
- File f = new File(folderLocationValue.trim());
- if (f.exists()) {
- setMessage(DEFAULT_MESSAGE, IMessageProvider.NONE);
- setPageComplete(true);
- } else {
- setMessage(
- Messages.getString("error.selectFolder"), IMessageProvider.ERROR); //$NON-NLS-1$
- setPageComplete(false);
+ String folderLocationValue = getFolderLocationString().trim();
+ if ( folderLocationValue.length( ) > 0 )
+ {
+ File f = new File( folderLocationValue );
+ if ( !f.isAbsolute( ) )
+ {
+ folderLocationValue = getResourceFolder( )
+ + File.separator + folderLocationValue;
+ f = new File( folderLocationValue.trim( ) );
+ }
+ if ( f.exists( ) )
+ {
+ if (f.isDirectory() ) {
+ File[] files = f.getAbsoluteFile().listFiles(
+ new ExcelFileFilter());
+ if (files.length == 0)
+ {
+ setMessage( Messages.getString( "error.emptyFolder" ), IMessageProvider.ERROR ); //$NON-NLS-1$
+ setPageComplete( false );
+ result = ERROR_FOLDER;
+ }
+ else
+ {
+ setMessage( DEFAULT_MESSAGE, IMessageProvider.NONE );
+ setPageComplete( true );
+ }
+ }
+ }
+ else
+ {
+ setMessage( Messages.getString( "error.selectFolder" ), IMessageProvider.ERROR ); //$NON-NLS-1$
+ setPageComplete( false );
result = ERROR_FOLDER;
}
- } else {
+ }
+ else {
setMessage(
Messages.getString("error.emptyPath"), IMessageProvider.ERROR); //$NON-NLS-1$
setPageComplete(false);
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePropertyPage.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePropertyPage.java
index cc396bf..0916511 100644
--- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePropertyPage.java
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePropertyPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Megha Nidhi Dahal.
+ * Copyright (c) 2012 Megha Nidhi Dahal and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
+ * Actuate Corporation - added support of relative file path
*******************************************************************************/
@@ -14,6 +15,7 @@ package org.eclipse.birt.report.data.oda.excel.ui.wizards;
import java.util.Properties;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSourceEditorPage;
import org.eclipse.swt.widgets.Composite;
@@ -52,7 +54,7 @@ public class ExcelDataSourcePropertyPage extends DataSourceEditorPage
{
if ( pageHelper == null )
pageHelper = new ExcelDataSourcePageHelper( this );
-
+ pageHelper.setResourceIdentifiers( getHostResourceIdentifiers( ) );
pageHelper.createCustomControl( parent );
/*
@@ -82,4 +84,12 @@ public class ExcelDataSourcePropertyPage extends DataSourceEditorPage
enableAllControls( getControl(), isSessionEditable() );
}
+ /* (non-Javadoc)
+ * @see org.eclipse.datatools.connectivity.oda.design.internal.ui.DataSourceEditorPageCore#createTestConnectionRunnable(org.eclipse.datatools.connectivity.IConnectionProfile)
+ */
+ protected Runnable createTestConnectionRunnable( IConnectionProfile profile )
+ {
+ return pageHelper.createTestConnectionRunnable( profile );
+ }
+
}
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourceWizardPage.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourceWizardPage.java
index 7e63f03..14b7a77 100644
--- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourceWizardPage.java
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourceWizardPage.java
@@ -8,6 +8,7 @@
* Contributors:
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - added support of read-only design session
+ * Actuate Corporation - added support of relative file path
******************************************************************************
**/
@@ -15,6 +16,7 @@ package org.eclipse.birt.report.data.oda.excel.ui.wizards;
import java.util.Properties;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSourceWizardPage;
import org.eclipse.swt.widgets.Composite;
@@ -36,6 +38,7 @@ public class ExcelDataSourceWizardPage extends DataSourceWizardPage{
{
if ( pageHelper == null )
pageHelper = new ExcelDataSourcePageHelper( this );
+ pageHelper.setResourceIdentifiers( getHostResourceIdentifiers( ) );
pageHelper.createCustomControl( parent );
pageHelper.initCustomControl( folderProperties ); // in case init was called before create
@@ -84,4 +87,13 @@ public class ExcelDataSourceWizardPage extends DataSourceWizardPage{
enableAllControls( getControl(), isSessionEditable() );
}
+ /* (non-Javadoc)
+ * @see org.eclipse.datatools.connectivity.oda.design.internal.ui.DataSourceWizardPageCore#createTestConnectionRunnable(org.eclipse.datatools.connectivity.IConnectionProfile)
+ */
+ protected Runnable createTestConnectionRunnable( IConnectionProfile profile )
+ {
+ return pageHelper.createTestConnectionRunnable( profile );
+ }
+
+
}
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java
index f550038..641d978 100644
--- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java
@@ -8,6 +8,7 @@
* Contributors:
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - support of timestamp, datetime, time, and date data types
+ * Actuate Corporation - added support of relative file path
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.ui.wizards;
@@ -38,6 +39,7 @@ import org.eclipse.datatools.connectivity.oda.design.ResultSetColumns;
import org.eclipse.datatools.connectivity.oda.design.ResultSetDefinition;
import org.eclipse.datatools.connectivity.oda.design.ui.designsession.DesignSessionUtil;
import org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSetWizardPage;
+import org.eclipse.datatools.connectivity.oda.util.ResourceIdentifiers;
import org.eclipse.datatools.connectivity.oda.util.manifest.ConnectionProfileProperty;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
@@ -142,6 +144,7 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
private java.util.List<String[]> originalFileColumnsInfoList = new ArrayList<String[]>();
private java.util.List<String[]> savedSelectedColumnsInfoList = new ArrayList<String[]>();
+ private ResourceIdentifiers ri;
/**
* @param pageName
*/
@@ -879,6 +882,11 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
.getProperty(ConnectionProfileProperty.PROFILE_STORE_FILE_PATH_PROP_KEY);
if (sourcePath != null) {
File cpFile = new File(sourcePath);
+ if ( !cpFile.isAbsolute( ) )
+ {
+ cpFile = new File( getResourceFolder( )
+ + File.separator + cpFile );
+ }
if (!cpFile.exists()) {
setMessage(
Messages.getFormattedString(
@@ -904,6 +912,38 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
}
}
+ private String getResourceFolder( )
+ {
+ if ( ri == null )
+ {
+ ri = DesignSessionUtil.createRuntimeResourceIdentifiers( getHostResourceIdentifiers( ) );
+ }
+ if ( ri != null )
+ {
+ if ( ri.getApplResourceBaseURI( ) != null )
+ {
+ return new File( ri.getApplResourceBaseURI( ) ).getAbsolutePath( );
+ }
+ }
+ return null;
+ }
+
+ static class ExcelFileFilter implements FilenameFilter {
+ @Override
+ public boolean accept(File dir, String fileName) {
+ File file = new File(dir + File.separator + fileName);
+ if (file.isFile() && !file.isHidden()) {
+ if (fileName.endsWith(ExcelODAConstants.XLS_FORMAT)
+ || fileName
+ .endsWith(ExcelODAConstants.XLSX_FORMAT))
+ return true;
+
+ return false;
+ } else
+ return false;
+ }
+ }
+
/**
* Update file list in combo viewer
*/
@@ -915,24 +955,14 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
}
File folder = new File(odaHome);
- FilenameFilter filenameFilter = new FilenameFilter() {
- @Override
- public boolean accept(File dir, String fileName) {
- File file = new File(dir + File.separator + fileName);
- if (file.isFile() && !file.isHidden()) {
- if (fileName.endsWith(ExcelODAConstants.XLS_FORMAT)
- || fileName
- .endsWith(ExcelODAConstants.XLSX_FORMAT))
- return true;
-
- return false;
- } else
- return false;
- }
- };
+ if ( !folder.isAbsolute( ) )
+ {
+ folder = new File( getResourceFolder( )
+ + File.separator + folder );
+ }
if (folder.isDirectory() && folder.exists()) {
File[] files = folder.getAbsoluteFile().listFiles(
- filenameFilter);
+ new ExcelFileFilter());
if (files != null) {
fileViewer.setInput(files);
@@ -1159,6 +1189,10 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
savedSelectedColumnsInfoString = (new QueryTextUtil(queryText))
.getColumnsInfo();
+ Map<String, Object> appContext =
+ DesignSessionUtil.createResourceIdentifiersContext( getHostResourceIdentifiers() );
+ conn.setAppContext( appContext );
+
conn.open(prop);
IQuery query = conn.newQuery(null);
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java
new file mode 100644
index 0000000..64f50c5
--- /dev/null
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java
@@ -0,0 +1,485 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Actuate Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Actuate Corporation - added support of relative file path
+ *******************************************************************************/
+
+package org.eclipse.birt.report.data.oda.excel.ui.wizards;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+
+/**
+ *
+ */
+
+public class MenuButton extends Composite
+{
+
+ private Button button;
+
+ private String text;
+ private Image image;
+
+ public String getText( )
+ {
+ return text;
+ }
+
+ public Image getImage( )
+ {
+ return image;
+ }
+
+ private static final int IMAGE_HEIGHT = 16, IMAGE_WIDTH = 16;
+
+ private static int DRAW_FLAGS = SWT.DRAW_MNEMONIC
+ | SWT.DRAW_TAB
+ | SWT.DRAW_TRANSPARENT
+ | SWT.DRAW_DELIMITER;
+
+ private static final int MARGIN_GAP = 4;
+
+ private static final int TRIANGLE_WIDTH = 5;
+
+ private static final int WIDTH_MORE = 2 * MARGIN_GAP + TRIANGLE_WIDTH + 1;
+
+ public void setText( String text )
+ {
+ this.text = text;
+ layoutControl( );
+ }
+
+ public void setToolTipText( String string )
+ {
+ button.setToolTipText( string );
+ }
+
+ private void layoutControl( )
+ {
+ getParent( ).layout( );
+ button.redraw( );
+ }
+
+ private Point defaultSize = new Point( 0, 0 );
+
+ public Point computeSize( int wHint, int hHint, boolean changed )
+ {
+
+ int width;
+ int height;
+
+ Button tmp = new Button( this, button.getStyle( ) );
+ if ( text != null )
+ {
+ tmp.setText( text );
+ height = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT ).y;
+ }
+ else
+ {
+ tmp.setText( "" ); //$NON-NLS-1$
+ height = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT ).y;
+ }
+ if ( image != null )
+ tmp.setImage( image );
+ Point size = tmp.computeSize( SWT.DEFAULT, SWT.DEFAULT );
+ tmp.dispose( );
+
+ if ( menu != null )
+ {
+ width = size.x + WIDTH_MORE;
+ }
+ else
+ width = size.x;
+
+ if ( isFixed && image != null )
+ {
+ int imageWidth = image.getImageData( ).width;
+ if ( imageWidth > IMAGE_WIDTH )
+ width -= ( imageWidth - IMAGE_WIDTH );
+
+ }
+ if ( !isFixed )
+ height = size.y;
+ defaultSize = new Point( width, height );
+ if ( wHint != SWT.DEFAULT )
+ width = wHint;
+ if ( hHint != SWT.DEFAULT )
+ height = hHint;
+
+ return new Point( width, height );
+ }
+
+ public void setImage( Image image )
+ {
+ this.image = image;
+ layoutControl( );
+ }
+
+ public void setBackground( Color color )
+ {
+ super.setBackground( color );
+ button.setBackground( color );
+ button.redraw( );
+ }
+
+ public void setForeground( Color color )
+ {
+ super.setBackground( color );
+ button.setForeground( color );
+ button.redraw( );
+ }
+
+ public void setFont( Font font )
+ {
+ super.setFont( font );
+ button.setFont( font );
+ button.redraw( );
+ }
+
+ public void setEnabled( boolean enable )
+ {
+ super.setEnabled( enable );
+ button.setEnabled( enable );
+ button.redraw( );
+ }
+
+ public MenuButton( Composite parent, int style )
+ {
+ this( parent, style, false );
+ }
+
+ private boolean isFixed = true;
+
+ private boolean mouseSelection = false;
+
+ public MenuButton( Composite parent, int style, boolean fixed )
+ {
+ super( parent, SWT.NONE );
+ isFixed = fixed;
+ GridLayout layout = new GridLayout( );
+ layout.marginHeight = layout.marginWidth = 0;
+ this.setLayout( layout );
+
+ button = new Button( this, style );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ button.setLayoutData( gd );
+ button.addPaintListener( new PaintListener( ) {
+
+ public void paintControl( PaintEvent e )
+ {
+ MenuButton.this.paintControl( e );
+ }
+ } );
+ button.addListener( SWT.MouseUp, new Listener( ) {
+
+ public void handleEvent( Event e )
+ {
+ if ( !button.isEnabled( ) || e.button != 1 )
+ return;
+ mouseSelection = true;
+ Rectangle size = button.getBounds( );
+ if ( !size.contains( e.x, e.y ) )
+ return;
+ int left = WIDTH_MORE + MARGIN_GAP - 1;
+ if ( menu == null )
+ left = 0;
+
+ if ( e.x < size.width - left )
+ {
+ if ( listeners == null )
+ return;
+
+ e.widget = MenuButton.this;
+
+ for ( int i = 0; i < listeners.size( ); i++ )
+ {
+ ( (SelectionListener) listeners.get( i ) ).widgetSelected( new SelectionEvent( e ) );
+ }
+ }
+ else
+ {
+ if ( menu != null )
+ {
+ menu.setLocation( button.toDisplay( new Point( 0,
+ size.height - 1 ) ) );
+ menu.setVisible( true );
+ }
+ }
+ }
+
+ } );
+ button.addListener( SWT.KeyUp, new Listener( ) {
+
+ public void handleEvent( Event e )
+ {
+ if ( e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP )
+ {
+ if ( menu != null )
+ {
+ Rectangle size = button.getBounds( );
+ menu.setLocation( button.toDisplay( new Point( 0,
+ size.height - 1 ) ) );
+ menu.setVisible( true );
+ }
+ }
+ }
+
+ } );
+ button.addListener( SWT.Selection, new Listener( ) {
+
+ public void handleEvent( Event e )
+ {
+ if ( mouseSelection == true )
+ {
+ mouseSelection = false;
+ return;
+ }
+
+ if ( listeners == null )
+ return;
+
+ e.widget = MenuButton.this;
+
+ for ( int i = 0; i < listeners.size( ); i++ )
+ {
+ ( (SelectionListener) listeners.get( i ) ).widgetSelected( new SelectionEvent( e ) );
+ }
+ }
+
+ } );
+ }
+
+ private Menu menu;
+
+ public void setDropDownMenu( Menu menu )
+ {
+ this.menu = menu;
+ }
+
+ private List<SelectionListener> listeners;
+
+ public void addSelectionListener( SelectionListener listener )
+ {
+ if ( listeners == null )
+ listeners = new ArrayList<SelectionListener>( );
+ listeners.add( listener );
+ }
+
+ public void removeSelectionListener( SelectionListener listener )
+ {
+ if ( listeners != null )
+ {
+ listeners.remove( listener );
+ if ( listeners.size( ) == 0 )
+ listeners = null;
+ }
+ }
+
+ public static RGB blend( RGB c1, RGB c2, int ratio )
+ {
+ int r = blend( c1.red, c2.red, ratio );
+ int g = blend( c1.green, c2.green, ratio );
+ int b = blend( c1.blue, c2.blue, ratio );
+ return new RGB( r, g, b );
+ }
+
+ private static int blend( int v1, int v2, int ratio )
+ {
+ int b = ( ratio * v1 + ( 100 - ratio ) * v2 ) / 100;
+ return Math.min( 255, b );
+ }
+
+ public static void drawArrow( GC gc, Rectangle rect, int style )
+ {
+ Point point = new Point( rect.x + ( rect.width / 2 ), rect.y
+ + ( rect.height / 2 ) );
+ int[] points = null;
+ switch ( style )
+ {
+ case SWT.LEFT :
+ points = new int[]{
+ point.x + 2,
+ point.y - 4,
+ point.x + 2,
+ point.y + 4,
+ point.x - 2,
+ point.y
+ };
+ gc.fillPolygon( points );
+ break;
+
+ /*
+ * Low efficiency because of Win98 bug.
+ */
+ case SWT.UP :
+ gc.fillRectangle( new Rectangle( point.x, point.y - 1, 1, 1 ) );
+ gc.fillRectangle( new Rectangle( point.x - 1, point.y, 3, 1 ) );
+ gc.fillRectangle( new Rectangle( point.x - 2, point.y + 1, 5, 1 ) );
+ break;
+
+ case SWT.RIGHT :
+ points = new int[]{
+ point.x - 2,
+ point.y - 4,
+ point.x - 2,
+ point.y + 4,
+ point.x + 2,
+ point.y
+ };
+ gc.fillPolygon( points );
+ break;
+
+ /*
+ * Low efficiency because of Win98 bug.
+ */
+ default :
+ gc.fillRectangle( new Rectangle( point.x - 2, point.y - 1, 5, 1 ) );
+ gc.fillRectangle( new Rectangle( point.x - 1, point.y, 3, 1 ) );
+ gc.fillRectangle( new Rectangle( point.x, point.y + 1, 1, 1 ) );
+ break;
+ }
+
+ }
+
+ protected void paintControl( PaintEvent e )
+ {
+ e.gc.setFont( getFont( ) );
+ Color fg = isEnabled( ) ? getForeground( )
+ : new Color( e.gc.getDevice( ),
+ blend( getBackground( ).getRGB( ),
+ getForeground( ).getRGB( ),
+ 70 ) );
+ try
+ {
+ e.gc.setForeground( fg );
+ Color bgColor = e.gc.getBackground( );
+ e.gc.setBackground( e.gc.getForeground( ) );
+ Rectangle size = button.getBounds( );
+
+ if ( menu != null )
+ {
+ Rectangle rect = new Rectangle( size.width - 12,
+ 0,
+ TRIANGLE_WIDTH,
+ size.height );
+ drawArrow( e.gc, rect, SWT.DOWN );
+ }
+
+ e.gc.setBackground( bgColor );
+
+ int height = e.gc.textExtent( "", DRAW_FLAGS ).y; //$NON-NLS-1$
+
+ if ( !isFixed && image != null )
+ {
+ int imageHeight = image.getImageData( ).height;
+ if ( height < imageHeight )
+ height = imageHeight;
+ }
+
+ if ( defaultSize.y > size.height )
+ {
+ height = height - ( defaultSize.y - size.height );
+ height = e.gc.textExtent( "", DRAW_FLAGS ).y > height ? e.gc.textExtent( "", //$NON-NLS-1$//$NON-NLS-2$
+ DRAW_FLAGS ).y
+ : height;
+ }
+
+ int left = WIDTH_MORE + MARGIN_GAP - 1;
+
+ if ( menu == null )
+ left = MARGIN_GAP - 1;
+
+ if ( menu != null )
+ {
+ Color fgColor = e.gc.getForeground( );
+ e.gc.setForeground( getDisplay( ).getSystemColor( SWT.COLOR_WIDGET_NORMAL_SHADOW ) );
+ e.gc.drawLine( size.width - left,
+ ( size.height - height ) / 2,
+ size.width - left,
+ ( size.height - height ) / 2 + height );
+ e.gc.setForeground( fgColor );
+ }
+
+ if ( text != null && text.trim( ).length( ) > 0 )
+ {
+ int width = e.gc.textExtent( text, DRAW_FLAGS ).x;
+ int fontHeight = e.gc.textExtent( text, DRAW_FLAGS ).y;
+ left += ( MARGIN_GAP + width );
+ e.gc.drawText( text,
+ ( size.width - left ) / 2 + MARGIN_GAP,
+ ( size.height - fontHeight ) / 2,
+ DRAW_FLAGS | SWT.DRAW_TRANSPARENT );
+ }
+
+ if ( image != null )
+ {
+ int imageWidth = image.getImageData( ).width;
+ int imageHeight = image.getImageData( ).height;
+
+ Image imageTemp;
+
+ if ( isEnabled( ) )
+ imageTemp = new Image( e.gc.getDevice( ),
+ image,
+ SWT.IMAGE_COPY );
+ else
+ imageTemp = new Image( e.gc.getDevice( ),
+ image,
+ SWT.IMAGE_DISABLE );
+
+ if ( isFixed )
+ {
+ imageWidth = imageWidth > IMAGE_WIDTH ? IMAGE_WIDTH
+ : imageWidth;
+ imageHeight = imageHeight > IMAGE_HEIGHT ? IMAGE_HEIGHT
+ : imageHeight;
+ }
+
+ left += ( MARGIN_GAP + imageWidth );
+ e.gc.drawImage( imageTemp,
+ 0,
+ 0,
+ imageTemp.getImageData( ).width,
+ imageTemp.getImageData( ).height,
+ ( size.width - left ) / 2 + MARGIN_GAP,
+ Math.round( ( (float) ( size.height - imageHeight ) / 2 ) ),
+ imageWidth,
+ imageHeight );
+
+ imageTemp.dispose( );
+ }
+
+ }
+ finally
+ {
+ if ( !isEnabled( ) && fg != null )
+ fg.dispose( );
+ }
+ }
+}
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFolderSelectionDialog.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFolderSelectionDialog.java
new file mode 100644
index 0000000..d661e3c
--- /dev/null
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFolderSelectionDialog.java
@@ -0,0 +1,301 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Actuate Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Actuate Corporation - added support of relative file path
+ *******************************************************************************/
+
+package org.eclipse.birt.report.data.oda.excel.ui.wizards;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.birt.report.data.oda.excel.ui.i18n.Messages;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+
+public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
+{
+
+ private final static Image IMG_FOLDER = PlatformUI.getWorkbench( )
+ .getSharedImages( )
+ .getImage( ISharedImages.IMG_OBJ_FOLDER );
+
+ private final static Image IMG_FILE = PlatformUI.getWorkbench( )
+ .getSharedImages( )
+ .getImage( ISharedImages.IMG_OBJ_FILE );
+
+ private File rootFolder;
+
+ public RelativeFolderSelectionDialog( Shell parent, File rootFolder )
+ {
+ super( parent, new LabelProvider( ), new ContentProvider( ) );
+
+ assert rootFolder != null;
+
+ this.setValidator( new SelectionValidator( ) );
+ this.setInput( rootFolder.getAbsolutePath( ) );
+ this.setTitle( Messages.getString( "RelativeFolderSelectionDialog.Title.SelectFolder" ) ); //$NON-NLS-1$
+ this.rootFolder = rootFolder;
+ }
+
+ public URI getSelectedURI( ) throws URISyntaxException
+ {
+ Object[] selection = getResult( );
+ if ( selection != null && selection.length > 0 )
+ {
+ if ( selection[0] instanceof File )
+ {
+ URI baseURI = rootFolder.toURI( );
+ return baseURI.relativize( ( (File) selection[0] ).toURI( ) );
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.dialogs.ElementTreeSelectionDialog#createDialogArea(org
+ * .eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea( Composite parent )
+ {
+ Control c = super.createDialogArea( parent );
+ this.getTreeViewer( ).expandToLevel( 2 );
+ return c;
+ }
+
+ private static class ContentProvider implements ITreeContentProvider
+ {
+
+ public Object[] getChildren( Object arg0 )
+ {
+ if ( arg0 instanceof File )
+ {
+ File f = (File) arg0;
+ return RelativeFolderSelectionDialog.getChildren( f );
+ }
+ return null;
+ }
+
+ public Object getParent( Object arg0 )
+ {
+ return null;
+ }
+
+ public boolean hasChildren( Object arg0 )
+ {
+ if ( arg0 instanceof File )
+ {
+ File f = (File) arg0;
+ return RelativeFolderSelectionDialog.getChildren( f ).length > 0;
+ }
+ return false;
+ }
+
+ public Object[] getElements( Object arg0 )
+ {
+ if ( arg0 instanceof String )
+ {
+ return new Object[]{
+ new File( (String) arg0 )
+ };
+ }
+ return null;
+ }
+
+ public void dispose( )
+ {
+
+ }
+
+ public void inputChanged( Viewer arg0, Object arg1, Object arg2 )
+ {
+
+ }
+ }
+
+ private static class LabelProvider implements ILabelProvider
+ {
+
+ public Image getImage( Object arg0 )
+ {
+ if ( arg0 instanceof File )
+ {
+ File f = (File) arg0;
+ if ( f.isFile( ) )
+ {
+ return IMG_FILE;
+ }
+ return IMG_FOLDER;
+ }
+ return null;
+ }
+
+ public String getText( Object arg0 )
+ {
+ if ( arg0 instanceof File )
+ {
+ File f = (File) arg0;
+ if ( f.getName( ).trim( ).equals( "" ) ) //$NON-NLS-1$
+ {
+ // For the case "File("C:\\")"
+ return f.getPath( );
+ }
+ return f.getName( );
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public void addListener( ILabelProviderListener arg0 )
+ {
+
+ }
+
+ public void dispose( )
+ {
+
+ }
+
+ public boolean isLabelProperty( Object arg0, String arg1 )
+ {
+ return false;
+ }
+
+ public void removeListener( ILabelProviderListener arg0 )
+ {
+
+ }
+
+ }
+
+ private static class SelectionValidator
+ implements
+ ISelectionStatusValidator
+ {
+
+ public IStatus validate( Object[] selections )
+ {
+ if ( selections != null && selections.length > 0 )
+ {
+ for ( Object o : selections )
+ {
+ if ( o instanceof File )
+ {
+ if ( ( (File) o ).isDirectory( ) )
+ {
+ return new Status( IStatus.OK,
+ "org.eclipse.birt.report.data.oda.excel.ui", //$NON-NLS-1$
+ IStatus.OK,
+ "", //$NON-NLS-1$
+ null );
+ }
+ }
+ }
+ }
+ return new Status( IStatus.ERROR,
+ "org.eclipse.birt.report.data.oda.excel.ui", //$NON-NLS-1$
+ IStatus.ERROR,
+ "", //$NON-NLS-1$
+ null );
+ }
+
+ }
+
+ private static File[] getChildren( File f )
+ {
+ if ( !f.isDirectory( ) )
+ {
+ return new File[0];
+ }
+ File[] result = f.listFiles( new FileFilter( ) {
+
+ public boolean accept( File child )
+ {
+ if ( child.isFile( ) )
+ {
+ return true;
+ }
+ return true;
+ }
+ } );
+ if ( result != null )
+ {
+ Arrays.sort( result, new FileComparator( ) );
+ }
+ return result == null ? new File[0] : result;
+ }
+
+ public String[] getSelectedItems( )
+ {
+ List<String> result = new ArrayList<String>( );
+ Object[] selected = this.getResult( ) == null ? new Object[0]
+ : this.getResult( );
+ for ( Object o : selected )
+ {
+ File f = (File) o;
+ if ( f.isDirectory( ) )
+ {
+ URI relative = rootFolder.toURI( ).relativize( f.toURI( ) );
+ result.add( relative.getPath( ) );
+ }
+ }
+
+ return result.toArray( new String[0] );
+ }
+
+ public static class FileComparator
+ implements
+ Comparator<File>,
+ Serializable
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ public int compare( File o1, File o2 )
+ {
+ if ( o1.isDirectory( ) && o2.isDirectory( ) )
+ {
+ return o1.getName( ).compareTo( o2.getName( ) );
+ }
+ else if ( o1.isFile( ) && o2.isFile( ) )
+ {
+ return o1.getName( ).compareTo( o2.getName( ) );
+ }
+ else if ( o1.isDirectory( ) && !o2.isDirectory( ) )
+ {
+ return -1;
+ }
+ else
+ {
+ // o1 is not a directory but o2 is a directory
+ return 1;
+ }
+ }
+ }
+}
diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java
index 421eab2..39a2cd3 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java
+++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java
@@ -8,12 +8,13 @@
* Contributors:
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - code cleanup
+ * Actuate Corporation - added support of relative file path
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.impl;
-import java.io.File;
+import java.util.Map;
import java.util.Properties;
import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants;
@@ -22,6 +23,7 @@ import org.eclipse.datatools.connectivity.oda.IConnection;
import org.eclipse.datatools.connectivity.oda.IDataSetMetaData;
import org.eclipse.datatools.connectivity.oda.IQuery;
import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.eclipse.datatools.connectivity.oda.util.ResourceIdentifiers;
import com.ibm.icu.util.ULocale;
@@ -31,7 +33,7 @@ import com.ibm.icu.util.ULocale;
public class Connection implements IConnection {
private boolean isOpen = false;
private Properties connProperties;
-
+ private Map appContext = null;
/*
* @see
* org.eclipse.datatools.connectivity.oda.IConnection#open(java.util.Properties
@@ -46,21 +48,16 @@ public class Connection implements IConnection {
validateHomeDir();
}
- private void validateHomeDir() throws OdaException {
- String homeDir = connProperties
- .getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP);
- if (homeDir != null) // found property
+ // move the test connection to ExcelDataSourcePageHelper.createTestConnectionRunnable
+ private void validateHomeDir( ) throws OdaException
+ {
+ String homeDir = connProperties.getProperty( ExcelODAConstants.CONN_HOME_DIR_PROP );
+ if ( homeDir != null && homeDir.trim( ).length( ) > 0 ) // found
{
- File file = new File(homeDir);
- if (file.exists()) {
- this.isOpen = true;
- return; // is valid, done
- }
+ this.isOpen = true;
+ return; // is valid, done
}
-
- throw new OdaException(
- Messages.getString("connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR") //$NON-NLS-1$
- + homeDir);
+ throw new OdaException( Messages.getString( "connection_MISSING_FILELOCATION" ));
}
/*
@@ -70,6 +67,7 @@ public class Connection implements IConnection {
*/
public void setAppContext(Object context) throws OdaException {
// do nothing; assumes no support for pass-through context
+ this.appContext = (Map) context;
}
/*
@@ -112,6 +110,11 @@ public class Connection implements IConnection {
return new ExcelFileQuery(connProperties, this);
}
+ public ResourceIdentifiers getResourceIdentifiers( )
+ {
+ return (ResourceIdentifiers) appContext.get( ResourceIdentifiers.ODA_APP_CONTEXT_KEY_CONSUMER_RESOURCE_IDS );
+ }
+
/*
* @see org.eclipse.datatools.connectivity.oda.IConnection#getMaxQueries()
*/
diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java
index 789457c..27318b8 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java
+++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java
@@ -9,6 +9,7 @@
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - more efficient xlsx processing;
* support of timestamp, datetime, time, and date data types
+ * Actuate Corporation - added support of relative file path
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.impl;
@@ -193,7 +194,7 @@ public class ExcelFileQuery implements IQuery {
// from a xlsx file
ExcelFileSource excelFileReader = new ExcelFileSource(connProperties,
currentTableName, worksheetNames, maxRowsToRead, null,
- null);
+ null, connection);
String[] allColumnNames;
String[] allColumnTypes;
@@ -489,7 +490,7 @@ public class ExcelFileQuery implements IQuery {
// from a xlsx file
ExcelFileSource excelFileSource = new ExcelFileSource(
this.connProperties, tableName, worksheetNames,
- maxRowsToRead, null, null);
+ maxRowsToRead, null, null, connection);
try {
if (!(metaDataType.trim().equalsIgnoreCase(NAME_LITERAL) || metaDataType
.trim().equalsIgnoreCase(TYPE_LITERAL)))
@@ -655,7 +656,7 @@ public class ExcelFileQuery implements IQuery {
return new ResultSet(new ExcelFileSource(this.connProperties,
this.currentTableName, worksheetNames,
this.maxRows, this.resultSetMetaData,
- this.resultSetMetaDataHelper), this.resultSetMetaData);
+ this.resultSetMetaDataHelper, connection), this.resultSetMetaData);
}
/*
diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java
index a9deb5f..5e05013 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java
+++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java
@@ -9,6 +9,7 @@
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - more efficient xlsx processing;
* support of timestamp, datetime, time, and date data types
+ * Actuate Corporation - added support of relative file path
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.impl.util;
@@ -24,8 +25,10 @@ import java.util.Properties;
import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants;
import org.eclipse.birt.report.data.oda.excel.ResultSetMetaDataHelper;
import org.eclipse.birt.report.data.oda.excel.impl.i18n.Messages;
+import org.eclipse.datatools.connectivity.oda.IConnection;
import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.eclipse.datatools.connectivity.oda.util.ResourceIdentifiers;
public class ExcelFileSource {
private String fileExtension;
@@ -48,7 +51,7 @@ public class ExcelFileSource {
private String[] originalColumnNames;
private boolean isFirstTimeToReadSourceData = true;
private List<String> nextDataLine;
-
+ private IConnection connection;
/**
* Constructor
*
@@ -67,12 +70,12 @@ public class ExcelFileSource {
public ExcelFileSource(Properties connProperties, String currentTableName,
String workSheetNames,
int statementMaxRows, IResultSetMetaData rsmd,
- ResultSetMetaDataHelper rsmdHelper) throws OdaException {
+ ResultSetMetaDataHelper rsmdHelper, IConnection connection) throws OdaException {
this.rsmd = rsmd;
this.rsmdHelper = rsmdHelper;
this.statementMaxRows = statementMaxRows;
this.currentTableName = currentTableName;
-
+ this.connection = connection;
this.fileExtension = extractFileExtension(currentTableName);
Properties properties = getCopyOfConnectionProperties(connProperties);
populateHomeDir(properties);
@@ -122,12 +125,28 @@ public class ExcelFileSource {
this.homeDir = connProperties
.getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP);
File file = new File(this.homeDir);
+ if ( !file.isAbsolute( ) )
+ {
+ file = new File( getAbsoluteFile( ) + File.separator + homeDir );
+ }
if (!file.exists())
throw new OdaException(
Messages.getString("connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR") //$NON-NLS-1$
+ this.homeDir);
}
+
+ private String getAbsoluteFile( )
+ {
+ ResourceIdentifiers ri = ( (org.eclipse.birt.report.data.oda.excel.impl.Connection) connection ).getResourceIdentifiers( );
+ if ( ri.getApplResourceBaseURI( ) != null )
+ {
+ return new File( ri.getApplResourceBaseURI( ) ).getAbsolutePath( );
+ }
+
+ return null;
+ }
+
/**
*
* @param connProperties
@@ -210,6 +229,12 @@ public class ExcelFileSource {
public String findDataFileAbsolutePath() throws OdaException {
File file = new File(this.homeDir + File.separator
+ this.currentTableName.trim());
+ if ( !file.isAbsolute( ) )
+ {
+ file = new File( getAbsoluteFile( )
+ + File.separator + this.homeDir + File.separator
+ + this.currentTableName.trim( ) );
+ }
if (!file.exists())
throw new OdaException(Messages.getString("query_invalidTableName") //$NON-NLS-1$
+ this.homeDir + File.separator + this.currentTableName);