Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-18 11:14:58 -0400
committerMikaël Barbero2013-10-20 04:26:18 -0400
commit38ec8f53db44c71320ae28500fea5ca8d1a1b09e (patch)
treebf4e01d3d20ac2a4d08b45d8ad0912d8924b8f2e /plugins/org.eclipse.emf.compare.ide.ui/src
parent39050ef8a43dcbbc046081a398b3702096183e6e (diff)
downloadorg.eclipse.emf.compare-38ec8f53db44c71320ae28500fea5ca8d1a1b09e.tar.gz
org.eclipse.emf.compare-38ec8f53db44c71320ae28500fea5ca8d1a1b09e.tar.xz
org.eclipse.emf.compare-38ec8f53db44c71320ae28500fea5ca8d1a1b09e.zip
Add progress bar to structure merge viewer during computation
Diffstat (limited to 'plugins/org.eclipse.emf.compare.ide.ui/src')
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressInfoComposite.java144
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressMonitorWrapper.java87
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java70
3 files changed, 287 insertions, 14 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressInfoComposite.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressInfoComposite.java
new file mode 100644
index 000000000..605e1f1ee
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressInfoComposite.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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");
+ 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"));
+ actionButton.setDisabledImage(EMFCompareIDEUIPlugin.getImage("icons/full/eobj16/stop.gif"));
+
+ 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);
+ }
+ });
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressMonitorWrapper.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressMonitorWrapper.java
new file mode 100644
index 000000000..540794f13
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/progress/JobProgressMonitorWrapper.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.IProgressMonitor;
+import org.eclipse.core.runtime.ProgressMonitorWrapper;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public final class JobProgressMonitorWrapper extends ProgressMonitorWrapper {
+
+ private final JobProgressInfoComposite progressInfoItem;
+
+ private int totalWork;
+
+ private double worked;
+
+ /**
+ * @param monitor
+ */
+ public JobProgressMonitorWrapper(IProgressMonitor monitor, JobProgressInfoComposite progressInfoItem) {
+ super(monitor);
+ this.progressInfoItem = progressInfoItem;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#beginTask(java.lang.String, int)
+ */
+ @Override
+ public void beginTask(String name, int totalWork) {
+ this.totalWork = totalWork;
+ this.worked = 0;
+ this.progressInfoItem.init();
+ this.progressInfoItem.setTaskName(name);
+ super.beginTask(name, totalWork);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#setTaskName(java.lang.String)
+ */
+ @Override
+ public void setTaskName(String name) {
+ this.progressInfoItem.setPercentDone(getPercentDone());
+ super.setTaskName(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#subTask(java.lang.String)
+ */
+ @Override
+ public void subTask(String name) {
+ this.progressInfoItem.setTaskName(name);
+ super.subTask(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#worked(int)
+ */
+ @Override
+ public void worked(int work) {
+ this.worked += work;
+ int percentDone = getPercentDone();
+ this.progressInfoItem.setPercentDone(percentDone);
+ super.worked(work);
+ }
+
+ private int getPercentDone() {
+ return Math.min((int)(worked * 100 / totalWork), 100);
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
index 726f7f08a..2ea8526fb 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
@@ -64,6 +64,8 @@ import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.RedoActio
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.UndoAction;
import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeInput;
import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
+import org.eclipse.emf.compare.ide.ui.internal.progress.JobProgressInfoComposite;
+import org.eclipse.emf.compare.ide.ui.internal.progress.JobProgressMonitorWrapper;
import org.eclipse.emf.compare.ide.ui.internal.util.CompareHandlerService;
import org.eclipse.emf.compare.ide.ui.internal.util.ExceptionUtil;
import org.eclipse.emf.compare.ide.ui.internal.util.JFaceUtil;
@@ -104,6 +106,7 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Tree;
@@ -117,6 +120,20 @@ import org.eclipse.ui.actions.ActionFactory;
*/
public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrapper<Composite, WrappableTreeViewer> implements CommandStackListener {
+ private final class CompareInputChangedJob extends Job {
+ private CompareInputChangedJob(String name) {
+ super(name);
+ }
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ IProgressMonitor wrapper = new JobProgressMonitorWrapper(monitor, progressInfoItem);
+ SubMonitor subMonitor = SubMonitor.convert(wrapper, "Computing Model Differences", 100);
+ compareInputChanged((ICompareInput)getInput(), subMonitor.newChild(100));
+ return Status.OK_STATUS;
+ }
+ }
+
private static final Predicate<Diff> UNRESOLVED_AND_WITHOUT_PSEUDO_CONFLICT = and(
hasState(DifferenceState.UNRESOLVED), not(hasConflict(ConflictKind.PSEUDO)));
@@ -175,14 +192,9 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
private final Listener fEraseItemListener;
- private final Job inputChangedTask = new Job("Compute Model Differences") {
- @Override
- public IStatus run(IProgressMonitor monitor) {
- SubMonitor subMonitor = SubMonitor.convert(monitor, "Computing Model Differences", 100);
- compareInputChanged((ICompareInput)getInput(), subMonitor.newChild(100));
- return Status.OK_STATUS;
- }
- };
+ private JobProgressInfoComposite progressInfoItem;
+
+ private Job inputChangedTask;
private CompareToolBar toolBar;
@@ -199,6 +211,8 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
public EMFCompareStructureMergeViewer(Composite parent, EMFCompareConfiguration config) {
super(parent, config);
+ updateLayout(true, false);
+
StructureMergeViewerFilter structureMergeViewerFilter = getCompareConfiguration()
.getStructureMergeViewerFilter();
getViewer().addFilter(structureMergeViewerFilter);
@@ -285,6 +299,8 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
requiredDiffColor = JFaceResources.getColorRegistry().get(REQUIRED_DIFF_COLOR);
unmergeableDiffColor = JFaceResources.getColorRegistry().get(UNMERGEABLE_DIFF_COLOR);
+
+ inputChangedTask = new CompareInputChangedJob("Computing Model Differences");
}
/**
@@ -298,14 +314,20 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
protected ControlAndViewer<Composite, WrappableTreeViewer> createControlAndViewer(Composite parent) {
Composite control = new Composite(parent, SWT.NONE);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ control.setLayoutData(data);
+
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
control.setLayout(layout);
- control.setLayoutData(data);
+
+ progressInfoItem = new JobProgressInfoComposite(inputChangedTask, control, SWT.SMOOTH
+ | SWT.HORIZONTAL, SWT.NONE);
+ progressInfoItem.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ progressInfoItem.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
final WrappableTreeViewer treeViewer = new WrappableTreeViewer(control, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL) {
@@ -330,13 +352,15 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
INavigatable nav = new Navigatable(fAdapterFactory, treeViewer);
control.setData(INavigatable.NAVIGATOR_PROPERTY, nav);
+
control.setData(CompareUI.COMPARE_VIEWER_TITLE, "Model differences");
treeRuler = new EMFCompareDiffTreeRuler(control, SWT.NONE, treeViewer, dependencyData);
- GridData layoutData = new GridData(SWT.FILL, SWT.FILL, false, true);
- layoutData.widthHint = TREE_RULER_WIDTH;
- layoutData.minimumWidth = TREE_RULER_WIDTH;
- treeRuler.setLayoutData(layoutData);
+ GridData rulerLayoutData = new GridData(SWT.FILL, SWT.FILL, false, true);
+ rulerLayoutData.exclude = true;
+ rulerLayoutData.widthHint = TREE_RULER_WIDTH;
+ rulerLayoutData.minimumWidth = TREE_RULER_WIDTH;
+ treeRuler.setLayoutData(rulerLayoutData);
return ControlAndViewer.create(control, treeViewer);
}
@@ -528,6 +552,7 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
// The compare configuration is nulled when the viewer is disposed
if (getCompareConfiguration() != null) {
+ updateLayout(true, true);
inputChangedTask.schedule();
}
}
@@ -572,6 +597,8 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
+ updateLayout(false, true);
+
// title is not initialized as the comparison was set in the configuration after the
// refresh caused by the initialization of the viewer filters and the groupe providers.
refreshTitle();
@@ -643,6 +670,21 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
}
+ private void updateLayout(boolean displayProgress, boolean doLayout) {
+ ((GridData)progressInfoItem.getLayoutData()).exclude = !displayProgress;
+ progressInfoItem.setVisible(displayProgress);
+
+ ((GridData)getViewer().getControl().getLayoutData()).exclude = displayProgress;
+ getViewer().getControl().setVisible(!displayProgress);
+
+ ((GridData)treeRuler.getLayoutData()).exclude = displayProgress;
+ treeRuler.setVisible(!displayProgress);
+
+ if (doLayout) {
+ getControl().layout(true, true);
+ }
+ }
+
private void compareInputChangedToNull() {
ResourceSet leftResourceSet = null;
ResourceSet rightResourceSet = null;

Back to the top