use of org.pentaho.di.trans.step.StepDialogInterface in project pentaho-kettle by pentaho.
the class Spoon method newStep.
/**
* Allocate new step, optionally open and rename it.
*
* @param id
* Id of the new step
* @param name
* Name of the new step
* @param description
* Description of the type of step
* @param openit
* Open the dialog for this step?
* @param rename
* Rename this step?
*
* @return The newly created StepMeta object.
*/
public StepMeta newStep(TransMeta transMeta, String id, String name, String description, boolean openit, boolean rename) {
StepMeta inf = null;
// See if we need to rename the step to avoid doubles!
if (rename && transMeta.findStep(name) != null) {
int i = 2;
String newName = name + " " + i;
while (transMeta.findStep(newName) != null) {
i++;
newName = name + " " + i;
}
name = newName;
}
PluginRegistry registry = PluginRegistry.getInstance();
PluginInterface stepPlugin = id != null ? registry.findPluginWithId(StepPluginType.class, id) : registry.findPluginWithName(StepPluginType.class, description);
try {
if (stepPlugin != null) {
StepMetaInterface info = (StepMetaInterface) registry.loadClass(stepPlugin);
info.setDefault();
if (openit) {
StepDialogInterface dialog = this.getStepEntryDialog(info, transMeta, name);
if (dialog != null) {
name = dialog.open();
}
}
inf = new StepMeta(stepPlugin.getIds()[0], name, info);
if (name != null) {
// OK pressed in the dialog: we have a step-name
String newName = name;
StepMeta stepMeta = transMeta.findStep(newName);
int nr = 2;
while (stepMeta != null) {
newName = name + " " + nr;
stepMeta = transMeta.findStep(newName);
nr++;
}
if (nr > 2) {
inf.setName(newName);
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
// "This stepName already exists. Spoon changed the stepName to ["+newName+"]"
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.ChangeStepname.Message", newName));
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.ChangeStepname.Title"));
mb.open();
}
// default location at (20,20)
inf.setLocation(20, 20);
transMeta.addStep(inf);
addUndoNew(transMeta, new StepMeta[] { inf }, new int[] { transMeta.indexOfStep(inf) });
// Also store it in the pluginHistory list...
props.increasePluginHistory(stepPlugin.getIds()[0]);
// stepHistoryChanged = true;
refreshTree();
} else {
// Cancel pressed in dialog.
return null;
}
setShellText();
}
} catch (KettleException e) {
String filename = stepPlugin.getErrorHelpFile();
if (!Utils.isEmpty(filename)) {
// OK, in stead of a normal error message, we give back the
// content of the error help file... (HTML)
FileInputStream fis = null;
try {
StringBuilder content = new StringBuilder();
fis = new FileInputStream(new File(filename));
int ch = fis.read();
while (ch >= 0) {
content.append((char) ch);
ch = fis.read();
}
ShowBrowserDialog sbd = new ShowBrowserDialog(// "Error help text"
shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorHelpText.Title"), content.toString());
sbd.open();
} catch (Exception ex) {
new ErrorDialog(shell, // "Error showing help text"
BaseMessages.getString(PKG, "Spoon.Dialog.ErrorShowingHelpText.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorShowingHelpText.Message"), ex);
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception ex) {
log.logError("Error closing plugin help file", ex);
}
}
}
} else {
new ErrorDialog(shell, // "I was unable to create a new step"
BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Message"), e);
}
return null;
} catch (Throwable e) {
if (!shell.isDisposed()) {
new ErrorDialog(shell, // "Error creating step"
BaseMessages.getString(PKG, "Spoon.Dialog.ErrorCreatingStep.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Message"), e);
}
return null;
}
return inf;
}
use of org.pentaho.di.trans.step.StepDialogInterface in project pentaho-kettle by pentaho.
the class SpoonStepsDelegate method getStepDialog.
public StepDialogInterface getStepDialog(StepMetaInterface stepMeta, TransMeta transMeta, String stepName) throws KettleException {
Class<?>[] paramClasses = new Class<?>[] { Shell.class, Object.class, TransMeta.class, String.class };
Object[] paramArgs = new Object[] { spoon.getShell(), stepMeta, transMeta, stepName };
PluginRegistry registry = PluginRegistry.getInstance();
PluginInterface plugin = registry.getPlugin(StepPluginType.class, stepMeta);
String dialogClassName = plugin.getClassMap().get(StepDialogInterface.class);
if (dialogClassName == null) {
// try the deprecated way
log.logDebug("Use of StepMetaInterface#getDialogClassName is deprecated, use PluginDialog annotation instead.");
dialogClassName = stepMeta.getDialogClassName();
}
try {
Class<StepDialogInterface> dialogClass = registry.getClass(plugin, dialogClassName);
Constructor<StepDialogInterface> dialogConstructor = dialogClass.getConstructor(paramClasses);
return dialogConstructor.newInstance(paramArgs);
} catch (Exception e) {
// try the old way for compatibility
try {
Class<?>[] sig = new Class<?>[] { Shell.class, StepMetaInterface.class, TransMeta.class, String.class };
Method method = stepMeta.getClass().getDeclaredMethod("getDialog", sig);
if (method != null) {
log.logDebug("Use of StepMetaInterface#getDialog is deprecated, use PluginDialog annotation instead.");
return (StepDialogInterface) method.invoke(stepMeta, paramArgs);
}
} catch (Throwable ignored) {
}
String errorTitle = BaseMessages.getString(PKG, "Spoon.Dialog.ErrorCreatingStepDialog.Title");
String errorMsg = BaseMessages.getString(PKG, "Spoon.Dialog.ErrorCreatingStepDialog.Message", dialogClassName);
new ErrorDialog(spoon.getShell(), errorTitle, errorMsg, e);
throw new KettleException(e);
}
}
use of org.pentaho.di.trans.step.StepDialogInterface in project pentaho-kettle by pentaho.
the class SpoonStepsDelegate method editStep.
public String editStep(TransMeta transMeta, StepMeta stepMeta) {
boolean refresh = false;
String stepname = null;
try {
String name = stepMeta.getName();
// Before we do anything, let's store the situation the way it
// was...
//
StepMeta before = (StepMeta) stepMeta.clone();
StepDialogInterface dialog = spoon.getStepEntryDialog(stepMeta.getStepMetaInterface(), transMeta, name);
if (dialog != null) {
dialog.setRepository(spoon.getRepository());
dialog.setMetaStore(spoon.getMetaStore());
stepname = dialog.open();
}
if (!Utils.isEmpty(stepname)) {
// Force the recreation of the step IO metadata object. (cached by default)
//
stepMeta.getStepMetaInterface().resetStepIoMeta();
//
// See if the new name the user enter, doesn't collide with
// another step.
// If so, change the stepname and warn the user!
//
String newname = stepname;
StepMeta smeta = transMeta.findStep(newname, stepMeta);
int nr = 2;
while (smeta != null) {
newname = stepname + " " + nr;
smeta = transMeta.findStep(newname);
nr++;
}
if (nr > 2) {
stepname = newname;
MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.StepnameExists.Message", stepname));
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.StepnameExists.Title"));
mb.open();
}
if (!stepname.equals(name)) {
refresh = true;
}
StepMeta newStepMeta = (StepMeta) stepMeta.clone();
newStepMeta.setName(stepname);
transMeta.clearCaches();
transMeta.notifyAllListeners(stepMeta, newStepMeta);
stepMeta.setName(stepname);
//
// OK, so the step has changed...
// Backup the situation for undo/redo
//
StepMeta after = (StepMeta) stepMeta.clone();
spoon.addUndoChange(transMeta, new StepMeta[] { before }, new StepMeta[] { after }, new int[] { transMeta.indexOfStep(stepMeta) });
} else {
// Perhaps new connections were created in the step dialog?
if (transMeta.haveConnectionsChanged()) {
refresh = true;
}
}
// name is displayed on the graph too.
spoon.refreshGraph();
// TODO: verify "double pathway" steps for bug #4365
// After the step was edited we can complain about the possible
// deadlock here.
//
} catch (Throwable e) {
if (spoon.getShell().isDisposed()) {
return null;
}
new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.UnableOpenDialog.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnableOpenDialog.Message"), e);
}
if (refresh) {
// Perhaps new connections were created in
spoon.refreshTree();
// the step
// dialog or the step name changed.
}
return stepname;
}
use of org.pentaho.di.trans.step.StepDialogInterface in project pentaho-kettle by pentaho.
the class SpoonStepsDelegate method getPartitionerDialog.
public StepDialogInterface getPartitionerDialog(StepMeta stepMeta, StepPartitioningMeta partitioningMeta, TransMeta transMeta) throws KettleException {
Partitioner partitioner = partitioningMeta.getPartitioner();
String dialogClassName = partitioner.getDialogClassName();
Class<?> dialogClass;
Class<?>[] paramClasses = new Class<?>[] { Shell.class, StepMeta.class, StepPartitioningMeta.class, TransMeta.class };
Object[] paramArgs = new Object[] { spoon.getShell(), stepMeta, partitioningMeta, transMeta };
Constructor<?> dialogConstructor;
try {
dialogClass = partitioner.getClass().getClassLoader().loadClass(dialogClassName);
dialogConstructor = dialogClass.getConstructor(paramClasses);
return (StepDialogInterface) dialogConstructor.newInstance(paramArgs);
} catch (Exception e) {
// try the old way for compatibility
Method method;
try {
Class<?>[] sig = new Class<?>[] { Shell.class, StepMetaInterface.class, TransMeta.class };
method = stepMeta.getClass().getDeclaredMethod("getDialog", sig);
if (method != null) {
return (StepDialogInterface) method.invoke(stepMeta, new Object[] { spoon.getShell(), stepMeta, transMeta });
}
} catch (Throwable ignored) {
}
throw new KettleException(e);
}
}
use of org.pentaho.di.trans.step.StepDialogInterface in project pentaho-kettle by pentaho.
the class SpecialMethodProcessor method askForField.
private void askForField(PartitionSettings settings, SpoonDelegates delegates) throws KettleException {
StepDialogInterface partitionDialog = delegates.steps.getPartitionerDialog(settings.getStepMeta(), settings.getStepMeta().getStepPartitioningMeta(), settings.getTransMeta());
String fieldName = partitionDialog.open();
if (StringUtil.isEmpty(fieldName)) {
settings.rollback(settings.getBefore());
}
}
Aggregations