use of org.pentaho.ui.xul.dom.Document 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.ui.xul.dom.Document in project pentaho-kettle by pentaho.
the class EESpoonPlugin method updateMenuState.
/**
* Change the menu-item states based on Execute and Create permissions.
* @param createPermitted
* - if true, we enable menu-items requiring creation permissions
* @param executePermitted
* - if true, we enable menu-items requiring execute permissions
*/
void updateMenuState(boolean createPermitted, boolean executePermitted) {
Document doc = getDocumentRoot();
if (doc != null) {
// Main spoon menu
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("process-run")).setDisabled(!executePermitted);
// $NON-NLS-1$
XulToolbarbutton transRunButton = ((XulToolbarbutton) doc.getElementById("trans-run"));
if (transRunButton != null) {
transRunButton.setDisabled(!executePermitted);
}
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-preview")).setDisabled(!executePermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-debug")).setDisabled(!executePermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-replay")).setDisabled(!executePermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-verify")).setDisabled(!executePermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-impact")).setDisabled(!executePermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-get-sql")).setDisabled(!executePermitted);
// Disable Show Last menu under the Action menu.
// $NON-NLS-1$
((XulMenu) doc.getElementById("trans-last")).setDisabled(!executePermitted);
// Schedule is a plugin
if (doc.getElementById("trans-schedule") != null) {
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-schedule")).setDisabled(!executePermitted);
}
// Main spoon toolbar
// $NON-NLS-1$
((XulToolbarbutton) doc.getElementById("toolbar-file-new")).setDisabled(!createPermitted);
// $NON-NLS-1$
((XulToolbarbutton) doc.getElementById("toolbar-file-save")).setDisabled(!createPermitted);
// $NON-NLS-1$
((XulToolbarbutton) doc.getElementById("toolbar-file-save-as")).setDisabled(!createPermitted);
// Popup menus
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("trans-class-new")).setDisabled(!createPermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("job-class-new")).setDisabled(!createPermitted);
// Main spoon menu
// $NON-NLS-1$
((XulMenu) doc.getElementById("file-new")).setDisabled(!createPermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("file-save")).setDisabled(!createPermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("file-save-as")).setDisabled(!createPermitted);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("file-close")).setDisabled(!createPermitted);
boolean exportAllowed = createPermitted && executePermitted;
// $NON-NLS-1$
((XulMenu) doc.getElementById("file-export")).setDisabled(!exportAllowed);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("repository-export-all")).setDisabled(!exportAllowed);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("file-save-as-vfs")).setDisabled(!exportAllowed);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("edit-cut-steps")).setDisabled(!exportAllowed);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("edit-copy-steps")).setDisabled(!exportAllowed);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("edit.copy-file")).setDisabled(!exportAllowed);
// $NON-NLS-1$
((XulMenuitem) doc.getElementById("edit-paste-steps")).setDisabled(!exportAllowed);
// $NON-NLS-1$
XulMenuitem transCopyContextMenu = ((XulMenuitem) doc.getElementById("trans-graph-entry-copy"));
if (transCopyContextMenu != null) {
transCopyContextMenu.setDisabled(!exportAllowed);
}
}
}
use of org.pentaho.ui.xul.dom.Document in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceRemapConfirmationDialog method open.
void open() throws KettleException {
Document xulDocument;
try {
xulDocument = initXul(parent, new KettleXulLoader(), new SwtXulRunner());
} catch (XulException e) {
throw new KettleException("Failed to create data service remap confirmation dialog", e);
}
((SwtDialog) xulDocument.getElementById(XUL_DIALOG_ID)).show();
}
use of org.pentaho.ui.xul.dom.Document in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceRemapConfirmationDialogTest method testOpen.
@Test
public void testOpen() throws XulException, KettleException {
Shell shell = mock(Shell.class);
final Document document = mock(Document.class);
SwtDialog swtDialog = mock(SwtDialog.class);
when(document.getElementById(DataServiceRemapConfirmationDialog.XUL_DIALOG_ID)).thenReturn(swtDialog);
DataServiceRemapConfirmationDialogController controller = mock(DataServiceRemapConfirmationDialogController.class);
DataServiceRemapConfirmationDialog dialog = spy(new DataServiceRemapConfirmationDialog(shell, controller));
doAnswer(new Answer() {
private int invocations = 0;
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
if (invocations == 0) {
invocations++;
return document;
} else {
throw new XulException("");
}
}
}).when(dialog).initXul(same(shell), any(XulLoader.class), any(XulRunner.class));
dialog.open();
verify(dialog).initXul(same(shell), any(XulLoader.class), any(XulRunner.class));
verify(swtDialog).show();
try {
dialog.open();
} catch (Exception e) {
Assert.assertTrue(e instanceof KettleException);
}
}
use of org.pentaho.ui.xul.dom.Document in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceRemapNoStepsDialogTest method testOpen.
@Test
public void testOpen() throws XulException, KettleException {
Shell shell = mock(Shell.class);
final Document document = mock(Document.class);
SwtDialog swtDialog = mock(SwtDialog.class);
when(document.getElementById(DataServiceRemapNoStepsDialog.XUL_DIALOG_ID)).thenReturn(swtDialog);
DataServiceRemapNoStepsDialogController controller = mock(DataServiceRemapNoStepsDialogController.class);
DataServiceRemapNoStepsDialog dialog = spy(new DataServiceRemapNoStepsDialog(shell, controller));
doAnswer(new Answer() {
private int invocations = 0;
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
if (invocations == 0) {
invocations++;
return document;
} else {
throw new XulException("");
}
}
}).when(dialog).initXul(same(shell), any(XulLoader.class), any(XulRunner.class));
dialog.open();
verify(dialog).initXul(same(shell), any(XulLoader.class), any(XulRunner.class));
verify(swtDialog).show();
try {
dialog.open();
} catch (Exception e) {
Assert.assertTrue(e instanceof KettleException);
}
}
Aggregations