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

The following examples show how to use org.eclipse.swt.widgets.Shell#dispose() . 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: AcfContentAssistProcessorTestBuilder.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Internally compute completion proposals.
 *
 * @param cursorPosition
 *          the position of the cursor in the {@link IXtextDocument}
 * @param xtextDocument
 *          the {@link IXtextDocument}
 * @return a pair of {@link ICompletionProposal}[] and {@link BadLocationException}. If the tail argument is not {@code null}, an exception occurred in the UI
 *         thread.
 */
private Pair<ICompletionProposal[], BadLocationException> internalComputeCompletionProposals(final int cursorPosition, final IXtextDocument xtextDocument) {
  XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
  Shell shell = new Shell();
  try {
    ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
    IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
    String contentType = xtextDocument.getContentType(cursorPosition);
    IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
    if (processor != null) {
      return Tuples.create(processor.computeCompletionProposals(sourceViewer, cursorPosition), null);
    }
    return Tuples.create(new ICompletionProposal[0], null);
  } catch (BadLocationException e) {
    return Tuples.create(new ICompletionProposal[0], e);
  } finally {
    shell.dispose();
  }
}
 
Example 2
Source File: BonitaStudioApplication.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void openErrorDialog(final Display display, final String javaVersion) {
    final Shell shell = new Shell(display);
    try {
        final Version version = Version.parseVersion(ProductVersion.CURRENT_VERSION);
        final String uriWithProductVersion = ONLINE_DOC_REQUIREMENTS + version.getMajor() + "."
                + version.getMinor();
        final URI uri = new URI(uriWithProductVersion);
        final MessageDialogWithLink messageDialog = new MessageDialogWithLink(shell,
                Messages.incompatibleJavaVersionTitle, null, String.format(
                        Messages.incompatibleJavaVersionMessage,
                        org.bonitasoft.studio.common.Messages.bonitaStudioModuleName, javaVersion,
                        "Java 1.8 and Java 11."),
                MessageDialog.ERROR,
                new String[] { IDialogConstants.OK_LABEL },
                0,
                uri);
        messageDialog.open();
    } catch (final URISyntaxException e) {
        BonitaStudioLog.error(e);
    } finally {
        shell.dispose();
    }
}
 
Example 3
Source File: ControlSpaceKeyAdapter.java    From hop with Apache License 2.0 5 votes vote down vote up
private static final void applyChanges( Shell shell, List list, Control control, int position,
                                        IInsertText insertTextInterface ) {
  String selection =
    list.getSelection()[ 0 ].contains( Const.getDeprecatedPrefix() )
      ? list.getSelection()[ 0 ].replace( Const.getDeprecatedPrefix(), "" )
      : list.getSelection()[ 0 ];
  String extra = "${" + selection + "}";
  if ( insertTextInterface != null ) {
    insertTextInterface.insertText( extra, position );
  } else {
    if ( control.isDisposed() ) {
      return;
    }

    if ( list.getSelectionCount() <= 0 ) {
      return;
    }
    if ( control instanceof Text ) {
      ( (Text) control ).insert( extra );
    } else if ( control instanceof CCombo ) {
      CCombo combo = (CCombo) control;
      combo.setText( extra ); // We can't know the location of the cursor yet. All we can do is overwrite.
    } else if ( control instanceof StyledTextComp ) {
      ( (StyledTextComp) control ).insert( extra );
    } else if ( control instanceof StyledText ) {
      ( (StyledText) control ).insert( extra );
    }
  }
  if ( !shell.isDisposed() ) {
    shell.dispose();
  }
  if ( !control.isDisposed() ) {
    control.setData( Boolean.FALSE );
  }
}
 
Example 4
Source File: SubTotalProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public int[] columnWidths( )
{
	Shell shell = new Shell( );
	GC gc = new GC( shell );
	int height = gc.stringExtent( "" ).y;
	gc.dispose( );
	shell.dispose( );

	return new int[]{
			height + (int) ( ( ( (float) height ) / 12 ) * 8 ),
			210,
			120,
			120
	};
}
 
Example 5
Source File: TabbedPropertyTitle.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the height of the title.
 */
public int getHeight( )
{
	Shell shell = new Shell( );
	GC gc = new GC( shell );
	gc.setFont( getFont( ) );
	Point point = gc.textExtent( BLANK );
	point.x++;
	int textOrImageHeight = Math.max( point.x, 16 );
	gc.dispose( );
	shell.dispose( );
	return textOrImageHeight + 8;
}
 
Example 6
Source File: DotProposalProviderDelegator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private ICompletionProposal[] computeCompletionProposals(
		final IXtextDocument xtextDocument, int cursorPosition)
		throws BadLocationException {
	Shell shell = new Shell();
	try {
		return computeCompletionProposals(xtextDocument, cursorPosition,
				shell);
	} finally {
		shell.dispose();
	}
}
 
Example 7
Source File: TabPageGeneratorTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Testcase for test createTabItems() method
 */
public void testCreateTabItems( )
{
	Shell shell = new Shell( );
	TabPageGenerator generator = new TabPageGenerator( );
	generator.createControl( shell, new ArrayList( ) );
	Control control = generator.getControl( );
	if(control instanceof CTabFolder)
	assertEquals( 0, ((CTabFolder)control).getItemCount( ) );
	shell.dispose( );
}
 
Example 8
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ContentAssistProcessorTestBuilder applyProposal(ICompletionProposal proposal, int position, IXtextDocument document)
		throws Exception {
	Shell shell = new Shell();
	try {
		XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
		ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
		return appendAndApplyProposal(proposal, sourceViewer, model, position);
	} finally {
		shell.dispose();
	}
}
 
Example 9
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Must run on UI thread
 * 
 * @return
 */
private static boolean test( )
{
	if ( !Constants.OS_WIN32.equalsIgnoreCase( Platform.getOS( ) )
			&& !Constants.OS_LINUX.equalsIgnoreCase( Platform.getOS( ) ) )
	{
		return false;
	}
	if ( !embeddedBrowserTested )
	{
		embeddedBrowserTested = true;
		Shell sh = new Shell( );
		try
		{
			new Browser( sh, SWT.NONE );
			embeddedBrowserAvailable = true;
		}
		catch ( SWTError se )
		{
			if ( se.code == SWT.ERROR_NO_HANDLES )
			{
				// Browser not implemented
				embeddedBrowserAvailable = false;
			}
		}
		catch ( Exception e )
		{
			// Browser not implemented
		}
		if ( sh != null && !sh.isDisposed( ) )
		{
			sh.dispose( );
		}
	}
	return embeddedBrowserAvailable;
}
 
Example 10
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public ContentAssistProcessorTestBuilder applyProposal(int position, String proposalString) throws Exception {
	IXtextDocument document = getDocument(getModel());
	Shell shell = new Shell();
	try {
		ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
		ICompletionProposal proposal = findProposal(proposalString, proposals);
		return applyProposal(proposal, position, document);
	} finally {
		shell.dispose();
	}
}
 
Example 11
Source File: AbstractWidgetTest.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected void runTestWithShell() {
	Shell shell = new Shell(Display.getDefault());
	try {

		doRunTest(shell);
	
	} finally {
		shell.dispose();
	}
}
 
Example 12
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public ContentAssistProcessorTestBuilder appendAndApplyProposal(String model, int position, String proposalString) throws Exception {
	IXtextDocument document = getDocument(getModel());
	Shell shell = new Shell();
	try {
		XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
		ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
		ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
		ICompletionProposal proposal = findProposal(proposalString, proposals);
		return appendAndApplyProposal(proposal, sourceViewer, model, position);
	} finally {
		shell.dispose();
	}
}
 
Example 13
Source File: ModuleTableViewer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
public void close() {
	Shell shell = table.getShell();

	if (shell != null && !shell.isDisposed())
		shell.dispose();
}
 
Example 14
Source File: AbstractStyleEditorDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
protected void doFormClear(Shell shell) {
	shell.dispose();
}
 
Example 15
Source File: ColumnRenameDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void doFormOK(Shell shell) {
	renamedColumnLabel = columnLabelPanel.getNewValue();
	shell.dispose();
}
 
Example 16
Source File: ComboBoxColorCellEditor.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected Object openDialogBox( Control cellEditorWindow )
{
	Shell shell = new Shell( Display.getCurrent( ), SWT.SHELL_TRIM );
	shell.setLocation( cellEditorWindow.toDisplay( 0, 0 ).x
			+ cellEditorWindow.getBounds( ).width,
			cellEditorWindow.toDisplay( 0, 0 ).y
					- cellEditorWindow.getBounds( ).height );
	ColorDialog dialog = new ColorDialog( shell, SWT.APPLICATION_MODAL );
	RGB[] rgbs = ReportPlugin.getDefault( ).getCustomColorsPreference( );
	if ( rgbs != null )
	{
		dialog.setRGBs( rgbs );
	}
	Object value = getValue( );

	try
	{
		int color;

		if ( value instanceof String )
		{
			color = ColorUtil.parseColor( (String) value );
		}
		else
		{
			color = ( (Integer) value ).intValue( );
		}

		dialog.setRGB( DEUtil.getRGBValue( color ) );

	}
	catch ( Exception e )
	{
		// ignore.
	}

	value = dialog.open( );
	ReportPlugin.getDefault( )
			.setCustomColorsPreference( dialog.getRGBs( ) );
	if ( value != null && dialog.getRGB( ) != null )
	{
		deactivate( );
		return ColorUtil.format( ColorUtil.formRGB( dialog.getRGB( ).red,
				dialog.getRGB( ).green,
				dialog.getRGB( ).blue ), ColorUtil.HTML_FORMAT );
	}
	comboBox.setFocus( );
	shell.dispose( );
	return value;
}
 
Example 17
Source File: ColumnStyleEditorDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void doFormClear(Shell shell) {
	this.newColumnCellStyle = null;
	shell.dispose();
}
 
Example 18
Source File: AbstractStyleEditorDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
protected void doFormClear(Shell shell) {
	shell.dispose();
}
 
Example 19
Source File: AbstractStyleEditorDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
protected void doFormCancel(Shell shell) {
	cancelPressed = true;
	shell.dispose();
}
 
Example 20
Source File: ColumnStyleEditorDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void doFormClear(Shell shell) {
	this.newColumnCellStyle = null;
	shell.dispose();
}