use of com.servoy.j2db.smart.dataui.DataRenderer 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.smart.dataui.DataRenderer in project servoy-client by Servoy.
the class SwingForm method initView.
public IView initView(IApplication application, FormController fp, int viewType) {
view = null;
IDataRenderer[] dataRenderers = fp.getDataRenderers();
setTitleHeader((JComponent) dataRenderers[Part.TITLE_HEADER]);
setHeader((JComponent) dataRenderers[Part.HEADER]);
setLeadingGrandSummary((JComponent) dataRenderers[Part.LEADING_GRAND_SUMMARY]);
setTrailingGrandSummary((JComponent) dataRenderers[Part.TRAILING_GRAND_SUMMARY]);
setFooter((JComponent) dataRenderers[Part.FOOTER]);
// remove any left slider
setWest(null);
switch(viewType) {
case FormController.LOCKED_LIST_VIEW:
case IForm.LIST_VIEW:
view = new ListView();
PrototypeState proto = null;
if (fp.getFoundSet() != null) {
proto = fp.getFoundSet().getPrototypeState();
} else {
proto = new PrototypeState(null);
}
// this call is extreemly inportant, it prevent all rows retrieval
((ListView) view).setPrototypeCellValue(proto);
FormBodyEditor editor = null;
if (dataRenderers[FormController.FORM_RENDERER] != null) {
Component[] rendererComponents = ((Container) dataRenderers[FormController.FORM_RENDERER]).getComponents();
for (Component rendererComponent : rendererComponents) {
if (rendererComponent instanceof ISupportAsyncLoading) {
// in listview it is impossible to get lazy loaded images displaying correctly, due to needed repaintfire, which we cannot initiate
((ISupportAsyncLoading) rendererComponent).setAsyncLoadingEnabled(false);
}
rendererComponent.setFocusable(false);
}
((Component) dataRenderers[FormController.FORM_RENDERER]).setFocusable(false);
}
editor = new FormBodyEditor((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
if (dataRenderers[FormController.FORM_RENDERER] != null) {
DataRenderer dr = (DataRenderer) dataRenderers[FormController.FORM_RENDERER];
dr.setRenderer(true);
String bgcolorCalc = fp.getForm().getRowBGColorCalculation();
if (bgcolorCalc != null) {
// dr.setRowBGColorProvider(bgcolorCalc);
dr.setShowSelection(false);
// $NON-NLS-1$
((ListView) view).setRowBGColorScript(bgcolorCalc, fp.getForm().getFlattenedMethodArguments("rowBGColorCalculation"));
((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
}
((ListView) view).setCellRenderer(dr);
} else {
// form with no body part - used only for printing probably
((ListView) view).setCellRenderer(new ListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// $NON-NLS-1$
return new JLabel("");
}
});
}
((ListView) view).setCellEditor(editor);
((ListView) view).setRendererSameAsEditor(false);
((ListView) view).setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
break;
case FormController.LOCKED_TABLE_VIEW:
case FormController.TABLE_VIEW:
view = new TableView(application, fp, fp.getForm(), fp.getForm(), fp.getScriptExecuter(), dataRenderers[Part.HEADER], dataRenderers[Part.LEADING_GRAND_SUMMARY], false);
if (dataRenderers[FormController.FORM_EDITOR] != null)
dataRenderers[FormController.FORM_EDITOR].destroy();
dataRenderers[FormController.FORM_EDITOR] = (IDataRenderer) view;
if (formController.getBodyStyle() != null) {
Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getCSSPairStyleForForm(application, fp.getForm());
if (pairStyle != null && pairStyle.getLeft() != null) {
Border border = pairStyle.getLeft().getBorder(formController.getBodyStyle());
if (border != null) {
innerPanel.setBorder(border);
}
}
}
break;
case IForm.LOCKED_RECORD_VIEW:
case IForm.RECORD_VIEW:
default:
view = new RecordView(formController);
if (dataRenderers[FormController.FORM_EDITOR] != null) {
((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
((RecordView) view).setCellRenderer((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
}
int form_id = fp.getForm().getNavigatorID();
if (form_id == 0) {
StyledEnablePanel slider = ((RecordView) view).getSliderComponent();
if (bgColor != null)
slider.setBackground(bgColor);
setWest(slider);
}
}
getVerticalScrollBar().setValue(1);
getVerticalScrollBar().setValue(0);
setViewportView((JComponent) view);
if (view instanceof TableView) {
// the table view needs it's orientation set correctly
OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
}
if (view instanceof ListView) {
view.requestFocus();
}
OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
if ((bgColor != null) && (view instanceof ListView))
((ListView) view).setBackground(bgColor);
// except if it's a table view, that is always transparent
if (!(view instanceof TableView)) {
setOpaque(isOpaque());
} else {
for (int i = FormController.FORM_RENDERER + 1; i < dataRenderers.length; i++) {
if (dataRenderers[i] != null && !(dataRenderers[i] instanceof TableView)) {
dataRenderers[i].setOpaque(isOpaque());
}
}
}
return view;
}
use of com.servoy.j2db.smart.dataui.DataRenderer in project servoy-client by Servoy.
the class SwingForm method makeElementsScriptObject.
/**
* @see com.servoy.j2db.IFormUIInternal#makeElementsScriptObject(org.mozilla.javascript.Scriptable)
*/
public ElementScope makeElementsScriptObject(Scriptable fs, Map<String, Object[]> hmChildrenJavaMembers, IDataRenderer[] dataRenderers, IView controller) {
ElementScope es = new ElementScope(fs);
int counter = 0;
for (int i = FormController.FORM_RENDERER + 1; i < dataRenderers.length; i++) {
IDataRenderer dr = dataRenderers[i];
if (dr == null)
continue;
Object[] comps = null;
Object[] compsRenderer = null;
if (dr instanceof DataRenderer) {
comps = ((DataRenderer) dr).getComponents();
if (i == FormController.FORM_EDITOR && dataRenderers[FormController.FORM_RENDERER] != null) {
compsRenderer = ((DataRenderer) dataRenderers[FormController.FORM_RENDERER]).getComponents();
}
} else if (dr instanceof TableView) {
TableView tv = (TableView) dr;
List<CellAdapter> nonViewableColumns = tv.getNonViewableColumns();
int componentCount = tv.getColumnCount() + nonViewableColumns.size();
comps = new Component[componentCount];
compsRenderer = new Component[componentCount];
CellAdapter[] tableCellAdapters = new CellAdapter[componentCount];
for (int j = 0; j < componentCount; j++) {
tableCellAdapters[j] = (j < tv.getColumnCount()) ? (CellAdapter) tv.getCellEditor(0, j) : nonViewableColumns.get(j - tv.getColumnCount());
comps[j] = tableCellAdapters[j].getEditor();
compsRenderer[j] = tableCellAdapters[j].getRenderer();
}
for (int j = 0; j < comps.length; j++) {
if (compsRenderer[j] instanceof Component && !((Component) compsRenderer[j]).isVisible()) {
tv.getColumnModel().removeColumn(tableCellAdapters[j]);
}
}
} else if (dr instanceof WebMarkupContainer) {
comps = new Object[((WebMarkupContainer) dr).size()];
Iterator<?> it = ((WebMarkupContainer) dr).iterator();
int j = 0;
while (it.hasNext()) {
comps[j++] = it.next();
}
}
counter = registerComponentsToScope(fs, es, counter, comps, compsRenderer, (Component) controller, hmChildrenJavaMembers);
}
es.setLocked(true);
return es;
}
use of com.servoy.j2db.smart.dataui.DataRenderer in project servoy-client by Servoy.
the class FormPreviewPanel method createPartPanels.
private Map<Part, DataRenderer> createPartPanels() throws RepositoryException {
try {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
part_panels = new LinkedHashMap<Part, DataRenderer>();
Iterator<Part> it = controllerBeingPreviewed.getForm().getParts();
while (it.hasNext()) {
Part part = it.next();
// printing is always swing
DataRenderer partpane = (DataRenderer) application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(controllerBeingPreviewed.getForm(), part), part.toString(), application, false);
part_panels.put(part, partpane);
}
return part_panels;
} finally {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", null);
}
}
use of com.servoy.j2db.smart.dataui.DataRenderer in project servoy-client by Servoy.
the class ListView method getReadOnlyAwareComponents.
private List<HasRuntimeReadOnly> getReadOnlyAwareComponents() {
List<HasRuntimeReadOnly> readOnlyAwareComponents = new ArrayList<HasRuntimeReadOnly>();
ListCellRenderer cellRenderer = getCellRenderer();
if (cellRenderer instanceof DataRenderer) {
DataRenderer dr = (DataRenderer) cellRenderer;
for (int i = 0; i < dr.getComponentCount(); i++) {
Component c = dr.getComponent(i);
if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof HasRuntimeReadOnly) {
readOnlyAwareComponents.add((HasRuntimeReadOnly) ((IScriptableProvider) c).getScriptObject());
}
}
}
IEditListEditor editorComponent = getCellEditor();
if (editorComponent instanceof FormBodyEditor) {
FormBodyEditor formBodyEditor = (FormBodyEditor) editorComponent;
DataRenderer dataRenderer = formBodyEditor.getDataRenderer();
for (int i = 0; i < dataRenderer.getComponentCount(); i++) {
Component c = dataRenderer.getComponent(i);
if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof HasRuntimeReadOnly) {
readOnlyAwareComponents.add((HasRuntimeReadOnly) ((IScriptableProvider) c).getScriptObject());
}
}
}
return readOnlyAwareComponents;
}
Aggregations