Java Code Examples for org.eclipse.swt.widgets.List#addListener()

The following examples show how to use org.eclipse.swt.widgets.List#addListener() . 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: CCombo.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
void createPopup(String[] items, int selectionIndex) {		
		// create shell and list
		popup = new Shell (getShell(), SWT.NO_TRIM | SWT.ON_TOP);
		int style = getStyle();
		int listStyle = SWT.SINGLE | SWT.V_SCROLL;
		if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT;
		if ((style & SWT.RIGHT_TO_LEFT) != 0) listStyle |= SWT.RIGHT_TO_LEFT;
		if ((style & SWT.LEFT_TO_RIGHT) != 0) listStyle |= SWT.LEFT_TO_RIGHT;
		list = new List (popup, listStyle);
		if (font != null) list.setFont(font);
		if (foreground != null) list.setForeground(foreground);
		if (background != null) list.setBackground(background);
		
		int [] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate};
		for (int i=0; i<popupEvents.length; i++) popup.addListener (popupEvents [i], listener);
		int [] listEvents = {SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.FocusOut, SWT.Dispose};
		for (int i=0; i<listEvents.length; i++) list.addListener (listEvents [i], listener);
		
		if (items != null) list.setItems(items);
		if (selectionIndex != -1) list.setSelection(selectionIndex);
}
 
Example 2
Source File: CustomCombo.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
void createPopup(String[] items, int selectionIndex) {
	// create shell and list
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
	int style = getStyle();
	int listStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		listStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		listStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		listStyle |= SWT.LEFT_TO_RIGHT;
	list = new List(popup, listStyle);
	if (font != null)
		list.setFont(font);
	if (foreground != null)
		list.setForeground(foreground);
	if (background != null)
		list.setBackground(background);

	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
	for (int i = 0; i < popupEvents.length; i++)
		popup.addListener(popupEvents[i], listener);
	int[] listEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < listEvents.length; i++)
		list.addListener(listEvents[i], listener);

	if (items != null)
		list.setItems(items);
	if (selectionIndex != -1)
		list.setSelection(selectionIndex);
}
 
Example 3
Source File: LoadQueryDialog.java    From Rel with Apache License 2.0 5 votes vote down vote up
/**
 * Create contents of the dialog.
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
	Composite container = (Composite) super.createDialogArea(parent);
	container.setLayout(new FillLayout(SWT.HORIZONTAL));
	
	List list = new List(container, SWT.BORDER);
	for (String item: items)
		list.add(item);
	list.addListener(SWT.Selection, e -> item = list.getSelection()[0]);

	return container;
}
 
Example 4
Source File: VarTypeDialog.java    From Rel with Apache License 2.0 4 votes vote down vote up
/**
 * Create contents of the dialog.
 */
private void createContents() {
	shlVariableTypeAndName = new Shell(getParent(), getStyle());
	shlVariableTypeAndName.setSize(550, 320);
	shlVariableTypeAndName.setText("Variable Type and Name");
	shlVariableTypeAndName.setLayout(new FormLayout());

	Label lblChooseTheKind = new Label(shlVariableTypeAndName, SWT.NONE);
	FormData fd_lblChooseTheKind = new FormData();
	fd_lblChooseTheKind.left = new FormAttachment(0, 10);
	fd_lblChooseTheKind.top = new FormAttachment(0, 10);
	fd_lblChooseTheKind.bottom = new FormAttachment(0, 24);
	fd_lblChooseTheKind.right = new FormAttachment(100, -10);
	lblChooseTheKind.setLayoutData(fd_lblChooseTheKind);
	lblChooseTheKind.setText("Choose the kind of variable you wish to create.");

	List listVarType = new List(shlVariableTypeAndName, SWT.BORDER);
	FormData fd_listVarType = new FormData();
	fd_listVarType.top = new FormAttachment(lblChooseTheKind, 6);
	fd_listVarType.left = new FormAttachment(0, 10);
	fd_listVarType.right = new FormAttachment(100, -10);
	listVarType.setLayoutData(fd_listVarType);

	if (lastVariableType == null)
		lastVariableType = "REAL";
	int index = 0;
	for (String relvarType : database.getRelvarTypes()) {
		listVarType.add(relvarType);
		if (getVarTypeCode(relvarType).equalsIgnoreCase(lastVariableType))
			listVarType.setSelection(index);
		index++;
	}

	Button btnCancel = new Button(shlVariableTypeAndName, SWT.NONE);
	FormData fd_btnCancel = new FormData();
	fd_btnCancel.bottom = new FormAttachment(100, -10);
	fd_btnCancel.right = new FormAttachment(100, -10);
	btnCancel.setLayoutData(fd_btnCancel);
	btnCancel.setText("Cancel");

	Button btnOk = new Button(shlVariableTypeAndName, SWT.NONE);
	FormData fd_btnOk = new FormData();
	fd_btnOk.bottom = new FormAttachment(100, -10);
	fd_btnOk.right = new FormAttachment(btnCancel, -10);
	btnOk.setLayoutData(fd_btnOk);
	btnOk.setText("Ok");

	fd_listVarType.bottom = new FormAttachment(btnCancel, -10);

	listVarType.addListener(SWT.Selection, e -> variableType = obtainSelectedType(listVarType));

	btnCancel.addListener(SWT.Selection, e -> {
		variableType = null;
		shlVariableTypeAndName.dispose();
	});

	btnOk.addListener(SWT.Selection, e -> {
		variableType = obtainSelectedType(listVarType);
		shlVariableTypeAndName.dispose();
	});

	listVarType.addListener(SWT.MouseDoubleClick, e -> {
		variableType = obtainSelectedType(listVarType);
		shlVariableTypeAndName.dispose();
	});

}
 
Example 5
Source File: DataItemCombo.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void createPopup( String[] items, int selectionIndex )
{
	// create shell and list
	popup = new Shell( getShell( ), SWT.NO_TRIM | SWT.ON_TOP );
	int style = getStyle( );
	int listStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ( ( style & SWT.FLAT ) != 0 )
		listStyle |= SWT.FLAT;
	if ( ( style & SWT.RIGHT_TO_LEFT ) != 0 )
		listStyle |= SWT.RIGHT_TO_LEFT;
	if ( ( style & SWT.LEFT_TO_RIGHT ) != 0 )
		listStyle |= SWT.LEFT_TO_RIGHT;
	list = new List( popup, listStyle );
	if ( font != null )
		list.setFont( font );
	if ( foreground != null )
		list.setForeground( foreground );
	if ( background != null )
		list.setBackground( background );

	int[] popupEvents = {
			SWT.Close, SWT.Paint, SWT.Deactivate
	};
	for ( int i = 0; i < popupEvents.length; i++ )
		popup.addListener( popupEvents[i], listener );
	int[] listEvents = {
			SWT.MouseUp,
			SWT.Selection,
			SWT.Traverse,
			SWT.KeyDown,
			SWT.KeyUp,
			SWT.FocusIn,
			SWT.Dispose
	};
	for ( int i = 0; i < listEvents.length; i++ )
		list.addListener( listEvents[i], listener );

	if ( items != null )
		list.setItems( items );
	if ( selectionIndex != -1 )
		list.setSelection( selectionIndex );
}