Permalink
Browse files

SmartPresentation orientation handling

  • Loading branch information...
1 parent 99435ef commit 4d6b232cdb301ed0a323c7675156e5597c6b0e06 Marlon Richert committed Feb 20, 2012
@@ -28,37 +28,37 @@
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.Table;
-public class SelectionControl<B>
+public class SelectionControl<T>
extends Control<AbstractSelect, ValueChangeListener> {
- private Class<B> beanType;
- private BeanItemContainer<B> model;
- private B[] selection;
+ private Class<T> beanType;
+ private BeanItemContainer<T> model;
+ private T[] selection;
@SuppressWarnings("unchecked")
- public SelectionControl(String name, Class<B> beanType) {
+ public SelectionControl(String name, Class<T> beanType) {
super(name, AbstractSelect.class, ValueChangeListener.class);
this.beanType = beanType;
- model = new BeanItemContainer<B>(beanType);
- selection = (B[]) Array.newInstance(beanType, 0);
+ model = new BeanItemContainer<T>(beanType);
+ selection = (T[]) Array.newInstance(beanType, 0);
}
- public void setChoices(B... choices) {
- setModel(new BeanItemContainer<B>(beanType, Arrays.asList(choices)));
+ public void setChoices(T... choices) {
+ setModel(new BeanItemContainer<T>(beanType, Arrays.asList(choices)));
}
- public void setModel(BeanItemContainer<B> model) {
+ public void setModel(BeanItemContainer<T> model) {
AbstractSelect rendition = getRendition();
if (rendition != null) {
rendition.setContainerDataSource(model);
}
this.model = model;
}
- public BeanItemContainer<B> getModel() {
+ public BeanItemContainer<T> getModel() {
return model;
}
- public void setSelection(B... selection) {
+ public void setSelection(T... selection) {
AbstractSelect rendition = getRendition();
if (rendition != null) {
switch (selection.length) {
@@ -76,17 +76,17 @@ public void setSelection(B... selection) {
}
@SuppressWarnings("unchecked")
- public B[] getSelection() {
+ public T[] getSelection() {
AbstractSelect rendition = getRendition();
if (rendition != null) {
Object value = rendition.getValue();
if (value instanceof Collection<?>) {
- Collection<B> collection = (Collection<B>) value;
+ Collection<T> collection = (Collection<T>) value;
selection = collection.toArray(
- (B[]) Array.newInstance(beanType, collection.size()));
+ (T[]) Array.newInstance(beanType, collection.size()));
} else {
- selection = (B[]) Array.newInstance(beanType, 1);
- selection[0] = (B) value;
+ selection = (T[]) Array.newInstance(beanType, 1);
+ selection[0] = (T) value;
}
}
return selection;
@@ -1,4 +1,4 @@
/**
- * Convenience implementations of {@link org.vaadin.jefferson.View} and {@link org.vaadin.jefferson.Composite}.
+ * Concrete implementations of {@link org.vaadin.jefferson.View}, {@link org.vaadin.jefferson.Composite} and {@link org.vaadin.jefferson.Control}.
*/
package org.vaadin.jefferson.content;
@@ -4,13 +4,17 @@
import org.vaadin.jefferson.Presentation;
import org.vaadin.jefferson.View;
+import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.AbstractSplitPanel;
+import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.PasswordField;
+import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;
@@ -35,12 +39,25 @@ protected void style(View<?> view) {
} else if (stretches(view)) {
rendition.setSizeFull();
expand(rendition);
- } else if (parentRendition instanceof HorizontalLayout) {
- // ((HorizontalLayout) parentRendition).setComponentAlignment(
- // rendition, Alignment.MIDDLE_LEFT);
- } else if (parentRendition instanceof VerticalLayout) {
- // ((VerticalLayout) parentRendition).setComponentAlignment(
- // rendition, Alignment.TOP_CENTER);
+ } else {
+ rendition.setSizeUndefined();
+ Orientation parentOrientation = getOrientation(view.getParent());
+ if (parentOrientation == Orientation.VERTICAL) {
+ rendition.setWidth(100, Sizeable.UNITS_PERCENTAGE);
+ if (parentRendition instanceof VerticalLayout) {
+ ((VerticalLayout) parentRendition).setComponentAlignment(
+ rendition, Alignment.TOP_CENTER);
+ }
+ } else if (parentOrientation == Orientation.HORIZONTAL) {
+ if (!(rendition instanceof TextField || rendition instanceof PasswordField)) {
+ rendition.setHeight(100, Sizeable.UNITS_PERCENTAGE);
+ }
+ if (parentRendition instanceof HorizontalLayout) {
+ ((HorizontalLayout) parentRendition).setComponentAlignment(
+ rendition, Alignment.MIDDLE_LEFT);
+ }
+ }
+
}
}
@@ -61,6 +78,10 @@ void render(Composite<ComponentContainer> view) {
setRendition(view, getRendition(view, invert(getOrientation(parent))));
}
+ // void render(ButtonControl view) {
+ // setRendition(view, new Button(view.getName()));
+ // }
+
private Orientation invert(Orientation input) {
Orientation output = defaultOrientation;
if (input == Orientation.HORIZONTAL) {
@@ -0,0 +1,4 @@
+/**
+ * {@link org.vaadin.jefferson.Presentation} classes.
+ */
+package org.vaadin.jefferson.presentation;

0 comments on commit 4d6b232

Please sign in to comment.