001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.hayabusa.taglib;
017
018import org.opengion.fukurou.util.ToString;                                              // 6.1.1.0 (2015/01/17)
019
020import static org.opengion.fukurou.util.StringUtil.nval;
021
022/**
023 * 左右分割スクロール処理を行う、View を設定します。
024 *
025 * BODY部に記述された Viewタグに対して、左右分割情報を追記設定します。
026 * Viewタグの左側には、このタグで指定された fixDisplay のカラムを columnDisplay に
027 * 設定するとともに、このタグで指定された numberType をセットします。
028 * (初期値は、numberType="sequence" です。)
029 * Viewタグの右側には、fixDisplay のカラムを noDisplay のカラムに設定するとともに、
030 * command="VIEW" , noMessage="true" , useSelectedRow="false" , numberType="delete"
031 * をセットします。(既存の設定値があれば、それに追記されます。)
032 *
033 * @og.formSample
034 * ●形式:<og:splitView  fixDisplay="CLM,NAME_JA"><og:view ・・・  /></og:splitView>
035 * ●body:あり(EVAL_BODY_INCLUDE:BODYをインクルードし、{@XXXX} は解析しません)
036 *
037 * ●Tag定義:
038 *   <og:splitView
039 *       fixDisplay         【TAG】固定するカラム名を、CSV形式(CSV形式)で設定します
040 *       debug              【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false)
041 *   >   ... Body ...
042 *   </og:splitView>
043 *
044 * ●使用例
045 *    <og:splitView fixDisplay="CLM,NAME_JA">
046 *      <og:view
047 *          viewFormType    = "HTMLTable"
048 *          command         = "{@command}"
049 *          checked         = "{@checked}"
050 *          startNo         = "{@startNo}"
051 *          pageSize        = "{@pageSize}"
052 *          noWritable      = "{@noWritable}"
053 *          columnWritable  = "{@columnWritable}"
054 *      />
055 *    </og:splitView>
056 *
057 * @og.rev 5.3.0.0 (2010/12/01) 新規作成
058 * @og.group 画面部品
059 *
060 * @version  4.0
061 * @author       Kazuhiko Hasegawa
062 * @since    JDK5.0,
063 */
064public class SplitViewTag extends CommonTagSupport {
065        /** このプログラムのVERSION文字列を設定します。   {@value} */
066        private static final String VERSION = "6.4.2.0 (2016/01/29)" ;
067        private static final long serialVersionUID = 642020160129L ;
068
069        private static final String SPLIT_A =
070                                  "<style type=\"text/css\">#GantBody div tr { height:22px; }</style>"                          + CR
071                                + "<table id=\"GantBody\" border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\""       + CR
072                                + "       frame=\"box\" rules=\"all\" style=\"margin:0px;padding:0px;\">"                       + CR
073                                + "  <tr style=\"margin:0px;padding:0px;\">"                                                                            + CR
074                                + "    <td valign=\"top\" style=\"margin:0px; padding:0px;\" >"                                         + CR
075                                + "      <div id=\"X1\" style=\"overflow-x:hidden; overflow-y:hidden;\" >"                      + CR ;
076
077        private static final String SPLIT_B =
078                                  "      </div>"                                                                                                        + CR
079                                + "    </td>"                                                                                                           + CR
080                                + "    <td valign=\"top\" style=\"margin:0px; padding:0px;\">"          + CR
081                                + "      <div id=\"X2\" style=\"position:absolute; overflow-x:hidden; overflow-y:hidden;\" >" + CR ;
082
083        private static final String SPLIT_C =
084                                  "       </div>"               + CR
085                                + "    </td>"                   + CR
086                                + "  </tr>"                             + CR
087                                + "</table>"                    + CR ;
088
089        private String  fixDisplay              ;
090        private boolean firstStepFlag   = true;         // BODY部の view 処理の制御
091
092        /**
093         * デフォルトコンストラクター
094         *
095         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
096         */
097        public SplitViewTag() { super(); }              // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
098
099        /**
100         * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。
101         *
102         * @return      後続処理の指示( EVAL_BODY_INCLUDE )
103         */
104        @Override
105        public int doStartTag() {
106                firstStepFlag = true;
107                // EVAL_BODY_BUFFERED ではなく、Viewなので、INCLUDE 処理します。
108                jspPrint( SPLIT_A );
109                return EVAL_BODY_INCLUDE ;      // Body インクルード( extends TagSupport 時)
110        }
111
112        /**
113         * Taglibのタグ本体を処理する doAfterBody() を オーバーライドします。
114         *
115         * @return      後続処理の指示(SKIP_BODY)
116         */
117        @Override
118        public int doAfterBody() {
119                // EVAL_BODY_INCLUDE なので、コンテンツの取得ではなく、処理のみ実行されます。
120
121                if( firstStepFlag ) {
122                        firstStepFlag = false;
123
124                        jspPrint( SPLIT_B );
125                        return EVAL_BODY_BUFFERED ;     // ボディーを再評価( extends BodyTagSupport 時)
126                }
127                else {
128                        jspPrint( SPLIT_C );
129                        return SKIP_BODY ;                              // Body を評価しない
130                }
131        }
132
133        /**
134         * タグリブオブジェクトをリリースします。
135         * キャッシュされて再利用されるので、フィールドの初期設定を行います。
136         *
137         */
138        @Override
139        protected void release2() {
140                super.release2();
141                fixDisplay = null;
142        }
143
144        /**
145         * 【TAG】固定するカラム名を、CSV形式(CSV形式)で設定します。
146         *
147         * @og.tag
148         * Viewタグの左側(固定部)には、このタグで指定された fixDisplay のカラムを
149         * columnDisplay に設定します。
150         * Viewタグの右側には、fixDisplay のカラムを noDisplay のカラムに設定します。
151         * 既存の設定値(noDisplay)があれば、それに追記されます。
152         *
153         * @param   clms 固定するカラム名(CSV形式)
154         */
155        public void setFixDisplay( final String clms ) {
156                fixDisplay = nval( getRequestParameter( clms ),fixDisplay );
157        }
158
159        /**
160         * 固定するカラム名を、CSV形式(CSV形式)で取得します。
161         *
162         * これは、BODY部に記述された、viewタグからアクセスされるメソッドです。
163         * 設定されていない場合は、null です。
164         *
165         * @return      固定するカラム名(CSV形式)
166         */
167        protected String getFixDisplay() {
168                return fixDisplay ;
169        }
170
171        /**
172         * BODY部の view 処理の制御を行うためのフラグを返します。
173         *
174         * 左右分割を行うには、Viewタグを2回出力する必要があります。
175         * ここでは isFirstStep="true" が1回目(左側:固定部)で、false が
176         * 右側(可変部)になるように、View側で制御します。
177         *
178         * @return      BODY部の view 処理の制御(true:1回目 / false:2回目)
179         */
180        protected boolean isFirstStep() {
181                return firstStepFlag ;
182        }
183
184        /**
185         * このオブジェクトの文字列表現を返します。
186         * 基本的にデバッグ目的に使用します。
187         *
188         * @return このクラスの文字列表現
189         * @og.rtnNotNull
190         */
191        @Override
192        public String toString() {
193                return ToString.title( this.getClass().getName() )
194                                .println( "VERSION"                     ,VERSION        )
195                                .println( "fixDisplay"          ,fixDisplay     )
196                                .println( "Other..."    ,getAttributes().getAttribute() )
197                                .fixForm().toString() ;
198        }
199}