{
// What we get from the TableViewer is a StructuredSelection
StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection();
// Here's the real object
Server server = ( Server ) selection.getFirstElement();
// Asking for confirmation
DeleteServerDialog dsd = new DeleteServerDialog( view.getSite().getShell(), server );
if ( dsd.open() == DeleteServerDialog.OK )
{
// Checking if the server is running
// If yes, we need to shut it down before removing its data
if ( server.getState() == ServerStateEnum.STARTED )
{
// Setting the server of the server to 'stopping'
server.setState( ServerStateEnum.STOPPING );
// Getting the launch job
LaunchServerJob launchJob = server.getLaunchJob();
if ( launchJob != null )
{
// Getting the launch
ILaunch launch = launchJob.getLaunch();
if ( ( launch != null ) && ( !launch.isTerminated() ) )
{
// Terminating the launch
try
{
launch.terminate();
}
catch ( DebugException e )
{
ApacheDsPluginUtils.reportError( "An error occurred when stopping the server.\n\n"
+ e.getMessage() );
}
}
}
}
// Removing the server
ServersHandler.getDefault().removeServer( server );
// Deleting the associated directory on disk
deleteDirectory( new File( ApacheDsPluginUtils.getApacheDsServersFolder().append( server.getId() )
.toOSString() ) );
}
}
}