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