Java Code Examples for org.eclipse.swt.widgets.Widget#getData()

The following examples show how to use org.eclipse.swt.widgets.Widget#getData() . 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: LazyItemsSelectionListener.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e) {
	// An item is selected
	Widget item = e.item;
	if (item.getData(LAST_ITEM_LOADED) != null) {
		// The selected item must load another page.
		PageableController controller = super.getController(e.widget);
		if (controller.hasNextPage()) {
			// There is next page, increment the current page of the
			// controller
			controller.setCurrentPage(controller.getCurrentPage() + 1);
		}
		// Set as null the LAST_ITEM_LOADED flag to avoid loading data when
		// the item is selected (data is already loaded).
		item.setData(LAST_ITEM_LOADED, null);
	}
}
 
Example 2
Source File: CTreeComboViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void virtualMaterializeItem(CTreeComboItem treeItem) {
	if (treeItem.getData() != null) {
		// already materialized
		return;
	}
	if (!contentProviderIsLazy) {
		return;
	}
	int index;
	Widget parent = treeItem.getParentItem();
	if (parent == null) {
		parent = treeItem.getParent();
	}
	Object parentElement = parent.getData();
	if (parentElement != null) {
		if (parent instanceof CTreeCombo) {
			index = ((CTreeCombo) parent).indexOf(treeItem);
		} else {
			index = ((CTreeComboItem) parent).indexOf(treeItem);
		}
		virtualLazyUpdateWidget(parent, index);
	}
}
 
Example 3
Source File: CTreeComboViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/** 
 * @see org.eclipse.jface.viewers.StructuredViewer#mapElement(java.lang.Object, org.eclipse.swt.widgets.Widget)
 */
protected void mapElement(Object element, final Widget item) {
	super.mapElement(element, item);
	// make sure to unmap elements if the tree is virtual
	if ((getTree().getStyle() & SWT.VIRTUAL) != 0) {
		// only add a dispose listener if item hasn't already on assigned
		// because it is reused
		if (item.getData(VIRTUAL_DISPOSE_KEY) == null) {
			item.setData(VIRTUAL_DISPOSE_KEY, Boolean.TRUE);
			item.addDisposeListener(new DisposeListener() {
				public void widgetDisposed(DisposeEvent e) {
					if (!treeIsDisposed) {
						Object data = item.getData();
						if (usingElementMap() && data != null) {
							unmapElement(data, item);
						}
					}
				}
			});
		}
	}
}
 
Example 4
Source File: CTreeComboViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Update the widget at index.
 * 
 * @param widget
 * @param index
 */
private void virtualLazyUpdateWidget(Widget widget, int index) {
	boolean oldBusy = isBusy();
	setBusy(false);
	try {
		if (contentProviderIsTreeBased) {
			TreePath treePath;
			if (widget instanceof Item) {
				if (widget.getData() == null) {
					return;
				}
				treePath = getTreePathFromItem((Item) widget);
			} else {
				treePath = TreePath.EMPTY;
			}
			((ILazyTreePathContentProvider) getContentProvider()).updateElement(treePath, index);
		} else {
			((ILazyTreeContentProvider) getContentProvider()).updateElement(widget.getData(), index);
		}
	} finally {
		setBusy(oldBusy);
	}
}
 
Example 5
Source File: ConversionProblemsDialog.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void handleMemberSelect(Widget item) {
	Object data = null;
	if (item != null)
		data = item.getData();
	if (data instanceof ICompilationUnit) {
		this.currentCU = (ICompilationUnit) data;
		problemsPane.setImage(CompareUI.getImage(this.currentCU.getResource()));
		String pattern = "Problems in file {0}";
		String title = MessageFormat.format(pattern, new Object[] { this.currentCU.getResource().getName() });
		problemsPane.setText(title);
		if (problemsTable != null) {
			problemsTable.setRedraw(false);
			problemsTable.removeAll();
			ConversionResult conversionResult = input.get(currentCU);
			for (String problem : conversionResult.getProblems()) {
				addProblemItem(problem);
			}
			problemsTable.setRedraw(true);
		}
	} else
		this.currentCU = null;
}
 
Example 6
Source File: OptionsConfigurationBlock.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void controlChanged( Widget widget )
{

	ControlData data = (ControlData) widget.getData( );
	String newValue = null;
	if ( widget instanceof Button )
	{
		if ( ( ( (Button) widget ).getStyle( ) & SWT.RADIO ) != 0 )
		{
			RadioComposite parent = (RadioComposite) ( (Button) widget ).getParent( );
			data = (ControlData) parent.getData( );
			newValue = data.getValue( parent.getBtnIndex( (Button) widget ) );
		}
		else
		{
			newValue = data.getValue( ( (Button) widget ).getSelection( ) );
		}

	}
	else if ( widget instanceof Combo )
	{
		newValue = data.getValue( ( (Combo) widget ).getSelectionIndex( ) );
	}
	else
	{
		return;
	}
	String oldValue = setValue( data.getKey( ), newValue );
	validateSettings( data.getKey( ), oldValue, newValue );
}
 
Example 7
Source File: ClassSelectionButton.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void widgetSelected( SelectionEvent e )
{
	Widget widget = e.widget;
	if ( widget instanceof MenuItem )
	{
		String exprType = (String) widget.getData( );
		provider.handleSelectionEvent( exprType );
		refresh( );
	}
	if ( widget instanceof MenuButton )
	{
		provider.handleSelectionEvent( ( (MenuButtonProvider) provider ).getDefaultOptionType( ) );
	}
}
 
Example 8
Source File: OptionsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void controlChanged(Widget widget) {
	ControlData data= (ControlData) widget.getData();
	String newValue= null;
	if (widget instanceof Button) {
		newValue= data.getValue(((Button)widget).getSelection());
	} else if (widget instanceof Combo) {
		newValue= data.getValue(((Combo)widget).getSelectionIndex());
	} else {
		return;
	}
	String oldValue= setValue(data.getKey(), newValue);
	validateSettings(data.getKey(), oldValue, newValue);
}
 
Example 9
Source File: OptionsConfigurationBlock.java    From typescript.java with MIT License 5 votes vote down vote up
protected void controlChanged(Widget widget) {
	ControlData data = (ControlData) widget.getData();
	String newValue = null;
	if (widget instanceof Button) {
		newValue = data.getValue(((Button) widget).getSelection());
	} else if (widget instanceof Combo) {
		newValue = data.getValue(((Combo) widget).getSelectionIndex());
	} else {
		return;
	}
	String oldValue = setValue(data.getKey(), newValue);
	reconcileControls();
	validateSettings(data.getKey(), oldValue, newValue);
}
 
Example 10
Source File: ExpressionButton.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void widgetSelected( SelectionEvent e )
{
	Widget widget = e.widget;
	if ( widget instanceof MenuItem )
	{
		String exprType = (String) widget.getData( );
		provider.handleSelectionEvent( exprType );
		refresh( );
	}
	else if ( widget instanceof MenuButton )
	{
		provider.handleSelectionEvent( getExpressionType( ) );
	}
}
 
Example 11
Source File: OptionsConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void controlChanged(Widget widget) {
	ControlData data = (ControlData) widget.getData();
	String newValue = null;
	if (widget instanceof Button) {
		newValue = data.getValue(((Button) widget).getSelection());
	} else if (widget instanceof Combo) {
		newValue = data.getValue(((Combo) widget).getSelectionIndex());
	} else {
		return;
	}
	String oldValue = setValue(data.getKey(), newValue);
	validateSettings(data.getKey(), oldValue, newValue);
}
 
Example 12
Source File: CContainerViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void disassociate(Widget item) {
	Object element = item.getData();
	Assert.isNotNull(element);
	//Clear the map before we clear the data
	unmapElement(element, item);
	item.setData(null);
}
 
Example 13
Source File: CContainerViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected List getSelectionFromWidget() {
	Widget[] items = container.getSelection();
	ArrayList list = new ArrayList(items.length);
	for (int i = 0; i < items.length; i++) {
		Widget item = items[i];
		Object e = item.getData();
		if (e != null)
			list.add(e);
	}
	return list;
}
 
Example 14
Source File: CContainerViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void associate(Object element, Widget item) {
	Object data = item.getData();
	if (data != element) {
		if (data != null) {
			disassociate(item);
		}
		item.setData(element);
	}
	// Always map the element, even if data == element,
	// since unmapAllElements() can leave the map inconsistent
	// See bug 2741 for details.
	mapElement(element, item);
}
 
Example 15
Source File: CTableTreeViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
    * Returns the tree path for the given item.
    * from abstracttreeviewer
    * @since 3.2
    */
   protected TreePath getTreePathFromItem(Widget item) {
	LinkedList segments = new LinkedList();
	while(item!=null) {
		Object segment = item.getData();
		Assert.isNotNull(segment);
		segments.addFirst(segment);
		item = ((CTableTreeItem) item).getParentItem();
	}
	return new TreePath(segments.toArray());
}
 
Example 16
Source File: GridViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected ViewerRow getViewerRowFromItem(Widget item) {
    ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);

    if (part == null) {
        part = new GridViewerRow(((GridItem) item));
    }

    return part;
}
 
Example 17
Source File: CTreeViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected ViewerRow getViewerRowFromItem(Widget item) {
	ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);

	if (part == null) {
		part = new CTreeViewerRow(((CTreeItem) item));
	}

	return part;
}
 
Example 18
Source File: VTracker.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static VControl getVControl(Widget widget) {
	if(widget instanceof Shell) {
		Control[] ca = ((Shell) widget).getTabList();
		if(ca.length > 0) {
			widget = ca[0];
		}
	}
	Object o = widget.getData("cwt_vcontrol");
	if(o instanceof VControl) {
		return (VControl) o;
	}
	return null;
}
 
Example 19
Source File: CTreeComboViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** 
 * @see org.eclipse.jface.viewers.AbstractTreeViewer#createChildren(org.eclipse.swt.widgets.Widget)
 */
protected void createChildren(Widget widget) {
	if (contentProviderIsLazy) {
		Object element = widget.getData();
		if (element == null && widget instanceof CTreeComboItem) {
			// parent has not been materialized
			virtualMaterializeItem((CTreeComboItem) widget);
			// try getting the element now that updateElement was called
			element = widget.getData();
		}
		if (element == null) {
			// give up because the parent is still not materialized
			return;
		}
		Item[] children = getChildren(widget);
		if (children.length == 1 && children[0].getData() == null) {
			// found a dummy node
			virtualLazyUpdateChildCount(widget, children.length);
			children = getChildren(widget);
		}
		// touch all children to make sure they are materialized
		for (int i = 0; i < children.length; i++) {
			if (children[i].getData() == null) {
				virtualLazyUpdateWidget(widget, i);
			}
		}
		return;
	}
	super.createChildren(widget);
}
 
Example 20
Source File: ExpressionCellEditor.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void setExpressionCellEditorProvider(
		IExpressionCellEditorProvider provider )
{
	if ( provider != null && provider != this.provider )
	{
		this.provider = provider;

		provider.setInput( this );

		for ( int i = 0; i < menu.getItemCount( ); i++ )
		{
			menu.getItem( i ).dispose( );
			i--;
		}

		String[] types = this.provider.getExpressionTypes( );

		listener = new SelectionAdapter( ) {

			public void widgetSelected( SelectionEvent e )
			{
				Widget widget = e.widget;
				if ( widget instanceof MenuItem )
				{
					String exprType = (String) widget.getData( );
					ExpressionCellEditor.this.provider.handleSelectionEvent( exprType );
				}
				else if ( widget instanceof Button )
				{
					ExpressionCellEditor.this.provider.handleSelectionEvent( getExpressionType( ) );
				}
			}

		};

		for ( int i = 0; i < types.length; i++ )
		{
			MenuItem item = new MenuItem( menu, SWT.CHECK );
			item.setText( this.provider.getText( types[i] ) );
			item.setData( types[i] );
			item.addSelectionListener( listener );
		}

		if ( menu.getItemCount( ) <= 1 )
		{
			menu = null;
			button.addSelectionListener( listener );
		}

		refresh( );
	}
}