<commit_before>package jfmi.control;

import javax.swing.JOptionPane;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Vector;

import jfmi.control.FileTag;
import jfmi.dao.FileTagDAO;
import jfmi.gui.FileTagHandlerDialog;
import jfmi.gui.GUIUtil;

/** A FileTagHandler handles application logic concerned with adding, removing,
  and updating tag records in the database. A FileTagHandler uses its parent
  JFMIApp's database to save tag changes, and a FileTagHandlerDialog to interface
  with a user.
  */
public class FileTagHandler {

	// PRIVATE INSTANCE Methods
	private JFMIApp jfmiApp;
	private FileTagHandlerDialog tagHandlerDialog;

	private FileTagDAO fileTagDAO;

	private Vector<FileTag> fileTagData;

	//************************************************************
	// PUBLIC INSTANCE Methods
	//************************************************************

	/** Construct a FileTagHandler with the specified JFMIApp as its parent.
	  @param jfmiApp_ JFMIApp reference used as this instance's parent.
	  */
	public FileTagHandler(JFMIApp jfmiApp_) 
	{
		setJFMIApp(jfmiApp_);

		fileTagDAO = new FileTagDAO();

		fileTagData = null;

		tagHandlerDialog = new FileTagHandlerDialog(jfmiApp.getJFMIGUI(), this);
		tagHandlerDialog.setVisible(false);
	}

	/** Begins an interaction with the user that allows them to enter the
	  value for a new FileTag and store it in the repository.
	  */
	public void beginAddTagInteraction()
	{
		String newTag = getNewTagFromUser();

		if (newTag == null) {
			return;	// user cancelled interaction
		}

		FileTag tag = new FileTag(newTag);
		addTagToRepo(tag, true);
		updateDataAndGUI(true);
	}

	/** Begins an interaction with the user which allows them to remove
	  tags from the repository. 
	  @param tags a list of tags to be deleted from the repository
	  */
	public void beginDeleteTagsInteraction(List<FileTag> tags)
	{
		if (tags == null) {
			return;
		}

		String msg = "Are you sure you want to delete the selected tags?";

		/* 	First we delete FileTagging records from the repo based on the
		   tags the user has selected - it won't make sense for the 
		   FileTagging records to be there if their associated tags are gone.
		   	We then delete the tags from the repo. We then update handler
		   data.
		   */
		if (tagHandlerDialog.getUserConfirmation(msg)) {
			jfmiApp.getTaggingHandler().deleteTaggingsByTags(tags, true);
			deleteTagsFromRepo(tags, true);

			updateDataAndGUI(true);
			jfmiApp.getFileHandler().updateDataAndGUI(true);
		}
	}

	/** When called, displays an interface to allow the user to
	  add/remove tags.
	  */
	public void beginManageTagsInteraction()
	{
		updateDataAndGUI(true);
		tagHandlerDialog.setVisible(true);
	}

	/** Accessor for the fileTagData field. This may be null.
	  @return Access to the list of tag records this instance has retrieved
	  		from the application repository.
	  */
	public List<FileTag> getFileTagData()
	{
		return fileTagData;
	}

	/** Sets the handler's file tag data from a Collection of FileTag.
	  @param tags the handler's tag data is initialized from this parameter
	  */
	public void setFileTagData(Collection<FileTag> tags)
	{<commit_msg>FileTagHandler doesn't remove taggings anymore<commit_after>package jfmi.control;

import javax.swing.JOptionPane;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Vector;

import jfmi.control.FileTag;
import jfmi.dao.FileTagDAO;
import jfmi.gui.FileTagHandlerDialog;
import jfmi.gui.GUIUtil;

/** A FileTagHandler handles application logic concerned with adding, removing,
  and updating tag records in the database. A FileTagHandler uses its parent
  JFMIApp's database to save tag changes, and a FileTagHandlerDialog to interface
  with a user.
  */
public class FileTagHandler {

	// PRIVATE INSTANCE Methods
	private JFMIApp jfmiApp;
	private FileTagHandlerDialog tagHandlerDialog;

	private FileTagDAO fileTagDAO;

	private Vector<FileTag> fileTagData;

	//************************************************************
	// PUBLIC INSTANCE Methods
	//************************************************************

	/** Construct a FileTagHandler with the specified JFMIApp as its parent.
	  @param jfmiApp_ JFMIApp reference used as this instance's parent.
	  */
	public FileTagHandler(JFMIApp jfmiApp_) 
	{
		setJFMIApp(jfmiApp_);

		fileTagDAO = new FileTagDAO();

		fileTagData = null;

		tagHandlerDialog = new FileTagHandlerDialog(jfmiApp.getJFMIGUI(), this);
		tagHandlerDialog.setVisible(false);
	}

	/** Begins an interaction with the user that allows them to enter the
	  value for a new FileTag and store it in the repository.
	  */
	public void beginAddTagInteraction()
	{
		String newTag = getNewTagFromUser();

		if (newTag == null) {
			return;	// user cancelled interaction
		}

		FileTag tag = new FileTag(newTag);
		addTagToRepo(tag, true);
		updateDataAndGUI(true);
	}

	/** Begins an interaction with the user which allows them to remove
	  tags from the repository. 
	  @param tags a list of tags to be deleted from the repository
	  */
	public void beginDeleteTagsInteraction(List<FileTag> tags)
	{
		if (tags == null) {
			return;
		}

		String msg = "Are you sure you want to delete the selected tags?";

		/* We delete the tags from the repo. We then update handler data, as
		   well as the the application's FileHandler's data.
		   */
		if (tagHandlerDialog.getUserConfirmation(msg)) {
			deleteTagsFromRepo(tags, true);
			updateDataAndGUI(true);
			jfmiApp.getFileHandler().updateDataAndGUI(true);
		}
	}

	/** When called, displays an interface to allow the user to
	  add/remove tags.
	  */
	public void beginManageTagsInteraction()
	{
		updateDataAndGUI(true);
		tagHandlerDialog.setVisible(true);
	}

	/** Accessor for the fileTagData field. This may be null.
	  @return Access to the list of tag records this instance has retrieved
	  		from the application repository.
	  */
	public List<FileTag> getFileTagData()
	{
		return fileTagData;
	}

	/** Sets the handler's file tag data from a Collection of FileTag.
	  @param tags the handler's tag data is initialized from this parameter
	  */
	public void setFileTagData(Collection<FileTag> tags)
	{
{'fraction_non_alphanumeric': 0.1132949824224992, 'fraction_numerical': 0.0, 'mean_word_length': 4.138752052545156, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6596392', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1835, 'n_words': 628}