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

The following examples show how to use org.eclipse.swt.widgets.Shell#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: BaseTransformDialog.java    From hop with Apache License 2.0 6 votes vote down vote up
public static void setSize( Shell shell, int prefWidth, int prefHeight ) {
  PropsUi props = PropsUi.getInstance();

  WindowProperty winprop = props.getScreen( shell.getText() );
  if ( winprop != null ) {
    winprop.setShell( shell, prefWidth, prefHeight );
  } else {
    shell.layout();

    winprop = new WindowProperty( shell.getText(), false, 0, 0, prefWidth, prefHeight );
    winprop.setShell( shell );

    // Now, as this is the first time it gets opened, try to put it in the middle of the screen...
    Rectangle shellBounds = shell.getBounds();
    Monitor monitor = shell.getDisplay().getPrimaryMonitor();
    if ( shell.getParent() != null ) {
      monitor = shell.getParent().getMonitor();
    }
    Rectangle monitorClientArea = monitor.getClientArea();

    int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2;
    int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2;

    shell.setLocation( middleX, middleY );
  }
}
 
Example 2
Source File: DataOverrideHandler.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private Shell getCenteredShell( Shell shell ) {
  Rectangle shellBounds = shell.getBounds();
  Monitor monitor = shell.getDisplay().getPrimaryMonitor();

  if ( shell.getParent() != null ) {
    monitor = shell.getParent().getMonitor();
  }

  Rectangle monitorClientArea = monitor.getClientArea();

  int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2;
  int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2;

  shell.setLocation( middleX, middleY );

  return shell;
}
 
Example 3
Source File: BaseTransformDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the size of this dialog with respect to the given parameters.
 *
 * @param shell     the shell
 * @param minWidth  the minimum width
 * @param minHeight the minimum height
 * @param packIt    true to pack the dialog components, false otherwise
 */
public static void setSize( Shell shell, int minWidth, int minHeight, boolean packIt ) {
  PropsUi props = PropsUi.getInstance();

  WindowProperty winprop = props.getScreen( shell.getText() );
  if ( winprop != null ) {
    winprop.setShell( shell, minWidth, minHeight );
  } else {
    if ( packIt ) {
      shell.pack();
    } else {
      shell.layout();
    }

    // OK, sometimes this produces dialogs that are waay too big.
    // Try to limit this a bit, m'kay?
    // Use the same algorithm by cheating :-)
    //
    winprop = new WindowProperty( shell );
    winprop.setShell( shell, minWidth, minHeight );

    // Now, as this is the first time it gets opened, try to put it in the middle of the screen...
    Rectangle shellBounds = shell.getBounds();
    Monitor monitor = shell.getDisplay().getPrimaryMonitor();
    if ( shell.getParent() != null ) {
      monitor = shell.getParent().getMonitor();
    }
    Rectangle monitorClientArea = monitor.getClientArea();

    int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2;
    int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2;

    shell.setLocation( middleX, middleY );
  }
}
 
Example 4
Source File: ChoicesDialog.java    From SWET with MIT License 5 votes vote down vote up
private void center(Shell shell) {

		Shell parent = (Shell) shell.getParent();
		Rectangle bounds = parent.getBounds();
		Point size = shell.getSize();

		int x = bounds.x + bounds.width / 2 - size.x / 2;
		int y = bounds.y + bounds.height / 2 - size.y / 2;
		// System.err.println("ChoiceDialog: center: x=" + x + " y=" + y);
		shell.setLocation(x, (y < 0) ? 0 : y);
	}
 
Example 5
Source File: MessagingControl.java    From offspring with MIT License 5 votes vote down vote up
private void openReplyDialog(Long recipientId, Long transactionId,
    boolean useEncryption) {
  Shell shell = getShell();
  if (shell != null) {
    while (shell.getParent() != null) {
      shell = shell.getParent().getShell();
    }
  }
  WizardDialog dialog = new WizardDialog(shell, new SendMessageWizard(
      userService, nxt, recipientId, transactionId, useEncryption));
  dialog.open();
}
 
Example 6
Source File: BaseDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return
 */
private IDialogSettings loadDialogSettings( )
{
	if ( !needRememberLastSize( ) )
	{
		return null;
	}
	IDialogSettings dialogSettings = ReportPlugin.getDefault( )
			.getDialogSettings( );
	StringBuffer buf = new StringBuffer( );
	Shell curShell = getShell( );
	while ( curShell != null )
	{
		buf.append( curShell.toString( ) + '/' );
		Composite parent = curShell.getParent( );
		if ( parent != null )
		{
			curShell = parent.getShell( );
		}
		else
		{
			curShell = null;
		}
	}
	if ( buf.length( ) > 0 )
	{
		buf.deleteCharAt( buf.length( ) - 1 );
		String sectionName = buf.toString( );
		IDialogSettings setting = dialogSettings.getSection( sectionName );
		if ( setting == null )
		{
			setting = dialogSettings.addNewSection( sectionName );
		}
		return setting;
	}
	else
	{
		return dialogSettings;
	}
}
 
Example 7
Source File: DocumentProposalListener.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected DocumentWizardDialog createDocumentWizardDialog(final DocumentWizard documentWizard) {
    Shell activeShell = Display
            .getDefault().getActiveShell();
    if (activeShell.getParent() != null) {
        activeShell = activeShell.getParent().getShell();
    }
    return new DocumentWizardDialog(activeShell,
            documentWizard, false);
}
 
Example 8
Source File: CreateBusinessDataProposalListener.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String handleEvent(EObject context, final String fixedReturnType) {
    Assert.isNotNull(context);
    while (!(context instanceof Pool)) {
        context = context.eContainer();
    }
    final BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> repositoryStore = RepositoryManager
            .getInstance().getRepositoryStore(BusinessObjectModelRepositoryStore.class);
    final AddBusinessObjectDataWizard newWizard = new AddBusinessObjectDataWizard((DataAware) context,
            newMultipleBusinessData(context), repositoryStore,
            TransactionUtil.getEditingDomain(context));
    Shell activeShell = Display
            .getDefault().getActiveShell();
    if (activeShell.getParent() != null) {
        activeShell = activeShell.getParent().getShell();
    }
    final CustomWizardDialog wizardDialog = new CustomWizardDialog(activeShell,
            newWizard, IDialogConstants.FINISH_LABEL);
    if (wizardDialog.open() == Dialog.OK) {
        final EObject obj = newWizard.getBusinessObjectData();
        if (obj instanceof Data) {
            final Data d = (Data) obj;
            if (d != null) {
                return d.getName();
            }
        }
    }
    return null;
}
 
Example 9
Source File: WindowProperty.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Performs calculations to size and position a dialog If the size passed in is too large for the primary monitor
 * client area, it is shrunk to fit. If the positioning leaves part of the dialog outside the client area, it is
 * centered instead.
 *
 * @param shell        The dialog to position and size
 * @param onlyPosition Unused argument. If the window is outside the viewable client are, it must be resized to prevent
 *                     inaccessibility.
 * @param minWidth
 * @param minHeight
 */
public void setShell( Shell shell, boolean onlyPosition, int minWidth, int minHeight ) {
  shell.setMaximized( maximized );
  shell.setBounds( new Rectangle(x, y, width, height) );

  if ( minWidth > 0 || minHeight > 0 ) {
    Rectangle bounds = shell.getBounds();
    if ( bounds.width < minWidth ) {
      bounds.width = minWidth;
    }
    if ( bounds.height < minHeight ) {
      bounds.height = minHeight;
    }
    shell.setSize( bounds.width, bounds.height );
  }

  // Just to double check: what is the preferred size of this dialog?
  // This computed is a minimum. If the minimum is smaller than the
  // size of the current shell, we make it larger.
  //
  Point computedSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT );
  Rectangle shellSize = shell.getBounds();
  if ( shellSize.width < computedSize.x ) {
    shellSize.width = computedSize.x;
  }
  if ( shellSize.height < computedSize.y ) {
    shellSize.height = computedSize.y;
  }
  shell.setBounds( shellSize );

  Rectangle entireClientArea = shell.getDisplay().getClientArea();
  Rectangle resizedRect = Geometry.copy( shellSize );
  constrainRectangleToContainer( resizedRect, entireClientArea );

  // If the persisted size/location doesn't perfectly fit
  // into the entire client area, the persisted settings
  // likely were not meant for this configuration of monitors.
  // Relocate the shell into either the parent monitor or if
  // there is no parent, the primary monitor then center it.
  //
  if ( !resizedRect.equals( shellSize ) || isClippedByUnalignedMonitors( resizedRect, shell.getDisplay() ) ) {
    Monitor monitor = shell.getDisplay().getPrimaryMonitor();
    if ( shell.getParent() != null ) {
      monitor = shell.getParent().getMonitor();
    }
    Rectangle monitorClientArea = monitor.getClientArea();
    constrainRectangleToContainer( resizedRect, monitorClientArea );

    resizedRect.x = monitorClientArea.x + ( monitorClientArea.width - resizedRect.width ) / 2;
    resizedRect.y = monitorClientArea.y + ( monitorClientArea.height - resizedRect.height ) / 2;

    shell.setBounds( resizedRect );
  }
}
 
Example 10
Source File: WindowProperty.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Performs calculations to size and position a dialog If the size passed in is too large for the primary monitor
 * client area, it is shrunk to fit. If the positioning leaves part of the dialog outside the client area, it is
 * centered instead Note that currently, many of the defaults in org.pentaho.di.ui.core/default.properties have crazy
 * values. This causes the failsafe code in here to fire a lot more than is really necessary.
 *
 * @param shell
 *          The dialog to position and size
 * @param onlyPosition
 *          Unused argument. If the window is outside the viewable client are, it must be resized to prevent
 *          inaccessibility.
 * @param minWidth
 * @param minHeight
 */
public void setShell( Shell shell, boolean onlyPosition, int minWidth, int minHeight ) {
  shell.setMaximized( maximized );
  shell.setBounds( rectangle );

  if ( minWidth > 0 || minHeight > 0 ) {
    Rectangle bounds = shell.getBounds();
    if ( bounds.width < minWidth ) {
      bounds.width = minWidth;
    }
    if ( bounds.height < minHeight ) {
      bounds.height = minHeight;
    }
    shell.setSize( bounds.width, bounds.height );
  }

  // Just to double check: what is the preferred size of this dialog?
  // This computed is a minimum. If the minimum is smaller than the
  // size of the current shell, we make it larger.
  //
  Point computedSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT );
  Rectangle shellSize = shell.getBounds();
  if ( shellSize.width < computedSize.x ) {
    shellSize.width = computedSize.x;
  }
  if ( shellSize.height < computedSize.y ) {
    shellSize.height = computedSize.y;
  }
  shell.setBounds( shellSize );

  Rectangle entireClientArea = shell.getDisplay().getClientArea();
  Rectangle resizedRect = Geometry.copy( shellSize );
  constrainRectangleToContainer( resizedRect, entireClientArea );

  // If the persisted size/location doesn't perfectly fit
  // into the entire client area, the persisted settings
  // likely were not meant for this configuration of monitors.
  // Relocate the shell into either the parent monitor or if
  // there is no parent, the primary monitor then center it.
  //
  if ( !resizedRect.equals( shellSize ) || isClippedByUnalignedMonitors( resizedRect, shell.getDisplay() ) ) {
    Monitor monitor = shell.getDisplay().getPrimaryMonitor();
    if ( shell.getParent() != null ) {
      monitor = shell.getParent().getMonitor();
    }
    Rectangle monitorClientArea = monitor.getClientArea();
    constrainRectangleToContainer( resizedRect, monitorClientArea );

    resizedRect.x = monitorClientArea.x + ( monitorClientArea.width - resizedRect.width ) / 2;
    resizedRect.y = monitorClientArea.y + ( monitorClientArea.height - resizedRect.height ) / 2;

    shell.setBounds( resizedRect );
  }
}