Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f955bf80ae801bc20e2c050c1e790ca44e897e2a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*****************************************************************************
 * Copyright (c) 2010 ATOS ORIGIN.
 *
 * 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:
 *  Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.infra.widgets.toolbox.notification.utils;

import org.eclipse.papyrus.infra.widgets.toolbox.notification.ICompositeCreator;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.PapyrusToolkit;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.Type;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.IContext;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
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.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.forms.widgets.FormToolkit;


public class PapyrusControlsFactory {

	/**
	 * Create a composite according to the type
	 *
	 * @param shell
	 *            , the shell of the element
	 * @param toolkit
	 *            , the toolkit used
	 * @param parent
	 *            , the parent containing the composite created
	 * @param type
	 *            , the type to create
	 * @param image
	 *            , the image to associate
	 * @param message
	 *            , the message to display
	 * @param useHTML
	 *            , if the composite use html
	 * @return the composite created
	 */
	public static Composite createCompositeWithType(Shell shell, FormToolkit toolkit, Composite parent, Type type, Image image, String message, boolean useHTML) {
		return createCompositeWithType(shell, toolkit, parent, type, image, message, useHTML, null, null);
	}

	/**
	 * Create a composite according to the type
	 *
	 * @param shell
	 *            , the shell of the element
	 * @param toolkit
	 *            , the toolkit used
	 * @param parent
	 *            , the parent containing the composite created
	 * @param type
	 *            , the type to create
	 * @param image
	 *            , the image to associate
	 * @param message
	 *            , the message to display
	 * @param useHTML
	 *            , if the composite use html
	 * @param creator
	 *            , the composite creator it can be null
	 * @param context
	 *            , the context to add the composite created by the creator
	 * @return the composite created
	 */
	public static Composite createCompositeWithType(Shell shell, FormToolkit toolkit, Composite parent, Type type, Image image, String message, boolean useHTML, ICompositeCreator creator, IContext context) {
		Composite top = null;
		if (toolkit == null) {
			top = new Composite(parent, SWT.None);
		} else {
			top = toolkit.createComposite(parent, SWT.NONE);
		}
		top.setLayout(new GridLayout(2, false));
		Image anImage = image;
		switch (type) {
		case ERROR:
			anImage = NotificationBuilder.getSWTImage(SWT.ICON_ERROR, shell);
			break;
		case INFO:
			anImage = NotificationBuilder.getSWTImage(SWT.ICON_INFORMATION, shell);
			break;
		case WARNING:
			anImage = NotificationBuilder.getSWTImage(SWT.ICON_WARNING, shell);
			break;
		case QUESTION:
			anImage = NotificationBuilder.getSWTImage(SWT.ICON_QUESTION, shell);
			break;
		default:
		}
		Label labelImage = new Label(top, SWT.None);
		if (anImage != null) {
			labelImage.setImage(anImage);
		}
		if (creator == null) {
			if (toolkit != null) {
				FormText label = toolkit.createFormText(top, false);
				label.setText(message, useHTML, true);
				label.setLayoutData(new GridData(GridData.FILL_BOTH));
			} else {
				Label label = new Label(top, SWT.None);
				label.setText(message);
				label.setLayoutData(new GridData(GridData.FILL_BOTH));
			}
		} else {
			if (toolkit == null) {
				toolkit = PapyrusToolkit.INSTANCE;
			}
			Composite compo = creator.createComposite(top, toolkit);
			if (context != null) {
				context.put(IContext.COMPOSITE_CREATED, compo);
			}
		}
		return top;
	}

}

Back to the top