BrightSide Workbench Full Report + Source Code
EditableCell.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.zkoss.zk.ui.Component;
21 import org.zkoss.zk.ui.HtmlBasedComponent;
22 import org.zkoss.zk.ui.ext.AfterCompose;
23 import org.zkoss.zul.Column;
24 import org.zkoss.zul.Row;
25 import org.zkoss.zul.impl.InputElement;
26 
31 public class EditableCell {
32 
33  protected EditableGrid grid;
34  protected Row row;
35  protected Component renderer;
36  protected HtmlBasedComponent editor;
37  protected Column column;
38  private int cellIndex;
39 
40  public EditableCell(EditableGrid grid, Row row, int cellIndex) {
41  this.grid = grid;
42  this.row = row;
43  this.renderer = row.getChildren().size() > cellIndex ?
44  (Component) row.getChildren().get(cellIndex) : null;
45  this.cellIndex = cellIndex;
46  this.column = grid.getEditableColumn(cellIndex);
47  }
48 
49  public EditableCell(EditableGrid grid, Row row, Component renderer) {
50  this.grid = grid;
51  this.row = row;
52  this.renderer = renderer;
53  this.cellIndex = row.getChildren().indexOf(renderer);
54  this.column = grid.getEditableColumn(cellIndex);
55  }
56 
57  public int getCellIndex() {
58  return cellIndex;
59  }
60 
61  public Column getColumn() {
62  return column;
63  }
64 
65  public Component getRenderer() {
66  return renderer;
67  }
68 
69  public Component getEditor() {
70  return editor;
71  }
72 
73  public EditableGrid getGrid() {
74  return grid;
75  }
76 
77  public Row getRow() {
78  return row;
79  }
80 
81  public String getFormat() {
82  return column instanceof EditableColumn ?
83  ((EditableColumn) column).getFormat() : null;
84  }
85 
86  public Class getJavaClass() {
87  return column instanceof EditableColumn ?
88  ((EditableColumn) column).getJavaClass() : null;
89  }
90 
91  public boolean isOnlyDate() {
92  return column instanceof EditableColumn ?
93  ((EditableColumn) column).isOnlyDate() : true;
94  }
95 
96  public boolean isOnlyTime() {
97  return column instanceof EditableColumn ?
98  ((EditableColumn) column).isOnlyTime() : true;
99  }
100 
101  public int getScale() {
102  return column instanceof EditableColumn ?
103  ((EditableColumn) column).getScale() : 2;
104  }
105 
106  public String getProperty() {
107  return column instanceof EditableColumn ?
108  ((EditableColumn) column).getProperty() : null;
109  }
110 
111  public boolean isReadOnly() {
112  return column instanceof EditableColumn ?
113  ((EditableColumn) column).isReadOnly() : false;
114  }
115 
116  public void edit() {
117  editor = grid.getEditor(this);
118  row.getChildren().remove(renderer);
119  row.getChildren().add(cellIndex, editor);
120  if(editor instanceof AfterCompose) {
121  ((AfterCompose) editor).afterCompose();
122  }
123  editor.setHflex("true");
124  editor.setFocus(true);
125  if(grid.isSelectInput() && editor instanceof InputElement) {
126  ((InputElement) editor).select();
127  }
128  }
129 
130  public void resume() {
131  if(editor != null) {
132  row.getChildren().remove(editor);
133  }
134  row.getChildren().add(cellIndex, renderer);
135  }
136 
137  public boolean isBoolean() {
138  return column instanceof EditableColumn ?
139  ((EditableColumn) column).isBoolean() : false;
140  }
141 
142  public boolean isNumber() {
143  return column instanceof EditableColumn ?
144  ((EditableColumn) column).isNumber() : false;
145  }
146 
147  public boolean isDate() {
148  return column instanceof EditableColumn ?
149  ((EditableColumn) column).isDate() : false;
150  }
151 }
EditableCell(EditableGrid grid, Row row, int cellIndex)
EditableCell(EditableGrid grid, Row row, Component renderer)
HtmlBasedComponent getEditor(EditableCell editableCell)
Column getEditableColumn(int cellIndex)