public static final class SourceFileListener extends FilteredListener<PropertyContentEvent>
{
@Override
protected void handleTypedEvent( final PropertyContentEvent event )
{
final CreateNormalizedXmlSchemaOp op = (CreateNormalizedXmlSchemaOp) event.property().element();
final Path sourceFilePath = op.getSourceFile().content();
String folder = null;
String fileName = null;
if( sourceFilePath != null && sourceFilePath.segmentCount() >= 2 )
{
final IFile sourceFile = ResourcesPlugin.getWorkspace().getRoot().getFile( PathBridge.create( sourceFilePath ) );
if( sourceFile.exists() )
{
folder = sourceFile.getParent().getFullPath().makeRelative().toPortableString();
fileName = sourceFile.getName();
if( fileName.toLowerCase().endsWith( ".xsd" ) )
{
fileName = fileName.substring( 0, fileName.length() - 4 ) + "-normalized.xsd";
}
else
{
fileName = null;
}
}
}
op.setFolder( folder );
op.setFile( fileName );
final PersistedState state = PersistedStateManager.load( sourceFilePath );
if( state == null )
{
op.getRootElements().clear();
}
else
{
try
{
op.getRootElements().copy( state );
op.getExclusions().copy( state );
op.getTypeSubstitutions().copy( state );
op.getSortSequenceContent().copy( state );
op.getRemoveWildcards().copy( state );
}
finally
{
state.dispose();
}