/*
 * Copyright (c) 2017 mikan
 */

package com.github.javatrainingcourse.obogmanager.ui;

import com.github.javatrainingcourse.obogmanager.Version;
import com.github.javatrainingcourse.obogmanager.ui.view.ErrorView;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.Viewport;
import com.vaadin.server.*;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.spring.annotation.SpringViewDisplay;
import com.vaadin.ui.UI;
import com.vaadin.ui.themes.ValoTheme;

/**
 * Vaadin UI を定義します。
 *
 * @author mikan
 * @since 0.1
 */
@SpringUI
@SpringViewDisplay
@Theme(ValoTheme.THEME_NAME)
@Title("Java研修 Go研修 OB・OG会")
@Viewport("user-scalable=no,width=600")
public class MainUI extends UI {

    public static final int FIELD_WIDTH_WIDE = 300;
    public static final int FIELD_WIDTH_SHORT = 50;
    private static final long serialVersionUID = Version.INSTANCE.getOBOG_MANAGER_SERIAL_VERSION_UID();
    private static final SystemMessagesProvider SYSTEM_MESSAGES = new JapaneseSystemMessageProvider();

    @Override
    protected void init(VaadinRequest request) {
        getReconnectDialogConfiguration().setDialogText("サーバーとの接続が切れました。再接続しています...");
        if (VaadinService.getCurrent() != null) {
            VaadinService.getCurrent().setSystemMessagesProvider(SYSTEM_MESSAGES);
        }
        getNavigator().setErrorView(ErrorView.class);
    }

    private static class JapaneseSystemMessageProvider implements SystemMessagesProvider {

        private static final long serialVersionUID = Version.INSTANCE.getOBOG_MANAGER_SERIAL_VERSION_UID();
        private static final CustomizedSystemMessages MESSAGES = new CustomizedSystemMessages();
        private static final String MSG1 = "保存していないデータがあれば書き留めた上で、";
        private static final String MSG2 = "<u>ここをクリック</u>するか ESC キーを押して続行してください。";

        static {
            MESSAGES.setSessionExpiredCaption("セッションが切れました");
            MESSAGES.setSessionExpiredMessage(MSG1 + MSG2);
            MESSAGES.setSessionExpiredNotificationEnabled(true);
            MESSAGES.setCommunicationErrorCaption("通信に失敗しました");
            MESSAGES.setCommunicationErrorMessage(MSG1 + MSG2);
            MESSAGES.setCommunicationErrorNotificationEnabled(true);
            MESSAGES.setAuthenticationErrorCaption("認証に失敗しました");
            MESSAGES.setAuthenticationErrorMessage(MSG1 + MSG2);
            MESSAGES.setAuthenticationErrorNotificationEnabled(true);
            MESSAGES.setInternalErrorCaption("内部エラーが発生しました");
            MESSAGES.setInternalErrorMessage(MSG1 + MSG2);
            MESSAGES.setInternalErrorNotificationEnabled(true);
            MESSAGES.setCookiesDisabledCaption("Cookie が無効です");
            MESSAGES.setCookiesDisabledMessage("このアプリケーションは Cookie 機能を利用しています。<br/>" +
                    "ブラウザで Cookie を有効にした後で、" + MSG2);
            MESSAGES.setCookiesDisabledNotificationEnabled(true);
        }

        @Override
        public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
            return MESSAGES;
        }
    }
}

@@ -1667,31 +1667,24 @@
     private 
-static 
 final Custom
@@ -1702,24 +1702,24 @@
 essages 
-MESSAGES
+messages
  = new C
@@ -1754,39 +1754,32 @@
         private 
-static 
 final String MSG
@@ -1775,19 +1775,23 @@
  String 
-MSG
+message
 1 = %22%E4%BF%9D%E5%AD%98%E3%81%97
@@ -1825,31 +1825,24 @@
     private 
-static 
 final String
@@ -1842,19 +1842,23 @@
  String 
-MSG
+message
 2 = %22%3Cu%3E
@@ -1905,22 +1905,47 @@
         
-static
+JapaneseSystemMessageProvider()
  %7B%0D%0A    
@@ -1948,32 +1948,32 @@
             
-MESSAGES
+messages
 .setSessionE
@@ -2011,32 +2011,32 @@
             
-MESSAGES
+messages
 .setSessionE
@@ -2045,34 +2045,42 @@
 iredMessage(
-MSG1 + MSG
+message1 + message
 2);%0D%0A       
@@ -2080,32 +2080,32 @@
             
-MESSAGES
+messages
 .setSessionE
@@ -2146,32 +2146,32 @@
             
-MESSAGES
+messages
 .setCommunic
@@ -2211,32 +2211,32 @@
             
-MESSAGES
+messages
 .setCommunic
@@ -2249,34 +2249,42 @@
 rrorMessage(
-MSG1 + MSG
+message1 + message
 2);%0D%0A       
@@ -2284,32 +2284,32 @@
             
-MESSAGES
+messages
 .setCommunic
@@ -2354,32 +2354,32 @@
             
-MESSAGES
+messages
 .setAuthenti
@@ -2420,32 +2420,32 @@
             
-MESSAGES
+messages
 .setAuthenti
@@ -2459,34 +2459,42 @@
 rrorMessage(
-MSG1 + MSG
+message1 + message
 2);%0D%0A       
@@ -2494,32 +2494,32 @@
             
-MESSAGES
+messages
 .setAuthenti
@@ -2565,32 +2565,32 @@
             
-MESSAGES
+messages
 .setInternal
@@ -2628,32 +2628,32 @@
             
-MESSAGES
+messages
 .setInternal
@@ -2669,18 +2669,26 @@
 age(
-MSG1 + MSG
+message1 + message
 2);%0D
@@ -2696,32 +2696,32 @@
             
-MESSAGES
+messages
 .setInternal
@@ -2761,32 +2761,32 @@
             
-MESSAGES
+messages
 .setCookiesD
@@ -2826,32 +2826,32 @@
             
-MESSAGES
+messages
 .setCookiesD
@@ -2957,11 +2957,15 @@
 %22 + 
-MSG
+message
 2);%0D
@@ -2977,24 +2977,24 @@
         
-MESSAGES
+messages
 .setCook
@@ -3173,24 +3173,24 @@
  return 
-MESSAGES
+messages
 ;%0D%0A     

update message provider