use of org.apache.hop.workflow.action.IActionDialog in project hop by apache.
the class HopGuiWorkflowActionDelegate method getActionDialog.
public IActionDialog getActionDialog(IAction action, WorkflowMeta workflowMeta) {
Class<?>[] paramClasses = new Class<?>[] { Shell.class, IAction.class, WorkflowMeta.class, IVariables.class };
Object[] paramArgs = new Object[] { hopGui.getShell(), action, workflowMeta, workflowGraph.getVariables() };
if (MissingAction.ID.equals(action.getPluginId())) {
return new MissingActionDialog(hopGui.getShell(), action, workflowMeta, workflowGraph.getVariables());
}
PluginRegistry registry = PluginRegistry.getInstance();
IPlugin plugin = registry.getPlugin(ActionPluginType.class, action);
String dialogClassName = action.getDialogClassName();
if (dialogClassName == null) {
// optimistic: simply Dialog added to the action class
//
// org.apache.hop.workflow.actions.ActionZipFile
//
// gives
//
// org.apache.hop.workflow.actions.ActionZipFileDialog
//
dialogClassName = action.getClass().getCanonicalName();
dialogClassName += "Dialog";
try {
// Try by injecting ui into the package. Convert:
//
// org.apache.hop.workflow.actions.ActionZipFileDialog
//
// into
//
// org.apache.hop.ui.workflow.actions.ActionZipFileDialog
//
ClassLoader pluginClassLoader = registry.getClassLoader(plugin);
String alternateName = dialogClassName.replaceFirst("\\.hop\\.", ".hop.ui.");
Class clazz = pluginClassLoader.loadClass(alternateName);
dialogClassName = clazz.getName();
} catch (Exception e) {
// do nothing and return the optimistic plugin classname
}
}
try {
Class<IActionDialog> dialogClass = registry.getClass(plugin, dialogClassName);
Constructor<IActionDialog> dialogConstructor = dialogClass.getConstructor(paramClasses);
IActionDialog entryDialogInterface = dialogConstructor.newInstance(paramArgs);
entryDialogInterface.setMetadataProvider(hopGui.getMetadataProvider());
return entryDialogInterface;
} catch (Throwable t) {
t.printStackTrace();
String errorTitle = BaseMessages.getString(PKG, "HopGui.Dialog.ErrorCreatingWorkflowDialog.Title");
String errorMsg = BaseMessages.getString(PKG, "HopGui.Dialog.ErrorCreatingActionDialog.Message", dialogClassName);
hopGui.getLog().logError(errorMsg);
new ErrorDialog(hopGui.getShell(), errorTitle, errorMsg, t);
return null;
}
}
use of org.apache.hop.workflow.action.IActionDialog in project hop by apache.
the class HopGuiWorkflowActionDelegate method editAction.
public void editAction(WorkflowMeta workflowMeta, ActionMeta action) {
try {
hopGui.getLog().logDetailed(BaseMessages.getString(PKG, "HopGui.Log.EditAction", action.getName()));
ActionMeta before = (ActionMeta) action.cloneDeep();
IAction jei = action.getAction();
IActionDialog d = getActionDialog(jei, workflowMeta);
if (d != null) {
if (d.open() != null) {
// First see if the name changed.
// If so, we need to verify that the name is not already used in the workflow.
//
workflowMeta.renameActionIfNameCollides(action);
ActionMeta after = (ActionMeta) action.clone();
hopGui.undoDelegate.addUndoChange(workflowMeta, new ActionMeta[] { before }, new ActionMeta[] { after }, new int[] { workflowMeta.indexOfAction(action) });
}
workflowGraph.updateGui();
} else {
MessageBox mb = new MessageBox(hopGui.getShell(), SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "HopGui.Dialog.ActionCanNotBeChanged.Message"));
mb.setText(BaseMessages.getString(PKG, "HopGui.Dialog.ActionCanNotBeChanged.Title"));
mb.open();
}
} catch (Exception e) {
if (!hopGui.getShell().isDisposed()) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "HopGui.ErrorDialog.ErrorEditingAction.Title"), BaseMessages.getString(PKG, "HopGui.ErrorDialog.ErrorEditingAction.Message"), e);
}
}
}
use of org.apache.hop.workflow.action.IActionDialog in project hop by apache.
the class HopGuiWorkflowActionDelegate method newAction.
public ActionMeta newAction(WorkflowMeta workflowMeta, String pluginId, String pluginName, boolean openIt, Point location) {
PluginRegistry registry = PluginRegistry.getInstance();
IPlugin actionPlugin;
try {
if (pluginId == null) {
actionPlugin = PluginRegistry.getInstance().findPluginWithName(ActionPluginType.class, pluginName);
} else {
actionPlugin = PluginRegistry.getInstance().findPluginWithId(ActionPluginType.class, pluginId);
}
if (actionPlugin != null) {
// Determine name & number for this entry.
// See if the name is already used...
//
String actionName = pluginName;
int nr = 2;
ActionMeta check = workflowMeta.findAction(actionName);
while (check != null) {
actionName = pluginName + " " + nr++;
check = workflowMeta.findAction(actionName);
}
// Generate the appropriate class...
IAction action = (IAction) registry.loadClass(actionPlugin);
action.setPluginId(actionPlugin.getIds()[0]);
action.setName(actionName);
if (action.isStart()) {
// Check if start is already on the canvas...
if (workflowMeta.findStart() != null) {
HopGuiWorkflowGraph.showOnlyStartOnceMessage(hopGui.getShell());
return null;
}
}
if (openIt) {
IActionDialog d = getActionDialog(action, workflowMeta);
if (d != null && d.open() != null) {
ActionMeta actionMeta = new ActionMeta();
actionMeta.setAction(action);
if (location == null) {
location = new Point(50, 50);
}
PropsUi.setLocation(actionMeta, location.x, location.y);
workflowMeta.addAction(actionMeta);
// Verify that the name is not already used in the workflow.
//
workflowMeta.renameActionIfNameCollides(actionMeta);
hopGui.undoDelegate.addUndoNew(workflowMeta, new ActionMeta[] { actionMeta }, new int[] { workflowMeta.indexOfAction(actionMeta) });
workflowGraph.adjustScrolling();
workflowGraph.updateGui();
return actionMeta;
} else {
return null;
}
} else {
ActionMeta actionMeta = new ActionMeta();
actionMeta.setAction(action);
if (location == null) {
location = new Point(50, 50);
}
PropsUi.setLocation(actionMeta, location.x, location.y);
workflowMeta.addAction(actionMeta);
hopGui.undoDelegate.addUndoNew(workflowMeta, new ActionMeta[] { actionMeta }, new int[] { workflowMeta.indexOfAction(actionMeta) });
workflowGraph.adjustScrolling();
workflowGraph.updateGui();
return actionMeta;
}
} else {
return null;
}
} catch (Throwable e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "HopGui.ErrorDialog.UnexpectedErrorCreatingNewJobGraphEntry.Title"), BaseMessages.getString(PKG, "HopGui.ErrorDialog.UnexpectedErrorCreatingNewJobGraphEntry.Message"), new Exception(e));
return null;
}
}
Aggregations