<commit_before>/* 
	Copyright (c) 2016, <NAME> <https://github.com/AquariusPower><https://sourceforge.net/u/teike/profile/>
	
	All rights reserved.

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

	1.	Redistributions of source code must retain the above copyright notice, this list of conditions 
		and the following disclaimer.

	2.	Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
		and the following disclaimer in the documentation and/or other materials provided with the distribution.
	
	3.	Neither the name of the copyright holder nor the names of its contributors may be used to endorse 
		or promote products derived from this software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
	WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
	PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
	ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
	LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
	OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
	IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.github.commandsconsolegui.spLemur.dialog;

import java.io.File;
import java.lang.reflect.Field;

import com.github.commandsconsolegui.spAppOs.globals.GlobalAppOSI;
import com.github.commandsconsolegui.spAppOs.misc.MsgI;
import com.github.commandsconsolegui.spAppOs.misc.PrerequisitesNotMetException;
import com.github.commandsconsolegui.spCmd.varfield.FileVarField;
import com.github.commandsconsolegui.spJme.extras.DialogListEntryData;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Command;


/**
 * 
 * @author <NAME> <https://github.com/AquariusPower><https://sourceforge.net/u/teike/profile/>
 *
 */
public class FileChoiceDialogStateI extends ChoiceLemurDialogStateAbs<Command<Button>,FileChoiceDialogStateI> {
	private static FileChoiceDialogStateI	instance=new FileChoiceDialogStateI();
	public static FileChoiceDialogStateI i(){return instance;}
	
	public static class CfgParm extends ChoiceLemurDialogStateAbs.CfgParm{
		public CfgParm() {
			super(null,null,null,null);
		}
	}
	
//	private File	flChosen;
	
	CfgParm cfg;
	
	@Override
	public FileChoiceDialogStateI configure(ICfgParm icfg) {
		this.cfg=(CfgParm)icfg;
		super.configure(icfg);
		return getThis();
	}
	
	@Override
	protected void updateList() {
		clearList();
		
		DialogListEntryData<Command<Button>> dledAtParent = getParentReferencedDledListCopy().get(0);
		Object obj = dledAtParent.getLinkedObj();
		File fl = null;
		if (obj instanceof FileVarField) {
			FileVarField flf = (FileVarField) obj;
			fl = flf.getFile();
		}else
		if (obj instanceof File) {
			fl = (File) obj;
		}else{
			throw new PrerequisitesNotMetException("unsupported type", obj.getClass(), obj);
		}
		
		if(!fl.exists()){
			fl=new File(GlobalAppOSI.i().getAssetsFolder()+File.separator+fl.getPath());
			PrerequisitesNotMetException.assertIsTrue("path exist", fl.exists(), fl);
		}
		
		File flDir = fl.getParentFile();
		
		MsgI.i().debug("current path",(new File(".")).getAbsolutePath());
		
		//folders 
		for(File flTmp:flDir.listFiles()){ //flDir=new File("./Sounds/Effects/UI/13940__gameaudio__game-audio-ui-sfx/")
			if(!flTmp.isDirectory())continue;
			DialogListEntryData dled = new DialogListEntryData(this);
			dled.setText(">"+flTmp.getName()+"/", flTmp); // prepended a token just to help on sorting
			addEntry(dled);
		}
		
		// files
		for(File flTmp:flDir.listFiles()){ //flDir=new File("./Sounds/Effects/UI/13940__gameaudio__game-audio-ui-sfx/")
			if(!flTmp.isFile())continue;
			DialogListEntryData dled = new DialogListEntryData(this);
			dled.setText(flTmp.getName(), flTmp);
			addEntry(dled);
		}
		<commit_msg>b4 fixing DialogListEntryData generics parm<commit_after>/* 
	Copyright (c) 2016, <NAME> <https://github.com/AquariusPower><https://sourceforge.net/u/teike/profile/>
	
	All rights reserved.

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

	1.	Redistributions of source code must retain the above copyright notice, this list of conditions 
		and the following disclaimer.

	2.	Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
		and the following disclaimer in the documentation and/or other materials provided with the distribution.
	
	3.	Neither the name of the copyright holder nor the names of its contributors may be used to endorse 
		or promote products derived from this software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
	WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
	PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
	ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
	LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
	OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
	IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.github.commandsconsolegui.spLemur.dialog;

import java.io.File;
import java.lang.reflect.Field;

import com.github.commandsconsolegui.spAppOs.globals.GlobalAppOSI;
import com.github.commandsconsolegui.spAppOs.misc.ManageCallQueueI;
import com.github.commandsconsolegui.spAppOs.misc.ManageCallQueueI.CallableX;
import com.github.commandsconsolegui.spAppOs.misc.MsgI;
import com.github.commandsconsolegui.spAppOs.misc.PrerequisitesNotMetException;
import com.github.commandsconsolegui.spCmd.varfield.FileVarField;
import com.github.commandsconsolegui.spJme.extras.DialogListEntryData;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Command;


/**
 * 
 * @author <NAME> <https://github.com/AquariusPower><https://sourceforge.net/u/teike/profile/>
 *
 */
public class FileChoiceDialogStateI extends ChoiceLemurDialogStateAbs<Command<Button>,FileChoiceDialogStateI> {
	private static FileChoiceDialogStateI	instance=new FileChoiceDialogStateI();
	public static FileChoiceDialogStateI i(){return instance;}
	
	public static class CfgParm extends ChoiceLemurDialogStateAbs.CfgParm{
		public CfgParm() {
			super(null,null,null,null);
		}
	}
	
//	private File	flChosen;
	
	CfgParm cfg;
	
	@Override
	public FileChoiceDialogStateI configure(ICfgParm icfg) {
		this.cfg=(CfgParm)icfg;
		super.configure(icfg);
		return getThis();
	}
	
	@Override
	protected void updateList() {
		clearList();
		
		DialogListEntryData<Command<Button>> dledAtParent = getParentReferencedDledListCopy().get(0);
		Object obj = dledAtParent.getLinkedObj();
		File flAtParentTmp;
		if (obj instanceof FileVarField) {
			FileVarField flf = (FileVarField) obj;
			flAtParentTmp = flf.getFile();
		}else
		if (obj instanceof File) {
			flAtParentTmp = (File) obj;
		}else{
			throw new PrerequisitesNotMetException("unsupported type", obj.getClass(), obj);
		}
		
		if(!flAtParentTmp.exists()){ //try assets folder
			flAtParentTmp=new File(GlobalAppOSI.i().getAssetsFolder()+File.separator+flAtParentTmp.getPath());
			PrerequisitesNotMetException.assertIsTrue("path exist", flAtParentTmp.exists(), flAtParentTmp);
		}
		
		File flDir = flAtParentTmp.getParentFile();
		
		MsgI.i().debug("current path",(new File(".")).getAbsolutePath()); //TODO this dont work why?
		
		DialogListEntryData<Command<Button>> dledSelectTmp=null;
		
		//folders 
		for(File flTmp:flDir.listFiles()){ //flDir=new File("./Sounds/Effects/UI/13940__gameaudio__game-audio-ui-sfx/")
			if(!flTmp.isDirectory())continue;
			DialogListEntryData dled = new DialogListEntryData(this);
			dled.setText(">"+flTmp.getName()+"/", flTmp); // prepended a token just to help on sorting
			addEntry(dled);
//			if(flTmp.equals(flAtParent)){
//				dledSelectTmp=dled;
//			}
		}
		
		// files
		for(File flTmp:flDir.listFiles()){ //flDir=new File("./Sounds/Effects/UI/13940__gameaudio__game-audio-ui-sfx/")
			if(!flTmp.isFile())continue;
			DialogListEntryData dled = new DialogListEntryData(this);
			dled.setText(flTmp.getName(), flTmp);
			addEntry(dled);
//			if(flTmp.equals(flAtParent)){
//				dledSelectTmp=dled;
//			}
		}
		
//		for(DialogListEntryData<Command<Button>> dled:getCompleteEntriesListCopy()){
//			if(dled.getLinkedObj().getName().equals(dledAtParent.getLinkedObj()))
//		}
		
//		final DialogListEntryData<Command<Button>> dledSelect=dledSelectTmp;
		final File flAtParent = flAtParentTmp;
		ManageCallQueueI.i().addCall(new CallableX(this,100) {
			@Override
			public Boolean call() {
				for(DialogListEntryData dled:getCompleteEntriesListCopy()){
					File fl = (File)dled.getLinkedObj();
					if(fl.equals(flAtParent)){
						selectEntry(dled);
						return true;
					}
				}
				return false;
			}
		});
		
{'fraction_non_alphanumeric': 0.10185959047221062, 'fraction_numerical': 0.004178854993731718, 'mean_word_length': 4.837195121951219, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 8, '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': '4629784', 'n_tokens_mistral': 3332, 'n_tokens_neox': 2911, 'n_words': 792}