BrightSide Workbench Full Report + Source Code
KeyEventListener.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.zk.ui.event.KeyEvent;
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  KeyEvent kev = (KeyEvent) event;
41  if(row != null) {
42  if(kev.isCtrlKey()) {
43  if(grid.isAllowDeletions() && kev.getKeyCode() == KeyEvent.DELETE) {
45  } else if(grid.isAllowInsertions() && kev.getKeyCode() == KeyEvent.INSERT) {
47  }
48  } else {
49  int cellIndex = row.getChildren().indexOf(comp);
50  if(kev.getKeyCode() == KeyEvent.DOWN) {
51  row = (Row) row.getNextSibling();
52  } else if(kev.getKeyCode() == KeyEvent.UP) {
53  row = (Row) row.getPreviousSibling();
54  }
55  if(row != null) {
56  comp = (Component) row.getChildren().get(cellIndex);
57  }
58  if(comp == null) {
59  if(grid.isAllowInsertions()) {
60  row = grid.addNewRow();
61  } else {
62  row = (Row) grid.getRows().getFirstChild();
63  }
64  if(row != null) {
65  comp = (Component) row.getChildren().get(cellIndex);
66  }
67  }
68  if(row != null && comp != null) {
69  grid.processEdition(new EditableCell(grid, row, comp));
70  }
71  }
72  }
73  }
74 
75 }
static Components from(Object component)
Definition: Components.java:46
void processEdition(EditableCell editableCell)
void deleteSelectedRow(final Row row)
Rows getRows(boolean create)