/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 */
package org.mwc.cmap.NarrativeViewer.actions;

import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.ActionGroup;
import org.mwc.cmap.NarrativeViewer.NarrativeViewer;
import org.mwc.cmap.NarrativeViewer.NarrativeViewerModel;


public class NarrativeViewerActions extends ActionGroup {
	private final AbstractDynamicAction myShowVisibleColumn;
	private final AbstractDynamicAction myShowSourceColumn;
	private final AbstractDynamicAction myShowTypeColumn;
	
	private final AbstractDynamicAction myFilterSource;
	private final AbstractDynamicAction myFilterType;
	
	public NarrativeViewerActions(final NarrativeViewer viewer){
		final NarrativeViewerModel model = viewer.getModel();
		myShowSourceColumn = new SwitchColumnVisibilityAction(model.getColumnSource(), "Show source");
		myShowVisibleColumn = new SwitchColumnVisibilityAction(model.getColumnVisible(), "Show visible");
		myShowVisibleColumn.setChecked(false);
		myShowTypeColumn = new SwitchColumnVisibilityAction(model.getColumnType(), "Show type");
		
		myFilterSource = new OpenFilterAction(viewer, model.getColumnSource(), "Set source filter...");
		myFilterType = new OpenFilterAction(viewer, model.getColumnType(), "Set type filter...");
	}
	
	@Override
	public void updateActionBars() {
		super.updateActionBars();
		updateActions();
	}
	
	@Override
	public void fillActionBars(final IActionBars actionBars) {
		super.fillActionBars(actionBars);
		final IMenuManager menu = actionBars.getMenuManager();
		menu.add(myShowVisibleColumn);
		menu.add(myShowSourceColumn);
		menu.add(myShowTypeColumn);
		menu.add(new Separator());
		menu.add(myFilterSource);
		menu.add(myFilterType);
		
		menu.addMenuListener(new IMenuListener() {
			public void menuAboutToShow(final IMenuManager manager) {
				updateActions();
			}
		});
	}
	
	void updateActions(){
		myFilterSource.refresh();
		myFilterType.refresh();
		myShowSourceColumn.refresh();
		myShowTypeColumn.refresh();
		myShowVisibleColumn.refresh();
	}
	
}

@@ -979,67 +979,8 @@
  %7B%0D%0A
-%09private final AbstractDynamicAction myShowVisibleColumn;%0D%0A
 %09pri
@@ -1033,16 +1033,16 @@
 olumn;%0D%0A
+
 %09private
@@ -1423,151 +1423,8 @@
 );%0D%0A
-%09%09myShowVisibleColumn = new SwitchColumnVisibilityAction(model.getColumnVisible(), %22Show visible%22);%0D%0A%09%09myShowVisibleColumn.setChecked(false);%0D%0A
 %09%09my
@@ -1989,42 +1989,8 @@
 );%0D%0A
-%09%09menu.add(myShowVisibleColumn);%0D%0A
 %09%09me
@@ -2394,32 +2394,32 @@
 umn.refresh();%0D%0A
+
 %09%09myShowTypeColu
@@ -2437,42 +2437,8 @@
 );%0D%0A
-%09%09myShowVisibleColumn.refresh();%0D%0A
 %09%7D%0D%0A

remove visible column