eu.future.earth.gwt.client.ui.panels.CleanPlaceHolderLabelFieldPanel Maven / Gradle / Ivy
The newest version!
package eu.future.earth.gwt.client.ui.panels;
import java.util.Iterator;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.InlineLabel;
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 CleanPlaceHolderLabelFieldPanel extends AbstractLabelFieldPanel {
private FlowPanel holderGrid = null;
public CleanPlaceHolderLabelFieldPanel() {
FlowPanel main = new FlowPanel();
holderGrid = new FlowPanel();
main.add(holderGrid);
main.add(requiredLabel);
initWidget(holderGrid);
requiredLabel.setVisible(false);
}
private final InlineLabel requiredLabel = new InlineLabel(ImageResources.STATIC_TEXT.requiredFields());
@Override
public void showRequired(boolean hasRequired) {
requiredLabel.setVisible(hasRequired);
}
public void clearButtons() {
holderGrid.clear();
}
@Override
public String getLabel(String name) {
return UiUtil.getPlaceHolder(getEdit(name));
}
@Override
public void setLabel(String name, String newText) {
UiUtil.setPlaceHolder(getEdit(name), newText);
}
@Override
protected void addFieldInternal(Field real) {
setElements(real.getId(), null, real.getWidget(), real.getExtraWidget());
if (real.getWidget() != null) {
addAndSetStyle(real.getWidget());
if (real.getLabel() != null) {
UiUtil.setPlaceHolder(real.getWidget(), real.getLabel());
}
}
if (real.getExtraWidget() != null) {
addAndSetStyle(real.getExtraWidget());
}
}
private void addAndSetStyle(Widget item) {
holderGrid.add(item);
}
@Override
public Field addTwoRows(Field result) {
if (result.getId() == null) {
result.setId(UUID.uuid());
}
if (result.getLabel() != null) {
UiUtil.setPlaceHolder(result.getManager(), result.getLabel());
addAndSetStyle(result.getManager());
}
setElements(result.getId(), null, result.getManager(), result.getExtraWidget());
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);
}
} else {
}
}
}
@Override
public void setVisible(String name, boolean newState) {
if (name != null) {
setVisibleElements(name, newState);
}
}
public void setRequiredAndVisible(String name, boolean newState) {
setRequired(name, newState);
setVisible(name, newState);
}
@Override
public void setRequired(String name, boolean newState) {
if (name != null) {
super.setRequiredForLabel(name, newState);
Widget lbl = super.getEdit(name);
if (lbl != null) {
// String pla = UiUtil.getPlaceHolder(lbl);
// if (pla != null) {
// if (pla.contains("*")) {
// if (!newState) {
// UiUtil.setPlaceHolder(lbl, pla.replace(" *", ""));
// }
// } else {
// if (newState) {
// UiUtil.setPlaceHolder(lbl, pla + " *");
//
// }
// }
// }
}
checkRequiredLegendas();
}
}
@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