package org.vaadin.patrik.demo;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Push;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;

@Push
@Theme("demo")
@Title("GridFastNavigation Add-on Demo")
@SuppressWarnings("serial")
public class DemoUI extends UI {

	@WebServlet(value = "/*", asyncSupported = true)
	@VaadinServletConfiguration(productionMode = false, ui = DemoUI.class, widgetset = "org.vaadin.patrik.demo.DemoWidgetSet")
	public static class Servlet extends VaadinServlet {
	}

	public DemoUI() {
	}

	@Override
	protected void init(VaadinRequest vaadinRequest) {
		final VerticalLayout layout = new VerticalLayout();

		layout.setSizeFull();
		
		MessageGrid messageGrid = new MessageGrid();
		DemoFastGrid demoGrid = new DemoFastGrid(messageGrid);
	
		
		Button clearButton = new Button("Clear");
		clearButton.addClickListener(e ->  {
			messageGrid.clear();
		});
		
		
		Button addButton = new Button();
		addButton.setIcon(VaadinIcons.PLUS_CIRCLE); // Add Row
		addButton.addClickListener(e -> {
			demoGrid.addBlankRow();
		});
		addButton.setDescription("Add a new row");

		Button rowValidationButton = new Button();
		rowValidationButton.setIcon(VaadinIcons.CHECK_CIRCLE_O);
		rowValidationButton.setStyleName(ValoTheme.BUTTON_QUIET);
		rowValidationButton.addClickListener(e -> {
			demoGrid.getNavigation().setRowValidation(!demoGrid.getNavigation().getRowValidation());
			if (!demoGrid.getNavigation().getRowValidation()) rowValidationButton.setStyleName(ValoTheme.BUTTON_QUIET);
			else rowValidationButton.setStyleName(ValoTheme.BUTTON_FRIENDLY);
		});
		rowValidationButton.setDescription("Toggle rowValidation");

		Button rowOpenClickButton = new Button();
		rowOpenClickButton.setIcon(VaadinIcons.FOLDER_OPEN_O);
		rowOpenClickButton.setStyleName(ValoTheme.BUTTON_FRIENDLY);
		rowOpenClickButton.addClickListener(e -> {
			demoGrid.getNavigation().setOpenEditorWithSingleClick(!demoGrid.getNavigation().getOpenEditorWithSingleClick());
			if (!demoGrid.getNavigation().getOpenEditorWithSingleClick()) rowOpenClickButton.setStyleName(ValoTheme.BUTTON_QUIET);
			else rowOpenClickButton.setStyleName(ValoTheme.BUTTON_FRIENDLY);
		});
		rowOpenClickButton.setDescription("Toggle openEditorWithSingleClick");

		Button rowOpenByTypingButton = new Button();
		rowOpenByTypingButton.setIcon(VaadinIcons.KEYBOARD_O);
		rowOpenByTypingButton.setStyleName(ValoTheme.BUTTON_FRIENDLY);
		rowOpenByTypingButton.addClickListener(e -> {
			demoGrid.getNavigation().setOpenEditorOnTyping(!demoGrid.getNavigation().getOpenEditorOnTyping());
			if (!demoGrid.getNavigation().getOpenEditorOnTyping()) rowOpenByTypingButton.setStyleName(ValoTheme.BUTTON_QUIET);
			else rowOpenByTypingButton.setStyleName(ValoTheme.BUTTON_FRIENDLY);
		});
		rowOpenByTypingButton.setDescription("Toggle openEditorOnTyping");
		
		HorizontalLayout buttons = new HorizontalLayout();
		buttons.addComponents(addButton,rowValidationButton,rowOpenClickButton,rowOpenByTypingButton);
		
		layout.setMargin(true);
		layout.setSpacing(true);
		layout.addComponent(demoGrid);
		layout.addComponent(buttons);
		layout.addComponent(messageGrid);
		layout.addComponent(clearButton);
		layout.setSizeFull();
		layout.setExpandRatio(demoGrid, 10);
		layout.setExpandRatio(buttons, 1);
		layout.setExpandRatio(clearButton, 1);
		layout.setExpandRatio(messageGrid, 6);

		setContent(layout);
	}
}

@@ -71,16 +71,65 @@
 rvlet;%0A%0A
+import com.vaadin.annotations.PreserveOnRefresh;%0A
 import c
@@ -581,16 +581,35 @@
 %0A%0A@Push%0A
+@PreserveOnRefresh%0A
 @Theme(%22
@@ -3279,16 +3279,744 @@
 yping%22);
+%0A%0A        Button disableGridEditButton = new Button();%0A        disableGridEditButton.setIcon(VaadinIcons.PENCIL);%0A%09%09disableGridEditButton.setDescription(%22Toggle Grid Editing%22);%0A%09%09disableGridEditButton.setStyleName(ValoTheme.BUTTON_FRIENDLY);%0A        disableGridEditButton.addClickListener(e-%3E%7B%0A        %09if (demoGrid.getEditor().isEnabled()) %7B%0A        %09%09if (demoGrid.getEditor().isOpen()) %7B%0A        %09%09%09demoGrid.getEditor().cancel();%0A        %09%09%7D%0A        %09%09demoGrid.getEditor().setEnabled(false);%0A        %09%09disableGridEditButton.setStyleName(ValoTheme.BUTTON_QUIET);%0A        %09%7D else %7B%0A        %09%09demoGrid.getEditor().setEnabled(true);%0A        %09%09disableGridEditButton.setStyleName(ValoTheme.BUTTON_FRIENDLY);%0A        %09%7D%0A        %7D);%09%09
 %0A%09%09%0A%09%09Ho
@@ -4154,24 +4154,46 @@
 TypingButton
+,disableGridEditButton
 );%0A%09%09%0A%09%09layo

Add editor enabled/disabled button to demo