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

The following examples show how to use org.eclipse.swt.widgets.Shell#setLocation() . 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: 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 2
Source File: PatternImageEditorDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void toggleDropDown( )
{
	if ( dropDown == null || dropDown.isDisposed( ) )
	{
		Point pt = UIHelper.getScreenLocation( host );
		int x = pt.x;
		int y = pt.y + host.getSize( ).y;

		Shell shell = new Shell( host.getShell( ), SWT.NONE );
		shell.setLayout( new GridLayout( ) );
		shell.setLocation( x, y );
		dropDown = createDropDown( shell );
		shell.layout( );
		shell.pack( );
		shell.open( );
	}
	else
	{
		dropDown.getShell( ).close( );
	}
}
 
Example 3
Source File: DropTestSnippet.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void open() {
	Shell parent = getParent();
	final Shell shell = new Shell(parent, getStyle());
	shell.setText("Testing");
	shell.setLayout(new GridLayout());

	final CDateTime cdc2 = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
	cdc2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

	Display display = parent.getDisplay();
	shell.layout(true, true);
	shell.pack();
	int x = shell.getSize().x;
	int y = shell.getSize().y;
	shell.setLocation(
			(display.getBounds().width-x)/2,
			(display.getBounds().height-y)/2
	);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
}
 
Example 4
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Try to make the shell fully visible in the display. If the shell cannot
 * fit the display, it will be positioned so that top-left corner is at
 * <code>(0, 0)</code> in display-relative coordinates.
 *
 * @param shell
 *            the shell to make fully visible
 */
private static void makeShellFullyVisible(Shell shell) {
    Rectangle displayBounds = shell.getDisplay().getBounds();
    Point absCoord = shell.toDisplay(0, 0);
    Point shellSize = shell.getSize();

    Point newLocation = new Point(absCoord.x, absCoord.y);
    newLocation.x = Math.max(0, Math.min(absCoord.x, displayBounds.width - shellSize.x));
    newLocation.y = Math.max(0, Math.min(absCoord.y, displayBounds.height - shellSize.y));
    if (!newLocation.equals(absCoord)) {
        shell.setLocation(newLocation);
    }
}
 
Example 5
Source File: SwtUtils.java    From http4e with Apache License 2.0 5 votes vote down vote up
public static void centreWindow( Shell shell){
   Rectangle displayRect;
   try {
      displayRect = shell.getMonitor().getClientArea();
   } catch (NoSuchMethodError e) {
      displayRect = shell.getDisplay().getClientArea();
   }
   Rectangle shellRect = shell.getBounds();
   int x = (displayRect.width - shellRect.width) / 2;
   int y = (displayRect.height - shellRect.height) / 2;
   shell.setLocation(x, y);
}
 
Example 6
Source File: Regression_141706_svg.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static void main( String args[] )
{
	display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setSize( 220, 80 );
	shell.setLocation( display.getClientArea( ).width / 2 - 110, display
			.getClientArea( ).height / 2 - 40 );
	shell.setLayout( new GridLayout( ) );

	Regression_141706_svg siv = new Regression_141706_svg( shell, SWT.NONE );
	GridData gd = new GridData( GridData.BEGINNING );
	gd.widthHint = 1;
	gd.heightHint = 1;
	siv.setLayoutData( gd );

	Composite cBottom = new Composite( shell, SWT.NONE );
	cBottom.setLayoutData( new GridData( GridData.CENTER ) );
	cBottom.setLayout( new RowLayout( ) );

	Label la = new Label( cBottom, SWT.NONE );
	la.setText( "Choose: " );//$NON-NLS-1$

	cbType = new Combo( cBottom, SWT.DROP_DOWN | SWT.READ_ONLY );
	cbType.add( "Show Tooltip" );//$NON-NLS-1$
	cbType.select( 0 );

	btn = new Button( cBottom, SWT.NONE );
	btn.setText( "Show" );//$NON-NLS-1$
	btn.addSelectionListener( siv );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 7
Source File: GeoMapViewerTest.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected Widget createUI(Display display) {
	Shell shell = new Shell(display, SWT.SHELL_TRIM);
	shell.setText("GeoMap Widget - SWT Native Map Browsing, Map data from openstreetmap.org");
	shell.setSize(600, 710);
	shell.setLocation(10, 10);
	shell.setLayout(new FillLayout());

	createControls(shell);
	shell.open();

	return shell;
}
 
Example 8
Source File: SyncApplicationDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void configureShell(Shell newShell) {
	super.configureShell(newShell);
	newShell.setText(Messages.SYNCPROJECT);
	newShell.setSize(506, 500);
	if(parentShell!=null){
		
		Rectangle parentBounds = parentShell.getBounds();
		Rectangle shellBounds = newShell.getBounds();
		newShell.setLocation(parentBounds.x
				+ (parentBounds.width - shellBounds.width) / 2, parentBounds.y
				+ (parentBounds.height - shellBounds.height) / 2);
	}
}
 
Example 9
Source File: DeviceNotFoundDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void configureShell(Shell newShell) {
	super.configureShell(newShell);
	newShell.setText(Messages.SYNCPROJECT);
	newShell.setSize(480, 310);
	Rectangle parentBounds = parentShell.getBounds();
	Rectangle shellBounds = newShell.getBounds();

	newShell.setLocation(parentBounds.x
			+ (parentBounds.width - shellBounds.width) / 2, parentBounds.y
			+ (parentBounds.height - shellBounds.height) / 2);
}
 
Example 10
Source File: WaitDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void centerDialogOnScreen(Shell shell) {
	shell.setSize(250, 75);
	Rectangle parentSize = getParentShell().getBounds();
	Rectangle mySize = shell.getBounds();
	int locationX, locationY;
	locationX = (parentSize.width - mySize.width)/2+parentSize.x;
	locationY = (parentSize.height - mySize.height)/2+parentSize.y;
	shell.setLocation(locationX, locationY);
}
 
Example 11
Source File: BrowserEnvironmentWarningDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * showWarningDialog
 * <p>
 * Shows a SWT dialog warning the user that something is wrong with the browser environment.
 *
 * @param title        the title on the top of the window.
 * @param message      the message at the center of the screen.
 * @param helpLink     a string that contains a hyperlink to a help web page.
 * @param maxTextWidth the width for the text inside the dialog.
 */
private void showWarningDialog( String title, String message, String helpLink, EnvironmentCase environment,
                                int maxTextWidth ) {
  if ( this.getParent().isDisposed() ) {
    return;
  }

  this.props = PropsUi.getInstance();
  Display display = this.getParent().getDisplay();
  shell = new Shell( this.getParent(), SWT.TITLE | SWT.APPLICATION_MODAL );
  props.setLook( shell );

  FormLayout formLayout = new FormLayout();
  formLayout.marginWidth = margin;
  formLayout.marginHeight = margin;
  shell.setLayout( formLayout ); // setting layout

  shell.setText( title ); //setting title of the window
  setWarningIcon( display ); //adding icon
  setWarningText( message, maxTextWidth ); //adding text
  setHelpLink( display, helpLink, maxTextWidth, environment ); //adding link
  setCloseButton(); //adding button

  shell.setSize( shell.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ) );
  Rectangle screenSize = display.getPrimaryMonitor().getBounds();
  shell.setLocation( ( screenSize.width - shell.getBounds().width ) / 2, ( screenSize.height - shell.getBounds().height ) / 2 );
  closeButton.setFocus();
  shell.open();
  while ( !shell.isDisposed() ) {
    if ( !display.readAndDispatch() ) {
      display.sleep();
    }
  }
}
 
Example 12
Source File: Regression_117865_svg.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static void main( String args[] )
{
	display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setLocation( display.getClientArea( ).width / 2 - 110, display
			.getClientArea( ).height / 2 - 40 );
	shell.setSize( 620, 450 );
	shell.setLayout( new GridLayout( ) );

	Regression_117865_svg siv = new Regression_117865_svg( shell, SWT.NONE );
	GridData gd = new GridData( GridData.BEGINNING );
	gd.widthHint = 1;
	gd.heightHint = 1;
	siv.setLayoutData( gd );

	try
	{
		RunTimeContext rtc = new RunTimeContext( );
		rtc.setULocale( ULocale.getDefault( ) );

		IDeviceRenderer idr = null;
		Chart cm = toggleVisibility_PieChart( );

		idr = PluginSettings.instance( ).getDevice( "dv.SVG" ); //$NON-NLS-1$
		Generator gr = Generator.instance( );
		GeneratedChartState gcs = null;
		Bounds bo = BoundsImpl.create( 0, 0, 450, 300 );
		gcs = gr.build( idr.getDisplayServer( ), cm, bo, null, rtc, null );

		idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, "c:/test.svg" ); //$NON-NLS-1$
		idr.setProperty(
				IDeviceRenderer.UPDATE_NOTIFIER,
				new EmptyUpdateNotifier( cm, gcs.getChartModel( ) ) );

		gr.render( idr, gcs );
	}

	catch ( ChartException ce )
	{
		ce.printStackTrace( );
	}

	Browser br = new Browser( shell, SWT.NONE );
	br.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	br.setUrl( "c:/test.svg" );//$NON-NLS-1$		
	br.setVisible( true );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 13
Source File: Regression_145712_svg.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static void main( String args[] )
{
	display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setLocation( display.getClientArea( ).width / 2 - 110, display
			.getClientArea( ).height / 2 - 40 );
	shell.setSize( 620, 450 );
	shell.setLayout( new GridLayout( ) );

	Regression_117865_svg siv = new Regression_117865_svg( shell, SWT.NONE );
	GridData gd = new GridData( GridData.BEGINNING );
	gd.widthHint = 1;
	gd.heightHint = 1;
	siv.setLayoutData( gd );

	try
	{
		RunTimeContext rtc = new RunTimeContext( );
		rtc.setULocale( ULocale.getDefault( ) );

		IDeviceRenderer idr = null;
		Chart cm = showTooltip_AreaChart( );

		idr = PluginSettings.instance( ).getDevice( "dv.SVG" ); //$NON-NLS-1$
		Generator gr = Generator.instance( );
		GeneratedChartState gcs = null;
		Bounds bo = BoundsImpl.create( 0, 0, 450, 300 );
		gcs = gr.build( idr.getDisplayServer( ), cm, bo, null, rtc, null );

		idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, "c:/test.svg" ); //$NON-NLS-1$
		idr.setProperty(
				IDeviceRenderer.UPDATE_NOTIFIER,
				new EmptyUpdateNotifier( cm, gcs.getChartModel( ) ) );

		gr.render( idr, gcs );
	}

	catch ( ChartException ce )
	{
		ce.printStackTrace( );
	}

	Browser br = new Browser( shell, SWT.NONE );
	br.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	br.setUrl( "c:/test.svg" );//$NON-NLS-1$		
	br.setVisible( true );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 14
Source File: VertexWindow.java    From ldparteditor with MIT License 4 votes vote down vote up
/**
 * Places the vertex window on the 3D editor
 */
public static void placeVertexWindow() {
    final Composite3D lastHoveredC3d = DatFile.getLastHoveredComposite();
    if (lastHoveredC3d == null || Display.getDefault().getActiveShell() == null) return;

    final VertexWindow vertexWindow = Editor3DWindow.getWindow().getVertexWindow();
    final DatFile df = lastHoveredC3d.getLockableDatFileReference();
    final Set<Vertex> selectedVertices = df.getVertexManager().getSelectedVertices();
    final boolean singleVertexSelected = !df.isReadOnly() && selectedVertices.size() == 1;
    final boolean addingSomething = Editor3DWindow.getWindow().isAddingSomething();

    final boolean windowShouldBeDisplayed = singleVertexSelected && !addingSomething;

    Vertex newSelectedVertex = new Vertex(0,0,0);

    if (singleVertexSelected) {
        try {
            newSelectedVertex = selectedVertices.iterator().next();
        } catch (NoSuchElementException consumed) {}
    }

    if (windowShouldBeDisplayed && vertexWindow.getShell() == null) {
        vertexWindow.run();
        lastHoveredC3d.setFocus();
        Editor3DWindow.getWindow().getShell().setActive();
    } else if (!windowShouldBeDisplayed && vertexWindow.getShell() != null) {
        vertexWindow.close();
    }

    final Shell vertexWindowShell = vertexWindow.getShell();
    if (vertexWindowShell == null || vertexWindowShell.isDisposed()) {
        return;
    }

    if (singleVertexSelected) {
        vertexWindow.updateVertex(newSelectedVertex);
    }

    final Point old = vertexWindowShell.getLocation();
    final Point a = ShellHelper.absolutePositionOnShell(lastHoveredC3d);
    final Point s = vertexWindowShell.getSize();

    final int xPos = a.x - s.x + lastHoveredC3d.getSize().x;
    final int yPos = a.y;

    if (old.x != xPos || old.y != yPos) {
        vertexWindowShell.setLocation(xPos, yPos);
    }
}
 
Example 15
Source File: NewJointDataSetAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void run( )
{
	if ( Policy.TRACING_ACTIONS )
	{
		System.out.println( "New joint data set action >> Run ..." ); //$NON-NLS-1$
	}
	if (SessionHandleAdapter.getInstance( ).getReportDesignHandle( ) == null)
	{
		return;
	}
	// Get the list of data sets before inserting a new Data Set
	List existingDataSets = getDataSets( );

	// Check if data sets are available
	if ( existingDataSets.isEmpty( ) )
	{
		MessageDialog.openError( PlatformUI.getWorkbench( )
				.getDisplay( )
				.getActiveShell( ),
				Messages.getString( "JointDataSetPage.error.nodataset.title" ), Messages.getString( "JointDataSetPage.error.nodataset.title" ) );//$NON-NLS-1$ //$NON-NLS-2$
		notifyResult( false );
	}
	else
	{
		if (SessionHandleAdapter.getInstance( ).getReportDesignHandle( ) == null)
		{
			return;
		}
		HandleAdapterFactory.getInstance( )
				.getReportDesignHandleAdapter( )
				.getModuleHandle( )
				.getCommandStack( )
				.startPersistentTrans( Messages.getString( "dataset.join.new" ) ); //$NON-NLS-1$

		JointDataSetWizard wizard = new JointDataSetWizard( );
		wizard.setWindowTitle( Messages.getString( "dataset.join.new" ) );//$NON-NLS-1$
		WizardDialog dialog = new BaseWizardDialog( PlatformUI.getWorkbench( )
				.getDisplay( )
				.getActiveShell( ), wizard ){
			
			protected void configureShell( Shell newShell )
			{
				super.configureShell( newShell );
				newShell.setSize( 750, 650 );
				Rectangle rect = Display.getDefault( ).getBounds( );
				newShell.setLocation( ( rect.width - 750 ) / 2,
						( rect.height - 650 ) / 2 );
			}
			
		};

		if ( dialog.open( ) == WizardDialog.OK )
		{
			// Get the list of data sets after inserting a new Data Set
			List newDataSets = getDataSets( );

			editDataSet( existingDataSets, newDataSets );

			HandleAdapterFactory.getInstance( )
					.getReportDesignHandleAdapter( )
					.getModuleHandle( )
					.getCommandStack( )
					.commit( );

			ReportRequest request = new ReportRequest( ReportRequest.CREATE_ELEMENT );
			List selectionObjects = new ArrayList( );
			selectionObjects.add( dataSetHandle );
			request.setSelectionObject( selectionObjects );
			SessionHandleAdapter.getInstance( )
					.getMediator( )
					.notifyRequest( request );

			notifyResult( true );
		}

		else
		{
			HandleAdapterFactory.getInstance( )
					.getReportDesignHandleAdapter( )
					.getModuleHandle( )
					.getCommandStack( )
					.rollback( );
			notifyResult( false );
		}
	}
}
 
Example 16
Source File: Regression_132620_svg.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static void main( String args[] )
{
	display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setLocation( display.getClientArea( ).width / 2 - 110, display
			.getClientArea( ).height / 2 - 40 );
	shell.setSize( 620, 450 );
	shell.setLayout( new GridLayout( ) );

	Regression_132620_svg siv = new Regression_132620_svg( shell, SWT.NONE );
	GridData gd = new GridData( GridData.BEGINNING );
	gd.widthHint = 1;
	gd.heightHint = 1;
	siv.setLayoutData( gd );

	try
	{
		RunTimeContext rtc = new RunTimeContext( );
		rtc.setULocale( ULocale.getDefault( ) );

		IDeviceRenderer idr = null;
		Chart cm = toggleVisibility_BarChart( );

		idr = PluginSettings.instance( ).getDevice( "dv.SVG" ); //$NON-NLS-1$
		Generator gr = Generator.instance( );
		GeneratedChartState gcs = null;
		Bounds bo = BoundsImpl.create( 0, 0, 450, 300 );
		gcs = gr.build( idr.getDisplayServer( ), cm, bo, null, rtc, null );

		idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, "c:/test.svg" ); //$NON-NLS-1$
		idr.setProperty(
				IDeviceRenderer.UPDATE_NOTIFIER,
				new EmptyUpdateNotifier( cm, gcs.getChartModel( ) ) );

		gr.render( idr, gcs );
	}

	catch ( ChartException ce )
	{
		ce.printStackTrace( );
	}

	Browser br = new Browser( shell, SWT.NONE );
	br.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	br.setUrl( "c:/test.svg" );//$NON-NLS-1$		
	br.setVisible( true );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 17
Source File: Regression_128590_svg.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static void main( String args[] )
{
	display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setLocation( display.getClientArea( ).width / 2 - 110, display
			.getClientArea( ).height / 2 - 40 );
	shell.setSize( 620, 450 );
	shell.setLayout( new GridLayout( ) );

	Regression_128590_svg siv = new Regression_128590_svg( shell, SWT.NONE );
	GridData gd = new GridData( GridData.BEGINNING );
	gd.widthHint = 1;
	gd.heightHint = 1;
	siv.setLayoutData( gd );

	try
	{
		RunTimeContext rtc = new RunTimeContext( );
		rtc.setULocale( ULocale.getDefault( ) );

		IDeviceRenderer idr = null;
		Chart cm = showTooltip_BarChart( );

		idr = PluginSettings.instance( ).getDevice( "dv.SVG" ); //$NON-NLS-1$
		Generator gr = Generator.instance( );
		GeneratedChartState gcs = null;
		Bounds bo = BoundsImpl.create( 0, 0, 450, 300 );
		gcs = gr.build( idr.getDisplayServer( ), cm, bo, null, rtc, null );

		idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, "c:/test.svg" ); //$NON-NLS-1$
		idr.setProperty(
				IDeviceRenderer.UPDATE_NOTIFIER,
				new EmptyUpdateNotifier( cm, gcs.getChartModel( ) ) );

		gr.render( idr, gcs );
	}
	catch ( ChartException ce )
	{
		ce.printStackTrace( );
	}

	Browser br = new Browser( shell, SWT.NONE );
	br.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	br.setUrl( "c:/test.svg" );//$NON-NLS-1$		
	br.setVisible( true );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 18
Source File: ConfigureExtensionModulesHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
	
	Shell shell = new Shell();
	shell.setText("Extension Module Configurations");

	
	shell.setSize(500, 400);
	
	Monitor primary = shell.getDisplay().getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();
    
    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;
    
    shell.setLocation(x, y);
	
	// Set layout for shell
	GridLayout layout = new GridLayout();
	shell.setLayout(layout);
	
	// Create a composite to hold the children
	Composite composite = new Composite(shell, SWT.NONE);
	final ModuleTableViewer moduleTableViewer = new ModuleTableViewer(composite);
	if (moduleTableViewer.isPlatformFound()) {
		moduleTableViewer.getControl().addDisposeListener(new DisposeListener() {

			@Override
			public void widgetDisposed(DisposeEvent e) {
				moduleTableViewer.dispose();
			}
		});
		
		// Ask the shell to display its content
		shell.open();
		moduleTableViewer.run(shell);
	}
	else {
		MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
		dialog.setText("Platform extension not found");
		dialog.setMessage("The platform extension was not found in the workspace. Please import it and try again.");
		dialog.open();
	}
	
	return null;
}
 
Example 19
Source File: TSVExtendedHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	
	Shell shell = new Shell();
	shell.setText("Extended TSV Analysis");
	shell.setSize(300, 400);
	
	Monitor primary = shell.getDisplay().getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();
    
    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;
    
    shell.setLocation(x, y);
	
	// Set layout for shell
	GridLayout layout = new GridLayout();
	shell.setLayout(layout);
	
	// Create a composite to hold the children
	Composite composite = new Composite(shell, SWT.NONE);
	final ModuleTableViewer moduleTableViewer = new ModuleTableViewer(composite);
	if (moduleTableViewer.isPlatformFound()) {
		moduleTableViewer.getControl().addDisposeListener(new DisposeListener() {

			@Override
			public void widgetDisposed(DisposeEvent e) {
				moduleTableViewer.dispose();
			}
		});
		
		// Ask the shell to display its content
		shell.open();
		moduleTableViewer.run(shell);
	}
	else {
		MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
		dialog.setText("Platform extension not found");
		dialog.setMessage("The platform extension was not found in the workspace. Please import it and try again.");
		dialog.open();
	}
	
}
 
Example 20
Source File: BreadcrumbItemDropDown.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Set the size of the given shell such that more content can be shown. The shell size does not
 * exceed a user-configurable maximum.
 *
 * @param shell the shell to resize
 */
private void resizeShell(final Shell shell) {
	Point size= shell.getSize();
	int currentWidth= size.x;
	int currentHeight= size.y;

	int maxHeight= getMaxHeight();
	
	if (currentHeight >= maxHeight && currentWidth >= DROP_DOWN_MAX_WIDTH)
		return;

	Point preferedSize= shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);

	int newWidth;
	if (currentWidth >= DROP_DOWN_MAX_WIDTH) {
		newWidth= currentWidth;
	} else {
		newWidth= Math.min(Math.max(preferedSize.x, currentWidth), DROP_DOWN_MAX_WIDTH);
	}
	int newHeight;
	if (currentHeight >= maxHeight) {
		newHeight= currentHeight;
	} else {
		newHeight= Math.min(Math.max(preferedSize.y, currentHeight), maxHeight);
	}

	if (newHeight != currentHeight || newWidth != currentWidth) {
		shell.setRedraw(false);
		try {
			isResizingProgrammatically= true;
			shell.setSize(newWidth, newHeight);
			if (!isLTR()) {
				Point location= shell.getLocation();
				shell.setLocation(location.x - (newWidth - currentWidth), location.y);
			}
		} finally {
			isResizingProgrammatically= false;
			shell.setRedraw(true);
		}
	}
}