use of org.pentaho.di.trans.steps.metainject.SourceStepField in project pentaho-kettle by pentaho.
the class MetaInjectDialog method processOldMDIDescription.
private void processOldMDIDescription(StepMeta stepMeta, TreeItem stepItem, StepMetaInjectionInterface injection) throws KettleException {
List<StepInjectionMetaEntry> entries = injection.getStepInjectionMetadataEntries();
for (final StepInjectionMetaEntry entry : entries) {
if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
TreeItem entryItem = new TreeItem(stepItem, SWT.NONE);
entryItem.setText(entry.getKey());
entryItem.setText(1, entry.getDescription());
TargetStepAttribute target = new TargetStepAttribute(stepMeta.getName(), entry.getKey(), false);
treeItemTargetMap.put(entryItem, target);
SourceStepField source = targetSourceMapping.get(target);
if (source != null) {
entryItem.setText(2, Const.NVL(source.getStepname(), ""));
entryItem.setText(3, Const.NVL(source.getField(), ""));
}
} else {
// Fields...
//
TreeItem listsItem = new TreeItem(stepItem, SWT.NONE);
listsItem.setText(entry.getKey());
listsItem.setText(1, entry.getDescription());
StepInjectionMetaEntry listEntry = entry.getDetails().get(0);
listsItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
System.out.println(entry.getKey() + " - " + entry.getDescription());
}
});
for (StepInjectionMetaEntry me : listEntry.getDetails()) {
TreeItem treeItem = new TreeItem(listsItem, SWT.NONE);
treeItem.setText(me.getKey());
treeItem.setText(1, me.getDescription());
TargetStepAttribute target = new TargetStepAttribute(stepMeta.getName(), me.getKey(), true);
treeItemTargetMap.put(treeItem, target);
SourceStepField source = targetSourceMapping.get(target);
if (source != null) {
treeItem.setText(2, Const.NVL(source.getStepname(), ""));
treeItem.setText(3, Const.NVL(source.getField(), ""));
}
}
}
}
}
use of org.pentaho.di.trans.steps.metainject.SourceStepField 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 && 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 });
}
}
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.SourceStepField in project pentaho-kettle by pentaho.
the class MetaInjectDialog method processNewMDIDescription.
private void processNewMDIDescription(StepMeta stepMeta, TreeItem stepItem, StepMetaInterface metaInterface) {
BeanInjectionInfo stepInjectionInfo = new BeanInjectionInfo(metaInterface.getClass());
for (BeanInjectionInfo.Group gr : stepInjectionInfo.getGroups()) {
boolean rootGroup = StringUtils.isEmpty(gr.getName());
TreeItem groupItem;
if (!rootGroup) {
groupItem = new TreeItem(stepItem, SWT.NONE);
groupItem.setText(gr.getName());
groupItem.setText(1, gr.getDescription());
} else {
groupItem = null;
}
for (BeanInjectionInfo.Property property : gr.getGroupProperties()) {
TreeItem treeItem = new TreeItem(rootGroup ? stepItem : groupItem, SWT.NONE);
treeItem.setText(property.getName());
treeItem.setText(1, property.getDescription());
TargetStepAttribute target = new TargetStepAttribute(stepMeta.getName(), property.getName(), !rootGroup);
treeItemTargetMap.put(treeItem, target);
SourceStepField source = targetSourceMapping.get(target);
if (source != null) {
treeItem.setText(2, Const.NVL(source.getStepname() == null ? CONST_VALUE : source.getStepname(), ""));
treeItem.setText(3, Const.NVL(source.getField(), ""));
}
}
}
}
use of org.pentaho.di.trans.steps.metainject.SourceStepField 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