Author: adietish
Date: 2010-12-15 09:49:01 -0500 (Wed, 15 Dec 2010)
New Revision: 27506
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ProfileComposite.java
Log:
cleanup
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ProfileComposite.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ProfileComposite.java 2010-12-15
14:10:23 UTC (rev 27505)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/ProfileComposite.java 2010-12-15
14:49:01 UTC (rev 27506)
@@ -30,12 +30,12 @@
* @author Jeff Johnston
*/
public class ProfileComposite {
-
+
private static final String CPU_LABEL = "Cpu.label"; //$NON-NLS-1$
private static final String MEMORY_LABEL = "Memory.label"; //$NON-NLS-1$
private static final String STORAGE_LABEL = "Storage.label"; //$NON-NLS-1$
private static final String DEFAULTED = "Defaulted"; //$NON-NLS-1$
-
+
private Composite container;
private DeltaCloudHardwareProfile profile;
private String cpu;
@@ -55,14 +55,14 @@
private Spinner storageSpinner;
private Combo storageCombo;
private int storageDecDigits;
-
- private int cw = 160;
-
+
+ private static int cw = 160;
+
private ModifyListener spinnerListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
- String value = ((Spinner)e.widget).getText();
+ String value = ((Spinner) e.widget).getText();
if (e.widget == cpuSpinner)
cpu = value;
else if (e.widget == memorySpinner)
@@ -72,12 +72,11 @@
}
};
-
private ModifyListener comboListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
- String value = ((Combo)e.widget).getText();
+ String value = ((Combo) e.widget).getText();
if (e.widget == cpuCombo)
cpu = value;
else if (e.widget == memoryCombo)
@@ -95,83 +94,140 @@
layout.marginHeight = 10;
layout.marginWidth = 10;
container.setLayout(layout);
- Control cpuControl = null;
- Control memoryControl = null;
- Control storageControl = null;
-
+
cpuLabel = new Label(container, SWT.NULL);
cpuLabel.setText(WizardMessages.getString(CPU_LABEL));
-
memoryLabel = new Label(container, SWT.NULL);
memoryLabel.setText(WizardMessages.getString(MEMORY_LABEL));
-
storageLabel = new Label(container, SWT.NULL);
storageLabel.setText(WizardMessages.getString(STORAGE_LABEL));
-
- DeltaCloudHardwareProperty cpuProperty = profile.getNamedProperty("cpu");
//$NON-NLS-1$
+
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
cpuLabel.setLayoutData(fd);
- if (cpuProperty != null) {
- if (cpuProperty.getKind() == DeltaCloudHardwareProperty.Kind.FIXED) {
- Label cpu = new Label(container, SWT.NULL);
- cpu.setText(cpuProperty.getValue());
+ DeltaCloudHardwareProperty cpuProperty = profile.getNamedProperty("cpu");
//$NON-NLS-1$
+ Control cpuControl = createCpuControls(cpuProperty, storageLabel, container);
+
+ fd = new FormData();
+ fd.left = new FormAttachment(cpuLabel, 0, SWT.LEFT);
+ fd.top = new FormAttachment(cpuLabel, 8);
+ memoryLabel.setLayoutData(fd);
+ DeltaCloudHardwareProperty memoryProperty =
profile.getNamedProperty("memory"); //$NON-NLS-1$
+ Control memoryControl = createMemoyControl(cpuControl, memoryProperty, storageLabel,
container);
+
+ fd = new FormData();
+ fd.left = new FormAttachment(cpuLabel, 0, SWT.LEFT);
+ fd.top = new FormAttachment(memoryControl, 8);
+ storageLabel.setLayoutData(fd);
+ DeltaCloudHardwareProperty storageProperty =
profile.getNamedProperty("storage"); //$NON-NLS-1$
+ createStorageControls(memoryControl, memoryProperty, storageProperty, container);
+ }
+
+ private Control createStorageControls(Control memoryControl, DeltaCloudHardwareProperty
memoryProperty,
+ DeltaCloudHardwareProperty storageProperty, Composite container) {
+ Control storageControl = null;
+ if (storageProperty != null) {
+ if (storageProperty.getKind() == DeltaCloudHardwareProperty.Kind.FIXED) {
+ Label storage = new Label(container, SWT.NULL);
+ storage.setText(storageProperty.getValue());
FormData f = new FormData();
f.left = new FormAttachment(storageLabel, 50);
- f.right = new FormAttachment(100, 0);
- cpu.setLayoutData(f);
- cpuControl = cpu;
- } else if (cpuProperty.getKind() == DeltaCloudHardwareProperty.Kind.RANGE) {
- cpuDefaultValue = cpuProperty.getValue();
- cpuSpinner = new Spinner(container, SWT.READ_ONLY);
- cpuSpinner.setMinimum(Integer.valueOf(cpuProperty.getRange().getFirst()));
- cpuSpinner.setMaximum(Integer.valueOf(cpuProperty.getRange().getLast()));
- cpuSpinner.addModifyListener(spinnerListener);
- cpuSpinner.setSelection(Integer.valueOf(cpuDefaultValue));
+ f.top = new FormAttachment(memoryControl, 8);
+ storage.setLayoutData(f);
+ storage.setVisible(true);
+ storageControl = storage;
+ } else if (storageProperty.getKind() == DeltaCloudHardwareProperty.Kind.RANGE) {
+ storageDefaultValue = storageProperty.getValue();
+ int indexDefault = storageDefaultValue.indexOf('.');
+ int decDigitsDefault = 0;
+ if (indexDefault >= 0) {
+ decDigitsDefault = storageDefaultValue.length() - indexDefault - 1;
+ storageDefaultValue = storageDefaultValue.replace(".", "");
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ Spinner storageSpinner = new Spinner(container, SWT.READ_ONLY | SWT.BORDER);
+ String first = memoryProperty.getRange().getFirst();
+ int indexFirst = first.indexOf('.');
+ int decDigitsFirst = 0;
+ if (indexFirst >= 0) {
+ decDigitsFirst = first.length() - indexFirst - 1;
+ first = first.replace(".", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ String last = memoryProperty.getRange().getLast();
+ int indexLast = first.indexOf('.');
+ int decDigitsLast = 0;
+ if (indexLast >= 0) {
+ decDigitsLast = last.length() - indexLast - 1;
+ last = last.replace(".", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ int decDigits = Math.max(decDigitsFirst, decDigitsLast);
+ storageDecDigits = Math.max(decDigits, decDigitsDefault);
+ if (decDigitsFirst < storageDecDigits) {
+ for (int i = 0; i < storageDecDigits - decDigitsFirst; ++i)
+ first = first.concat("0"); //$NON-NLS-1$
+ }
+ if (decDigitsLast < storageDecDigits) {
+ for (int i = 0; i < storageDecDigits - decDigitsLast; ++i)
+ last = last.concat("0"); //$NON-NLS-1$
+ }
+ if (decDigitsDefault < storageDecDigits) {
+ for (int i = 0; i < storageDecDigits - decDigitsLast; ++i)
+ storageDefaultValue = storageDefaultValue.concat("0"); //$NON-NLS-1$
+ }
+ storageSpinner.setMinimum(Integer.valueOf(first));
+ storageSpinner.setMaximum(Integer.valueOf(last));
+ storageSpinner.setDigits(storageDecDigits);
+ storageSpinner.addModifyListener(spinnerListener);
+ storageSpinner.setSelection(Integer.valueOf(storageDefaultValue));
FormData f = new FormData();
f.width = 80;
+ f.top = new FormAttachment(memoryControl, 5);
f.left = new FormAttachment(storageLabel, 50);
f.right = new FormAttachment(storageLabel, cw, SWT.RIGHT);
- cpuSpinner.setLayoutData(f);
- cpuControl = cpuSpinner;
- } else if (cpuProperty.getKind() == DeltaCloudHardwareProperty.Kind.ENUM) {
- cpuDefaultValue = cpuProperty.getValue();
- List<String> values = cpuProperty.getEnums();
- cpuCombo = new Combo(container, SWT.BORDER);
+ storageSpinner.setLayoutData(f);
+ storageControl = storageSpinner;
+ } else if (storageProperty.getKind() == DeltaCloudHardwareProperty.Kind.ENUM) {
+ storageDefaultValue = storageProperty.getValue();
+ List<String> values = storageProperty.getEnums();
+ storageCombo = new Combo(container, SWT.BORDER | SWT.READ_ONLY);
String[] items = new String[values.size()];
- cpuCombo.setItems(values.toArray(items));
- cpuCombo.setText(items[0]);
- cpuCombo.addModifyListener(comboListener);
+ storageCombo.setItems(values.toArray(items));
+ storageCombo.setText(items[0]);
+ storageCombo.addModifyListener(comboListener);
FormData f = new FormData();
f.width = 80;
f.left = new FormAttachment(storageLabel, 50);
f.right = new FormAttachment(storageLabel, cw, SWT.RIGHT);
- cpuCombo.setLayoutData(f);
- cpuControl = cpuCombo;
+ f.top = new FormAttachment(memoryControl, 5);
+ storageCombo.setLayoutData(f);
+ storageControl = storageCombo;
}
- String cpuUnit = cpuProperty.getUnit();
- if (cpuUnit != null && !cpuUnit.equals("label") &&
!cpuUnit.equals("count")) { //$NON-NLS-1$ //$NON-NLS-1$
+ String storageUnit = storageProperty.getUnit();
+ if (storageUnit != null && !storageUnit.equals("label")) {
//$NON-NLS-1$
Label unitLabel = new Label(container, SWT.NULL);
- unitLabel.setText(cpuProperty.getUnit());
+ unitLabel.setText(storageUnit);
FormData f = new FormData();
- f.left = new FormAttachment(cpuControl, 5);
+ f.left = new FormAttachment(storageControl, 3);
+ f.top = new FormAttachment(memoryControl, 8);
unitLabel.setLayoutData(f);
}
+
} else {
- Label cpu = new Label(container, SWT.NULL);
- cpu.setText(WizardMessages.getString(DEFAULTED));
+ Label storage = new Label(container, SWT.NULL);
+ storage.setText(WizardMessages.getString(DEFAULTED));
FormData f = new FormData();
f.left = new FormAttachment(storageLabel, 50);
+ f.top = new FormAttachment(memoryControl, 8);
f.right = new FormAttachment(100, 0);
- cpu.setLayoutData(f);
- cpuControl = cpu;
+ storage.setLayoutData(f);
+ storage.setVisible(true);
+ storageControl = storage;
}
- DeltaCloudHardwareProperty memoryProperty =
profile.getNamedProperty("memory"); //$NON-NLS-1$
- fd = new FormData();
- fd.left = new FormAttachment(cpuLabel, 0, SWT.LEFT);
- fd.top = new FormAttachment(cpuLabel, 8);
- memoryLabel.setLayoutData(fd);
+ return storageControl;
+ }
+
+ private Control createMemoyControl(Control cpuControl, DeltaCloudHardwareProperty
memoryProperty, Label storageLabel, Composite container) {
+ Control memoryControl = null;
if (memoryProperty != null) {
if (memoryProperty.getKind() == DeltaCloudHardwareProperty.Kind.FIXED) {
Label memory = new Label(container, SWT.NULL);
@@ -207,13 +263,13 @@
int decDigits = Math.max(decDigitsFirst, decDigitsLast);
memoryDecDigits = Math.max(decDigits, decDigitsDefault);
if (decDigitsFirst < memoryDecDigits) {
- for (int i= 0; i < memoryDecDigits - decDigitsFirst; ++i)
+ for (int i = 0; i < memoryDecDigits - decDigitsFirst; ++i)
first = first.concat("0"); //$NON-NLS-1$
- }
+ }
if (decDigitsLast < memoryDecDigits) {
for (int i = 0; i < memoryDecDigits - decDigitsLast; ++i)
last = last.concat("0"); //$NON-NLS-1$
- }
+ }
if (decDigitsDefault < memoryDecDigits) {
for (int i = 0; i < memoryDecDigits - decDigitsLast; ++i)
memoryDefaultValue = memoryDefaultValue.concat("0"); //$NON-NLS-1$
@@ -265,109 +321,68 @@
memory.setLayoutData(f);
memoryControl = memory;
}
- DeltaCloudHardwareProperty storageProperty =
profile.getNamedProperty("storage"); //$NON-NLS-1$
- fd = new FormData();
- fd.left = new FormAttachment(cpuLabel, 0, SWT.LEFT);
- fd.top = new FormAttachment(memoryControl, 8);
- storageLabel.setLayoutData(fd);
- if (storageProperty != null) {
- if (storageProperty.getKind() == DeltaCloudHardwareProperty.Kind.FIXED) {
- Label storage = new Label(container, SWT.NULL);
- storage.setText(storageProperty.getValue());
+ return memoryControl;
+ }
+
+ private Control createCpuControls(DeltaCloudHardwareProperty cpuProperty, Label
storageLabel, Composite container) {
+ Control cpuControl = null;
+ if (cpuProperty != null) {
+ if (cpuProperty.getKind() == DeltaCloudHardwareProperty.Kind.FIXED) {
+ Label cpu = new Label(container, SWT.NULL);
+ cpu.setText(cpuProperty.getValue());
FormData f = new FormData();
f.left = new FormAttachment(storageLabel, 50);
- f.top = new FormAttachment(memoryControl, 8);
- storage.setLayoutData(f);
- storage.setVisible(true);
- storageControl = storage;
- } else if (storageProperty.getKind() == DeltaCloudHardwareProperty.Kind.RANGE) {
- storageDefaultValue = storageProperty.getValue();
- int indexDefault = storageDefaultValue.indexOf('.');
- int decDigitsDefault = 0;
- if (indexDefault >= 0) {
- decDigitsDefault = storageDefaultValue.length() - indexDefault - 1;
- storageDefaultValue = storageDefaultValue.replace(".", "");
//$NON-NLS-1$ //$NON-NLS-2$
- }
- Spinner storageSpinner = new Spinner(container, SWT.READ_ONLY | SWT.BORDER);
- String first = memoryProperty.getRange().getFirst();
- int indexFirst = first.indexOf('.');
- int decDigitsFirst = 0;
- if (indexFirst >= 0) {
- decDigitsFirst = first.length() - indexFirst - 1;
- first = first.replace(".", ""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- String last = memoryProperty.getRange().getLast();
- int indexLast = first.indexOf('.');
- int decDigitsLast = 0;
- if (indexLast >= 0) {
- decDigitsLast = last.length() - indexLast - 1;
- last = last.replace(".", ""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- int decDigits = Math.max(decDigitsFirst, decDigitsLast);
- storageDecDigits = Math.max(decDigits, decDigitsDefault);
- if (decDigitsFirst < storageDecDigits) {
- for (int i= 0; i < storageDecDigits - decDigitsFirst; ++i)
- first = first.concat("0"); //$NON-NLS-1$
- }
- if (decDigitsLast < storageDecDigits) {
- for (int i = 0; i < storageDecDigits - decDigitsLast; ++i)
- last = last.concat("0"); //$NON-NLS-1$
- }
- if (decDigitsDefault < storageDecDigits) {
- for (int i = 0; i < storageDecDigits - decDigitsLast; ++i)
- storageDefaultValue = storageDefaultValue.concat("0"); //$NON-NLS-1$
- }
- storageSpinner.setMinimum(Integer.valueOf(first));
- storageSpinner.setMaximum(Integer.valueOf(last));
- storageSpinner.setDigits(storageDecDigits);
- storageSpinner.addModifyListener(spinnerListener);
- storageSpinner.setSelection(Integer.valueOf(storageDefaultValue));
+ f.right = new FormAttachment(100, 0);
+ cpu.setLayoutData(f);
+ cpuControl = cpu;
+ } else if (cpuProperty.getKind() == DeltaCloudHardwareProperty.Kind.RANGE) {
+ cpuDefaultValue = cpuProperty.getValue();
+ cpuSpinner = new Spinner(container, SWT.READ_ONLY);
+ cpuSpinner.setMinimum(Integer.valueOf(cpuProperty.getRange().getFirst()));
+ cpuSpinner.setMaximum(Integer.valueOf(cpuProperty.getRange().getLast()));
+ cpuSpinner.addModifyListener(spinnerListener);
+ cpuSpinner.setSelection(Integer.valueOf(cpuDefaultValue));
FormData f = new FormData();
f.width = 80;
- f.top = new FormAttachment(memoryControl, 5);
f.left = new FormAttachment(storageLabel, 50);
f.right = new FormAttachment(storageLabel, cw, SWT.RIGHT);
- storageSpinner.setLayoutData(f);
- storageControl = storageSpinner;
- } else if (storageProperty.getKind() == DeltaCloudHardwareProperty.Kind.ENUM) {
- storageDefaultValue = storageProperty.getValue();
- List<String> values = storageProperty.getEnums();
- storageCombo = new Combo(container, SWT.BORDER | SWT.READ_ONLY);
+ cpuSpinner.setLayoutData(f);
+ cpuControl = cpuSpinner;
+ } else if (cpuProperty.getKind() == DeltaCloudHardwareProperty.Kind.ENUM) {
+ cpuDefaultValue = cpuProperty.getValue();
+ List<String> values = cpuProperty.getEnums();
+ cpuCombo = new Combo(container, SWT.BORDER);
String[] items = new String[values.size()];
- storageCombo.setItems(values.toArray(items));
- storageCombo.setText(items[0]);
- storageCombo.addModifyListener(comboListener);
+ cpuCombo.setItems(values.toArray(items));
+ cpuCombo.setText(items[0]);
+ cpuCombo.addModifyListener(comboListener);
FormData f = new FormData();
f.width = 80;
f.left = new FormAttachment(storageLabel, 50);
f.right = new FormAttachment(storageLabel, cw, SWT.RIGHT);
- f.top = new FormAttachment(memoryControl, 5);
- storageCombo.setLayoutData(f);
- storageControl = storageCombo;
+ cpuCombo.setLayoutData(f);
+ cpuControl = cpuCombo;
}
- String storageUnit = storageProperty.getUnit();
- if (storageUnit != null && !storageUnit.equals("label")) {
//$NON-NLS-1$
+ String cpuUnit = cpuProperty.getUnit();
+ if (cpuUnit != null && !cpuUnit.equals("label") &&
!cpuUnit.equals("count")) { //$NON-NLS-1$ //$NON-NLS-1$
Label unitLabel = new Label(container, SWT.NULL);
- unitLabel.setText(storageUnit);
+ unitLabel.setText(cpuProperty.getUnit());
FormData f = new FormData();
- f.left = new FormAttachment(storageControl, 3);
- f.top = new FormAttachment(memoryControl, 8);
+ f.left = new FormAttachment(cpuControl, 5);
unitLabel.setLayoutData(f);
}
-
} else {
- Label storage = new Label(container, SWT.NULL);
- storage.setText(WizardMessages.getString(DEFAULTED));
+ Label cpu = new Label(container, SWT.NULL);
+ cpu.setText(WizardMessages.getString(DEFAULTED));
FormData f = new FormData();
f.left = new FormAttachment(storageLabel, 50);
- f.top = new FormAttachment(memoryControl, 8);
f.right = new FormAttachment(100, 0);
- storage.setLayoutData(f);
- storage.setVisible(true);
- storageControl = storage;
+ cpu.setLayoutData(f);
+ cpuControl = cpu;
}
+ return cpuControl;
}
-
+
public void setVisible(boolean visible) {
container.setVisible(visible);
}
@@ -377,14 +392,14 @@
return cpu;
return null;
}
-
+
public String getMemory() {
if (memory != null && !memory.equals(memoryDefaultValue)) {
return memory;
}
return null;
}
-
+
public String getStorage() {
if (storage != null && !storage.equals(storageDefaultValue)) {
return storage;