/**
 * 
 */
package org.sinouplen.tools.ui.file;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;

import org.apache.log4j.Logger;

/**
 * @author Sinouplen
 * 
 */
public class OpenFileModel<R extends Object, T extends ILoadFile<R>> extends
		AbstractAction {

	private static final long serialVersionUID = -2317690157960036847L;

	private static final Logger LOGGER = Logger.getLogger(OpenFileModel.class);

	private Component component;
	private JFileChooser jFileChooser;

	private Class<R> returnClass;
	private T loadFile;
	private R returnObject;

	/**
	 * @return the returnObject
	 */
	public R getReturnObject() {
		return returnObject;
	}

	/**
	 * 
	 * @return the parent file of chooser file
	 */
	public File getParentFileChooserPath() {
		return this.jFileChooser.getSelectedFile().getParentFile();
	}

	public OpenFileModel(Class<R> returnClass, T loadFile, Component component,
			JFileChooser jFileChosser) {
		super("Open File...");
		this.component = component;
		this.jFileChooser = jFileChosser;

		this.returnClass = returnClass;
		this.loadFile = loadFile;
	}

	public void actionPerformed(ActionEvent actionEvent) {
		LOGGER.debug("OpenFileModel action performed");
		// Show the open file dialog and not return until dialog is closed
		this.jFileChooser.showOpenDialog(this.component);

		if (this.jFileChooser.getSelectedFile() != null) {
			File selectedFile = this.jFileChooser.getSelectedFile();
			if (selectedFile == null) {
				this.returnObject = null;
			} else {
				LOGGER.debug("Show load file object " + this.loadFile);
				this.returnObject = this.loadFile.Open(returnClass,
						selectedFile);
				LOGGER.debug("Show return object " + this.returnObject);
			}
		}
	}
}

@@ -288,18 +288,16 @@
 ileModel
-%3CR
  extends
@@ -301,50 +301,8 @@
 nds 
-Object, T extends ILoadFile%3CR%3E%3E extends%0A%09%09
 Abst
@@ -543,74 +543,23 @@
 ate 
-Class%3CR%3E returnClass;%0A%09private T loadFile;%0A%09private R
+File
  return
-Object
+File
 ;%0A%0A%09
@@ -604,17 +604,20 @@
 %09public 
-R
+File
  getRetu
@@ -618,22 +618,20 @@
 etReturn
-Object
+File
 () %7B%0A%09%09r
@@ -642,22 +642,20 @@
 n return
-Object
+File
 ;%0A%09%7D%0A%0A%09/
@@ -845,42 +845,8 @@
 del(
-Class%3CR%3E returnClass, T loadFile, 
 Comp
@@ -861,20 +861,17 @@
 mponent,
-%0A%09%09%09
+ 
 JFileCho
@@ -985,71 +985,8 @@
 ser;
-%0A%0A%09%09this.returnClass = returnClass;%0A%09%09this.loadFile = loadFile;
 %0A%09%7D%0A
@@ -1274,21 +1274,19 @@
 %0A%09%09%09
-File selected
+this.return
 File
@@ -1329,284 +1329,8 @@
 ();%0A
-%09%09%09if (selectedFile == null) %7B%0A%09%09%09%09this.returnObject = null;%0A%09%09%09%7D else %7B%0A%09%09%09%09LOGGER.debug(%22Show load file object %22 + this.loadFile);%0A%09%09%09%09this.returnObject = this.loadFile.Open(returnClass,%0A%09%09%09%09%09%09selectedFile);%0A%09%09%09%09LOGGER.debug(%22Show return object %22 + this.returnObject);%0A%09%09%09%7D%0A
 %09%09%7D%0A

Update OpenFileModel.java