| author | xwu | 2013-01-29 03:11:35 (EST) |
|---|---|---|
| committer | lzhu | 2013-01-29 03:11:35 (EST) |
| commit | 0134c388a000458fa83c04fc755ff35ad18bef16 (patch) (side-by-side diff) | |
| tree | 9aa5ab4100d45fcd3efa083733c6b63c82b087cb | |
| parent | b92c80fbc54eb42294db251394ebbbe257d44165 (diff) | |
| download | org.eclipse.datatools.enablement.oda-0134c388a000458fa83c04fc755ff35ad18bef16.zip org.eclipse.datatools.enablement.oda-0134c388a000458fa83c04fc755ff35ad18bef16.tar.gz org.eclipse.datatools.enablement.oda-0134c388a000458fa83c04fc755ff35ad18bef16.tar.bz2 | |
CheckIn: Fix an issue - Buttons need to be disabled when do not input
XML file URL as new XML data source and dataset[55578].
3 files changed, 207 insertions, 157 deletions
diff --git a/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/i18n/messages.properties b/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/i18n/messages.properties index ad9dd00..21c3a5f 100644 --- a/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/i18n/messages.properties +++ b/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/i18n/messages.properties @@ -25,6 +25,9 @@ designer.preview.preference.numberOfElementPassedToGetSchema=Number of data elem designer.preview.preference.numberOfElementPassedToGetSchema.errormessage=Please enter a number between 0 and {0}. designer.preview.preference.columnMappingPage.group.title=Column Mapping +#XML data source folder selection wizard page +XMLSelectionWizardPage.message.error.emptyXMLSource=Please specify the XML source URL or browse the XML file. + #row mapping page messages xPathChoosePage.messages.elementSelection.label=XML Element Selection xPathChoosePage.messages.elementSelection.item.absolutePath=&XML elements named "{0}" at fixed absolute path\n @@ -91,6 +94,7 @@ error.selectFolder=The selected file URL is invalid or the file doesn't exist. error.emptyPath=The file URL is empty. error.xpath.canNotContainAttribute=The XPath expression cannot map to an XML attribute. error.xpath.getPathList=Error occurred when getting the XPath list by the selected XML tree item. +error.dataset.Error.MissingFileLocation=Please specify the XML file location. error.dataset.maxRowNumberError=The max row should be a non-negative number. error.columnMapping.createPage=Error occurred in column mapping page. error.columnMapping.columnElement.create=Error occurred when mapping a column mapping element. diff --git a/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XMLSelectionPageHelper.java b/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XMLSelectionPageHelper.java index 178acf1..0c13725 100644 --- a/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XMLSelectionPageHelper.java +++ b/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XMLSelectionPageHelper.java @@ -14,7 +14,6 @@ package org.eclipse.datatools.enablement.oda.xml.ui.wizards; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -38,9 +37,12 @@ import org.eclipse.datatools.enablement.oda.xml.ui.utils.IHelpConstants; import org.eclipse.datatools.enablement.oda.xml.ui.utils.XMLRelationInfoUtil; import org.eclipse.datatools.enablement.oda.xml.util.ResourceLocatorUtil; import org.eclipse.datatools.enablement.oda.xml.util.XMLSourceFromPath; +import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; @@ -55,39 +57,41 @@ import org.eclipse.swt.widgets.Text; */ public class XMLSelectionPageHelper { - private static final String AUTO_ENCODING = Messages.getString( "wizard.autoEncoding" ); //$NON-NLS-1$ + + private static final String AUTO_ENCODING = Messages.getString( "wizard.autoEncoding" ); //$NON-NLS-1$ private WizardPage m_wizardPage; - private PreferencePage m_propertyPage; + private PreferencePage m_propertyPage; - private transient Text m_folderLocation = null; - private transient Text m_schemaLocation = null; + private transient Text m_folderLocation = null; + private transient Text m_schemaLocation = null; private transient FileSelectionButton browseFolderButton = null; private transient Combo encodingCombo = null; private transient Composite parent = null; private transient org.eclipse.datatools.connectivity.oda.util.ResourceIdentifiers ri = null; - static final String DEFAULT_MESSAGE = - Messages.getString( "wizard.defaultMessage.selectFolder" ); //$NON-NLS-1$ + static final String DEFAULT_MESSAGE = Messages.getString( "wizard.defaultMessage.selectFolder" ); //$NON-NLS-1$ - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - private final String[] XML_FILTER = new String[]{"*.xml", "*.*"} ; //$NON-NLS-1$ //$NON-NLS-2$ - private final String[] XSD_FILTER = new String[]{"*.xsd", "*.*"} ; //$NON-NLS-1$ //$NON-NLS-2$ + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + private final String[] XML_FILTER = new String[]{ + "*.xml", "*.*"}; //$NON-NLS-1$ //$NON-NLS-2$ + private final String[] XSD_FILTER = new String[]{ + "*.xsd", "*.*"}; //$NON-NLS-1$ //$NON-NLS-2$ - XMLSelectionPageHelper( WizardPage page ) - { - m_wizardPage = page; - } + XMLSelectionPageHelper( WizardPage page ) + { + m_wizardPage = page; + } - XMLSelectionPageHelper( PreferencePage page ) - { - m_propertyPage = page; - } + XMLSelectionPageHelper( PreferencePage page ) + { + m_propertyPage = page; + } - void createCustomControl( Composite parent ) - { - this.parent = parent; - this.setMessage( DEFAULT_MESSAGE ); + void createCustomControl( Composite parent ) + { + this.parent = parent; + this.setMessage( DEFAULT_MESSAGE ); Composite composite = new Composite( parent, SWT.NONE ); GridLayout layout = new GridLayout( ); layout.numColumns = 2; @@ -111,7 +115,7 @@ public class XMLSelectionPageHelper label3.setLayoutData( data ); setupSchemaFolderLocation( composite ); - + data = new GridData( GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL ); data.horizontalSpan = 2; @@ -119,26 +123,26 @@ public class XMLSelectionPageHelper label2.setText( Messages.getString( "label.selectEncoding" ) ); //$NON-NLS-1$ label2.setLayoutData( data ); setupEncodingControl( composite ); - - XMLRelationInfoUtil.setSystemHelp( getControl(), + + XMLRelationInfoUtil.setSystemHelp( getControl( ), IHelpConstants.CONEXT_ID_DATASOURCE_XML ); - } - - String getFolderLocation() - { - if( m_folderLocation == null ) - return EMPTY_STRING; - return getFolderLocationString( ); - } - - String getSchemaFileLocation() - { - if( m_schemaLocation == null ) - return EMPTY_STRING; - return getSchemaLocationString( ); - } - - String getEncoding( ) + } + + String getFolderLocation( ) + { + if ( m_folderLocation == null ) + return EMPTY_STRING; + return getFolderLocationString( ); + } + + String getSchemaFileLocation( ) + { + if ( m_schemaLocation == null ) + return EMPTY_STRING; + return getSchemaLocationString( ); + } + + String getEncoding( ) { if ( encodingCombo == null || encodingCombo.getText( ).equals( AUTO_ENCODING ) ) @@ -146,71 +150,75 @@ public class XMLSelectionPageHelper else return encodingCombo.getText( ); } - - Properties collectCustomProperties( Properties props ) - { - if( props == null ) - props = new Properties(); - - // set custom driver specific properties - props.setProperty( Constants.CONST_PROP_FILELIST, - getFolderLocation( ) ); + + Properties collectCustomProperties( Properties props ) + { + if ( props == null ) + props = new Properties( ); + + // set custom driver specific properties + props.setProperty( Constants.CONST_PROP_FILELIST, getFolderLocation( ) ); props.setProperty( Constants.CONST_PROP_SCHEMA_FILELIST, getSchemaFileLocation( ) ); props.setProperty( Constants.CONST_PROP_ENCODINGLIST, getEncoding( ) ); return props; - } - - void initCustomControl( Properties profileProps ) - { - if( profileProps == null || profileProps.isEmpty() || - m_folderLocation == null ) - return; // nothing to initialize - - String folderPath = profileProps.getProperty( Constants.CONST_PROP_FILELIST ); - if( folderPath == null ) - folderPath = EMPTY_STRING; - setFolderLocation( folderPath ); - - String encoding = profileProps.getProperty( Constants.CONST_PROP_ENCODINGLIST ); - if ( encoding == null ) - {//use auto encoding + } + + void initCustomControl( Properties profileProps ) + { + if ( profileProps == null + || profileProps.isEmpty( ) || m_folderLocation == null ) + { + validatePageStatus( ); + return; // nothing to initialize + } + + String folderPath = profileProps.getProperty( Constants.CONST_PROP_FILELIST ); + if ( folderPath == null ) + folderPath = EMPTY_STRING; + setFolderLocation( folderPath ); + + String encoding = profileProps.getProperty( Constants.CONST_PROP_ENCODINGLIST ); + if ( encoding == null ) + {// use auto encoding encodingCombo.select( 0 ); } else { encodingCombo.select( getIndex( encoding ) ); } - - String schemaPath = profileProps.getProperty( Constants.CONST_PROP_SCHEMA_FILELIST ); - if( schemaPath == null ) - schemaPath = EMPTY_STRING; - setSchemaLocation( schemaPath ); - } + String schemaPath = profileProps.getProperty( Constants.CONST_PROP_SCHEMA_FILELIST ); + if ( schemaPath == null ) + schemaPath = EMPTY_STRING; + setSchemaLocation( schemaPath ); - private int getIndex( String encoding ) + validatePageStatus( ); + + } + + private int getIndex( String encoding ) { return Arrays.binarySearch( encodingCombo.getItems( ), encoding ); } /** - * @param composite - */ - private void setupEncodingControl( Composite composite ) - { - GridData data = new GridData( GridData.FILL_HORIZONTAL ); - encodingCombo = new Combo(composite, SWT.READ_ONLY); - encodingCombo.setLayoutData( data ); - encodingCombo.add( AUTO_ENCODING ); - for ( Iterator i = Charset.availableCharsets( ).keySet( ).iterator( ); i.hasNext( ); ) + * @param composite + */ + private void setupEncodingControl( Composite composite ) + { + GridData data = new GridData( GridData.FILL_HORIZONTAL ); + encodingCombo = new Combo( composite, SWT.READ_ONLY ); + encodingCombo.setLayoutData( data ); + encodingCombo.add( AUTO_ENCODING ); + for ( Iterator i = Charset.availableCharsets( ).keySet( ).iterator( ); i.hasNext( ); ) { - String encoding = (String) i.next( ); - encodingCombo.add( encoding ); + String encoding = (String) i.next( ); + encodingCombo.add( encoding ); } - encodingCombo.select( 0 ); - } - + encodingCombo.select( 0 ); + } + /** * @param composite */ @@ -220,10 +228,18 @@ public class XMLSelectionPageHelper GridData data = new GridData( GridData.FILL_HORIZONTAL ); m_folderLocation = new Text( composite, SWT.BORDER ); m_folderLocation.setLayoutData( data ); + m_folderLocation.addModifyListener( new ModifyListener( ) { + + public void modifyText( ModifyEvent e ) + { + validatePageStatus( ); + } + + } ); browseFolderButton = new FileSelectionButton( composite, SWT.NONE ); browseFolderButton.setText( Messages.getString( "file.choose" ) ); //$NON-NLS-1$ - browseFolderButton.setActionHandler( new IMenuActionHandler( ){ + browseFolderButton.setActionHandler( new IMenuActionHandler( ) { public String getBaseFolder( ) { @@ -238,24 +254,25 @@ public class XMLSelectionPageHelper public void setPath( String path ) { m_folderLocation.setText( path ); + validatePageStatus( ); } public String getFilePath( ) { return getFolderLocation( ); } - - }); - + + } ); + } - + private String getResourceFolder( ) { if ( ri != null ) { if ( ri.getApplResourceBaseURI( ) != null ) { - return new File(ri.getApplResourceBaseURI( )).getAbsolutePath( ); + return new File( ri.getApplResourceBaseURI( ) ).getAbsolutePath( ); } } return null; @@ -274,7 +291,7 @@ public class XMLSelectionPageHelper browseFolderButton = new FileSelectionButton( composite, SWT.NONE ); browseFolderButton.setText( Messages.getString( "schema.choose" ) ); //$NON-NLS-1$ - browseFolderButton.setActionHandler( new IMenuActionHandler( ){ + browseFolderButton.setActionHandler( new IMenuActionHandler( ) { public String getBaseFolder( ) { @@ -295,10 +312,10 @@ public class XMLSelectionPageHelper { return getSchemaFileLocation( ); } - - }); + + } ); } - + /** * * @param text @@ -306,17 +323,18 @@ public class XMLSelectionPageHelper private void setFolderLocation( String text ) { m_folderLocation.setText( ResourceLocatorUtil.processPath( TextProcessorWrapper.process( text ) ) ); + validatePageStatus( ); } - + /** * * @return */ private String getFolderLocationString( ) { - return TextProcessorWrapper.deprocess( ResourceLocatorUtil.processPath( m_folderLocation.getText( ) ) ); + return TextProcessorWrapper.deprocess( ResourceLocatorUtil.processPath( m_folderLocation.getText( ) ) ); } - + /** * * @param text @@ -325,18 +343,19 @@ public class XMLSelectionPageHelper { m_schemaLocation.setText( ResourceLocatorUtil.processPath( TextProcessorWrapper.process( text ) ) ); } - + /** * * @return */ private String getSchemaLocationString( ) { - return TextProcessorWrapper.deprocess( ResourceLocatorUtil.processPath( m_schemaLocation.getText( ) ) ); + return TextProcessorWrapper.deprocess( ResourceLocatorUtil.processPath( m_schemaLocation.getText( ) ) ); } - + /** * set message + * * @param message */ private void setMessage( String message ) @@ -346,53 +365,70 @@ public class XMLSelectionPageHelper else if ( m_propertyPage != null ) m_propertyPage.setMessage( message ); } - - private Control getControl() - { - if ( m_wizardPage != null ) - return m_wizardPage.getControl(); - assert( m_propertyPage != null ); - return m_propertyPage.getControl(); - } - - public Runnable createTestConnectionRunnable( final IConnectionProfile profile ) + + private Control getControl( ) + { + if ( m_wizardPage != null ) + return m_wizardPage.getControl( ); + assert ( m_propertyPage != null ); + return m_propertyPage.getControl( ); + } + + 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 - { + return new Runnable( ) { + + public void run( ) + { + IConnection conn = PingJob.createTestConnection( profile ); + + Throwable exception = PingJob.getTestConnectionException( conn ); + + if ( exception == null ) // succeed in creating connection + { try { testConnection( ); } - catch( Exception ex ) + catch ( Exception ex ) { exception = ex; } - } - - PingJob.PingUIJob.showTestConnectionMessage( parent.getShell( ), exception ); - if( conn != null ) - { - conn.close(); - } - } + } + + PingJob.PingUIJob.showTestConnectionMessage( parent.getShell( ), + exception ); + if ( conn != null ) + { + conn.close( ); + } + } }; } - - private void testConnection( ) throws Exception + + private void validatePageStatus( ) + { + if ( getFolderLocation( ).trim( ).length( ) == 0 ) + { + m_wizardPage.setMessage( Messages.getString( "XMLSelectionWizardPage.message.error.emptyXMLSource" ),//$NON-NLS-1$ + IMessageProvider.ERROR ); + m_wizardPage.setPageComplete( false ); + } + else + { + m_wizardPage.setMessage( DEFAULT_MESSAGE ); + m_wizardPage.setPageComplete( true ); + } + } + + private void testConnection( ) throws Exception { - String schema = getSchemaFileLocation(); + String schema = getSchemaFileLocation( ); String encoding = getEncoding( ); if ( schema != null && schema.length( ) > 0 ) { - //if XML schema is provided, check whether it's valid + // if XML schema is provided, check whether it's valid InputStream is = new XMLSourceFromPath( schema, encoding, ri ).openInputStream( ); try { @@ -401,13 +437,14 @@ public class XMLSelectionPageHelper catch ( IOException e ) { } - //schemaFile provided is valid, this connection at least can be used to fetch meta data + // schemaFile provided is valid, this connection at least can be + // used to fetch meta data } - + String xmlFile = getFolderLocation( ); - if ( xmlFile == null || xmlFile.length( ) <= 0) - throw new OdaException( Messages.getString( "error.invalidSource" )); //$NON-NLS-1$ - + if ( xmlFile == null || xmlFile.length( ) <= 0 ) + throw new OdaException( Messages.getString( "error.invalidSource" ) ); //$NON-NLS-1$ + InputStream is = new XMLSourceFromPath( xmlFile, encoding, ri ).openInputStream( ); try { @@ -417,12 +454,12 @@ public class XMLSelectionPageHelper { } } - + protected void setResourceIdentifiers( ResourceIdentifiers ri ) { if ( ri == null ) return; - + this.ri = DesignSessionUtil.createRuntimeResourceIdentifiers( ri ); } } diff --git a/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XmlDataSetSelectionPage.java b/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XmlDataSetSelectionPage.java index 563f665..126a7de 100644 --- a/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XmlDataSetSelectionPage.java +++ b/plugins/org.eclipse.datatools.enablement.oda.xml.ui/src/org/eclipse/datatools/enablement/oda/xml/ui/wizards/XmlDataSetSelectionPage.java @@ -164,7 +164,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage { numberText.setText( rowNumber ); } - setPageStatus( ); + updatePageStatus( ); } catch ( NumberFormatException e ) { @@ -221,11 +221,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage public void modifyText( ModifyEvent e ) { - if ( numberText.getText( ) != null - && numberText.getText( ).trim( ).length( ) > 0 ) - { - setPageStatus( ); - } + updatePageStatus( ); } } ); final Label label = new Label( numOfLinesGroup, SWT.BEGINNING ); @@ -265,7 +261,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage fileLocation = folderLocation.getText( ); } setXMLFileLocaiton(); - setPageStatus( ); + updatePageStatus( ); } public void widgetDefaultSelected( SelectionEvent e ) @@ -279,9 +275,9 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage sourceData.horizontalSpan = 3; sourceData.verticalIndent = 8; enterXMLSourceButton = new Button( composite, SWT.RADIO ); - //enterXMLSourceButton.addSelectionListener( sa ); - enterXMLSourceButton.setLayoutData( sourceData ); + enterXMLSourceButton.setLayoutData( sourceData ); enterXMLSourceButton.setText( Messages.getString( "lable.selectXmlFile" ) ); //$NON-NLS-1$ + enterXMLSourceButton.addSelectionListener( sa ); } /** @@ -293,12 +289,23 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage folderLocation.setEnabled( enable ); browseFolderButton.setEnabled( enable ); } + /** * set page status based on row number * */ - private void setPageStatus( ) + private void updatePageStatus( ) { + if( enterXMLSourceButton.getSelection( ) ) + { + if( fileLocation == null || fileLocation.trim( ).length( ) == 0 ) + { + setDetailsMessage( Messages.getString( "error.dataset.Error.MissingFileLocation" ), //$NON-NLS-1$ + IMessageProvider.ERROR ); + setPageComplete( false ); + return; + } + } if ( numberText == null ) { setMessage( DEFAULT_MESSAGE ); @@ -309,7 +316,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage if ( maxRow == INVALID_ROW_NUMBER || maxRow == NEGATIVE_ROW_NUMBER ) { setPageComplete( false ); - setDetailsMessage( Messages.getString( "error.dataset.maxRowNumberError" ), //$NON-NLS-1$ + setDetailsMessage( Messages.getString( "error.dataset.maxRowNumberError" ), //$NON-NLS-1$ IMessageProvider.ERROR ); } else @@ -378,6 +385,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage public void modifyText( ModifyEvent e ) { setXMLFileLocaiton( ); + updatePageStatus( ); } } ); @@ -413,6 +421,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage folderLocation.setText( selectedLocation ); setXMLFileLocaiton( ); } + updatePageStatus( ); } } ); @@ -599,7 +608,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage */ private boolean isValid( ) { - if ( maxRow == UNUSED_ROW_CACHE || maxRow >= 0 ) + if ( isPageComplete( ) && ( maxRow == UNUSED_ROW_CACHE || maxRow >= 0 ) ) return true; else return false; @@ -631,7 +640,7 @@ public class XmlDataSetSelectionPage extends DataSetWizardPage */ protected boolean canLeave( ) { - setPageStatus( ); + updatePageStatus( ); return isValid( ); } |

