use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class ComponentFactory method createComponentEx.
protected static IComponent createComponentEx(IApplication application, Form form, IPersist meta, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
IComponent comp = null;
switch(meta.getTypeID()) {
case IRepository.FIELDS:
comp = createField(application, form, (Field) meta, dataProviderLookup, el, printing);
break;
case IRepository.GRAPHICALCOMPONENTS:
comp = createGraphicalComponent(application, form, (GraphicalComponent) meta, el, dataProviderLookup);
break;
case IRepository.RECTSHAPES:
comp = createRectangle(application, form, (RectShape) meta);
break;
case IRepository.PORTALS:
comp = createPortal(application, form, (Portal) meta, dataProviderLookup, el, printing);
break;
case IRepository.PARTS:
comp = createPart(application, (Part) meta);
break;
case IRepository.TABPANELS:
TabPanel tabPanelMeta = (TabPanel) meta;
int orient = tabPanelMeta.getTabOrientation();
if (orient == TabPanel.SPLIT_HORIZONTAL || orient == TabPanel.SPLIT_VERTICAL)
comp = createSplitPane(application, form, tabPanelMeta, el);
else
comp = createTabPanel(application, form, tabPanelMeta, el);
break;
case IRepository.BEANS:
comp = createBean(application, form, (Bean) meta, null);
break;
case IRepository.WEBCOMPONENTS:
comp = createWebComponentPlaceholder(application, form, (WebComponent) meta);
break;
default:
Debug.error("ComponentFactory:unkown type " + meta.getTypeID() + ", uuid: " + meta.getUUID() + ", parent:" + meta.getParent());
IStandardLabel label = application.getItemFactory().createLabel(getWebID(form, meta), "ComponentFactory:unkown type " + meta.getTypeID());
label.setSize(new Dimension(200, 20));
comp = label;
}
if (comp instanceof JComponent) {
((JComponent) comp).putClientProperty("Id", ComponentFactory.getWebID(form, meta));
}
return comp;
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class FormController method createDataRenderers.
private void createDataRenderers(int viewType) throws Exception {
int v = viewType;
if (getDataSource() == null) {
// form not based on any datasource
v = LOCKED_RECORD_VIEW;
}
application.getDataRenderFactory().prepareRenderers(application, form);
Part bodyPart = null;
Map<Part, IDataRenderer> part_panels = new LinkedHashMap<Part, IDataRenderer>();
Iterator<Part> e2 = form.getParts();
while (e2.hasNext()) {
Part part = e2.next();
Color partColor = ComponentFactory.getPartBackground(application, part, form);
// extract the body (bgcolor)
if (part.getPartType() == Part.BODY) {
bodyPart = part;
bgColor = partColor;
Pair<IStyleSheet, IStyleRule> partStyle = ComponentFactory.getStyleForBasicComponent(application, part, form);
bodyRule = partStyle != null ? partStyle.getRight() : null;
}
if (part.getPartType() == Part.BODY && v == FormController.LOCKED_TABLE_VIEW) {
// don't create part, view == part
continue;
}
IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, part), part.toString(), application, (part.getPartType() == Part.BODY));
dr.initDragNDrop(this, form.getPartStartYPos(part.getID()));
dataRenderers[part.getPartType()] = dr;
dr.setName(part.toString());
part_panels.put(part, dr);
if (part.getPartType() == Part.BODY) {
int onRenderMethodID = form.getOnRenderMethodID();
if (onRenderMethodID > 0) {
dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
}
}
dr.setBackground(partColor);
}
tabSequence.clear();
application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), tabSequence);
if (bodyPart != null && (v == FormController.LOCKED_LIST_VIEW || v == IForm.LIST_VIEW)) {
IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, bodyPart), bodyPart.toString(), application, true);
int onRenderMethodID = form.getOnRenderMethodID();
if (onRenderMethodID > 0) {
dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
}
// apply bgcolor to renderer
if (bgColor != null) {
dr.setBackground(bgColor);
}
dataRenderers[FORM_RENDERER] = dr;
dr.setName(bodyPart.toString());
part_panels = new LinkedHashMap<Part, IDataRenderer>();
part_panels.put(bodyPart, dr);
application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), null);
}
// apply security
int access = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
if (access != -1) {
boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
if (!b_accessible) {
for (IDataRenderer dataRenderer : dataRenderers) {
if (dataRenderer != null) {
Iterator<? extends IComponent> componentIterator = dataRenderer.getComponentIterator();
while (componentIterator.hasNext()) {
IComponent c = componentIterator.next();
if (c instanceof ISupportSecuritySettings) {
if (!b_accessible)
((ISupportSecuritySettings) c).setAccessible(b_accessible);
}
}
}
}
}
}
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class PageDefinition method handleSink.
void handleSink() {
heightLeft -= skipOnY;
if (heightLeft > 0) {
for (int i = panels.size() - 1; i >= 0; i--) {
DataRendererDefinition drd = panels.get(i);
Part part = drd.getPart();
if (part != null) {
if (part.getPartType() == Part.FOOTER || part.getPartType() == Part.TITLE_FOOTER) {
continue;
}
if (part.getSinkWhenLast()) {
// sink
drd.setYlocation(drd.getYlocation() + heightLeft);
heightLeft = 0;
}
}
break;
}
}
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class FormPreviewPanel method process.
// build the chain and fill the renderers,returns number of pages
public int process() throws Exception {
// clear
root = null;
// set size of this panel
orgWidth = new Dimension((int) (currentPageFormat.getWidth() * (1 / factor)), (int) (currentPageFormat.getHeight() * (1 / factor)));
applySize();
part_panels = createPartPanels();
Form form = controllerBeingPreviewed.getForm();
// otherwise you cannot print multiple columns (int) (application.getPageFormat().getImageableWidth()*(1/factor));
int w = form.getWidth();
try {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
Map componentsUsingSliding = application.getDataRenderFactory().completeRenderers(application, form, controllerBeingPreviewed.getScriptExecuter(), part_panels, w, true, null, null);
PropertyCopy.copyExistingPrintableProperties(application, controllerBeingPreviewed, part_panels);
Iterator<DataRenderer> panels = part_panels.values().iterator();
while (panels.hasNext()) {
DataRenderer panel = panels.next();
panel.setComponentsUsingSliding(componentsUsingSliding);
DataRendererFactory.addSpringsBetweenComponents(application, panel);
}
// $NON-NLS-1$
Debug.trace("usesSliding " + (componentsUsingSliding.size() != 0));
} finally {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", null);
}
// create list
renderParent = application.getPrintingRendererParent();
plist = new PageList(application, this, renderParent);
PartNode node = null;
// create the chain based on the sort,LAST node must be the body part (is virtal added if not present)
Part body = null;
FormController fp = ((FormManager) application.getFormManager()).leaseFormPanel(controllerBeingPreviewed.getName());
if (fp != null && !fp.isShowingData()) {
// List lst = fp.getFormModel().getLastSearchColumns();
if (fp.wantEmptyFoundSet()) {
if (fp.getFormModel() != null)
fp.getFormModel().clear();
} else {
fp.loadAllRecords();
}
// fp.getFormModel().sort(lst);
}
List<SortColumn> sortColumns = ((FoundSet) formData).getLastSortColumns();
if (formData.getSize() != 0) {
if (sortColumns != null) {
Set<String> consumed = new HashSet<String>();
for (int i = 0; i < sortColumns.size(); i++) {
SortColumn sc = sortColumns.get(i);
Iterator<Part> it = part_panels.keySet().iterator();
while (it.hasNext()) {
Part part = it.next();
DataRenderer dr = part_panels.get(part);
if (part.getPartType() == Part.BODY) {
body = part;
continue;
}
if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
IRecordInternal state = new PageNumberState(formData, plist);
plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
continue;
}
boolean match = false;
int inlineCount = 0;
List<SortColumn> partSortColumns = new ArrayList<SortColumn>();
SortColumn lastMatch = sc;
String groupByDataproviders = part.getGroupbyDataProviderIDs() != null ? part.getGroupbyDataProviderIDs() : "";
// $NON-NLS-1$ //$NON-NLS-2$
StringTokenizer tk = new StringTokenizer("" + groupByDataproviders.toLowerCase(), ", ");
int tokenCount = tk.countTokens();
String[] ids = new String[tokenCount];
for (; inlineCount < tokenCount; inlineCount++) {
String id = tk.nextToken();
ids[inlineCount] = id;
if (lastMatch.getDataProviderID().equals(id)) {
partSortColumns.add(lastMatch);
if ((i + inlineCount + 1) < sortColumns.size()) {
lastMatch = sortColumns.get(i + inlineCount + 1);
if (part.getPartType() == Part.LEADING_SUBSUMMARY && consumed.contains(lastMatch)) {
break;
}
} else {
break;
}
} else {
break;
}
}
if (// did all match?
tokenCount > 0 && partSortColumns.size() == tokenCount) {
match = true;
if (part.getPartType() == Part.LEADING_SUBSUMMARY) {
for (String element : ids) {
consumed.add(element);
}
}
}
if (match) {
SortColumn[] array = new SortColumn[partSortColumns.size()];
partSortColumns.toArray(array);
if (// create root
root == null) {
root = new PartNode(this, part, dr, renderParent, array);
node = root;
} else {
if (!tryToPlaceInExistingNodes(part, dr, array)) {
PartNode newNode = new PartNode(this, part, dr, renderParent, array);
node.setChild(newNode);
node = newNode;
}
}
}
}
}
PartNode newNode = null;
if (body == null) {
// a virtual body (when no body is placed in the parts)
newNode = new PartNode(this, null, null, renderParent, null);
} else {
// the body
newNode = new PartNode(this, body, part_panels.get(body), renderParent, null);
}
if (node != null) {
node.setChild(newNode);
} else {
root = newNode;
}
} else // no sort...
{
if (// search for body
body == null) {
Iterator<Part> it = part_panels.keySet().iterator();
while (it.hasNext()) {
Part part = it.next();
DataRenderer dr = part_panels.get(part);
IRecordInternal state = new PageNumberState(formData, plist);
if (part.getPartType() == Part.BODY) {
body = part;
continue;
}
if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
continue;
}
}
}
if (body == null) {
// a virtual body (when no body is placed in the parts)
root = new PartNode(this, null, null, renderParent, null);
} else // if (body != null)
{
// the body
root = new PartNode(this, body, part_panels.get(body), renderParent, null);
}
}
}
try {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
long t1 = System.currentTimeMillis();
// fill the renderers with data
if (root != null) {
// dump chain
// $NON-NLS-1$
Debug.trace("Root " + root);
QuerySelect sqlString = ((FoundSet) formData).getQuerySelectForReading();
Table table = formData.getSQLSheet().getTable();
FoundSet fs = (FoundSet) ((FoundSetManager) application.getFoundSetManager()).getNewFoundSet(table, null, sortColumns);
fs.browseAll(sqlString);
long t3 = System.currentTimeMillis();
List<DataRendererDefinition> childRetval = root.process(this, fs, table, sqlString);
long t4 = System.currentTimeMillis();
if (Debug.tracing()) {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.trace("Database queries took " + ((t4 - t3) / 1000f) + " second");
}
if (childRetval != null) {
for (int i = 0; i < childRetval.size(); i++) {
plist.addPanel(childRetval.get(i));
}
}
}
plist.finish();
long t2 = System.currentTimeMillis();
int pageCount = plist.getNumberOfPages();
// dump
if (Debug.tracing()) {
Debug.trace(plist);
// $NON-NLS-1$ //$NON-NLS-2$
Debug.trace("Generated " + pageCount / ((t2 - t1) / 1000f) + " printable pages per second");
}
} finally {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", null);
}
renderParent.removeAll();
return plist.getNumberOfPages();
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class WebListFormUI method getFormElements.
@Override
public List<FormElement> getFormElements() {
if (cachedElements.size() == 0) {
Form form = getController().getForm();
List<IFormElement> elements = form.getFlattenedObjects(PositionComparator.XY_PERSIST_COMPARATOR);
Iterator<IFormElement> it = elements.iterator();
Part body = FormElementHelper.INSTANCE.getBodyPart(form);
int bodyStartY = form.getPartStartYPos(body.getID());
int bodyEndY = body.getHeight();
// only the elements from other form parts then body still need to be added to cached elements
while (it.hasNext()) {
IFormElement element = it.next();
if (bodyStartY <= element.getLocation().y && bodyEndY > element.getLocation().y) {
it.remove();
}
}
elements.add(getPortal());
cachedElements = FormElementHelper.INSTANCE.getFormElements(new ArrayList<IPersist>(elements).iterator(), getDataConverterContext());
}
return cachedElements;
}
Aggregations