package edu.fichte.pbi.ide;

import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	public static final String MY_COLROW_TELLER = Activator.PLUGIN_ID
			+ ".colrowteller";
	private IWorkbenchAction save;
	private IWorkbenchAction saveAll;
	private IWorkbenchAction saveAs;

	// IWorkbenchAction newFile;

	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	@Override
	protected void makeActions(IWorkbenchWindow window) {
		save = ActionFactory.SAVE.create(window);
		saveAll = ActionFactory.SAVE_ALL.create(window);
		saveAs = ActionFactory.SAVE_AS.create(window);
		// newFile = ActionFactory.NEW.create(window);
	}

	@Override
	protected void fillCoolBar(ICoolBarManager coolBar) {
		ToolBarManager toolBarManager = new ToolBarManager();
		toolBarManager.add(save);
		toolBarManager.add(saveAs);
		toolBarManager.add(saveAll);
		// toolBarManager.add(newFile);
		// for (IWizardDescriptor e : getAllWizards(WorkbenchPlugin.getDefault()
		// .getNewWizardRegistry().getRootCategory().getCategories())) {
		// System.out.println(e.toString());
		//
		// }
		// AbstractExtensionWizardRegistry wizardRegistry =
		// (AbstractExtensionWizardRegistry)WorkbenchPlugin.getDefault().getNewWizardRegistry();
		//
		// IWizardCategory[] categories =
		// WorkbenchPlugin.getDefault().getNewWizardRegistry().getRootCategory().getCategories();
		//
		// for(IWizardDescriptor wizard : getAllWizards(categories)){
		// WorkbenchWizardElement wizardElement = (WorkbenchWizardElement)
		// wizard;
		// wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
		// new Object[]{wizardElement});
		// }
		coolBar.add(new GroupMarker("edu.fichte.pbi.ide.toolbar"));
		coolBar.add(toolBarManager);
	}

	@Override
	protected void fillMenuBar(IMenuManager menuBar) {
	}

	// private IWizardDescriptor[] getAllWizards(IWizardCategory[] categories) {
	// List<IWizardDescriptor> results = new ArrayList<IWizardDescriptor>();
	// for (IWizardCategory wizardCategory : categories) {
	// results.addAll(Arrays.asList(wizardCategory.getWizards()));
	// results.addAll(Arrays.asList(getAllWizards(wizardCategory
	// .getCategories())));
	// }
	// return results.toArray(new IWizardDescriptor[0]);
	// }

	@Override
	protected void fillStatusLine(IStatusLineManager statusLine) {
		statusLine.add(new StatusLineContributionItem(MY_COLROW_TELLER, 10));
		super.fillStatusLine(statusLine);
	}

}
