Java Code Examples for org.eclipse.ui.dialogs.IOverwriteQuery#queryOverwrite()

The following examples show how to use org.eclipse.ui.dialogs.IOverwriteQuery#queryOverwrite() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebArtifactUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Configure the servlet settings
 * 
 * @param map
 * @param project
 * @param query
 * @param monitor
 * @throws CoreException
 */
public static void configureServlet( Map map, IProject project,
		IOverwriteQuery query, IProgressMonitor monitor )
		throws CoreException
{
	// cancel progress
	if ( monitor.isCanceled( ) )
		return;

	if ( map == null || project == null )
	{
		return;
	}

	// create WebArtifact
	WebArtifactEdit webEdit = WebArtifactEdit
			.getWebArtifactEditForWrite( project );
	if ( webEdit == null )
		return;

	try
	{
		WebApp webapp = (WebApp) webEdit.getDeploymentDescriptorRoot( );

		// handle servlet settings
		Iterator it = map.keySet( ).iterator( );
		while ( it.hasNext( ) )
		{
			String name = DataUtil.getString( it.next( ), false );
			ServletBean bean = (ServletBean) map.get( name );

			if ( bean == null )
				continue;

			// if contained this servlet
			Object obj = getServletByName( webapp.getServlets( ), name );
			if ( obj != null )
			{
				String ret = query
						.queryOverwrite( "Servlet '" + name + "'" ); //$NON-NLS-1$ //$NON-NLS-2$

				// check overwrite query result
				if ( IOverwriteQuery.NO.equalsIgnoreCase( ret ) )
				{
					continue;
				}
				if ( IOverwriteQuery.CANCEL.equalsIgnoreCase( ret ) )
				{
					monitor.setCanceled( true );
					return;
				}

				// remove old item
				webapp.getServlets( ).remove( obj );
			}

			String className = bean.getClassName( );
			String description = bean.getDescription( );

			// create Servlet Type object
			ServletType servletType = WebapplicationFactory.eINSTANCE
					.createServletType( );
			servletType.setClassName( className );

			// create Servlet object
			Servlet servlet = WebapplicationFactory.eINSTANCE
					.createServlet( );
			servlet.setServletName( name );
			if ( description != null )
				servlet.setDescription( description );

			servlet.setWebType( servletType );

			servlet.setWebApp( webapp );
		}

		webEdit.saveIfNecessary( monitor );
	}
	finally
	{
		webEdit.dispose( );
	}
}
 
Example 2
Source File: WebArtifactUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Configure the servlet-mapping settings
 * 
 * @param map
 * @param project
 * @param query
 * @param monitor
 * @throws CoreException
 */
public static void configureServletMapping( Map map, IProject project,
		IOverwriteQuery query, IProgressMonitor monitor )
		throws CoreException
{
	// cancel progress
	if ( monitor.isCanceled( ) )
		return;

	if ( map == null || project == null )
	{
		return;
	}

	// create WebArtifact
	WebArtifactEdit webEdit = WebArtifactEdit
			.getWebArtifactEditForWrite( project );
	if ( webEdit == null )
		return;

	try
	{
		WebApp webapp = (WebApp) webEdit.getDeploymentDescriptorRoot( );

		// handle servlet-mapping settings
		Iterator it = map.keySet( ).iterator( );
		while ( it.hasNext( ) )
		{
			String uri = DataUtil.getString( it.next( ), false );
			ServletMappingBean bean = (ServletMappingBean) map.get( uri );

			if ( bean == null )
				continue;

			// if contained this servlet-mapping
			Object obj = getServletMappingByUri( webapp
					.getServletMappings( ), uri );
			if ( obj != null )
			{
				String ret = query
						.queryOverwrite( "Servlet-mapping '" + uri + "'" ); //$NON-NLS-1$ //$NON-NLS-2$

				// check overwrite query result
				if ( IOverwriteQuery.NO.equalsIgnoreCase( ret ) )
				{
					continue;
				}
				if ( IOverwriteQuery.CANCEL.equalsIgnoreCase( ret ) )
				{
					monitor.setCanceled( true );
					return;
				}

				// remove old item
				webapp.getServletMappings( ).remove( obj );
			}

			// servlet name
			String name = bean.getName( );

			// create ServletMapping object
			ServletMapping mapping = WebapplicationFactory.eINSTANCE
					.createServletMapping( );

			// get servlet by name
			Servlet servlet = webapp.getServletNamed( name );
			if ( servlet != null )
			{
				mapping.setServlet( servlet );
				mapping.setUrlPattern( uri );
				mapping.setWebApp( webapp );
			}
		}

		webEdit.saveIfNecessary( monitor );
	}
	finally
	{
		webEdit.dispose( );
	}
}