use of org.pentaho.ui.xul.jface.tags.JfaceMenuitem in project pentaho-kettle by pentaho.
the class Spoon method addMenuLast.
public void addMenuLast() {
org.pentaho.ui.xul.dom.Document doc = mainSpoonContainer.getDocumentRoot();
JfaceMenupopup recentFilesPopup = (JfaceMenupopup) doc.getElementById("file-open-recent-popup");
recentFilesPopup.removeChildren();
// Previously loaded files...
List<LastUsedFile> lastUsedFiles = props.getLastUsedFiles();
for (int i = 0; i < lastUsedFiles.size(); i++) {
final LastUsedFile lastUsedFile = lastUsedFiles.get(i);
char chr = (char) ('1' + i);
String accessKey = "ctrl-" + chr;
String accessText = "CTRL-" + chr;
String text = lastUsedFile.toString();
String id = "last-file-" + i;
if (i > 8) {
accessKey = null;
accessText = null;
}
final String lastFileId = Integer.toString(i);
Action action = new Action("open-last-file-" + (i + 1), Action.AS_DROP_DOWN_MENU) {
@Override
public void run() {
lastFileSelect(lastFileId);
}
};
// shorten the filename if necessary
int targetLength = 40;
if (text.length() > targetLength) {
int lastSep = text.replace('\\', '/').lastIndexOf('/');
if (lastSep != -1) {
String fileName = "..." + text.substring(lastSep);
if (fileName.length() < targetLength) {
// add the start of the file path
int leadSize = targetLength - fileName.length();
text = text.substring(0, leadSize) + fileName;
} else {
text = fileName;
}
}
}
JfaceMenuitem miFileLast = new JfaceMenuitem(null, recentFilesPopup, mainSpoonContainer, text, 0, action);
miFileLast.setLabel(text);
miFileLast.setId(id);
if (accessText != null && accessKey != null) {
miFileLast.setAcceltext(accessText);
miFileLast.setAccesskey(accessKey);
}
if (lastUsedFile.isTransformation()) {
miFileLast.setImage(GUIResource.getInstance().getImageTransGraph());
} else if (lastUsedFile.isJob()) {
miFileLast.setImage(GUIResource.getInstance().getImageJobGraph());
}
miFileLast.setCommand("spoon.lastFileSelect('" + i + "')");
}
}
use of org.pentaho.ui.xul.jface.tags.JfaceMenuitem in project pentaho-kettle by pentaho.
the class JobGraph method setMenu.
protected synchronized void setMenu(int x, int y) {
currentMouseX = x;
currentMouseY = y;
final JobEntryCopy jobEntry = jobMeta.getJobEntryCopy(x, y, iconsize);
setJobEntry(jobEntry);
Document doc = xulDomContainer.getDocumentRoot();
if (jobEntry != null) {
// We clicked on a Job Entry!
XulMenupopup menu = (XulMenupopup) doc.getElementById("job-graph-entry");
if (menu != null) {
List<JobEntryCopy> selection = jobMeta.getSelectedEntries();
doRightClickSelection(jobEntry, selection);
int sels = selection.size();
XulMenuitem item = (XulMenuitem) doc.getElementById("job-graph-entry-newhop");
item.setDisabled(sels < 2);
JfaceMenupopup launchMenu = (JfaceMenupopup) doc.getElementById("job-graph-entry-launch-popup");
String[] referencedObjects = jobEntry.getEntry().getReferencedObjectDescriptions();
boolean[] enabledObjects = jobEntry.getEntry().isReferencedObjectEnabled();
launchMenu.setDisabled(Utils.isEmpty(referencedObjects));
launchMenu.removeChildren();
if (!Utils.isEmpty(referencedObjects)) {
for (int i = 0; i < referencedObjects.length; i++) {
final int index = i;
String referencedObject = referencedObjects[i];
Action action = new Action(referencedObject, Action.AS_DROP_DOWN_MENU) {
public void run() {
loadReferencedObject(jobEntry, index);
}
};
JfaceMenuitem child = new JfaceMenuitem(null, launchMenu, xulDomContainer, referencedObject, i, action);
child.setLabel(referencedObject);
child.setDisabled(!enabledObjects[i]);
}
}
item = (XulMenuitem) doc.getElementById("job-graph-entry-align-snap");
item.setAcceltext("ALT-HOME");
item.setLabel(BaseMessages.getString(PKG, "JobGraph.PopupMenu.JobEntry.AllignDistribute.SnapToGrid"));
item.setAccesskey("alt-home");
XulMenu aMenu = (XulMenu) doc.getElementById("job-graph-entry-align");
if (aMenu != null) {
aMenu.setDisabled(sels < 1);
}
item = (XulMenuitem) doc.getElementById("job-graph-entry-detach");
if (item != null) {
item.setDisabled(!jobMeta.isEntryUsedInHops(jobEntry));
}
item = (XulMenuitem) doc.getElementById("job-graph-entry-hide");
if (item != null) {
item.setDisabled(!(jobEntry.isDrawn() && !jobMeta.isEntryUsedInHops(jobEntry)));
}
item = (XulMenuitem) doc.getElementById("job-graph-entry-delete");
if (item != null) {
item.setDisabled(!jobEntry.isDrawn());
}
item = (XulMenuitem) doc.getElementById("job-graph-entry-parallel");
if (item != null) {
item.setSelected(jobEntry.isLaunchingInParallel());
}
try {
JobGraphJobEntryMenuExtension extension = new JobGraphJobEntryMenuExtension(xulDomContainer, doc, jobMeta, jobEntry, this);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobGraphJobEntrySetMenu.id, extension);
} catch (Exception e) {
log.logError("Error handling menu right click on job entry through extension point", e);
}
ConstUI.displayMenu(menu, canvas);
}
} else {
// Clear the menu
final JobHopMeta hi = findJobHop(x, y);
setCurrentHop(hi);
if (hi != null) {
// We clicked on a HOP!
XulMenupopup menu = (XulMenupopup) doc.getElementById("job-graph-hop");
if (menu != null) {
XulMenuitem miPopEvalUncond = (XulMenuitem) doc.getElementById("job-graph-hop-evaluation-uncond");
XulMenuitem miPopEvalTrue = (XulMenuitem) doc.getElementById("job-graph-hop-evaluation-true");
XulMenuitem miPopEvalFalse = (XulMenuitem) doc.getElementById("job-graph-hop-evaluation-false");
XulMenuitem miDisHop = (XulMenuitem) doc.getElementById("job-graph-hop-enabled");
XulMenuitem miFlipHop = (XulMenuitem) doc.getElementById("job-graph-hop-flip");
//
if (miPopEvalUncond != null && miPopEvalTrue != null && miPopEvalFalse != null) {
if (hi.isUnconditional()) {
miPopEvalUncond.setSelected(true);
miPopEvalTrue.setSelected(false);
miPopEvalFalse.setSelected(false);
} else {
if (hi.getEvaluation()) {
miPopEvalUncond.setSelected(false);
miPopEvalTrue.setSelected(true);
miPopEvalFalse.setSelected(false);
} else {
miPopEvalUncond.setSelected(false);
miPopEvalTrue.setSelected(false);
miPopEvalFalse.setSelected(true);
}
}
if (!hi.getFromEntry().evaluates()) {
miPopEvalTrue.setDisabled(true);
miPopEvalFalse.setDisabled(true);
} else {
miPopEvalTrue.setDisabled(false);
miPopEvalFalse.setDisabled(false);
}
if (!hi.getFromEntry().isUnconditional()) {
miPopEvalUncond.setDisabled(true);
} else {
miPopEvalUncond.setDisabled(false);
}
if (hi.getFromEntry().isStart()) {
miFlipHop.setDisabled(true);
} else {
miFlipHop.setDisabled(false);
}
}
if (miDisHop != null) {
if (hi.isEnabled()) {
miDisHop.setLabel(BaseMessages.getString(PKG, "JobGraph.PopupMenu.Hop.Disable"));
} else {
miDisHop.setLabel(BaseMessages.getString(PKG, "JobGraph.PopupMenu.Hop.Enable"));
}
}
ConstUI.displayMenu(menu, canvas);
}
} else {
// Clicked on the background: maybe we hit a note?
final NotePadMeta ni = jobMeta.getNote(x, y);
setCurrentNote(ni);
if (ni != null) {
XulMenupopup menu = (XulMenupopup) doc.getElementById("job-graph-note");
if (menu != null) {
ConstUI.displayMenu(menu, canvas);
}
} else {
XulMenupopup menu = (XulMenupopup) doc.getElementById("job-graph-background");
if (menu != null) {
final String clipcontent = spoon.fromClipboard();
XulMenuitem item = (XulMenuitem) doc.getElementById("job-graph-note-paste");
if (item != null) {
item.setDisabled(clipcontent == null);
}
ConstUI.displayMenu(menu, canvas);
}
}
}
}
}
use of org.pentaho.ui.xul.jface.tags.JfaceMenuitem 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();
}
}
Aggregations