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.SWT;
 import  org.eclipse.swt.events.ModifyEvent;
 import  org.eclipse.swt.events.ModifyListener;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
 import  org.eclipse.swt.widgets.Label;
 import  org.eclipse.swt.widgets.Text;

Dialog field containing a label and a text control.
 
 public class StringDialogField extends DialogField {
 
 	private String fText;
 	private Text fTextControl;
 	private ModifyListener fModifyListener;
 
 	public StringDialogField() {
 		super();
 		 = ""//$NON-NLS-1$
 	}
 
 	// ------- layout helpers 
 
 	/*
 	 * @see DialogField#doFillIntoGrid
 	 */
 	public Control[] doFillIntoGrid(Composite parentint nColumns) {
 		assertEnoughColumns(nColumns);
 
 		Label label = getLabelControl(parent);
 		label.setLayoutData(gridDataForLabel(1));
 		Text text = getTextControl(parent);
 		text.setLayoutData(gridDataForText(nColumns - 1));
 
 		return new Control[] { labeltext };
 	}
 
 	/*
 	 * @see DialogField#getNumberOfControls
 	 */
 	public int getNumberOfControls() {
 		return 2;
 	}
 
 	protected static GridData gridDataForText(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();
 			.setSelection(0, .getText().length());
 		}
 		return true;
 	}
 
 	// ------- ui creation
 
Creates or returns the created text control.

Parameters:
parent The parent composite or null when the widget has already been created.
 
 	public Text getTextControl(Composite parent) {
 		if ( == null) {
 			 = new ModifyListener() {
 				public void modifyText(ModifyEvent e) {
 				}
			};
			 = new Text(parent, SWT.SINGLE | SWT.BORDER);
			// moved up due to 1GEUNW2
			.setFont(parent.getFont());
			.addModifyListener();
			.setEnabled(isEnabled());
		}
		return ;
	}
	private void doModifyText(ModifyEvent e) {
			 = .getText();
		}
	}
	// ------ enable / disable management
	/*
	 * @see DialogField#updateEnableState
	 */
	protected void updateEnableState() {
			.setEnabled(isEnabled());
		}
	}
	// ------ text access
Gets the text. Can not be null
	public String getText() {
		return ;
	}

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

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