<commit_before>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.views.actions;

import java.util.logging.Level;

import org.eclipse.birt.report.designer.internal.ui.command.CommandUtils;
import org.eclipse.birt.report.designer.internal.ui.util.UIUtil;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.model.api.LibraryHandle;
import org.eclipse.birt.report.model.api.ModuleHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.jface.dialogs.MessageDialog;

/**
 * 
 */

public class RefreshModuleHandleAction extends AbstractViewAction
{

	public static final String ID = "org.eclipse.birt.report.designer.internal.ui.views.actions.RefreshModuleHandleAction"; //$NON-NLS-1$
	public static final String ACTION_TEXT = Messages.getString( "RefreshModuleHandleAction.Action.Text" ); //$NON-NLS-1$

	/**
	 * @param selectedObject
	 */
	public RefreshModuleHandleAction( Object selectedObject )
	{
		super( selectedObject, ACTION_TEXT );
	}

	/**
	 * @param selectedObject
	 * @param text
	 */
	public RefreshModuleHandleAction( Object selectedObject, String text )
	{
		super( selectedObject, text );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see isEnabled()
	 */
	public boolean isEnabled( )
	{
		if ( getSelection( ) instanceof ReportDesignHandle
				|| getSelection( ) instanceof LibraryHandle )
		{
			return true;
		}
		else
			return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.action.Action#run()
	 */
	public void run( )
	{
		if ( ( (ModuleHandle) getSelection( ) ).needsSave( ) )
		{
			MessageDialog md = new MessageDialog( UIUtil.getDefaultShell( ),
					Messages.getString( "RefreshModuleHandleAction.MessageBox.Title" ), //$NON-NLS-1$
					null,
					Messages.getString( "RefreshModuleHandleAction.MessageBox.Text" ), //$NON-NLS-1$
					MessageDialog.QUESTION_WITH_CANCEL,
					new String[]{
							Messages.getString( "RefreshModuleHandleAction.MessageBox.SaveButton" ), //$NON-NLS-1$
							Messages.getString( "RefreshModuleHandleAction.MessageBox.DiscardButton" ), //$NON-NLS-1$
							Messages.getString( "RefreshModuleHandleAction.MessageBox.CancelButton" ) //$NON-NLS-1$
					},
					0 );

			switch ( md.open( ) )
			{
				case 0 :
					try
					{
						( (ModuleHandle) getSelection( ) ).save( );
						CommandUtils.executeCommand( "org.eclipse.birt.report.designer.ui.command.refreshLibraryCommand", null ); //$NON-NLS-1$
					}
					catch ( Exception e )
					{
						logger.log( Level.SEVERE, e.getMessage( ), e );
					}
					break;
				case 1 :
					try
					{
						CommandUtils.executeCommand( "org.eclipse.birt.report.designer.ui.command.refreshLibraryCommand", null ); //$NON-NLS-1$
					}
					catch ( Exception e )
					{
						logger.log( Level.SEVERE, e.getMessage( ), e );
					}
					break;
				default :
			}
		}
		else<commit_msg>- Summary: 	Fixed Bugzilla #279563 - Refresh library will remove the 'unsaved' tag from report. - Bugzilla Bug(s) Resolved: 	#279563 - Description: 	fixed. - Tests Description: 	Manual Test - Code Reviewer: 	None - Files Added: 	None - Files Edited: 	/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/views/actions/RefreshModuleHandleAction.java - Files Deleted: 	None - Notes to Build Team: 	None - Notes to Developers: 	None - Notes to QA: 	None - Notes to Documentation: 	None<commit_after>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.views.actions;

import java.util.logging.Level;

import org.eclipse.birt.report.designer.core.model.SessionHandleAdapter;
import org.eclipse.birt.report.designer.internal.ui.command.CommandUtils;
import org.eclipse.birt.report.designer.internal.ui.util.UIUtil;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.model.api.LibraryHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.jface.dialogs.MessageDialog;

/**
 * 
 */

public class RefreshModuleHandleAction extends AbstractViewAction
{

	public static final String ID = "org.eclipse.birt.report.designer.internal.ui.views.actions.RefreshModuleHandleAction"; //$NON-NLS-1$
	public static final String ACTION_TEXT = Messages.getString( "RefreshModuleHandleAction.Action.Text" ); //$NON-NLS-1$

	/**
	 * @param selectedObject
	 */
	public RefreshModuleHandleAction( Object selectedObject )
	{
		super( selectedObject, ACTION_TEXT );
	}

	/**
	 * @param selectedObject
	 * @param text
	 */
	public RefreshModuleHandleAction( Object selectedObject, String text )
	{
		super( selectedObject, text );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see isEnabled()
	 */
	public boolean isEnabled( )
	{
		if ( getSelection( ) instanceof ReportDesignHandle
				|| getSelection( ) instanceof LibraryHandle )
		{
			return true;
		}
		else
			return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.action.Action#run()
	 */
	public void run( )
	{
		if ( SessionHandleAdapter.getInstance( ).getReportDesignHandle( ).needsSave( ) )
		{
			MessageDialog md = new MessageDialog( UIUtil.getDefaultShell( ),
					Messages.getString( "RefreshModuleHandleAction.MessageBox.Title" ), //$NON-NLS-1$
					null,
					Messages.getString( "RefreshModuleHandleAction.MessageBox.Text" ), //$NON-NLS-1$
					MessageDialog.QUESTION_WITH_CANCEL,
					new String[]{
							Messages.getString( "RefreshModuleHandleAction.MessageBox.SaveButton" ), //$NON-NLS-1$
							Messages.getString( "RefreshModuleHandleAction.MessageBox.DiscardButton" ), //$NON-NLS-1$
							Messages.getString( "RefreshModuleHandleAction.MessageBox.CancelButton" ) //$NON-NLS-1$
					},
					0 );

			switch ( md.open( ) )
			{
				case 0 :
					try
					{
						SessionHandleAdapter.getInstance( ).getReportDesignHandle( ).save( );
						CommandUtils.executeCommand( "org.eclipse.birt.report.designer.ui.command.refreshLibraryCommand", null ); //$NON-NLS-1$
					}
					catch ( Exception e )
					{
						logger.log( Level.SEVERE, e.getMessage( ), e );
					}
					break;
				case 1 :
					try
					{
						CommandUtils.executeCommand( "org.eclipse.birt.report.designer.ui.command.refreshLibraryCommand", null ); //$NON-NLS-1$
					}
					catch ( Exception e )
					{
						logger.log( Level.SEVERE, e.getMessage( ), e );
					}
					break;
				default :
			}
		}
		else
{'fraction_non_alphanumeric': 0.16185286103542235, 'fraction_numerical': 0.007084468664850136, 'mean_word_length': 3.5795383655645665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1800055', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2207, 'n_words': 437}