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

The following examples show how to use org.eclipse.swt.widgets.Control#getParent() . 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: UIUtil.java    From birt with 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 File: NewSourceContainerWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
  * 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 3
Source File: OptionsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 4
Source File: OptionsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 5
Source File: AbstractConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 6
Source File: AggregateEditorComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isChildrenOfThis( Control control )
{
	while ( control != null )
	{
		if ( control == this )
		{
			return true;
		}
		control = control.getParent( );
	}
	return false;
}
 
Example 7
Source File: AbstractPopupSheet.java    From birt with 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 8
Source File: JDBCSelectionPageHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 9
Source File: SourceViewerInformationControl.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@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 10
Source File: HeaderPage.java    From uima-uimaj with 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 11
Source File: HiveSelectionPageHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 12
Source File: MonthCalendar.java    From nebula with 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 13
Source File: CustomAbstractInformationControl.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: OptionsConfigurationBlock.java    From typescript.java with MIT License 5 votes vote down vote up
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 15
Source File: BonitaSashForm.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isFocusAncestorA (Control control) {
    Display display = getDisplay ();
    Control focusControl = display.getFocusControl ();
    while (focusControl != null && focusControl != control) {
        focusControl = focusControl. getParent();
    }
    return control == focusControl;
}
 
Example 16
Source File: MarkerEditorComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isChildrenOfThis( Control control )
{
	while ( control != null )
	{
		if ( control == this )
		{
			return true;
		}
		control = control.getParent( );
	}
	return false;
}
 
Example 17
Source File: OptionsConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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 18
Source File: BaseMDI.java    From BiglyBT with 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 19
Source File: HeaderPage.java    From uima-uimaj with 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 20
Source File: View.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
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);
}