[jboss-svn-commits] JBL Code SVN: r7271 - 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
Wed Nov 1 07:31:46 EST 2006


Author: stevearoonie
Date: 2006-11-01 07:31:42 -0500 (Wed, 01 Nov 2006)
New Revision: 7271

Modified:
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/EditableDTGrid.java
Log:
add ability to move editable cells

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-11-01 12:26:53 UTC (rev 7270)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/decisiontable/EditableDTGrid.java	2006-11-01 12:31:42 UTC (rev 7271)
@@ -1,6 +1,5 @@
 package org.drools.brms.client.decisiontable;
 
-import com.google.gwt.user.client.ui.ClickListener;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HorizontalPanel;
@@ -31,21 +30,6 @@
 
 	private static final int START_DATA_ROW = 1;
 
-	private static final int EDIT_COLUMN_OFFSET = 2;
-
-	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 static final int MERGE_COLUMN_OFFSET = SHUFFLE_DOWN_COLUMN_OFFSET
-	// + 1;
-
 	private FlexTable table = new FlexTable();
 
 	private int currentRow;
@@ -88,22 +72,21 @@
 		// and the data follows
 		populateDataGrid();
 
-		// and this is how you span/merge things, FYI
-		// table.getFlexCellFormatter().setColSpan( 2, 3, 4 );
-
 		// needed for Composite
 		initWidget(vert);
 	}
 
 	protected void setCurrentCell(int row, int col) {
 
-		if (col > 0 && col <= numCols() && row > 0 && (row != currentRow || col != currentCol)) {
-			if (currentRow > 0) {
-				cellFormatter.setStyleName(currentRow, currentCol,
-						"dt-editor-Cell");
+		if (col > 0 && col <= numCols() && row >= START_DATA_ROW
+				&& (row != currentRow || col != currentCol)) {
+			if (currentRow > START_DATA_ROW) {
+				TextBox text = (TextBox) table
+						.getWidget(currentRow, currentCol);
+				newCell(currentRow, currentCol, text.getText());
 			}
 			if (currentRow != row) {
-				if (currentRow > 0) {
+				if (currentRow > START_DATA_ROW) {
 					cellFormatter.setStyleName(currentRow, 0,
 							"dt-editor-CountColumn");
 				}
@@ -136,75 +119,6 @@
 		}
 	}
 
-	// private class DTCell extends Composite {
-	// private HorizontalPanel panel = new HorizontalPanel();
-	//
-	// private Image merge;
-	//
-	// private Label content;
-	//
-	// private MergeListener mergeListener;
-	//
-	// private SplitListener splitListener;
-	//
-	// DTCell(String value, final MergeListener mergeListener,
-	// final SplitListener splitListener) {
-	// this.mergeListener = mergeListener;
-	// this.splitListener = splitListener;
-	// content = new Label(value);
-	// merge = new Image("images/refresh.gif");
-	// merge.setTitle("Merge cells in this row");
-	// merge.addClickListener(new ClickListener() {
-	//
-	// public void onClick(Widget w) {
-	// MyPopup popup = new MyPopup(mergeListener, splitListener);
-	// popup.setPopupPosition(w.getAbsoluteLeft(), w
-	// .getAbsoluteTop() + 20);
-	// popup.show();
-	// }
-	// });
-	// panel.add(content);
-	// panel.add(merge);
-	// initWidget(panel);
-	// }
-	//
-	// public void setColumn(int col) {
-	// mergeListener.setColumn(col);
-	// splitListener.setColumn(col);
-	// }
-	//
-	// public void setRow(int row) {
-	// mergeListener.setRow(row);
-	// splitListener.setRow(row);
-	// }
-	// }
-
-	// private static class MyPopup extends PopupPanel {
-	//
-	// public MyPopup(ClickListener mergeListener, ClickListener splitListener)
-	// {
-	// // PopupPanel's constructor takes 'auto-hide' as its boolean
-	// // parameter.
-	// // If this is set, the panel closes itself automatically when the
-	// // user
-	// // clicks outside of it.
-	// super(true);
-	//
-	// // PopupPanel is a SimplePanel, so you have to set it's widget
-	// // property to
-	// // whatever you want its contents to be.
-	// HorizontalPanel panel = new HorizontalPanel();
-	// Image mergeLeft = new Image("images/shuffle_up.gif");
-	// mergeLeft.addClickListener(mergeListener);
-	// Image mergeRight = new Image("images/shuffle_down.gif");
-	// mergeRight.addClickListener(splitListener);
-	// panel.add(mergeLeft);
-	// panel.add(mergeRight);
-	// panel.setBorderWidth(1);
-	// setWidget(panel);
-	// }
-	// }
-
 	/**
 	 * This populates the "data" part of the decision table (not the header
 	 * bits). It starts at the row offset.
@@ -225,89 +139,20 @@
 			table.setText(row, 0, Integer.toString(rowCount));
 			cellFormatter.setStyleName(row, 0, "dt-editor-CountColumn");
 			for (; column < numCols() + 1; column++) {
-				// table.setText(row, column, "boo " + column);
 				String text = "boo " + column;
 				newCell(row, column, text);
-				cellFormatter.setStyleName(row, column, "dt-editor-Cell");
 			}
 
-			final int currentRow = row;
-
-			addActions(column, currentRow, false);
 		}
 	}
 
 	private void newCell(int row, int column, String text) {
 		table.setText(row, column, text);
-		// table.setWidget(row, column, new DTCell(text,
-		// new MergeListener(row, column), new SplitListener(row,
-		// column)));
+		cellFormatter.setStyleName(row, column, "dt-editor-Cell");
 	}
 
-	// private class MergeListener implements ClickListener {
-	//
-	// private int row;
-	//
-	// private int col;
-	//
-	// MergeListener(int row, int col) {
-	// this.row = row;
-	// this.col = col;
-	// }
-	//
-	// public void onClick(Widget w) {
-	// mergeCell(row, col);
-	// }
-	//
-	// public void setColumn(int col) {
-	// this.col = col;
-	//			
-	// }
-	//
-	// public void setRow(int row) {
-	// this.row = row;
-	// }
-	//
-	// }
-	//
-	// private class SplitListener implements ClickListener {
-	//
-	// private int row;
-	//
-	// private int col;
-	//
-	// SplitListener(int row, int col) {
-	// this.row = row;
-	// this.col = col;
-	// }
-	//
-	// public void onClick(Widget w) {
-	// splitCell(row, col);
-	// }
-	//
-	// public void setColumn(int col) {
-	// this.col = col;
-	//			
-	// }
-	//
-	// public void setRow(int row) {
-	// this.row = row;
-	// }
-	//
-	// }
 
-	private void addActions(final int startCol, final int currentRow,
-			boolean newRow) {
-		// the action magic
-		addEditActions(startCol, currentRow, newRow);
 
-		// addInsertAction(startCol, currentRow);
-		// addDeleteAction(startCol, currentRow);
-		// addShuffleUpAction(startCol, currentRow);
-		// addShuffleDownAction(startCol, currentRow);
-		// addMergeAction(currentRow);
-	}
-
 	public void mergeCell(int row, int col) {
 		int currentSpan = cellFormatter.getColSpan(row, col);
 		if (col + currentSpan <= numCols()) {
@@ -327,80 +172,6 @@
 		}
 	}
 
-	// private void addShuffleDownAction(final int numCols, 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 numCols, 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 numCols, 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 numCols, 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 numCols, 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
 	 */
@@ -408,9 +179,6 @@
 		void onClick(Widget w, int row);
 	}
 
-	// counter for dummy new row data
-	private int cellId;
-
 	private int numRows = 14;
 
 	/**
@@ -424,25 +192,11 @@
 		// so this is two above the original row
 		int newRow = addNewRow(currentRow - 1);
 
-		int lastCol = copyRow(currentRow + 1, newRow);
-		addActions(lastCol, newRow, false);
+		copyRow(currentRow + 1, newRow);
 
 		// remove the original row
 		table.removeRow(currentRow + 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 (currentRow == START_DATA_ROW + 1) {
-		// addShuffleUpAction(lastCol, currentRow);
-		// }
-		// if the original row was the last row we need to remove the shuffle
-		// down
-		// widget from the new last row
-		// if (currentRow == numRows()) {
-		// removeShuffleDown();
-		// }
-		// renumberRow(currentRow - 1);
 		renumberRow(currentRow);
 		currentRow = -1;
 		setCurrentCell(newRow, currentCol);
@@ -455,18 +209,20 @@
 	 * @param sourceRow
 	 * @param targetRow
 	 */
-	private int copyRow(int sourceRow, int targetRow) {
-		// TODO handle editable rows
+	private void copyRow(int sourceRow, int targetRow) {
 		int column = 1;
 		int colIndex = 1;
 		while (column <= numCols()) {
-			newCell(targetRow, colIndex, table.getText(sourceRow, colIndex));
-			cellFormatter.setStyleName(targetRow, colIndex, "dt-editor-Cell");
+			if (column == currentCol) {
+				TextBox box = (TextBox) table.getWidget(sourceRow, column);
+				newCell(targetRow, colIndex, box.getText());
+			} else {
+				newCell(targetRow, colIndex, table.getText(sourceRow, colIndex));
+			}
 			int colSpan = cellFormatter.getColSpan(sourceRow, colIndex);
 			column = column + colSpan;
 			cellFormatter.setColSpan(targetRow, colIndex++, colSpan);
 		}
-		return colIndex;
 	}
 
 	/**
@@ -493,24 +249,10 @@
 		// so this is two below the original row
 		int newRow = addNewRow(currentRow + 2);
 
-		int lastCol = copyRow(currentRow, newRow);
+		copyRow(currentRow, 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(currentRow);
-		addActions(lastCol, 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(lastCol, row);
-		// }
-		System.err.println("currentRow: " + currentRow);
 		renumberRow(currentRow);
 		renumberRow(currentRow + 1);
 		currentRow = -1;
@@ -518,28 +260,30 @@
 
 	}
 
-	// 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) {
+	void deleteRow() {
 		numRows--;
-		table.removeRow(row);
-		reorderRows(row);
+		table.removeRow(currentRow);
+		reorderRows(currentRow);
+		currentRow = -1;
+		clearCurrentCell();
 	}
 
+	private void clearCurrentCell() {
+		if (currentRow > 0) {
+			cellFormatter
+					.setStyleName(currentRow, currentCol, "dt-editor-Cell");
+			currentRow = -1;
+		}
+		if (currentCol > 0) {
+			cellFormatter.setStyleName(0, currentCol,
+					"dt-editor-DescriptionCell");
+			currentCol = -1;
+		}
+	}
+
 	/**
 	 * Renumber the rows from the start row and change the row the actions will
 	 * act on
@@ -559,32 +303,6 @@
 	 */
 	private void renumberRow(int row) {
 		table.setText(row, 0, Integer.toString(row));
-		// for (int i = 1; i < numCols(); i++) {
-		// DTCell cell = (DTCell) table.getWidget(row, i);
-		// cell.setRow(row);
-		// }
-		// int lastColumn = numCols();
-		// System.err.println("lastColumn: " + lastColumn);
-		// System.err.println("row: " + row);
-		// System.err.println("table.getHTML(row, lastColumn): "
-		// + table.getHTML(row, lastColumn + EDIT_COLUMN_OFFSET));
-		// 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);
 	}
 
 	/**
@@ -596,42 +314,23 @@
 			int newRow = addNewRow(currentRow + 1);
 			int column = 1;
 			for (; column < numCols() + 1; column++) {
-				table.setText(newRow, column, "new " + cellId++);
-				cellFormatter.setStyleName(newRow, column, "dt-editor-Cell");
+				newCell(newRow, column, "");
 			}
-			addActions(column, newRow, true);
-			editRow(newRow);
+			// addActions(column, newRow, true);
 			reorderRows(newRow);
+			setCurrentCell(newRow, 1);
 		}
 	}
 
-	/**
-	 * Apply the changes to the row.
-	 */
-	private void updateRow(int row) {
-		for (int column = 1; column < numCols() + 1; column++) {
-			TextBox text = (TextBox) table.getWidget(row, column);
-			newCell(row, column, text.getText());
-		}
-	}
-
-	/**
-	 * This switches the given row into edit mode.
-	 * 
-	 * @param row
-	 */
-	private void editRow(int row) {
-		for (int column = 1; column < numCols() + 1; column++) {
-			editColumn(row, column);
-		}
-	}
-
 	private void editColumn(int row, int column) {
 		String text = table.getText(row, column);
+		editColumn(row, column, text);
+	}
+
+	private void editColumn(int row, int column, String text) {
 		TextBox box = new TextBox();
 		box.setText(text);
 		box.setStyleName("dsl-field-TextBox");
-		//box.setVisibleLength(3);
 		table.setWidget(row, column, box);
 		box.setFocus(true);
 	}




More information about the jboss-svn-commits mailing list