PDA

View Full Version : [CLOSED] Window + Table + TriggerField = Crash Safari



thatone
7 Apr 2009, 2:18 PM
Hi, I have a very weird bug. Here's the state/situation:

I'm creating a custom TriggerField where if the TriggerButton is clicked, it'll show a Window that contains a table.

When the following snippets are run, I got this message:

Invalid memory access of location 00000004 eip=92e0b394

On Safari _and_ Hosted Mode (Mac).

To use this TriggerField, you can add to the FormsExample.java of GXT examples:



SomeTriggerField customTrigger = new SomeTriggerField();
customTrigger.setFieldLabel("Custom Trigger");
simple.add(customTrigger);


Here's the custom TriggerField code:



import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import com.extjs.gxt.samples.resources.client.TestData;
import com.extjs.gxt.samples.resources.client.model.Stock;
import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.TableEvent;
import com.extjs.gxt.ui.client.util.BaseEventPreview;
import com.extjs.gxt.ui.client.util.Rectangle;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TriggerField;
import com.extjs.gxt.ui.client.widget.table.Table;
import com.extjs.gxt.ui.client.widget.table.TableColumn;
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
import com.extjs.gxt.ui.client.widget.table.TableItem;

public class SomeTriggerField extends TriggerField {

private Window window = new Window();
private Button button = new Button("Press Me to Close");
private BaseEventPreview focusPreview = new BaseEventPreview();

public SomeTriggerField() {
window.setResizable(false);
window.setDraggable(false);
window.setAutoHide(true);
window.setHeaderVisible(false);
window.add(createTable());
button.addSelectionListener(new SelectionListener<ComponentEvent>() {

@Override
public void componentSelected(final ComponentEvent ce) {
window.hide();
el().blur();
}
});
}

@Override
protected void onFocus(final ComponentEvent ce) {
super.onFocus(ce);
focusPreview.add();
}

@Override
protected void onTriggerClick(final ComponentEvent ce) {
super.onTriggerClick(ce);
if (disabled || isReadOnly()) {
return;
}

expand();

getInputEl().focus();
}

public void expand() {
window.show();
window.alignTo(wrap.dom, "tl-bl?", new int[] {
0, 0
});
window.focus();
}

@Override
protected void onBlur(final ComponentEvent ce) {

Rectangle rec = trigger.getBounds();
if (rec.contains(BaseEventPreview.getLastClientX(), BaseEventPreview.getLastClientY())) {
ce.stopEvent();
return;
}
if (window != null && window.isVisible()) {
return;
}
hasFocus = false;
doBlur(ce);
}

private void doBlur(final ComponentEvent ce) {
if (window != null && window.isVisible()) {
window.hide();
}
super.onBlur(ce);
focusPreview.remove();
}

private Table createTable() {

List<TableColumn> columns = new LinkedList<TableColumn>();
columns.add(new TableColumn("name", 0.20f));
columns.add(new TableColumn("symbol", 0.20f));
columns.add(new TableColumn("last", 0.20f));
columns.add(new TableColumn("date", 0.20f));
columns.add(new TableColumn("change", 0.20f));
TableColumnModel model = new TableColumnModel(columns);
Table table = new Table(model);
List<Stock> stocks = TestData.getShortStocks();
for (Stock stock : stocks) {
Collection<Object> values = stock.getProperties().values();
if (values != null && values.size() > 0) {
TableItem item = new TableItem(values.toArray());
table.add(item);
}
}
table.addListener(Events.RowClick, new Listener<TableEvent>() {

public void handleEvent(final TableEvent be) {
window.hide();
}

});
return table;
}
}

sven
7 Apr 2009, 2:37 PM
This is the wrong forum.

If you listen to the SelectionChange event or hide the window deferred in the rowclick event it works quite well.

thatone
7 Apr 2009, 3:00 PM
This is the wrong forum.

If you listen to the SelectionChange event or hide the window deferred in the rowclick event it works quite well.

Care to explain how to "hide the window deferred in the RowClick" ?

Also would you mind explaining why I got the "Invalid memory access" (which crashed Safari?)

I tried the following code to no luck:


table.addListener(Events.RowClick, new Listener<TableEvent>() {

public void handleEvent(final TableEvent be) {
DeferredCommand.addCommand(new Command() {

public void execute() {
window.hide();
}

});
}

});

thatone
7 Apr 2009, 4:26 PM
I've also tested using CellClick with the same crashing result.

Would you explain what's going on between Window and Table?

sven
8 Apr 2009, 12:56 AM
I dont know what is going on but it likly some bug in the webkit engine. Use the selection change event as i suggested.

thatone
8 Apr 2009, 8:21 AM
I dont know what is going on but it likly some bug in the webkit engine. Use the selection change event as i suggested.

Unfortunately I need to find out exactly which cell it is being clicked on. Is there a workaround that you know of? SelectionChange doesn't give much information.

... and yes, it seems like it is a bug in the webkit engine.