Skip to content

Commit

Permalink
fix paste issues
Browse files Browse the repository at this point in the history
When the table is copy/paste the rows enters into the change tracker and
if you then modify any rows on any table the rows from the copy/paste
table will be added on save operation.
  • Loading branch information
Igor Cher committed Aug 27, 2014
1 parent a27f1a2 commit 088eea0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
22 changes: 19 additions & 3 deletions src/main/java/hrider/hbase/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ public void createOrModifyTable(String tableName) throws IOException, TableNotFo
* @throws IOException Error accessing hbase.
*/
public void createOrModifyTable(TableDescriptor tableDescriptor) throws IOException, TableNotFoundException {
createOrModifyTable(tableDescriptor, null);
}

/**
* Creates a new table or modifies an existing one in the hbase cluster.
*
* @param tableDescriptor The descriptor of the table to create.
* @throws IOException Error accessing hbase.
*/
public void createOrModifyTable(TableDescriptor tableDescriptor, byte[][] splitKeys) throws IOException, TableNotFoundException {
if (this.hbaseAdmin.tableExists(tableDescriptor.getName())) {
if (this.hbaseAdmin.isTableEnabled(tableDescriptor.getName())) {
this.hbaseAdmin.disableTable(tableDescriptor.getName());
Expand All @@ -223,7 +233,7 @@ public void createOrModifyTable(TableDescriptor tableDescriptor) throws IOExcept
}
}
else {
this.hbaseAdmin.createTable(tableDescriptor.toDescriptor());
this.hbaseAdmin.createTable(tableDescriptor.toDescriptor(), splitKeys);

for (HbaseActionListener listener : this.listeners) {
listener.tableOperation(tableDescriptor.getName(), "created");
Expand Down Expand Up @@ -289,9 +299,15 @@ public void truncateTable(String tableName) throws IOException, TableNotFoundExc
* @throws IOException Error accessing hbase on one of the clusters or on both clusters.
*/
public void copyTable(TableDescriptor targetTable, TableDescriptor sourceTable, Connection sourceCluster) throws IOException, TableNotFoundException {
createOrModifyTable(targetTable);

HTable source = sourceCluster.factory.get(sourceTable.getName());

byte[][] startKeys = source.getStartKeys();
byte[][] splitKeys = new byte[startKeys.length - 1][];

System.arraycopy(startKeys, 1, splitKeys, 0, startKeys.length - 1);

createOrModifyTable(targetTable, splitKeys);

HTable target = this.factory.get(targetTable.getName());

Scan scan = new Scan();
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/hrider/ui/forms/PasteDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import hrider.data.DataRow;
import hrider.data.ConvertibleObject;
import hrider.ui.ChangeTracker;
import hrider.data.DataRow;
import hrider.ui.design.JCellEditor;

import javax.swing.*;
Expand Down Expand Up @@ -39,16 +38,16 @@ public class PasteDialog extends JDialog {
//region Variables
private static final long serialVersionUID = 1459899796815018087L;

private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTable table;
private boolean okPressed;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTable table;
private boolean okPressed;
private Map<ConvertibleObject, DataRow> rows;
//endregion

//region Constructor
public PasteDialog(ChangeTracker changeTracker, Iterable<DataRow> rows) {
public PasteDialog(Iterable<DataRow> rows) {
this.rows = new HashMap<ConvertibleObject, DataRow>();

setContentPane(this.contentPane);
Expand All @@ -63,8 +62,8 @@ public PasteDialog(ChangeTracker changeTracker, Iterable<DataRow> rows) {
tableModel.addColumn("New Key");
this.table.setRowHeight(this.table.getFont().getSize() + 8);
this.table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
this.table.getColumn("Original Key").setCellEditor(new JCellEditor(changeTracker, false));
this.table.getColumn("New Key").setCellEditor(new JCellEditor(changeTracker, true));
this.table.getColumn("Original Key").setCellEditor(new JCellEditor(null, false));
this.table.getColumn("New Key").setCellEditor(new JCellEditor(null, true));

for (DataRow row : rows) {
this.rows.put(row.getKey(), row);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hrider/ui/views/DesignerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ private void pasteRowsFromClipboard() {
if (table.getRowsCount() > 0) {
owner.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
PasteDialog dialog = new PasteDialog(changeTracker, table.getRows());
PasteDialog dialog = new PasteDialog(table.getRows());
if (dialog.showDialog(topPanel)) {
Collection<DataRow> updatedRows = dialog.getRows();
for (DataRow row : updatedRows) {
Expand Down

0 comments on commit 088eea0

Please sign in to comment.