[jboss-svn-commits] JBL Code SVN: r7075 - labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 24 07:39:20 EDT 2006
Author: stevearoonie
Date: 2006-10-24 07:39:11 -0400 (Tue, 24 Oct 2006)
New Revision: 7075
Added:
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/DeleteAction.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleAction.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleDownAction.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleUpAction.java
Modified:
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/EditableDTGrid.java
Log:
Add delete row, shuffle up and shuffle down actions
Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/DeleteAction.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/DeleteAction.java 2006-10-24 11:32:09 UTC (rev 7074)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/DeleteAction.java 2006-10-24 11:39:11 UTC (rev 7075)
@@ -0,0 +1,52 @@
+package org.drools.brms.client.decisiontable;
+
+import org.drools.brms.client.decisiontable.EditableDTGrid.RowClickListener;
+
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * This shows the widget for deleting a row.
+ * @author Steven Williams
+ */
+public class DeleteAction extends Composite {
+
+ private HorizontalPanel panel = new HorizontalPanel();
+ private Image delete;
+ private int row;
+
+
+
+
+ /**
+ * Pass in the click listener delegate for when the respective action is clicked
+ * @param clickListener
+ * @param okClickListener
+ */
+ public DeleteAction(final int currentRow, final RowClickListener clickListener) {
+ row = currentRow;
+ delete = new Image("images/clear_item.gif");
+ delete.setTitle( "Delete this row" );
+ delete.addClickListener( new ClickListener() {
+ public void onClick(final Widget w) {
+ clickListener.onClick(w, row);
+ }
+ });
+
+ panel.add( delete);
+
+ initWidget( panel );
+ }
+
+ public void setRow(final int row) {
+ this.row = row;
+ }
+
+ public int getRow() {
+ return row;
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/EditableDTGrid.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/EditableDTGrid.java 2006-10-24 11:32:09 UTC (rev 7074)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/EditableDTGrid.java 2006-10-24 11:39:11 UTC (rev 7075)
@@ -27,6 +27,12 @@
public class EditableDTGrid extends Composite {
private static final int START_DATA_ROW = 1;
+
+ private static final int EDIT_COLUMN_OFFSET = 1;
+ private static final int INSERT_COLUMN_OFFSET = EDIT_COLUMN_OFFSET + 1;
+ private static final int DELETE_COLUMN_OFFSET = INSERT_COLUMN_OFFSET + 1;
+ private static final int SHUFFLE_UP_COLUMN_OFFSET = DELETE_COLUMN_OFFSET + 1;
+ private static final int SHUFFLE_DOWN_COLUMN_OFFSET = SHUFFLE_UP_COLUMN_OFFSET + 1;
private FlexTable table = new FlexTable();
@@ -102,65 +108,256 @@
final int currentRow = row;
- addActions(column, currentRow, false);
+ addActions(currentRow, false);
}
}
- private void addActions(int column, final int currentRow, boolean newRow) {
+ private void addActions(final int currentRow, boolean newRow) {
// the action magic
- final EditActions actions = new EditActions(currentRow, new RowClickListener() {
- public void onClick(Widget w, int row) {
- editRow(row);
- }
- }, new RowClickListener() {
- public void onClick(Widget w, int row) {
- updateRow(row);
- }
- });
- if (newRow) actions.makeEditable();
- table.setWidget(currentRow, column++, actions);
+ addEditActions(currentRow, newRow);
- final InsertAction insertAction = new InsertAction(currentRow, new RowClickListener() {
- public void onClick(Widget w, int row) {
- insertRow(row);
- }
- });
- table.setWidget(currentRow, column, insertAction);
+ addInsertAction(currentRow);
+ addDeleteAction(currentRow);
+ addShuffleUpAction(currentRow);
+ addShuffleDownAction(currentRow);
}
-
+
+ private void addShuffleDownAction(final int currentRow) {
+ final ShuffleAction shuffleDownAction;
+ if (currentRow == numRows()) {
+ shuffleDownAction = new ShuffleAction();
+ } else {
+ shuffleDownAction = new ShuffleDownAction(
+ currentRow, new RowClickListener() {
+ public void onClick(Widget w, int row) {
+ shuffleDown(row);
+ }
+ });
+ }
+ table.setWidget(currentRow, numCols() + SHUFFLE_DOWN_COLUMN_OFFSET, shuffleDownAction);
+ }
+
+ private void addShuffleUpAction(final int currentRow) {
+ final ShuffleAction shuffleUpAction;
+ if (currentRow == START_DATA_ROW) {
+ shuffleUpAction = new ShuffleAction();
+ } else {
+
+ shuffleUpAction = new ShuffleUpAction(currentRow,
+ new RowClickListener() {
+ public void onClick(Widget w, int row) {
+ shuffleUp(row);
+ }
+ });
+ }
+ table.setWidget(currentRow, numCols() + SHUFFLE_UP_COLUMN_OFFSET, shuffleUpAction);
+ }
+
+ private void addDeleteAction(final int currentRow) {
+ final DeleteAction deleteAction = new DeleteAction(currentRow,
+ new RowClickListener() {
+ public void onClick(Widget w, int row) {
+ deleteRow(row);
+ }
+ });
+ table.setWidget(currentRow, numCols() + DELETE_COLUMN_OFFSET, deleteAction);
+ }
+
+ private void addInsertAction(final int currentRow) {
+ final InsertAction insertAction = new InsertAction(currentRow,
+ new RowClickListener() {
+ public void onClick(Widget w, int row) {
+ insertRow(row);
+ }
+ });
+ table.setWidget(currentRow, numCols() + INSERT_COLUMN_OFFSET, insertAction);
+ }
+
+ private void addEditActions(final int currentRow, boolean newRow) {
+ final EditActions actions = new EditActions(currentRow,
+ new RowClickListener() {
+ public void onClick(Widget w, int row) {
+ editRow(row);
+ }
+ }, new RowClickListener() {
+ public void onClick(Widget w, int row) {
+ updateRow(row);
+ }
+ });
+ if (newRow)
+ actions.makeEditable();
+ table.setWidget(currentRow, numCols() + EDIT_COLUMN_OFFSET, actions);
+ }
+
/**
* Listener for click events that affect a whole row
*/
interface RowClickListener {
void onClick(Widget w, int row);
}
-
- //counter for dummy new row data
+
+ // counter for dummy new row data
private int cellId;
-
+
+ private int numRows = 14;
+
/**
+ * Shuffle the given row up one
+ * @param row
+ */
+ private void shuffleUp(int row) {
+ //create a new row above the given row
+ //remember that insertRow will insert above the given row
+ //so this is two above the original row
+ int newRow = addNewRow(row - 1);
+
+ copyRow(row + 1, newRow);
+ addActions(newRow, false);
+
+ //remove the original row
+ table.removeRow(row + 1);
+
+ //if the original row was the second row then we need to add a shuffle up
+ //widget to the new second row (originally the first row)
+ if (row == START_DATA_ROW + 1) {
+ addShuffleUpAction(row);
+ }
+ //if the original row was the last row we need to remove the shuffle down
+ //widget from the new last row
+ if (row == numRows()) {
+ removeShuffleDown();
+ }
+ renumberRow(row - 1);
+ renumberRow(row);
+
+ }
+
+ /**
+ * Copy the data from the source row to the target row
+ * @param sourceRow
+ * @param targetRow
+ */
+ private void copyRow(int sourceRow, int targetRow) {
+ //TODO handle editable rows
+ int column = 1;
+ for (; column < numCols() + 1; column++) {
+ table.setText(targetRow, column, table.getText(sourceRow, column));
+ cellFormatter.setStyleName(targetRow, column, "dt-editor-Cell");
+ }
+ }
+ /**
+ * Add a new row and set the row number
+ * @param row
+ * @return
+ */
+ private int addNewRow(int row) {
+ int newRow = table.insertRow(row);
+ table.setText(newRow, 0, Integer.toString(newRow));
+ cellFormatter.setStyleName(newRow, 0, "dt-editor-CountColumn");
+ return newRow;
+ }
+
+ /**
+ * Shuffle the given row down one
+ * @param row
+ */
+ private void shuffleDown(int row) {
+ //create a new row below the given row
+ //remember that insertRow will insert above the given row
+ //so this is two below the original row
+ int newRow = addNewRow(row + 2);
+
+ copyRow(row, newRow);
+ //remove row before adding action widgets so that the row number
+ //is correct (otherwise the shuffle down button may not be displayed
+ table.removeRow(row);
+ addActions(newRow - 1, false);
+ //if the original row was the first row we need to remove the shuffle up
+ //widget from the new first row
+ if (row == START_DATA_ROW) {
+ removeShuffleUp();
+ }
+ //if the original row was the second last row then we need to add a shuffle down
+ //widget to the new second last row (originally the last row)
+ if (row == numRows() - 1) {
+ addShuffleDownAction(row);
+ }
+ renumberRow(row);
+ renumberRow(row + 1);
+
+ }
+
+ private void removeShuffleUp() {
+ table.setWidget(START_DATA_ROW, numCols() + SHUFFLE_UP_COLUMN_OFFSET, new ShuffleAction());
+ }
+ private void removeShuffleDown() {
+ table.setWidget(numRows(), numCols() + SHUFFLE_DOWN_COLUMN_OFFSET, new ShuffleAction());
+ }
+
+ /**
+ * Delete the specified row
+ *
+ * @param row
+ * the row to delete
+ */
+ private void deleteRow(int row) {
+ numRows--;
+ table.removeRow(row);
+ reorderRows(row);
+ }
+
+ /**
+ * Renumber the rows from the start row and change the row the actions will
+ * act on
+ *
+ * @param startRow
+ */
+ private void reorderRows(final int startRow) {
+ for (int r = startRow; r < table.getRowCount(); r++) {
+ renumberRow(r);
+ }
+ }
+ /**
+ * Renumber the given row and change the row the actions will act on
+ * @param row
+ */
+ private void renumberRow(int row) {
+ table.setText(row, 0, Integer.toString(row));
+ int lastColumn = numCols();
+ EditActions editActions = (EditActions) table.getWidget(row,
+ lastColumn + EDIT_COLUMN_OFFSET);
+ editActions.setRow(row);
+ InsertAction insertAction = (InsertAction) table.getWidget(row,
+ lastColumn + INSERT_COLUMN_OFFSET);
+ insertAction.setRow(row);
+ DeleteAction deleteAction = (DeleteAction) table.getWidget(row,
+ lastColumn + DELETE_COLUMN_OFFSET);
+ deleteAction.setRow(row);
+ ShuffleAction shuffleUpAction = (ShuffleAction) table.getWidget(row,
+ lastColumn + SHUFFLE_UP_COLUMN_OFFSET);
+ shuffleUpAction.setRow(row);
+ ShuffleAction shuffleDownAction = (ShuffleAction) table.getWidget(
+ row, lastColumn + SHUFFLE_DOWN_COLUMN_OFFSET);
+ shuffleDownAction.setRow(row);
+ }
+
+ /**
* Add a new row after the specified row
- * @param row the row to insert after
+ *
+ * @param row
+ * the row to insert after
*/
private void insertRow(int row) {
- int newRow = table.insertRow(row + 1);
- table.setText(newRow, 0, Integer.toString(newRow));
- cellFormatter.setStyleName(newRow, 0, "dt-editor-CountColumn");
+ numRows++;
+ int newRow = addNewRow(row + 1);
int column = 1;
for (; column < numCols() + 1; column++) {
table.setText(newRow, column, "new " + cellId++);
cellFormatter.setStyleName(newRow, column, "dt-editor-Cell");
}
- addActions(column, newRow, true);
+ addActions(newRow, true);
editRow(newRow);
- for (int r = newRow + 1; r < table.getRowCount(); r++) {
- table.setText(r, 0, Integer.toString(r));
- EditActions editActions = (EditActions) table.getWidget(r, column);
- editActions.setRow(r);
- InsertAction insertAction = (InsertAction) table.getWidget(r, column + 1);
- insertAction.setRow(r);
- }
-
+ reorderRows(newRow);
}
/**
@@ -195,7 +392,7 @@
}
private int numRows() {
- return 14;
+ return numRows;
}
}
Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleAction.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleAction.java 2006-10-24 11:32:09 UTC (rev 7074)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleAction.java 2006-10-24 11:39:11 UTC (rev 7075)
@@ -0,0 +1,58 @@
+package org.drools.brms.client.decisiontable;
+
+import org.drools.brms.client.decisiontable.EditableDTGrid.RowClickListener;
+
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * This shows the widget for moving a row up or down.
+ * @author Steven Williams
+ */
+public class ShuffleAction extends Composite {
+
+ private HorizontalPanel panel = new HorizontalPanel();
+ private Image shuffle;
+ private int row;
+
+ public final static ShuffleAction EMPTY1 = new ShuffleAction() {
+
+ };
+
+ public ShuffleAction() {
+ initWidget(panel);
+ }
+ /**
+ * Pass in the click listener delegate for when the respective action is clicked and the
+ * direction to move the row
+ * @param currentRow
+ * @param clickListener
+ * @param direction
+ */
+ public ShuffleAction(final int currentRow, final RowClickListener clickListener, final String direction) {
+ row = currentRow;
+ shuffle = new Image("images/shuffle_" + direction + ".gif");
+ shuffle.setTitle( "Move this row " + direction );
+ shuffle.addClickListener( new ClickListener() {
+ public void onClick(final Widget w) {
+ clickListener.onClick(w, row);
+ }
+ });
+
+ panel.add( shuffle);
+
+ initWidget( panel );
+ }
+
+ public void setRow(final int row) {
+ this.row = row;
+ }
+
+ public int getRow() {
+ return row;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleDownAction.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleDownAction.java 2006-10-24 11:32:09 UTC (rev 7074)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleDownAction.java 2006-10-24 11:39:11 UTC (rev 7075)
@@ -0,0 +1,20 @@
+package org.drools.brms.client.decisiontable;
+
+import org.drools.brms.client.decisiontable.EditableDTGrid.RowClickListener;
+
+/**
+ * This shows the widget for moving a row down.
+ * @author Steven Williams
+ */
+public class ShuffleDownAction extends ShuffleAction {
+
+ /**
+ * Pass in the click listener delegate for when the respective action is clicked
+ * @param clickListener
+ * @param okClickListener
+ */
+ public ShuffleDownAction(final int currentRow, final RowClickListener clickListener) {
+ super(currentRow, clickListener, "down");
+ }
+
+}
Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleUpAction.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleUpAction.java 2006-10-24 11:32:09 UTC (rev 7074)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/ShuffleUpAction.java 2006-10-24 11:39:11 UTC (rev 7075)
@@ -0,0 +1,20 @@
+package org.drools.brms.client.decisiontable;
+
+import org.drools.brms.client.decisiontable.EditableDTGrid.RowClickListener;
+
+/**
+ * This shows the widget for moving a row up.
+ * @author Steven Williams
+ */
+public class ShuffleUpAction extends ShuffleAction {
+
+ /**
+ * Pass in the click listener delegate for when the respective action is clicked
+ * @param clickListener
+ * @param okClickListener
+ */
+ public ShuffleUpAction(final int currentRow, final RowClickListener clickListener) {
+ super(currentRow, clickListener, "up");
+ }
+
+}
More information about the jboss-svn-commits
mailing list