Author: adietish
Date: 2011-01-12 04:45:04 -0500 (Wed, 12 Jan 2011)
New Revision: 28118
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/WizardUtils.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPageModel.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysWizard.java
Log:
[JBIDE-8081] refreshing keys now uses the wizards progress monitor and disables the
widgets while refreshing is running
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2011-01-12 06:05:26
UTC (rev 28117)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2011-01-12 09:45:04
UTC (rev 28118)
@@ -1,3 +1,9 @@
+2011-01-12 André Dietisheim <André Dietisheim@adietisheim-thinkpad>
+
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPageModel.java
(asyncGetKeys):
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPage.java (refreshKeys):
+ [JBIDE-8081] refreshing keys now uses the wizards progress monitor and disables the
widgets while refreshing is running
+
2011-01-11 André Dietisheim <André Dietisheim@adietisheim-thinkpad>
* src/org/jboss/tools/deltacloud/ui/views/cloud/InstancesCategoryItem.java (filter):
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/WizardUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/WizardUtils.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/WizardUtils.java 2011-01-12
09:45:04 UTC (rev 28118)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.internal.deltacloud.ui.utils;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.CountDownLatch;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.IWizardContainer;
+
+/**
+ * @author André Dietisheim
+ */
+public class WizardUtils {
+
+ /**
+ * Runs the given job in the given wizard container. In order to have the
+ * wizard displaying a progress bar, you need to set
+ * Wizard#setNeedsProgressMonitor to <code>true</code>.
+ *
+ *
+ * @param job
+ * the job to run
+ * @param container
+ * the wizard container to run the job in
+ * @throws InvocationTargetException
+ * the invocation target exception
+ * @throws InterruptedException
+ * the interrupted exception
+ *
+ * @author André Dietisheim
+ */
+ public static void runInWizard(final Job job, 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);
+ final CountDownLatch latch = new CountDownLatch(1);
+ job.addJobChangeListener(new JobChangeAdapter() {
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ latch.countDown();
+ }
+ });
+ job.schedule();
+ latch.await();
+ monitor.done();
+ }
+ });
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/WizardUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPage.java 2011-01-12
06:05:26 UTC (rev 28117)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPage.java 2011-01-12
09:45:04 UTC (rev 28118)
@@ -19,6 +19,7 @@
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
@@ -41,6 +42,7 @@
import org.jboss.tools.deltacloud.ui.ErrorUtils;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.BoundObjectPresentConverter;
+import org.jboss.tools.internal.deltacloud.ui.utils.WizardUtils;
/**
* @author Jeff Johnston
@@ -121,6 +123,15 @@
setPageComplete(false);
}
+ private void refreshKeys() {
+ try {
+ Job job = model.refreshKeys();
+ WizardUtils.runInWizard(job, getContainer());
+ } catch (Exception e) {
+ // ignore since the job will report its failure
+ }
+ }
+
public DeltaCloudKey getKey() {
return model.getSelectedKey();
}
@@ -155,6 +166,8 @@
GridDataFactory.fillDefaults().applyTo(deleteButton);
setControl(container);
+
+ refreshKeys();
}
private Button createDeleteButton(Composite container, DataBindingContext dbc) {
@@ -191,38 +204,9 @@
BeanProperties.value(ManageKeysPageModel.PROP_SELECTED_KEY).observe(model),
new UpdateValueStrategy().setConverter(new Id2KeyConverter()),
new UpdateValueStrategy().setConverter(new Key2IdConverter()));
- bindKeyListEnablement(keyList, dbc);
return keyList;
}
- private void bindKeyListEnablement(final List keyList, DataBindingContext dbc) {
- dbc.bindValue(WidgetProperties.enabled().observe(keyList),
- BeanProperties.value(ManageKeysPageModel.PROP_KEYS).observe(model),
- new UpdateValueStrategy(UpdateSetStrategy.POLICY_NEVER),
- new UpdateValueStrategy().setConverter(new Converter(java.util.List.class,
Boolean.class) {
-
- @SuppressWarnings("rawtypes")
- @Override
- public Object convert(Object fromObject) {
- if (fromObject == null) {
- return false;
- }
- return ((java.util.List) fromObject).size() > 0;
- }
- }));
- //
BeanProperties.value(ManageKeysPageModel.PROP_KEYS).observe(model).addValueChangeListener(
- // new IValueChangeListener() {
- //
- // @Override
- // public void handleValueChange(ValueChangeEvent event) {
- // @SuppressWarnings("rawtypes")
- // boolean keysPresent = ((java.util.List)
- // event.diff.getNewValue()).size() > 0;
- // keyList.setEnabled(keysPresent);
- // }
- // });
- }
-
private SelectionAdapter onDeletePressed() {
return new SelectionAdapter() {
@Override
@@ -242,7 +226,7 @@
@Override
public void widgetSelected(SelectionEvent e) {
- model.refreshKeys();
+ refreshKeys();
}
};
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPageModel.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPageModel.java 2011-01-12
06:05:26 UTC (rev 28117)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysPageModel.java 2011-01-12
09:45:04 UTC (rev 28118)
@@ -18,6 +18,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
@@ -40,16 +41,12 @@
private List<DeltaCloudKey> keys = new ArrayList<DeltaCloudKey>();
private DeltaCloud cloud;
private DeltaCloudKey selectedKey;
-
+
public ManageKeysPageModel(DeltaCloud cloud) {
this.cloud = cloud;
- asyncGetKeys(cloud);
+ // asyncGetKeys(cloud);
}
- public void refreshKeys() {
- asyncGetKeys(cloud);
- }
-
public void deleteSelectedKey() throws DeltaCloudException {
if (selectedKey == null) {
return;
@@ -71,6 +68,10 @@
PemFileManager.create(key);
}
+ public Job refreshKeys() {
+ return asyncGetKeys();
+ }
+
public DeltaCloudKey getSelectedKey() {
return selectedKey;
}
@@ -99,12 +100,28 @@
setSelectedKey(key);
}
+ /**
+ * Sets the currently selected key or the the first key (in the available
+ * keys) as selected key.
+ */
+ public void setSelectedKey() {
+ DeltaCloudKey key = getSelectedKey();
+ if (key == null) {
+System.err.println("selected key = 0");
+ setSelectedKey(0);
+ } else {
+System.err.println("selected key = " + key);
+ setSelectedKey(key);
+ }
+ }
+
public List<DeltaCloudKey> getKeys() {
return keys;
}
public void setKeys(List<DeltaCloudKey> newKeys) {
- firePropertyChange(PROP_KEYS, keys, keys = newKeys);
+ firePropertyChange(PROP_KEYS, this.keys, this.keys = newKeys);
+ setSelectedKey();
}
public DeltaCloudKey getKey(String keyId) {
@@ -122,25 +139,24 @@
return matchingKey;
}
- private void asyncGetKeys(final DeltaCloud cloud) {
- // TODO: internationalize strings
- new AbstractCloudElementJob("get keys", cloud, CLOUDELEMENT.KEYS) {
+ private Job asyncGetKeys() {
+ Job job = new AbstractCloudElementJob("Get keys", cloud, CLOUDELEMENT.KEYS)
{
protected IStatus doRun(IProgressMonitor monitor) throws Exception {
try {
- List<DeltaCloudKey> newKeys = new ArrayList<DeltaCloudKey>();
- newKeys.addAll(Arrays.asList(cloud.getKeys()));
+ java.util.List<DeltaCloudKey> newKeys = new ArrayList<DeltaCloudKey>();
+ newKeys.addAll(Arrays.asList(getCloud().getKeys()));
setKeys(newKeys);
- setSelectedKey(null);
return Status.OK_STATUS;
} catch (DeltaCloudException e) {
// TODO: internationalize strings
return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
- MessageFormat.format("Could not get keys from cloud {0}",
cloud.getName()), e);
+ MessageFormat.format("Could not get keys from cloud {0}",
getCloud().getName()), e);
}
}
- }.schedule();
+ };
+ job.schedule();
+ return job;
}
-
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysWizard.java 2011-01-12
06:05:26 UTC (rev 28117)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ManageKeysWizard.java 2011-01-12
09:45:04 UTC (rev 28118)
@@ -48,4 +48,10 @@
this.key = mainPage.getKey();
return true;
}
+
+ @Override
+ public boolean needsProgressMonitor() {
+ return true;
+ }
+
}