// Getting the selection
StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection();
if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) )
{
// Getting the server
LdapServer server = ( LdapServer ) selection.getFirstElement();
LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension();
if ( ( ldapServerAdapterExtension != null ) && ( ldapServerAdapterExtension.getInstance() != null ) )
{
LdapServerAdapter ldapServerAdapter = ldapServerAdapterExtension.getInstance();
try
{
// Getting the ports already in use
String[] portsAlreadyInUse = ldapServerAdapter.checkPortsBeforeServerStart( server );
if ( ( portsAlreadyInUse == null ) || ( portsAlreadyInUse.length > 0 ) )
{
String title = null;
String message = null;
if ( portsAlreadyInUse.length == 1 )
{
title = Messages.getString( "StartAction.PortInUse" ); //$NON-NLS-1$
message = NLS
.bind(
Messages.getString( "StartAction.PortOfProtocolInUse" ), new String[] { portsAlreadyInUse[0] } ); //$NON-NLS-1$
}
else
{
title = Messages.getString( "StartAction.PortsInUse" ); //$NON-NLS-1$
message = Messages.getString( "StartAction.PortsOfProtocolsInUse" ); //$NON-NLS-1$
for ( String portAlreadyInUse : portsAlreadyInUse )
{
message += "\n - " + portAlreadyInUse; //$NON-NLS-1$
}
}
message += "\n\n" + Messages.getString( "StartAction.Continue" ); //$NON-NLS-1$ //$NON-NLS-2$
MessageDialog dialog = new MessageDialog( view.getSite().getShell(), title, null, message,
MessageDialog.WARNING, new String[]
{ IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, MessageDialog.OK );
if ( dialog.open() == MessageDialog.CANCEL )
{
return;
}
}
// Creating and scheduling the job to start the server
StudioLdapServerJob job = new StudioLdapServerJob( new StartLdapServerRunnable( server ) );
job.schedule();
}
catch ( Exception e )
{
// Showing an error in case no LDAP Server Adapter can be found
MessageDialog
.openError( view.getSite().getShell(),
Messages.getString( "StartAction.ErrorStartingServer" ), //$NON-NLS-1$
NLS.bind(
Messages.getString( "StartAction.ServerCanNotBeStarted" ) + "\n" + Messages.getString( "StartAction.Cause" ), server.getName(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
e.getMessage() ) );
}
}
else
{
// Showing an error in case no LDAP Server Adapter can be found
MessageDialog.openError( view.getSite().getShell(),
Messages.getString( "StartAction.NoLdapServerAdapter" ), //$NON-NLS-1$
NLS.bind( Messages.getString( "StartAction.ServerCanNotBeStarted" ) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
+ Messages.getString( "StartAction.NoLdapServerAdapterCouldBeFound" ), server.getName() ) ); //$NON-NLS-1$
}
}
}
}