pl.netanel.swt.matrix
Class ZoneEditor<X extends java.lang.Number,Y extends java.lang.Number>

java.lang.Object
  extended by pl.netanel.swt.matrix.ZoneEditor<X,Y>
Type Parameters:
X - indexing type for the horizontal axis
Y - indexing type for vertical axis

public class ZoneEditor<X extends java.lang.Number,Y extends java.lang.Number>
extends java.lang.Object

Provides editing support for zone cells.


Constructor Summary
ZoneEditor(Zone<X,Y> zone)
          Default constructor, facilitates editing of the specified zone.
 
Method Summary
 Control activate(X indexX, Y indexY)
          Shows a control to edit the value of the specified cell.
 void apply(Control control)
          Applies the editor value to the model by invoking setModelValue(Number, Number, Object) and if successful then calls cancel(Control), otherwise leaves the editor control active.
 void cancel(Control control)
          Deactivates the editor control.
 void copy()
          Copies selected cells to the clipboard.
protected  Control createControl(X indexX, Y indexY)
          Creates a control to edit the value of the specified cell.
protected  Control createControl(X indexX, Y indexY, char ch)
           
 void cut()
          Cuts the selected cells by copying them to the clipboard and setting null value to them.
 boolean delete()
          Sets the null value to the selected cells.
protected  java.lang.String format(X indexX, Y indexY)
          Returns the label for the specified cell to be included in the clipboard copying.
protected  java.lang.Object[] getCheckboxEmulation(X indexX, Y indexY)
          Returns the check box emulation data.
 Control getControl(X indexX, Y indexY)
          Returns editor control associated with the given cell or null if cell does not have editor control created, which may happen when it is not visible or the editor has not been activated.
protected  java.lang.Object[] getDefaultCheckboxLabels()
          Returns the default labels to emulate check boxes.
protected  java.lang.Object getEditorValue(Control control)
          Returns a value from the specified edit control.
 Control getEmbeddedControl(X indexX, Y indexY)
          Returns a control embedded in the cell with the given coordinates or null if the cell does not have an embedded control or the control is not visible.
 java.lang.Object getModelValue(X indexX, Y indexY)
          Returns value from the model referring to the given cell coordinates.
 Zone<X,Y> getZone()
          Returns zone of the editor.
protected  boolean hasEmbeddedControl(X indexX, Y indexY)
          Returns true if the cell editor control for the specified cell is embedded in the cell, or false if it is a pop-up.
 void layoutControls()
           
protected  java.lang.Object parse(X indexX, Y indexY, java.lang.String s)
          Parses a text for the specified cell during paste operation.
 boolean paste()
          Pastes from the clipboard to the zone starting from the focus cell.
 void redraw()
          Makes the embedded controls to be recreated.
protected  void removeControl(Control control)
          Disposes the edit control.
protected  void setBounds(X indexX, Y indexY, Control control)
          Sets the bounds of the specified edit control in the specified cell.
protected  void setEditorValue(Control control, java.lang.Object value)
          Sets the value in the cell editor control.
 boolean setModelValue(X indexX, Y indexY, java.lang.Object value)
          Sets the specified value to the model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZoneEditor

public ZoneEditor(Zone<X,Y> zone)
Default constructor, facilitates editing of the specified zone.

If an editor was created before it will be replace with this new one.

Parameters:
zone -
Method Detail

getModelValue

public java.lang.Object getModelValue(X indexX,
                                      Y indexY)
Returns value from the model referring to the given cell coordinates.

This method is usually overridden, since the default implementation returns the Painter.text after calling Painter.setupSpatial(Number, Number) method of the zone's Painter.NAME_CELLS painter, which is always String, while some edit controls require other types, like Boolean or Date. If the Painter.NAME_CELLS painter does not exist in the zone it always returns null.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
value from the model referring to the given cell coordinates

setModelValue

public boolean setModelValue(X indexX,
                             Y indexY,
                             java.lang.Object value)
Sets the specified value to the model. It is used to apply the result of cell editing.

Performs the input validation and returns false if the value is not valid, and true otherwise

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
value - to set in the model
Returns:
false if the value is not valid, and true otherwise

getEditorValue

protected java.lang.Object getEditorValue(Control control)
Returns a value from the specified edit control.

It returns:

Preconditions:

Returns:
a value from the specified control
See Also:
setEditorValue(Control, Object)

setEditorValue

protected void setEditorValue(Control control,
                              java.lang.Object value)
Sets the value in the cell editor control.

The value must of the following type:

Preconditions:

Parameters:
control - to set the value for
value - to set in the control
See Also:
getEditorValue(Control)

getControl

public Control getControl(X indexX,
                          Y indexY)
Returns editor control associated with the given cell or null if cell does not have editor control created, which may happen when it is not visible or the editor has not been activated.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
editor control associated with the given cell

apply

public void apply(Control control)
Applies the editor value to the model by invoking setModelValue(Number, Number, Object) and if successful then calls cancel(Control), otherwise leaves the editor control active.

Parameters:
control - editor control to apply the data from.

cancel

public void cancel(Control control)
Deactivates the editor control. If the control is not embedded then it calls removeControl(Control). Regardless of that is sets the focus back to the Matrix.

Parameters:
control -

activate

public Control activate(X indexX,
                        Y indexY)
Shows a control to edit the value of the specified cell. Before that it scrolls the viewport to make the cell visible. If the cell is hidden then it does nothing.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
the editor control for the given cell

createControl

protected Control createControl(X indexX,
                                Y indexY)
Creates a control to edit the value of the specified cell.

It creates a Text control by default. The method should return null to make the cell read only.

The parent argument is always the parent of Matrix component. It is passed explicitly to discourage creating edit controls as children of Matrix which would block the matrix from receiving focus and thus any key or mouse events.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
control to edit the value of the specified cell
See Also:
createControl(Number, Number)

createControl

protected Control createControl(X indexX,
                                Y indexY,
                                char ch)

removeControl

protected void removeControl(Control control)
Disposes the edit control. This method can be overridden to implement the control hiding instead of disposing, making also the createControl(Number, Number) method to show the control instead of creating a new one in that case.

Parameters:
control -
See Also:
createControl(Number, Number)

setBounds

protected void setBounds(X indexX,
                         Y indexY,
                         Control control)
Sets the bounds of the specified edit control in the specified cell.

The cell bounds are offset by 1 pixel and applied with the Control#setBounds(Rectangle) method, unless the control is a check button whose size is not modified. Then the control location is centralized relating to the cell.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
control - to set the bounds for

hasEmbeddedControl

protected boolean hasEmbeddedControl(X indexX,
                                     Y indexY)
Returns true if the cell editor control for the specified cell is embedded in the cell, or false if it is a pop-up.

By default this function returns false.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
embedded state of the cell editor

getEmbeddedControl

public Control getEmbeddedControl(X indexX,
                                  Y indexY)
Returns a control embedded in the cell with the given coordinates or null if the cell does not have an embedded control or the control is not visible.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
The control embedded in the cell with the given coordinates

delete

public boolean delete()
Sets the null value to the selected cells.

Returns:
false if the cell modifications was invalid.
See Also:
setModelValue(Number, Number, Object)

copy

public void copy()
Copies selected cells to the clipboard.

Only rectangular area can be copied, i.e. it copies the smallest rectangle including all the selected cells. The values are formatted with format(Number, Number) method and separated with '\t', while lines are separated with System.getProperty("line.separator").


paste

public boolean paste()
Pastes from the clipboard to the zone starting from the focus cell.

Values in the clipboard exceeding the existing zone capacity are ignored.

Atomicity: Model changes done with the method will be rolled back when isBulkEditAtomic returns true and:

Returns:
false if the cell modifications was invalid.
See Also:
setModelValue(Number, Number, Object)

cut

public void cut()
Cuts the selected cells by copying them to the clipboard and setting null value to them.

Invokes copy and delete, so all the rules for those methods apply here.

See Also:
copy(), delete()

format

protected java.lang.String format(X indexX,
                                  Y indexY)
Returns the label for the specified cell to be included in the clipboard copying. By default it returns a value from the Painter.text field after calling Painter.setupSpatial(Number, Number).

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
the label for the specified cell to be included in the clipboard copying
See Also:
copy()

parse

protected java.lang.Object parse(X indexX,
                                 Y indexY,
                                 java.lang.String s)
Parses a text for the specified cell during paste operation. To parse a value from editor control use getEditorValue(Control).

By default it returns the s argument.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
s - text to parse from
Returns:
parsed text of specified cell during paste operation
See Also:
paste()

getZone

public Zone<X,Y> getZone()
Returns zone of the editor.

Returns:
zone of the editor

getCheckboxEmulation

protected java.lang.Object[] getCheckboxEmulation(X indexX,
                                                  Y indexY)
Returns the check box emulation data. It is an array with either two String elements for a true value label and false value label, or two Image elements for a true value image and a false value image.

Parameters:
indexX - cell index on the horizontal axis
indexY - cell index on the vertical axis
Returns:
the check box emulation data.
See Also:
getDefaultCheckboxLabels()

getDefaultCheckboxLabels

protected final java.lang.Object[] getDefaultCheckboxLabels()
Returns the default labels to emulate check boxes. The first label in the returned array is ✓ for the true value, the second one is null for the false value.

Returns:
default labels to emulate check boxes.
See Also:
getCheckboxEmulation(Number, Number)

redraw

public void redraw()
Makes the embedded controls to be recreated.


layoutControls

public void layoutControls()


Copyright © 2011 netanel.pl. All Rights Reserved.