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.SelectionEvent;
 import  org.eclipse.swt.events.SelectionListener;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.widgets.Button;
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
Dialog Field containing a single button such as a radio or checkbox button.
 
 public class SelectionButtonDialogField extends DialogField {
 
 	private Button fButton;
 	private boolean fIsSelected;
 	private int fButtonStyle;

Creates a selection button. Allowed button styles: SWT.RADIO, SWT.CHECK, SWT.TOGGLE, SWT.PUSH
 
 	public SelectionButtonDialogField(int buttonStyle) {
 		super();
 		 = false;
 		 = buttonStyle;
 	}

Attaches a field to the selection state of the selection button. The attached field will be disabled if the selection button is not selected.
 
 	public void attachDialogField(DialogField dialogField) {
 		attachDialogFields(new DialogField[] { dialogField });
 	}

Attaches fields to the selection state of the selection button. The attached fields will be disabled if the selection button is not selected.
 
 	public void attachDialogFields(DialogField[] dialogFields) {
 		 = dialogFields;
 		for (int i = 0; i < dialogFields.lengthi++) {
 			dialogFields[i].setEnabled();
 		}
 	}

Returns true is teh gived field is attached to the selection button.
 
 	public boolean isAttached(DialogField editor) {
 		if ( != null) {
 			for (int i = 0; i < .i++) {
 				if ([i] == editor) {
 					return true;
 				}
 			}
 		}
 		return false;
 	}
 
 	// ------- layout helpers
 
 	/*
 	 * @see DialogField#doFillIntoGrid
 	 */
 	public Control[] doFillIntoGrid(Composite parentint nColumns) {
 		assertEnoughColumns(nColumns);
 
 		Button button = getSelectionButton(parent);
 		GridData gd = new GridData();
 		gd.horizontalSpan = nColumns;
 		gd.horizontalAlignment = GridData.FILL;
 		if ( == SWT.PUSH) {
 			gd.widthHint = SWTUtil.getButtonWidthHint(button);
 		}
 
 		button.setLayoutData(gd);
 
 		return new Control[] { button };
 	}
 
 	/*
	 * @see DialogField#getNumberOfControls
	 */
	public int getNumberOfControls() {
		return 1;
	}
	// ------- ui creation
Returns the selection button widget. When called the first time, the widget will be created.

Parameters:
group The parent composite when called the first time, or null after.
	public Button getSelectionButton(Composite group) {
		if ( == null) {
			 = new Button(group);
			.setFont(group.getFont());
			.setEnabled(isEnabled());
			.setSelection();
			.addSelectionListener(new SelectionListener() {
				public void widgetDefaultSelected(SelectionEvent e) {
				}
				public void widgetSelected(SelectionEvent e) {
				}
			});
		}
		return ;
	}
	private void doWidgetSelected(SelectionEvent e) {
			changeValue(.getSelection());
		}
	}
	private void changeValue(boolean newState) {
		if ( != newState) {
			 = newState;
			if ( != null) {
				boolean focusSet = false;
				for (int i = 0; i < .i++) {
					if ( && !focusSet) {
					}
				}
			}
else if ( == SWT.PUSH) {
		}
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField#setLabelText
	 * (java.lang.String)
	 */
	public void setLabelText(String labeltext) {
		 = labeltext;
			.setText(labeltext);
		}
	}
	// ------ model access
Returns the selection state of the button.
	public boolean isSelected() {
		return ;
	}

Sets the selection state of the button.
	public void setSelection(boolean selected) {
		changeValue(selected);
			.setSelection(selected);
		}
	}
	// ------ enable / disable management
	/*
	 * @see DialogField#updateEnableState
	 */
	protected void updateEnableState() {
			.setEnabled(isEnabled());
		}
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField#refresh()
	 */
	public void refresh() {
		super.refresh();
			.setSelection();
		}
	}
New to GrepCode? Check out our FAQ X