]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/InfoDialog.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/InfoDialog.java
new file mode 100644 (file)
index 0000000..53a0957
--- /dev/null
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.utils.ui.dialogs;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IconAndMessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.28.0
+ */
+public class InfoDialog extends IconAndMessageDialog {
+
+       private String title;
+       private Text messageText;
+
+       protected InfoDialog(Shell parentShell, String title, String message) {
+               super(parentShell);
+               this.title = title;
+               this.message = message;
+               setShellStyle(getShellStyle() | SWT.RESIZE);
+       }
+
+       @Override
+       protected Image getImage() {
+               return getInfoImage();
+       }
+
+       @Override
+       protected void configureShell(Shell newShell) {
+               super.configureShell(newShell);
+               newShell.setText(title);
+               newShell.setImage(newShell.getDisplay().getSystemImage(SWT.ICON_INFORMATION));
+       }
+
+       protected Control createMessageArea(Composite composite) {
+               // create image
+               Image image = getImage();
+               if (image != null) {
+                       imageLabel = new Label(composite, SWT.NULL);
+                       image.setBackground(imageLabel.getBackground());
+                       imageLabel.setImage(image);
+                       GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING)
+                       .applyTo(imageLabel);
+               }
+               // create message
+               if (message != null) {
+                       messageText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.FLAT | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
+                       messageText.setEditable(false);
+                       messageText.setText(message);
+                       GridDataFactory
+                       .fillDefaults()
+                       .grab(true, true)
+                       .hint(
+                                       convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
+                                       SWT.DEFAULT).applyTo(messageText);
+               }
+               return composite;
+       }
+
+       protected Control createDialogArea(Composite parent) {
+               Composite composite = new Composite(parent, SWT.NONE);
+
+               createMessageArea(composite);
+
+               GridLayout layout = new GridLayout();
+               layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+               layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+               layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+               layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+               layout.numColumns = 2;
+               composite.setLayout(layout);
+               GridData childData = new GridData(GridData.FILL_BOTH);
+               childData.horizontalSpan = 2;
+               childData.grabExcessVerticalSpace = true;
+               composite.setLayoutData(childData);
+               applyDialogFont(composite);
+
+               return composite;
+       }
+
+       protected void createButtonsForButtonBar(Composite parent) {
+               // create OK button by default
+               createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
+                               true);
+       }
+
+       @Override
+       protected void buttonPressed(int buttonId) {
+               super.buttonPressed(buttonId);
+       }
+
+       public static boolean open(Shell parent, String title, String message, int style) {
+               InfoDialog dialog = new InfoDialog(parent, title, message);
+               style &= SWT.SHEET;
+               dialog.setShellStyle(dialog.getShellStyle() | style);
+               return dialog.open() == 0;
+       }
+
+}
\ No newline at end of file