use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class ComponentFactory method sortElementsOnPositionAndGroup.
/**
* Return a new list with the elements of the input list sorted on position. Grouped elements are placed together.
* @param elements
*/
public static List<IPersist> sortElementsOnPositionAndGroup(List<IPersist> elements) {
if (elements == null)
return null;
// first sort on position, then move all grouped elements together
List<IPersist> lst = new ArrayList<IPersist>(elements);
Collections.sort(lst, PositionComparator.XY_PERSIST_COMPARATOR);
for (int i = 0; i < lst.size(); i++) {
IPersist element = lst.get(i);
if (element instanceof IFormElement && ((IFormElement) element).getGroupID() != null) {
// find other group elements, move them to the left
for (int j = i + 2; j < lst.size(); j++) {
IPersist element2 = lst.get(j);
if (element2 instanceof IFormElement && ((IFormElement) element).getGroupID().equals(((IFormElement) element2).getGroupID())) {
// same group, move to the left
lst.add(i + 1, lst.remove(j));
i++;
}
}
}
}
return lst;
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class JSSecurity method hasFormAccess.
private boolean hasFormAccess(String formName, String elementName, int accessType) {
Form form = application.getFlattenedSolution().getForm(formName);
int access = 0;
if (form != null) {
UUID accesUUID = null;
if (elementName != null) {
for (IPersist persist : form.getFlattenedFormElementsAndLayoutContainers()) {
if (persist instanceof ISupportName && Utils.equalObjects(elementName, ((ISupportName) persist).getName())) {
accesUUID = persist.getUUID();
break;
}
}
} else {
accesUUID = form.getUUID();
}
if (accesUUID != null) {
access = application.getFlattenedSolution().getSecurityAccess(accesUUID, form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
}
}
return ((access & accessType) != 0);
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class PartNode method getAggregatesFromRenderer.
private void getAggregatesFromRenderer(final List<AggregateVariable> aggregates, final Form f, DataRenderer a_renderer) throws RepositoryException {
Map<IPersist, IDisplay> allFields = a_renderer.getFieldComponents();
Iterator<IDisplay> it = allFields.values().iterator();
while (it.hasNext()) {
IDisplay display = it.next();
if (display instanceof IDisplayData) {
String dataProviderID = ((IDisplayData) display).getDataProviderID();
if (dataProviderID != null) {
IDataProvider dp = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), f).getDataProvider(dataProviderID);
if (dp instanceof AggregateVariable) {
if (!aggregates.contains(dp))
aggregates.add((AggregateVariable) dp);
}
} else if (display instanceof IDisplayTagText) {
String tagText = ((IDisplayTagText) display).getTagText();
Text.processTags(tagText, new ITagResolver() {
public String getStringValue(String name) {
try {
IDataProvider dp = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), f).getDataProvider(name);
if (dp instanceof AggregateVariable) {
if (!aggregates.contains(dp))
aggregates.add((AggregateVariable) dp);
}
} catch (Exception e) {
Debug.error(e);
}
return null;
}
});
}
}
}
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class DataRenderer method createDataAdapter.
void createDataAdapter(IApplication app, IDataProviderLookup dataProviderLookup, IScriptExecuter el, ControllerUndoManager undoManager) throws Exception {
// IScriptExecutor can be null for a design component
FormController formController = el == null ? null : el.getFormController();
dataAdapterList = new DataAdapterList(app, dataProviderLookup, fieldComponents, formController, null, undoManager);
// make it really fields only
HashMap<IPersist, IDisplay> f = new HashMap<IPersist, IDisplay>();
Iterator<Map.Entry<IPersist, IDisplay>> it = fieldComponents.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<IPersist, IDisplay> element = it.next();
if (element.getValue() instanceof IDisplayData) {
String id = ((IDisplayData) element.getValue()).getDataProviderID();
if (dataProviderLookup.getDataProvider(id) instanceof ScriptVariable) {
globalFields.add(element.getValue());
}
f.put(element.getKey(), element.getValue());
}
}
fieldComponents = f;
}
use of com.servoy.j2db.persistence.IPersist 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;
}
Aggregations