eu.future.earth.gwt.client.ui.panels.FlowLabelFieldPanel Maven / Gradle / Ivy
The newest version!
package eu.future.earth.gwt.client.ui.panels;
import java.util.Iterator;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import eu.future.earth.gwt.client.logic.UUID;
import eu.future.earth.gwt.client.ui.ImageResources;
import eu.future.earth.gwt.client.ui.general.UiUtil;
public class FlowLabelFieldPanel extends AbstractLabelFieldPanel {
private FlowPanel holderGrid = null;
@UiConstructor
public FlowLabelFieldPanel() {
FlowPanel main = new FlowPanel();
holderGrid = new FlowPanel();
holderGrid.addStyleName("flow-info-panel");
main.add(holderGrid);
main.add(requiredLabel);
initWidget(main);
requiredLabel.setVisible(false);
}
private final Label requiredLabel = new Label(ImageResources.STATIC_TEXT.requiredFields());
@Override
public void showRequired(boolean hasRequired) {
requiredLabel.setVisible(hasRequired);
}
@Override
public void setRequired(String name, boolean newState) {
if (name != null) {
super.setRequiredForLabel(name, newState);
if (newState) {
showRequired(newState);
}
checkRequiredLegendas();
}
}
@Override
public String getLabel(String name) {
Widget to = labels.get(name);
return UiUtil.getTextOnWidget(to);
}
@Override
public void setLabel(String name, String newText) {
Widget to = labels.get(name);
if (to instanceof HasText) {
HasText re = (HasText) to;
re.setText(newText);
}
}
public void clearButtons() {
holderGrid.clear();
}
@Override
public Field addTwoRows(Field result) {
if (result.getId() == null) {
result.setId(UUID.uuid());
}
Label label = null;
if (result.getLabel() != null) {
label = new Label(result.getLabel());
label.addStyleName("ftr-label");
label.addStyleName("ftr-flow-label");
holderGrid.add(label);
}
if (result.getManager() != null) {
holderGrid.add(result.getManager());
result.getManager().getElement().getStyle().setWidth(100, Unit.PCT);
}
setElements(result.getId(), label, result.getManager(), null);
return result;
}
@Override
public void showFilled() {
Iterator labelsName = labels.keySet().iterator();
while (labelsName.hasNext()) {
String labelName = labelsName.next();
Widget item = edits.get(labelName);
if (item instanceof HasText) {
HasText real = (HasText) item;
if (real.getText() != null && real.getText().length() > 0) {
setVisible(labelName, true);
} else {
setVisible(labelName, false);
}
}
}
}
@Override
public void setVisible(String name, boolean newState) {
if (name != null) {
setVisibleElements(name, newState);
}
}
@Override
protected void addFieldInternal(Field real) {
Label labelWidget = null;
if (real.getLabel() != null) {
labelWidget = new Label(real.getLabel());
labelWidget.addStyleName("ftr-label");
labelWidget.addStyleName("ftr-flow-label");
holderGrid.add(labelWidget);
}
setElements(real.getId(), labelWidget, real.getWidget(), real.getExtraWidget());
if (real.getWidget() != null) {
holderGrid.add(real.getWidget());
}
if (real.getExtraWidget() != null) {
holderGrid.add(real.getExtraWidget());
}
}
public void setRequiredAndVisible(String name, boolean newState) {
setRequired(name, newState);
setVisible(name, newState);
}
@Override
public void setError(String name, boolean newState) {
if (name != null) {
super.setErrorForLabel(name, newState);
}
}
@Override
public void setWordWrapForLabel(String labelName, boolean b) {
}
@Override
public void clear() {
holderGrid.clear();
}
@Override
public Iterator iterator() {
return holderGrid.iterator();
}
@Override
public boolean remove(Widget w) {
return holderGrid.remove(w);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy