package smart_gs.swingui.toolbar.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.swing.JOptionPane;

import org.apache.commons.io.FileUtils;

import smart_gs.logical.LineSegment;
import smart_gs.logical.Spread;
import smart_gs.smleditor.swingui.LineSegEditor;
import smart_gs.swingui.AbstractGSWindow;
import smart_gs.util.DSCFileMaker;

public class DeleteLineSegmentsFileAction implements ActionListener {
	private LineSegEditor editor;
	private Spread spread;
	public DeleteLineSegmentsFileAction(LineSegEditor parent) {
		this.editor = parent;
	}

	public void actionPerformed(ActionEvent e) {
		this.spread = this.editor.getSpread();

		String folderPath = Spread.DSC_FOLDER_PATH+spread.getSpreadDirParent().getPath();
		String filename = spread.getFileNameWithoutExtension();
		File file = new File(folderPath + filename + ".xml");
		try {
			FileUtils.forceDelete(file);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		System.out.println(file.toString());
		if (!file.exists()){
			JOptionPane.showMessageDialog(null,filename + ".xml deleted");
		} else {
			JOptionPane.showMessageDialog(null,"failed to delete " + filename + ".xml");
		}
	}
}