Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBIDE-25091] corrected resource limit unit labels #1598

Merged
merged 1 commit into from Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/org.jboss.tools.openshift.ui/plugin.properties
Expand Up @@ -12,7 +12,7 @@ openshift.command.build.clonebuild = Clone Build
openshift.command.build.logs = Build Log...
openshift.command.build.showwebhooks = Show Webhooks...
openshift.command.deploymentconfig.deploy = Deploy Latest
openshift.command.deploymentconfig.editresourcelimits = Edit resource limits
openshift.command.deploymentconfig.editresourcelimits = Edit Resource Limits...
openshift.command.openwebconsole = Web Console
openshift.command.showproperties = Properties
openshift.command.pod.logs = Pod Log...
Expand Down
Expand Up @@ -15,7 +15,7 @@ InvalidHostNameErrorMessage=Invalid hostname {0}. Hostname must consist of lower
EmptyHostNameErrorMessage=Hostname is empty. OpenShift will therefore generate a hostname for you.
RoundRobinRoutingMessage=Ports will be load balanced by created route.

EditResourceLimitsPageTitle=Edit resource limits
EditResourceLimitsPageTitle=Edit Resource Limits
EditResourceLimitsPageDescription=Edit the resource requirements for deployment {0}
EditResourceLimitsJobTitle=Updating resource limits for {0}
EditResourceLimitsJobErrorMessage=Unable to update resource limits for {0}
Expand Down
Expand Up @@ -36,84 +36,114 @@
import org.jboss.tools.openshift.internal.ui.OpenShiftUIMessages;
import org.jboss.tools.openshift.internal.ui.wizard.common.EditResourceLimitsPageModel;

import com.openshift.restclient.model.IContainer;

public class EditResourceLimitsPage extends AbstractOpenShiftWizardPage {
public static final String[] MEMORY_SUFFIXES = {"M", "G", "Mi", "Gi", ""};
public static final String[] MEMORY_SUFFIXES_LABELS = {"MB", "GB", "MiB", "GiB", "MiB"};
public static final String[] CPU_SUFFIXES = {"m", "k", "M", "G", ""};
public static final String[] CPU_SUFFIXES_LABELS = {"millicores", "kcores", "Mcores", "Gcores", "cores"};

private EditResourceLimitsPageModel model;
public static final String[] MEMORY_SUFFIXES =
{ "M", "G", "Mi", "Gi", "" };
public static final String[] MEMORY_SUFFIXES_LABELS =
{ "MB (1000 KB)", "GB (1000 MB)", "MiB (1024 KB)", "GiB (1024 MB)", "bytes" };
public static final String[] CPU_SUFFIXES =
{ "m", "k", "M", "G", "" };
public static final String[] CPU_SUFFIXES_LABELS =
{ "millicores", "kcores", "Mcores", "Gcores", "cores" };

private EditResourceLimitsPageModel model;

public EditResourceLimitsPage(EditResourceLimitsPageModel model, IWizard wizard) {
super(OpenShiftUIMessages.EditResourceLimitsPageTitle,
NLS.bind(OpenShiftUIMessages.EditResourceLimitsPageDescription,
model.getUpdatedReplicationController().getName()),
"EditResourceLimitsPage", wizard);
this.model = model;
}

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().applyTo(parent);
final Composite dialogArea = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).grab(true, true)
.applyTo(dialogArea);
GridLayoutFactory.fillDefaults()
.numColumns(3).margins(10, 10).spacing(20, SWT.DEFAULT)
.applyTo(dialogArea);

Group group = new Group(dialogArea, SWT.NONE);
group.setText(OpenShiftUIMessages.MemoryLabel);
GridDataFactory.fillDefaults().span(3, 1).grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(group);
GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).spacing(10, 4).applyTo(group);
createResourceWidgets(OpenShiftUIMessages.RequestLabel, EditResourceLimitsPageModel.REQUESTS_MEMORY,
MEMORY_SUFFIXES, MEMORY_SUFFIXES_LABELS, group, dbc);
createResourceWidgets(OpenShiftUIMessages.LimitLabel, EditResourceLimitsPageModel.LIMITS_MEMORY,
MEMORY_SUFFIXES, MEMORY_SUFFIXES_LABELS, group, dbc);

group = new Group(dialogArea, SWT.NONE);
group.setText(OpenShiftUIMessages.CPULabel);
GridDataFactory.fillDefaults().span(3, 1).grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(group);
GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).spacing(10, 4).applyTo(group);
createResourceWidgets(OpenShiftUIMessages.RequestLabel, EditResourceLimitsPageModel.REQUESTS_CPU,
CPU_SUFFIXES, CPU_SUFFIXES_LABELS, group, dbc);
createResourceWidgets(OpenShiftUIMessages.LimitLabel, EditResourceLimitsPageModel.LIMITS_CPU,
CPU_SUFFIXES, CPU_SUFFIXES_LABELS, group, dbc);
}

public EditResourceLimitsPage(EditResourceLimitsPageModel model, IWizard wizard) {
super(OpenShiftUIMessages.EditResourceLimitsPageTitle,
NLS.bind(OpenShiftUIMessages.EditResourceLimitsPageDescription, model.getUpdatedReplicationController().getName()),
"EditResourceLimitsPage",
wizard);
this.model = model;
}
private void createResourceWidgets(String label, String property, String[] suffixes, String[] labels,
Group parent, DataBindingContext dbc) {
// label
Label labelComp = new Label(parent, SWT.NONE);
labelComp.setText(label);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER)
.applyTo(labelComp);

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().applyTo(parent);
final Composite dialogArea = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(dialogArea);
GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).spacing(20, SWT.DEFAULT).applyTo(dialogArea);
// value text
Text text = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).grab(true, false)
.applyTo(text);

Group group = new Group(dialogArea, SWT.NONE);
group.setText(OpenShiftUIMessages.MemoryLabel);
GridDataFactory.fillDefaults().span(3, 1).grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(group);
GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).spacing(10, 4).applyTo(group);
createResourceWidgets(dbc, group, OpenShiftUIMessages.RequestLabel, EditResourceLimitsPageModel.REQUESTS_MEMORY, MEMORY_SUFFIXES, MEMORY_SUFFIXES_LABELS);
createResourceWidgets(dbc, group, OpenShiftUIMessages.LimitLabel, EditResourceLimitsPageModel.LIMITS_MEMORY, MEMORY_SUFFIXES, MEMORY_SUFFIXES_LABELS);

group = new Group(dialogArea, SWT.NONE);
group.setText(OpenShiftUIMessages.CPULabel);
GridDataFactory.fillDefaults().span(3, 1).grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(group);
GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).spacing(10, 4).applyTo(group);
createResourceWidgets(dbc, group, OpenShiftUIMessages.RequestLabel, EditResourceLimitsPageModel.REQUESTS_CPU, CPU_SUFFIXES, CPU_SUFFIXES_LABELS);
createResourceWidgets(dbc, group, OpenShiftUIMessages.LimitLabel, EditResourceLimitsPageModel.LIMITS_CPU, CPU_SUFFIXES, CPU_SUFFIXES_LABELS);
}

private void createResourceWidgets(DataBindingContext dbc, Group group, String label, String property, String[] suffixes, String[] labels) {
// label
Label labelComp = new Label(group, SWT.NONE);
labelComp.setText(label);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(labelComp);
// unit combo
ComboViewer combo = new ComboViewer(parent);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER).hint(140, SWT.DEFAULT)
.applyTo(combo.getControl());
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setInput(suffixes);
combo.setLabelProvider(new LabelProvider() {

// scale spinner
Text text = new Text(group, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(text);
ComboViewer combo = new ComboViewer(group);
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setInput(suffixes);
combo.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return getLabelForSuffix(element, suffixes, labels);
}

@Override
public String getText(Object element) {
for(int i=0; i < suffixes.length;++i) {
if (element.equals(suffixes[i])) {
element = labels[i];
break;
}
}
return (String) element;
}

});
private String getLabelForSuffix(Object element, String[] suffixes, String[] labels) {
String label = (String) element;
for (int i = 0; i < suffixes.length; ++i) {
if (element.equals(suffixes[i])) {
label = labels[i];
break;
}
}
return label;
}
});

IObservableValue textObservable = WidgetProperties.text(SWT.Modify).observe(text);
IObservableValue comboObservable = ViewerProperties.singleSelection().observe(combo);
IObservableValue master = BeanProperties.value(EditResourceLimitsPageModel.SELECTED_CONTAINER).observe(model);
ValueBindingBuilder.bind(textObservable)
.validatingAfterGet(new NumericValidator("integer", Integer::parseInt))
.converting(new AggregatingConverter(comboObservable, true))
.to(PojoProperties.value(property).observeDetail(master))
.converting(new KeywordConverter(suffixes, true))
.in(dbc);
ValueBindingBuilder.bind(comboObservable)
.converting(new AggregatingConverter(textObservable, false))
.to(PojoProperties.value(property).observeDetail(master))
.converting(new KeywordConverter(suffixes, false))
.in(dbc);
}
IObservableValue<String> valueObservable = WidgetProperties.text(SWT.Modify).observe(text);
IObservableValue<String> selectedUnitObservable = ViewerProperties.singleSelection().observe(combo);
IObservableValue<IContainer> master = BeanProperties.value(EditResourceLimitsPageModel.SELECTED_CONTAINER).observe(model);
ValueBindingBuilder
.bind(valueObservable)
.validatingAfterGet(new NumericValidator("integer", Integer::parseInt))
.converting(new AggregatingConverter(selectedUnitObservable, true))
.to(PojoProperties.value(property).observeDetail(master))
.converting(new KeywordConverter(suffixes, true))
.in(dbc);
ValueBindingBuilder
.bind(selectedUnitObservable)
.converting(new AggregatingConverter(valueObservable, false))
.to(PojoProperties.value(property).observeDetail(master))
.converting(new KeywordConverter(suffixes, false))
.in(dbc);
}
}