1 /*******************************************************************************
2 * Copyright (c) 2018 Association for Decentralized Information Management
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.modeling.ui.diagramEditor.dnd;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.dialogs.IDialogSettings;
17 import org.eclipse.jface.layout.GridDataFactory;
18 import org.eclipse.jface.text.Document;
19 import org.eclipse.mylyn.wikitext.markdown.MarkdownLanguage;
20 import org.eclipse.mylyn.wikitext.ui.viewer.MarkupViewer;
21 import org.eclipse.mylyn.wikitext.ui.viewer.MarkupViewerConfiguration;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Shell;
26 import org.eclipse.swt.widgets.Text;
27 import org.simantics.modeling.ui.Activator;
30 * @author Tuukka Lehtonen
33 class MarkupDialog extends Dialog {
36 private String topText;
37 private String message;
38 private int dialogIconType;
39 private int viewerStyle;
40 private MarkupViewer viewer;
42 private IDialogSettings dialogBoundsSettings;
44 protected MarkupDialog(Shell parentShell, String dialogId, String title, String topText, String message, int dialogIconType, int viewerStyle) {
47 this.topText = topText;
48 this.message = message;
49 this.dialogIconType = dialogIconType;
50 this.viewerStyle = viewerStyle;
51 setShellStyle(getShellStyle() | SWT.RESIZE);
53 IDialogSettings settings = Activator.getDefault().getDialogSettings();
54 dialogBoundsSettings = settings.getSection(dialogId);
55 if (dialogBoundsSettings == null)
56 dialogBoundsSettings = settings.addNewSection(dialogId);
60 protected IDialogSettings getDialogBoundsSettings() {
61 return dialogBoundsSettings;
65 protected void configureShell(Shell newShell) {
66 super.configureShell(newShell);
67 newShell.setText(title);
68 newShell.setImage(newShell.getDisplay().getSystemImage(dialogIconType));
72 protected Control createDialogArea(Composite parent) {
73 Composite composite = (Composite) super.createDialogArea(parent);
75 Text text = new Text(composite, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
76 text.setEditable(false);
77 text.setText(topText);
78 GridDataFactory.fillDefaults()
80 .hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT)
83 viewer = new MarkupViewer(composite, null, viewerStyle);
84 viewer.setMarkupLanguage(new MarkdownLanguage());
85 viewer.setEditable(false);
86 MarkupViewerConfiguration configuration = new MarkupViewerConfiguration(viewer, Activator.getDefault().getPreferenceStore());
87 viewer.configure(configuration);
88 viewer.setDocument(new Document(message));
89 GridDataFactory.fillDefaults()
91 .hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT)
92 .applyTo(viewer.getControl());
97 protected void createButtonsForButtonBar(Composite parent) {
98 createButton(parent, IDialogConstants.PROCEED_ID, IDialogConstants.PROCEED_LABEL, true);
99 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
103 protected void buttonPressed(int buttonId) {
104 if (IDialogConstants.PROCEED_ID == buttonId) {
106 } else if (IDialogConstants.CANCEL_ID == buttonId) {
111 public static int open(Shell parent, String dialogId, String title, String topText, String message, int dialogIconType, int dialogStyle, int sourceViewerStyle) {
112 MarkupDialog dialog = new MarkupDialog(parent, dialogId, title, topText, message, dialogIconType, sourceViewerStyle);
113 dialogStyle &= SWT.SHEET;
114 dialog.setShellStyle(dialog.getShellStyle() | dialogStyle);
115 return dialog.open();