Home pageFind It!Contact JeksJeks documentation

Jeks

 Jeks forum

This forum is dedicated to Jeks.
You may read freely the messages it contents. If you want to write a message or answer to a subject, subscribe to it first.

Subjects Recent messages Login Subscribe

Messages of subject Recalculating cells values

hhuynh

Location : USA
Member since : Feb 10, 2004
Messages : 4
 Apr 23, 2004 at 1:00 AM
Hi,

I added functionality that allows users to modify their functions. The problem is that cells don't automatically update their values according to the new function.

Would it be possible to pull it off? (model.fireDataChanged() throws ArrayIndexOutOfBound exception, model.fireRowUpdate(int, int) doesn't help)

Thank you,

Hung Huynh-

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Apr 23, 2004 at 6:47 AM
> model.fireDataChanged() throws ArrayIndexOutOfBound exception

Would you have any stack trace ?

> I added functionality that allows users to modify their functions. The problem is that cells don't automatically update their values according to the new function.

Do you mean you let the user edit a function definition and then you compile it with the compileFunction method with a call that looks like the following lines ?
  CompiledFunction oldFunction = ...
  table.getExpressionParser ().removeUserFunction (oldFunction);
  CompiledFunction newFunction = table.getExpressionParser ().getFunctionParser ().compileFunction (functionDef);
  table.getExpressionParser ().addUserFunction (newFunction);

If you did something like that you must compile again all the cells formulas that used the old CompiledFunction instance because the compiled version of each formula directly references the CompiledFunction instances they use. You can compile a cell formula with the compileExpression method of com.eteks.jeks.JeksExpressionParser :
  Object obj = tableModel.getValueAt(row, column);
  if (obj instanceof JeksExpression)
  {
    String cellFormula = ((JeksExpression)obj).getDefinition ();
    tableModel.setValueAt (table.getExpressionParser ().compileExpression(cellFormula, row, column));
  }

If you need to check cell circularity during the new formula compilations have a look at the getModelValue method of com.eteks.jeks.JeksCellEditor.
---
Manu (moderator/modérateur)

hhuynh

Location : USA
Member since : Feb 10, 2004
Messages : 4
 Apr 23, 2004 at 6:44 PM
Yes, that's exactly what I try to do. Thanks for the prompt response Manu.
Below is the exception thrown when I used model.fireTableDataChanged();

Regarding the cell format option, my boss just requires that functionality and I read in the forum that you're gonna support it in the next version. I'd rather hold out and wait for you. Do you have a specific date when you will release it?

Thank you,

Hung Huynh-


java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 500
at com.eteks.jeks.JeksTableModel.getValueAt(JeksTableModel.java:98)
at com.eteks.jeks.ReferringCellsListener.updateCellParameters(ReferringCellsListener.java:367)
at com.eteks.jeks.ReferringCellsListener.tableUpdated(ReferringCellsListener.java:277)
at com.eteks.jeks.ReferringCellsListener.access$000(ReferringCellsListener.java:45)
at com.eteks.jeks.ReferringCellsListener$1.run(ReferringCellsListener.java:256)
at com.eteks.jeks.ReferringCellsListener.tableChanged(ReferringCellsListener.java:244)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
at javax.swing.table.AbstractTableModel.fireTableDataChanged(AbstractTableModel.java:182)
at cseo.gui.spreadsheet.SpreadSheetFrame$2.mouseClicked(SpreadSheetFrame.java:371)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5103)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3207)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Apr 24, 2004 at 5:34 AM
> Below is the exception thrown when I used model.fireTableDataChanged();

Thank you for the exception trace. It helped me discover that in your case, TableModelEvent constructor uses Integer.MAX_VALUE as a default value for the last row of an event.
The call to the tableUpdated method in the implementation of tableChanged in com.eteks.jeks.ReferringCellsListener class should be changed this way :
  tableUpdated (updatedModel, event.getFirstRow (),
    event.getLastRow () < updatedModel.getRowCount()
      ? event.getLastRow ()
      : updatedModel.getRowCount() - 1,
    event.getColumn ());

This bug will be corrected in next Jeks release.

> Regarding the cell format option, [...] Do you have a specific date when you will release it?

The next release of Jeks which will provide the cell format option, should be available at the beginning of July 2004.
---
Manu (moderator/modérateur)


Home pageFind It!ContactTop

© Copyrights 1997-2023 eTeks - All rights reserved

JeksJeks documentation