X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fdialogs%2FInfoDialog.java;fp=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fdialogs%2FInfoDialog.java;h=53a0957d95d7e2fc67452934c316fd4b9e11e33d;hb=9acebe9584f8f2a78f0322b6e0e24438e7ceb984;hp=0000000000000000000000000000000000000000;hpb=081bf7e08a67c0af23c5846e163be39bb19f12cb;p=simantics%2Fplatform.git 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 index 000000000..53a0957d9 --- /dev/null +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/InfoDialog.java @@ -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