BrightSide Workbench Full Report + Source Code
NextEventListener.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.zkoss.grid;
19 
20 import org.turro.elephant.util.Components;
21 import org.zkoss.zk.ui.Component;
22 import org.zkoss.zk.ui.event.Event;
23 import org.zkoss.zul.Detail;
24 import org.zkoss.zul.Row;
25 
31 
33  super(grid);
34  }
35 
36  @Override
37  public void onEvent(Event event) throws Exception {
38  Component comp = event.getTarget();
39  Row row = Components.from(comp).parent(Row.class);
40  while(row != null) {
41  comp = comp.getNextSibling();
42  if(comp == null) {
43  row = (Row) row.getNextSibling();
44  if(row != null) {
45  comp = (Component) row.getChildren().get(0);
46  }
47  }
48  if(comp == null) {
49  if(grid.isAllowInsertions()) {
50  row = grid.addNewRow();
51  } else {
52  row = (Row) grid.getRows().getFirstChild();
53  }
54  if(row != null) {
55  comp = (Component) row.getChildren().get(0);
56  }
57  }
58  if(row != null && comp != null && !(comp instanceof Detail) ) {
59  EditableCell ec = new EditableCell(grid, row, comp);
60  if(!(ec.getColumn() instanceof EditableColumn && ((EditableColumn) ec.getColumn()).isReadOnly())) {
61  grid.processEdition(ec);
62  break;
63  }
64  }
65  }
66  }
67 
68 }
static Components from(Object component)
Definition: Components.java:46
void processEdition(EditableCell editableCell)
Rows getRows(boolean create)