1 23 package org.objectweb.clif.scenario.util.isac.plugin.gui; 24 25 import java.util.EventListener ; 26 import java.util.Hashtable ; 27 import java.util.StringTokenizer ; 28 import java.util.Vector ; 29 30 import org.apache.log4j.Category; 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.custom.TableEditor; 33 import org.eclipse.swt.events.ModifyListener; 34 import org.eclipse.swt.events.SelectionEvent; 35 import org.eclipse.swt.events.SelectionListener; 36 import org.eclipse.swt.layout.FillLayout; 37 import org.eclipse.swt.layout.GridData; 38 import org.eclipse.swt.layout.GridLayout; 39 import org.eclipse.swt.widgets.Button; 40 import org.eclipse.swt.widgets.Combo; 41 import org.eclipse.swt.widgets.Composite; 42 import org.eclipse.swt.widgets.Control; 43 import org.eclipse.swt.widgets.Group; 44 import org.eclipse.swt.widgets.Label; 45 import org.eclipse.swt.widgets.Table; 46 import org.eclipse.swt.widgets.TableColumn; 47 import org.eclipse.swt.widgets.TableItem; 48 import org.eclipse.swt.widgets.Text; 49 50 56 public class ParameterWidget implements SelectionListener { 57 58 static Category cat = Category.getInstance(ParameterWidget.class.getName()); 59 60 private static final String EMPTY = "to be edited..."; 61 62 65 private int style; 66 67 private Composite composite; 68 69 private String name; 70 71 private String labelValue; 72 73 private Text textField; 74 75 private Group radioGroup; 76 77 private Group checkBox; 78 79 private Group group; 80 81 private Vector buttons; 82 83 private Combo combo; 84 85 private EventListener listener; 86 87 private Vector nfield; 88 89 private Vector nfieldLabel; 90 91 private Button nfieldAdd; 92 93 private Button nfieldRemove; 94 95 private Group nfieldGroup; 96 97 private Composite parent; 98 99 private Table table; 100 101 private Vector cellEditors; 102 103 private int cellYAxis; 104 105 private Vector cellText; 106 107 private Vector tableColumns; 108 109 126 public ParameterWidget(int style, String name, String labelValue, 127 Hashtable params, Composite parent, EventListener listener) { 128 cat.debug("-> constructor"); 129 this.listener = listener; 130 this.style = style; 131 this.name = name; 132 if (labelValue == null) { 133 this.labelValue = name; 134 } else { 135 if (labelValue.equals("")) { 136 this.labelValue = name; 137 } else { 138 this.labelValue = labelValue; 139 } 140 } 141 this.textField = null; 143 this.radioGroup = null; 144 this.checkBox = null; 145 this.group = null; 146 this.buttons = null; 147 this.nfield = null; 148 this.nfieldLabel = null; 149 this.nfieldAdd = null; 150 this.nfieldRemove = null; 151 this.nfieldGroup = null; 152 this.table = null; 153 this.tableColumns = null; 154 this.parent = parent; 156 this.composite = new Composite(parent, SWT.FLAT); 157 this.composite.setBackground(parent.getDisplay().getSystemColor( 158 SWT.COLOR_WHITE)); 159 GridLayout gridLayout = new GridLayout(); 160 gridLayout.numColumns = 1; 161 this.composite.setLayout(gridLayout); 162 GridData gridData = new GridData(); 164 gridData.horizontalAlignment = GridData.FILL; 165 gridData.grabExcessHorizontalSpace = true; 166 this.composite.setLayoutData(gridData); 167 switch (style) { 169 case WidgetDescription.TEXT_FIELD: 170 initField(params, this.composite); 171 break; 172 case WidgetDescription.RADIO_GROUP: 173 initRadioGroup(params, this.composite); 174 break; 175 case WidgetDescription.CHECK_BOX: 176 initCheckBox(params, this.composite); 177 break; 178 case WidgetDescription.GROUP: 179 initGroup(params, this.composite); 180 break; 181 case WidgetDescription.COMBO: 182 initCombo(params, this.composite); 183 break; 184 case WidgetDescription.NFIELD: 185 initNField(params, this.composite); 186 break; 187 case WidgetDescription.TABLE: 188 initTable(params, this.composite); 189 break; 190 default: 191 cat.warn("UNKNOW WIDGET STYLE : " + style); 192 } 193 } 194 195 198 public String getValue() { 199 cat.debug("-> getValue"); 200 switch (this.style) { 201 case WidgetDescription.TEXT_FIELD: 202 return getValueField(); 203 case WidgetDescription.RADIO_GROUP: 204 return getValueRadioGroup(); 205 case WidgetDescription.CHECK_BOX: 206 return getValueCheckBox(); 207 case WidgetDescription.GROUP: 208 return getValueGroup(); 209 case WidgetDescription.COMBO: 210 return getValueCombo(); 211 case WidgetDescription.NFIELD: 212 return getValueNField(); 213 case WidgetDescription.TABLE: 214 return getValueTable(); 215 default: 216 cat.warn("UNKNOW WIDGET STYLE..."); 217 return null; 218 } 219 } 220 221 227 public void setValue(String value) { 228 cat.debug("-> setValue"); 229 removeListeners(); 232 switch (this.style) { 233 case WidgetDescription.TEXT_FIELD: 234 setValueField(value); 235 break; 236 case WidgetDescription.RADIO_GROUP: 237 setValueRadioGroup(value); 238 break; 239 case WidgetDescription.CHECK_BOX: 240 setValueCheckBox(value); 241 break; 242 case WidgetDescription.GROUP: 243 setValueGroup(value); 244 break; 245 case WidgetDescription.COMBO: 246 setValueCombo(value); 247 break; 248 case WidgetDescription.NFIELD: 249 setValueNField(value); 250 break; 251 case WidgetDescription.TABLE: 252 setValueTable(value); 253 break; 254 default: 255 cat.warn("UNKNOW WIDGET STYLE..."); 256 } 257 addListeners(); 258 } 259 260 266 public void setComboValues(Vector values) { 267 cat.debug("-> setComboValues"); 268 for (int i = 0; i < values.size(); i++) { 269 this.combo.add((String ) values.elementAt(i)); 270 } 271 } 272 273 279 public boolean addEmtyFieldForNField(Object source) { 280 cat.debug("-> addEmptyFieldForNField"); 281 if (source != this.nfieldAdd) 283 return false; 284 Label label = new Label(this.nfieldGroup, SWT.NONE); 286 label 287 .setBackground(parent.getDisplay().getSystemColor( 288 SWT.COLOR_WHITE)); 289 label.setText("field " + this.nfield.size() + " : "); 291 this.nfieldLabel.add(label); 293 Text text = new Text(this.nfieldGroup, SWT.BORDER); 295 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 296 text.addModifyListener((ModifyListener) this.listener); 298 this.nfield.add(text); 300 this.nfieldGroup.layout(); 302 this.composite.layout(); 303 this.parent.layout(); 304 return true; 305 } 306 307 314 public boolean addEmtyEntryForTable(Object source) { 315 if (source != this.nfieldAdd) 316 return false; 317 TableItem temp = new TableItem(table, SWT.NONE); 318 String [] values = new String [this.tableColumns.size()]; 320 for (int i = 0; i < this.tableColumns.size(); i++) { 321 values[i] = new String (EMPTY); 322 } 323 temp.setText(values); 324 return true; 325 } 326 327 334 public boolean removeLastEntryForTable(Object source) { 335 if (source != this.nfieldRemove) 336 return false; 337 this.table.remove(this.table.getItemCount() - 1); 338 return true; 339 } 340 341 347 public boolean removeLastFieldForNField(Object source) { 348 cat.debug("-> removeLastFieldForNField"); 349 if (source != this.nfieldRemove) 351 return false; 352 if (this.nfield.isEmpty()) 353 return true; 354 Label lastLabel = (Label) this.nfieldLabel.elementAt(this.nfieldLabel 356 .size() - 1); 357 Text lastText = (Text) this.nfield.elementAt(this.nfield.size() - 1); 358 this.nfield.remove(lastText); 360 this.nfieldLabel.remove(lastLabel); 361 lastLabel.dispose(); 363 lastText.dispose(); 364 this.nfieldGroup.layout(); 366 this.composite.layout(); 367 this.parent.layout(); 368 return true; 369 } 370 371 375 378 public void removeListeners() { 379 switch (this.style) { 380 case WidgetDescription.TEXT_FIELD: 381 this.textField.removeModifyListener((ModifyListener) listener); 382 return; 383 case WidgetDescription.RADIO_GROUP: 384 this.removeButtonsListeners(); 385 return; 386 case WidgetDescription.CHECK_BOX: 387 this.removeButtonsListeners(); 388 return; 389 case WidgetDescription.COMBO: 390 this.combo.removeSelectionListener((SelectionListener) listener); 391 return; 392 case WidgetDescription.NFIELD: 393 this.removeNFieldListeners(); 394 return; 395 case WidgetDescription.TABLE: 396 return; 398 default: 399 cat.warn("UNKNOW WIDGET STYLE..."); 400 } 401 } 402 403 406 public void addListeners() { 407 switch (this.style) { 408 case WidgetDescription.TEXT_FIELD: 409 this.textField.addModifyListener((ModifyListener) listener); 410 return; 411 case WidgetDescription.RADIO_GROUP: 412 this.addButtonsListeners(); 413 return; 414 case WidgetDescription.CHECK_BOX: 415 this.addButtonsListeners(); 416 return; 417 case WidgetDescription.COMBO: 418 this.combo.addSelectionListener((SelectionListener) listener); 419 return; 420 case WidgetDescription.NFIELD: 421 this.addNFieldListeners(); 422 return; 423 case WidgetDescription.TABLE: 424 return; 426 default: 427 cat.warn("UNKNOW WIDGET STYLE..."); 428 } 429 } 430 431 435 private void removeButtonsListeners() { 436 for (int i = 0; i < this.buttons.size(); i++) 437 ((Button) this.buttons.elementAt(i)) 438 .removeSelectionListener((SelectionListener) listener); 439 } 440 441 private void addButtonsListeners() { 442 for (int i = 0; i < this.buttons.size(); i++) 443 ((Button) this.buttons.elementAt(i)) 444 .addSelectionListener((SelectionListener) listener); 445 } 446 447 450 private void removeNFieldListeners() { 451 for (int i = 0; i < this.nfield.size(); i++) { 452 ((Text) this.nfield.elementAt(i)) 453 .removeModifyListener((ModifyListener) this.listener); 454 } 455 } 456 457 460 private void addNFieldListeners() { 461 for (int i = 0; i < this.nfield.size(); i++) { 462 ((Text) this.nfield.elementAt(i)) 463 .addModifyListener((ModifyListener) this.listener); 464 } 465 } 466 467 471 474 private void initTable(Hashtable params, Composite parent) { 475 cat.debug("-> initTable, p=" + params); 476 this.nfieldGroup = new Group(parent, SWT.BORDER); 478 this.nfieldGroup.setBackground(parent.getDisplay().getSystemColor( 479 SWT.COLOR_WHITE)); 480 this.nfieldGroup.setText(this.labelValue + " : "); 481 this.nfieldGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); 483 GridLayout gd = new GridLayout(); 485 gd.numColumns = 1; 486 this.nfieldGroup.setLayout(gd); 487 Composite cButtons = new Composite(this.nfieldGroup, SWT.FLAT); 488 GridLayout gdc = new GridLayout(); 489 gdc.numColumns = 2; 490 cButtons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 491 cButtons.setBackground(parent.getDisplay().getSystemColor( 492 SWT.COLOR_WHITE)); 493 cButtons.setLayout(gdc); 494 this.nfieldAdd = new Button(cButtons, SWT.FLAT); 496 this.nfieldAdd.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 498 this.nfieldAdd.setText("Add entry"); 499 this.nfieldAdd.addSelectionListener((SelectionListener) this.listener); 500 this.nfieldRemove = new Button(cButtons, SWT.FLAT); 501 this.nfieldRemove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 502 this.nfieldRemove.setText("Remove entry"); 503 this.nfieldRemove 504 .addSelectionListener((SelectionListener) this.listener); 505 this.table = new Table(this.nfieldGroup, SWT.BORDER); 507 this.table.setLayoutData(new GridData(GridData.FILL_BOTH)); 508 this.tableColumns = new Vector (); 510 String cols = (String ) params.get("cols"); 512 Vector colsNames = getRealTokens(";",cols); 513 for (int i=0;i<colsNames.size();i++) { 514 TableColumn col = new TableColumn(this.table, SWT.LEFT); 515 col.setText((String )colsNames.elementAt(i)); 516 col.setWidth(60); 517 this.tableColumns.add(col); 518 } 519 table.setHeaderVisible(true); 520 table.setLinesVisible(true); 521 table.addSelectionListener(this); 523 this.cellEditors = new Vector (); 525 this.cellText = new Vector (); 526 } 527 528 531 private void initLabel() { 532 cat.debug("-> initLabel"); 533 Label label = new Label(this.composite, SWT.RIGHT); 534 label.setBackground(composite.getDisplay().getSystemColor( 535 SWT.COLOR_WHITE)); 536 label.setText(this.labelValue + " : "); 537 } 538 539 547 private void initField(Hashtable params, Composite parent) { 548 cat.debug("-> initField"); 549 ((GridLayout) this.composite.getLayout()).numColumns = 2; 551 this.initLabel(); 553 this.textField = new Text(this.composite, SWT.SINGLE | SWT.BORDER); 555 this.textField.setBackground(parent.getDisplay().getSystemColor( 557 SWT.COLOR_WHITE)); 558 559 GridData gridData = new GridData(); 561 gridData.horizontalAlignment = GridData.FILL; 562 gridData.grabExcessHorizontalSpace = true; 563 this.textField.setLayoutData(gridData); 564 if (params != null) { 566 if (params.containsKey("text")) { 567 this.textField.setText((String ) params.get("text")); 568 } 569 } 570 this.textField.addModifyListener((ModifyListener) listener); 572 } 573 574 582 private void initNField(Hashtable params, Composite parent) { 583 cat.debug("-> initNField"); 584 this.nfieldGroup = new Group(parent, SWT.BORDER); 586 this.nfieldGroup.setBackground(parent.getDisplay().getSystemColor( 587 SWT.COLOR_WHITE)); 588 this.nfieldGroup.setText(this.labelValue + " : "); 589 this.nfieldGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); 591 GridLayout gd = new GridLayout(); 593 gd.numColumns = 2; 594 this.nfieldGroup.setLayout(gd); 595 this.nfieldAdd = new Button(this.nfieldGroup, SWT.FLAT); 597 this.nfieldAdd.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 599 this.nfieldAdd.setText("Add field"); 600 this.nfieldAdd.addSelectionListener((SelectionListener) this.listener); 601 this.nfieldRemove = new Button(this.nfieldGroup, SWT.FLAT); 602 this.nfieldRemove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 603 this.nfieldRemove.setText("Remove field"); 604 this.nfieldRemove 605 .addSelectionListener((SelectionListener) this.listener); 606 this.nfield = new Vector (); 608 this.nfieldLabel = new Vector (); 609 } 610 611 619 private void initRadioGroup(Hashtable params, Composite parent) { 620 cat.debug("-> initRadioGroup"); 621 this.radioGroup = new Group(parent, SWT.BORDER); 622 this.radioGroup.setBackground(parent.getDisplay().getSystemColor( 624 SWT.COLOR_WHITE)); 625 626 this.radioGroup.setText(this.labelValue); 627 GridData gridData = new GridData(); 629 gridData.horizontalAlignment = GridData.FILL; 630 gridData.grabExcessHorizontalSpace = true; 631 this.radioGroup.setLayoutData(gridData); 632 FillLayout fill = new FillLayout(); 633 fill.type = SWT.VERTICAL; 634 this.radioGroup.setLayout(fill); 635 636 this.buttons = new Vector (); 637 Vector choices = null; 639 if (params.containsKey("choices")) { 640 choices = (Vector ) params.get("choices"); 641 } 642 Vector selected = null; 643 if (params.containsKey("selected")) { 644 selected = (Vector ) params.get("selected"); 645 } 646 if (choices != null) { 648 for (int i = 0; i < choices.size(); i++) { 649 Button temp = new Button(this.radioGroup, SWT.RADIO); 650 temp.setBackground(parent.getDisplay().getSystemColor( 651 SWT.COLOR_WHITE)); 652 String buttonName = (String ) choices.elementAt(i); 653 temp.setText(buttonName); 654 temp.addSelectionListener((SelectionListener) listener); 656 this.buttons.add(temp); 657 if (selected.contains(buttonName)) 659 temp.setSelection(true); 660 } 661 } 662 } 663 664 672 private void initCheckBox(Hashtable params, Composite parent) { 673 cat.debug("-> initCheckBox"); 674 this.checkBox = new Group(parent, SWT.BORDER); 675 this.checkBox.setBackground(parent.getDisplay().getSystemColor( 677 SWT.COLOR_WHITE)); 678 679 this.checkBox.setText(this.labelValue); 680 GridData gridData = new GridData(); 682 gridData.horizontalAlignment = GridData.FILL; 683 gridData.grabExcessHorizontalSpace = true; 684 this.checkBox.setLayoutData(gridData); 685 FillLayout fill = new FillLayout(); 686 fill.type = SWT.VERTICAL; 687 this.checkBox.setLayout(fill); 688 689 this.buttons = new Vector (); 690 691 Vector choices = null; 693 if (params.containsKey("choices")) { 694 choices = (Vector ) params.get("choices"); 695 } 696 Vector selected = null; 697 if (params.containsKey("selected")) { 698 selected = (Vector ) params.get("selected"); 699 } 700 if (choices != null) { 702 for (int i = 0; i < choices.size(); i++) { 703 Button temp = new Button(this.checkBox, SWT.CHECK); 704 temp.setBackground(parent.getDisplay().getSystemColor( 705 SWT.COLOR_WHITE)); 706 String buttonName = (String ) choices.elementAt(i); 707 temp.setText(buttonName); 708 temp.addSelectionListener((SelectionListener) listener); 709 this.buttons.add(temp); 710 if (selected.contains(buttonName)) 712 temp.setSelection(true); 713 } 714 } 715 } 716 717 725 private void initCombo(Hashtable params, Composite parent) { 726 cat.debug("-> initCombo"); 727 ((GridLayout) this.composite.getLayout()).numColumns = 2; 729 this.initLabel(); 731 this.combo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY); 732 this.combo.setBackground(parent.getDisplay().getSystemColor( 734 SWT.COLOR_WHITE)); 735 736 GridData gridData = new GridData(); 738 gridData.horizontalAlignment = GridData.FILL; 739 gridData.grabExcessHorizontalSpace = true; 740 this.combo.setLayoutData(gridData); 741 Vector choices = null; 743 if (params == null) 745 return; 746 if (params.containsKey("choices")) { 747 choices = (Vector ) params.get("choices"); 748 } 749 if (choices != null) { 750 for (int i = 0; i < choices.size(); i++) { 752 this.combo.add((String ) choices.elementAt(i)); 753 } 754 } 755 this.combo.addSelectionListener((SelectionListener) listener); 756 } 757 758 766 private void initGroup(Hashtable params, Composite parent) { 767 cat.debug("-> initGroup"); 768 this.group = new Group(parent, SWT.BORDER); 769 this.group.setBackground(parent.getDisplay().getSystemColor( 771 SWT.COLOR_WHITE)); 772 this.group.setText(this.labelValue); 773 GridData gridData = new GridData(); 775 gridData.horizontalAlignment = GridData.FILL; 776 gridData.grabExcessHorizontalSpace = true; 777 this.group.setLayoutData(gridData); 778 GridLayout groupLayout = new GridLayout(); 779 groupLayout.numColumns = 1; 780 this.group.setLayout(groupLayout); 781 } 782 783 788 private String getValueTable() { 789 cat.debug("-> getValueTable"); 790 String result = ""; 791 TableItem[] items = this.table.getItems(); 792 for (int i = 0; i < items.length; i++) { 793 for (int j = 0; j < this.tableColumns.size(); j++) { 794 String colName = ((TableColumn) this.tableColumns.elementAt(j)) 795 .getText(); 796 String colNameModified = addEscapeCharacter("\\", colName); 797 colNameModified = addEscapeCharacter(";",colNameModified); 798 colNameModified = addEscapeCharacter("|",colNameModified); 799 colNameModified = addEscapeCharacter("=",colNameModified); 800 String colValue = items[i].getText(j); 801 String colValueModified = addEscapeCharacter("\\",colValue); 802 colValueModified = addEscapeCharacter(";",colValueModified); 803 colValueModified = addEscapeCharacter("|",colValueModified); 804 colValueModified = addEscapeCharacter("=",colValueModified); 805 result = result.concat(colNameModified + "=" + colValueModified 806 + "|"); 807 } 808 result = result.concat(";"); 809 } 810 return result; 811 } 812 813 816 private String getValueField() { 817 cat.debug("-> getValueField"); 818 String value = this.textField.getText(); 819 if (!value.equals("")) 820 return value; 821 return null; 822 } 823 824 829 private String getValueNField() { 830 cat.debug("-> getValueNField"); 831 String result = new String (""); 832 for (int i = 0; i < this.nfield.size(); i++) { 834 Text text = (Text) this.nfield.elementAt(i); 836 String value = addEscapeCharacter("\\",text.getText()); 838 value = addEscapeCharacter(";",value); 839 result = result.concat(value + ";"); 841 } 842 return result; 844 } 845 846 849 private String getValueRadioGroup() { 850 cat.debug("-> getValueRadioGroup"); 851 String result = ""; 852 for (int i = 0; i < this.buttons.size(); i++) { 853 Button temp = (Button) this.buttons.elementAt(i); 854 if (temp.getSelection()) { 855 String value = temp.getText(); 856 value = addEscapeCharacter("\\",value); 857 result = result.concat(addEscapeCharacter(";",value)); 858 break; 859 } 860 } 861 if (result.equals("")) 862 return null; 863 else 864 return result; 865 } 866 867 870 private String getValueCheckBox() { 871 cat.debug("-> getValueCheckBox"); 872 String result = ""; 873 for (int i = 0; i < this.buttons.size(); i++) { 874 Button temp = (Button) this.buttons.elementAt(i); 875 if (temp.getSelection()) { 876 String value = temp.getText(); 877 value = addEscapeCharacter("\\",value); 878 result = result.concat(addEscapeCharacter(";",value)+";"); 879 } 880 } 881 if (result.equals("")) 882 return null; 883 else 884 return result; 885 } 886 887 890 private String getValueCombo() { 891 cat.debug("-> getValueCombo"); 892 String result = this.combo.getText(); 893 return result; 894 } 895 896 899 private String getValueGroup() { 900 cat.debug("-> getValueGroup"); 901 return null; 903 } 904 905 911 private void setValueTable(String value) { 912 Vector entries = null; 913 try { 914 entries = getTableEntries(value); 915 } catch (Exception e) { 916 e.printStackTrace(); 917 return; 918 } 919 for (int i = 0; i < entries.size(); i++) { 920 Vector values = (Vector ) entries.elementAt(i); 921 String [] entryValues = (String []) values.toArray(new String [values 922 .size()]); 923 TableItem item = new TableItem(this.table, SWT.NONE); 924 item.setText(entryValues); 925 } 926 } 927 928 934 private void setValueField(String value) { 935 cat.debug("-> setValueField"); 936 this.textField.setText(value); 937 } 938 939 945 private void setValueNField(String value) { 946 cat.debug("-> setValueNField"); 947 for (int i = 0; i < nfield.size(); i++) { 949 ((Text) nfield.elementAt(i)).dispose(); 950 ((Label) nfieldLabel.elementAt(i)).dispose(); 951 } 952 Vector realTokens = getRealTokens(";",value); 953 for (int i=0;i<realTokens.size();i++) { 955 String v = (String )realTokens.elementAt(i); 957 v = removeEscapeCharacterForBackslash(v); 958 Label label = new Label(this.nfieldGroup, SWT.NONE); 960 label.setBackground(parent.getDisplay().getSystemColor( 961 SWT.COLOR_WHITE)); 962 label.setText("field " + i + " : "); 963 this.nfieldLabel.add(label); 964 Text text = new Text(this.nfieldGroup, SWT.BORDER); 965 GridData data = new GridData(GridData.FILL_HORIZONTAL); 967 text.setLayoutData(data); 968 text.setText(v); 970 text.addModifyListener((ModifyListener) this.listener); 972 this.nfield.add(text); 974 } 975 this.nfieldGroup.layout(); 977 } 978 979 985 private void setValueRadioGroup(String value) { 986 cat.debug("-> setValueRadioGroup"); 987 Vector realTokens = getRealTokens(";",value); 989 for (int i=0;i<realTokens.size();i++) { 990 String v = (String )realTokens.elementAt(i); 992 v = removeEscapeCharacterForBackslash(v); 993 for (int j = 0; j < this.buttons.size(); j++) { 995 Button temp = (Button) this.buttons.elementAt(j); 996 temp.setSelection(temp.getText().equals(v)); 997 } 998 } 999 } 1000 1001 1007 private void setValueCheckBox(String value) { 1008 cat.debug("-> setValueCheckBox"); 1009 if (value.equals("")) { 1010 return; 1011 } 1012 for (int i = 0; i < this.buttons.size(); i++) { 1014 Button temp = (Button) this.buttons.elementAt(i); 1015 temp.setSelection(false); 1016 } 1017 1018 Vector realTokens = getRealTokens(";",value); 1020 for (int i=0;i<realTokens.size();i++) { 1021 String v = (String )realTokens.elementAt(i); 1023 v = removeEscapeCharacterForBackslash(v); 1024 for (int j = 0; j < this.buttons.size(); j++) { 1026 Button temp = (Button) this.buttons.elementAt(j); 1027 if (temp.getText().equals(v)) 1028 temp.setSelection(true); 1029 } 1030 } 1031 } 1032 1033 1039 private void setValueCombo(String value) { 1040 cat.debug("-> setValueCombo"); 1041 1042 if (value.equals("")) { 1044 this.combo.setText(value); 1045 return; 1046 } 1047 String [] values = this.combo.getItems(); 1049 boolean flag = false; 1050 for (int i = 0; i < values.length; i++) { 1051 if (values[i].equals(value)) { 1052 flag = true; 1053 break; 1054 } 1055 } 1056 if (flag) 1057 this.combo.setText(value); 1058 } 1059 1060 1065 private void setValueGroup(String value) { 1066 cat.debug("-> setValueGroup"); 1067 } 1069 1070 1073 public Composite getComposite() { 1074 cat.debug("-> getComposite"); 1075 switch (this.style) { 1076 case WidgetDescription.GROUP: 1077 return this.group; 1078 default: 1079 return this.composite; 1080 } 1081 } 1082 1083 1086 public void dispose() { 1087 cat.debug("-> dispose"); 1088 switch (this.style) { 1089 case WidgetDescription.GROUP: 1090 this.group.dispose(); 1091 break; 1092 case WidgetDescription.TEXT_FIELD: 1093 this.textField.dispose(); 1094 break; 1095 case WidgetDescription.RADIO_GROUP: 1096 this.radioGroup.dispose(); 1097 break; 1098 case WidgetDescription.CHECK_BOX: 1099 this.checkBox.dispose(); 1100 break; 1101 case WidgetDescription.COMBO: 1102 this.combo.dispose(); 1103 break; 1104 } 1105 this.composite.dispose(); 1106 } 1107 1108 1113 public String getName() { 1114 cat.debug("-> getName"); 1115 return name; 1116 } 1117 1118 1121 public int getStyle() { 1122 return style; 1123 } 1124 1125 1129 1139 private Vector getTableEntries(String value) { 1140 Vector result = new Vector (); 1142 Vector tempEntries = getRealTokens(";",value); 1143 Vector allValues = new Vector (); 1145 for (int i = 0; i < tempEntries.size(); i++) { 1146 String tempEntry = (String ) tempEntries.elementAt(i); 1147 Vector values = getRealTokens("|",tempEntry); 1148 allValues.add(values); 1149 } 1150 for (int i = 0; i < allValues.size(); i++) { 1152 Vector resultValues = new Vector (); 1153 Vector tempValues = (Vector ) allValues.elementAt(i); 1154 for (int j = 0; j < tempValues.size(); j++) { 1155 String v = (String ) tempValues.elementAt(j); 1156 Vector temp = getRealTokens("=",v); 1157 if (temp.size() != 2) { 1158 cat.warn("The vector containing {colName,colValue}, should have only 2 elements, hier we found "+temp.size()); 1159 } 1160 String col = (String )temp.elementAt(0); 1161 String res = (String )temp.elementAt(1); 1162 res = removeEscapeCharacterForBackslash(res); 1164 resultValues.add(res); 1165 } 1166 result.add(resultValues); 1167 } 1168 1169 return result; 1171 } 1172 1173 1178 private int getNumberOfEscapeCharacter(String value) { 1179 int result = 0; 1180 if (value.length() > 0) { 1181 int last = value.lastIndexOf("\\"); 1182 if (last == value.length()-1) { 1183 result = 1 + getNumberOfEscapeCharacter(value.substring(0,last)); 1184 } 1185 } 1186 return result; 1187 } 1188 1189 1195 private String addEscapeCharacter(String separator, String value) { 1196 String result = ""; 1197 StringTokenizer st = new StringTokenizer (value,separator,true); 1198 while (st.hasMoreTokens()) { 1199 String token = st.nextToken(); 1200 if (token.equals(separator)) { 1201 result = result.concat("\\"+token); 1202 } 1203 else { 1204 result = result.concat(token) ; 1205 } 1206 } 1207 return result; 1208 } 1209 1210 1217 private Vector getRealTokens(String separator, String value) { 1218 Vector result = new Vector (); 1219 StringTokenizer st = new StringTokenizer (value,separator,true); 1220 String currentRealToken = ""; 1221 while (st.hasMoreTokens()) { 1222 String token = st.nextToken(); 1223 if (token.equals(separator)) { 1225 int nb = getNumberOfEscapeCharacter(currentRealToken); 1226 if (nb%2 == 0) { 1228 result.add(currentRealToken); 1229 currentRealToken = ""; 1230 } 1231 else { 1233 currentRealToken = currentRealToken.substring(0,currentRealToken.length()-1); 1235 currentRealToken = currentRealToken.concat(separator); 1237 if (!st.hasMoreTokens()) { 1239 result.add(currentRealToken); 1240 } 1241 } 1242 } 1243 else { 1245 currentRealToken = currentRealToken.concat(token); 1246 if (!st.hasMoreTokens()) { 1248 result.add(currentRealToken); 1249 } 1250 } 1251 } 1252 return result; 1253 } 1254 1255 1260 private String removeEscapeCharacterForBackslash(String value) { 1261 String result = ""; 1262 StringTokenizer st = new StringTokenizer (value, "\\", true) ; 1263 while (st.hasMoreTokens()) { 1264 String token = st.nextToken(); 1265 if (token.equals("\\")) { 1266 if (st.hasMoreTokens()) { 1268 st.nextToken(); 1269 } 1270 result = result.concat("\\"); 1271 } 1272 else { 1273 result = result.concat(token); 1274 } 1275 } 1276 return result; 1277 } 1278 1279 1280 1286 public boolean modifyText(Object source) { 1287 boolean isText = false; 1288 for (int i = 0; i < cellText.size(); i++) { 1289 if (cellText.elementAt(i) == source) { 1290 isText = true; 1291 } 1292 } 1293 if (isText) { 1294 String [] colValues = new String [this.tableColumns.size()]; 1296 for (int i = 0; i < cellText.size(); i++) { 1297 colValues[i] = ((Text) cellText.elementAt(i)).getText(); 1298 } 1299 TableItem item = this.table.getItem(cellYAxis); 1300 item.setText(colValues); 1301 } 1302 return isText; 1303 } 1304 1305 1308 public void widgetDefaultSelected(SelectionEvent arg0) { 1309 } 1311 1312 1315 public void widgetSelected(SelectionEvent arg0) { 1316 for (int i = 0; i < cellEditors.size(); i++) { 1318 Control oldEditor = ((TableEditor) cellEditors.elementAt(i)) 1319 .getEditor(); 1320 oldEditor.dispose(); 1321 } 1322 cellEditors.removeAllElements(); 1324 cellText.removeAllElements(); 1325 1326 int index = table.getSelectionIndex(); 1328 if (index == -1) 1329 return; 1330 TableItem item = table.getItem(index); 1331 cellYAxis = index; 1332 for (int i = 0; i < tableColumns.size(); i++) { 1333 Text text = new Text(table, SWT.NONE); 1335 String toSet = item.getText(i); 1336 if (toSet != null) { 1337 text.setText(toSet); 1338 } else { 1339 text.setText(""); 1340 } 1341 text.addModifyListener((ModifyListener) this.listener); 1342 1343 TableEditor editor = new TableEditor(table); 1344 editor.horizontalAlignment = SWT.LEFT; 1347 editor.grabHorizontal = true; 1348 editor.minimumWidth = 50; 1349 1350 editor.setEditor(text, item, i); 1352 cellEditors.add(editor); 1353 cellText.add(text); 1354 } 1355 } 1356 1357 1366 public static ParameterWidget createParameterWidget(WidgetDescription wd, 1367 Composite parent, EventListener listener) { 1368 cat.debug("-> createParameterWidget"); 1369 return new ParameterWidget(wd.getType(), wd.getText(), wd.getLabel(), 1370 wd.getParams(), parent, listener); 1371 } 1372} | Popular Tags |