Author: adietish
Date: 2010-11-09 08:08:40 -0500 (Tue, 09 Nov 2010)
New Revision: 26361
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
Log:
[JBIDE-7518] cleanup code duplication (imageFilter and instanceFilter creation)
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-11-09
13:06:17 UTC (rev 26360)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-11-09
13:08:40 UTC (rev 26361)
@@ -74,18 +74,8 @@
this.name = name;
this.username = username;
this.type = type;
- imageFilter = new ImageFilter();
- try {
- imageFilter.setRules(imageFilterRules);
- } catch (PatternSyntaxException e) {
- imageFilter.setRules(IImageFilter.ALL_STRING);
- }
- instanceFilter = new InstanceFilter();
- try {
- instanceFilter.setRules(instanceFilterRules);
- } catch (PatternSyntaxException e) {
- instanceFilter.setRules(IInstanceFilter.ALL_STRING);
- }
+ imageFilter = createImageFilter(imageFilterRules);
+ instanceFilter = createInstanceFilter(instanceFilterRules);
if (persistent) {
storePassword(url, username, passwd);
}
@@ -100,7 +90,8 @@
this.type = type;
storePassword(url, username, passwd);
save();
- // TODO: remove notification with all instances, replace by notifying the changed
instance
+ // TODO: remove notification with all instances, replace by notifying
+ // the changed instance
notifyInstanceListListeners(instances.toArray(instances.toArray(new
DeltaCloudInstance[instances.size()])));
}
@@ -158,39 +149,60 @@
return instanceFilter;
}
- public void createInstanceFilter(String ruleString) {
+ public void updateInstanceFilter(String ruleString) {
String rules = getInstanceFilter().toString();
- if (IInstanceFilter.ALL_STRING.equals(ruleString))
- instanceFilter = new AllInstanceFilter();
- else {
- instanceFilter = new InstanceFilter();
- instanceFilter.setRules(ruleString);
- }
+ instanceFilter = createInstanceFilter(ruleString);
if (!rules.equals(ruleString)) {
save();
- // TODO: remove notification with all instances, replace by notifying the changed
instance
+ // TODO: remove notification with all instances, replace by
+ // notifying the changed instance
notifyInstanceListListeners(instances.toArray(instances.toArray(new
DeltaCloudInstance[instances.size()])));
}
}
+ private IInstanceFilter createInstanceFilter(String ruleString) {
+ IInstanceFilter instanceFilter = null;
+ if (IInstanceFilter.ALL_STRING.equals(ruleString))
+ instanceFilter = new AllInstanceFilter();
+ else {
+ try {
+ instanceFilter = new InstanceFilter();
+ instanceFilter.setRules(ruleString);
+ } catch (PatternSyntaxException e) {
+ instanceFilter.setRules(IInstanceFilter.ALL_STRING);
+ }
+ }
+ return instanceFilter;
+ }
+
public IImageFilter getImageFilter() {
return imageFilter;
}
- public void createImageFilter(String ruleString) {
+ public void updateImageFilter(String ruleString) {
String rules = getImageFilter().toString();
- if (IImageFilter.ALL_STRING.equals(ruleString))
- imageFilter = new AllImageFilter();
- else {
- imageFilter = new ImageFilter();
- imageFilter.setRules(ruleString);
- }
+ this.imageFilter = createImageFilter(ruleString);
if (!rules.equals(ruleString)) {
save();
notifyImageListListeners(getCurrImages());
}
}
+ private IImageFilter createImageFilter(String ruleString) {
+ IImageFilter imageFilter = null;
+ if (IImageFilter.ALL_STRING.equals(ruleString))
+ imageFilter = new AllImageFilter();
+ else {
+ try {
+ imageFilter = new ImageFilter();
+ imageFilter.setRules(ruleString);
+ } catch (PatternSyntaxException e) {
+ imageFilter.setRules(IImageFilter.ALL_STRING);
+ }
+ }
+ return imageFilter;
+ }
+
public void loadChildren() {
Thread t = new Thread(new Runnable() {
@@ -275,7 +287,8 @@
} catch (DeltaCloudClientException e) {
Activator.log(e);
}
- // TODO: remove notification with all instances, replace by notifying the changed
instance
+ // TODO: remove notification with all instances, replace by
+ // notifying the changed instance
DeltaCloudInstance[] instancesArray = instances.toArray(new
DeltaCloudInstance[instances.size()]);
notifyInstanceListListeners(instancesArray);
return instancesArray;
@@ -301,8 +314,10 @@
} catch (DeltaCloudException e) {
return null;
}
- // TODO: remove notification with all instances, replace by notifying the changed
instance
- DeltaCloudInstance[] instancesArray = instances.toArray(instances.toArray(new
DeltaCloudInstance[instances.size()]));
+ // TODO: remove notification with all instances, replace by notifying
+ // the changed instance
+ DeltaCloudInstance[] instancesArray = instances.toArray(instances.toArray(new
DeltaCloudInstance[instances
+ .size()]));
notifyInstanceListListeners(instancesArray);
return instancesArray;
}
@@ -337,9 +352,9 @@
if (!found) {
instances.add(instance);
}
- // TODO: remove notification with all instances, replace by notifying the changed
instance
- notifyInstanceListListeners(
- instances.toArray(instances.toArray(new DeltaCloudInstance[instances.size()])));
+ // TODO: remove notification with all instances, replace by
+ // notifying the changed instance
+ notifyInstanceListListeners(instances.toArray(instances.toArray(new
DeltaCloudInstance[instances.size()])));
}
}
@@ -379,8 +394,10 @@
boolean result = instance.performInstanceAction(actionId, client);
if (result) {
- // TODO: remove notification with all instances, replace by notifying the changed
instance
- notifyInstanceListListeners(instances.toArray(instances.toArray(new
DeltaCloudInstance[instances.size()])));
+ // TODO: remove notification with all instances, replace by
+ // notifying the changed instance
+ notifyInstanceListListeners(instances
+ .toArray(instances.toArray(new DeltaCloudInstance[instances.size()])));
}
return result;
} catch (DeltaCloudClientException e) {