use of com.servoy.j2db.persistence.Field in project servoy-client by Servoy.
the class FormTemplateGenerator method isSingleValueComponent.
/**
* @return false if the persist has no valuelist or at most one value in the valuelist, true otherwise
*/
public static boolean isSingleValueComponent(IFormElement persist) {
Field field = (Field) persist;
if (field.getValuelistID() > 0) {
try {
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
FlattenedSolution fs = new FlattenedSolution((SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(((Solution) persist.getRootObject()).getName(), IRepository.SOLUTIONS), new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return ApplicationServerRegistry.get().getLocalRepository();
}
});
ValueList valuelist = fs.getValueList(field.getValuelistID());
return isSingleValue(valuelist);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return true;
}
use of com.servoy.j2db.persistence.Field 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.persistence.Field in project servoy-client by Servoy.
the class JSForm method newField.
/**
* Creates a new JSField object on the form - including the dataprovider/JSVariable of the JSField object, the "x" and "y" position of the JSField object in pixels, as well as the width and height of the JSField object in pixels.
*
* @sample
* var form = solutionModel.newForm('newForm1', myDatasource, null, true, 800, 600);
* var variable = form.newVariable('myVar', JSVariable.TEXT);
* variable.defaultValue = "'This is a default value (with triple quotes)!'";
* var field = form.newField(variable, JSField.TEXT_FIELD, 100, 100, 200, 200);
* forms['newForm1'].controller.show();
*
* @param dataprovider the specified dataprovider name/JSVariable of the JSField object
*
* @param type the display type of the JSField object (see the Solution Model -> JSField node for display types)
*
* @param x the horizontal "x" position of the JSField object in pixels
*
* @param y the vertical "y" position of the JSField object in pixels
*
* @param width the width of the JSField object in pixels
*
* @param height the height of the JSField object in pixels
*
* @return a new JSField object (of the specified display type)
*/
@JSFunction
public JSField newField(Object dataprovider, int type, int x, int y, int width, int height) {
checkModification();
try {
Field field = getContainer().createNewField(new Point(x, y));
field.setDisplayType(type);
CSSPositionUtils.setSize(field, width, height);
if (dataprovider instanceof String) {
field.setDataProviderID((String) dataprovider);
} else if (dataprovider instanceof JSVariable) {
field.setDataProviderID(((JSVariable) dataprovider).getScriptVariable().getDataProviderID());
}
return JSField.createField(this, field, application, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.Field in project servoy-client by Servoy.
the class JSForm method getFields.
/**
* Returns all JSField objects of this form, including the ones without a name.
*
* @sample
* var frm = solutionModel.getForm("myForm");
* var fields = frm.getFields();
* for (var f in fields)
* {
* var fname = fields[f].name;
* if (fname != null)
* application.output(fname);
* }
*
* @param returnInheritedElements boolean true to also return the elements from the parent form
* @return all JSField objects of this form
*/
@JSFunction
public JSField[] getFields(boolean returnInheritedElements) {
List<JSField> fields = new ArrayList<JSField>();
AbstractContainer form2use = returnInheritedElements ? getFlattenedContainer() : getContainer();
Iterator<Field> iterator = form2use.getFields();
while (iterator.hasNext()) {
fields.add(JSField.createField(this, iterator.next(), application, false));
}
return fields.toArray(new JSField[fields.size()]);
}
use of com.servoy.j2db.persistence.Field in project servoy-client by Servoy.
the class JSPortal method getFields.
/**
* Retrieves an array with all fields in a portal.
*
* @sampleas getField(String)
*
* @return An array with JSField instances corresponding to all fields in the portal.
*/
@JSFunction
public JSField[] getFields() {
ArrayList<JSField> fields = new ArrayList<JSField>();
Iterator<Field> iterator = getBaseComponent(false).getFields();
while (iterator.hasNext()) {
Field field = iterator.next();
fields.add(JSField.createField(this, field, application, false));
}
return fields.toArray(new JSField[fields.size()]);
}
Aggregations