Author: jjohnstn
Date: 2010-08-18 19:59:05 -0400 (Wed, 18 Aug 2010)
New Revision: 24280
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstance.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
Log:
2010-08-18 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java (listChanged):
Get
the default display as there might not be a current one for the thread.
* src/org/jboss/tools/deltacloud/ui/views/ImageView.java (listChanged): Make this run
under Display sync thread.
* src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java (Column):
* src/org/jboss/tools/deltacloud/ui/views/InstanceView.java (listChanged): Make this run
under Display sync thread.
(PerformInstanceActionThread): Add expected state.
(PerformInstanceActionThread.run): Look for expected state or cancelled or
instance because low-level refreshInstance may return a new DeltaCloudInstance.
TERMINATED to stop loop. Try syncExec method of Display thread.
(refreshInstance): Change logic to look at id rather than comparing actual
* src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
(getColumnText): Add
check for null instance.
(Column): Change the column weights.
* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstance.java (performFinish):
Fix logic
to start watching job.
(WatchCreateJob.run): Watch job as long as it is PENDING.
* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
(createControl): Use the
realm id plus its name in the combo box because the name can be duplicated.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-08-18 22:17:46
UTC (rev 24279)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-08-18 23:59:05
UTC (rev 24280)
@@ -1,3 +1,26 @@
+2010-08-18 Jeff Johnston <jjohnstn(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java (listChanged):
Get
+ the default display as there might not be a current one for the thread.
+ * src/org/jboss/tools/deltacloud/ui/views/ImageView.java (listChanged): Make this run
+ under Display sync thread.
+ * src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
(Column):
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceView.java (listChanged): Make this
run
+ under Display sync thread.
+ (PerformInstanceActionThread): Add expected state.
+ (PerformInstanceActionThread.run): Look for expected state or cancelled or
+ instance because low-level refreshInstance may return a new DeltaCloudInstance.
+ TERMINATED to stop loop. Try syncExec method of Display thread.
+ (refreshInstance): Change logic to look at id rather than comparing actual
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
(getColumnText): Add
+ check for null instance.
+ (Column): Change the column weights.
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstance.java (performFinish):
Fix logic
+ to start watching job.
+ (WatchCreateJob.run): Watch job as long as it is PENDING.
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
(createControl): Use the
+ realm id plus its name in the combo box because the name can be duplicated.
+
2010-08-17 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/ui/views/CVPropertySection.java: New file.
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-08-18
22:17:46 UTC (rev 24279)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-08-18
23:59:05 UTC (rev 24280)
@@ -52,7 +52,7 @@
addChild(element);
}
initialized = true;
- Display.getCurrent().asyncExec(new Runnable() {
+ Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
((TreeViewer)viewer).refresh(category, false);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-08-18
22:17:46 UTC (rev 24279)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-08-18
23:59:05 UTC (rev 24280)
@@ -355,10 +355,18 @@
}
public void listChanged(DeltaCloudImage[] list) {
- currCloud.removeImageListListener(parentView);
- viewer.setInput(list);
- currCloud.addImageListListener(parentView);
- viewer.refresh();
+ final DeltaCloudImage[] finalList = list;
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ currCloud.removeImageListListener(parentView);
+ viewer.setInput(finalList);
+ currCloud.addImageListListener(parentView);
+ viewer.refresh();
+ }
+
+ });
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java 2010-08-18
22:17:46 UTC (rev 24279)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java 2010-08-18
23:59:05 UTC (rev 24280)
@@ -18,10 +18,10 @@
private DeltaCloudImage[] images;
public enum Column {
- NAME(0, 30),
+ NAME(0, 20),
ID(1, 20),
ARCH(2, 20),
- DESC(3, 30);
+ DESC(3, 40);
private int column;
private int weight;
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-08-18
22:17:46 UTC (rev 24279)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-08-18
23:59:05 UTC (rev 24280)
@@ -46,6 +46,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
import org.jboss.tools.deltacloud.core.ICloudManagerListener;
@@ -85,6 +86,7 @@
private Action rebootAction;
private Map<String, Action> instanceActions;
+ private Map<String, Job> currentPerformingActions = new HashMap<String,
Job>();
private InstanceView parentView;
@@ -297,14 +299,16 @@
private DeltaCloudInstance instance;
private String action;
private String taskName;
+ private String expectedState;
public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
- String action, String title, String taskName) {
+ String action, String title, String taskName, String expectedState) {
super(title);
this.cloud = cloud;
this.instance = instance;
this.action = action;
this.taskName = taskName;
+ this.expectedState = expectedState;
}
@Override
@@ -312,13 +316,35 @@
try {
pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
pm.worked(1);
+ // To handle the user starting a new action when we haven't confirmed the last
one yet,
+ // cancel the previous job and then go on performing this action
+ Job job = currentPerformingActions.get(instance.getId());
+ if (job != null) {
+ job.cancel();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // do nothing, this is ok
+ }
+ }
+ currentPerformingActions.put(instance.getId(), this);
cloud.performInstanceAction(instance.getId(), action);
- Display.getDefault().asyncExec(new Runnable() {
+ Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
- refreshInstance(instance);
+ while (instance != null && !(instance.getState().equals(expectedState))
+ && !(instance.getState().equals(DeltaCloudInstance.TERMINATED))) {
+ instance = refreshInstance(instance);
+ try {
+ Thread.sleep(300);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
}
});
+ } catch (DeltaCloudException e) {
+ // do nothing..action had problem executing..perhaps illegal
} finally {
pm.done();
}
@@ -371,7 +397,8 @@
DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.START,
CVMessages.getString(STARTING_INSTANCE_TITLE),
- CVMessages.getFormattedString(STARTING_INSTANCE_MSG, new
String[]{instance.getName()}));
+ CVMessages.getFormattedString(STARTING_INSTANCE_MSG, new
String[]{instance.getName()}),
+ DeltaCloudInstance.RUNNING);
t.setUser(true);
t.schedule();
}
@@ -385,7 +412,8 @@
DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.STOP,
CVMessages.getString(STOPPING_INSTANCE_TITLE),
- CVMessages.getFormattedString(STOPPING_INSTANCE_MSG, new
String[]{instance.getName()}));
+ CVMessages.getFormattedString(STOPPING_INSTANCE_MSG, new
String[]{instance.getName()}),
+ DeltaCloudInstance.STOPPED);
t.setUser(true);
t.schedule();
}
@@ -399,7 +427,8 @@
DeltaCloudInstance instance =
(DeltaCloudInstance)((IStructuredSelection)selection).getFirstElement();
PerformInstanceActionThread t = new PerformInstanceActionThread(currCloud, instance,
DeltaCloudInstance.REBOOT,
CVMessages.getString(REBOOTING_INSTANCE_TITLE),
- CVMessages.getFormattedString(REBOOTING_INSTANCE_MSG, new
String[]{instance.getName()}));
+ CVMessages.getFormattedString(REBOOTING_INSTANCE_MSG, new
String[]{instance.getName()}),
+ DeltaCloudInstance.RUNNING);
t.setUser(true);
t.schedule();
}
@@ -428,15 +457,15 @@
instanceActions.put(DeltaCloudInstance.DESTROY, destroyAction);
}
- private void refreshInstance(DeltaCloudInstance instance) {
+ private DeltaCloudInstance refreshInstance(DeltaCloudInstance instance) {
DeltaCloudInstance[] instances =
(DeltaCloudInstance[])contentProvider.getElements(currCloud);
for (int i = 0; i < instances.length; ++i) {
DeltaCloudInstance d = instances[i];
- if (d == instance) {
- currCloud.refreshInstance(d.getId());
- break;
+ if (d.getId().equals(instance.getId())) {
+ return currCloud.refreshInstance(d.getId());
}
}
+ return null;
}
private void hookDoubleClickAction() {
@@ -501,10 +530,19 @@
}
public void listChanged(DeltaCloudInstance[] list) {
- currCloud.removeInstanceListListener(parentView);
- viewer.setInput(list);
- currCloud.addInstanceListListener(parentView);
- viewer.refresh();
+ // Run following under Display thread since this can be
+ // triggered by a non-display thread notifying listeners.
+ final DeltaCloudInstance[] finalList = list;
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ currCloud.removeInstanceListListener(parentView);
+ viewer.setInput(finalList);
+ currCloud.addInstanceListListener(parentView);
+ viewer.refresh();
+ }
+ });
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-08-18
22:17:46 UTC (rev 24279)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-08-18
23:59:05 UTC (rev 24280)
@@ -18,10 +18,10 @@
private DeltaCloudInstance[] instances;
public enum Column {
- NAME(0, 30),
+ NAME(0, 20),
ID(1, 20),
STATUS(2, 20),
- HOSTNAME(3, 30);
+ HOSTNAME(3, 40);
private int column;
private int weight;
@@ -88,15 +88,17 @@
public String getColumnText(Object element, int columnIndex) {
Column c = Column.getColumn(columnIndex);
DeltaCloudInstance i = (DeltaCloudInstance)element;
- switch (c) {
- case NAME:
- return i.getName();
- case ID:
- return i.getId();
- case STATUS:
- return i.getState();
- case HOSTNAME:
- return i.getHostName();
+ if (i != null) {
+ switch (c) {
+ case NAME:
+ return i.getName();
+ case ID:
+ return i.getId();
+ case STATUS:
+ return i.getState();
+ case HOSTNAME:
+ return i.getHostName();
+ }
}
return "";
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstance.java 2010-08-18
22:17:46 UTC (rev 24279)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstance.java 2010-08-18
23:59:05 UTC (rev 24280)
@@ -16,6 +16,7 @@
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.deltacloud.core.DeltaCloudManager;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
import org.osgi.service.prefs.Preferences;
@@ -77,7 +78,7 @@
boolean finished = false;
while (!finished && !pm.isCanceled()) {
DeltaCloudInstance instance = cloud.refreshInstance(instanceId);
- if (!instance.getState().equals(DeltaCloudInstance.PENDING))
+ if (instance != null &&
!instance.getState().equals(DeltaCloudInstance.PENDING))
break;
Thread.sleep(400);
}
@@ -85,6 +86,14 @@
} catch (Exception e) {
// do nothing
} finally {
+ if (!pm.isCanceled()) {
+ // cause a refresh to occur to all instance watchers
+ // NOTE: this could be done also by getting current
+ // instances and refreshing the one instance, but this
+ // method is already being run in a job and we might
+ // as well get updates for all instances
+ cloud.getInstances();
+ }
pm.done();
}
return Status.OK_STATUS;
@@ -134,9 +143,9 @@
instance = cloud.createInstance(name, imageId, realmId, profileId, memory, storage);
if (instance != null)
result = true;
- final String instanceId = instance.getId();
- final String instanceName = name;
- if (instance != null &&
!instance.getState().equals(DeltaCloudInstance.PENDING)) {
+ if (instance != null &&
instance.getState().equals(DeltaCloudInstance.PENDING)) {
+ final String instanceId = instance.getId();
+ final String instanceName = name;
Job job = new WatchCreateJob(WizardMessages.getString(STARTING_INSTANCE_TITLE),
cloud, instanceId, instanceName);
job.setUser(true);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-08-18
22:17:46 UTC (rev 24279)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-08-18
23:59:05 UTC (rev 24280)
@@ -186,7 +186,7 @@
for (int i = 0; i < realms.length; ++i) {
DeltaCloudRealm r = realms[i];
if (r.getState() == null || r.getState().equals(DeltaCloudRealm.AVAILABLE)) {
- realmNames.add(r.getName());
+ realmNames.add(r.getId() + " [" + r.getName() + "]");
//$NON-NLS-1$ //$NON-NLS-2$
realmIds.add(r.getId());
}
}