package de.ugoe.cs.swe.memos.gui.menu;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.PlatformUI;

import de.ugoe.cs.swe.memos.ExportManager;
import de.ugoe.cs.swe.memos.gui.dialogs.ExportDialog;

public class exportHandler implements IHandler {
	private static boolean enabled = true;

	public static void setEnabled(boolean state) {
		enabled = state;
	}

	@Override
	public void addHandlerListener(IHandlerListener handlerListener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		ExportDialog exportdialog = new ExportDialog(PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getShell());
		ExportManager exportmanager = ExportManager.getInstance();

		if (exportdialog.open() == IDialogConstants.OK_ID) {

			exportmanager.setAuthorFilter(exportdialog.getAuthorFilter());
			exportmanager.setCategoryFilter(exportdialog
					.getActivecategoryFilter());
			exportmanager.setTimeFilter(exportdialog.getFromPointInTime(),
					exportdialog.getTillPointInTime());
			exportmanager.setExportPath(exportdialog.getExportFile());
			exportmanager.setUseDateFilter(exportdialog.isUseDateFilter());
			exportmanager.setUseCategoryFilter(exportdialog.isUseCategoryFilter());
			exportmanager.ExportFilteredMemosToXML();
		}

		return null;
	}

	@Override
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return enabled;
	}

	@Override
	public boolean isHandled() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void removeHandlerListener(IHandlerListener handlerListener) {
		// TODO Auto-generated method stub

	}

}
