use of org.pentaho.di.trans.steps.metainject.TargetStepAttribute in project pentaho-kettle by pentaho.
the class MetaInjectDialog method addInjectTab.
private void addInjectTab() {
// ////////////////////////
// START OF INJECT TAB ///
// ////////////////////////
wInjectTab = new CTabItem(wTabFolder, SWT.NONE);
wInjectTab.setText(BaseMessages.getString(PKG, "MetaInjectDialog.InjectTab.TabTitle"));
wInjectSComp = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
wInjectSComp.setLayout(new FillLayout());
wInjectComp = new Composite(wInjectSComp, SWT.NONE);
props.setLook(wInjectComp);
FormLayout fileLayout = new FormLayout();
fileLayout.marginWidth = 15;
fileLayout.marginHeight = 15;
wInjectComp.setLayout(fileLayout);
wTree = new Tree(wInjectComp, SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
FormData fdTree = new FormData();
fdTree.left = new FormAttachment(0, 0);
fdTree.top = new FormAttachment(0, 0);
fdTree.right = new FormAttachment(100, 0);
fdTree.bottom = new FormAttachment(100, 0);
wTree.setLayoutData(fdTree);
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.TargetStep"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.TargetDescription"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.SourceStep"), ColumnInfo.COLUMN_TYPE_CCOMBO, false, true), new ColumnInfo(BaseMessages.getString(PKG, "MetaInjectDialog.Column.SourceField"), ColumnInfo.COLUMN_TYPE_CCOMBO, false, true) };
wTree.setHeaderVisible(true);
for (int i = 0; i < colinf.length; i++) {
ColumnInfo columnInfo = colinf[i];
TreeColumn treeColumn = new TreeColumn(wTree, columnInfo.getAllignement());
treeColumn.setText(columnInfo.getName());
treeColumn.setWidth(200);
}
wTree.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
try {
Point point = new Point(event.x, event.y);
TreeItem item = wTree.getItem(point);
if (item != null) {
TargetStepAttribute target = treeItemTargetMap.get(item);
if (target != null) {
SourceStepField source = targetSourceMapping.get(target);
String[] prevStepNames = transMeta.getPrevStepNames(stepMeta);
Arrays.sort(prevStepNames);
Map<String, SourceStepField> fieldMap = new HashMap<>();
for (String prevStepName : prevStepNames) {
RowMetaInterface fields = transMeta.getStepFields(prevStepName);
for (ValueMetaInterface field : fields.getValueMetaList()) {
String key = buildStepFieldKey(prevStepName, field.getName());
fieldMap.put(key, new SourceStepField(prevStepName, field.getName()));
}
}
String[] sourceFields = fieldMap.keySet().toArray(new String[fieldMap.size()]);
Arrays.sort(sourceFields);
String constant = source != null && source.getStepname() == null ? source.getField() : "";
EnterSelectionDialog selectSourceField = new EnterSelectionDialog(shell, sourceFields, BaseMessages.getString(PKG, "MetaInjectDialog.SourceFieldDialog.Title"), BaseMessages.getString(PKG, "MetaInjectDialog.SourceFieldDialog.Label"), constant, transMeta);
if (source != null) {
if (source.getStepname() != null && !Utils.isEmpty(source.getStepname())) {
String key = buildStepFieldKey(source.getStepname(), source.getField());
selectSourceField.setCurrentValue(key);
int index = Const.indexOfString(key, sourceFields);
if (index >= 0) {
selectSourceField.setSelectedNrs(new int[] { index });
}
} else {
selectSourceField.setCurrentValue(source.getField());
}
}
String selectedStepField = selectSourceField.open();
if (selectedStepField != null) {
SourceStepField newSource = fieldMap.get(selectedStepField);
if (newSource == null) {
newSource = new SourceStepField(null, selectedStepField);
item.setText(2, CONST_VALUE);
item.setText(3, selectedStepField);
} else {
item.setText(2, newSource.getStepname());
item.setText(3, newSource.getField());
}
targetSourceMapping.put(target, newSource);
} else {
item.setText(2, "");
item.setText(3, "");
targetSourceMapping.remove(target);
}
/*
* EnterSelectionDialog selectStep = new EnterSelectionDialog(shell, prevStepNames, "Select source step",
* "Select the source step"); if (source!=null && !Utils.isEmpty(source.getStepname())) { int index =
* Const.indexOfString(source.getStepname(), prevStepNames); if (index>=0) { selectStep.setSelectedNrs(new
* int[] {index,}); } } String prevStep = selectStep.open(); if (prevStep!=null) { // OK, now we list the
* fields from that step... // RowMetaInterface fields = transMeta.getStepFields(prevStep); String[]
* fieldNames = fields.getFieldNames(); Arrays.sort(fieldNames); EnterSelectionDialog selectField = new
* EnterSelectionDialog(shell, fieldNames, "Select field", "Select the source field"); if (source!=null &&
* !Utils.isEmpty(source.getField())) { int index = Const.indexOfString(source.getField(), fieldNames); if
* (index>=0) { selectField.setSelectedNrs(new int[] {index,}); } } String fieldName = selectField.open();
* if (fieldName!=null) { // Store the selection, update the UI... // item.setText(2, prevStep);
* item.setText(3, fieldName); source = new SourceStepField(prevStep, fieldName);
* targetSourceMapping.put(target, source); } } else { item.setText(2, ""); item.setText(3, "");
* targetSourceMapping.remove(target); }
*/
}
}
} catch (Exception e) {
new ErrorDialog(shell, "Oops", "Unexpected Error", e);
}
}
});
FormData fdInjectComp = new FormData();
fdInjectComp.left = new FormAttachment(0, 0);
fdInjectComp.top = new FormAttachment(0, 0);
fdInjectComp.right = new FormAttachment(100, 0);
fdInjectComp.bottom = new FormAttachment(100, 0);
wInjectComp.setLayoutData(fdInjectComp);
wInjectComp.pack();
Rectangle bounds = wInjectComp.getBounds();
wInjectSComp.setContent(wInjectComp);
wInjectSComp.setExpandHorizontal(true);
wInjectSComp.setExpandVertical(true);
wInjectSComp.setMinWidth(bounds.width);
wInjectSComp.setMinHeight(bounds.height);
wInjectTab.setControl(wInjectSComp);
// ///////////////////////////////////////////////////////////
// / END OF INJECT TAB
// ///////////////////////////////////////////////////////////
}
use of org.pentaho.di.trans.steps.metainject.TargetStepAttribute in project pentaho-kettle by pentaho.
the class TransMetaTest method testTransListeners.
@Test
public void testTransListeners() {
TransMeta TransMeta = new TransMeta();
StepMeta oldFormStep = new StepMeta();
oldFormStep.setName("Generate_1");
StepMeta newFormStep = new StepMeta();
newFormStep.setName("Generate_2");
StepMeta toStep = new StepMeta();
toStep.setStepMetaInterface(new MetaInjectMeta());
toStep.setName("ETL Inject Metadata");
StepMeta deletedStep = new StepMeta();
deletedStep.setStepMetaInterface(new MetaInjectMeta());
deletedStep.setName("ETL Inject Metadata for delete");
// Verify add & remove listeners
TransMeta.addStep(oldFormStep);
TransMeta.addStep(toStep);
TransMeta.addStep(deletedStep);
assertEquals(TransMeta.nrStepChangeListeners(), 2);
TransMeta.removeStepChangeListener((StepMetaChangeListenerInterface) deletedStep.getStepMetaInterface());
assertEquals(TransMeta.nrStepChangeListeners(), 1);
TransMeta.removeStep(2);
TransHopMeta hi = new TransHopMeta(oldFormStep, toStep);
TransMeta.addTransHop(hi);
// Verify MetaInjectMeta.onStepChange()
// add new TargetStepAttribute
MetaInjectMeta toMeta = (MetaInjectMeta) toStep.getStepMetaInterface();
Map<TargetStepAttribute, SourceStepField> sourceMapping = new HashMap<TargetStepAttribute, SourceStepField>();
TargetStepAttribute keyTest = new TargetStepAttribute("File", "key", true);
SourceStepField valueTest = new SourceStepField(oldFormStep.getName(), oldFormStep.getName());
sourceMapping.put(keyTest, valueTest);
toMeta.setTargetSourceMapping(sourceMapping);
// Run all listeners
TransMeta.notifyAllListeners(oldFormStep, newFormStep);
// Verify changes, which listeners makes
sourceMapping = toMeta.getTargetSourceMapping();
for (Entry<TargetStepAttribute, SourceStepField> entry : sourceMapping.entrySet()) {
SourceStepField value = entry.getValue();
if (!value.getStepname().equals(newFormStep.getName())) {
fail();
}
}
// verify another functions
TransMeta.addStep(deletedStep);
assertEquals(TransMeta.nrSteps(), 3);
assertEquals(TransMeta.nrStepChangeListeners(), 2);
TransMeta.removeStep(0);
assertEquals(TransMeta.nrSteps(), 2);
}
Aggregations