private void populateTableWithIncomingFields() { if (m_incomingFieldsProducer != null) { RowMetaInterface incomingRowMeta = m_incomingFieldsProducer.getIncomingFields(); Table table = m_fieldsView.table; if (incomingRowMeta != null) { Set<String> existingRowAliases = new HashSet<String>(); for (int i = 0; i < table.getItemCount(); i++) { TableItem tableItem = table.getItem(i); String alias = tableItem.getText(1); if (!Const.isEmpty(alias)) { existingRowAliases.add(alias); } } int choice = 0; if (existingRowAliases.size() > 0) { // Ask what we should do with existing mapping data MessageDialog md = new MessageDialog( m_shell, Messages.getString("MappingDialog.GetFieldsChoice.Title"), null, Messages.getString( "MappingDialog.GetFieldsChoice.Message", "" + existingRowAliases.size(), "" + incomingRowMeta.size()), MessageDialog.WARNING, new String[] { Messages.getString("MappingDialog.AddNew"), Messages.getString("MappingOutputDialog.Add"), Messages.getString("MappingOutputDialog.ClearAndAdd"), Messages.getString("MappingOutputDialog.Cancel"), }, 0); MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon()); int idx = md.open(); choice = idx & 0xFF; } if (choice == 3 || choice == 255 /* 255 = escape pressed */) { return; // Cancel } if (choice == 2) { m_fieldsView.clearAll(); } for (int i = 0; i < incomingRowMeta.size(); i++) { ValueMetaInterface vm = incomingRowMeta.getValueMeta(i); boolean addIt = true; if (choice == 0) { // only add if its not already in the table if (existingRowAliases.contains(vm.getName())) { addIt = false; } } if (addIt) { TableItem item = new TableItem(m_fieldsView.table, SWT.NONE); item.setText(1, vm.getName()); item.setText(2, "N"); if (m_familyCI.getComboValues()[0].length() > 0) { // use existing first column family name as the default item.setText(3, m_familyCI.getComboValues()[0]); } else { // default item.setText(3, DEFAULT_FAMILY); } item.setText(4, vm.getName()); item.setText(5, vm.getTypeDesc()); if (vm.getType() == ValueMetaInterface.TYPE_INTEGER) { item.setText(5, "Long"); } if (vm.getType() == ValueMetaInterface.TYPE_NUMBER) { item.setText(5, "Double"); } if (vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_INDEXED) { Object[] indexValus = vm.getIndex(); String indexValsS = HBaseValueMeta.objectIndexValuesToString(indexValus); item.setText(6, indexValsS); } } } m_fieldsView.removeEmptyRows(); m_fieldsView.setRowNums(); m_fieldsView.optWidth(true); } } }
public Mapping getMapping(boolean checkForMissingTableAndMapping) { String tableName = ""; if (!Const.isEmpty(m_existingTableNamesCombo.getText().trim())) { tableName = m_existingTableNamesCombo.getText().trim(); if (tableName.indexOf('@') > 0) { tableName = tableName.substring(0, tableName.indexOf('@')); } } if (checkForMissingTableAndMapping && (Const.isEmpty(m_existingTableNamesCombo.getText().trim()) || Const.isEmpty(tableName))) { MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.MissingTableMappingName"), Messages.getString("MappingDialog.Error.Message.MissingTableMappingName")); return null; } // do we have any non-empty rows in the table? if (m_fieldsView.nrNonEmpty() == 0) { MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.NoFieldsDefined"), Messages.getString("MappingDialog.Error.Message.NoFieldsDefined")); return null; } // do we have a key defined in the table? Mapping theMapping = new Mapping(tableName, m_existingMappingNamesCombo.getText().trim()); boolean keyDefined = false; boolean moreThanOneKey = false; List<String> missingFamilies = new ArrayList<String>(); List<String> missingColumnNames = new ArrayList<String>(); List<String> missingTypes = new ArrayList<String>(); int nrNonEmpty = m_fieldsView.nrNonEmpty(); // is the mapping a tuple mapping? boolean isTupleMapping = false; int tupleIdCount = 0; if (nrNonEmpty == 5) { for (int i = 0; i < nrNonEmpty; i++) { if (m_fieldsView.getNonEmpty(i).getText(1).equals("KEY") || m_fieldsView.getNonEmpty(i).getText(1).equals("Family") || m_fieldsView.getNonEmpty(i).getText(1).equals("Column") || m_fieldsView.getNonEmpty(i).getText(1).equals("Value") || m_fieldsView.getNonEmpty(i).getText(1).equals("Timestamp")) { tupleIdCount++; } } } /* if (nrNonEmpty == 5 && m_fieldsView.getNonEmpty(0).getText(1).equals("KEY") && m_fieldsView.getNonEmpty(1).getText(1).equals("Family") && m_fieldsView.getNonEmpty(2).getText(1).equals("Column") && m_fieldsView.getNonEmpty(3).getText(1).equals("Value") && m_fieldsView.getNonEmpty(4).getText(1).equals("Timestamp")) { isTupleMapping = true; theMapping.setTupleMapping(true); } */ if (tupleIdCount == 5) { isTupleMapping = true; theMapping.setTupleMapping(true); } for (int i = 0; i < nrNonEmpty; i++) { TableItem item = m_fieldsView.getNonEmpty(i); boolean isKey = false; String alias = null; if (!Const.isEmpty(item.getText(1))) { alias = item.getText(1).trim(); } if (!Const.isEmpty(item.getText(2))) { isKey = item.getText(2).trim().equalsIgnoreCase("Y"); if (isKey && keyDefined) { // more than one key, break here moreThanOneKey = true; break; } if (isKey) { keyDefined = true; } } // String family = null; String family = ""; if (!Const.isEmpty(item.getText(3))) { family = item.getText(3); } else { if (!isKey && !isTupleMapping) { missingFamilies.add(item.getText(0)); } } // String colName = null; String colName = ""; if (!Const.isEmpty(item.getText(4))) { colName = item.getText(4); } else { if (!isKey && !isTupleMapping) { missingColumnNames.add(item.getText(0)); } } String type = null; if (!Const.isEmpty(item.getText(5))) { type = item.getText(5); } else { missingTypes.add(item.getText(0)); } String indexedVals = null; if (!Const.isEmpty(item.getText(6))) { indexedVals = item.getText(6); } /* else { if (!isKey && type != null && type.equalsIgnoreCase("String")) { missingIndexedValues.add(item.getText(0)); } }*/ // only add if we have all data and its all correct if (isKey && !moreThanOneKey) { if (Const.isEmpty(alias)) { // pop up an error dialog - key must have an alias because it does not // belong to a column family or have a column name MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.NoAliasForKey"), Messages.getString("MappingDialog.Error.Message.NoAliasForKey")); return null; } if (Const.isEmpty(type)) { // pop up an error dialog - must have a type for the key MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.NoTypeForKey"), Messages.getString("MappingDialog.Error.Message.NoTypeForKey")); return null; } if (moreThanOneKey) { // popup an error and then return MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.MoreThanOneKey"), Messages.getString("MappingDialog.Error.Message.MoreThanOneKey")); return null; } if (isTupleMapping) { theMapping.setKeyName(alias); theMapping.setTupleFamilies(family); } else { theMapping.setKeyName(alias); } try { theMapping.setKeyTypeAsString(type); } catch (Exception ex) { } } else { // don't bother adding if there are any errors if (missingFamilies.size() == 0 && missingColumnNames.size() == 0 && missingTypes.size() == 0) { String combinedName = family + HBaseValueMeta.SEPARATOR + colName; if (!Const.isEmpty(alias)) { combinedName += (HBaseValueMeta.SEPARATOR + alias); } HBaseValueMeta vm = new HBaseValueMeta(combinedName, 0, -1, -1); try { vm.setHBaseTypeFromString(type); } catch (IllegalArgumentException e) { // TODO pop up an error dialog for this one return null; } if (vm.isString() && indexedVals != null && indexedVals.length() > 0) { Object[] vals = HBaseValueMeta.stringIndexListToObjects(indexedVals); vm.setIndex(vals); vm.setStorageType(ValueMetaInterface.STORAGE_TYPE_INDEXED); } try { theMapping.addMappedColumn(vm, isTupleMapping); } catch (Exception ex) { // popup an error if this family:column is already in the mapping and // then return. MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.DuplicateColumn"), Messages.getString("MappingDialog.Error.Message1.DuplicateColumn") + family + HBaseValueMeta.SEPARATOR + colName + Messages.getString("MappingDialog.Error.Message2.DuplicateColumn")); ex.printStackTrace(); return null; } } } } // now check for any errors in our Lists if (!keyDefined) { MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.NoKeyDefined"), Messages.getString("MappingDialog.Error.Message.NoKeyDefined")); return null; } if (missingFamilies.size() > 0 || missingColumnNames.size() > 0 || missingTypes.size() > 0) { StringBuffer buff = new StringBuffer(); buff.append( Messages.getString("MappingDialog.Error.Message.IssuesPreventingSaving") + ":\n\n"); if (missingFamilies.size() > 0) { buff.append(Messages.getString("MappingDialog.Error.Message.FamilyIssue") + ":\n"); buff.append(missingFamilies.toString()).append("\n\n"); } if (missingColumnNames.size() > 0) { buff.append(Messages.getString("MappingDialog.Error.Message.ColumnIssue") + ":\n"); buff.append(missingColumnNames.toString()).append("\n\n"); } if (missingTypes.size() > 0) { buff.append(Messages.getString("MappingDialog.Error.Message.TypeIssue") + ":\n"); buff.append(missingTypes.toString()).append("\n\n"); } MessageDialog.openError( m_shell, Messages.getString("MappingDialog.Error.Title.IssuesPreventingSaving"), buff.toString()); return null; } return theMapping; }
public void setMapping(Mapping mapping) { if (mapping == null) { return; } m_fieldsView.clearAll(); // do the key first TableItem keyItem = new TableItem(m_fieldsView.table, SWT.NONE); keyItem.setText(1, mapping.getKeyName()); keyItem.setText(2, "Y"); keyItem.setText(5, mapping.getKeyType().toString()); if (mapping.isTupleMapping() && !Const.isEmpty(mapping.getTupleFamilies())) { keyItem.setText(3, mapping.getTupleFamilies()); } // the rest of the fields in the mapping Map<String, HBaseValueMeta> mappedFields = mapping.getMappedColumns(); for (String alias : mappedFields.keySet()) { HBaseValueMeta vm = mappedFields.get(alias); TableItem item = new TableItem(m_fieldsView.table, SWT.NONE); item.setText(1, alias); item.setText(2, "N"); item.setText(3, vm.getColumnFamily()); item.setText(4, vm.getColumnName()); if (vm.isInteger()) { if (vm.getIsLongOrDouble()) { item.setText(5, "Long"); } else { item.setText(5, "Integer"); } } else if (vm.isNumber()) { if (vm.getIsLongOrDouble()) { item.setText(5, "Double"); } else { item.setText(5, "Float"); } } else { item.setText(5, vm.getTypeDesc()); } if (vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_INDEXED) { item.setText(6, HBaseValueMeta.objectIndexValuesToString(vm.getIndex())); } } m_fieldsView.removeEmptyRows(); m_fieldsView.setRowNums(); m_fieldsView.optWidth(true); }