Java Code Examples for org.eclipse.swt.widgets.Control#getParent()

The following examples show how to use org.eclipse.swt.widgets.Control#getParent() . These examples are extracted from open source projects. 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 Project: birt   File: UIUtil.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static boolean containsFocusControl( Control container )
{
	Control control = container.getDisplay( ).getFocusControl( );

	if ( control == container )
		return true;

	while ( control != null )
	{
		control = control.getParent( );
		if ( control == container )
			return true;
	}

	return false;
}
 
Example 2
Source Project: nebula   File: MonthCalendar.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private Day getDay(MouseEvent e) {
	Control control = (Control) e.widget;
	while (!(control instanceof Day)) {
		control = control.getParent();
	}
	Day day = (Day) control;
	return day;
}
 
Example 3
private void addDropListener(Composite parent) {
	LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();

	DropTargetAdapter dragAdapter = new DropTargetAdapter() {
		@Override
		public void drop(DropTargetEvent event) {
			Control droppedObj = (Control) ((StructuredSelection) transfer.getSelection()).getFirstElement();

			// Get the existing parent of the dragged control
			Composite oldParent = droppedObj.getParent();

			if (oldParent == parent) {
				return;
			}

			if  (droppedObj instanceof Label) {
				System.out.println("Dropped");
			}
			// handle the drop
			if (droppedObj instanceof Label) {
				Label droppedLabel = (Label) droppedObj;
				droppedLabel.setParent(parent); // Change parent
			}

			if (droppedObj instanceof Button) {
				Button droppedButton = (Button) droppedObj;
				droppedButton.setParent(parent); // Change parent
			}

			// request a layout pass
			oldParent.requestLayout();
			// If you change that to layout the layout will be correct
			parent.layout();
		}
	};

	DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY);
	dropTarget.setTransfer(new Transfer[] { transfer });
	dropTarget.addDropListener(dragAdapter);
}
 
Example 4
Source Project: uima-uimaj   File: HeaderPage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Setup 2 column layout.
 *
 * @param managedForm the managed form
 * @param w1 the w 1
 * @param w2 the w 2
 * @return the form 2 panel
 */
public Form2Panel setup2ColumnLayout(IManagedForm managedForm, int w1, int w2) {
  final ScrolledForm sform = managedForm.getForm();
  final Composite form = sform.getBody();
  form.setLayout(new GridLayout(1, false)); // this is required !
  Composite xtra = toolkit.createComposite(form);
  xtra.setLayout(new GridLayout(1, false));
  xtra.setLayoutData(new GridData(GridData.FILL_BOTH));
  Control c = xtra.getParent();
  while (!(c instanceof ScrolledComposite))
    c = c.getParent();
  ((GridData) xtra.getLayoutData()).widthHint = c.getSize().x;
  ((GridData) xtra.getLayoutData()).heightHint = c.getSize().y;
  sashForm = new SashForm(xtra, SWT.HORIZONTAL);

  sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); // needed

  leftPanel = newComposite(sashForm);
  ((GridLayout) leftPanel.getLayout()).marginHeight = 5;
  ((GridLayout) leftPanel.getLayout()).marginWidth = 5;
  rightPanel = newComposite(sashForm);
  ((GridLayout) rightPanel.getLayout()).marginHeight = 5;
  ((GridLayout) rightPanel.getLayout()).marginWidth = 5;
  sashForm.setWeights(new int[] { w1, w2 });
  leftPanelPercent = (float) w1 / (float) (w1 + w2);
  rightPanelPercent = (float) w2 / (float) (w1 + w2);

  rightPanel.addControlListener(new ControlAdapter() {
    @Override
    public void controlResized(ControlEvent e) {
      setSashFormWidths();
    }
  });

  return new Form2Panel(form, leftPanel, rightPanel);
}
 
Example 5
Source Project: BiglyBT   File: BaseMDI.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static BaseMdiEntry getEntryFromSkinObject(PluginUISWTSkinObject pluginSkinObject) {
	if (pluginSkinObject instanceof SWTSkinObject) {
		Control control = ((SWTSkinObject) pluginSkinObject).getControl();
		while (control != null && !control.isDisposed()) {
			Object entry = control.getData("BaseMDIEntry");
			if (entry instanceof BaseMdiEntry) {
				BaseMdiEntry mdiEntry = (BaseMdiEntry) entry;
				return mdiEntry;
			}
			control = control.getParent();
		}
	}
	return null;
}
 
Example 6
private ScrolledPageContent getParentScrolledComposite(Control control) {
	Control parent = control.getParent();
	while (!(parent instanceof ScrolledPageContent) && parent != null) {
		parent = parent.getParent();
	}
	if (parent instanceof ScrolledPageContent) {
		return (ScrolledPageContent) parent;
	}
	return null;
}
 
Example 7
private boolean isChildrenOfThis( Control control )
{
	while ( control != null )
	{
		if ( control == this )
		{
			return true;
		}
		control = control.getParent( );
	}
	return false;
}
 
Example 8
protected boolean isFocusAncestorA (Control control) {
    Display display = getDisplay ();
    Control focusControl = display.getFocusControl ();
    while (focusControl != null && focusControl != control) {
        focusControl = focusControl. getParent();
    }
    return control == focusControl;
}
 
Example 9
protected ExpandableComposite getParentExpandableComposite(Control control) {
	Control parent = control.getParent();
	while (!(parent instanceof ExpandableComposite) && parent != null) {
		parent = parent.getParent();
	}
	if (parent instanceof ExpandableComposite) {
		return (ExpandableComposite) parent;
	}
	return null;
}
 
Example 10
public boolean containsControl(Control control)
{
	do
	{
		if (control == fShell)
			return true;
		if (control instanceof Shell)
			return false;
		control = control.getParent();
	}
	while (control != null);
	return false;
}
 
Example 11
/**
  * Get the scrolled page content of the given control by
  * traversing the parents.
  *
  * @param control the control to get the scrolled page content for
  * @return the scrolled page content or <code>null</code> if none found
  */
 private ScrolledPageContent getParentScrolledComposite(Control control) {
    Control parent= control.getParent();
    while (!(parent instanceof ScrolledPageContent)) {
        parent= parent.getParent();
    }
    if (parent instanceof ScrolledPageContent) {
        return (ScrolledPageContent) parent;
    }
    return null;
}
 
Example 12
/**
 * Enable the specified composite.
 */
private void enableParent( Control control )
{
    Composite parent = control.getParent( );
    if ( parent == null || parent instanceof Shell )
    {
        return;
    }
    if ( !parent.isEnabled( ) )
    {
        parent.setEnabled( true );
    }
    enableParent( parent );
}
 
Example 13
Source Project: uima-uimaj   File: HeaderPage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Setup 1 column layout.
 *
 * @param managedForm the managed form
 * @return the composite
 */
public Composite setup1ColumnLayout(IManagedForm managedForm) {
  final ScrolledForm sform = managedForm.getForm();
  final Composite form = sform.getBody();
  form.setLayout(new GridLayout(1, false)); // this is required !
  Composite xtra = toolkit.createComposite(form);
  xtra.setLayout(new GridLayout(1, false));
  xtra.setLayoutData(new GridData(GridData.FILL_BOTH));

  Control c = form.getParent();
  while (!(c instanceof ScrolledComposite))
    c = c.getParent();
  ((GridData) xtra.getLayoutData()).widthHint = c.getSize().x;
  return xtra;
}
 
Example 14
@Override
public boolean containsControl(Control control) {
	do {
		if (control == fShell)
			return true;
		if (control instanceof Shell)
			return false;
		control= control.getParent();
	} while (control != null);
	return false;
}
 
Example 15
/**
 * Enable the specific composite
 */
private void enableParent( Control control )
{
	Composite parent = control.getParent( );
	if ( parent == null || parent instanceof Shell )
	{
		return;
	}
	if ( !parent.isEnabled( ) )
	{
		parent.setEnabled( true );
	}
	enableParent( parent );
}
 
Example 16
Source Project: birt   File: AbstractPopupSheet.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void helpPressed( )
{
	Control c = cmpTop.getDisplay( ).getFocusControl( );
	while ( c != null )
	{
		if ( c.isListening( SWT.Help ) )
		{
			c.notifyListeners( SWT.Help, new Event( ) );
			break;
		}
		c = c.getParent( );
	}
}
 
Example 17
private boolean isChildrenOfThis( Control control )
{
	while ( control != null )
	{
		if ( control == this )
		{
			return true;
		}
		control = control.getParent( );
	}
	return false;
}
 
Example 18
private final ExpandableComposite getParentExpandableComposite(Control control) {
	Control parent= control.getParent();
	while (!(parent instanceof ExpandableComposite) && parent != null) {
		parent= parent.getParent();
	}
	if (parent instanceof ExpandableComposite) {
		return (ExpandableComposite) parent;
	}
	return null;
}
 
Example 19
protected ScrolledPageContent getParentScrolledComposite(Control control) {
	Control parent= control.getParent();
	while (!(parent instanceof ScrolledPageContent) && parent != null) {
		parent= parent.getParent();
	}
	if (parent instanceof ScrolledPageContent) {
		return (ScrolledPageContent) parent;
	}
	return null;
}
 
Example 20
protected ExpandableComposite getParentExpandableComposite(Control control) {
	Control parent= control.getParent();
	while (!(parent instanceof ExpandableComposite) && parent != null) {
		parent= parent.getParent();
	}
	if (parent instanceof ExpandableComposite) {
		return (ExpandableComposite) parent;
	}
	return null;
}