use of com.servoy.j2db.dataui.IServoyAwareBean in project servoy-client by Servoy.
the class ComponentFactory method createBean.
protected static IComponent createBean(IApplication application, Form form, Bean bean, FlattenedSolution flattenedSolution) {
IComponent c = null;
try {
Object obj = getBeanInstanceFromXML(application, bean.getBeanClassName(), bean.getBeanXML());
if (flattenedSolution != null && obj != null) {
obj = flattenedSolution.setBeanDesignInstance(bean, obj);
}
if (obj instanceof Component) {
((Component) obj).setName(bean.getName());
} else if (obj instanceof IComponent) {
((IComponent) obj).setName(bean.getName());
}
if (obj instanceof IServoyAwareBean) {
((IServoyAwareBean) obj).initialize((IClientPluginAccess) application.getPluginAccess());
}
if (obj instanceof IServoyBeanFactory) {
testReturnTypesForBean(application, obj);
obj = ((IServoyBeanFactory) obj).getBeanInstance(application.getApplicationType(), (IClientPluginAccess) application.getPluginAccess(), new Object[] { ComponentFactory.getWebID(form, bean), form.getName(), form.getStyleName() });
}
testReturnTypesForBean(application, obj);
if (obj instanceof Applet) {
((FormManager) application.getFormManager()).initializeApplet((Applet) obj, bean.getSize());
}
if (obj == null) {
c = application.getItemFactory().createLabel(ComponentFactory.getWebID(form, bean), "bean missing " + bean.getBeanClassName());
} else if (!(obj instanceof java.awt.Component) && !(obj instanceof IComponent)) {
c = application.getItemFactory().createInvisibleBean(ComponentFactory.getWebID(form, bean), obj);
} else if (!(obj instanceof IComponent)) {
c = application.getItemFactory().createBeanHolder(ComponentFactory.getWebID(form, bean), (Component) obj, bean.getAnchors());
} else {
c = (IComponent) obj;
}
// beans do not store the transparent property, keep the value from component
boolean isOpaque = c.isOpaque();
applyBasicComponentProperties(application, c, bean, null);
c.setOpaque(isOpaque);
} catch (// sometimes setting size or location throws exception or even error...create label instead
Throwable e) {
Debug.error(e);
c = application.getItemFactory().createLabel(bean.getName(), "error acessing bean" + bean.getBeanClassName());
java.awt.Dimension dim = bean.getSize();
if (dim != null)
c.setSize(bean.getSize());
}
return c;
}
use of com.servoy.j2db.dataui.IServoyAwareBean in project servoy-client by Servoy.
the class DataAdapterList method valueChanged.
/*
* _____________________________________________________________ JavaScriptModificationListner
*/
/**
* listen for global var changes via own listener and state vars(mainly columns) via state listener if via javascript any var is changed it will be noted
* here,and dispatched to refresh the displays
*/
public void valueChanged(ModificationEvent e) {
if (destroyed) {
Debug.error("Destroyed DataAdapterList " + formController + " was still attached to the record: " + e.getRecord() + ", removing it if possible, currentRecord: " + currentRecord, new RuntimeException());
if (e.getRecord() != null)
e.getRecord().removeModificationListener(this);
else if (currentRecord != null)
currentRecord.removeModificationListener(this);
return;
}
if (formController != null && formController.isDestroyed()) {
Debug.error("Destroying DataAdapterList of a destroyed " + formController, new RuntimeException());
destroy();
return;
}
FormScope formScope = getFormScope();
if (visible && (currentRecord != null || (formScope != null && formScope.has(e.getName(), formScope)))) {
for (IDataAdapter da : dataAdapters.values()) {
// dataAdapter should call state.getValue if name from event is same as its dataProviderID
da.valueChanged(e);
}
// check if a related adapter depends on he global
if (e != null && e.getName() != null) {
for (IDisplayRelatedData drd : relatedDataAdapters) {
boolean depends = false;
String[] allRelationNames = drd.getAllRelationNames();
for (int a = 0; !depends && allRelationNames != null && a < allRelationNames.length; a++) {
Relation[] relations = application.getFlattenedSolution().getRelationSequence(allRelationNames[a]);
for (int r = 0; !depends && relations != null && r < relations.length; r++) {
try {
IDataProvider[] primaryDataProviders = relations[r].getPrimaryDataProviders(application.getFlattenedSolution());
for (int p = 0; !depends && primaryDataProviders != null && p < primaryDataProviders.length; p++) {
depends = e.getName().equals(primaryDataProviders[p].getDataProviderID());
}
} catch (RepositoryException ex) {
Debug.log(ex);
}
}
}
if (depends) {
// related adapter depends on the modified global
if (drd instanceof IDisplayDependencyData)
((IDisplayDependencyData) drd).dependencyChanged(currentRecord);
else
drd.setRecord(currentRecord, true);
}
}
}
// inform servoy aware beans
for (IServoyAwareBean drd : servoyAwareBeans) {
if (drd instanceof IModificationListener) {
try {
((IModificationListener) drd).valueChanged(e);
} catch (RuntimeException ex) {
// never make the app break on faulty beans
Debug.error(ex);
}
}
}
}
}
use of com.servoy.j2db.dataui.IServoyAwareBean in project servoy-client by Servoy.
the class DataAdapterList method destroy.
/**
*/
public void destroy() {
if (currentRecord != null) {
// With prototype you can still get global foundsets
// setRecord(new PrototypeState(currentRecord.getParentFoundSet()), true);
setRecord(null, false);
}
if (formController != null && !formController.isDestroyed() && formController.getFormScope() != null) {
formController.getFormScope().getModificationSubject().removeModificationListener(this);
}
IExecutingEnviroment er = application.getScriptEngine();
if (er != null) {
SolutionScope ss = er.getSolutionScope();
if (ss != null) {
ScopesScope gs = ss.getScopesScope();
if (gs != null) {
gs.getModificationSubject().removeModificationListener(this);
}
}
}
if (servoyAwareBeans != null) {
for (IServoyAwareBean b : servoyAwareBeans) {
try {
if (b instanceof IDestroyable) {
((IDestroyable) b).destroy();
}
} catch (RuntimeException e) {
// never make the app break on faulty beans
Debug.error(e);
}
}
}
servoyAwareBeans = null;
if (relatedDataAdapters != null) {
for (IDisplayRelatedData drd : relatedDataAdapters) {
drd.destroy();
}
}
relatedDataAdapters = null;
if (dataDisplays != null) {
for (IDisplayData dd : dataDisplays) {
if (dd instanceof IDestroyable) {
((IDestroyable) dd).destroy();
}
}
}
dataDisplays = null;
if (dataAdapters != null) {
for (IDataAdapter da : dataAdapters.values()) {
if (da instanceof IDestroyable) {
((IDestroyable) da).destroy();
}
}
}
dataAdapters = null;
currentDisplay = null;
visible = false;
destroyed = true;
if (currentRecord != null) {
// $NON-NLS-1$
Debug.error("After destroy there is still a current record in DataAdapterList of formcontroller: " + formController, new RuntimeException());
currentRecord.removeModificationListener(this);
}
}
use of com.servoy.j2db.dataui.IServoyAwareBean 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.dataui.IServoyAwareBean in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method initializeComponent.
@SuppressWarnings("nls")
private void initializeComponent(final Component c, AbstractBase view, IPersist element) {
if (dal != null && dal.isDestroyed()) {
Debug.error("Trying to initialize a component: " + c + " of " + view + " element: " + element + " that is in a destroyed tableview", new RuntimeException());
return;
}
if (// Don't know any other place for this
view instanceof Portal && c instanceof IDisplayData) {
String id = ((IDisplayData) c).getDataProviderID();
if (id != null && !ScopesUtils.isVariableScope(id) && id.startsWith(((Portal) view).getRelationName() + '.')) {
((IDisplayData) c).setDataProviderID(id.substring(((Portal) cellview).getRelationName().length() + 1));
}
}
if (!isListViewMode() && c instanceof WebDataCheckBox) {
// $NON-NLS-1$
((WebDataCheckBox) c).setText("");
}
if (element != null) {
// apply to this cell the state of the columnIdentifier IComponent, do keep the location that is set by the tableview when creating these components the first time.
// for listview this is the location to use.
Point loc = ((IComponent) c).getLocation();
int height = ((IComponent) c).getSize().height;
PropertyCopy.copyElementProps((IComponent) elementToColumnIdentifierComponent.get(element), (IComponent) c);
if (!isListViewMode()) {
((IComponent) c).setLocation(loc);
// it shouldn't be possible to change the height
if (c instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) c).getScriptObject();
if (so instanceof IRuntimeComponent) {
IRuntimeComponent ic = (IRuntimeComponent) so;
if (ic.getHeight() != height) {
ic.setSize(ic.getWidth(), height);
}
}
}
}
} else {
// $NON-NLS-1$
Debug.log("Cannot find the IPersist element for cell " + c.getMarkupId());
}
if (c instanceof IDisplayData) {
IDisplayData cdd = (IDisplayData) c;
if (!(dal != null && dal.getFormScope() != null && cdd.getDataProviderID() != null && // skip for form variables
dal.getFormScope().get(cdd.getDataProviderID()) != Scriptable.NOT_FOUND)) {
cdd.setValidationEnabled(validationEnabled);
}
} else if (c instanceof IDisplayRelatedData) {
((IDisplayRelatedData) c).setValidationEnabled(validationEnabled);
} else if (c instanceof IServoyAwareBean) {
((IServoyAwareBean) c).setValidationEnabled(validationEnabled);
}
addClassToCellComponent(c);
if (// the check could be extended against IDelegate<?>
c instanceof WebDataCompositeTextField) {
Object delegate = ((WebDataCompositeTextField) c).getDelegate();
if (delegate instanceof Component) {
// make sure that this class is added accordingly in TemplateGenerator as a style selector containing relevant properties
addClassToCellComponent((Component) delegate);
}
}
if (c instanceof ISupportValueList) {
ISupportValueList idVl = (ISupportValueList) elementToColumnIdentifierComponent.get(element);
IValueList list;
if (idVl != null && (list = idVl.getValueList()) != null) {
ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
((ISupportValueList) c).setValueList(list);
}
}
}
applyClientProperties(c, element);
}
Aggregations