use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class TransGraph method openMapping.
/**
* Open the transformation mentioned in the mapping...
*/
public void openMapping(StepMeta stepMeta, int index) {
try {
Object referencedMeta = null;
Trans subTrans = getActiveSubtransformation(this, stepMeta);
if (subTrans != null && (stepMeta.getStepMetaInterface().getActiveReferencedObjectDescription() == null || index < 0)) {
TransMeta subTransMeta = subTrans.getTransMeta();
referencedMeta = subTransMeta;
Object[] objectArray = new Object[4];
objectArray[0] = stepMeta;
objectArray[1] = subTransMeta;
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.OpenMapping.id, objectArray);
} else {
StepMetaInterface meta = stepMeta.getStepMetaInterface();
if (!Utils.isEmpty(meta.getReferencedObjectDescriptions())) {
referencedMeta = meta.loadReferencedObject(index, spoon.rep, spoon.metaStore, transMeta);
}
}
if (referencedMeta == null) {
return;
}
if (referencedMeta instanceof TransMeta) {
TransMeta mappingMeta = (TransMeta) referencedMeta;
mappingMeta.clearChanged();
spoon.addTransGraph(mappingMeta);
TransGraph subTransGraph = spoon.getActiveTransGraph();
attachActiveTrans(subTransGraph, this.currentStep);
}
if (referencedMeta instanceof JobMeta) {
JobMeta jobMeta = (JobMeta) referencedMeta;
jobMeta.clearChanged();
spoon.addJobGraph(jobMeta);
JobGraph jobGraph = spoon.getActiveJobGraph();
attachActiveJob(jobGraph, this.currentStep);
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TransGraph.Exception.UnableToLoadMapping.Title"), BaseMessages.getString(PKG, "TransGraph.Exception.UnableToLoadMapping.Message"), e);
}
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class TransDialog method get.
// Get the dependencies
private void get() {
Table table = wFields.table;
for (int i = 0; i < transMeta.nrSteps(); i++) {
StepMeta stepMeta = transMeta.getStep(i);
String con = null;
String tab = null;
TableItem item = null;
StepMetaInterface sii = stepMeta.getStepMetaInterface();
if (sii instanceof TableInputMeta) {
TableInputMeta tii = (TableInputMeta) stepMeta.getStepMetaInterface();
if (tii.getDatabaseMeta() == null) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "TransDialog.DatabaseMetaNotSet.Text"));
mb.open();
return;
}
con = tii.getDatabaseMeta().getName();
tab = getTableFromSQL(tii.getSQL());
if (tab == null) {
tab = stepMeta.getName();
}
}
if (sii instanceof DatabaseLookupMeta) {
DatabaseLookupMeta dvli = (DatabaseLookupMeta) stepMeta.getStepMetaInterface();
con = dvli.getDatabaseMeta().getName();
tab = dvli.getTablename();
if (tab == null) {
tab = stepMeta.getName();
}
break;
}
if (tab != null || con != null) {
item = new TableItem(table, SWT.NONE);
if (con != null) {
item.setText(1, con);
}
if (tab != null) {
item.setText(2, tab);
}
}
}
wFields.setRowNums();
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class TransGraph method setMenu.
/**
* This sets the popup-menu on the background of the canvas based on the xy coordinate of the mouse. This method is
* called after a mouse-click.
*
* @param x X-coordinate on screen
* @param y Y-coordinate on screen
*/
private synchronized void setMenu(int x, int y) {
try {
currentMouseX = x;
currentMouseY = y;
final StepMeta stepMeta = transMeta.getStep(x, y, iconsize);
if (stepMeta != null) {
// We clicked on a Step!
setCurrentStep(stepMeta);
XulMenupopup menu = menuMap.get("trans-graph-entry");
try {
ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransStepRightClick.id, new StepMenuExtension(this, menu));
} catch (Exception ex) {
LogChannel.GENERAL.logError("Error calling TransStepRightClick extension point", ex);
}
if (menu != null) {
List<StepMeta> selection = transMeta.getSelectedSteps();
doRightClickSelection(stepMeta, selection);
int sels = selection.size();
Document doc = getXulDomContainer().getDocumentRoot();
// TODO: cache the next line (seems fast enough)?
//
List<PluginInterface> rowDistributionPlugins = PluginRegistry.getInstance().getPlugins(RowDistributionPluginType.class);
JfaceMenupopup customRowDistMenu = (JfaceMenupopup) doc.getElementById("trans-graph-entry-data-movement-popup");
customRowDistMenu.setDisabled(false);
customRowDistMenu.removeChildren();
// Add the default round robin plugin...
//
Action action = new Action("RoundRobinRowDistribution", Action.AS_CHECK_BOX) {
@Override
public void run() {
// default
stepMeta.setRowDistribution(null);
stepMeta.setDistributes(true);
}
};
boolean selected = stepMeta.isDistributes() && stepMeta.getRowDistribution() == null;
action.setChecked(selected);
JfaceMenuitem child = new JfaceMenuitem(null, customRowDistMenu, xulDomContainer, "Round Robin row distribution", 0, action);
child.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.RoundRobin"));
child.setDisabled(false);
child.setSelected(selected);
for (int p = 0; p < rowDistributionPlugins.size(); p++) {
final PluginInterface rowDistributionPlugin = rowDistributionPlugins.get(p);
selected = stepMeta.isDistributes() && stepMeta.getRowDistribution() != null && stepMeta.getRowDistribution().getCode().equals(rowDistributionPlugin.getIds()[0]);
action = new Action(rowDistributionPlugin.getIds()[0], Action.AS_CHECK_BOX) {
@Override
public void run() {
try {
stepMeta.setRowDistribution((RowDistributionInterface) PluginRegistry.getInstance().loadClass(rowDistributionPlugin));
} catch (Exception e) {
LogChannel.GENERAL.logError("Error loading row distribution plugin class: ", e);
}
}
};
action.setChecked(selected);
child = new JfaceMenuitem(null, customRowDistMenu, xulDomContainer, rowDistributionPlugin.getName(), p + 1, action);
child.setLabel(rowDistributionPlugin.getName());
child.setDisabled(false);
child.setSelected(selected);
}
// Add the default copy rows plugin...
//
action = new Action("CopyRowsDistribution", Action.AS_CHECK_BOX) {
@Override
public void run() {
stepMeta.setDistributes(false);
}
};
selected = !stepMeta.isDistributes();
action.setChecked(selected);
child = new JfaceMenuitem(null, customRowDistMenu, xulDomContainer, "Copy rows distribution", 0, action);
child.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.CopyData"));
child.setDisabled(false);
child.setSelected(selected);
JfaceMenupopup launchMenu = (JfaceMenupopup) doc.getElementById("trans-graph-entry-launch-popup");
String[] referencedObjects = stepMeta.getStepMetaInterface().getReferencedObjectDescriptions();
boolean[] enabledObjects = stepMeta.getStepMetaInterface().isReferencedObjectEnabled();
launchMenu.setDisabled(Utils.isEmpty(referencedObjects));
launchMenu.removeChildren();
int childIndex = 0;
// First see if we need to add a special "active" entry (running transformation)
//
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
String activeReferencedObjectDescription = stepMetaInterface.getActiveReferencedObjectDescription();
if (getActiveSubtransformation(this, stepMeta) != null && activeReferencedObjectDescription != null) {
action = new Action(activeReferencedObjectDescription, Action.AS_DROP_DOWN_MENU) {
@Override
public void run() {
// negative by convention
openMapping(stepMeta, -1);
}
};
child = new JfaceMenuitem(null, launchMenu, xulDomContainer, activeReferencedObjectDescription, childIndex++, action);
child.setLabel(activeReferencedObjectDescription);
child.setDisabled(false);
}
if (!Utils.isEmpty(referencedObjects)) {
for (int i = 0; i < referencedObjects.length; i++) {
final int index = i;
String referencedObject = referencedObjects[i];
action = new Action(referencedObject, Action.AS_DROP_DOWN_MENU) {
@Override
public void run() {
openMapping(stepMeta, index);
}
};
child = new JfaceMenuitem(null, launchMenu, xulDomContainer, referencedObject, childIndex++, action);
child.setLabel(referencedObject);
child.setDisabled(!enabledObjects[i]);
}
}
initializeXulMenu(doc, selection, stepMeta);
ConstUI.displayMenu(menu, canvas);
}
} else {
final TransHopMeta hi = findHop(x, y);
if (hi != null) {
// We clicked on a HOP!
XulMenupopup menu = menuMap.get("trans-graph-hop");
if (menu != null) {
setCurrentHop(hi);
XulMenuitem item = (XulMenuitem) getXulDomContainer().getDocumentRoot().getElementById("trans-graph-hop-enabled");
if (item != null) {
if (hi.isEnabled()) {
item.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.DisableHop"));
} else {
item.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.EnableHop"));
}
}
ConstUI.displayMenu(menu, canvas);
}
} else {
// Clicked on the background: maybe we hit a note?
final NotePadMeta ni = transMeta.getNote(x, y);
setCurrentNote(ni);
if (ni != null) {
XulMenupopup menu = menuMap.get("trans-graph-note");
if (menu != null) {
ConstUI.displayMenu(menu, canvas);
}
} else {
XulMenupopup menu = menuMap.get("trans-graph-background");
if (menu != null) {
final String clipcontent = spoon.fromClipboard();
XulMenuitem item = (XulMenuitem) getXulDomContainer().getDocumentRoot().getElementById("trans-graph-background-paste");
if (item != null) {
item.setDisabled(clipcontent == null);
}
ConstUI.displayMenu(menu, canvas);
}
}
}
}
} catch (Throwable t) {
// TODO: fix this: log somehow, is IGNORED for now.
t.printStackTrace();
}
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class LucidDBStreamingLoaderDialog method getFields.
/**
* Description: When click button called get Field, return all fields in table
*
* @param tabName
*/
private void getFields(String tabName) {
TableView myTb;
// disable update field when select insert
boolean flag = false;
if (tabName.equals(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.KeyTab.TabTitle"))) {
myTb = wKeysTb;
} else if (tabName.equals(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.FieldsTab.TabTitle"))) {
myTb = wFieldsTb;
if (BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item2").equalsIgnoreCase(wOperation.getItem(wOperation.getSelectionIndex()))) {
flag = true;
}
} else {
return;
}
RowMetaInterface streamMeta;
try {
streamMeta = transMeta.getPrevStepFields(stepMeta);
String[] fieldNamesOfStream = streamMeta.getFieldNames();
input.setSchemaName(wSchema.getText());
input.setTableName(wTable.getText());
input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
RowMetaInterface tblMeta = null;
String[] fieldsNamesOfTbl = null;
try {
tblMeta = stepMetaInterface.getRequiredFields(transMeta);
fieldsNamesOfTbl = tblMeta.getFieldNames();
} catch (KettleException ke) {
// Ignore errors
}
int count = 0;
if (fieldsNamesOfTbl == null) {
count = fieldNamesOfStream.length;
myTb.table.setItemCount(count);
for (int i = 0; i < count; i++) {
TableItem item = myTb.table.getItem(i);
item.setText(1, fieldNamesOfStream[i]);
item.setText(2, fieldNamesOfStream[i]);
}
} else {
count = ((fieldNamesOfStream.length >= fieldsNamesOfTbl.length) ? fieldNamesOfStream.length : fieldsNamesOfTbl.length);
myTb.table.setItemCount(count);
for (int i = 0; i < count; i++) {
TableItem item = myTb.table.getItem(i);
if (i < (fieldsNamesOfTbl.length)) {
if (fieldsNamesOfTbl[i] != null) {
item.setText(1, fieldsNamesOfTbl[i]);
}
}
if (i < fieldNamesOfStream.length) {
if (fieldNamesOfStream[i] != null) {
item.setText(2, fieldNamesOfStream[i]);
}
}
}
}
myTb.setRowNums();
myTb.optWidth(true);
if (flag) {
myTb.table.getColumn(3).setWidth(0);
System.out.println(myTb.table.getColumn(3).getWidth());
}
} catch (KettleStepException e) {
// Ignore errors
}
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class LucidDBStreamingLoaderDialog method generateMappings.
/**
* Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
* information. After the user did the mapping, those information is put into the Select/Rename table.
*/
private void generateMappings(String tabName) {
TableView myTb;
boolean flag = false;
if (tabName.equals(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.KeyTab.TabTitle"))) {
myTb = wKeysTb;
} else if (tabName.equals(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.FieldsTab.TabTitle"))) {
myTb = wFieldsTb;
// Hidden Update Field when select operation INSERT
if (BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item2").equalsIgnoreCase(wOperation.getItem(wOperation.getSelectionIndex()))) {
flag = true;
}
} else {
return;
}
// Determine the source and target fields...
//
RowMetaInterface sourceFields;
RowMetaInterface targetFields;
try {
sourceFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
// refresh data
input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
input.setTableName(transMeta.environmentSubstitute(wTable.getText()));
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
try {
targetFields = stepMetaInterface.getRequiredFields(transMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
ValueMetaInterface value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuffer missingSourceFields = new StringBuffer();
StringBuffer missingTargetFields = new StringBuffer();
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(LucidDBStreamingLoaderDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
myTb.table.removeAll();
myTb.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = myTb.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
myTb.setRowNums();
myTb.optWidth(true);
// Hidden Update Field when select INSERT.
int width = myTb.table.getColumn(3).getWidth();
if (flag) {
myTb.table.getColumn(3).setWidth(0);
} else {
myTb.table.getColumn(3).setWidth(width);
}
}
}
Aggregations