diff options
author | Christian W. Damus | 2014-11-14 17:05:36 +0000 |
---|---|---|
committer | Christian W. Damus | 2014-11-14 19:05:46 +0000 |
commit | d0557a86e852fd7ae0d3d428380d2fdf9b3733d5 (patch) | |
tree | d4b1fda585dba4e1f64c3b53ce1bb2893901a020 | |
parent | 397fd13342b0fa8b2f769cdd441760cad342ada7 (diff) | |
download | org.eclipse.papyrus-d0557a86e852fd7ae0d3d428380d2fdf9b3733d5.tar.gz org.eclipse.papyrus-d0557a86e852fd7ae0d3d428380d2fdf9b3733d5.tar.xz org.eclipse.papyrus-d0557a86e852fd7ae0d3d428380d2fdf9b3733d5.zip |
451557: Stereotype repair dialog buttons still enabled during long repair operation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=451557
Disable the repair dialog buttons while the repair is in progress and provide a cancel button to stop and rewind the repair operation.
Conflicts:
plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/UIUtil.java
plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/participants/StereotypeApplicationRepairParticipant.java
plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/ApplyProfileAction.java
12 files changed, 233 insertions, 41 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/TransactionHelper.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/TransactionHelper.java index 5a0168f200e..0e9fc6ececc 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/TransactionHelper.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/TransactionHelper.java @@ -1,5 +1,5 @@ /*****************************************************************************
- * Copyright (c) 2014 CEA LIST and others.
+ * Copyright (c) 2014 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,6 +11,7 @@ * Christian W. Damus (CEA) - bug 429826
* Christian W. Damus (CEA) - bug 408491
* Christian W. Damus (CEA) - bug 433320
+ * Christian W. Damus - bug 451557
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.utils;
@@ -21,6 +22,7 @@ import java.util.Map; import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
@@ -231,6 +233,8 @@ public class TransactionHelper extends org.eclipse.papyrus.infra.core.sasheditor public void run() {
try {
runnable.run(monitorHolder[0]);
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
throw new WrappedException(e);
}
@@ -245,6 +249,8 @@ public class TransactionHelper extends org.eclipse.papyrus.infra.core.sasheditor try {
privileged.run();
+ } catch (OperationCanceledException e) {
+ throw new InterruptedException(e.getLocalizedMessage());
} catch (WrappedException e) {
Exception unwrapped = e.exception();
if (unwrapped instanceof InvocationTargetException) {
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/Iterators2.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/Iterators2.java new file mode 100644 index 00000000000..bd10ef4e9d7 --- /dev/null +++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/Iterators2.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2014 Christian W. Damus and others. + * + * 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: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.tools.util; + +import java.util.Iterator; + +import org.eclipse.emf.common.util.TreeIterator; + +import com.google.common.collect.AbstractIterator; +import com.google.common.collect.Iterators; + +/** + * Utilities for working with iterators that are not provided by {@linkplain Iterators Guava}. + */ +public class Iterators2 { + /** + * Not instantiable by clients. + */ + private Iterators2() { + super(); + } + + /** + * Filters an EMF tree iterator for elements of a particular {@code type}. + * + * @param treeIterator + * the tree iterator to filter + * @param type + * the type of elements to include in the filtered tree iterator + * @return the filtered tree iterator + */ + public static <T> TreeIterator<T> filter(final TreeIterator<?> treeIterator, final Class<T> type) { + class FilteredTreeIterator extends AbstractIterator<T> implements TreeIterator<T> { + final Iterator<T> delegate = Iterators.filter(treeIterator, type); + + @Override + protected T computeNext() { + return delegate.hasNext() ? delegate.next() : endOfData(); + } + + public void prune() { + treeIterator.prune(); + } + } + + return new FilteredTreeIterator(); + } +} diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/UIUtil.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/UIUtil.java index 945be4fc150..3c6823a4528 100644 --- a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/UIUtil.java +++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/UIUtil.java @@ -9,6 +9,7 @@ * Contributors: * Christian W. Damus (CEA) - Initial API and implementation * Christian W. Damus - bug 399859 + * Christian W. Damus - bug 451557 * */ package org.eclipse.papyrus.infra.tools.util; @@ -16,6 +17,7 @@ package org.eclipse.papyrus.infra.tools.util; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Date; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Queue; @@ -36,9 +38,15 @@ import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.emf.common.util.AbstractTreeIterator; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IMemento; +import com.google.common.collect.Iterators; + /** * Miscellaneous general-purpose UI utilities. @@ -238,6 +246,38 @@ public class UIUtil { }; } + /** + * Obtains a tree iterator over all of the controls contained within a given {@code root} control, not including that {@code root}. + * + * @param root + * a control to iterate + * @return an unmodifiable iterator over all of its nested controls, which naturally will be empty if the {@code root} is not a {@link Composite} + */ + public static TreeIterator<Control> allChildren(Control root) { + return new AbstractTreeIterator<Control>(root, false) { + private static final long serialVersionUID = 1L; + + @Override + protected Iterator<? extends Control> getChildren(Object object) { + return (object instanceof Composite) ? Iterators.forArray(((Composite) object).getChildren()) : Iterators.<Control> emptyIterator(); + } + }; + } + + /** + * Obtains a tree iterator over all of the controls of a particular type contained within a given {@code root} control, not including that {@code root}. + * + * @param root + * a control to iterate + * @param type + * the type of children to include in the iteration + * + * @return an unmodifiable iterator over all of its nested controls, which naturally will be empty if the {@code root} is not a {@link Composite} + */ + public static <C extends Control> TreeIterator<C> allChildren(Control root, final Class<C> type) { + return Iterators2.filter(allChildren(root), type); + } + // // Nested types // diff --git a/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/internal/providers/ExternalizedProfileApplicationDelegate.java b/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/internal/providers/ExternalizedProfileApplicationDelegate.java index 1246fff3e4b..4d8f72a357b 100644 --- a/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/internal/providers/ExternalizedProfileApplicationDelegate.java +++ b/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/internal/providers/ExternalizedProfileApplicationDelegate.java @@ -12,7 +12,7 @@ * Kenn Hussey - 323181, 348433 * Kenn Hussey (CEA) - 327039, 369492, 313951, 163556, 418466, 447901 * Christian W. Damus (CEA) - 300957, 431998 - * Christian W. Damus - 444588, 399859 + * Christian W. Damus - 444588, 399859, 451557 * *****************************************************************************/ @@ -21,6 +21,9 @@ package org.eclipse.papyrus.uml.decoratormodel.internal.providers; import java.util.ArrayList; import java.util.Collection; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.TreeIterator; @@ -31,6 +34,7 @@ import org.eclipse.emf.ecore.EStructuralFeature.Setting; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xmi.XMLResource; +import org.eclipse.osgi.util.NLS; import org.eclipse.papyrus.uml.decoratormodel.helper.DecoratorModelUtils; import org.eclipse.papyrus.uml.tools.helper.IProfileApplicationDelegate; import org.eclipse.uml2.uml.Element; @@ -80,33 +84,37 @@ public class ExternalizedProfileApplicationDelegate implements IProfileApplicati } @Override - public EList<EObject> applyProfile(Package package_, Profile profile, Package context) { - EList<EObject> result; - + public EList<EObject> applyProfile(Package package_, Profile profile, Package context, IProgressMonitor monitor) { + // Create the new profile application and then "reapply" it in place + ProfileApplication profileApplication; if (!DecoratorModelUtils.isDecoratorModel(context) || EcoreUtil.isAncestor(context, package_)) { // The context is meaningless to me or we are creating an externalized profile application - result = package_.applyProfile(profile); + profileApplication = package_.createProfileApplication(); } else { Package decorator = DecoratorModelUtils.getDecoratorPackage(context, package_, true); - - // Create the new profile application and then "reapply" it in place - ProfileApplication profileApplication = decorator.createProfileApplication(); - profileApplication.setAppliedProfile(profile); - result = util.reapplyProfile(package_, profileApplication); + profileApplication = decorator.createProfileApplication(); } - return result; + profileApplication.setAppliedProfile(profile); + + return util.reapplyProfile(package_, profileApplication, monitor); } @Override public boolean appliesTo(ProfileApplication profileApplication) { - Resource resource = profileApplication.eResource(); - return (resource != null) && DecoratorModelUtils.isDecoratorModel(resource); + return true; } @Override public Package getApplyingPackage(ProfileApplication profileApplication) { - return DecoratorModelUtils.getUserModelApplyingPackage(profileApplication); + Package result = profileApplication.getApplyingPackage(); + + Resource resource = (result == null) ? null : result.eResource(); + if ((resource != null) && DecoratorModelUtils.isDecoratorModel(resource)) { + result = DecoratorModelUtils.getUserModelApplyingPackage(profileApplication); + } + + return result; } @Override @@ -115,11 +123,10 @@ public class ExternalizedProfileApplicationDelegate implements IProfileApplicati } @Override - public EList<EObject> reapplyProfile(Package package_, Profile profile) { + public EList<EObject> reapplyProfile(Package package_, Profile profile, IProgressMonitor monitor) { ProfileApplication existing = getProfileApplication(package_, profile); return (existing == null) ? ECollections.<EObject> emptyEList() // Nothing to do - : (existing.getApplyingPackage() == package_) ? package_.applyProfile(profile) // Simple UML case - : util.reapplyProfile(package_, existing); // Our extended UML case + : util.reapplyProfile(package_, existing, monitor); // Our extended UML case } // @@ -130,10 +137,12 @@ public class ExternalizedProfileApplicationDelegate implements IProfileApplicati @SuppressWarnings("restriction") private class PrivateUtil extends org.eclipse.uml2.uml.internal.operations.PackageOperations { - EList<EObject> reapplyProfile(Package package_, ProfileApplication profileApplication) { + EList<EObject> reapplyProfile(Package package_, ProfileApplication profileApplication, IProgressMonitor monitor) { Profile profile = ExternalizedProfileApplicationDelegate.this.getAppliedProfile(profileApplication); EPackage definition = profile.getDefinition(); + monitor = SubMonitor.convert(monitor, NLS.bind("Re-applying profile \"{0}\" to package \"{1}\"", profile.getName(), package_.getName()), IProgressMonitor.UNKNOWN); + Collection<EObject> originals = Lists.newArrayList(); StereotypeApplicationCopier copier = new PrivateStereotypeCopier(profile); @@ -142,6 +151,10 @@ public class ExternalizedProfileApplicationDelegate implements IProfileApplicati EObject eObject = allContents.next(); if (eObject instanceof Element) { + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + Element element = (Element) eObject; if (element instanceof Package) { @@ -183,11 +196,19 @@ public class ExternalizedProfileApplicationDelegate implements IProfileApplicati } } + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + // Copy cross-references within the stereotype application forest that was copied copier.copyReferences(); // Propagate object IDs of stereotype applications and update all incoming cross-references from objects that were not copied for (EObject key : copier.keySet()) { + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + EObject copy = copier.get(key); Resource eResource = key.eResource(); @@ -220,9 +241,17 @@ public class ExternalizedProfileApplicationDelegate implements IProfileApplicati } } + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + // Delete all of the original stereotype applications (leaving only the copies) destroyAll(originals); + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + // Easy result in the common case of the profile not having any required metaclass extensions return profile.getOwnedExtensions(true).isEmpty() ? ECollections.<EObject> emptyEList() : applyAllRequiredStereotypes(package_); } diff --git a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/participants/StereotypeApplicationRepairParticipant.java b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/participants/StereotypeApplicationRepairParticipant.java index d3c03ff0c7c..08652c9e7cc 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/participants/StereotypeApplicationRepairParticipant.java +++ b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/participants/StereotypeApplicationRepairParticipant.java @@ -10,6 +10,7 @@ * Christian W. Damus (CEA) - Initial API and implementation * Christian W. Damus - bug 399859 * Christian W. Damus - bug 450524 + * Christian W. Damus - bug 451557 * */ package org.eclipse.papyrus.uml.modelrepair.internal.participants; @@ -22,6 +23,7 @@ import java.util.Queue; import java.util.regex.Pattern; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.emf.common.util.BasicDiagnostic; import org.eclipse.emf.common.util.Diagnostic; @@ -235,6 +237,10 @@ public class StereotypeApplicationRepairParticipant extends PackageOperations im } for (EObject next : stereotypeApplications) { + if (sub.isCanceled()) { + throw new OperationCanceledException(); + } + EObject newInstance = copier.copy(next); if ((newInstance != null) && (newInstance != next)) { // Depends how we copied the stereotype instance (by applying again or not), @@ -255,6 +261,10 @@ public class StereotypeApplicationRepairParticipant extends PackageOperations im // Preserve the identities of stereotype applications and their contents and update references not accounted for by the copier // (for example, references from Notation views/styles in the diagrams) for (Map.Entry<EObject, EObject> next : copier.entrySet()) { + if (sub.isCanceled()) { + throw new OperationCanceledException(); + } + EObject original = next.getKey(); EObject copy = next.getValue(); @@ -293,6 +303,10 @@ public class StereotypeApplicationRepairParticipant extends PackageOperations im // Delete all trace of the old stereotype applications for (EObject root : stereotypeApplications) { + if (sub.isCanceled()) { + throw new OperationCanceledException(); + } + safelyDestroy(root); EcoreUtil.remove(root); } @@ -300,6 +314,8 @@ public class StereotypeApplicationRepairParticipant extends PackageOperations im sub.worked(1); copier.clear(); + + sub.done(); } private void safelyDestroy(EObject eObject) { diff --git a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/ApplyProfileAction.java b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/ApplyProfileAction.java index bd6c7c854f1..94c5929a69b 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/ApplyProfileAction.java +++ b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/ApplyProfileAction.java @@ -9,6 +9,7 @@ * Contributors: * Christian W. Damus (CEA) - Initial API and implementation * Christian W. Damus - bug 399859 + * Christian W. Damus - bug 451557 * */ package org.eclipse.papyrus.uml.modelrepair.internal.stereotypes; @@ -17,6 +18,7 @@ import java.util.Collection; import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.emf.common.util.DiagnosticChain; import org.eclipse.emf.ecore.EObject; @@ -90,7 +92,11 @@ public class ApplyProfileAction extends AbstractRepairAction { // Apply the profile StereotypeApplicationRepairParticipant.createStereotypeApplicationMigrator(resource, profile, diagnostics).migrate(stereotypeApplications, sub.newChild(stereotypeApplications.size())); for (Package next : packages) { - applyProfile(next, profile); + if (sub.isCanceled()) { + throw new OperationCanceledException(); + } + + applyProfile(next, profile, sub.newChild(stereotypeApplications.size() / 2)); } result = true; @@ -101,7 +107,9 @@ public class ApplyProfileAction extends AbstractRepairAction { return result; } - protected ProfileApplication applyProfile(Package package_, Profile profile) { + protected ProfileApplication applyProfile(Package package_, Profile profile, IProgressMonitor monitor) { + monitor = SubMonitor.convert(monitor); + ProfileApplication result; IProfileApplicationDelegate delegate = ProfileApplicationDelegateRegistry.INSTANCE.getDelegate(package_); @@ -110,14 +118,14 @@ public class ApplyProfileAction extends AbstractRepairAction { ProfileApplication existing = delegate.getProfileApplication(package_, profile); if (existing != null) { delegate = ProfileApplicationDelegateRegistry.INSTANCE.getDelegate(existing); - delegate.reapplyProfile(package_, profile); + delegate.reapplyProfile(package_, profile, monitor); result = existing; } else { // Try to get a delegate appropriate to the resource we're repairing (it could be a profile-application model) Package root = Iterables.getFirst(Iterables.filter(resourceUnderRepair.getContents(), Package.class), null); if (root != null) { delegate = ProfileApplicationDelegateRegistry.INSTANCE.getDelegate(root); - delegate.applyProfile(package_, profile, root); + delegate.applyProfile(package_, profile, root, monitor); } else { // Simple profile application scenario package_.applyProfile(profile); @@ -125,6 +133,8 @@ public class ApplyProfileAction extends AbstractRepairAction { result = delegate.getProfileApplication(package_, profile); } + monitor.done(); + return result; } } diff --git a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/DeleteAction.java b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/DeleteAction.java index 8c9f7692425..ab10cee87cc 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/DeleteAction.java +++ b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/DeleteAction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 CEA and others. + * Copyright (c) 2014 CEA, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Christian W. Damus (CEA) - Initial API and implementation + * Christian W. Damus - bug 451557 * */ package org.eclipse.papyrus.uml.modelrepair.internal.stereotypes; @@ -15,6 +16,7 @@ package org.eclipse.papyrus.uml.modelrepair.internal.stereotypes; import java.util.Collection; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.emf.common.util.DiagnosticChain; import org.eclipse.emf.ecore.EObject; @@ -37,6 +39,10 @@ public class DeleteAction extends AbstractRepairAction { monitor = SubMonitor.convert(monitor, "Deleting stereotype applications...", stereotypeApplications.size()); for (EObject next : stereotypeApplications) { + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + destroy(next); monitor.worked(1); } diff --git a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/ui/ZombieStereotypesDialog.java b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/ui/ZombieStereotypesDialog.java index 609cfbb0df2..ba476c48916 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/ui/ZombieStereotypesDialog.java +++ b/plugins/uml/org.eclipse.papyrus.uml.modelrepair/src/org/eclipse/papyrus/uml/modelrepair/ui/ZombieStereotypesDialog.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014 CEA and others. + * Copyright (c) 2013, 2014 CEA, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -10,6 +10,7 @@ * CEA - Initial API and implementation * Christian W. Damus (CEA) - bug 431953 (adapted from SwitchProfileDialog) * Christian W. Damus - bug 451338 + * Christian W. Damus - bug 451557 * */ package org.eclipse.papyrus.uml.modelrepair.ui; @@ -61,6 +62,7 @@ import org.eclipse.papyrus.infra.core.utils.TransactionHelper; import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet; import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; import org.eclipse.papyrus.infra.services.markerlistener.dialogs.DiagnosticDialog; +import org.eclipse.papyrus.infra.tools.util.UIUtil; import org.eclipse.papyrus.uml.modelrepair.Activator; import org.eclipse.papyrus.uml.modelrepair.internal.stereotypes.IRepairAction; import org.eclipse.papyrus.uml.modelrepair.internal.stereotypes.ZombieStereotypesDescriptor; @@ -68,6 +70,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -194,7 +197,7 @@ public class ZombieStereotypesDialog extends TrayDialog { table.setLabelProvider(new ZombiesLabelProvider()); table.setInput(getMissingSchemas()); - progress = new ProgressMonitorPart(self, null); + progress = new ProgressMonitorPart(self, null, true); progress.setLayoutData(new GridData(SWT.FILL, SWT.LEAD, true, false)); progress.setVisible(false); @@ -256,21 +259,26 @@ public class ZombieStereotypesDialog extends TrayDialog { } }); - Cursor waitCursor = new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT); + final Cursor previousCursor = getShell().getCursor(); + Cursor waitCursor = getShell().getDisplay().getSystemCursor(SWT.CURSOR_WAIT); try { getShell().setCursor(waitCursor); progress.setVisible(true); + progress.attachToCancelComponent(null); // Enable the stop button + enableButtons(false); ModalContext.run(runnable, true, progress, getShell().getDisplay()); + } catch (InterruptedException e) { + // User cancelled. That's normal } catch (Exception e) { - getShell().setCursor(null); + getShell().setCursor(previousCursor); Throwable t = e; if (e instanceof InvocationTargetException) { t = ((InvocationTargetException) e).getTargetException(); } StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to repair stereotypes.", t), StatusManager.BLOCK | StatusManager.LOG); } finally { - getShell().setCursor(null); - waitCursor.dispose(); + enableButtons(true); + getShell().setCursor(previousCursor); progress.setVisible(false); } @@ -318,6 +326,12 @@ public class ZombieStereotypesDialog extends TrayDialog { super.buttonPressed(buttonId); } + void enableButtons(boolean enable) { + for (Iterator<Button> iter = UIUtil.allChildren(getButtonBar(), Button.class); iter.hasNext();) { + iter.next().setEnabled(enable); + } + } + @Override public void create() { super.create(); @@ -343,7 +357,12 @@ public class ZombieStereotypesDialog extends TrayDialog { protected void okPressed() { applyPressed(); - super.okPressed(); + updateControls(); + + // Maybe the user cancelled the work + if (!getButton(APPLY_ID).isEnabled()) { + super.okPressed(); + } } @Override diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java index cdeb557d6df..b781258a79b 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java @@ -10,6 +10,7 @@ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation * Christian W. Damus - bug 399859 + * Christian W. Damus - bug 451557 * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.commands; @@ -156,7 +157,7 @@ public class ApplyProfileCommand extends RecordingCommand { ProfileApplication existing = delegate.getProfileApplication(package_, profile); if (existing != null) { delegate = ProfileApplicationDelegateRegistry.INSTANCE.getDelegate(existing); - delegate.reapplyProfile(package_, profile); + delegate.reapplyProfile(package_, profile, null); result = existing; } else { package_.applyProfile(profile); diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/IProfileApplicationDelegate.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/IProfileApplicationDelegate.java index 5c1f5bbedc5..7f45aeedcb5 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/IProfileApplicationDelegate.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/IProfileApplicationDelegate.java @@ -13,6 +13,7 @@ package org.eclipse.papyrus.uml.tools.helper; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.uml2.uml.Package; @@ -66,10 +67,12 @@ public interface IProfileApplicationDelegate { * @param context * a context in which to apply the profile, which may be the same as or a nesting package of the applying package, or some distinct other package * altogether (such as a profile-application model) + * @param monitor + * an optional monitor for reporting profile re-application progress (may be {@code null}) * * @return any new stereotype applications created as a consequence of required metaclass extensions */ - EList<EObject> applyProfile(Package package_, Profile profile, Package context); + EList<EObject> applyProfile(Package package_, Profile profile, Package context, IProgressMonitor monitor); /** * Queries whether I am applicable to (support introspection/manipulation of) a given profile application. @@ -105,10 +108,12 @@ public interface IProfileApplicationDelegate { * the package to which to re-apply the {@code profile}. The profile must already be applied * @param profile * the profile to re-apply + * @param monitor + * an optional monitor for reporting profile re-application progress (may be {@code null}) * * @return any new stereotype applications created as a consequence of required metaclass extensions */ - EList<EObject> reapplyProfile(Package package_, Profile profile); + EList<EObject> reapplyProfile(Package package_, Profile profile, IProgressMonitor monitor); // // Nested types @@ -131,7 +136,7 @@ public interface IProfileApplicationDelegate { return package_.getProfileApplication(profile); } - public EList<EObject> applyProfile(Package package_, Profile profile, Package context) { + public EList<EObject> applyProfile(Package package_, Profile profile, Package context, IProgressMonitor monitor) { // I just simply apply the profile (I don't handle weird context scenarios) return package_.applyProfile(profile); } @@ -148,7 +153,7 @@ public interface IProfileApplicationDelegate { return profileApplication.getAppliedProfile(); } - public EList<EObject> reapplyProfile(Package package_, Profile profile) { + public EList<EObject> reapplyProfile(Package package_, Profile profile, IProgressMonitor monitor) { return package_.applyProfile(profile); } } diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/ProfileApplicationDelegateRegistry.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/ProfileApplicationDelegateRegistry.java index fb7c7b2e9b3..79e22945a25 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/ProfileApplicationDelegateRegistry.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/helper/ProfileApplicationDelegateRegistry.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.ListIterator; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; @@ -229,8 +230,8 @@ public class ProfileApplicationDelegateRegistry { return getInstance().getProfileApplication(package_, profile); } - public EList<EObject> applyProfile(Package package_, Profile profile, Package context) { - return getInstance().applyProfile(package_, profile, context); + public EList<EObject> applyProfile(Package package_, Profile profile, Package context, IProgressMonitor monitor) { + return getInstance().applyProfile(package_, profile, context, monitor); } public Package getApplyingPackage(ProfileApplication profileApplication) { @@ -241,8 +242,8 @@ public class ProfileApplicationDelegateRegistry { return getInstance().getAppliedProfile(profileApplication); } - public EList<EObject> reapplyProfile(Package package_, Profile profile) { - return getInstance().reapplyProfile(package_, profile); + public EList<EObject> reapplyProfile(Package package_, Profile profile, IProgressMonitor monitor) { + return getInstance().reapplyProfile(package_, profile, monitor); } } } diff --git a/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/tests/ProfileMigrationTest.java b/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/tests/ProfileMigrationTest.java index f6b9e23bacb..dea79f32d44 100644 --- a/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/tests/ProfileMigrationTest.java +++ b/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/tests/ProfileMigrationTest.java @@ -82,7 +82,7 @@ public class ProfileMigrationTest extends AbstractProfileExternalizationTest { public void run() { @SuppressWarnings("restriction") IProfileApplicationDelegate delegate = new org.eclipse.papyrus.uml.decoratormodel.internal.providers.ExternalizedProfileApplicationDelegate(); - delegate.reapplyProfile(package_, profile); + delegate.reapplyProfile(package_, profile, null); } }); } |