You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/10/06 14:02:55 UTC
svn commit: r822232 - in
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: TreeView.java
content/ListViewItemEditor.java content/TableViewCellEditor.java
content/TreeViewNodeEditor.java
Author: tvolkert
Date: Tue Oct 6 12:02:54 2009
New Revision: 822232
URL: http://svn.apache.org/viewvc?rev=822232&view=rev
Log:
PIVOT-299 :: Wire up the editor events to the remaining stock editors
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java?rev=822232&r1=822231&r2=822232&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java Tue Oct 6 12:02:54 2009
@@ -243,7 +243,8 @@
}
@Override
- public Vote previewSaveChanges(NodeEditor nodeEditor, TreeView treeView, Path path, Object changes) {
+ public Vote previewSaveChanges(NodeEditor nodeEditor, TreeView treeView, Path path,
+ Object changes) {
return Vote.APPROVE;
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java?rev=822232&r1=822231&r2=822232&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java Tue Oct 6 12:02:54 2009
@@ -18,6 +18,7 @@
import org.apache.pivot.collections.List;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.ApplicationContext;
import org.apache.pivot.wtk.Bounds;
import org.apache.pivot.wtk.Component;
@@ -166,19 +167,6 @@
};
/**
- * Gets the text input that serves as the editor component. This component
- * will only be non-<tt>null</tt> while editing.
- *
- * @return
- * This editor's component, or <tt>null</tt> if an edit is not in progress
- *
- * @see #isEditing()
- */
- protected final TextInput getEditor() {
- return textInput;
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -187,26 +175,34 @@
throw new IllegalStateException("Currently editing.");
}
- this.listView = listView;
- this.index = index;
+ Vote vote = itemEditorListeners.previewEditItem(this, listView, index);
- // Get the data being edited
- List<?> listData = listView.getListData();
- ListItem listItem = (ListItem)listData.get(index);
+ if (vote == Vote.APPROVE) {
+ this.listView = listView;
+ this.index = index;
+
+ // Get the data being edited
+ List<?> listData = listView.getListData();
+ ListItem listItem = (ListItem)listData.get(index);
- textInput = new TextInput();
- textInput.setText(listItem.getText());
- textInput.getComponentKeyListeners().add(textInputKeyHandler);
-
- // Create and open the popup
- popup = new Window(textInput);
- popup.getWindowStateListeners().add(popupWindowStateHandler);
- popup.open(listView.getWindow());
- reposition();
+ textInput = new TextInput();
+ textInput.setText(listItem.getText());
+ textInput.getComponentKeyListeners().add(textInputKeyHandler);
- textInput.selectAll();
- textInput.requestFocus();
+ // Create and open the popup
+ popup = new Window(textInput);
+ popup.getWindowStateListeners().add(popupWindowStateHandler);
+ popup.open(listView.getWindow());
+ reposition();
+
+ textInput.selectAll();
+ textInput.requestFocus();
+
+ itemEditorListeners.itemEditing(this, listView, index);
+ } else if (vote == Vote.DENY) {
+ itemEditorListeners.editItemVetoed(this, vote);
+ }
}
/**
@@ -267,27 +263,37 @@
throw new IllegalStateException();
}
- List<Object> listData = (List<Object>)listView.getListData();
- ListItem listItem = (ListItem)listData.get(index);
+ // Save local reference to members variables before they get cleared
+ ListView listView = this.listView;
+ int index = this.index;
- // Update the item data
+ // Preview the changes
String text = textInput.getText();
- listItem.setText(text);
+ Vote vote = itemEditorListeners.previewSaveChanges(this, listView, index, text);
- // Notifying the parent will close the popup
- if (listData.getComparator() == null) {
- listData.update(index, listItem);
- } else {
- // Save local reference to members variables before they get cleared
- ListView listView = this.listView;
-
- listData.remove(index, 1);
- listData.add(listItem);
-
- // Re-select the item, and make sure it's visible
- index = listData.indexOf(listItem);
- listView.setSelectedIndex(index);
- listView.scrollAreaToVisible(listView.getItemBounds(index));
+ if (vote == Vote.APPROVE) {
+ List<Object> listData = (List<Object>)listView.getListData();
+ ListItem listItem = (ListItem)listData.get(index);
+
+ // Update the item data
+ listItem.setText(text);
+
+ // Notifying the parent will close the popup
+ if (listData.getComparator() == null) {
+ listData.update(index, listItem);
+ } else {
+ listData.remove(index, 1);
+ listData.add(listItem);
+
+ // Re-select the item, and make sure it's visible
+ index = listData.indexOf(listItem);
+ listView.setSelectedIndex(index);
+ listView.scrollAreaToVisible(listView.getItemBounds(index));
+ }
+
+ itemEditorListeners.changesSaved(this, listView, index);
+ } else if (vote == Vote.DENY) {
+ itemEditorListeners.saveChangesVetoed(this, vote);
}
}
@@ -300,7 +306,13 @@
throw new IllegalStateException();
}
+ // Save local reference to members variables before they get cleared
+ ListView listView = this.listView;
+ int index = this.index;
+
popup.close();
+
+ itemEditorListeners.editCancelled(this, listView, index);
}
@Override
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java?rev=822232&r1=822231&r2=822232&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java Tue Oct 6 12:02:54 2009
@@ -18,8 +18,10 @@
import org.apache.pivot.beans.BeanDictionary;
import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.collections.HashMap;
import org.apache.pivot.collections.List;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.ApplicationContext;
import org.apache.pivot.wtk.Bounds;
import org.apache.pivot.wtk.Component;
@@ -193,19 +195,6 @@
private RowEditorListenerList rowEditorListeners = new RowEditorListenerList();
/**
- * Gets the text input that serves as the editor component. This component
- * will only be non-<tt>null</tt> while editing.
- *
- * @return
- * This editor's component, or <tt>null</tt> if an edit is not in progress
- *
- * @see #isEditing()
- */
- protected final TextInput getEditor() {
- return textInput;
- }
-
- /**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@@ -215,10 +204,6 @@
throw new IllegalStateException("Currently editing.");
}
- this.tableView = tableView;
- this.rowIndex = rowIndex;
- this.columnIndex = columnIndex;
-
boolean isReadOnly = false;
String columnName = tableView.getColumns().get(columnIndex).getName();
@@ -233,26 +218,35 @@
rowData = beanDictionary;
}
- if (isReadOnly) {
- // Don't initiate the edit
- this.tableView = null;
- } else {
- // Get the data being edited
- Object cellData = rowData.get(columnName);
+ if (!isReadOnly) {
+ Vote vote = rowEditorListeners.previewEditRow(this, tableView, rowIndex, columnIndex);
- // Create the text input
- textInput = new TextInput();
- textInput.setText(cellData == null ? "" : cellData.toString());
- textInput.getComponentKeyListeners().add(textInputKeyHandler);
-
- // Create and open the popup
- popup = new Window(textInput);
- popup.getWindowStateListeners().add(popupWindowStateHandler);
- popup.open(tableView.getWindow());
- reposition();
-
- textInput.selectAll();
- textInput.requestFocus();
+ if (vote == Vote.APPROVE) {
+ this.tableView = tableView;
+ this.rowIndex = rowIndex;
+ this.columnIndex = columnIndex;
+
+ // Get the data being edited
+ Object cellData = rowData.get(columnName);
+
+ // Create the text input
+ textInput = new TextInput();
+ textInput.setText(cellData == null ? "" : cellData.toString());
+ textInput.getComponentKeyListeners().add(textInputKeyHandler);
+
+ // Create and open the popup
+ popup = new Window(textInput);
+ popup.getWindowStateListeners().add(popupWindowStateHandler);
+ popup.open(tableView.getWindow());
+ reposition();
+
+ textInput.selectAll();
+ textInput.requestFocus();
+
+ rowEditorListeners.rowEditing(this, tableView, rowIndex, columnIndex);
+ } else if (vote == Vote.DENY) {
+ rowEditorListeners.editRowVetoed(this, vote);
+ }
}
}
@@ -289,36 +283,52 @@
throw new IllegalStateException();
}
- List<Object> tableData = (List<Object>)tableView.getTableData();
+ // Save local reference to members variables before they get cleared
+ TableView tableView = this.tableView;
+ int rowIndex = this.rowIndex;
+ int columnIndex = this.columnIndex;
- // Get the row data, represented as a Dictionary
- Object tableRow = tableData.get(rowIndex);
- Dictionary<String, Object> rowData;
- if (tableRow instanceof Dictionary<?, ?>) {
- rowData = (Dictionary<String, Object>)tableRow;
- } else {
- rowData = new BeanDictionary(tableRow);
- }
-
- // Update the cell data
+ // Get the changes
String text = textInput.getText();
String columnName = tableView.getColumns().get(columnIndex).getName();
- rowData.put(columnName, text);
- // Notifying the parent will close the popup
- if (tableData.getComparator() == null) {
- tableData.update(rowIndex, tableRow);
- } else {
- // Save local reference to members variables before they get cleared
- TableView tableView = this.tableView;
+ // Preview the changes
+ HashMap<String, Object> changes = new HashMap<String, Object>();
+ changes.put(columnName, text);
+ Vote vote = rowEditorListeners.previewSaveChanges(this, tableView, rowIndex,
+ columnIndex, changes);
+
+ if (vote == Vote.APPROVE) {
+ List<Object> tableData = (List<Object>)tableView.getTableData();
+
+ // Get the row data, represented as a Dictionary
+ Object tableRow = tableData.get(rowIndex);
+ Dictionary<String, Object> rowData;
+ if (tableRow instanceof Dictionary<?, ?>) {
+ rowData = (Dictionary<String, Object>)tableRow;
+ } else {
+ rowData = new BeanDictionary(tableRow);
+ }
+
+ // Update the cell data
+ rowData.put(columnName, text);
- tableData.remove(rowIndex, 1);
- tableData.add(tableRow);
+ // Notifying the parent will close the popup
+ if (tableData.getComparator() == null) {
+ tableData.update(rowIndex, tableRow);
+ } else {
+ tableData.remove(rowIndex, 1);
+ tableData.add(tableRow);
+
+ // Re-select the row, and make sure it's visible
+ rowIndex = tableData.indexOf(tableRow);
+ tableView.setSelectedIndex(rowIndex);
+ tableView.scrollAreaToVisible(tableView.getRowBounds(rowIndex));
+ }
- // Re-select the row, and make sure it's visible
- rowIndex = tableData.indexOf(tableRow);
- tableView.setSelectedIndex(rowIndex);
- tableView.scrollAreaToVisible(tableView.getRowBounds(rowIndex));
+ rowEditorListeners.changesSaved(this, tableView, rowIndex, columnIndex);
+ } else if (vote == Vote.DENY) {
+ rowEditorListeners.saveChangesVetoed(this, vote);
}
}
@@ -331,7 +341,14 @@
throw new IllegalStateException();
}
+ // Save local reference to members variables before they get cleared
+ TableView tableView = this.tableView;
+ int rowIndex = this.rowIndex;
+ int columnIndex = this.columnIndex;
+
popup.close();
+
+ rowEditorListeners.editCancelled(this, tableView, rowIndex, columnIndex);
}
/**
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java?rev=822232&r1=822231&r2=822232&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java Tue Oct 6 12:02:54 2009
@@ -20,6 +20,7 @@
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.collections.Sequence.Tree.Path;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.ApplicationContext;
import org.apache.pivot.wtk.Bounds;
import org.apache.pivot.wtk.Component;
@@ -198,19 +199,6 @@
private NodeEditorListenerList nodeEditorListeners = new NodeEditorListenerList();
/**
- * Gets the text input that serves as the editor component. This component
- * will only be non-<tt>null</tt> while editing.
- *
- * @return
- * This editor's component, or <tt>null</tt> if an edit is not in progress
- *
- * @see #isEditing()
- */
- protected final TextInput getEditor() {
- return textInput;
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -219,24 +207,32 @@
throw new IllegalStateException();
}
- this.treeView = treeView;
- this.path = path;
-
- // Get the data being edited
- List<?> treeData = treeView.getTreeData();
- TreeNode nodeData = (TreeNode)Sequence.Tree.get(treeData, path);
-
- textInput = new TextInput();
- textInput.setText(nodeData.getText());
- textInput.getComponentKeyListeners().add(textInputKeyHandler);
-
- popup = new Window(textInput);
- popup.getWindowStateListeners().add(popupStateHandler);
- popup.open(treeView.getWindow());
- reposition();
+ Vote vote = nodeEditorListeners.previewEditNode(this, treeView, path);
- textInput.selectAll();
- textInput.requestFocus();
+ if (vote == Vote.APPROVE) {
+ this.treeView = treeView;
+ this.path = path;
+
+ // Get the data being edited
+ List<?> treeData = treeView.getTreeData();
+ TreeNode nodeData = (TreeNode)Sequence.Tree.get(treeData, path);
+
+ textInput = new TextInput();
+ textInput.setText(nodeData.getText());
+ textInput.getComponentKeyListeners().add(textInputKeyHandler);
+
+ popup = new Window(textInput);
+ popup.getWindowStateListeners().add(popupStateHandler);
+ popup.open(treeView.getWindow());
+ reposition();
+
+ textInput.selectAll();
+ textInput.requestFocus();
+
+ nodeEditorListeners.nodeEditing(this, treeView, path);
+ } else if (vote == Vote.DENY) {
+ nodeEditorListeners.editNodeVetoed(this, vote);
+ }
}
/**
@@ -298,40 +294,48 @@
throw new IllegalStateException();
}
- List<?> treeData = treeView.getTreeData();
- TreeNode treeNode = (TreeNode)Sequence.Tree.get(treeData, path);
+ // Save local reference to members variables before they get cleared
+ TreeView treeView = this.treeView;
+ Path path = this.path;
- // Update the node data
+ // Preview the changes
String text = textInput.getText();
- treeNode.setText(text);
+ Vote vote = nodeEditorListeners.previewSaveChanges(this, treeView, path, text);
+
+ if (vote == Vote.APPROVE) {
+ // Update the node data
+ List<?> treeData = treeView.getTreeData();
+ TreeNode treeNode = (TreeNode)Sequence.Tree.get(treeData, path);
+ treeNode.setText(text);
+
+ // Get a reference to the parent of the node data
+ int n = path.getLength();
+ List<TreeNode> parentData;
+
+ if (n == 1) {
+ parentData = (List<TreeNode>)treeData;
+ } else {
+ Path parentPath = new Path(path, n - 1);
+ parentData = (List<TreeNode>)Sequence.Tree.get(treeData, parentPath);
+ }
- // Get a reference to the parent of the node data
- int n = path.getLength();
- List<TreeNode> parentData;
-
- if (n == 1) {
- parentData = (List<TreeNode>)treeData;
- } else {
- Path parentPath = new Path(path, n - 1);
- parentData = (List<TreeNode>)Sequence.Tree.get(treeData, parentPath);
- }
-
- // Notifying the parent will close the popup
- if (parentData.getComparator() == null) {
- parentData.update(path.get(n - 1), treeNode);
- } else {
- // Save local reference to members variables before they get cleared
- TreeView treeView = this.treeView;
- Path path = this.path;
-
- parentData.remove(path.get(n - 1), 1);
- parentData.add(treeNode);
-
- // Re-select the node, and make sure it's visible
- Path newPath = new Path(path, n - 1);
- newPath.add(parentData.indexOf(treeNode));
- treeView.setSelectedPath(newPath);
- treeView.scrollAreaToVisible(treeView.getNodeBounds(newPath));
+ // Notifying the parent will close the popup
+ if (parentData.getComparator() == null) {
+ parentData.update(path.get(n - 1), treeNode);
+ } else {
+ parentData.remove(path.get(n - 1), 1);
+ parentData.add(treeNode);
+
+ // Re-select the node, and make sure it's visible
+ path = new Path(path, n - 1);
+ path.add(parentData.indexOf(treeNode));
+ treeView.setSelectedPath(path);
+ treeView.scrollAreaToVisible(treeView.getNodeBounds(path));
+ }
+
+ nodeEditorListeners.changesSaved(this, treeView, path);
+ } else if (vote == Vote.DENY) {
+ nodeEditorListeners.saveChangesVetoed(this, vote);
}
}
@@ -344,7 +348,13 @@
throw new IllegalStateException();
}
+ // Save local reference to members variables before they get cleared
+ TreeView treeView = this.treeView;
+ Path path = this.path;
+
popup.close();
+
+ nodeEditorListeners.editCancelled(this, treeView, path);
}
/**