use of org.pentaho.ui.xul.components.XulMenuitem 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.components.XulMenuitem 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.components.XulMenuitem in project pentaho-kettle by pentaho.
the class SpoonLockController method lockContent.
public void lockContent() throws Exception {
try {
if (workingMeta != null && workingMeta.getObjectId() != null && supportsLocking(Spoon.getInstance().getRepository())) {
// Look in the SpoonTransformationDelegate for details on the TabItem creation
if (!tabBound) {
bindingFactory.createBinding(this, "activeMetaUnlocked", Spoon.getInstance().delegates.tabs.findTabMapEntry(workingMeta).getTabItem(), "image", new // $NON-NLS-1$ //$NON-NLS-2$
BindingConvertor<Boolean, Image>() {
@Override
public Image sourceToTarget(Boolean activeMetaUnlocked) {
if (activeMetaUnlocked) {
if (workingMeta instanceof TransMeta) {
return GUIResource.getInstance().getImageTransGraph();
} else if (workingMeta instanceof JobMeta) {
return GUIResource.getInstance().getImageJobGraph();
}
} else {
return GUIResource.getInstance().getImageLocked();
}
return null;
}
@Override
public Boolean targetToSource(Image arg0) {
return false;
}
});
tabBound = true;
}
// Decide whether to lock or unlock the object
if (fetchRepositoryLock(workingMeta) == null) {
// Lock the object (it currently is NOT locked)
XulPromptBox lockNotePrompt = promptLockMessage(document, messages, null);
lockNotePrompt.addDialogCallback(new XulDialogCallback<String>() {
public void onClose(XulComponent component, Status status, String value) {
if (!status.equals(Status.CANCEL)) {
try {
if (workingMeta instanceof TransMeta) {
getService(Spoon.getInstance().getRepository()).lockTransformation(workingMeta.getObjectId(), value);
} else if (workingMeta instanceof JobMeta) {
getService(Spoon.getInstance().getRepository()).lockJob(workingMeta.getObjectId(), value);
}
// Execute binding. Notify listeners that the object is now locked
// $NON-NLS-1$ //$NON-NLS-2$
firePropertyChange("activeMetaUnlocked", true, false);
// this keeps the menu item and the state in sync
// could a binding be used instead?
XulDomContainer container = getXulDomContainer();
XulMenuitem lockMenuItem = // $NON-NLS-1$
(XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
lockMenuItem.setSelected(true);
} catch (Exception e) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
} else {
// this keeps the menu item and the state in sync
// could a binding be used instead?
XulDomContainer container = getXulDomContainer();
XulMenuitem lockMenuItem = // $NON-NLS-1$
(XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
lockMenuItem.setSelected(false);
}
}
public void onError(XulComponent component, Throwable err) {
throw new RuntimeException(err);
}
});
lockNotePrompt.open();
} else {
// Unlock the object (it currently IS locked)
if (workingMeta instanceof TransMeta) {
getService(Spoon.getInstance().getRepository()).unlockTransformation(workingMeta.getObjectId());
} else if (workingMeta instanceof JobMeta) {
getService(Spoon.getInstance().getRepository()).unlockJob(workingMeta.getObjectId());
}
// Execute binding. Notify listeners that the object is now unlocked
// $NON-NLS-1$ //$NON-NLS-2$
firePropertyChange("activeMetaUnlocked", false, true);
}
} else if (workingMeta != null && workingMeta.getObjectId() == null && supportsLocking(Spoon.getInstance().getRepository())) {
XulDomContainer container = getXulDomContainer();
// $NON-NLS-1$
XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
lockMenuItem.setSelected(false);
// $NON-NLS-1$
XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
// $NON-NLS-1$
msgBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
msgBox.setMessage(BaseMessages.getString(PKG, "LockController.SaveBeforeLock"));
msgBox.setModalParent(shell);
msgBox.open();
} else {
XulDomContainer container = getXulDomContainer();
// $NON-NLS-1$
XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
lockMenuItem.setSelected(false);
// $NON-NLS-1$
XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
// $NON-NLS-1$
msgBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
msgBox.setMessage(BaseMessages.getString(PKG, "LockController.NoLockingSupport"));
msgBox.setModalParent(shell);
msgBox.open();
}
} catch (Throwable th) {
// $NON-NLS-1$
log.error(BaseMessages.getString(PKG, "LockController.NoLockingSupport"), th);
new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), BaseMessages.getString(PKG, "Dialog.Error"), BaseMessages.getString(PKG, "LockController.NoLockingSupport"), // $NON-NLS-1$ //$NON-NLS-2$
th);
}
}
use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-platform by pentaho.
the class MantleController method setMenuItemEnabled.
public void setMenuItemEnabled(String id, boolean enabled) {
XulMenuitem item = (XulMenuitem) document.getElementById(id);
item.setDisabled(!enabled);
}
use of org.pentaho.ui.xul.components.XulMenuitem in project data-access by pentaho.
the class DatasourceAdminDialogController method getDatasourceTypes.
private void getDatasourceTypes() {
List<String> datasourceTypes = manager.getTypes();
// Clear out the current component list
List<XulComponent> components = datasourceTypeMenuPopup.getChildNodes();
// remove exist import and plugins
for (int i = 0; i < components.size(); i++) {
XulComponent component = components.get(i);
if (component.getId() == null) {
continue;
}
if (component.getId().startsWith("import") || component.getId().startsWith("plugin")) {
// remove import and plugins items
datasourceTypeMenuPopup.removeComponent(component);
}
}
// find separator
components = datasourceTypeMenuPopup.getChildNodes();
int beforePlugins = 0;
XulComponent beforePluginsMenuItem = null;
for (int i = 0; i < components.size(); i++) {
XulComponent component = components.get(i);
if ("beforePlugins".equals(component.getId())) {
beforePlugins = i;
beforePluginsMenuItem = component;
}
}
List<IDatasourceInfo> datasourceInfoList = datasourceAdminDialogModel.getDatasourcesList();
// Add "Import..." items first
for (String datasourceType : datasourceTypes) {
IUIDatasourceAdminService datasourceAdminService = manager.getService(datasourceType);
if (datasourceAdminService instanceof DSWUIDatasourceService) {
// Data Source Wizard
continue;
}
if (datasourceAdminService instanceof JdbcDatasourceService) {
// JDBC
continue;
}
if (// Analysis - import
!(datasourceAdminService instanceof MondrianUIDatasourceService) && !(datasourceAdminService instanceof MetadataUIDatasourceService)) {
// Metadata - import
continue;
}
if (!datasourceAdminService.isCreatable()) {
continue;
}
XulMenuitem menuItem;
try {
String displayName = DatasourceInfo.getDisplayType(datasourceType, messageBundle);
String label = messageBundle.getString(IMPORT_MSG_ID, displayName);
menuItem = (XulMenuitem) document.createElement("menuitem");
menuItem.setLabel(label);
menuItem.setCommand(getName() + ".launchNewUI(\"" + datasourceType + "\")");
menuItem.setId("import" + datasourceType);
datasourceTypeMenuPopup.addChildAt(menuItem, beforePlugins++);
} catch (XulException e) {
throw new RuntimeException(e);
}
}
// Add plugin items
boolean hasPlugins = false;
beforePlugins++;
for (String datasourceType : datasourceTypes) {
IUIDatasourceAdminService datasourceAdminService = manager.getService(datasourceType);
if (datasourceAdminService instanceof DSWUIDatasourceService) {
// Data Source Wizard
continue;
}
if (datasourceAdminService instanceof JdbcDatasourceService) {
// JDBC
continue;
}
if (datasourceAdminService instanceof MondrianUIDatasourceService) {
// Analysis - import
continue;
} else if (datasourceAdminService instanceof MetadataUIDatasourceService) {
// Metadata - import
continue;
}
if (!datasourceAdminService.isCreatable()) {
continue;
}
hasPlugins = true;
XulMenuitem menuItem;
try {
String displayName = DatasourceInfo.getDisplayType(datasourceType, messageBundle);
String label = messageBundle.getString(PLUGIN_MSG_ID, displayName);
menuItem = (XulMenuitem) document.createElement("menuitem");
menuItem.setLabel(label);
menuItem.setCommand(getName() + ".launchNewUI(\"" + datasourceType + "\")");
menuItem.setId("plugin" + datasourceType);
datasourceTypeMenuPopup.addChildAt(menuItem, beforePlugins++);
} catch (XulException e) {
throw new RuntimeException(e);
}
}
beforePluginsMenuItem.setVisible(hasPlugins);
datasourceAdminDialogModel.setDatasourceTypeList(datasourceTypes);
}
Aggregations