use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.
the class Spoon method enableMenus.
public void enableMenus() {
boolean disableTransMenu = getActiveTransformation() == null;
boolean disableJobMenu = getActiveJob() == null;
boolean disableMetaMenu = getActiveMeta() == null;
boolean isRepositoryRunning = rep != null;
boolean disablePreviewButton = true;
String activePerspectiveId = null;
SpoonPerspectiveManager manager = SpoonPerspectiveManager.getInstance();
if (manager != null && manager.getActivePerspective() != null) {
activePerspectiveId = manager.getActivePerspective().getId();
}
boolean etlPerspective = false;
if (activePerspectiveId != null && activePerspectiveId.length() > 0) {
etlPerspective = activePerspectiveId.equals(MainSpoonPerspective.ID);
}
TransGraph transGraph = getActiveTransGraph();
if (transGraph != null) {
disablePreviewButton = !(transGraph.isRunning() && !transGraph.isHalting());
}
boolean disableSave = true;
boolean disableDatabaseExplore = true;
TabItemInterface currentTab = getActiveTabitem();
if (currentTab != null && currentTab.canHandleSave()) {
disableSave = !currentTab.hasContentChanged();
}
EngineMetaInterface meta = getActiveMeta();
if (meta != null) {
disableSave = !meta.canSave();
disableDatabaseExplore = false;
}
org.pentaho.ui.xul.dom.Document doc;
if (mainSpoonContainer != null) {
doc = mainSpoonContainer.getDocumentRoot();
if (doc != null) {
if (etlPerspective) {
doc.getElementById("file").setVisible(etlPerspective);
doc.getElementById("edit").setVisible(etlPerspective);
doc.getElementById("view").setVisible(etlPerspective);
doc.getElementById("action").setVisible(etlPerspective);
doc.getElementById("tools").setVisible(etlPerspective);
doc.getElementById("help").setVisible(etlPerspective);
doc.getElementById("help-welcome").setVisible(etlPerspective);
doc.getElementById("help-plugins").setVisible(true);
}
// Only enable certain menu-items if we need to.
disableMenuItem(doc, "file-new-database", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "menubar-new-database", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "file-save", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave);
disableMenuItem(doc, "toolbar-file-save", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave);
disableMenuItem(doc, "file-save-as", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave);
disableMenuItem(doc, "toolbar-file-save-as", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave);
disableMenuItem(doc, "file-save-as-vfs", disableTransMenu && disableJobMenu && disableMetaMenu);
disableMenuItem(doc, "file-close", disableTransMenu && disableJobMenu && disableMetaMenu);
disableMenuItem(doc, "file-print", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "file-export-to-xml", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "file-export-all-to-xml", disableTransMenu && disableJobMenu);
// Disable the undo and redo menus if there is no active transformation
// or active job
// DO NOT ENABLE them otherwise ... leave that to the undo/redo settings
//
disableMenuItem(doc, UNDO_MENU_ITEM, disableTransMenu && disableJobMenu);
disableMenuItem(doc, REDO_MENU_ITEM, disableTransMenu && disableJobMenu);
disableMenuItem(doc, "edit-clear-selection", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "edit-select-all", disableTransMenu && disableJobMenu);
updateSettingsMenu(doc, disableTransMenu, disableJobMenu);
disableMenuItem(doc, "edit-settings", disableTransMenu && disableJobMenu && disableMetaMenu);
// View Menu
((XulMenuitem) doc.getElementById("view-results")).setSelected(isExecutionResultsPaneVisible());
disableMenuItem(doc, "view-results", transGraph == null && disableJobMenu);
disableMenuItem(doc, "view-zoom-in", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "view-zoom-out", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "view-zoom-100pct", disableTransMenu && disableJobMenu);
// Transformations
disableMenuItem(doc, "process-run", disableTransMenu && disablePreviewButton && disableJobMenu);
disableMenuItem(doc, "process-run-options", disableTransMenu && disablePreviewButton && disableJobMenu);
disableMenuItem(doc, "trans-replay", disableTransMenu && disablePreviewButton);
disableMenuItem(doc, "trans-preview", disableTransMenu && disablePreviewButton);
disableMenuItem(doc, "trans-debug", disableTransMenu && disablePreviewButton);
disableMenuItem(doc, "trans-verify", disableTransMenu);
disableMenuItem(doc, "trans-impact", disableTransMenu);
disableMenuItem(doc, "trans-get-sql", disableTransMenu);
disableMenuItem(doc, "trans-last-impact", disableTransMenu);
// Tools
disableMenuItem(doc, "repository-explore", !isRepositoryRunning);
disableMenuItem(doc, "tools-dabase-explore", !isRepositoryRunning && disableDatabaseExplore);
disableMenuItem(doc, "repository-clear-shared-object-cache", !isRepositoryRunning);
disableMenuItem(doc, "toolbar-expore-repository", !isRepositoryRunning);
disableMenuItem(doc, "repository-export-all", !isRepositoryRunning);
disableMenuItem(doc, "repository-import-directory", !isRepositoryRunning);
disableMenuItem(doc, "trans-last-preview", !isRepositoryRunning || disableTransMenu);
// Wizard
disableMenuItem(doc, "wizard-connection", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "wizard-copy-table", disableTransMenu && disableJobMenu);
disableMenuItem(doc, "wizard-copy-tables", isRepositoryRunning && disableTransMenu && disableJobMenu);
disableMenuItem(doc, "database-inst-dependancy", !isRepositoryRunning);
SpoonPluginManager.getInstance().notifyLifecycleListeners(SpoonLifeCycleEvent.MENUS_REFRESHED);
MenuManager menuManager = getMenuBarManager();
menuManager.updateAll(true);
// What steps & plugins to show?
refreshCoreObjects();
fireMenuControlers();
}
}
}
use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.
the class Spoon method enableMenuItem.
public void enableMenuItem(String itemId) {
XulMenuitem item = (XulMenuitem) mainSpoonContainer.getDocumentRoot().getElementById(itemId);
item.setDisabled(false);
}
use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.
the class Spoon method setUndoMenu.
/**
* Sets the text and enabled settings for the undo and redo menu items
*
* @param undoInterface
* the object which holds the undo/redo information
*/
public void setUndoMenu(UndoInterface undoInterface) {
if (shell.isDisposed()) {
return;
}
TransAction prev = undoInterface != null ? undoInterface.viewThisUndo() : null;
TransAction next = undoInterface != null ? undoInterface.viewNextUndo() : null;
// Set the menubar text and enabled flags
XulMenuitem item = (XulMenuitem) mainSpoonContainer.getDocumentRoot().getElementById(UNDO_MENU_ITEM);
item.setLabel(prev == null ? UNDO_UNAVAILABLE : BaseMessages.getString(PKG, "Spoon.Menu.Undo.Available", prev.toString()));
item.setDisabled(prev == null);
item = (XulMenuitem) mainSpoonContainer.getDocumentRoot().getElementById(REDO_MENU_ITEM);
item.setLabel(next == null ? REDO_UNAVAILABLE : BaseMessages.getString(PKG, "Spoon.Menu.Redo.Available", next.toString()));
item.setDisabled(next == null);
}
use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.
the class TransGraph method initializeXulMenu.
protected void initializeXulMenu(Document doc, List<StepMeta> selection, StepMeta stepMeta) throws KettleException {
XulMenuitem item = (XulMenuitem) doc.getElementById("trans-graph-entry-newhop");
int sels = selection.size();
item.setDisabled(sels != 2);
item = (XulMenuitem) doc.getElementById("trans-graph-entry-align-snap");
item.setAcceltext("ALT-HOME");
item.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.SnapToGrid"));
item.setAccesskey("alt-home");
item = (XulMenuitem) doc.getElementById("trans-graph-entry-open-mapping");
XulMenu men = (XulMenu) doc.getElementById(TRANS_GRAPH_ENTRY_SNIFF);
men.setDisabled(trans == null || trans.isRunning() == false);
item = (XulMenuitem) doc.getElementById("trans-graph-entry-sniff-input");
item.setDisabled(trans == null || trans.isRunning() == false);
item = (XulMenuitem) doc.getElementById("trans-graph-entry-sniff-output");
item.setDisabled(trans == null || trans.isRunning() == false);
item = (XulMenuitem) doc.getElementById("trans-graph-entry-sniff-error");
item.setDisabled(!(stepMeta.supportsErrorHandling() && stepMeta.getStepErrorMeta() != null && stepMeta.getStepErrorMeta().getTargetStep() != null && trans != null && trans.isRunning()));
XulMenu aMenu = (XulMenu) doc.getElementById(TRANS_GRAPH_ENTRY_AGAIN);
if (aMenu != null) {
aMenu.setDisabled(sels < 2);
}
// item = (XulMenuitem) doc.getElementById("trans-graph-entry-data-movement-distribute");
// item.setSelected(stepMeta.isDistributes());
item = (XulMenuitem) doc.getElementById("trans-graph-entry-partitioning");
item.setDisabled(spoon.getPartitionSchemasNames(transMeta).isEmpty());
item = (XulMenuitem) doc.getElementById("trans-graph-entry-data-movement-copy");
item.setSelected(!stepMeta.isDistributes());
item = (XulMenuitem) doc.getElementById("trans-graph-entry-hide");
item.setDisabled(!(stepMeta.isDrawn() && !transMeta.isAnySelectedStepUsedInTransHops()));
item = (XulMenuitem) doc.getElementById("trans-graph-entry-detach");
item.setDisabled(!transMeta.isStepUsedInTransHops(stepMeta));
item = (XulMenuitem) doc.getElementById("trans-graph-entry-errors");
item.setDisabled(!stepMeta.supportsErrorHandling());
}
use of org.pentaho.ui.xul.components.XulMenuitem 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);
}
}
}
}
}
Aggregations