<commit_before>package cz.spiffyk.flpmanager.application.controls.workspace;

import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import org.apache.commons.io.FileUtils;

import cz.spiffyk.flpmanager.application.controls.tags.TagsViewer;
import cz.spiffyk.flpmanager.application.screens.ProjectEditorDialog;
import cz.spiffyk.flpmanager.application.screens.SongEditorDialog;
import cz.spiffyk.flpmanager.data.Project;
import cz.spiffyk.flpmanager.data.Song;
import cz.spiffyk.flpmanager.util.Messenger;
import cz.spiffyk.flpmanager.util.Messenger.MessageType;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Window;
import javafx.scene.control.Alert.AlertType;

public class SongTreeCellContent extends WorkspaceNodeTreeCellContent<Song> implements Observer {
	
	private final Song song;
	
	private final CheckBox favoriteCheckBox;
	private final ContextMenu contextMenu;
	private final TagsViewer tags;
	
	public SongTreeCellContent(Song node) {
		super(node);
		this.contextMenu = new SongContextMenu();
		this.setOnContextMenuRequested((event) -> {
			this.contextMenu.show(this.getScene().getWindow(), event.getScreenX(), event.getScreenY());
		});
		getStyleClass().add("song-cell");
		this.song = node;
		node.addObserver(this);
		
		this.favoriteCheckBox = new CheckBox();
		this.favoriteCheckBox.getStyleClass().add("favorite-check-box");
		this.favoriteCheckBox.setOnAction((event) -> {
			song.setFavorite(this.favoriteCheckBox.isSelected());
		});
		getLeftBox().getChildren().addAll(this.favoriteCheckBox);
		
		this.tags = new TagsViewer();
		tags.setTags(this.song.getTags());
		getRightBox().getChildren().add(this.tags);
		
		update();
	}

	@Override
	public void update(Observable o, Object arg) {
		update();
	}
	
	private void update() {
		this.favoriteCheckBox.setSelected(song.isFavorite());
		if (song.getAuthor().isEmpty()) {
			getLabel().setText(song.getName());
		} else {
			getLabel().setText(song.getAuthor() + " - " + song.getName());
		}
	}
	
	private class SongContextMenu extends ContextMenu {
		public SongContextMenu() {
			final Window owner = this.getOwnerWindow();
			
			MenuItem editItem = new MenuItem("_Edit song info...");
			editItem.setOnAction((event) -> {
				new SongEditorDialog(song).showAndWait();
				update();
			});
			
			MenuItem openDirItem = new MenuItem("_Open in system explorer...");
			openDirItem.setOnAction((event) -> {
				song.openInSystemBrowser();
			});
			
			MenuItem newProjectItem = new MenuItem("Create a new project...");
			newProjectItem.setOnAction((event) -> {
				final Project project = new Project(song);
				final ProjectEditorDialog dialog = new ProjectEditorDialog(project);
				dialog.initOwner(owner);
				dialog.showAndWait().ifPresent((b) -> {
					if (b.booleanValue()) {
						song.getProjects().add(project);
						project.updateFiles();
					}
				});
			});
			
			MenuItem importProjectItem = new MenuItem("Import project from file...");
			importProjectItem.setOnAction((event) -> {
				
				final FileChooser chooser = new FileChooser();
				chooser.setTitle("Select FLP to import...");
				chooser.getExtensionFilters().add(new ExtensionFilter("FL Studio project file", "*.flp"));
				File file = chooser.showOpenDialog(getOwnerWindow());
				if (file != null) {
					Project project = new Project(song);
					project.setName(file.getName());
					ProjectEditorDialog dialog = new ProjectEditorDialog(project);
					dialog.initOwner(owner);
					dialog.showAndWait().ifPresent((b) -> {
						if (b.booleanValue()) {
							try {
								FileUtils.copyFile(file, project.getProjectFile());
								song.getProjects().add(project);
								project.updateFiles();
							} catch (IOException e) {
								e.printStackTrace();
								Messenger.get().message(MessageType.ERROR, "Could not copy project file.", e.getMessage());
							}
						}
					});
				}
			});<commit_msg>Fix project importing<commit_after>package cz.spiffyk.flpmanager.application.controls.workspace;

import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import org.apache.commons.io.FileUtils;

import cz.spiffyk.flpmanager.application.controls.tags.TagsViewer;
import cz.spiffyk.flpmanager.application.screens.ProjectEditorDialog;
import cz.spiffyk.flpmanager.application.screens.SongEditorDialog;
import cz.spiffyk.flpmanager.data.Project;
import cz.spiffyk.flpmanager.data.Song;
import cz.spiffyk.flpmanager.util.Messenger;
import cz.spiffyk.flpmanager.util.Messenger.MessageType;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Window;
import javafx.scene.control.Alert.AlertType;

public class SongTreeCellContent extends WorkspaceNodeTreeCellContent<Song> implements Observer {
	
	private final Song song;
	
	private final CheckBox favoriteCheckBox;
	private final ContextMenu contextMenu;
	private final TagsViewer tags;
	
	private Window owner;
	
	public SongTreeCellContent(Song node) {
		super(node);
		this.contextMenu = new SongContextMenu();
		this.setOnContextMenuRequested((event) -> {
			this.contextMenu.show(this.getScene().getWindow(), event.getScreenX(), event.getScreenY());
		});
		getStyleClass().add("song-cell");
		this.song = node;
		node.addObserver(this);
		
		this.favoriteCheckBox = new CheckBox();
		this.favoriteCheckBox.getStyleClass().add("favorite-check-box");
		this.favoriteCheckBox.setOnAction((event) -> {
			song.setFavorite(this.favoriteCheckBox.isSelected());
		});
		getLeftBox().getChildren().addAll(this.favoriteCheckBox);
		
		this.tags = new TagsViewer();
		tags.setTags(this.song.getTags());
		getRightBox().getChildren().add(this.tags);
		
		update();
	}

	@Override
	public void update(Observable o, Object arg) {
		update();
	}
	
	private void update() {
		if (getScene() != null) {
			this.owner = getScene().getWindow();
		} else {
			this.owner = null;
		}
		
		this.favoriteCheckBox.setSelected(song.isFavorite());
		if (song.getAuthor().isEmpty()) {
			getLabel().setText(song.getName());
		} else {
			getLabel().setText(song.getAuthor() + " - " + song.getName());
		}
	}
	
	private class SongContextMenu extends ContextMenu {
		public SongContextMenu() {
			MenuItem editItem = new MenuItem("_Edit song info...");
			editItem.setOnAction((event) -> {
				new SongEditorDialog(song).showAndWait();
				update();
			});
			
			MenuItem openDirItem = new MenuItem("_Open in system explorer...");
			openDirItem.setOnAction((event) -> {
				song.openInSystemBrowser();
			});
			
			MenuItem newProjectItem = new MenuItem("Create a new project...");
			newProjectItem.setOnAction((event) -> {
				final Project project = new Project(song);
				final ProjectEditorDialog dialog = new ProjectEditorDialog(project);
				dialog.initOwner(owner);
				dialog.showAndWait().ifPresent((b) -> {
					if (b.booleanValue()) {
						song.getProjects().add(project);
						project.updateFiles();
					}
				});
			});
			
			MenuItem importProjectItem = new MenuItem("Import project from file...");
			importProjectItem.setOnAction((event) -> {
				
				final FileChooser chooser = new FileChooser();
				chooser.setTitle("Select FLP to import...");
				chooser.getExtensionFilters().add(new ExtensionFilter("FL Studio project file", "*.flp"));
				File file = chooser.showOpenDialog(getOwnerWindow());
				if (file != null) {
					Project project = new Project(song);
					project.setName(file.getName());
					ProjectEditorDialog dialog = new ProjectEditorDialog(project);
					dialog.initOwner(owner);
					dialog.showAndWait().ifPresent((b) -> {
						if (b.booleanValue()) {
							try {
								song.getProjects().add(project);
								project.updateFiles();
								FileUtils.copyFile(file, project.getProjectFile());
							} catch (IOException e) {
								e.printStackTrace();
								Messenger.get().message(MessageType.ERROR, "Could not copy project file.", e.getMessage());
							}
						}
					});
				}
			});
{'fraction_non_alphanumeric': 0.1349671669793621, 'fraction_numerical': 0.0, 'mean_word_length': 4.178506375227687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6351963', 'n_tokens_mistral': 3085, 'n_tokens_neox': 2550, 'n_words': 463}