Java Code Examples for org.eclipse.swt.widgets.Combo#getItems()

The following examples show how to use org.eclipse.swt.widgets.Combo#getItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuiToolbarWidgets.java    From hop with Apache License 2.0 6 votes vote down vote up
private int calculateComboWidth( Combo combo ) {
  Image image = new Image( HopGui.getInstance().getDisplay(), 10, 10 );
  GC gc = new GC( image );

  int maxWidth = combo.getSize().x;
  for ( String item : combo.getItems() ) {
    int width = gc.textExtent( item ).x;
    if ( width > maxWidth ) {
      maxWidth = width;
    }
  }

  gc.dispose();
  image.dispose();

  return maxWidth;
}
 
Example 2
Source File: NewProjectWizardProjInfoPage.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取项目属性字段集合
 * @return key 为属性名称,value 中第一个值为选中的属性值,第二个值为该属性对应的所有属性值集合
 */
public LinkedHashMap<String, Object[]> getAttributeMap() {
	LinkedHashMap<String, Object[]> mapAttr = new LinkedHashMap<String, Object[]>();
	if (lstCombo != null) {
		for (Combo cmb : lstCombo) {
			if (!cmb.isDisposed()) {
				ArrayList<String> lstAttrValue = new ArrayList<String>();
				for (String attrVal : cmb.getItems()) {
					lstAttrValue.add(TextUtil.stringToXML(attrVal));
				}
				mapAttr.put(TextUtil.stringToXML((String) cmb.getData()),
						new Object[] { TextUtil.stringToXML(cmb.getText()), lstAttrValue });
			}
		}
	}
	return mapAttr;
}
 
Example 3
Source File: NewProjectWizardProjInfoPage.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取项目属性字段集合
 * @return key 为属性名称,value 中第一个值为选中的属性值,第二个值为该属性对应的所有属性值集合
 */
public LinkedHashMap<String, Object[]> getAttributeMap() {
	LinkedHashMap<String, Object[]> mapAttr = new LinkedHashMap<String, Object[]>();
	if (lstCombo != null) {
		for (Combo cmb : lstCombo) {
			if (!cmb.isDisposed()) {
				ArrayList<String> lstAttrValue = new ArrayList<String>();
				for (String attrVal : cmb.getItems()) {
					lstAttrValue.add(TextUtil.stringToXML(attrVal));
				}
				mapAttr.put(TextUtil.stringToXML((String) cmb.getData()),
						new Object[] { TextUtil.stringToXML(cmb.getText()), lstAttrValue });
			}
		}
	}
	return mapAttr;
}
 
Example 4
Source File: AdvancedNewProjectPage.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void select(Combo combo, Enum<?> enu) {
	String[] items = combo.getItems();
	for (int i = 0; i < items.length; i++) {
		if (enu.toString().equals(items[i])) {
			combo.select(i);
			break;
		}
	}
}
 
Example 5
Source File: ImportTraceWizardPage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Set the source path that was selected by the user by various input
 * methods (Browse button, typing, etc).
 *
 * Clients can also call this to set the path programmatically (hard-coded
 * initial path) and this can also be overridden to be notified when the
 * source path changes.
 *
 * @param path
 *            the source path
 */
protected void setSourcePath(String path) {
    Combo sourceField = getSourceField();
    if (sourceField == null) {
        return;
    }

    if (path.length() > 0) {
        String[] currentItems = sourceField.getItems();
        int selectionIndex = -1;
        for (int i = 0; i < currentItems.length; i++) {
            if (currentItems[i].equals(path)) {
                selectionIndex = i;
            }
        }
        if (selectionIndex < 0) {
            int oldLength = currentItems.length;
            String[] newItems = new String[oldLength + 1];
            System.arraycopy(currentItems, 0, newItems, 0, oldLength);
            newItems[oldLength] = path;
            sourceField.setItems(newItems);
            selectionIndex = oldLength;
        }
        sourceField.select(selectionIndex);
    }
    resetSelection();
}
 
Example 6
Source File: ImportTraceWizardPage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void saveComboValues(Combo combo, IDialogSettings settings, String key) {
    // update names history
    String[] directoryNames = settings.getArray(key);
    if (directoryNames == null) {
        directoryNames = new String[0];
    }

    String items[] = combo.getItems();
    for (int i = 0; i < items.length; i++) {
        directoryNames = addToHistory(directoryNames, items[i]);
    }
    settings.put(key, directoryNames);
}
 
Example 7
Source File: ProjectSettingBaseInfoPage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean performOk() {
	if (lstText != null) {
		LinkedHashMap<String, String> mapField = new LinkedHashMap<String, String>();
		for (Text txt : lstText) {
			if (!txt.isDisposed()) {
				mapField.put(TextUtil.stringToXML((String) txt.getData()), TextUtil.stringToXML(txt.getText()).trim());
			}
		}
		projCfgBean.setMapField(mapField);
	}

	if (lstCombo != null) {
		LinkedHashMap<String, Object[]> mapAttr = new LinkedHashMap<String, Object[]>();
		for (Combo cmb : lstCombo) {
			if (!cmb.isDisposed()) {
				ArrayList<String> lstAttrValue = new ArrayList<String>();
				for (String attrVal : cmb.getItems()) {
					lstAttrValue.add(TextUtil.stringToXML(attrVal));
				}
				mapAttr.put(TextUtil.stringToXML((String) cmb.getData()),
						new Object[] { TextUtil.stringToXML(cmb.getText()), lstAttrValue });
			}
		}
		projCfgBean.setMapAttr(mapAttr);
	}
	return super.performOk();
}
 
Example 8
Source File: ProjectSettingBaseInfoPage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean performOk() {
	if (lstText != null) {
		LinkedHashMap<String, String> mapField = new LinkedHashMap<String, String>();
		for (Text txt : lstText) {
			if (!txt.isDisposed()) {
				mapField.put(TextUtil.stringToXML((String) txt.getData()), TextUtil.stringToXML(txt.getText()).trim());
			}
		}
		projCfgBean.setMapField(mapField);
	}

	if (lstCombo != null) {
		LinkedHashMap<String, Object[]> mapAttr = new LinkedHashMap<String, Object[]>();
		for (Combo cmb : lstCombo) {
			if (!cmb.isDisposed()) {
				ArrayList<String> lstAttrValue = new ArrayList<String>();
				for (String attrVal : cmb.getItems()) {
					lstAttrValue.add(TextUtil.stringToXML(attrVal));
				}
				mapAttr.put(TextUtil.stringToXML((String) cmb.getData()),
						new Object[] { TextUtil.stringToXML(cmb.getText()), lstAttrValue });
			}
		}
		projCfgBean.setMapAttr(mapAttr);
	}
	return super.performOk();
}
 
Example 9
Source File: HierarchyWizardPageRedaction.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the item, or adds it to the combo.
 *
 * @param combo
 * @param value
 * @return
 */
private int indexOf(Combo combo, char value){
    for (int i=0; i < combo.getItems().length; i++) {
        if (combo.getItem(i).toCharArray()[1]==value) {
            return i;
        }
    }
    combo.add("("+String.valueOf(value)+")"); //$NON-NLS-1$ //$NON-NLS-2$
    return combo.getItemCount()-1;
}