use of com.servoy.j2db.FormManager 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.FormManager in project servoy-client by Servoy.
the class DataProviderEditor method fillDataProviderList.
protected void fillDataProviderList() {
try {
ITable table = null;
if (definedTable == null) {
FormManager fm = (FormManager) application.getFormManager();
FormController fc = fm.getCurrentMainShowingFormController();
if (fc != null) {
Form form = fc.getForm();
table = application.getFlattenedSolution().getTable(form.getDataSource());
}
} else {
if (!showRelatedOptionsOnly)
table = definedTable;
}
DefaultListModel model = (DefaultListModel) list.getModel();
model.removeAllElements();
if (showNoneOption)
model.addElement("-none-");
if (!showColumnsOnly)
model.addElement("*columns");
Object o = relationsComboBox.getSelectedItem();
if (o != null) {
if (o instanceof String) {
// table = form.getTable();
} else {
table = application.getFlattenedSolution().getTable(((Relation) o).getForeignDataSource());
}
if (table != null) {
Iterator<Column> it = table.getColumnsSortedByName();
while (it.hasNext()) {
IColumn c = it.next();
ColumnInfo ci = c.getColumnInfo();
if (ci != null && ci.isExcluded()) {
continue;
}
if (hideMediaColumns) {
// use dataprovider type as defined by column converter
ComponentFormat componentFormat = ComponentFormat.getComponentFormat(null, c, application);
if (componentFormat.dpType == IColumnTypes.MEDIA) {
continue;
}
}
model.addElement(c);
}
}
}
FlattenedSolution s = application.getFlattenedSolution();
if (table != null && !showColumnsOnly) {
Iterator it = s.getScriptCalculations(table, true);
if (it.hasNext()) {
model.addElement("*calculations");
}
while (it.hasNext()) {
ScriptCalculation sc = (ScriptCalculation) it.next();
for (int i = 0; i < model.size(); i++) {
Object obj = model.elementAt(i);
if (obj instanceof IDataProvider) {
IDataProvider dp = (IDataProvider) obj;
if (dp.getDataProviderID().equals(sc.getDataProviderID())) {
// remove the column from the list if use by
model.remove(i);
// stored calc
break;
}
}
}
model.addElement(sc);
}
Iterator it2 = s.getScriptVariables(true);
if (it2.hasNext()) {
model.addElement("*globals");
}
while (it2.hasNext()) {
model.addElement(it2.next());
}
Iterator it3 = s.getAggregateVariables(table, true);
if (it3.hasNext()) {
model.addElement("*aggregates");
}
while (it3.hasNext()) {
model.addElement(it3.next());
}
}
if (table != null && showColumnsOnly && showSortableOnly) {
Iterator it3 = s.getAggregateVariables(table, true);
while (it3.hasNext()) {
model.addElement(it3.next());
}
}
if (showGlobalsOption && showColumnsOnly) {
Iterator it2 = s.getScriptVariables(true);
if (it2.hasNext()) {
model.addElement("*globals");
}
while (it2.hasNext()) {
model.addElement(it2.next());
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
use of com.servoy.j2db.FormManager in project servoy-client by Servoy.
the class DataProviderEditor method fillRelationsComboBox.
protected void fillRelationsComboBox(Relation[] relations) throws Exception {
boolean relationsAdded = false;
String item = null;
ITable table = null;
if (definedTable == null) {
FormManager fm = (FormManager) application.getFormManager();
FormController fc = fm.getCurrentMainShowingFormController();
if (fc != null) {
Form form = fc.getForm();
table = application.getFlattenedSolution().getTable(form.getDataSource());
}
} else {
table = definedTable;
// definedTable = null;//clear!
}
if (relationsComboBox.getItemCount() > 0)
relationsComboBox.removeAllItems();
Iterator it = application.getFlattenedSolution().getRelations(table, true, true);
while (it.hasNext()) {
Relation rel = (Relation) it.next();
if (!showSortableOnly || (showSortableOnly && rel.isUsableInSort())) {
relationsComboBox.addItem(rel);
relationsAdded = true;
}
}
if (!showRelatedOptionsOnly) {
// $NON-NLS-1$
String tname = "";
if (table != null)
tname = table.getName();
item = "DataProviders for " + tname;
if (relationsComboBox.getModel().getSize() > 0) {
relationsComboBox.insertItemAt(item, 0);
} else {
relationsComboBox.addItem(item);
}
}
if (relations == null) {
if (item == null) {
if (relationsComboBox.getModel().getSize() != 0)
relationsComboBox.setSelectedIndex(0);
} else {
relationsComboBox.setSelectedItem(item);
}
} else {
relationsComboBox.setSelectedItem(relations[0]);
}
relationsComboBox.setEnabled(relationsAdded && !showRelatedOptionsOnly);
}
use of com.servoy.j2db.FormManager 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.FormManager in project servoy-client by Servoy.
the class FormLookupPanel method createFormPanel.
private FormController createFormPanel() {
FormManager fm = (FormManager) application.getFormManager();
FormController fp = fm.getFormController(formName, this);
if (fp != null) {
IFormUIInternal ui = fp.getFormUI();
if (ui instanceof Component) {
add((Component) ui, BorderLayout.CENTER);
// just to be sure the cardlayout of main panel does return them as not visible
ui.setComponentVisible(true);
// delegate readOnly, really set it once from the form manager state
fp.setReadOnly(fm.isFormReadOnly(formName));
Container con = getParent();
if (con != null && (con instanceof ITabPaneAlike) && !con.isEnabled()) {
// reaply the isEnabled state of the tabpanel to its child tabs (tabs are added after enabled state is set); only if the tabpanel is disabled
this.setEnabled(con.isEnabled());
}
while (con != null) {
if (con instanceof IFormUIInternal) {
fp.getUndoManager().setFormUndoManager(((IFormUIInternal) con).getUndoManager());
break;
}
con = con.getParent();
}
// invalidate later so that everything is first visible (like the datamodel of a tableview)
application.invokeLater(new Runnable() {
public void run() {
validate();
}
});
}
}
return fp;
}
Aggregations