Search in sources :

Example 1 with JfaceMenupopup

use of org.pentaho.ui.xul.jface.tags.JfaceMenupopup 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 + "')");
    }
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Action(org.eclipse.jface.action.Action) JfaceMenuitem(org.pentaho.ui.xul.jface.tags.JfaceMenuitem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) JfaceMenupopup(org.pentaho.ui.xul.jface.tags.JfaceMenupopup) LastUsedFile(org.pentaho.di.core.LastUsedFile) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 2 with JfaceMenupopup

use of org.pentaho.ui.xul.jface.tags.JfaceMenupopup 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);
                }
            }
        }
    }
}
Also used : Action(org.eclipse.jface.action.Action) JobHopMeta(org.pentaho.di.job.JobHopMeta) JfaceMenuitem(org.pentaho.ui.xul.jface.tags.JfaceMenuitem) Document(org.pentaho.ui.xul.dom.Document) JfaceMenupopup(org.pentaho.ui.xul.jface.tags.JfaceMenupopup) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) XulException(org.pentaho.ui.xul.XulException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleException(org.pentaho.di.core.exception.KettleException) XulMenupopup(org.pentaho.ui.xul.containers.XulMenupopup) XulMenu(org.pentaho.ui.xul.containers.XulMenu) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Example 3 with JfaceMenupopup

use of org.pentaho.ui.xul.jface.tags.JfaceMenupopup 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();
    }
}
Also used : Action(org.eclipse.jface.action.Action) JfaceMenuitem(org.pentaho.ui.xul.jface.tags.JfaceMenuitem) SpoonUiExtenderPluginInterface(org.pentaho.di.ui.spoon.SpoonUiExtenderPluginInterface) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Document(org.pentaho.ui.xul.dom.Document) JfaceMenupopup(org.pentaho.ui.xul.jface.tags.JfaceMenupopup) StepMeta(org.pentaho.di.trans.step.StepMeta) XulException(org.pentaho.ui.xul.XulException) InvocationTargetException(java.lang.reflect.InvocationTargetException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleException(org.pentaho.di.core.exception.KettleException) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) XulMenupopup(org.pentaho.ui.xul.containers.XulMenupopup) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) RowDistributionInterface(org.pentaho.di.trans.step.RowDistributionInterface) TransHopMeta(org.pentaho.di.trans.TransHopMeta) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Aggregations

Action (org.eclipse.jface.action.Action)3 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 Point (org.pentaho.di.core.gui.Point)3 JfaceMenuitem (org.pentaho.ui.xul.jface.tags.JfaceMenuitem)3 JfaceMenupopup (org.pentaho.ui.xul.jface.tags.JfaceMenupopup)3 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)2 XulException (org.pentaho.ui.xul.XulException)2 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)2 XulMenupopup (org.pentaho.ui.xul.containers.XulMenupopup)2 Document (org.pentaho.ui.xul.dom.Document)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LastUsedFile (org.pentaho.di.core.LastUsedFile)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 TransAction (org.pentaho.di.core.undo.TransAction)1 JobHopMeta (org.pentaho.di.job.JobHopMeta)1