use of com.servoy.j2db.ui.IFieldComponent in project servoy-client by Servoy.
the class WebDataRendererFactory method placeElements.
protected Map placeElements(IApplication app, Form form, IScriptExecuter listener, Map emptyDataRenderers, boolean printing, ControllerUndoManager undoManager, TabSequenceHelper<Component> tabSequence) throws Exception {
// $NON-NLS-1$
final boolean useAJAX = Utils.getAsBoolean(app.getRuntimeProperties().get("useAJAX"));
IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
Map listTocomplete = new HashMap();
Map labelForComponents = new HashMap();
String orientation = OrientationApplier.getHTMLContainerOrientation(app.getLocale(), app.getSolution().getTextOrientation());
// $NON-NLS-1$
boolean leftToRight = !"rtl".equalsIgnoreCase(orientation);
// $NON-NLS-1$
boolean isAnchoringEnabled = Utils.getAsBoolean(app.getRuntimeProperties().get("enableAnchors"));
// Insets insets = new Insets(0, 0, 0, 0);
for (IFormElement obj : Utils.iterate(form.getFormElementsSortedByFormIndex())) {
Point l = null;
l = (obj).getLocation();
// unknown where to add
if (l == null)
continue;
if (printing && obj instanceof ISupportPrinting) {
if (!((ISupportPrinting) obj).getPrintable())
continue;
}
Iterator it = emptyDataRenderers.values().iterator();
while (it.hasNext()) {
WebDataRenderer panel = (WebDataRenderer) it.next();
// Border border = panel.getBorder();
// if (border instanceof EmptyBorder)
// {
// insets = ((EmptyBorder)border).getBorderInsets();
// }
int start = panel.getLocation().y;
if (l.y >= start && l.y < start + panel.getSize().height) {
org.apache.wicket.Component comp = (org.apache.wicket.Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listener, printing);
if (comp != null) {
if (obj instanceof Field) {
String name = ((Field) obj).getName();
if (name != null && !"".equals(name)) {
labelForComponents.put(name, comp);
}
} else if (obj instanceof GraphicalComponent && (comp instanceof WebBaseLabel || comp instanceof WebBaseSubmitLink)) {
String labelFor = ((GraphicalComponent) obj).getLabelFor();
if (labelFor != null && !"".equals(labelFor)) {
labelForComponents.put(comp, labelFor);
}
}
if ((obj instanceof ISupportTabSeq) && (tabSequence != null)) {
tabSequence.add(panel, (ISupportTabSeq) obj, comp);
}
org.apache.wicket.Component newComp = comp;
if (newComp instanceof IDisplay) {
panel.addDisplayComponent(obj, (IDisplay) newComp);
} else if (newComp instanceof WebImageBeanHolder) {
WebImageBeanHolder wiBeanHolder = (WebImageBeanHolder) newComp;
Object bean = wiBeanHolder.getDelegate();
if (bean instanceof IServoyAwareBean) {
IServoyAwareBean ourBean = (IServoyAwareBean) bean;
panel.addDisplayComponent(obj, ourBean);
}
}
((IComponent) comp).setLocation(new Point((l.x), (l.y - start)));
if (form.getOnRecordEditStartMethodID() > 0 && comp instanceof IFieldComponent) {
if (useAJAX && comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null && !ScopesUtils.isVariableScope(((IDisplayData) comp).getDataProviderID())) {
StartEditOnFocusGainedEventBehavior.addNewBehaviour(comp);
}
}
// - beans
if (isAnchoringEnabled && (((obj instanceof Field) && WebAnchoringHelper.needsWrapperDivForAnchoring((Field) obj)) || (obj instanceof Bean) || ((obj instanceof GraphicalComponent) && ComponentFactory.isButton((GraphicalComponent) obj)))) {
panel.add(WebAnchoringHelper.getWrapperComponent(comp, obj, start, panel.getSize(), leftToRight, false));
} else {
panel.add(comp);
}
}
}
}
}
Iterator it = labelForComponents.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Entry) it.next();
Object key = entry.getKey();
if (key instanceof WebBaseLabel || key instanceof WebBaseSubmitLink) {
IFieldComponent component = (IFieldComponent) labelForComponents.get(entry.getValue());
if (component != null) {
if (key instanceof WebBaseLabel) {
((WebBaseLabel) entry.getKey()).setLabelFor(component);
} else {
((WebBaseSubmitLink) entry.getKey()).setLabelFor(component);
}
(component).addLabelFor((ILabel) entry.getKey());
if (!component.isVisible()) {
component.setComponentVisible(component.isVisible());
}
if (!component.isEnabled()) {
component.setComponentEnabled(component.isEnabled());
}
}
}
}
it = emptyDataRenderers.values().iterator();
while (it.hasNext()) {
WebDataRenderer panel = (WebDataRenderer) it.next();
panel.createDataAdapter(app, dataProviderLookup, listener, undoManager);
}
return listTocomplete;
}
use of com.servoy.j2db.ui.IFieldComponent in project servoy-client by Servoy.
the class ComponentFactory method createTypeAheadWithValueList.
/**
* @param application
* @param field
* @param dataProviderLookup
* @param fl
* @return
*/
private static IFieldComponent createTypeAheadWithValueList(IApplication application, Form form, Field field, IDataProviderLookup dataProviderLookup, int type, ParsedFormat format, IStylePropertyChangesRecorder jsChangeRecorder) {
RuntimeDataField scriptable;
IFieldComponent fl;
ValueList valuelist = application.getFlattenedSolution().getValueList(field.getValuelistID());
if (valuelist == null) {
scriptable = new RuntimeDataField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataField(scriptable, getWebID(form, field));
} else {
scriptable = new RuntimeDataLookupField(jsChangeRecorder, application);
if (valuelist.getValueListType() == IValueListConstants.DATABASE_VALUES) {
try {
IValueList secondLookup = getFallbackValueList(application, field.getDataProviderID(), type, format, valuelist);
LookupValueList lookupValueList = new LookupValueList(valuelist, application, secondLookup, format != null ? format.getDisplayFormat() : null);
fl = application.getItemFactory().createDataLookupField((RuntimeDataLookupField) scriptable, getWebID(form, field), lookupValueList);
} catch (Exception e1) {
Debug.error(e1);
return null;
}
} else if (valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES || valuelist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
fl = application.getItemFactory().createDataLookupField((RuntimeDataLookupField) scriptable, getWebID(form, field), (CustomValueList) getRealValueList(application, valuelist, true, type, format, field.getDataProviderID()));
} else {
return null;
}
}
scriptable.setComponent(fl, field);
return fl;
}
use of com.servoy.j2db.ui.IFieldComponent in project servoy-client by Servoy.
the class DataRendererFactory method placeElements.
// returns usesSliding
private Map placeElements(Iterator<IFormElement> e1, IApplication app, Form form, IScriptExecuter listner, Map emptyDataRenderers, int width, int XCorrection, int YCorrection, boolean printing, boolean cutDataProviderNames, ControllerUndoManager undoManager, boolean isPortal, TabSequenceHelper<Component> tabSequence) throws Exception {
IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
Map listTocomplete = new HashMap();
Map labelForComponents = new HashMap();
// Insets insets = new Insets(0, 0, 0, 0);
while (e1.hasNext()) {
Point l = null;
IPersist obj = e1.next();
l = ((IFormElement) obj).getLocation();
// unkown where to add
if (l == null)
continue;
if (printing && obj instanceof ISupportPrinting) {
if (!((ISupportPrinting) obj).getPrintable())
continue;
}
Iterator it = emptyDataRenderers.values().iterator();
while (it.hasNext()) {
DataRenderer panel = (DataRenderer) it.next();
int start = panel.getLocation().y;
if (l.y >= start && l.y < start + panel.getSize().height) {
Component comp = (Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listner, printing);
// Test for a visible bean, then get the real component
if (comp instanceof VisibleBean) {
comp = ((VisibleBean) comp).getDelegate();
}
if (comp != null) {
if (obj instanceof Field && comp instanceof JComponent) {
String name = ((Field) obj).getName();
if (name != null && !"".equals(name)) {
labelForComponents.put(name, comp);
}
} else if (obj instanceof GraphicalComponent && comp instanceof JLabel) {
String labelFor = ((GraphicalComponent) obj).getLabelFor();
if (labelFor != null && !"".equals(labelFor)) {
labelForComponents.put(comp, labelFor);
}
}
if (obj instanceof ISupportTabSeq && comp instanceof JComponent && (tabSequence != null)) {
tabSequence.add(panel, (ISupportTabSeq) obj, comp);
}
Component newComp = comp;
if (newComp instanceof IDisplay) {
// HACK:don;t no other way to do this.........
if (newComp instanceof IDisplayData && cutDataProviderNames) {
IDisplayData da = (IDisplayData) newComp;
String id = da.getDataProviderID();
if (id != null && !ScopesUtils.isVariableScope(id)) {
// only cut first relation (so you can have relation chain inside portal)
int index = id.indexOf('.');
// TODO:check if part before . is same as relation name (objToRender.getRelationID() )
if (index > 0) {
id = id.substring(index + 1);
}
da.setDataProviderID(id);
}
}
panel.addDisplayComponent(obj, (IDisplay) newComp);
}
comp.setLocation((l.x) + XCorrection, (l.y - start) + YCorrection);
int index = 0;
if (!printing && obj instanceof ISupportAnchors) {
panel.add(comp, new Integer(((ISupportAnchors) obj).getAnchors()), index);
} else if (printing) {
if (obj instanceof ISupportPrintSliding && !isPortal) {
int slide = ((ISupportPrintSliding) obj).getPrintSliding();
if (slide != ISupportPrintSliding.NO_SLIDING) {
listTocomplete.put(comp, new Integer(slide));
panel.setUsingSliding(true);
}
}
panel.add(comp, index);
} else {
panel.add(comp, index);
}
}
}
}
}
if (!printing) {
Iterator it = labelForComponents.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Entry) it.next();
if (entry.getKey() instanceof JLabel) {
JComponent component = (JComponent) labelForComponents.get(entry.getValue());
if (component != null) {
((JLabel) entry.getKey()).setLabelFor(component);
if (component instanceof IFieldComponent) {
((IFieldComponent) component).addLabelFor((ILabel) entry.getKey());
if (!((IFieldComponent) component).isVisible()) {
((IFieldComponent) component).setComponentVisible(((IFieldComponent) component).isVisible());
}
if (!((IFieldComponent) component).isEnabled()) {
((IFieldComponent) component).setComponentEnabled(((IFieldComponent) component).isEnabled());
}
}
}
}
}
}
Iterator it = emptyDataRenderers.values().iterator();
while (it.hasNext()) {
DataRenderer panel = (DataRenderer) it.next();
panel.createDataAdapter(app, dataProviderLookup, listner, undoManager);
}
return listTocomplete;
}
use of com.servoy.j2db.ui.IFieldComponent in project servoy-client by Servoy.
the class WebBaseLabel method onComponentTag.
@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
// $NON-NLS-1$
boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX"));
if (useAJAX) {
// $NON-NLS-1$
Object oe = scriptable.getClientProperty("ajax.enabled");
if (oe != null)
useAJAX = Utils.getAsBoolean(oe);
}
if (!useAJAX) {
Form<?> f = getForm();
if (f != null) {
if (eventExecutor.hasActionCmd()) {
CharSequence url = urlFor(ILinkListener.INTERFACE);
// $NON-NLS-1$
tag.put("onclick", f.getJsForInterfaceUrl(url));
}
if (eventExecutor.hasDoubleClickCmd()) {
CharSequence urld = urlFor(IDoubleClickListener.INTERFACE);
// $NON-NLS-1$
tag.put("ondblclick", f.getJsForInterfaceUrl(urld));
}
if (eventExecutor.hasRightClickCmd()) {
CharSequence urlr = urlFor(IRightClickListener.INTERFACE);
// We need a "return false;" so that the context menu is not displayed in the browser.
// $NON-NLS-1$ //$NON-NLS-2$
tag.put("oncontextmenu", f.getJsForInterfaceUrl(urlr) + " return false;");
}
}
}
if (// $NON-NLS-1$
tag.getName().equalsIgnoreCase("label")) {
IFieldComponent labelFor = getLabelFor();
if (labelFor instanceof Component) {
// $NON-NLS-1$
tag.put("for", ((Component) labelFor).getMarkupId());
char displayMnemonic = (char) getDisplayedMnemonic();
// $NON-NLS-1$
if (displayMnemonic > 0)
tag.put("accesskey", Character.toString(displayMnemonic));
}
}
}
use of com.servoy.j2db.ui.IFieldComponent in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method focusFirstField.
public void focusFirstField() {
// find column that should get focus
ArrayList<PersistColumnIdentifierComponent> orderedPersistColumnIdentifierComponent = getOrderedPersistColumnIdentifierComponents();
Component firstFocusableColumnIdentifier = null;
for (PersistColumnIdentifierComponent pci : orderedPersistColumnIdentifierComponent) {
IComponent c = pci.getComponent();
if (!(c instanceof WebBaseButton || c instanceof WebBaseLabel || !c.isEnabled() || (validationEnabled && c instanceof IFieldComponent && !((IFieldComponent) c).isEditable()))) {
firstFocusableColumnIdentifier = (Component) c;
break;
}
}
if (firstFocusableColumnIdentifier != null)
setColumnThatRequestsFocus(firstFocusableColumnIdentifier);
}
Aggregations