public IWizardPage getNextPage()
{
if ( templateButton.getSelection() )
{
final IConnection connection = entryWidget.getConnection();
final DN dn = entryWidget.getDn();
final IEntry[] templateEntries = new IEntry[1];
if ( connection == null )
{
getShell().getDisplay().syncExec( new Runnable()
{
public void run()
{
MessageDialog.openError( getShell(), "Error", "No connection" );
}
} );
return null;
}
if ( dn == null )
{
getShell().getDisplay().syncExec( new Runnable()
{
public void run()
{
MessageDialog.openError( getShell(), "Error", "No dn" );
}
} );
return null;
}
// check if selected DN exists
ReadEntryJob readEntryJob = new ReadEntryJob( connection, dn );
RunnableContextJobAdapter.execute( readEntryJob, getContainer(), false );
templateEntries[0] = readEntryJob.getReadEntry();
if ( templateEntries[0] == null )
{
getShell().getDisplay().syncExec( new Runnable()
{
public void run()
{
MessageDialog.openError( getShell(), "Error", "Entry " + dn.toString() + " doesn't exists" );
}
} );
return null;
}
// init attributes
if ( !templateEntries[0].isAttributesInitialized() )
{
InitializeAttributesJob job = new InitializeAttributesJob( templateEntries, false );
RunnableContextJobAdapter.execute( job, getContainer() );
}
// clone entry and remove non-modifyable attributes
try
{
EventRegistry.suspendEventFireingInCurrentThread();
LdifContentRecord record = ModelConverter.entryToLdifContentRecord( templateEntries[0] );
DummyEntry prototypeEntry = ModelConverter.ldifContentRecordToEntry( record, connection );
IAttribute[] attributes = prototypeEntry.getAttributes();
for ( int i = 0; i < attributes.length; i++ )
{
if ( !SchemaUtils.isModifyable( attributes[i].getAttributeTypeDescription() ) )
{
prototypeEntry.deleteAttribute( attributes[i] );
}
}
wizard.setPrototypeEntry( prototypeEntry );
}
catch ( Exception e )
{
e.printStackTrace();
}
finally
{
EventRegistry.resumeEventFireingInCurrentThread();
}
}
else
{
wizard.setPrototypeEntry( new DummyEntry( new DN(), wizard.getSelectedConnection() ) );
}
return super.getNextPage();
}