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.FontDescriptor;
26 import com.sun.star.awt.XListBox;
27 import com.sun.star.wizards.common.*;
28 import com.sun.star.wizards.common.JavaTools;
29 
30 import java.util.*;
31 
32 /**
33  *
34  * @author  bc93774
35  */
36 public class FieldSelection
37 {
38     public XListBox xFieldsListBox;                 // Left ListBox
39     public XListBox xSelectedFieldsListBox;         // right (selected) ListBox
40 
41     protected UnoDialog CurUnoDialog;
42     protected String sIncSuffix;
43     protected int FirstHelpIndex;
44     protected boolean AppendMode = false;
45     protected Integer IStep;
46 
47     protected int CompPosX;
48     protected int CompPosY;
49     protected int CompHeight;
50     protected int CompWidth;
51 
52     private XFieldSelectionListener xFieldSelection;
53     private int maxfieldcount = 10000000;
54     private String[] AllFieldNames;
55     private Integer ListBoxWidth;
56 
57     private Integer SelListBoxPosX;
58 
59     private boolean bisModified = false;
60 
61     private final static int SOCMDMOVESEL = 1;
62     private final static int SOCMDMOVEALL = 2;
63     private final static int SOCMDREMOVESEL = 3;
64     private final static int SOCMDREMOVEALL = 4;
65     private final static int SOCMDMOVEUP = 5;
66     private final static int SOCMDMOVEDOWN = 6;
67     private final static int SOFLDSLST = 7;
68     private final static int SOSELFLDSLST = 8;
69 
70 
71     class ItemListenerImpl implements com.sun.star.awt.XItemListener
72     {
73 
itemStateChanged(com.sun.star.awt.ItemEvent EventObject)74         public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject)
75         {
76             // int iPos;
77             com.sun.star.wizards.common.Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE);
78             int iKey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList);
79             switch (iKey)
80             {
81 
82                 case SOFLDSLST:
83                     toggleListboxButtons((short) - 1, (short) - 1);
84                     break;
85 
86                 case SOSELFLDSLST:
87                     toggleListboxButtons((short) - 1, (short) - 1);
88                     break;
89                 default:
90                     break;
91             }
92             com.sun.star.wizards.common.Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.TRUE);
93         }
94 
disposing(com.sun.star.lang.EventObject eventObject)95         public void disposing(com.sun.star.lang.EventObject eventObject)
96         {
97         }
98     }
99 
100     class ActionListenerImpl implements com.sun.star.awt.XActionListener
101     {
102 
disposing(com.sun.star.lang.EventObject eventObject)103         public void disposing(com.sun.star.lang.EventObject eventObject)
104         {
105         }
106 
actionPerformed(com.sun.star.awt.ActionEvent actionEvent)107         public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent)
108         {
109             try
110             {
111                 int iKey = CurUnoDialog.getControlKey(actionEvent.Source, CurUnoDialog.ControlList);
112                 switch (iKey)
113                 {
114                     case SOFLDSLST:
115                         selectFields(false);
116                         break;
117 
118                     case SOSELFLDSLST:
119                         deselectFields(false);
120                         break;
121 
122                     case SOCMDMOVESEL:
123                         selectFields(false);
124                         break;
125 
126                     case SOCMDMOVEALL:
127                         selectFields(true);
128                         break;
129 
130                     case SOCMDREMOVESEL:
131                         deselectFields(false);
132                         break;
133 
134                     case SOCMDREMOVEALL:
135                         deselectFields(true);
136                         break;
137 
138                     case SOCMDMOVEUP:
139                         changeSelectionOrder(-1);
140                         break;
141 
142                     case SOCMDMOVEDOWN:
143                         changeSelectionOrder(1);
144                         break;
145 
146                     default:
147                         // System.err.println( exception);
148                         break;
149                 }
150             }
151             catch (Exception exception)
152             {
153                 exception.printStackTrace(System.out);
154             }
155         }
156     }
157 
addFieldSelectionListener(XFieldSelectionListener xFieldSelection)158     public void addFieldSelectionListener(XFieldSelectionListener xFieldSelection)
159     {
160         this.xFieldSelection = xFieldSelection;
161         this.xFieldSelection.setID(sIncSuffix);
162     }
163 
setAppendMode(boolean _AppendMode)164     public void setAppendMode(boolean _AppendMode)
165     {
166         AppendMode = _AppendMode;
167     }
168 
getAppendMode()169     public boolean getAppendMode()
170     {
171         return AppendMode;
172     }
173 
FieldSelection(UnoDialog CurUnoDialog, int _iStep, int CompPosX, int CompPosY, int CompWidth, int CompHeight, String slblFields, String slblSelFields, int _FirstHelpIndex, boolean bshowFourButtons)174     public FieldSelection(UnoDialog CurUnoDialog, int _iStep, int CompPosX, int CompPosY, int CompWidth, int CompHeight, String slblFields, String slblSelFields, int _FirstHelpIndex, boolean bshowFourButtons)
175     {
176         try
177         {
178             final String AccessTextMoveSelected = CurUnoDialog.m_oResource.getResText(UIConsts.RID_DB_COMMON + 39);
179             final String AccessTextRemoveSelected = CurUnoDialog.m_oResource.getResText(UIConsts.RID_DB_COMMON + 40);
180             final String AccessTextMoveAll = CurUnoDialog.m_oResource.getResText(UIConsts.RID_DB_COMMON + 41);
181             final String AccessTextRemoveAll = CurUnoDialog.m_oResource.getResText(UIConsts.RID_DB_COMMON + 42);
182             final String AccessMoveFieldUp = CurUnoDialog.m_oResource.getResText(UIConsts.RID_DB_COMMON + 43);
183             final String AccessMoveFieldDown = CurUnoDialog.m_oResource.getResText(UIConsts.RID_DB_COMMON + 44);
184 
185             FirstHelpIndex = _FirstHelpIndex;
186             short curtabindex = UnoDialog.setInitialTabindex(_iStep);
187             int ShiftButtonCount = 2;
188             int a = 0;
189             this.CurUnoDialog = CurUnoDialog;
190             this.CompPosX = CompPosX;
191             this.CompPosY = CompPosY;
192             this.CompHeight = CompHeight;
193             this.CompWidth = CompWidth;
194             Object btnmoveall = null;
195             Object btnremoveall = null;
196 
197             final int cmdButtonWidth = 16;
198             final int cmdButtonHoriDist = 4;
199             final int lblHeight = 8;
200             final int lblVertiDist = 2;
201 
202             ListBoxWidth = new Integer(((CompWidth - 3 * cmdButtonHoriDist - 2 * cmdButtonWidth) / 2));
203             Integer cmdShiftButtonPosX = new Integer((CompPosX + ListBoxWidth.intValue() + cmdButtonHoriDist));
204             Integer ListBoxPosY = new Integer(CompPosY + lblVertiDist + lblHeight);
205             Integer ListBoxHeight = new Integer(CompHeight - 8 - 2);
206             SelListBoxPosX = new Integer(cmdShiftButtonPosX.intValue() + cmdButtonWidth + cmdButtonHoriDist);
207 
208             IStep = new Integer(_iStep);
209             if (bshowFourButtons)
210             {
211                 ShiftButtonCount = 4;
212             }
213             Integer[] ShiftButtonPosY = getYButtonPositions(ShiftButtonCount);
214             Integer[] MoveButtonPosY = getYButtonPositions(2);
215             Integer cmdMoveButtonPosX = new Integer(SelListBoxPosX.intValue() + ListBoxWidth.intValue() + cmdButtonHoriDist);
216 
217             Integer CmdButtonWidth = new Integer(cmdButtonWidth);
218 
219             sIncSuffix = "_" + com.sun.star.wizards.common.Desktop.getIncrementSuffix(CurUnoDialog.getDlgNameAccess(), "lblFields_");
220 
221             // Label
222             CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblFields" + sIncSuffix,
223                     new String[]
224                     {
225                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
226                     },
227                     new Object[]
228                     {
229                         8, slblFields, new Integer(CompPosX), new Integer(CompPosY), IStep, new Short(curtabindex), 109
230                     });
231 
232             // Listbox 'Available fields'
233             xFieldsListBox = CurUnoDialog.insertListBox("lstFields" + sIncSuffix, SOFLDSLST, new ActionListenerImpl(), new ItemListenerImpl(),
234                     new String[]
235                     {
236                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "MultiSelection", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
237                     },
238                     new Object[]
239                     {
240                         ListBoxHeight, HelpIds.getHelpIdString(_FirstHelpIndex), Boolean.TRUE, new Integer(CompPosX), ListBoxPosY, IStep, new Short((curtabindex++)), ListBoxWidth
241                     });
242 
243             Object btnmoveselected = CurUnoDialog.insertButton("cmdMoveSelected" + sIncSuffix, SOCMDMOVESEL, new ActionListenerImpl(),
244                     new String[]
245                     {
246                         PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
247                     },
248                     new Object[]
249                     {
250                         Boolean.FALSE, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 1), ">", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, new Short(curtabindex++), CmdButtonWidth
251                     });
252 
253             if (bshowFourButtons)
254             {
255                 btnmoveall = CurUnoDialog.insertButton("cmdMoveAll" + sIncSuffix, SOCMDMOVEALL, new ActionListenerImpl(),
256                         new String[]
257                         {
258                             PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
259                         },
260                         new Object[]
261                         {
262                             14, HelpIds.getHelpIdString(_FirstHelpIndex + 2), ">>", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, new Short(curtabindex++), CmdButtonWidth
263                         });
264             }
265             Object btnremoveselected = CurUnoDialog.insertButton("cmdRemoveSelected" + sIncSuffix, SOCMDREMOVESEL, new ActionListenerImpl(),
266                     new String[]
267                     {
268                         PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
269                     },
270                     new Object[]
271                     {
272                         Boolean.FALSE, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 3), "<", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, new Short(curtabindex++), CmdButtonWidth
273                     });
274 
275             if (bshowFourButtons)
276             {
277                 btnremoveall = CurUnoDialog.insertButton("cmdRemoveAll" + sIncSuffix, SOCMDREMOVEALL, new ActionListenerImpl(),
278                         new String[]
279                         {
280                             PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
281                         },
282                         new Object[]
283                         {
284                             14, HelpIds.getHelpIdString(_FirstHelpIndex + 4), "<<", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, new Short(curtabindex++), CmdButtonWidth
285                         });
286             }
287 
288             FontDescriptor oFontDesc = new FontDescriptor();
289             oFontDesc.Name = "StarSymbol";
290 
291             // Label 'Fields in the form'
292             CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblSelFields" + sIncSuffix,
293                     new String[]
294                     {
295                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
296                     },
297                     new Object[]
298                     {
299                         8, slblSelFields, SelListBoxPosX, new Integer(CompPosY), IStep, new Short(curtabindex++), ListBoxWidth
300                     });
301 
302             // ListBox 'Fields in the form'
303             xSelectedFieldsListBox = CurUnoDialog.insertListBox("lstSelFields" + sIncSuffix, SOSELFLDSLST, new ActionListenerImpl(), new ItemListenerImpl(),
304                     new String[]
305                     {
306                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "MultiSelection", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
307                     },
308                     new Object[]
309                     {
310                         ListBoxHeight, HelpIds.getHelpIdString(_FirstHelpIndex + 5), Boolean.TRUE, SelListBoxPosX, ListBoxPosY, IStep, new Short(curtabindex++), ListBoxWidth
311                     });
312 
313             Object btnmoveup = CurUnoDialog.insertButton("cmdMoveUp" + sIncSuffix, SOCMDMOVEUP, new ActionListenerImpl(),
314                     new String[]
315                     {
316                         PropertyNames.PROPERTY_ENABLED, PropertyNames.FONT_DESCRIPTOR, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
317                     },
318                     new Object[]
319                     {
320                         Boolean.FALSE, oFontDesc, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 6), String.valueOf((char) 8743), cmdMoveButtonPosX, MoveButtonPosY[0], IStep, new Short(curtabindex++), CmdButtonWidth
321                     });
322 
323             Object btnmovedown = CurUnoDialog.insertButton("cmdMoveDown" + sIncSuffix, SOCMDMOVEDOWN, new ActionListenerImpl(),
324                     new String[]
325                     {
326                         PropertyNames.PROPERTY_ENABLED, PropertyNames.FONT_DESCRIPTOR, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
327                     },
328                     new Object[]
329                     {
330                         Boolean.FALSE, oFontDesc, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 7), String.valueOf((char) 8744), cmdMoveButtonPosX, MoveButtonPosY[1], IStep, new Short(curtabindex++), CmdButtonWidth
331                     });
332 
333             CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmoveselected, AccessTextMoveSelected);
334             CurUnoDialog.getPeerConfiguration().setAccessibleName(btnremoveselected, AccessTextRemoveSelected);
335             CurUnoDialog.getPeerConfiguration().setAccessibleName(xFieldsListBox, JavaTools.replaceSubString(slblFields, PropertyNames.EMPTY_STRING, "~"));
336             CurUnoDialog.getPeerConfiguration().setAccessibleName(xSelectedFieldsListBox, JavaTools.replaceSubString(slblSelFields, PropertyNames.EMPTY_STRING, "~"));
337             if (btnmoveall != null)
338             {
339                 CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmoveall, AccessTextMoveAll);
340             }
341             if (btnremoveall != null)
342             {
343                 CurUnoDialog.getPeerConfiguration().setAccessibleName(btnremoveall, AccessTextRemoveAll);
344             }
345             if (btnmoveup != null)
346             {
347                 CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmoveup, AccessMoveFieldUp);
348             }
349             if (btnmovedown != null)
350             {
351                 CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmovedown, AccessMoveFieldDown);
352             }
353 
354         }
355         catch (Exception exception)
356         {
357             exception.printStackTrace(System.out);
358         }
359     }
360 
361     // Todo: If Value is getting smaller than zero -> throw exception
getYButtonPositions(int ButtonCount)362     private Integer[] getYButtonPositions(int ButtonCount)
363     {
364         Integer[] YPosArray;
365         if (ButtonCount > 0)
366         {
367             YPosArray = new Integer[ButtonCount];
368             final int cmdButtonHeight = 14;
369             final int cmdButtonVertiDist = 2;
370 
371             YPosArray[0] = new Integer( (CompPosY + 10 + (((CompHeight - 10) - (ButtonCount * cmdButtonHeight) - ((ButtonCount - 1) * cmdButtonVertiDist)) / 2)));
372             if (ButtonCount > 1)
373             {
374                 for (int i = 1; i < ButtonCount; i++)
375                 {
376                     YPosArray[i] = new Integer(YPosArray[i - 1].intValue() + cmdButtonHeight + cmdButtonVertiDist);
377                 }
378             }
379             return YPosArray;
380         }
381         return null;
382     }
383 
getListboxWidth()384     public Integer getListboxWidth()
385     {
386         return this.ListBoxWidth;
387     }
388 
changeSelectionOrder(int iNeighbor)389     private void changeSelectionOrder(int iNeighbor)
390     {
391         short[] iSelIndices = xSelectedFieldsListBox.getSelectedItemsPos();
392         // Todo: we are assuming that the array starts with the lowest index. Verfy this assumption!!!!!
393         if (iSelIndices.length == 1)
394         {
395             short iSelIndex = iSelIndices[0];
396             String[] NewItemList = xSelectedFieldsListBox.getItems();
397             String CurItem = NewItemList[iSelIndex];
398             String NeighborItem = NewItemList[iSelIndex + iNeighbor];
399             NewItemList[iSelIndex + iNeighbor] = CurItem;
400             NewItemList[iSelIndex] = NeighborItem;
401             CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, NewItemList);
402             xSelectedFieldsListBox.selectItem(CurItem, true);
403             if (xFieldSelection != null)
404             {
405                 if (iNeighbor < 0)
406                 {
407                     xFieldSelection.moveItemUp(CurItem);
408                 }
409                 else
410                 {
411                     xFieldSelection.moveItemDown(CurItem);
412                 }
413             }
414         }
415     }
416 
toggleListboxControls(Boolean BDoEnable)417     public void toggleListboxControls(Boolean BDoEnable)
418     {
419         try
420         {
421             CurUnoDialog.setControlProperty("lblFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable);
422             CurUnoDialog.setControlProperty("lblSelFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable);
423             CurUnoDialog.setControlProperty("lstFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable);
424             CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable);
425 
426             if (BDoEnable.booleanValue())
427             {
428                 toggleListboxButtons((short) - 1, (short) - 1);
429             }
430             else
431             {
432                 CurUnoDialog.setControlProperty("cmdRemoveAll" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable);
433                 CurUnoDialog.setControlProperty("cmdRemoveSelected" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable);
434                 toggleMoveButtons(BDoEnable.booleanValue(), BDoEnable.booleanValue());
435             }
436         }
437         catch (Exception exception)
438         {
439             exception.printStackTrace(System.out);
440         }
441     }
442 
443     // Enable or disable the buttons used for moving the available
444     // fields between the two list boxes.
toggleListboxButtons(short iFieldsSelIndex, short iSelFieldsSelIndex)445     protected void toggleListboxButtons(short iFieldsSelIndex, short iSelFieldsSelIndex)
446     {
447         try
448         {
449             boolean bmoveUpenabled = false;
450             boolean bmoveDownenabled = false;
451             CurUnoDialog.selectListBoxItem(xFieldsListBox, iFieldsSelIndex);
452             CurUnoDialog.selectListBoxItem(xSelectedFieldsListBox, iSelFieldsSelIndex);
453             int SelListBoxSelLength = xSelectedFieldsListBox.getSelectedItems().length;
454             int ListBoxSelLength = xFieldsListBox.getSelectedItems().length;
455             boolean bIsFieldSelected = (ListBoxSelLength > 0);
456             int FieldCount = xFieldsListBox.getItemCount();
457             boolean bSelectSelected = (SelListBoxSelLength > 0);
458             int SelectCount = xSelectedFieldsListBox.getItemCount();
459             if (bSelectSelected)
460             {
461                 short[] iSelIndices = xSelectedFieldsListBox.getSelectedItemsPos();
462                 bmoveUpenabled = ((iSelIndices[0] > 0) && (iSelIndices.length == 1));
463                 bmoveDownenabled = (((iSelIndices[SelListBoxSelLength - 1]) < (short) (SelectCount - 1)) && (iSelIndices.length == 1));
464             }
465             CurUnoDialog.setControlProperty("cmdRemoveAll" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(SelectCount >= 1));
466             CurUnoDialog.setControlProperty("cmdRemoveSelected" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bSelectSelected));
467             toggleMoveButtons((FieldCount >= 1), bIsFieldSelected);
468             CurUnoDialog.setControlProperty("cmdMoveUp" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bmoveUpenabled));
469             CurUnoDialog.setControlProperty("cmdMoveDown" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bmoveDownenabled));
470         }
471         catch (Exception exception)
472         {
473             exception.printStackTrace(System.out);
474         }
475     }
476 
toggleMoveButtons(boolean _btoggleMoveAll, boolean _btoggleMoveSelected)477     protected void toggleMoveButtons(boolean _btoggleMoveAll, boolean _btoggleMoveSelected)
478     {
479         boolean btoggleMoveAll = (((xFieldsListBox.getItemCount() + xSelectedFieldsListBox.getItemCount()) < maxfieldcount) && (_btoggleMoveAll));
480         boolean btoggleMoveSelected = (((xFieldsListBox.getSelectedItems().length + xSelectedFieldsListBox.getItemCount()) < maxfieldcount) && (_btoggleMoveSelected));
481         CurUnoDialog.setControlProperty("cmdMoveAll" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(btoggleMoveAll));
482         CurUnoDialog.setControlProperty("cmdMoveSelected" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(btoggleMoveSelected));
483     }
484 
setMultipleMode(boolean _bisMultiple)485     public void setMultipleMode(boolean _bisMultiple)
486     {
487         xFieldsListBox.setMultipleMode(_bisMultiple);
488         xSelectedFieldsListBox.setMultipleMode(_bisMultiple);
489     }
490 
emptyFieldsListBoxes()491     public void emptyFieldsListBoxes()
492     {
493         try
494         {
495             toggleListboxControls(Boolean.FALSE);
496             CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, new String[]
497                     {
498                     });
499             CurUnoDialog.setControlProperty("lstFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, new String[]
500                     {
501                     });
502         }
503         catch (Exception exception)
504         {
505             exception.printStackTrace(System.out);
506         }
507     }
508 
mergeList(String[] AllFieldNames, String[] SecondList)509     public void mergeList(String[] AllFieldNames, String[] SecondList)
510     {
511         // int MaxIndex = SecondList.length;
512         xFieldsListBox.addItems(AllFieldNames, (short) 0);
513         toggleListboxButtons((short) - 1, (short) - 1);
514     }
515 
intializeSelectedFields(String[] _SelectedFieldNames)516     public void intializeSelectedFields(String[] _SelectedFieldNames)
517     {
518         xSelectedFieldsListBox.addItems(_SelectedFieldNames, xSelectedFieldsListBox.getItemCount());
519     }
520 
removeAllItems(XListBox _xListBox)521     private void removeAllItems(XListBox _xListBox)
522     {
523         _xListBox.removeItems((short) 0, _xListBox.getItemCount());
524     }
525 
526     // Note Boolean Parameter
initialize(String[] _AllFieldNames, boolean _AppendMode)527     public void initialize(String[] _AllFieldNames, boolean _AppendMode)
528     {
529         AppendMode = _AppendMode;
530         removeAllItems(xFieldsListBox);
531         xFieldsListBox.addItems(_AllFieldNames, (short) 0);
532         AllFieldNames = xFieldsListBox.getItems();
533         if ((xSelectedFieldsListBox.getItemCount() > 0) && (!AppendMode))
534         {
535             removeAllItems(xSelectedFieldsListBox);
536         }
537         toggleListboxControls(Boolean.TRUE);
538     }
539 
initialize(String[][] _AllFieldNamesTable, boolean _AppendMode, int _maxfieldcount)540     public void initialize(String[][] _AllFieldNamesTable, boolean _AppendMode, int _maxfieldcount)
541     {
542         String[] AllFieldNames_ = new String[_AllFieldNamesTable.length];
543         for (int i = 0; i < _AllFieldNamesTable.length; i++)
544         {
545             AllFieldNames_[i] = _AllFieldNamesTable[i][0];
546         }
547         initialize(AllFieldNames_, _AppendMode, _maxfieldcount);
548     }
549 
initialize(String[] _AllFieldNames, boolean _AppendMode, int _maxfieldcount)550     public void initialize(String[] _AllFieldNames, boolean _AppendMode, int _maxfieldcount)
551     {
552         maxfieldcount = _maxfieldcount;
553         initialize(_AllFieldNames, _AppendMode);
554     }
555 
initialize(String[] _AllFieldNames, String[] _SelFieldNames, boolean _AppendMode)556     public void initialize(String[] _AllFieldNames, String[] _SelFieldNames, boolean _AppendMode)
557     {
558         removeAllItems(xSelectedFieldsListBox);
559         xSelectedFieldsListBox.addItems(_SelFieldNames, (short) 0);
560         initialize(_AllFieldNames, _AppendMode);
561     }
562 
selectFields(boolean bMoveAll)563     public void selectFields(boolean bMoveAll)
564     {
565         // int CurIndex;
566         short iFieldSelected = (short) - 1;
567         short iSelFieldSelected = (short) - 1;
568         // int MaxCurTarget = xSelectedFieldsListBox.getItemCount();
569         String[] SelFieldItems;
570         if (bMoveAll)
571         {
572             SelFieldItems = xFieldsListBox.getItems();
573             removeAllItems(xFieldsListBox);
574             if (!AppendMode)
575             {
576                 removeAllItems(xSelectedFieldsListBox);
577                 xSelectedFieldsListBox.addItems(AllFieldNames, (short) 0);
578             }
579             else
580             {
581                 xSelectedFieldsListBox.addItems(SelFieldItems, xSelectedFieldsListBox.getItemCount());
582             }
583         }
584         else
585         {
586             SelFieldItems = xFieldsListBox.getSelectedItems();
587             int MaxSourceSelected = SelFieldItems.length;
588             if (MaxSourceSelected > 0)
589             {
590                 iFieldSelected = xFieldsListBox.getSelectedItemPos();
591                 iSelFieldSelected = xSelectedFieldsListBox.getSelectedItemPos();
592                 short[] SourceSelList = new short[xFieldsListBox.getSelectedItemsPos().length];
593                 SourceSelList = xFieldsListBox.getSelectedItemsPos();
594                 xSelectedFieldsListBox.addItems(SelFieldItems, xSelectedFieldsListBox.getItemCount());
595                 CurUnoDialog.removeSelectedItems(xFieldsListBox);
596                 xSelectedFieldsListBox.selectItemPos((short) 0, xSelectedFieldsListBox.getSelectedItems().length > 0);
597             }
598         }
599         toggleListboxButtons(iFieldSelected, iSelFieldSelected);
600         if (xFieldSelection != null)
601         {
602             xFieldSelection.shiftFromLeftToRight(SelFieldItems, xSelectedFieldsListBox.getItems());
603         }
604     }
605 
deselectFields(boolean bMoveAll)606     public void deselectFields(boolean bMoveAll)
607     {
608         // int m = 0;
609         String SearchString;
610         short iOldFieldSelected = xFieldsListBox.getSelectedItemPos();
611         short iOldSelFieldSelected = xSelectedFieldsListBox.getSelectedItemPos();
612         String[] OldSelFieldItems = xSelectedFieldsListBox.getSelectedItems();
613         if (bMoveAll)
614         {
615             OldSelFieldItems = xSelectedFieldsListBox.getItems();
616             removeAllItems(xFieldsListBox);
617             xFieldsListBox.addItems(AllFieldNames, (short) 0);
618             removeAllItems(xSelectedFieldsListBox);
619         }
620         else
621         {
622             int MaxOriginalCount = AllFieldNames.length;
623             // int MaxSelected = OldSelFieldItems.length;
624             String[] SelList = xFieldsListBox.getItems();
625             Vector<String> NewSourceVector = new Vector<String>();
626             for (int i = 0; i < MaxOriginalCount; i++)
627             {
628                 SearchString = AllFieldNames[i];
629                 if (JavaTools.FieldInList(SelList, SearchString) != -1)
630                 {
631                     NewSourceVector.addElement(SearchString);
632                 }
633                 else if (JavaTools.FieldInList(OldSelFieldItems, SearchString) != -1)
634                 {
635                     NewSourceVector.addElement(SearchString);
636                 }
637             }
638             xFieldsListBox.removeItems((short) 0, xFieldsListBox.getItemCount());
639             if (NewSourceVector.size() > 0)
640             {
641                 String[] NewSourceList = new String[NewSourceVector.size()];
642                 NewSourceVector.toArray(NewSourceList);
643                 xFieldsListBox.addItems(NewSourceList, (short) 0);
644             }
645             CurUnoDialog.removeSelectedItems(xSelectedFieldsListBox);
646         }
647         toggleListboxButtons(iOldFieldSelected, iOldSelFieldSelected);
648         String[] NewSelFieldItems = xSelectedFieldsListBox.getItems();
649         if (xFieldSelection != null)
650         {
651             xFieldSelection.shiftFromRightToLeft(OldSelFieldItems, NewSelFieldItems);
652         }
653     }
654 
addItemsToFieldsListbox(String[] _sItems)655     public void addItemsToFieldsListbox(String[] _sItems)
656     {
657         String[] sOldList = xFieldsListBox.getItems();
658         for (int i = 0; i < _sItems.length; i++)
659         {
660             if (JavaTools.FieldInList(sOldList, _sItems[i]) < 0)
661             {
662                 xFieldsListBox.addItem(_sItems[i], xFieldsListBox.getItemCount());
663             }
664         }
665     }
666 
getSelectedFieldNames()667     public String[] getSelectedFieldNames()
668     {
669         return (String[]) CurUnoDialog.getControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST);
670     }
671 
setSelectedFieldNames(String[] _sfieldnames)672     public void setSelectedFieldNames(String[] _sfieldnames)
673     {
674         CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, _sfieldnames);
675         String[] sleftboxfieldnames = JavaTools.removefromList(xFieldsListBox.getItems(), _sfieldnames);
676         CurUnoDialog.setControlProperty("lstFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, sleftboxfieldnames);
677     }
678 
setModified(boolean _bModified)679     public void setModified(boolean _bModified)
680     {
681         bisModified = _bModified;
682     }
683 
isModified()684     public boolean isModified()
685     {
686         return bisModified;
687     }
688 
changeSelectedFieldNames(String[] _sfieldnames)689     public void changeSelectedFieldNames(String[] _sfieldnames)
690     {
691         CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, _sfieldnames);
692     }
693 }
694