List of usage examples for org.eclipse.jface.dialogs IconAndMessageDialog IconAndMessageDialog
public IconAndMessageDialog(Shell parentShell)
From source file:com.google.gapid.views.ErrorDialog.java
License:Apache License
public static void showErrorDialog(Shell shell, String text, String detailString) { new IconAndMessageDialog(shell) { private Group details; @Override//from w w w . j av a 2 s . c o m protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText("Error"); } @Override protected boolean isResizable() { return true; } @Override protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); ((GridLayout) container.getLayout()).numColumns = 2; createMessageArea(container); String msg = String.format(Messages.ERROR_MESSAGE, text); withLayoutData(createTextbox(container, SWT.WRAP | SWT.READ_ONLY, msg), withSizeHints(new GridData(SWT.FILL, SWT.CENTER, true, false), getWidthHint(), SWT.DEFAULT)) .setBackground(container.getBackground()); if (detailString != null) { ExpandBar bar = withLayoutData(new ExpandBar(container, SWT.NONE), withSpans(new GridData(SWT.FILL, SWT.TOP, true, false), 2, 1)); new ExpandItem(bar, SWT.NONE, 0).setText("Details..."); bar.addListener(SWT.Expand, e -> { createDetails(container); Point curr = getShell().getSize(); Point want = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); if (want.y > curr.y) { getShell().setSize( new Point(curr.x, curr.y + Math.min(MAX_DETAILS_SIZE, want.y - curr.y))); } else { details.requestLayout(); } }); bar.addListener(SWT.Collapse, e -> { Point curr = getShell().getSize(); if (details != null) { details.dispose(); details = null; } Point want = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); if (want.y < curr.y) { getShell().setSize(new Point(curr.x, want.y)); } }); } return container; } private int getWidthHint() { return convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); } private void createDetails(Composite container) { details = createGroup(container, ""); GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(details); Composite inner = createComposite(details, new GridLayout(1, false)); withLayoutData(createTextbox(inner, DETAILS_STYLE, detailString), new GridData(SWT.FILL, SWT.FILL, true, true)); withLayoutData(createLink(inner, "<a>File a bug</a> on GitHub", e -> { Program.launch(getFileBugUrl()); }), new GridData(SWT.RIGHT, SWT.BOTTOM, false, false)); withLayoutData(createLink(inner, "<a>Show logs</a> directory", e -> { AboutDialog.showLogDir(); }), new GridData(SWT.RIGHT, SWT.BOTTOM, false, false)); } private String getFileBugUrl() { Escaper esc = UrlEscapers.urlFormParameterEscaper(); return String.format(FILE_BUG_URL, esc.escape(text), esc.escape(Messages.BUG_BODY)); } @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true).setFocus(); } @Override protected Image getImage() { return getErrorImage(); } }.open(); }