Exemplo n.º 1
0
 public static Combo createEncodingCombo(Composite parent, String curCharset) {
   if (curCharset == null) {
     curCharset = GeneralUtils.getDefaultFileEncoding();
   }
   Combo encodingCombo = new Combo(parent, SWT.DROP_DOWN);
   encodingCombo.setVisibleItemCount(30);
   SortedMap<String, Charset> charsetMap = Charset.availableCharsets();
   int index = 0;
   int defIndex = -1;
   for (String csName : charsetMap.keySet()) {
     Charset charset = charsetMap.get(csName);
     encodingCombo.add(charset.displayName());
     if (charset.displayName().equalsIgnoreCase(curCharset)) {
       defIndex = index;
     }
     if (defIndex < 0) {
       for (String alias : charset.aliases()) {
         if (alias.equalsIgnoreCase(curCharset)) {
           defIndex = index;
         }
       }
     }
     index++;
   }
   if (defIndex >= 0) {
     encodingCombo.select(defIndex);
   } else {
     log.warn("Charset '" + curCharset + "' is not recognized"); // $NON-NLS-1$ //$NON-NLS-2$
   }
   return encodingCombo;
 }
Exemplo n.º 2
0
 @Nullable
 public static String getComboSelection(Combo combo) {
   int selectionIndex = combo.getSelectionIndex();
   if (selectionIndex < 0) {
     return null;
   }
   return combo.getItem(selectionIndex);
 }
Exemplo n.º 3
0
  public static Combo createLabelCombo(Composite parent, String label, int style) {
    Label labelControl = createControlLabel(parent, label);
    // labelControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Combo combo = new Combo(parent, style);
    combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    return combo;
  }
Exemplo n.º 4
0
 public static boolean setComboSelection(Combo combo, String value) {
   if (value == null) {
     return false;
   }
   int count = combo.getItemCount();
   for (int i = 0; i < count; i++) {
     if (value.equals(combo.getItem(i))) {
       combo.select(i);
       return true;
     }
   }
   return false;
 }