Tomas Jelinek has uploaded a new change for review. Change subject: frontend: introduce generics to UICommon (part 2) ......................................................................
frontend: introduce generics to UICommon (part 2) Infrastructure part of the introduction of the generics into UICommon Changes: - Changed the SearchableListModel to be generic (only uses type <T> but as soon as the children will be refactored to be generic than it will change to <T extends IVdcQueryable> - created the generic versions of the following widgets: EntityModelLabel, EntityModelTextAreaLabel, EntityModelPasswordBox, EntityModelTextArea, ListModelSuggestBox Change-Id: Ic835d37aba4821d2497652177ae84b1fd37ba61d Signed-off-by: Tomas Jelinek <[email protected]> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabel.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabelEditor.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBox.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBoxEditor.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextArea.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaEditor.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabel.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabelEditor.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabel.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabelEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBox.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBoxEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextArea.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabel.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabelEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBox.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBoxEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabel.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabelEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBox.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBoxEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextArea.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaEditor.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabel.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabelEditor.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java 29 files changed, 426 insertions(+), 52 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/20118/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabel.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabel.java index 15855f0..1564dc9 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabel.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabel.java @@ -12,7 +12,9 @@ /** * An {@link EditorWidget} that only shows a Label (readonly) + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelLabel instead */ +@Deprecated public class EntityModelLabel extends ValueBox<Object> implements EditorWidget<Object, ValueBoxEditor<Object>> { public EntityModelLabel() { diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabelEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabelEditor.java index 657af70..450d3fa 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabelEditor.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelLabelEditor.java @@ -3,6 +3,10 @@ import com.google.gwt.text.shared.Parser; import com.google.gwt.text.shared.Renderer; +/** + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelLabelEditor instead + */ +@Deprecated public class EntityModelLabelEditor extends AbstractValueBoxWithLabelEditor<Object, EntityModelLabel> { /** diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBox.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBox.java index 44c4e06..8dbcfd0 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBox.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBox.java @@ -6,6 +6,10 @@ import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor; import com.google.gwt.user.client.ui.ValueBoxBase; +/** + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelPasswordBox instead + */ +@Deprecated public class EntityModelPasswordBox extends ValueBoxBase<Object> implements EditorWidget<Object, ValueBoxEditor<Object>> { private ObservableValueBoxEditor editor; diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBoxEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBoxEditor.java index 29936e1..00fa303 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBoxEditor.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelPasswordBoxEditor.java @@ -2,7 +2,9 @@ /** * Composite Editor that uses {@link EntityModelPasswordBox}. + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelPasswordBox instead */ +@Deprecated public class EntityModelPasswordBoxEditor extends AbstractValueBoxWithLabelEditor<Object, EntityModelPasswordBox> { public EntityModelPasswordBoxEditor() { diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextArea.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextArea.java index 7019ba6..efb0908 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextArea.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextArea.java @@ -7,6 +7,10 @@ import com.google.gwt.user.client.ui.ValueBoxBase; import org.ovirt.engine.ui.common.widget.parser.EntityModelParser; +/** + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelTextArea instead + */ +@Deprecated public class EntityModelTextArea extends ValueBoxBase<Object> implements EditorWidget<Object, ValueBoxEditor<Object>> { private ObservableValueBoxEditor editor; diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaEditor.java index 69ade19..bfef08c 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaEditor.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaEditor.java @@ -3,6 +3,10 @@ import com.google.gwt.text.shared.Parser; import com.google.gwt.text.shared.Renderer; +/** + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelTextAreaEditor instead + */ +@Deprecated public class EntityModelTextAreaEditor extends AbstractValueBoxWithLabelEditor<Object, EntityModelTextArea> { public EntityModelTextAreaEditor() { diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabel.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabel.java index 14e27d9..0d13d58 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabel.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabel.java @@ -12,7 +12,9 @@ /** * An {@link EditorWidget} that only shows a Label (readonly) + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelTextAreaLabel instead */ +@Deprecated public class EntityModelTextAreaLabel extends ValueBoxBase<Object> implements EditorWidget<Object, ValueBoxEditor<Object>> { public EntityModelTextAreaLabel() { diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabelEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabelEditor.java index 20323ec..ea7216f 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabelEditor.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelTextAreaLabelEditor.java @@ -5,6 +5,10 @@ import com.google.gwt.text.shared.Parser; import com.google.gwt.text.shared.Renderer; +/** + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.EntityModelTextAreaLabelEditor instead + */ +@Deprecated public class EntityModelTextAreaLabelEditor extends AbstractValueBoxWithLabelEditor<Object, EntityModelTextAreaLabel> { /** diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java index fd96814..3e51635 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java @@ -10,7 +10,9 @@ /** * SuggestBox widget that adapts to UiCommon list model items. Expects all of it's items to be non null Strings + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.ListModelSuggestBox instead */ +@Deprecated public class ListModelSuggestBox extends BaseListModelSuggestBox<Object> { public ListModelSuggestBox() { diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java index cf90e9b..349f483 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java @@ -6,8 +6,9 @@ /** * Composite Editor that uses {@link ListModelSuggestBox}. - * + * @deprecated use the org.ovirt.engine.ui.common.widget.editor.generic.ListModelSuggestBoxEditor instead */ +@Deprecated public class ListModelSuggestBoxEditor extends AbstractValidatedWidgetWithLabel<Object, ListModelSuggestBox> implements IsEditor<WidgetWithLabelEditor<Object, ListModelSuggestBoxEditor>> { diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabel.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabel.java new file mode 100644 index 0000000..4cf0042 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabel.java @@ -0,0 +1,28 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor; +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import com.google.gwt.user.client.ui.ValueBox; +import org.ovirt.engine.ui.common.widget.editor.EditorWidget; +import org.ovirt.engine.ui.common.widget.renderer.EmptyValueRenderer; + +/** + * An {@link org.ovirt.engine.ui.common.widget.editor.EditorWidget} that only shows a Label (readonly) + */ +public class EntityModelLabel<T> extends ValueBox<T> implements EditorWidget<T, ValueBoxEditor<T>> { + + public EntityModelLabel(Renderer<T> renderer, Parser<T> parser) { + super(Document.get().createTextInputElement(), renderer, parser); + } + + @Override + public void setText(String text) { + super.setText(new EmptyValueRenderer<String>().render(text)); + setReadOnly(true); + getElement().getStyle().setBorderWidth(0, Unit.PX); + } + +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabelEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabelEditor.java new file mode 100644 index 0000000..1aeb5cb --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelLabelEditor.java @@ -0,0 +1,19 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import org.ovirt.engine.ui.common.widget.editor.AbstractValueBoxWithLabelEditor; + +public class EntityModelLabelEditor<T> extends AbstractValueBoxWithLabelEditor<T, EntityModelLabel<T>> { + + /** + * A ValueBoxWithLabelEditor that has a Label as the widget + */ + public EntityModelLabelEditor(Renderer<T> renderer, Parser<T> parser) { + this(new EntityModelLabel<T>(renderer, parser)); + } + + public EntityModelLabelEditor(EntityModelLabel<T> widget) { + super(widget); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBox.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBox.java new file mode 100644 index 0000000..b95ab58 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBox.java @@ -0,0 +1,27 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor; +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import com.google.gwt.user.client.ui.ValueBoxBase; +import org.ovirt.engine.ui.common.widget.editor.EditorWidget; + +public class EntityModelPasswordBox<T> extends ValueBoxBase<T> implements EditorWidget<T, ValueBoxEditor<T>> { + + private ObservableValueBoxEditor<T> editor; + + + public EntityModelPasswordBox(Renderer<T> renderer, Parser<T> parser) { + super(Document.get().createPasswordInputElement(), renderer, parser); + } + + @Override + public ValueBoxEditor<T> asEditor() { + if (editor == null) { + editor = new ObservableValueBoxEditor(this); + } + return editor; + } + +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBoxEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBoxEditor.java new file mode 100644 index 0000000..fc4dea6 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelPasswordBoxEditor.java @@ -0,0 +1,16 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import org.ovirt.engine.ui.common.widget.editor.AbstractValueBoxWithLabelEditor; + +/** + * Composite Editor that uses {@link EntityModelPasswordBox}. + */ +public class EntityModelPasswordBoxEditor<T> extends AbstractValueBoxWithLabelEditor<T, EntityModelPasswordBox<T>> { + + public EntityModelPasswordBoxEditor(Renderer<T> renderer, Parser<T> parser) { + super(new EntityModelPasswordBox<T>(renderer, parser)); + } + +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextArea.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextArea.java new file mode 100644 index 0000000..0306561 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextArea.java @@ -0,0 +1,26 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor; +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import com.google.gwt.user.client.ui.ValueBoxBase; +import org.ovirt.engine.ui.common.widget.editor.EditorWidget; + +public class EntityModelTextArea<T> extends ValueBoxBase<T> implements EditorWidget<T, ValueBoxEditor<T>> { + + private ObservableValueBoxEditor<T> editor; + + public EntityModelTextArea(Renderer<T> renderer, Parser<T> parser) { + super(Document.get().createTextAreaElement(), renderer, parser); + } + + @Override + public ValueBoxEditor<T> asEditor() { + if (editor == null) { + editor = new ObservableValueBoxEditor(this); + } + return editor; + } + +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaEditor.java new file mode 100644 index 0000000..5225b6b --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaEditor.java @@ -0,0 +1,16 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import org.ovirt.engine.ui.common.widget.editor.AbstractValueBoxWithLabelEditor; + +public class EntityModelTextAreaEditor<T> extends AbstractValueBoxWithLabelEditor<T, EntityModelTextArea<T>> { + + public EntityModelTextAreaEditor(Renderer<T> renderer, Parser<T> parser) { + this(new EntityModelTextArea<T>(renderer, parser)); + } + + public EntityModelTextAreaEditor(EntityModelTextArea<T> widget) { + super(widget); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabel.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabel.java new file mode 100644 index 0000000..4ddb014 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabel.java @@ -0,0 +1,28 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor; +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import com.google.gwt.user.client.ui.ValueBoxBase; +import org.ovirt.engine.ui.common.widget.editor.EditorWidget; +import org.ovirt.engine.ui.common.widget.renderer.EmptyValueRenderer; + +/** + * An {@link org.ovirt.engine.ui.common.widget.editor.EditorWidget} that only shows a Label (readonly) + */ +public class EntityModelTextAreaLabel<T> extends ValueBoxBase<T> implements EditorWidget<T, ValueBoxEditor<T>> { + + public EntityModelTextAreaLabel(Renderer<T> renderer, Parser<T> parser) { + super(Document.get().createTextAreaElement(), renderer, parser); + } + + @Override + public void setText(String text) { + super.setText(new EmptyValueRenderer<String>().render(text)); + setReadOnly(true); + getElement().getStyle().setBorderWidth(0, Unit.PX); + } + +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabelEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabelEditor.java new file mode 100644 index 0000000..348aa68 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/EntityModelTextAreaLabelEditor.java @@ -0,0 +1,38 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; +import org.ovirt.engine.ui.common.widget.editor.AbstractValueBoxWithLabelEditor; +import org.ovirt.engine.ui.common.widget.renderer.EmptyValueRenderer; + + +public class EntityModelTextAreaLabelEditor<T> extends AbstractValueBoxWithLabelEditor<T, EntityModelTextAreaLabel<T>> { + + /** + * A ValueBoxWithLabelEditor that has a Label as the widget + */ + public EntityModelTextAreaLabelEditor(Renderer<T> renderer, Parser<T> parser) { + this(new EntityModelTextAreaLabel<T>(renderer, parser)); + } + + public EntityModelTextAreaLabelEditor(EntityModelTextAreaLabel<T> widget) { + super(widget); + } + + public EntityModelTextAreaLabelEditor(final boolean showBorder, final boolean disableResizing, Renderer<T> renderer, Parser<T> parser) { + super(new EntityModelTextAreaLabel<T>(renderer, parser) { + @Override + public void setText(String text) { + super.setText(new EmptyValueRenderer<String>().render(text)); + + if (showBorder) { + getElement().getStyle().setBorderWidth(1, Unit.PX); + } + if (disableResizing) { + getElement().getStyle().setProperty("resize", "none"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + }); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBox.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBox.java new file mode 100644 index 0000000..5d2de01 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBox.java @@ -0,0 +1,45 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.event.dom.client.FocusEvent; +import com.google.gwt.event.dom.client.FocusHandler; +import com.google.gwt.user.client.ui.MultiWordSuggestOracle; +import java.util.Collection; +import org.ovirt.engine.ui.common.widget.editor.BaseListModelSuggestBox; + +/** + * SuggestBox widget that adapts to UiCommon list model items. Expects all of it's items to be non null Strings + */ +public class ListModelSuggestBox extends BaseListModelSuggestBox<String> { + + public ListModelSuggestBox() { + super(new MultiWordSuggestOracle()); + initWidget(asSuggestBox()); + + asSuggestBox().getTextBox().addFocusHandler(new FocusHandler() { + + @Override + public void onFocus(FocusEvent event) { + asSuggestBox().showSuggestionList(); + } + }); + } + + @Override + public void setAcceptableValues(Collection<String> values) { + MultiWordSuggestOracle suggestOracle = (MultiWordSuggestOracle) asSuggestBox().getSuggestOracle(); + suggestOracle.clear(); + suggestOracle.addAll(values); + suggestOracle.setDefaultSuggestionsFromText(values); + } + + @Override + protected void render(String value, boolean fireEvents) { + asSuggestBox().setValue(value, fireEvents); + } + + @Override + protected String asEntity(String value) { + return value; + } + +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBoxEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBoxEditor.java new file mode 100644 index 0000000..cacd939 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/ListModelSuggestBoxEditor.java @@ -0,0 +1,26 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.editor.client.IsEditor; +import org.ovirt.engine.ui.common.widget.AbstractValidatedWidgetWithLabel; +import org.ovirt.engine.ui.common.widget.editor.WidgetWithLabelEditor; + +/** + * Composite Editor that uses {@link ListModelSuggestBox}. + * + */ +public class ListModelSuggestBoxEditor extends AbstractValidatedWidgetWithLabel<String, ListModelSuggestBox> + implements IsEditor<WidgetWithLabelEditor<String, ListModelSuggestBoxEditor>> { + + private final WidgetWithLabelEditor<String, ListModelSuggestBoxEditor> editor; + + public ListModelSuggestBoxEditor() { + super(new ListModelSuggestBox()); + this.editor = WidgetWithLabelEditor.of(getContentWidget().asEditor(), this); + } + + @Override + public WidgetWithLabelEditor<String, ListModelSuggestBoxEditor> asEditor() { + return editor; + } + +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabel.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabel.java new file mode 100644 index 0000000..cfdff98 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabel.java @@ -0,0 +1,10 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import org.ovirt.engine.ui.common.widget.parser.generic.ToStringEntityModelParser; + +public class StringEntityModelLabel extends EntityModelLabel<String> { + + public StringEntityModelLabel() { + super(new ToStringEntityModelRenderer<String>(), new ToStringEntityModelParser()); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabelEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabelEditor.java new file mode 100644 index 0000000..5223b69 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelLabelEditor.java @@ -0,0 +1,15 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import com.google.gwt.text.shared.Parser; +import com.google.gwt.text.shared.Renderer; + +public class StringEntityModelLabelEditor extends EntityModelLabelEditor<String> { + + public StringEntityModelLabelEditor(Renderer<String> renderer, Parser<String> parser) { + super(renderer, parser); + } + + public StringEntityModelLabelEditor() { + super(new StringEntityModelLabel()); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBox.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBox.java new file mode 100644 index 0000000..a5855bb --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBox.java @@ -0,0 +1,10 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import org.ovirt.engine.ui.common.widget.parser.generic.ToStringEntityModelParser; + +public class StringEntityModelPasswordBox extends EntityModelPasswordBox<String> { + + public StringEntityModelPasswordBox() { + super(new ToStringEntityModelRenderer<String>(), new ToStringEntityModelParser()); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBoxEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBoxEditor.java new file mode 100644 index 0000000..f56086c --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelPasswordBoxEditor.java @@ -0,0 +1,10 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import org.ovirt.engine.ui.common.widget.parser.generic.ToStringEntityModelParser; + +public class StringEntityModelPasswordBoxEditor extends EntityModelPasswordBoxEditor<String> { + + public StringEntityModelPasswordBoxEditor() { + super(new ToStringEntityModelRenderer<String>(), new ToStringEntityModelParser()); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextArea.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextArea.java new file mode 100644 index 0000000..4e81d8d --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextArea.java @@ -0,0 +1,10 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import org.ovirt.engine.ui.common.widget.parser.generic.ToStringEntityModelParser; + +public class StringEntityModelTextArea extends EntityModelTextArea<String> { + + public StringEntityModelTextArea() { + super(new ToStringEntityModelRenderer<String>(), new ToStringEntityModelParser()); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaEditor.java new file mode 100644 index 0000000..6719e59 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaEditor.java @@ -0,0 +1,8 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +public class StringEntityModelTextAreaEditor extends EntityModelTextAreaEditor<String> { + + public StringEntityModelTextAreaEditor() { + super(new StringEntityModelTextArea()); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabel.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabel.java new file mode 100644 index 0000000..b6f90c2 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabel.java @@ -0,0 +1,10 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import org.ovirt.engine.ui.common.widget.parser.generic.ToStringEntityModelParser; + +public class StringEntityModelTextAreaLabel extends EntityModelTextAreaLabel<String> { + + public StringEntityModelTextAreaLabel() { + super(new ToStringEntityModelRenderer<String>(), new ToStringEntityModelParser()); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabelEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabelEditor.java new file mode 100644 index 0000000..85895d7 --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/generic/StringEntityModelTextAreaLabelEditor.java @@ -0,0 +1,14 @@ +package org.ovirt.engine.ui.common.widget.editor.generic; + +import org.ovirt.engine.ui.common.widget.parser.generic.ToStringEntityModelParser; + +public class StringEntityModelTextAreaLabelEditor extends EntityModelTextAreaLabelEditor<String> { + + public StringEntityModelTextAreaLabelEditor() { + super(new StringEntityModelTextAreaLabel()); + } + + public StringEntityModelTextAreaLabelEditor(boolean showBorder, boolean disableResizing) { + super(showBorder, disableResizing, new ToStringEntityModelRenderer<String>(), new ToStringEntityModelParser()); + } +} diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java index 89b1443..612f9c5 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java @@ -43,8 +43,8 @@ /** * Represents a list model with ability to fetch items both sync and async. */ -@SuppressWarnings("unused") -public abstract class SearchableListModel extends ListModel implements GridController +// TODO once all the children of this class will be refactored to use generics, change from <T> to <T extends IVdcQueryable> +public abstract class SearchableListModel<T> extends ListModel<T> implements GridController { private static final int UnknownInteger = -1; private static Logger logger = Logger.getLogger(SearchableListModel.class.getName()); @@ -109,7 +109,7 @@ { if (openReportCommands.add(reportCommand)) { - ArrayList<IVdcQueryable> items = + List<IVdcQueryable> items = getSelectedItems() != null ? Linq.<IVdcQueryable> cast(getSelectedItems()) : new ArrayList<IVdcQueryable>(); updateReportCommandAvailability(reportCommand, items); @@ -257,7 +257,7 @@ return getSearchPageNumber() == 1 ? 1 : getSearchPageNumber() - 1; } - private final PrivateAsyncCallback asyncCallback; + private final PrivateAsyncCallback<T> asyncCallback; protected SearchableListModel() { @@ -266,7 +266,7 @@ setSearchPreviousPageCommand(new UICommand("SearchPreviousPage", this)); //$NON-NLS-1$ setForceRefreshCommand(new UICommand("ForceRefresh", this)); //$NON-NLS-1$ setSearchPageSize(UnknownInteger); - asyncCallback = new PrivateAsyncCallback(this); + asyncCallback = new PrivateAsyncCallback<T>(this); updateActionAvailability(); @@ -323,29 +323,26 @@ } @Override - public void setSelectedItem(Object value) { + public void setSelectedItem(T value) { setIsQueryFirstTime(true); super.setSelectedItem(value); setIsQueryFirstTime(false); } @Override - public void setEntity(Object value) { + public void setEntity(T value) { if (getEntity() == null) { super.setEntity(value); return; } // Equals doesn't always has the same outcome as checking the ids of the elements. - if (getEntity() instanceof IVdcQueryable) { - if (value != null) { - IVdcQueryable ivdcq_value = (IVdcQueryable) value; - IVdcQueryable ivdcq_entity = (IVdcQueryable) getEntity(); - if (!ivdcq_value.getQueryableId().equals(ivdcq_entity.getQueryableId())) { - super.setEntity(value); - return; - } + if (value != null) { + if (!((IVdcQueryable) value).getQueryableId().equals(((IVdcQueryable) getEntity()).getQueryableId())) { + super.setEntity(value); + return; } } + if (!getEntity().equals(value)) { super.setEntity(value); return; @@ -419,7 +416,7 @@ reportModel.setReportUnit(reportCommand.getUriValue()); if (reportCommand.getIdParamName() != null) { - for (Object item : getSelectedItems()) { + for (T item : getSelectedItems()) { if (((ReportCommand) getLastExecutedCommand()).isMultiple) { reportModel.addResourceId(reportCommand.getIdParamName(), ((BusinessEntity<?>) item).getId() .toString()); @@ -430,16 +427,14 @@ } } - boolean isFromSameDc = true; boolean firstItem = true; String dcId = ""; //$NON-NLS-1$ - for (Object item : getSelectedItems()) { + for (T item : getSelectedItems()) { if (item instanceof HasStoragePool) { if (firstItem) { dcId = ((HasStoragePool<?>) item).getStoragePoolId().toString(); firstItem = false; } else if (!(((HasStoragePool<?>) item).getStoragePoolId().toString().equals(dcId))) { - isFromSameDc = false; reportModel.setDifferntDcError(true); continue; } @@ -635,45 +630,39 @@ { } - private Comparator comparator; + private Comparator<T> comparator; - protected void setComparator(Comparator comparator) { + protected void setComparator(Comparator<T> comparator) { if (comparator == this.comparator) { return; } this.comparator = comparator; - Iterable items = getItems(); + Iterable<T> items = getItems(); if (items == null) { return; } - Collection identicalItems = (comparator == null) ? new ArrayList() : new TreeSet(comparator); - for (Object item : items) { + Collection<T> identicalItems = (comparator == null) ? new ArrayList<T>() : new TreeSet<T>(comparator); + for (T item : items) { identicalItems.add(item); } setItems(identicalItems); } @Override - public Iterable getItems() - { - return items; - } - - @Override - public void setItems(Iterable value) + public void setItems(Iterable<T> value) { if (items != value) { - IVdcQueryable lastSelectedItem = (IVdcQueryable) getSelectedItem(); - ArrayList<IVdcQueryable> lastSelectedItems = new ArrayList<IVdcQueryable>(); + T lastSelectedItem = getSelectedItem(); + List<T> lastSelectedItems = new ArrayList<T>(); if (getSelectedItems() != null) { - for (Object item : getSelectedItems()) + for (T item : getSelectedItems()) { - lastSelectedItems.add((IVdcQueryable) item); + lastSelectedItems.add(item); } } @@ -682,10 +671,10 @@ itemsChanging(value, items); items = value; } else { - TreeSet sortedValue = null; + TreeSet<T> sortedValue = null; if (value != null) { - sortedValue = new TreeSet(comparator); - for (Object item : value) { + sortedValue = new TreeSet<T>(comparator); + for (T item : value) { sortedValue.add(item); } } @@ -705,29 +694,29 @@ if (lastSelectedItem != null && items != null) { - IVdcQueryable newSelectedItem = null; - ArrayList<IVdcQueryable> newItems = new ArrayList<IVdcQueryable>(); + T newSelectedItem = null; + List<T> newItems = new ArrayList<T>(); - for (Object item : items) + for (T item : items) { - newItems.add((IVdcQueryable) item); + newItems.add(item); } if (newItems != null) { - for (IVdcQueryable newItem : newItems) + for (T newItem : newItems) { // Search for selected item - if (newItem.getQueryableId().equals(lastSelectedItem.getQueryableId())) + if (((IVdcQueryable) newItem).getQueryableId().equals(((IVdcQueryable) lastSelectedItem).getQueryableId())) { newSelectedItem = newItem; } else { // Search for selected items - for (IVdcQueryable item : lastSelectedItems) + for (T item : lastSelectedItems) { - if (newItem.getQueryableId().equals(item.getQueryableId())) + if (((IVdcQueryable) newItem).getQueryableId().equals(((IVdcQueryable) item).getQueryableId())) { selectedItems.add(newItem); } @@ -803,12 +792,12 @@ } } - public final static class PrivateAsyncCallback + public final static class PrivateAsyncCallback<T> { - private final SearchableListModel model; + private final SearchableListModel<T> model; private boolean searchRequested; - public PrivateAsyncCallback(SearchableListModel model) + public PrivateAsyncCallback(SearchableListModel<T> model) { this.model = model; AsyncQuery _asyncQuery1 = new AsyncQuery(); @@ -817,7 +806,7 @@ @Override public void onSuccess(Object model1, Object result1) { - PrivateAsyncCallback privateAsyncCallback1 = (PrivateAsyncCallback) model1; + PrivateAsyncCallback<T> privateAsyncCallback1 = (PrivateAsyncCallback<T>) model1; privateAsyncCallback1.ApplySearchPageSize((Integer) result1); } }; @@ -827,7 +816,7 @@ public void RequestSearch() { searchRequested = true; - model.setItems(new ArrayList()); + model.setItems(new ArrayList<T>()); model.getSelectedItemChangedEvent().raise(this, new EventArgs()); model.getSelectedItemsChangedEvent().raise(this, new EventArgs()); } -- To view, visit http://gerrit.ovirt.org/20118 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic835d37aba4821d2497652177ae84b1fd37ba61d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Tomas Jelinek <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
