Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-01-13 14:11:17 -0500
committerBrian Vosburgh2016-01-13 14:11:17 -0500
commit4751e8fbf032cb40b4c085d2effdb8338b9a0682 (patch)
treea6ca66287543c9f50ef71a59d160d066d0e3bd16 /common/plugins/org.eclipse.jpt.common.core/src
parent404795e9b255c6e7f55a8cfcf68bde28d812eeb2 (diff)
downloadwebtools.dali-4751e8fbf032cb40b4c085d2effdb8338b9a0682.tar.gz
webtools.dali-4751e8fbf032cb40b4c085d2effdb8338b9a0682.tar.xz
webtools.dali-4751e8fbf032cb40b4c085d2effdb8338b9a0682.zip
[466421] pass IProgressMonitor to JpaFactory.buildJpaProject(...) so
user can cancel "Build JPA Project" job
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.core/src')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java21
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java21
3 files changed, 54 insertions, 18 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java
index 6bad23cc21..37d93fb688 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2016 Oracle. 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.
@@ -67,8 +67,10 @@ public class NotifyingRepeatingJobCommandWrapper
@Override
/* private protected */ IStatus executeCommand(IProgressMonitor monitor) {
IStatus status = super.executeCommand(monitor);
- if (this.state.isQuiesced()) {
- // hmmm - we will notify listeners even when we are "stopped"; that seems OK...
+ if (status.getSeverity() == IStatus.CANCEL) {
+ this.executionCanceled();
+ }
+ else if (this.state.isQuiesced()) {
this.executionQuiesced();
}
return status;
@@ -80,15 +82,33 @@ public class NotifyingRepeatingJobCommandWrapper
*/
private void executionQuiesced() {
for (Listener listener : this.listenerList) {
- this.notifyListener(listener);
+ this.notifyListenerQuiesced(listener);
}
}
- private void notifyListener(Listener listener) {
+ private void notifyListenerQuiesced(Listener listener) {
try {
listener.executionQuiesced(this);
} catch (Throwable ex) {
this.exceptionHandler.handleException(ex);
}
}
+
+ /**
+ * Notify our listeners. All listeners are notified. There is no way to
+ * cancel the notifications (e.g. via a monitor or exception).
+ */
+ private void executionCanceled() {
+ for (Listener listener : this.listenerList) {
+ this.notifyListenerCanceled(listener);
+ }
+ }
+
+ private void notifyListenerCanceled(Listener listener) {
+ try {
+ listener.executionCanceled(this);
+ } catch (Throwable ex) {
+ this.exceptionHandler.handleException(ex);
+ }
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java
index 6362a3de06..ae50a2a992 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2016 Oracle. 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.
@@ -82,7 +82,7 @@ public class RepeatingJobCommandWrapper
* starting with the initial invocation. The list is cleared with each
* initial invocation of the command.
*/
- private final ArrayList<StackTrace> stackTraces = debug() ? new ArrayList<StackTrace>() : null;
+ private final ArrayList<StackTrace> stackTraces = debug() ? new ArrayList<>() : null;
private static boolean debug() {
return JptCommonCorePlugin.instance().isDebugEnabled();
@@ -184,17 +184,21 @@ public class RepeatingJobCommandWrapper
* causing the command to execute again.
*/
/* CU private */ IStatus execute_(IProgressMonitor monitor) {
+ IStatus status = Status.OK_STATUS;
if (this.state.wasStoppedBeforeFirstExecutionCouldStart()) {
- return Status.OK_STATUS;
+ return status;
}
+ // if the command is canceled, suppress further executions
+ // (this will include any concurrent, unrelated invocations that might have slipped in);
+ // but keep looping, so we can leave 'state' in a consistent state
+ // (i.e. 'state' assumes we will call 'isRepeat()' until it returns false...)
do {
- IStatus status = this.executeCommand(monitor);
- if (status.getSeverity() == IStatus.CANCEL) {
- return status; // seems reasonable...
+ if (status.getSeverity() != IStatus.CANCEL) {
+ status = this.executeCommand(monitor);
}
} while (this.state.isRepeat());
- return Status.OK_STATUS;
+ return status;
}
/**
@@ -206,6 +210,9 @@ public class RepeatingJobCommandWrapper
try {
return this.command.execute(monitor);
} catch (OperationCanceledException ex) {
+ // capture where the cancel occurred;
+ // if we have an infinite loop, the stack trace may give us a hint of what is going on...
+ this.exceptionHandler.handleException(ex);
return Status.CANCEL_STATUS; // seems reasonable...
} catch (Throwable ex) {
this.exceptionHandler.handleException(ex);
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java
index fd4fb11243..0cd402eb04 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2016 Oracle. 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.
@@ -13,11 +13,15 @@ import java.util.EventListener;
/**
* Extend the repeating job command to support listeners that are notified
- * when an execution "cycle" is complete; i.e. the job command has,
- * for the moment, handled every execution request and quiesced.
- * This notification is <em>not</em> guaranteed to occur with <em>every</em>
- * execution "cycle"; since other, unrelated, executions can be triggered
- * concurrently, causing the "cycle" to continue.
+ * when:
+ * <ul>
+ * <li>an execution "cycle" is complete; i.e. the job command has,
+ * for the moment, handled every execution request and quiesced
+ * (This notification is <em>not</em> guaranteed to occur with <em>every</em>
+ * execution "cycle"; since other, unrelated, executions can be triggered
+ * concurrently, causing the "cycle" to continue.)
+ * <li>the job command has been canceled (typically by a user)
+ * </ul>
* <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
@@ -54,5 +58,10 @@ public interface NotifyingRepeatingJobCommand
* The specified job command has quiesced.
*/
void executionQuiesced(JobCommand command);
+
+ /**
+ * The specified job command has been canceled.
+ */
+ void executionCanceled(JobCommand command);
}
}

Back to the top