Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9f7c8593d7f572bc1212640ceede19d61f5f1159 (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
129
130
131
132
133
134
135
136
/*****************************************************************************
 * Copyright (c) 2021 CEA LIST and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.infra.ui.internal.services.status;

import org.eclipse.jface.dialogs.IconAndMessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;

/**
 * A dialog that display a message and a ProgressBar
 * (This dialog looks like the {@link org.eclipse.jface.dialogs.ProgressMonitorDialog}, the main difference
 * is that the ProgressMonitorDialog work with the run execution here we don't have a runnable)
 */
public class ProgressDialog extends IconAndMessageDialog {

	private Image image;
	private String title;
	private ProgressBar progressBar;
	private Label subTaskLabel;

	/**
	 *
	 * Constructor.
	 *
	 * @param parentShell
	 * @param title
	 * @param message
	 */
	public ProgressDialog(Shell parentShell, String title, String message) {
		super(parentShell);
		this.image = getInfoImage();
		this.message = message;
		this.title = title;
		setShellStyle(getDefaultOrientation() | SWT.BORDER | SWT.TITLE
				| SWT.APPLICATION_MODAL | SWT.CLOSE);
		setBlockOnOpen(false);
	}

	/**
	 * @see org.eclipse.jface.dialogs.IconAndMessageDialog#getImage()
	 *
	 * @return
	 */
	@Override
	protected Image getImage() {
		return image;
	}

	/**
	 *
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
	 *
	 * @param shell
	 */
	@Override
	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		if (title != null) {
			shell.setText(title);
		}
	}

	/**
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 *
	 * @param parent
	 * @return
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Control control = super.createDialogArea(parent);

		createMessageArea(parent);

		progressBar = new ProgressBar(parent, SWT.SMOOTH);
		GridData gd2 = new GridData();
		gd2.horizontalAlignment = GridData.FILL;
		gd2.grabExcessHorizontalSpace = true;
		gd2.horizontalSpan = 2;
		progressBar.setLayoutData(gd2);
		progressBar.setMaximum(4);

		GridData gd3 = new GridData();
		gd3.horizontalAlignment = GridData.FILL;
		gd3.grabExcessHorizontalSpace = true;
		gd3.horizontalSpan = 2;
		subTaskLabel = new Label(parent, SWT.WRAP);
		subTaskLabel.setText("Start operation"); //$NON-NLS-1$
		subTaskLabel.setLayoutData(gd3);

		return control;
	}

	/**
	 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
	 *
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		// Do nothing
	}

	/**
	 * Increase the progression
	 *
	 * @param subTaskMessage
	 *            the message of the subtask
	 */
	public void work(String subTaskMessage) {
		progressBar.setState(SWT.NORMAL);
		int sel = progressBar.getSelection();
		progressBar.setSelection(sel + 1);
		subTaskLabel.setText(subTaskMessage);
	}

}

Back to the top