Author: adietish
Date: 2010-12-13 04:25:26 -0500 (Mon, 13 Dec 2010)
New Revision: 27395
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromAnyImageHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromSpecificImageHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudInstancePropertyTester.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudPropertyTester.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler2.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstancePropertyTester.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml
Log:
[JBIDE-7864] added hasImages property tester, rename CreateInstanceHandler2 to
CreateInstanceFromAnyImage,renamed CreateInstanceHandler to
CreateInstanceFromSpecificImage
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-13 09:01:14
UTC (rev 27394)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-13 09:25:26
UTC (rev 27395)
@@ -1,3 +1,9 @@
+2010-12-13 André Dietisheim <adietish(a)redhat.com>
+
+ * plugin.xml:
+ [JBIDE-7864] added hasImages property tester, rename CreateInstanceHandler2 to
CreateInstanceFromAnyImage,
+ renamed CreateInstanceHandler to CreateInstanceFromSpecificImage
+
2010-12-10 André Dietisheim <adietish(a)redhat.com>
*
src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml 2010-12-13 09:01:14
UTC (rev 27394)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml 2010-12-13 09:25:26
UTC (rev 27395)
@@ -292,17 +292,19 @@
</enabledWhen>
</handler>
<handler
-
class="org.jboss.tools.deltacloud.ui.commands.CreateInstanceHandler2"
- commandId="org.jboss.tools.deltacloud.ui.createinstance2">
+
class="org.jboss.tools.deltacloud.ui.commands.CreateInstanceFromAnyImageHandler"
+
commandId="org.jboss.tools.deltacloud.ui.createinstanceFromAnyImage">
<activeWhen>
- <with
- variable="selection">
- <iterate>
- <instanceof
-
value="org.jboss.tools.deltacloud.ui.views.cloud.DeltaCloudViewItem">
- </instanceof>
- </iterate>
- </with>
+ <with
+ variable="selection">
+ <iterate operator="and">
+ <adapt
+ type="org.jboss.tools.deltacloud.core.DeltaCloud">
+ <test property="org.jboss.tools.deltacloud.ui.commands.hasImages"
+ value="true"/>
+ </adapt>
+ </iterate>
+ </with>
</activeWhen>
<enabledWhen>
<with
@@ -316,8 +318,8 @@
point="org.eclipse.ui.handlers">
<!-- image command handlers -->
<handler
-
class="org.jboss.tools.deltacloud.ui.commands.CreateInstanceHandler"
- commandId="org.jboss.tools.deltacloud.ui.createinstance">
+
class="org.jboss.tools.deltacloud.ui.commands.CreateInstanceFromSpecificImageHandler"
+
commandId="org.jboss.tools.deltacloud.ui.createinstanceFromSpecificImage">
<activeWhen>
<with
variable="selection">
@@ -664,7 +666,7 @@
locationURI="popup:org.jboss.tools.deltacloud.ui.views.DeltaCloudView?after=images">
<!-- image commands -->
<command
- commandId="org.jboss.tools.deltacloud.ui.createinstance"
+
commandId="org.jboss.tools.deltacloud.ui.createinstanceFromSpecificImage"
icon="icons/instance.gif"
label="%command.createinstance.label"
style="push"
@@ -687,7 +689,7 @@
locationURI="popup:org.jboss.tools.deltacloud.ui.views.DeltaCloudView?after=images">
<!-- image commands -->
<command
- commandId="org.jboss.tools.deltacloud.ui.createinstance2"
+
commandId="org.jboss.tools.deltacloud.ui.createinstanceFromAnyImage"
icon="icons/instance.gif"
label="%command.createinstance.label"
style="push"
@@ -763,7 +765,7 @@
locationURI="popup:org.jboss.tools.deltacloud.ui.views.ImageView?after=images">
<!-- image commands -->
<command
- commandId="org.jboss.tools.deltacloud.ui.createinstance"
+
commandId="org.jboss.tools.deltacloud.ui.createinstanceFromSpecificImage"
icon="icons/instance.gif"
label="%command.createinstance.label"
style="push"
@@ -810,13 +812,13 @@
</command>
<command
description="%command.createinstance.description"
- id="org.jboss.tools.deltacloud.ui.createinstance2"
+ id="org.jboss.tools.deltacloud.ui.createinstanceFromAnyImage"
name="%command.createinstance.name">
</command>
<!-- image commands -->
<command
description="%command.createinstance.description"
- id="org.jboss.tools.deltacloud.ui.createinstance"
+ id="org.jboss.tools.deltacloud.ui.createinstanceFromSpecificImage"
name="%command.createinstance.name">
</command>
<!-- instance commands -->
@@ -860,12 +862,19 @@
</extension>
<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
- class="org.jboss.tools.deltacloud.ui.commands.InstancePropertyTester"
+ class="org.jboss.tools.deltacloud.ui.commands.DeltaCloudInstancePropertyTester"
id="org.jboss.tools.deltacloud.ui.commands.instancepropertytester"
namespace="org.jboss.tools.deltacloud.ui.commands"
properties="canStart,canStop,canReboot,canDestroy,isRunning"
type="org.jboss.tools.deltacloud.core.DeltaCloudInstance">
</propertyTester>
+ <propertyTester
+ class="org.jboss.tools.deltacloud.ui.commands.DeltaCloudPropertyTester"
+ id="org.jboss.tools.deltacloud.ui.commands.cloudpropertytester"
+ namespace="org.jboss.tools.deltacloud.ui.commands"
+ properties="hasImages"
+ type="org.jboss.tools.deltacloud.core.DeltaCloud">
+ </propertyTester>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromAnyImageHandler.java
(from rev 27393,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler2.java)
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromAnyImageHandler.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromAnyImageHandler.java 2010-12-13
09:25:26 UTC (rev 27395)
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.deltacloud.ui.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
+import org.jboss.tools.internal.deltacloud.ui.wizards.NewInstanceWizard;
+
+/**
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public class CreateInstanceFromAnyImageHandler extends AbstractHandler implements
IHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ DeltaCloud cloud = UIUtils.getFirstAdaptedElement(selection, DeltaCloud.class);
+ IWizard wizard = new NewInstanceWizard(cloud);
+ WizardDialog dialog = new WizardDialog(UIUtils.getActiveWorkbenchWindow().getShell(),
+ wizard);
+ dialog.create();
+ dialog.open();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromAnyImageHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromSpecificImageHandler.java
(from rev 27269,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler.java)
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromSpecificImageHandler.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromSpecificImageHandler.java 2010-12-13
09:25:26 UTC (rev 27395)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.deltacloud.ui.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudImage;
+import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
+import org.jboss.tools.internal.deltacloud.ui.wizards.NewInstanceWizard;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class CreateInstanceFromSpecificImageHandler extends AbstractHandler implements
IHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ DeltaCloudImage deltaCloudImage = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudImage.class);
+ createInstance(deltaCloudImage, HandlerUtil.getActiveShell(event));
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ private void createInstance(DeltaCloudImage deltaCloudImage, Shell shell) {
+ if (deltaCloudImage != null) {
+ DeltaCloud deltaCloud = deltaCloudImage.getDeltaCloud();
+ IWizard wizard = new NewInstanceWizard(deltaCloud, deltaCloudImage);
+ WizardDialog dialog = new WizardDialog(shell, wizard);
+ dialog.create();
+ dialog.open();
+ }
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceFromSpecificImageHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler.java 2010-12-13
09:01:14 UTC (rev 27394)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler.java 2010-12-13
09:25:26 UTC (rev 27395)
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * 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.deltacloud.ui.commands;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.core.DeltaCloudImage;
-import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
-import org.jboss.tools.internal.deltacloud.ui.wizards.NewInstanceWizard;
-
-/**
- * @author Andre Dietisheim
- */
-public class CreateInstanceHandler extends AbstractHandler implements IHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- DeltaCloudImage deltaCloudImage = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudImage.class);
- createInstance(deltaCloudImage, HandlerUtil.getActiveShell(event));
- }
-
- return Status.OK_STATUS;
- }
-
- private void createInstance(DeltaCloudImage deltaCloudImage, Shell shell) {
- if (deltaCloudImage != null) {
- DeltaCloud deltaCloud = deltaCloudImage.getDeltaCloud();
- IWizard wizard = new NewInstanceWizard(deltaCloud, deltaCloudImage);
- WizardDialog dialog = new WizardDialog(shell, wizard);
- dialog.create();
- dialog.open();
- }
- }
-}
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler2.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler2.java 2010-12-13
09:01:14 UTC (rev 27394)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CreateInstanceHandler2.java 2010-12-13
09:25:26 UTC (rev 27395)
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * 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.deltacloud.ui.commands;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.ui.views.cloud.CloudItem;
-import org.jboss.tools.deltacloud.ui.views.cloud.DeltaCloudViewItem;
-import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
-import org.jboss.tools.internal.deltacloud.ui.wizards.NewInstanceWizard;
-
-/**
- * @author Jeff Johnston
- */
-public class CreateInstanceHandler2 extends AbstractHandler implements IHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- DeltaCloudViewItem<?> element = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudViewItem.class);
- while (element != null && !(element instanceof CloudItem)) {
- element = (DeltaCloudViewItem<?>) element.getParent();
- }
- if (element != null) {
- CloudItem cloudElement = (CloudItem) element;
- DeltaCloud cloud = (DeltaCloud) cloudElement.getModel();
- IWizard wizard = new NewInstanceWizard(cloud);
- WizardDialog dialog = new
WizardDialog(UIUtils.getActiveWorkbenchWindow().getShell(),
- wizard);
- dialog.create();
- dialog.open();
- }
- }
-
- return Status.OK_STATUS;
- }
-
-}
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudInstancePropertyTester.java
(from rev 27269,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstancePropertyTester.java)
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudInstancePropertyTester.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudInstancePropertyTester.java 2010-12-13
09:25:26 UTC (rev 27395)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.deltacloud.ui.commands;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.runtime.Assert;
+import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
+
+/**
+ * A property tester for the command framework that answers if the given
+ * instance is stopped
+ *
+ * @author Andre Dietisheim
+ */
+public class DeltaCloudInstancePropertyTester extends PropertyTester {
+
+ private static final String PROPERTY_ACTION_CANSTART = "canStart";
+ private static final String PROPERTY_ACTION_CANSTOP = "canStop";
+ private static final String PROPERTY_ACTION_CANREBOOT = "canReboot";
+ private static final String PROPERTY_ACTION_CANDESTROY = "canDestroy";
+ private static final String PROPERTY_ACTION_ISRUNNING = "isRunning";
+
+ @Override
+ public boolean test(Object receiver, String property, Object[] args, Object
expectedValue) {
+ DeltaCloudInstance instance = UIUtils.adapt(receiver, DeltaCloudInstance.class);
+ if (instance == null) {
+ return false;
+ }
+
+ if (PROPERTY_ACTION_CANSTART.equals(property)) {
+ return equalsExpectedValue(instance.canStart(), expectedValue);
+ }
+ else if (PROPERTY_ACTION_CANSTOP.equals(property)) {
+ return equalsExpectedValue(instance.canStop(), expectedValue);
+ }
+ else if (PROPERTY_ACTION_CANREBOOT.equals(property)) {
+ return equalsExpectedValue(instance.canReboot(), expectedValue);
+ }
+ else if (PROPERTY_ACTION_CANDESTROY.equals(property)) {
+ return equalsExpectedValue(instance.canDestroy(), expectedValue);
+ }
+ else if (PROPERTY_ACTION_ISRUNNING.equals(property)) {
+ return equalsExpectedValue(instance.isRunning(), expectedValue);
+ }
+ return false;
+ }
+
+ private boolean equalsExpectedValue(boolean propertyValue, Object expectedValue) {
+ Assert.isTrue(expectedValue instanceof Boolean);
+ Boolean expectedBoolean = (Boolean) expectedValue;
+ return expectedBoolean.equals(propertyValue);
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudInstancePropertyTester.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudPropertyTester.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudPropertyTester.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudPropertyTester.java 2010-12-13
09:25:26 UTC (rev 27395)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.deltacloud.ui.commands;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.runtime.Assert;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import org.jboss.tools.deltacloud.core.DeltaCloudImage;
+import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
+
+/**
+ * A property tester for the command framework that answers if the given
+ * DeltaCloud has images
+ *
+ * @author Andre Dietisheim
+ */
+public class DeltaCloudPropertyTester extends PropertyTester {
+
+ private static final String PROPERTY_HAS_IMAGES = "hasImages";
+
+ @Override
+ public boolean test(Object receiver, String property, Object[] args, Object
expectedValue) {
+ DeltaCloud cloud = UIUtils.adapt(receiver, DeltaCloud.class);
+ if (cloud == null) {
+ return false;
+ }
+
+ if (PROPERTY_HAS_IMAGES.equals(property)) {
+ return equalsExpectedValue(getImages(cloud), true);
+ }
+ return false;
+ }
+
+ private DeltaCloudImage[] getImages(DeltaCloud cloud) {
+ try {
+ return cloud.getImages();
+ } catch (DeltaCloudException e) {
+ return new DeltaCloudImage[] {};
+ }
+ }
+
+ private boolean equalsExpectedValue(DeltaCloudImage[] images, Object expectedValue) {
+ Assert.isTrue(expectedValue instanceof Boolean);
+ Boolean expectedBoolean = (Boolean) expectedValue;
+ return expectedBoolean.equals(images.length > 0);
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DeltaCloudPropertyTester.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstancePropertyTester.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstancePropertyTester.java 2010-12-13
09:01:14 UTC (rev 27394)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/InstancePropertyTester.java 2010-12-13
09:25:26 UTC (rev 27395)
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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.deltacloud.ui.commands;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.runtime.Assert;
-import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
-
-/**
- * A property tester for the command framework that answers if the given
- * instance is stopped
- *
- * @author Andre Dietisheim
- */
-public class InstancePropertyTester extends PropertyTester {
-
- private static final String PROPERTY_ACTION_CANSTART = "canStart";
- private static final String PROPERTY_ACTION_CANSTOP = "canStop";
- private static final String PROPERTY_ACTION_CANREBOOT = "canReboot";
- private static final String PROPERTY_ACTION_CANDESTROY = "canDestroy";
- private static final String PROPERTY_ACTION_ISRUNNING = "isRunning";
-
- @Override
- public boolean test(Object receiver, String property, Object[] args, Object
expectedValue) {
- DeltaCloudInstance instance = UIUtils.adapt(receiver, DeltaCloudInstance.class);
- if (instance == null) {
- return false;
- }
-
- if (PROPERTY_ACTION_CANSTART.equals(property)) {
- return equalsExpectedValue(instance.canStart(), expectedValue);
- }
- else if (PROPERTY_ACTION_CANSTOP.equals(property)) {
- return equalsExpectedValue(instance.canStop(), expectedValue);
- }
- else if (PROPERTY_ACTION_CANREBOOT.equals(property)) {
- return equalsExpectedValue(instance.canReboot(), expectedValue);
- }
- else if (PROPERTY_ACTION_CANDESTROY.equals(property)) {
- return equalsExpectedValue(instance.canDestroy(), expectedValue);
- }
- else if (PROPERTY_ACTION_ISRUNNING.equals(property)) {
- return equalsExpectedValue(instance.isRunning(), expectedValue);
- }
- return false;
- }
-
- private boolean equalsExpectedValue(boolean propertyValue, Object expectedValue) {
- Assert.isTrue(expectedValue instanceof Boolean);
- Boolean expectedBoolean = (Boolean) expectedValue;
- return expectedBoolean.equals(propertyValue);
- }
-
-}