Search in sources :

Example 11 with Document

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();
    }
}
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)

Example 12 with Document

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);
        }
    }
}
Also used : XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) Document(org.pentaho.ui.xul.dom.Document) XulToolbarbutton(org.pentaho.ui.xul.components.XulToolbarbutton) XulMenu(org.pentaho.ui.xul.containers.XulMenu)

Example 13 with Document

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();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) XulException(org.pentaho.ui.xul.XulException) SwtDialog(org.pentaho.ui.xul.swt.tags.SwtDialog) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) Document(org.pentaho.ui.xul.dom.Document) SwtXulRunner(org.pentaho.ui.xul.swt.SwtXulRunner)

Example 14 with Document

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) XulLoader(org.pentaho.ui.xul.XulLoader) Document(org.pentaho.ui.xul.dom.Document) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) SwtDialog(org.pentaho.ui.xul.swt.tags.SwtDialog) DataServiceRemapConfirmationDialogController(org.pentaho.di.trans.dataservice.ui.controller.DataServiceRemapConfirmationDialogController) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XulRunner(org.pentaho.ui.xul.XulRunner) Test(org.junit.Test)

Example 15 with Document

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceRemapNoStepsDialogController(org.pentaho.di.trans.dataservice.ui.controller.DataServiceRemapNoStepsDialogController) XulLoader(org.pentaho.ui.xul.XulLoader) Document(org.pentaho.ui.xul.dom.Document) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) SwtDialog(org.pentaho.ui.xul.swt.tags.SwtDialog) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XulRunner(org.pentaho.ui.xul.XulRunner) Test(org.junit.Test)

Aggregations

Document (org.pentaho.ui.xul.dom.Document)17 Test (org.junit.Test)7 KettleException (org.pentaho.di.core.exception.KettleException)7 XulException (org.pentaho.ui.xul.XulException)7 XulDomContainer (org.pentaho.ui.xul.XulDomContainer)5 SwtDialog (org.pentaho.ui.xul.swt.tags.SwtDialog)5 Shell (org.eclipse.swt.widgets.Shell)4 XulComponent (org.pentaho.ui.xul.XulComponent)4 XulRunner (org.pentaho.ui.xul.XulRunner)4 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 XulLoader (org.pentaho.ui.xul.XulLoader)3 XulMenu (org.pentaho.ui.xul.containers.XulMenu)3 Action (org.eclipse.jface.action.Action)2 Before (org.junit.Before)2 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2 Point (org.pentaho.di.core.gui.Point)2