1 /*******************************************************************************
2 * Copyright (c) 2017 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.ui.dialogs;
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.jface.dialogs.IconAndMessageDialog;
16 import org.eclipse.jface.layout.GridDataFactory;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.swt.widgets.Shell;
25 import org.eclipse.swt.widgets.Text;
28 * @author Tuukka Lehtonen
31 public class InfoDialog extends IconAndMessageDialog {
34 private Text messageText;
36 protected InfoDialog(Shell parentShell, String title, String message) {
39 this.message = message;
40 setShellStyle(getShellStyle() | SWT.RESIZE);
44 protected Image getImage() {
45 return getInfoImage();
49 protected void configureShell(Shell newShell) {
50 super.configureShell(newShell);
51 newShell.setText(title);
52 newShell.setImage(newShell.getDisplay().getSystemImage(SWT.ICON_INFORMATION));
55 protected Control createMessageArea(Composite composite) {
57 Image image = getImage();
59 imageLabel = new Label(composite, SWT.NULL);
60 image.setBackground(imageLabel.getBackground());
61 imageLabel.setImage(image);
62 GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING)
66 if (message != null) {
67 messageText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.FLAT | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
68 messageText.setEditable(false);
69 messageText.setText(message);
74 convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
75 SWT.DEFAULT).applyTo(messageText);
80 protected Control createDialogArea(Composite parent) {
81 Composite composite = new Composite(parent, SWT.NONE);
83 createMessageArea(composite);
85 GridLayout layout = new GridLayout();
86 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
87 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
88 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
89 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
90 layout.numColumns = 2;
91 composite.setLayout(layout);
92 GridData childData = new GridData(GridData.FILL_BOTH);
93 childData.horizontalSpan = 2;
94 childData.grabExcessVerticalSpace = true;
95 composite.setLayoutData(childData);
96 applyDialogFont(composite);
101 protected void createButtonsForButtonBar(Composite parent) {
102 // create OK button by default
103 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
108 protected void buttonPressed(int buttonId) {
109 super.buttonPressed(buttonId);
112 public static boolean open(Shell parent, String title, String message, int style) {
113 InfoDialog dialog = new InfoDialog(parent, title, message);
115 dialog.setShellStyle(dialog.getShellStyle() | style);
116 return dialog.open() == 0;