Skip to main content
summaryrefslogtreecommitdiffstats
blob: bebb689136817e4fc3618cf30fd439e3540a2d43 (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
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2013, 2014 Obeo.
 * 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:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.progress;

import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
import org.eclipse.emf.compare.rcp.ui.internal.util.SWTUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.ProgressBar;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.internal.progress.ProgressMessages;

/**
 * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
 */
public class JobProgressInfoComposite extends Composite {

	private ProgressBar progressBar;

	private Label jobImageLabel;

	private Label jobNameLabel;

	private Label taskNameLabel;

	private ToolBar actionBar;

	private ToolItem actionButton;

	private final Job job;

	/**
	 * @param parent
	 * @param style
	 */
	public JobProgressInfoComposite(Job job, Composite parent, int progressBarStyle, int style) {
		super(parent, style);
		this.job = job;

		GridLayout gridLayout = new GridLayout(3, false);
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		gridLayout.marginTop = 2;
		gridLayout.marginBottom = 2;
		gridLayout.marginLeft = 2;
		gridLayout.marginRight = 2;
		gridLayout.verticalSpacing = 2;
		gridLayout.horizontalSpacing = 2;
		setLayout(gridLayout);

		Image jobImage = EMFCompareIDEUIPlugin.getImage("icons/full/eobj16/task.gif"); //$NON-NLS-1$
		jobNameLabel = new Label(this, SWT.NONE);
		int horizontalIndent = jobImage.getBounds().width + 2;
		GridData gridData = new GridData();
		gridData.grabExcessHorizontalSpace = true;
		gridData.horizontalIndent = horizontalIndent;
		gridData.horizontalSpan = 3;
		jobNameLabel.setLayoutData(gridData);
		jobNameLabel.setText(job.getName());

		jobImageLabel = new Label(this, SWT.NONE);
		jobImageLabel.setImage(jobImage);
		jobImageLabel.setLayoutData(new GridData());

		progressBar = new ProgressBar(this, SWT.HORIZONTAL | progressBarStyle);
		gridData = new GridData();
		gridData.grabExcessHorizontalSpace = true;
		gridData.horizontalAlignment = SWT.FILL;
		progressBar.setLayoutData(gridData);
		progressBar.setMinimum(0);
		progressBar.setMaximum(100);

		actionBar = new ToolBar(this, SWT.FLAT);
		actionBar.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
		actionBar.setLayoutData(new GridData());

		// set cursor to overwrite any busy cursor we might have

		actionButton = new ToolItem(actionBar, SWT.NONE);
		actionButton.setToolTipText(ProgressMessages.NewProgressView_CancelJobToolTip);
		actionButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				actionButton.setEnabled(false);
				JobProgressInfoComposite.this.job.cancel();
			}
		});
		actionButton.setImage(EMFCompareIDEUIPlugin.getImage("icons/full/dobj16/stop.gif")); //$NON-NLS-1$
		actionButton.setDisabledImage(EMFCompareIDEUIPlugin.getImage("icons/full/eobj16/stop.gif")); //$NON-NLS-1$

		taskNameLabel = new Label(this, SWT.NONE);
		gridData = new GridData();
		gridData.grabExcessHorizontalSpace = true;
		gridData.horizontalIndent = horizontalIndent;
		gridData.horizontalSpan = 3;
		taskNameLabel.setLayoutData(gridData);
	}

	void init() {
		SWTUtil.safeAsyncExec(new Runnable() {
			public void run() {
				actionButton.setEnabled(true);
				progressBar.setSelection(0);
			}
		});
	}

	/**
	 * @param taskNameLabel
	 *            the taskNameLabel to set
	 */
	public void setTaskName(final String taskName) {
		SWTUtil.safeAsyncExec(new Runnable() {
			public void run() {
				taskNameLabel.setText(taskName);
				layout();
			}
		});
	}

	public void setPercentDone(final int percent) {
		SWTUtil.safeAsyncExec(new Runnable() {
			public void run() {
				progressBar.setSelection(percent);
			}
		});
	}
}

Back to the top