use of com.servoy.j2db.dataprocessing.IDisplayData 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.dataprocessing.IDisplayData in project servoy-client by Servoy.
the class GlobalAutoScrollerFocusListener method propertyChange.
public void propertyChange(PropertyChangeEvent e) {
if (// $NON-NLS-1$
"focusOwner".equals(e.getPropertyName())) {
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (owner != null) {
// System.out.println("focus moved to ->" + owner.getClass().getCanonicalName() + "/" + owner + "<-");
// if (owner instanceof Component) System.out.println("\towner name is: " + (owner).getName());
// Container focusRoot = KeyboardFocusManager.getCurrentKeyboardFocusManager().getCurrentFocusCycleRoot();
// System.out.println("focus cycle root is now ->" + focusRoot.getClass().getCanonicalName() + "/" + focusRoot + "<-");
owner = getEventualParentScrollPane(owner);
/* Auto scroll only when our specific fields receive focus. */
if (owner instanceof IDisplayData || owner instanceof ScriptButton) {
/* Find a scrollable parent, if any. */
JComponent scrollableParent = findScrollableParent(owner);
while (scrollableParent != null) {
/* Compute the coordinates of the owner relative to the scrollable parent. */
Rectangle r = owner.getBounds();
Component c = owner.getParent();
while (c != scrollableParent && c != null) {
Rectangle s = c.getBounds();
r.setLocation(r.x + s.x, r.y + s.y);
c = c.getParent();
}
scrollableParent.scrollRectToVisible(r);
// If we are inside a tab panel, then we go up one level and scroll everything again,
// because the tab panel itself can be out of the screen now.
scrollableParent = findTabPanelParent(scrollableParent);
if (scrollableParent != null)
scrollableParent = findScrollableParent(scrollableParent.getParent());
}
}
}
}
}
use of com.servoy.j2db.dataprocessing.IDisplayData in project servoy-client by Servoy.
the class CellAdapter method valueChanged.
/*
* @see JSModificationListener#valueChanged(ModificationEvent)
*/
public void valueChanged(ModificationEvent e) {
if (adjusting)
return;
try {
adjusting = true;
// ignore globals in a cell adapter, will be handled by the row manager
if (!table.isEditing() && ScopesUtils.isVariableScope(e.getName())) {
// test if it is a related
if (dataProviderID != null && dataProviderID.indexOf('.') != -1) {
TableModel parent = table.getModel();
if (parent instanceof ISwingFoundSet) {
// it could be based on that global so fire a table event.
((ISwingFoundSet) parent).fireTableModelEvent(0, parent.getRowCount() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE);
}
}
return;
}
// refresh value
IRecord s = e.getRecord();
if (s == null) {
TableModel tm = table.getModel();
if (tm instanceof IFoundSetInternal) {
IFoundSetInternal fs = (IFoundSetInternal) tm;
int selRow = fs.getSelectedIndex();
if (selRow != -1) {
s = fs.getRecord(selRow);
}
}
}
if (s != null) {
Object obj = e.getValue();
if (e.getName().equals(dataProviderID)) {
// make sure the change is seen and pushed to display by jtable
fireModificationEvent(s);
} else {
obj = dal.getValueObject(s, dataProviderID);
if (obj == Scriptable.NOT_FOUND) {
obj = null;
}
}
if (s == currentEditingState && table.getEditorComponent() == editor && editor instanceof IDisplayData) {
convertAndSetValue(((IDisplayData) editor), obj);
}
}
} finally {
adjusting = false;
}
}
use of com.servoy.j2db.dataprocessing.IDisplayData in project servoy-client by Servoy.
the class CellAdapter method getBgColor.
private Color getBgColor(JTable jtable, boolean isSelected, int row, boolean isEdited) {
Color bgColor = null;
IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState || state == null || state.getRawData() == null);
if (/* !(renderer instanceof JButton) && */
!specialStateCase) {
ISwingFoundSet foundset = (ISwingFoundSet) jtable.getModel();
bgColor = (Color) getStyleAttributeForRow(jtable, isSelected, row, ISupportRowStyling.ATTRIBUTE.BGCOLOR);
String strRowBGColorProvider = null;
List<Object> rowBGColorArgs = null;
if (jtable instanceof IView) {
strRowBGColorProvider = ((IView) jtable).getRowBGColorScript();
rowBGColorArgs = ((IView) jtable).getRowBGColorArgs();
}
// $NON-NLS-1$
if (strRowBGColorProvider == null)
strRowBGColorProvider = "servoy_row_bgcolor";
boolean isRowBGColorCalculation = state.getRawData().containsCalculation(strRowBGColorProvider);
if (// $NON-NLS-1$
!isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
// $NON-NLS-1$
strRowBGColorProvider = "";
}
if (// $NON-NLS-1$
strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
Object bg_color = null;
// TODO this should be done better....
Record.VALIDATE_CALCS.set(Boolean.FALSE);
try {
String type = (editor instanceof IScriptableProvider && ((IScriptableProvider) editor).getScriptObject() instanceof IRuntimeComponent) ? ((IRuntimeComponent) ((IScriptableProvider) editor).getScriptObject()).getElementType() : null;
String nm = (editor instanceof IDisplayData) ? ((IDisplayData) editor).getDataProviderID() : null;
if (isRowBGColorCalculation) {
bg_color = foundset.getCalculationValue(state, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), null);
} else {
try {
FormController currentForm = dal.getFormController();
bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, currentForm.getName(), state, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
} catch (Exception ex) {
Debug.error(ex);
}
}
} finally {
Record.VALIDATE_CALCS.set(null);
}
if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
bgColor = PersistHelper.createColor(bg_color.toString());
}
}
}
return bgColor;
}
use of com.servoy.j2db.dataprocessing.IDisplayData in project servoy-client by Servoy.
the class CellAdapter method testCalc.
private boolean testCalc(final String possibleCalcDataprovider, final IRecordInternal state, final int row, final int column, final ISwingFoundSet foundset) {
if (state != null && state.getRawData() != null && !(state instanceof PrototypeState || state instanceof FindState) && state.getRawData().containsCalculation(possibleCalcDataprovider) && state.getRawData().mustRecalculate(possibleCalcDataprovider, true)) {
IApplication app = dal.getApplication();
convertAndSetValue(((IDisplayData) renderer), state.getRawData().getValue(possibleCalcDataprovider));
// $NON-NLS-1$
final String key = row + "_" + possibleCalcDataprovider;
if (!rowAndDataprovider.contains(key)) {
rowAndDataprovider.add(key);
app.getScheduledExecutor().execute(new Runnable() {
public void run() {
state.getValue(possibleCalcDataprovider);
application.invokeLater(new Runnable() {
public void run() {
rowAndDataprovider.remove(key);
foundset.fireTableModelEvent(row, row, column, TableModelEvent.UPDATE);
Container parent = table.getParent();
while (parent != null && !(parent instanceof ListView)) {
parent = parent.getParent();
}
if (parent instanceof ListView) {
((ListView) parent).repaint();
}
}
});
}
});
}
return true;
}
return false;
}
Aggregations