]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/InfoDialog.java
Import/export changes. A load.
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / dialogs / InfoDialog.java
1 /*******************************************************************************
2  * Copyright (c) 2017 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.utils.ui.dialogs;
13
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;
26
27 /**
28  * @author Tuukka Lehtonen
29  * @since 1.28.0
30  */
31 public class InfoDialog extends IconAndMessageDialog {
32
33         private String title;
34         private Text messageText;
35
36         protected InfoDialog(Shell parentShell, String title, String message) {
37                 super(parentShell);
38                 this.title = title;
39                 this.message = message;
40                 setShellStyle(getShellStyle() | SWT.RESIZE);
41         }
42
43         @Override
44         protected Image getImage() {
45                 return getInfoImage();
46         }
47
48         @Override
49         protected void configureShell(Shell newShell) {
50                 super.configureShell(newShell);
51                 newShell.setText(title);
52                 newShell.setImage(newShell.getDisplay().getSystemImage(SWT.ICON_INFORMATION));
53         }
54
55         protected Control createMessageArea(Composite composite) {
56                 // create image
57                 Image image = getImage();
58                 if (image != null) {
59                         imageLabel = new Label(composite, SWT.NULL);
60                         image.setBackground(imageLabel.getBackground());
61                         imageLabel.setImage(image);
62                         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING)
63                         .applyTo(imageLabel);
64                 }
65                 // create message
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);
70                         GridDataFactory
71                         .fillDefaults()
72                         .grab(true, true)
73                         .hint(
74                                         convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
75                                         SWT.DEFAULT).applyTo(messageText);
76                 }
77                 return composite;
78         }
79
80         protected Control createDialogArea(Composite parent) {
81                 Composite composite = new Composite(parent, SWT.NONE);
82
83                 createMessageArea(composite);
84
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);
97
98                 return composite;
99         }
100
101         protected void createButtonsForButtonBar(Composite parent) {
102                 // create OK button by default
103                 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
104                                 true);
105         }
106
107         @Override
108         protected void buttonPressed(int buttonId) {
109                 super.buttonPressed(buttonId);
110         }
111
112         public static boolean open(Shell parent, String title, String message, int style) {
113                 InfoDialog dialog = new InfoDialog(parent, title, message);
114                 style &= SWT.SHEET;
115                 dialog.setShellStyle(dialog.getShellStyle() | style);
116                 return dialog.open() == 0;
117         }
118
119 }