Author: adietish
Date: 2011-12-21 14:28:55 -0500 (Wed, 21 Dec 2011)
New Revision: 37499
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
Log:
[JBIDE-10549] implemented reporting of subtask when creating an OpenShift application.
other jobs are still not reporting.
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java 2011-12-21
19:28:55 UTC (rev 37499)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * An IProgressMonitor that aggregates other monitors and delegates call to the monitors
+ * that were added to it.
+ *
+ * @author André Dietisheim
+ */
+public class DelegatingProgressMonitor implements IProgressMonitor {
+
+ List<IProgressMonitor> monitors = new
CopyOnWriteArrayList<IProgressMonitor>();
+
+ public void add(IProgressMonitor monitor) {
+ monitors.add(monitor);
+ }
+
+ @Override
+ public void subTask(final String name) {
+ doForAllMonitors(new IMonitorOperation() {
+
+ @Override
+ public void doWithMonitor(IProgressMonitor monitor) {
+ monitor.subTask(name);
+ }
+ });
+ }
+
+ @Override
+ public void beginTask(final String name, final int totalWork) {
+ doForAllMonitors(new IMonitorOperation() {
+
+ @Override
+ public void doWithMonitor(IProgressMonitor monitor) {
+ monitor.beginTask(name, totalWork);
+ }
+ });
+ }
+
+ @Override
+ public void done() {
+ doForAllMonitors(new IMonitorOperation() {
+
+ @Override
+ public void doWithMonitor(IProgressMonitor monitor) {
+ monitor.done();
+ }
+ });
+ }
+
+ @Override
+ public void internalWorked(final double work) {
+ doForAllMonitors(new IMonitorOperation() {
+
+ @Override
+ public void doWithMonitor(IProgressMonitor monitor) {
+ monitor.internalWorked(work);
+ }
+ });
+
+ }
+
+ @Override
+ public boolean isCanceled() {
+ for (IProgressMonitor monitor : monitors) {
+ if (monitor.isCanceled()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void setCanceled(final boolean value) {
+ doForAllMonitors(new IMonitorOperation() {
+
+ @Override
+ public void doWithMonitor(IProgressMonitor monitor) {
+ monitor.setCanceled(value);
+ }
+ });
+ }
+
+ @Override
+ public void setTaskName(final String name) {
+ doForAllMonitors(new IMonitorOperation() {
+
+ @Override
+ public void doWithMonitor(IProgressMonitor monitor) {
+ monitor.setTaskName(name);
+ }
+ });
+
+ }
+
+ @Override
+ public void worked(final int work) {
+ doForAllMonitors(new IMonitorOperation() {
+
+ @Override
+ public void doWithMonitor(IProgressMonitor monitor) {
+ monitor.worked(work);
+ }
+ });
+ }
+
+ private void doForAllMonitors(IMonitorOperation operation) {
+ for (IProgressMonitor monitor : monitors) {
+ operation.doWithMonitor(monitor);
+ }
+ }
+
+ private interface IMonitorOperation {
+ public void doWithMonitor(IProgressMonitor monitor);
+ }
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java 2011-12-21
19:10:54 UTC (rev 37498)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java 2011-12-21
19:28:55 UTC (rev 37499)
@@ -49,17 +49,33 @@
*/
public static void runInWizard(final Job job, IWizardContainer container) throws
InvocationTargetException,
InterruptedException {
+ runInWizard(job, null, container);
+ }
+
+ public static void runInWizard(final Job job, final DelegatingProgressMonitor
delegatingMonitor, IWizardContainer container) throws InvocationTargetException,
+ InterruptedException {
container.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- monitor.beginTask(job.getName(), IProgressMonitor.UNKNOWN);
+ if (delegatingMonitor == null) {
+ monitor.beginTask(job.getName(), IProgressMonitor.UNKNOWN);
+ } else {
+ delegatingMonitor.add(monitor);
+ delegatingMonitor.beginTask(job.getName(), IProgressMonitor.UNKNOWN);
+ }
+
job.schedule();
job.join();
- monitor.done();
+
+ if (delegatingMonitor == null) {
+ monitor.done();
+ } else {
+ delegatingMonitor.done();
+ }
}
});
}
-
+
/**
* Runs the given job in the given wizard container.
* <p>
@@ -89,6 +105,14 @@
dbc.updateModels();
}
+ public static void runInWizard(final Job job, IWizardContainer container,
DelegatingProgressMonitor monitor,
+ final DataBindingContext dbc)
+ throws InvocationTargetException, InterruptedException {
+ runInWizard(job, container);
+ dbc.updateTargets();
+ dbc.updateModels();
+ }
+
/**
* Flips to the next wizard page or finishes the current wizard.
*
@@ -106,7 +130,7 @@
}
}
}
-
+
public static int openWizardDialog(IWizard wizard, Shell shell) {
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.create();
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2011-12-21
19:10:54 UTC (rev 37498)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2011-12-21
19:28:55 UTC (rev 37499)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
@@ -63,8 +64,8 @@
this.cartridge = cartridge;
}
- public void createApplication() throws OpenShiftException {
- IApplication application = createApplication(name, cartridge);
+ public void createApplication(IProgressMonitor monitor) throws OpenShiftException {
+ IApplication application = createApplication(name, cartridge, monitor);
setApplication(application);
}
@@ -76,9 +77,10 @@
return application;
}
- public IApplication createApplication(String name, ICartridge cartridge) throws
OpenShiftException {
+ public IApplication createApplication(String name, ICartridge cartridge,
IProgressMonitor monitor) throws OpenShiftException {
+ monitor.subTask("Creating application...");
IApplication application = getUser().createApplication(name, cartridge);
- waitForAccessible(application);
+ waitForAccessible(application, monitor);
return application;
}
@@ -86,7 +88,8 @@
return user.hasApplication(name);
}
- private void waitForAccessible(IApplication application) throws
OpenShiftApplicationNotAvailableException, OpenShiftException {
+ private void waitForAccessible(IApplication application, IProgressMonitor monitor)
throws OpenShiftApplicationNotAvailableException, OpenShiftException {
+ monitor.subTask("Waiting for application to become accessible...");
if (!application.waitForAccessible(APP_CREATION_TIMEOUT * 1000)) {
throw new OpenShiftApplicationNotAvailableException(NLS.bind(
OpenShiftExpressUIMessages.HOSTNAME_NOT_ANSWERING,
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-12-21
19:10:54 UTC (rev 37498)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-12-21
19:28:55 UTC (rev 37499)
@@ -183,7 +183,7 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- IApplication jenkinsApplication = model.createJenkinsApplication(name);
+ IApplication jenkinsApplication = model.createJenkinsApplication(name, monitor);
model.getSelectedEmbeddableCartridges().add(cartridge);
openLogDialog(jenkinsApplication);
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-12-21
19:10:54 UTC (rev 37498)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-12-21
19:28:55 UTC (rev 37499)
@@ -18,6 +18,7 @@
import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.list.ListDiff;
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -93,8 +94,8 @@
return wizardModel.getApplication();
}
- public IApplication createJenkinsApplication(String name) throws OpenShiftException {
- return wizardModel.createApplication(name, ICartridge.JENKINS_14);
+ public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException {
+ return wizardModel.createApplication(name, ICartridge.JENKINS_14, monitor);
}
/**
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-12-21
19:10:54 UTC (rev 37498)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-12-21
19:28:55 UTC (rev 37499)
@@ -36,6 +36,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.ui.DelegatingProgressMonitor;
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -53,7 +54,8 @@
private ApplicationWizardModel wizardModel;
public NewApplicationWizardPage(ApplicationWizardModel wizardModel, IWizard wizard) {
- super("New OpenShift Express Application", "Select a name and an type
for your new OpenShift Express application",
+ super("New OpenShift Express Application",
+ "Select a name and an type for your new OpenShift Express application",
"NewOpenShiftExpressApplication", wizard);
this.wizardModel = wizardModel;
this.model = new NewApplicationWizardPageModel(wizardModel);
@@ -165,27 +167,31 @@
public boolean createApplication() {
final ArrayBlockingQueue<Boolean> applicationCreated = new
ArrayBlockingQueue<Boolean>(1);
+ final DelegatingProgressMonitor delegatingMonitor = new DelegatingProgressMonitor();
try {
- WizardUtils.runInWizard(new Job(NLS.bind("Creating application
\"{0}\"...", wizardModel.getName())) {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating application
\"{0}\"", wizardModel.getName())) {
@Override
protected IStatus run(IProgressMonitor monitor) {
+ delegatingMonitor.add(monitor);
try {
- wizardModel.createApplication();
+ wizardModel.createApplication(delegatingMonitor);
applicationCreated.offer(true);
return Status.OK_STATUS;
} catch (OpenShiftApplicationNotAvailableException e) {
applicationCreated.offer(false);
- return OpenShiftUIActivator.createErrorStatus(e.getMessage(), e,
- wizardModel.getName());
+ return OpenShiftUIActivator.createErrorStatus(
+ e.getMessage(), e, wizardModel.getName());
} catch (OpenShiftException e) {
applicationCreated.offer(false);
- return OpenShiftUIActivator.createErrorStatus("Could not create application
\"{0}\"", (Throwable)e,
- wizardModel.getName());
+ return OpenShiftUIActivator.createErrorStatus(
+ "Could not create application \"{0}\"",
+ (Throwable) e, wizardModel.getName());
}
}
- }, getContainer());
+ }, delegatingMonitor, getContainer());
} catch (Exception e) {
+ e.printStackTrace();
// ignore
}
return applicationCreated.poll();