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

The following examples show how to use org.eclipse.swt.widgets.Shell#close() . 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: ShowDetailDialog.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void openWithWaitShell ( final Shell parentShell, final String detailViewId, final Map<String, String> parameters )
{

    final Shell waitShell = new Shell ( parentShell, SWT.PRIMARY_MODAL | SWT.BORDER );
    waitShell.setLayout ( new FillLayout () );
    final Label label = new Label ( waitShell, SWT.NONE );
    label.setText ( "Opening view…" );

    waitShell.pack ();
    waitShell.open ();

    // make sure the text is visible
    waitShell.getDisplay ().update ();

    try
    {
        open ( parentShell, detailViewId, parameters );
    }
    finally
    {
        // close the wait shell
        waitShell.close ();
    }

}
 
Example 2
Source File: RCPTestSetupHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Close all open windows, editors, perspectives. Open and reset default perspective.
 */
private static void resetWorkbench() {
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        
        Shell activeShell = Display.getCurrent().getActiveShell();
        if (activeShell != null && activeShell != workbenchWindow.getShell()) {
            activeShell.close();
        }
        
        page.closeAllEditors(false);
        page.resetPerspective();
        
        String defaultPerspectiveId = workbench.getPerspectiveRegistry().getDefaultPerspective();
        workbench.showPerspective(defaultPerspectiveId, workbenchWindow);
        page.resetPerspective();
        
        page.showView("org.eclipse.ui.internal.introview");
    } catch (WorkbenchException e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: SquareButtonIntegTest.java    From swt-bling with MIT License 6 votes vote down vote up
@Test
public void testToggleable() {
  Display display = Display.getDefault();
  Shell shell = new Shell(display);

  shell.open();

  SquareButton button = new SquareButton(shell, SWT.CENTER);
  button.setText(buttonText);
  button.setToggleable(true);

  Assert.assertTrue(button.isToggleable());

  button.setToggled(true);
  Assert.assertTrue(button.isToggled());


  button.setToggled(false);
  Assert.assertFalse(button.isToggled());

  shell.close();
  display.dispose();
}
 
Example 4
Source File: TestRunConfiguration.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
@After
public void testErrorPopup() {
	Shell errorPopup = getErrorPopup();
	if (errorPopup != null) {
		errorPopup.close();
	}
}
 
Example 5
Source File: AggregateEditorComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close Aggregate editor window.
 * @param shell
 */
private void closeAggregateEditor( Shell shell )
{
	if ( shell != null && !shell.isDisposed( ) )
	{
		shell.close( );
	}
}
 
Example 6
Source File: SquareButtonIntegTest.java    From swt-bling with MIT License 5 votes vote down vote up
@Test
public void testTextSetting() {
  Display display = Display.getDefault();
  Shell shell = new Shell(display);

  shell.open();

  SquareButton button = new SquareButton(shell, SWT.CENTER);
  button.setText(buttonText);

  Assert.assertEquals(buttonText, button.getText());

  shell.close();
  display.dispose();
}
 
Example 7
Source File: BreadcrumbItemDropDown.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public BreadcrumbItemDropDown(BreadcrumbItem parent, Composite composite) {
  fParent = parent;
  fParentComposite = composite;
  fMenuIsShown = false;
  fEnabled = true;

  fToolBar = new ToolBar(composite, SWT.FLAT);
  fToolBar.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
  // SWTUtil.setAccessibilityText(
  // fToolBar,
  // BreadcrumbMessages.BreadcrumbItemDropDown_showDropDownMenu_action_toolTip);
  ToolBarManager manager = new ToolBarManager(fToolBar);

  final Action showDropDownMenuAction = new Action(null, SWT.NONE) {
    public void run() {
      Shell shell = fParent.getDropDownShell();
      if (shell != null)
        return;

      shell = fParent.getViewer().getDropDownShell();
      if (shell != null)
        shell.close();

      showMenu();

      fShell.setFocus();
    }
  };

  showDropDownMenuAction.setImageDescriptor(new AccessibelArrowImage(isLTR()));
  // showDropDownMenuAction.setToolTipText(BreadcrumbMessages.BreadcrumbItemDropDown_showDropDownMenu_action_toolTip);
  manager.add(showDropDownMenuAction);

  manager.update(true);
  if (IS_MAC_WORKAROUND) {
    manager.getControl().addMouseListener(new MouseAdapter() {
      // see also BreadcrumbItemDetails#addElementListener(Control)
      public void mouseDown(MouseEvent e) {
        showDropDownMenuAction.run();
      }
    });
  }
}
 
Example 8
Source File: BreadcrumbItemDropDown.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public BreadcrumbItemDropDown(BreadcrumbItem parent, Composite composite) {
	fParent= parent;
	fParentComposite= composite;
	fMenuIsShown= false;
	fEnabled= true;

	fToolBar= new ToolBar(composite, SWT.FLAT);
	fToolBar.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
	SWTUtil.setAccessibilityText(fToolBar, BreadcrumbMessages.BreadcrumbItemDropDown_showDropDownMenu_action_toolTip);
	ToolBarManager manager= new ToolBarManager(fToolBar);

	final Action showDropDownMenuAction= new Action(null, SWT.NONE) {
		@Override
		public void run() {
			Shell shell= fParent.getDropDownShell();
			if (shell != null)
				return;

			shell= fParent.getViewer().getDropDownShell();
			if (shell != null)
				shell.close();

			showMenu();

			fShell.setFocus();
		}
	};

	showDropDownMenuAction.setImageDescriptor(new AccessibelArrowImage(isLTR()));
	showDropDownMenuAction.setToolTipText(BreadcrumbMessages.BreadcrumbItemDropDown_showDropDownMenu_action_toolTip);
	manager.add(showDropDownMenuAction);

	manager.update(true);
	if (IS_MAC_WORKAROUND) {
		manager.getControl().addMouseListener(new MouseAdapter() {
			// see also BreadcrumbItemDetails#addElementListener(Control)
			@Override
			public void mouseDown(MouseEvent e) {
				showDropDownMenuAction.run();
			}
		});
	}
}
 
Example 9
Source File: BreadcrumbItemDropDown.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public BreadcrumbItemDropDown(BreadcrumbItem parent, Composite composite) {
	fParent= parent;
	fParentComposite= composite;
	fMenuIsShown= false;
	fEnabled= true;

	fToolBar= new ToolBar(composite, SWT.FLAT);
	fToolBar.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
	setAccessibilityText(fToolBar, Messages.getString( "BreadcrumbItemDropDown.showDropDownMenu.action.toolTip") ); //$NON-NLS-1$
	ToolBarManager manager= new ToolBarManager(fToolBar);

	final Action showDropDownMenuAction= new Action(null, SWT.NONE) {
		public void run() {
			Shell shell= fParent.getDropDownShell();
			if (shell != null)
				return;

			shell= fParent.getViewer().getDropDownShell();
			if (shell != null)
				shell.close();

			showMenu();

			fShell.setFocus();
		}
	};

	showDropDownMenuAction.setImageDescriptor(new AccessibelArrowImage(isLTR()));
	showDropDownMenuAction.setToolTipText(Messages.getString( "BreadcrumbItemDropDown.showDropDownMenu.action.toolTip")); //$NON-NLS-1$
	manager.add(showDropDownMenuAction);

	manager.update(true);
	if (IS_MAC_WORKAROUND) {
		manager.getControl().addMouseListener(new MouseAdapter() {
			// see also BreadcrumbItemDetails#addElementListener(Control)
			public void mouseDown(MouseEvent e) {
				showDropDownMenuAction.run();
			}
		});
	}
}
 
Example 10
Source File: CheckboxCellContentProvider.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * If the enabled/disabled checked/unchecked checkbox <code>Image</code>s
 * have not already been created and added to the JFace
 * <code>ImageRegistry</code>, this method generates and registers them.
 * This produces platform-specific images at run-time.
 * 
 * @param display
 *            The <code>Display</code> shared with the underlying
 *            <code>ColumnViewer</code>.
 * @param background
 *            The background of the <code>ColumnViewer</code>'s cells.
 */
private static void registerImages(final Display display, Color background) {

	if (display != null && IMAGES_REGISTERED.compareAndSet(false, true)) {

		// Get the ImageRegistry for JFace images. We will load up images
		// for each combination of checkbox enabled/disabled and
		// checked/unchecked.
		ImageRegistry jfaceImages = JFaceResources.getImageRegistry();

		// Create a temporary shell and checkbox Button to generate
		// platform-specific images of checkboxes.
		Shell shell = new Shell(display, SWT.NO_TRIM);
		Button checkbox = new Button(shell, SWT.CHECK);

		// Set the widget's background to the viewer's cell background.
		checkbox.setBackground(background);

		// Reduce the size of the shell to a square (checkboxes are supposed
		// to be square!!!).
		Point size = checkbox.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		// int width = Math.min(size.x, size.y);
		checkbox.setSize(size);
		// checkbox.setLocation(width - size.x, width - size.y);
		// shell.setSize(width, width);
		shell.setSize(size);

		// Open the shell to enable widget drawing.
		shell.open();

		// Create the enabled/unchecked image.
		jfaceImages.put(ENABLED_UNCHECKED, createImage(checkbox));
		// Create the enabled/checked image.
		checkbox.setSelection(true);
		jfaceImages.put(ENABLED_CHECKED, createImage(checkbox));
		// Create the disabled/checked image.
		checkbox.setEnabled(false);
		jfaceImages.put(DISABLED_CHECKED, createImage(checkbox));
		// Create the disabled/unchecked image.
		checkbox.setSelection(false);
		jfaceImages.put(DISABLED_UNCHECKED, createImage(checkbox));

		// Release any remaining resources.
		// gc.dispose();
		shell.close();
	}

	return;
}
 
Example 11
Source File: EmulatedNativeCheckBoxLabelProvider.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private Image makeShot(Control control, boolean type) {
    /* Hopefully no platform uses exactly this color because we'll make
       it transparent in the image.*/
    Color greenScreen = new Color(control.getDisplay(), 222, 223, 224);

    shell = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            SWT.NO_TRIM | SWT.NO_BACKGROUND);

    // otherwise we have a default gray color
    shell.setBackground(greenScreen);

    Button button = new Button(shell, SWT.CHECK | SWT.NO_BACKGROUND);
    button.setBackground(greenScreen);
    button.setSelection(type);

    // otherwise an image is located in a corner
    button.setLocation(1, 1);
    Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    // otherwise an image is stretched by width
    bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
    bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
    button.setSize(bsize);

    GC gc = new GC(shell);
    Point shellSize = new Point(32, 32);
    shell.setSize(shellSize);
    shell.open();

    Image image = new Image(control.getDisplay(), bsize.x, bsize.y);
    gc.copyArea(image, 0, 0);
    gc.dispose();
    shell.close();

    ImageData imageData = image.getImageData();
    imageData.transparentPixel = imageData.palette.getPixel(greenScreen
            .getRGB());

    Image img = new Image(control.getDisplay(), imageData);
    image.dispose();

    return img;
}