Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.xtext.ui.editor.tasks.dialogfields;
 
 import  org.eclipse.swt.events.ModifyEvent;
 import  org.eclipse.swt.events.ModifyListener;
 import  org.eclipse.swt.events.SelectionEvent;
 import  org.eclipse.swt.events.SelectionListener;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.widgets.Combo;
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
 import  org.eclipse.swt.widgets.Label;

Dialog field containing a label and a combo control.
 
 public class ComboDialogField extends DialogField {
 
 	private String fText;
 	private int fSelectionIndex;
 	private String[] fItems;
 	private Combo fComboControl;
 	private ModifyListener fModifyListener;
 	private int fFlags;
 
 	public ComboDialogField(int flags) {
 		super();
 		 = ""//$NON-NLS-1$
 		 = new String[0];
 		 = flags;
 	}
 
 	// ------- layout helpers
 
 	/*
 	 * @see DialogField#doFillIntoGrid
 	 */
 	public Control[] doFillIntoGrid(Composite parentint nColumns) {
 		assertEnoughColumns(nColumns);
 
 		Label label = getLabelControl(parent);
 		label.setLayoutData(gridDataForLabel(1));
 		Combo combo = getComboControl(parent);
 		combo.setLayoutData(gridDataForCombo(nColumns - 1));
 
 		return new Control[] { labelcombo };
 	}
 
 	/*
 	 * @see DialogField#getNumberOfControls
 	 */
 	public int getNumberOfControls() {
 		return 2;
 	}
 
 	protected static GridData gridDataForCombo(int span) {
 		GridData gd = new GridData();
 		gd.horizontalAlignment = GridData.FILL;
 		gd.grabExcessHorizontalSpace = false;
 		gd.horizontalSpan = span;
 		return gd;
 	}
 
 	// ------- focus methods
 
 	/*
 	 * @see DialogField#setFocus
 	 */
 	public boolean setFocus() {
 			.setFocus();
 		}
 		return true;
 	}
 
 	// ------- ui creation
 
Creates or returns the created combo control.

Parameters:
parent The parent composite or null when the widget has already been created.
 
 	public Combo getComboControl(Composite parent) {
 		if ( == null) {
			 = new ModifyListener() {
				public void modifyText(ModifyEvent e) {
				}
			};
			SelectionListener selectionListener = new SelectionListener() {
				public void widgetSelected(SelectionEvent e) {
				}
				public void widgetDefaultSelected(SelectionEvent e) {
				}
			};
			 = new Combo(parent);
			// moved up due to 1GEUNW2
			if ( != -1) {
else {
			}
			.setFont(parent.getFont());
			.addModifyListener();
			.addSelectionListener(selectionListener);
			.setEnabled(isEnabled());
		}
	}
	private void doModifyText(ModifyEvent e) {
			 = .getText();
			 = .getSelectionIndex();
		}
	}
	private void doSelectionChanged(SelectionEvent e) {
			 = .getItems();
			 = .getText();
			 = .getSelectionIndex();
		}
	}
	// ------ enable / disable management
	/*
	 * @see DialogField#updateEnableState
	 */
	protected void updateEnableState() {
			.setEnabled(isEnabled());
		}
	}
	// ------ text access
Gets the combo items.
	public String[] getItems() {
		return ;
	}

Sets the combo items. Triggers a dialog-changed event.
	public void setItems(String[] items) {
		 = items;
			.setItems(items);
		}
	}

Gets the text.
	public String getText() {
		return ;
	}

Sets the text. Triggers a dialog-changed event.
	public void setText(String text) {
		 = text;
			.setText(text);
else {
		}
	}

Selects an item.
	public boolean selectItem(int index) {
		boolean success = false;
			.select(index);
			success = .getSelectionIndex() == index;
else {
			if (index >= 0 && index < .) {
				 = [index];
				 = index;
				success = true;
			}
		}
		if (success) {
		}
		return success;
	}

Selects an item.
	public boolean selectItem(String name) {
		for (int i = 0; i < .i++) {
			if ([i].equals(name)) {
				return selectItem(i);
			}
		}
		return false;
	}
	public int getSelectionIndex() {
	}

Sets the text without triggering a dialog-changed event.
	public void setTextWithoutUpdate(String text) {
		 = text;
			.removeModifyListener();
			.setText(text);
			.addModifyListener();
		}
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField#refresh()
	 */
	public void refresh() {
		super.refresh();
	}
New to GrepCode? Check out our FAQ X