下面列出了org.eclipse.swt.widgets.Shell#dispose ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
}
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();
}
}
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 );
}
}
/**
* @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;
}
private ICompletionProposal[] computeCompletionProposals(
final IXtextDocument xtextDocument, int cursorPosition)
throws BadLocationException {
Shell shell = new Shell();
try {
return computeCompletionProposals(xtextDocument, cursorPosition,
shell);
} finally {
shell.dispose();
}
}
/**
* 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( );
}
/**
* 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;
}
protected void runTestWithShell() {
Shell shell = new Shell(Display.getDefault());
try {
doRunTest(shell);
} finally {
shell.dispose();
}
}
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();
}
}
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();
}
}
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();
}
}
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
};
}
@Override
protected void doFormClear(Shell shell) {
this.newColumnCellStyle = null;
shell.dispose();
}
protected void doFormCancel(Shell shell) {
cancelPressed = true;
shell.dispose();
}
protected void doFormClear(Shell shell) {
shell.dispose();
}
@Override
protected void doFormClear(Shell shell) {
this.newColumnCellStyle = null;
shell.dispose();
}
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;
}
@Override
protected void doFormOK(Shell shell) {
renamedColumnLabel = columnLabelPanel.getNewValue();
shell.dispose();
}
protected void doFormClear(Shell shell) {
shell.dispose();
}
public void close() {
Shell shell = table.getShell();
if (shell != null && !shell.isDisposed())
shell.dispose();
}