use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class TransGraph method findHop.
/**
* See if location (x,y) is on a line between two steps: the hop!
*
* @param x
* @param y
* @param exclude the step to exclude from the hops (from or to location). Specify null if no step is to be excluded.
* @return the transformation hop on the specified location, otherwise: null
*/
private TransHopMeta findHop(int x, int y, StepMeta exclude) {
int i;
TransHopMeta online = null;
for (i = 0; i < transMeta.nrTransHops(); i++) {
TransHopMeta hi = transMeta.getTransHop(i);
StepMeta fs = hi.getFromStep();
StepMeta ts = hi.getToStep();
if (fs == null || ts == null) {
return null;
}
//
if (exclude != null && (exclude.equals(fs) || exclude.equals(ts))) {
continue;
}
int[] line = getLine(fs, ts);
if (pointOnLine(x, y, line)) {
online = hi;
}
}
return online;
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class TransGraph method mouseDown.
@Override
public void mouseDown(MouseEvent e) {
boolean alt = (e.stateMask & SWT.ALT) != 0;
boolean control = (e.stateMask & SWT.MOD1) != 0;
boolean shift = (e.stateMask & SWT.SHIFT) != 0;
lastButton = e.button;
Point real = screen2real(e.x, e.y);
lastclick = new Point(real.x, real.y);
// Hide the tooltip!
hideToolTips();
// Set the pop-up menu
if (e.button == 3) {
setMenu(real.x, real.y);
return;
}
try {
ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransGraphMouseDown.id, new TransGraphExtension(this, e, real));
} catch (Exception ex) {
LogChannel.GENERAL.logError("Error calling TransGraphMouseDown extension point", ex);
}
//
if (e.button == 1 || e.button == 2) {
AreaOwner areaOwner = getVisibleAreaOwner(real.x, real.y);
if (areaOwner != null && areaOwner.getAreaType() != null) {
switch(areaOwner.getAreaType()) {
case STEP_OUTPUT_HOP_ICON:
// Click on the output icon means: start of drag
// Action: We show the input icons on the other steps...
//
selectedStep = null;
startHopStep = (StepMeta) areaOwner.getParent();
candidateHopType = null;
startErrorHopStep = false;
// stopStepMouseOverDelayTimer(startHopStep);
break;
case STEP_INPUT_HOP_ICON:
// Click on the input icon means: start to a new hop
// In this case, we set the end hop step...
//
selectedStep = null;
startHopStep = null;
endHopStep = (StepMeta) areaOwner.getParent();
candidateHopType = null;
startErrorHopStep = false;
// stopStepMouseOverDelayTimer(endHopStep);
break;
case HOP_ERROR_ICON:
// Click on the error icon means: Edit error handling
//
StepMeta stepMeta = (StepMeta) areaOwner.getParent();
spoon.editStepErrorHandling(transMeta, stepMeta);
break;
case STEP_TARGET_HOP_ICON_OPTION:
// Below, see showStepTargetOptions()
break;
case STEP_EDIT_ICON:
clearSettings();
currentStep = (StepMeta) areaOwner.getParent();
stopStepMouseOverDelayTimer(currentStep);
editStep();
break;
case STEP_INJECT_ICON:
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "TransGraph.StepInjectionSupported.Tooltip"));
mb.setText(BaseMessages.getString(PKG, "TransGraph.StepInjectionSupported.Title"));
mb.open();
break;
case STEP_MENU_ICON:
clearSettings();
stepMeta = (StepMeta) areaOwner.getParent();
setMenu(stepMeta.getLocation().x, stepMeta.getLocation().y);
break;
case STEP_ICON:
stepMeta = (StepMeta) areaOwner.getOwner();
currentStep = stepMeta;
for (StepSelectionListener listener : currentStepListeners) {
listener.onUpdateSelection(currentStep);
}
if (candidate != null) {
addCandidateAsHop(e.x, e.y);
} else {
if (transPreviewDelegate.isActive()) {
transPreviewDelegate.setSelectedStep(currentStep);
for (SelectedStepListener stepListener : stepListeners) {
if (this.extraViewComposite != null && !this.extraViewComposite.isDisposed()) {
stepListener.onSelect(currentStep);
}
}
transPreviewDelegate.refreshView();
}
}
//
if (e.button == 1 && alt && stepMeta.supportsErrorHandling()) {
spoon.editStepErrorHandling(transMeta, stepMeta);
return;
} else if (e.button == 2 || (e.button == 1 && shift)) {
// SHIFT CLICK is start of drag to create a new hop
//
startHopStep = stepMeta;
} else {
selectedSteps = transMeta.getSelectedSteps();
selectedStep = stepMeta;
//
// When an icon is moved that is not selected, it gets
// selected too late.
// It is not captured here, but in the mouseMoveListener...
//
previous_step_locations = transMeta.getSelectedStepLocations();
Point p = stepMeta.getLocation();
iconoffset = new Point(real.x - p.x, real.y - p.y);
}
redraw();
break;
case NOTE:
ni = (NotePadMeta) areaOwner.getOwner();
selectedNotes = transMeta.getSelectedNotes();
selectedNote = ni;
Point loc = ni.getLocation();
previous_note_locations = transMeta.getSelectedNoteLocations();
noteoffset = new Point(real.x - loc.x, real.y - loc.y);
redraw();
break;
case STEP_COPIES_TEXT:
copies((StepMeta) areaOwner.getOwner());
break;
case STEP_DATA_SERVICE:
editProperties(transMeta, spoon, spoon.getRepository(), true, TransDialog.Tabs.EXTRA_TAB);
break;
default:
break;
}
} else {
// A hop? --> enable/disable
//
TransHopMeta hop = findHop(real.x, real.y);
if (hop != null) {
TransHopMeta before = (TransHopMeta) hop.clone();
setHopEnabled(hop, !hop.isEnabled());
if (hop.isEnabled() && transMeta.hasLoop(hop.getToStep())) {
setHopEnabled(hop, false);
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "TransGraph.Dialog.HopCausesLoop.Message"));
mb.setText(BaseMessages.getString(PKG, "TransGraph.Dialog.HopCausesLoop.Title"));
mb.open();
}
TransHopMeta after = (TransHopMeta) hop.clone();
spoon.addUndoChange(transMeta, new TransHopMeta[] { before }, new TransHopMeta[] { after }, new int[] { transMeta.indexOfTransHop(hop) });
redraw();
spoon.setShellText();
} else {
// No area-owner & no hop means : background click:
//
startHopStep = null;
if (!control) {
selectionRegion = new org.pentaho.di.core.gui.Rectangle(real.x, real.y, 0, 0);
}
redraw();
}
}
}
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class TransGraph method addStepToChain.
public void addStepToChain(PluginInterface stepPlugin, boolean shift) {
TransMeta transMeta = spoon.getActiveTransformation();
if (transMeta == null) {
return;
}
//
if (lastChained != null && transMeta.findStep(lastChained.getName()) == null) {
lastChained = null;
}
// If there is exactly one selected step, pick that one as last chained.
//
List<StepMeta> sel = transMeta.getSelectedSteps();
if (sel.size() == 1) {
lastChained = sel.get(0);
}
// Where do we add this?
Point p = null;
if (lastChained == null) {
p = transMeta.getMaximum();
p.x -= 100;
} else {
p = new Point(lastChained.getLocation().x, lastChained.getLocation().y);
}
p.x += 200;
// Which is the new step?
StepMeta newStep = spoon.newStep(transMeta, stepPlugin.getIds()[0], stepPlugin.getName(), stepPlugin.getName(), false, true);
if (newStep == null) {
return;
}
newStep.setLocation(p.x, p.y);
newStep.setDraw(true);
if (lastChained != null) {
TransHopMeta hop = new TransHopMeta(lastChained, newStep);
spoon.newHop(transMeta, hop);
}
lastChained = newStep;
spoon.refreshGraph();
spoon.refreshTree();
if (shift) {
editStep(newStep);
}
transMeta.unselectAll();
newStep.setSelected(true);
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class TransGraph method splitHop.
private void splitHop(TransHopMeta hi) {
int id = 0;
if (!spoon.props.getAutoSplit()) {
MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "TransGraph.Dialog.SplitHop.Title"), null, BaseMessages.getString(PKG, "TransGraph.Dialog.SplitHop.Message") + Const.CR + hi.toString(), MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 0, BaseMessages.getString(PKG, "TransGraph.Dialog.Option.SplitHop.DoNotAskAgain"), spoon.props.getAutoSplit());
MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
id = md.open();
spoon.props.setAutoSplit(md.getToggleState());
}
if ((id & 0xFF) == 0) {
// Means: "Yes" button clicked!
// Only split A-->--B by putting C in between IF...
// C-->--A or B-->--C don't exists...
// A ==> hi.getFromStep()
// B ==> hi.getToStep();
// C ==> selected_step
//
boolean caExists = transMeta.findTransHop(selectedStep, hi.getFromStep()) != null;
boolean bcExists = transMeta.findTransHop(hi.getToStep(), selectedStep) != null;
if (!caExists && !bcExists) {
StepMeta fromStep = hi.getFromStep();
StepMeta toStep = hi.getToStep();
// In case step A targets B then we now need to target C
//
StepIOMetaInterface fromIo = fromStep.getStepMetaInterface().getStepIOMeta();
for (StreamInterface stream : fromIo.getTargetStreams()) {
if (stream.getStepMeta() != null && stream.getStepMeta().equals(toStep)) {
// This target stream was directed to B, now we need to direct it to C
stream.setStepMeta(selectedStep);
fromStep.getStepMetaInterface().handleStreamSelection(stream);
}
}
// In case step B sources from A then we now need to source from C
//
StepIOMetaInterface toIo = toStep.getStepMetaInterface().getStepIOMeta();
for (StreamInterface stream : toIo.getInfoStreams()) {
if (stream.getStepMeta() != null && stream.getStepMeta().equals(fromStep)) {
// This info stream was reading from B, now we need to direct it to C
stream.setStepMeta(selectedStep);
toStep.getStepMetaInterface().handleStreamSelection(stream);
}
}
// In case there is error handling on A, we want to make it point to C now
//
StepErrorMeta errorMeta = fromStep.getStepErrorMeta();
if (fromStep.isDoingErrorHandling() && toStep.equals(errorMeta.getTargetStep())) {
errorMeta.setTargetStep(selectedStep);
}
TransHopMeta newhop1 = new TransHopMeta(hi.getFromStep(), selectedStep);
if (transMeta.findTransHop(newhop1) == null) {
transMeta.addTransHop(newhop1);
spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop1 }, new int[] { transMeta.indexOfTransHop(newhop1) }, true);
}
TransHopMeta newhop2 = new TransHopMeta(selectedStep, hi.getToStep());
if (transMeta.findTransHop(newhop2) == null) {
transMeta.addTransHop(newhop2);
spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop2 }, new int[] { transMeta.indexOfTransHop(newhop2) }, true);
}
int idx = transMeta.indexOfTransHop(hi);
spoon.addUndoDelete(transMeta, new TransHopMeta[] { hi }, new int[] { idx }, true);
transMeta.removeTransHop(idx);
spoon.refreshTree();
}
// else: Silently discard this hop-split attempt.
}
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class TransGraph method setToolTip.
private AreaOwner setToolTip(int x, int y, int screenX, int screenY) {
AreaOwner subject = null;
if (!spoon.getProperties().showToolTips()) {
return subject;
}
canvas.setToolTipText(null);
String newTip = null;
Image tipImage = null;
final TransHopMeta hi = findHop(x, y);
// check the area owner list...
//
StringBuilder tip = new StringBuilder();
AreaOwner areaOwner = getVisibleAreaOwner(x, y);
if (areaOwner != null && areaOwner.getAreaType() != null) {
switch(areaOwner.getAreaType()) {
case REMOTE_INPUT_STEP:
StepMeta step = (StepMeta) areaOwner.getParent();
tip.append("Remote input steps:").append(Const.CR).append("-----------------------").append(Const.CR);
for (RemoteStep remoteStep : step.getRemoteInputSteps()) {
tip.append(remoteStep.toString()).append(Const.CR);
}
break;
case REMOTE_OUTPUT_STEP:
step = (StepMeta) areaOwner.getParent();
tip.append("Remote output steps:").append(Const.CR).append("-----------------------").append(Const.CR);
for (RemoteStep remoteStep : step.getRemoteOutputSteps()) {
tip.append(remoteStep.toString()).append(Const.CR);
}
break;
case STEP_PARTITIONING:
step = (StepMeta) areaOwner.getParent();
tip.append("Step partitioning:").append(Const.CR).append("-----------------------").append(Const.CR);
tip.append(step.getStepPartitioningMeta().toString()).append(Const.CR);
if (step.getTargetStepPartitioningMeta() != null) {
tip.append(Const.CR).append(Const.CR).append("TARGET: " + step.getTargetStepPartitioningMeta().toString()).append(Const.CR);
}
break;
case STEP_ERROR_ICON:
String log = (String) areaOwner.getParent();
tip.append(log);
tipImage = GUIResource.getInstance().getImageStepError();
break;
case STEP_ERROR_RED_ICON:
String redLog = (String) areaOwner.getParent();
tip.append(redLog);
tipImage = GUIResource.getInstance().getImageRedStepError();
break;
case HOP_COPY_ICON:
step = (StepMeta) areaOwner.getParent();
tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.HopTypeCopy", step.getName(), Const.CR));
tipImage = GUIResource.getInstance().getImageCopyHop();
break;
case ROW_DISTRIBUTION_ICON:
step = (StepMeta) areaOwner.getParent();
tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.RowDistribution", step.getName(), step.getRowDistribution() == null ? "" : step.getRowDistribution().getDescription()));
tip.append(Const.CR);
tipImage = GUIResource.getInstance().getImageBalance();
break;
case HOP_INFO_ICON:
StepMeta from = (StepMeta) areaOwner.getParent();
StepMeta to = (StepMeta) areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.HopTypeInfo", to.getName(), from.getName(), Const.CR));
tipImage = GUIResource.getInstance().getImageInfoHop();
break;
case HOP_ERROR_ICON:
from = (StepMeta) areaOwner.getParent();
to = (StepMeta) areaOwner.getOwner();
areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.HopTypeError", from.getName(), to.getName(), Const.CR));
tipImage = GUIResource.getInstance().getImageErrorHop();
break;
case HOP_INFO_STEP_COPIES_ERROR:
from = (StepMeta) areaOwner.getParent();
to = (StepMeta) areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "TransGraph.Hop.Tooltip.InfoStepCopies", from.getName(), to.getName(), Const.CR));
tipImage = GUIResource.getInstance().getImageStepError();
break;
case STEP_INPUT_HOP_ICON:
// StepMeta subjectStep = (StepMeta) (areaOwner.getParent());
tip.append(BaseMessages.getString(PKG, "TransGraph.StepInputConnector.Tooltip"));
tipImage = GUIResource.getInstance().getImageHopInput();
break;
case STEP_OUTPUT_HOP_ICON:
// subjectStep = (StepMeta) (areaOwner.getParent());
tip.append(BaseMessages.getString(PKG, "TransGraph.StepOutputConnector.Tooltip"));
tipImage = GUIResource.getInstance().getImageHopOutput();
break;
case STEP_INFO_HOP_ICON:
// subjectStep = (StepMeta) (areaOwner.getParent());
// StreamInterface stream = (StreamInterface) areaOwner.getOwner();
StepIOMetaInterface ioMeta = (StepIOMetaInterface) areaOwner.getOwner();
tip.append(BaseMessages.getString(PKG, "TransGraph.StepInfoConnector.Tooltip") + Const.CR + ioMeta.toString());
tipImage = GUIResource.getInstance().getImageHopOutput();
break;
case STEP_TARGET_HOP_ICON:
StreamInterface stream = (StreamInterface) areaOwner.getOwner();
tip.append(stream.getDescription());
tipImage = GUIResource.getInstance().getImageHopOutput();
break;
case STEP_ERROR_HOP_ICON:
StepMeta stepMeta = (StepMeta) areaOwner.getParent();
if (stepMeta.supportsErrorHandling()) {
tip.append(BaseMessages.getString(PKG, "TransGraph.StepSupportsErrorHandling.Tooltip"));
} else {
tip.append(BaseMessages.getString(PKG, "TransGraph.StepDoesNotSupportsErrorHandling.Tooltip"));
}
tipImage = GUIResource.getInstance().getImageHopOutput();
break;
case STEP_EDIT_ICON:
stepMeta = (StepMeta) (areaOwner.getParent());
tip.append(BaseMessages.getString(PKG, "TransGraph.EditStep.Tooltip"));
tipImage = GUIResource.getInstance().getImageEdit();
break;
case STEP_INJECT_ICON:
stepMeta = (StepMeta) (areaOwner.getParent());
Object injection = areaOwner.getOwner();
if (injection != null) {
tip.append(BaseMessages.getString(PKG, "TransGraph.StepInjectionSupported.Tooltip"));
} else {
tip.append(BaseMessages.getString(PKG, "TransGraph.StepInjectionNotSupported.Tooltip"));
}
tipImage = GUIResource.getInstance().getImageInject();
break;
case STEP_MENU_ICON:
tip.append(BaseMessages.getString(PKG, "TransGraph.ShowMenu.Tooltip"));
tipImage = GUIResource.getInstance().getImageContextMenu();
break;
default:
break;
}
}
if (hi != null) {
// We clicked on a HOP!
// Set the tooltip for the hop:
tip.append(Const.CR).append(BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo")).append(newTip = hi.toString()).append(Const.CR);
}
if (tip.length() == 0) {
newTip = null;
} else {
newTip = tip.toString();
}
if (newTip == null) {
toolTip.hide();
if (hi != null) {
// We clicked on a HOP!
// Set the tooltip for the hop:
newTip = BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo") + Const.CR + BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.SourceStep") + " " + hi.getFromStep().getName() + Const.CR + BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.TargetStep") + " " + hi.getToStep().getName() + Const.CR + BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.Status") + " " + (hi.isEnabled() ? BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.Enable") : BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.Disable"));
toolTip.setText(newTip);
if (hi.isEnabled()) {
toolTip.setImage(GUIResource.getInstance().getImageHop());
} else {
toolTip.setImage(GUIResource.getInstance().getImageDisabledHop());
}
toolTip.show(new org.eclipse.swt.graphics.Point(screenX, screenY));
} else {
newTip = null;
}
} else if (!newTip.equalsIgnoreCase(getToolTipText())) {
Image tooltipImage = null;
if (tipImage != null) {
tooltipImage = tipImage;
} else {
tooltipImage = GUIResource.getInstance().getImageSpoonLow();
}
showTooltip(newTip, tooltipImage, screenX, screenY);
}
if (areaOwner != null && areaOwner.getExtensionAreaType() != null) {
try {
TransPainterFlyoutTooltipExtension extension = new TransPainterFlyoutTooltipExtension(areaOwner, this, new Point(screenX, screenY));
ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransPainterFlyoutTooltip.id, extension);
} catch (Exception e) {
LogChannel.GENERAL.logError("Error calling extension point(s) for the transformation painter step", e);
}
}
return subject;
}
Aggregations