1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.wizards.ui;
24 
25 import com.sun.star.awt.XListBox;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.wizards.common.Helper;
28 import com.sun.star.wizards.common.JavaTools;
29 import com.sun.star.wizards.common.PropertyNames;
30 
31 /**
32  * @author Administrator
33  *
34  * To change the template for this generated type comment go to
35  * Window>Preferences>Java>Code Generation>Code and Comments
36  */
37 public abstract class DBLimitedFieldSelection
38 {
39 
40     protected XMultiServiceFactory xMSF;
41     protected WizardDialog CurUnoDialog;
42     protected String sNoField;
43     protected Integer IStep;
44     protected Integer ICompPosX;
45     protected Integer ICompPosY;
46     protected Integer ICompWidth;
47     protected final int rowcount = 4;
48     protected final int MAXSELINDEX = rowcount - 1;
49     protected short curtabindex;
50     protected int iCurPosY;
51     protected int FirstHelpIndex;
52     protected int iCompPosX;
53     // protected int MaxSelIndex;
54 
DBLimitedFieldSelection(WizardDialog _CurUnoDialog, int iStep, int _iCompPosX, int iCompPosY, int iCompWidth, int _FirstHelpIndex)55     public DBLimitedFieldSelection(WizardDialog _CurUnoDialog, int iStep, int _iCompPosX, int iCompPosY, int iCompWidth, int _FirstHelpIndex)
56     {
57         this.CurUnoDialog = _CurUnoDialog;
58         xMSF = CurUnoDialog.xMSF;
59         FirstHelpIndex = _FirstHelpIndex;
60         curtabindex = (short) (iStep * 100);
61         sNoField = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 8);
62         IStep = new Integer(iStep);
63         iCompPosX = _iCompPosX;
64         ICompPosX = new Integer(iCompPosX);
65         ICompPosY = new Integer(iCompPosY);
66         ICompWidth = new Integer(iCompWidth);
67         // boolean bDoEnable;
68         iCurPosY = iCompPosY;
69         for (int i = 0; i < rowcount; i++)
70         {
71             insertControlGroup(i);
72         }
73     }
74 
insertControlGroup(int index)75     protected abstract void insertControlGroup(int index);
76 
toggleControlRow(int CurIndex, boolean bDoEnable)77     protected abstract void toggleControlRow(int CurIndex, boolean bDoEnable);
78 
enableNextControlRow(int CurIndex)79     protected abstract void enableNextControlRow(int CurIndex);
80 
updateFromNextControlRow(int CurIndex)81     protected abstract void updateFromNextControlRow(int CurIndex);
82 
83     // protected abstract void setMaxSelIndex();
84 
getMaxSelIndex()85     protected abstract int getMaxSelIndex();
86 
moveupSelectedItems(int CurIndex, boolean bDoEnable)87     protected void moveupSelectedItems(int CurIndex, boolean bDoEnable)
88     {
89         // short iNextItemPos;
90         if ((!bDoEnable) && (MAXSELINDEX > CurIndex))
91         {
92             for (int i = CurIndex; i < MAXSELINDEX; i++)
93             {
94                 updateFromNextControlRow(i);
95             }
96             if (getMaxSelIndex() < rowcount - 2)
97             {
98                 toggleControlRow(getMaxSelIndex() + 2, false);
99             }
100         }
101         else
102         {
103             toggleControlRow(CurIndex + 1, bDoEnable);
104         }
105     }
106 
addNoneFieldItemToList(String[] _FieldNames)107     protected String[] addNoneFieldItemToList(String[] _FieldNames)
108     {
109         int FieldCount = _FieldNames.length;
110         String[] ViewFieldNames = new String[FieldCount + 1];
111         ViewFieldNames[0] = sNoField;
112         System.arraycopy(_FieldNames, 0, ViewFieldNames, 1, FieldCount);
113         return ViewFieldNames;
114     }
115 
initializeListBox(XListBox xListBox, String[] _AllFieldNames, String[] _SelFieldNames, int curindex)116     protected void initializeListBox(XListBox xListBox, String[] _AllFieldNames, String[] _SelFieldNames, int curindex)
117     {
118         short[] SelList = null;
119         Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.STRING_ITEM_LIST, _AllFieldNames);
120         if (_SelFieldNames != null)
121         {
122             if (curindex < _SelFieldNames.length)
123             {
124                 int index = JavaTools.FieldInList(_AllFieldNames, _SelFieldNames[curindex]);
125                 if (index > -1)
126                 {
127                     SelList = new short[] { (short) (index) };
128                 }
129                 else
130                 {
131                     SelList = new short[] { (short) (0) };
132                 }
133                 Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList);
134                 return;
135             }
136         }
137         SelList = new short[] { (short) (0) };
138         Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList);
139 
140     }
141 
initializeListBox(XListBox xListBox, String[] _AllFieldNames, String _SelFieldName)142     protected void initializeListBox(XListBox xListBox, String[] _AllFieldNames, String _SelFieldName)
143     {
144         Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.STRING_ITEM_LIST, _AllFieldNames);
145         short[] SelList = null;
146         int index = JavaTools.FieldInList(_AllFieldNames, _SelFieldName);
147         SelList = new short[] { (short) (index) };
148         Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList);
149     }
150 }
151 
152 
153