Search in sources :

Example 1 with XulMenuitem

use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.

the class TransGraphTest method testInitializeXulMenu.

@SuppressWarnings("unchecked")
@Test
public void testInitializeXulMenu() throws KettleException {
    StepMeta stepMeta = mock(StepMeta.class);
    TransGraph transGraph = mock(TransGraph.class);
    TransMeta transMeta = mock(TransMeta.class);
    Document document = mock(Document.class);
    XulMenuitem xulItem = mock(XulMenuitem.class);
    XulMenu xulMenu = mock(XulMenu.class);
    StepErrorMeta stepErrorMeta = mock(StepErrorMeta.class);
    Spoon spoon = mock(Spoon.class);
    List<StepMeta> selection = Arrays.asList(new StepMeta(), stepMeta, new StepMeta());
    doCallRealMethod().when(transGraph).setTransMeta(any(TransMeta.class));
    doCallRealMethod().when(transGraph).setSpoon(any(Spoon.class));
    transGraph.setTransMeta(transMeta);
    transGraph.setSpoon(spoon);
    when(stepMeta.getStepErrorMeta()).thenReturn(stepErrorMeta);
    when(stepMeta.isDrawn()).thenReturn(true);
    when(document.getElementById(any(String.class))).thenReturn(xulItem);
    when(document.getElementById(TransGraph.TRANS_GRAPH_ENTRY_AGAIN)).thenReturn(xulMenu);
    when(document.getElementById(TransGraph.TRANS_GRAPH_ENTRY_SNIFF)).thenReturn(xulMenu);
    doCallRealMethod().when(transGraph).initializeXulMenu(any(Document.class), any(List.class), any(StepMeta.class));
    transGraph.initializeXulMenu(document, selection, stepMeta);
    verify(transMeta).isAnySelectedStepUsedInTransHops();
}
Also used : XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) Spoon(org.pentaho.di.ui.spoon.Spoon) TransMeta(org.pentaho.di.trans.TransMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) List(java.util.List) Document(org.pentaho.ui.xul.dom.Document) StepMeta(org.pentaho.di.trans.step.StepMeta) XulMenu(org.pentaho.ui.xul.containers.XulMenu) Test(org.junit.Test)

Example 2 with XulMenuitem

use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.

the class RepositoryLockControllerTest method testBlockLock.

@Test
public void testBlockLock() throws Exception {
    RepositoryLockController repositoryLockController = new RepositoryLockController();
    List<UIRepositoryObject> selectedRepoObjects = new ArrayList<>();
    UIEETransformation lockObject = Mockito.mock(UIEETransformation.class);
    selectedRepoObjects.add(lockObject);
    Mockito.when(lockObject.isLocked()).thenReturn(true);
    ObjectId objectId = Mockito.mock(ObjectId.class);
    Mockito.when(lockObject.getObjectId()).thenReturn(objectId);
    XulMenuitem lockFileMenuItem = Mockito.mock(XulMenuitem.class);
    Field lockFileMenuItemField = repositoryLockController.getClass().getDeclaredField("lockFileMenuItem");
    lockFileMenuItemField.setAccessible(true);
    lockFileMenuItemField.set(repositoryLockController, lockFileMenuItem);
    XulMenuitem deleteFileMenuItem = Mockito.mock(XulMenuitem.class);
    Field deleteFileMenuItemField = repositoryLockController.getClass().getDeclaredField("deleteFileMenuItem");
    deleteFileMenuItemField.setAccessible(true);
    deleteFileMenuItemField.set(repositoryLockController, deleteFileMenuItem);
    XulMenuitem renameFileMenuItem = Mockito.mock(XulMenuitem.class);
    Field renameFileMenuItemField = repositoryLockController.getClass().getDeclaredField("renameFileMenuItem");
    renameFileMenuItemField.setAccessible(true);
    renameFileMenuItemField.set(repositoryLockController, renameFileMenuItem);
    Repository repository = Mockito.mock(Repository.class);
    PurRepositoryMeta repositoryMeta = Mockito.mock(PurRepositoryMeta.class);
    Mockito.when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
    Field repositoryField = repositoryLockController.getClass().getDeclaredField("repository");
    repositoryField.setAccessible(true);
    repositoryField.set(repositoryLockController, repository);
    ILockService service = Mockito.mock(ILockService.class);
    Mockito.when(service.canUnlockFileById(objectId)).thenReturn(true);
    Field serviceField = repositoryLockController.getClass().getDeclaredField("service");
    serviceField.setAccessible(true);
    serviceField.set(repositoryLockController, service);
    repositoryLockController.setMenuItemEnabledState(selectedRepoObjects);
    Assert.assertFalse(lockFileMenuItem.isDisabled());
    Mockito.verify(lockFileMenuItem).setDisabled(false);
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) Field(java.lang.reflect.Field) Repository(org.pentaho.di.repository.Repository) ObjectId(org.pentaho.di.repository.ObjectId) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) ArrayList(java.util.ArrayList) PurRepositoryMeta(org.pentaho.di.repository.pur.PurRepositoryMeta) UIEETransformation(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEETransformation) Test(org.junit.Test)

Example 3 with XulMenuitem

use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.

the class SpoonLockController method init.

protected void init() {
    try {
        if ((Spoon.getInstance().getRepository() != null) && (Spoon.getInstance().getRepository().hasService(IAbsSecurityProvider.class))) {
            IAbsSecurityProvider securityService = (IAbsSecurityProvider) Spoon.getInstance().getRepository().getService(IAbsSecurityProvider.class);
            setCreateAllowed(allowedActionsContains(securityService, IAbsSecurityProvider.CREATE_CONTENT_ACTION));
        }
        shell = (((Spoon) SpoonFactory.getInstance()).getShell());
        XulDomContainer container = getXulDomContainer();
        bindingFactory = new DefaultBindingFactory();
        bindingFactory.setDocument(container.getDocumentRoot());
        bindingFactory.setBindingType(Type.ONE_WAY);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        bindingFactory.createBinding(this, "activeMetaUnlocked", "lock-context-locknotes", "disabled");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        bindingFactory.createBinding(this, "lockingNotAllowed", "lock-context-lock", "disabled");
        // Try transformation
        if (container.getEventHandlers().containsKey("transgraph")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            workingMeta = ((TransGraph) container.getEventHandler("transgraph")).getMeta();
        } else if (container.getEventHandlers().containsKey("jobgraph")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            workingMeta = ((JobGraph) container.getEventHandler("jobgraph")).getMeta();
        }
        RepositoryLock repoLock = fetchRepositoryLock(workingMeta);
        if (repoLock != null) {
            // $NON-NLS-1$
            XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
            lockMenuItem.setSelected(true);
            // Permit locking/unlocking if the user owns the lock
            if (Spoon.getInstance().getRepository() instanceof PurRepository) {
                setLockingAllowed(new UnifiedRepositoryLockService(((PurRepository) Spoon.getInstance().getRepository()).getUnderlyingRepository()).canUnlockFileById(workingMeta.getObjectId()));
            } else {
                setLockingAllowed(repoLock.getLogin().equalsIgnoreCase(Spoon.getInstance().getRepository().getUserInfo().getLogin()));
            }
        } else {
            setLockingAllowed(true);
        }
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        firePropertyChange("activeMetaUnlocked", null, repoLock == null);
    } catch (Exception e) {
        // $NON-NLS-1$
        log.error(BaseMessages.getString(PKG, "LockController.NoLockingSupport"), e);
        new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), BaseMessages.getString(PKG, "Dialog.Error"), e.getMessage(), // $NON-NLS-1$
        e);
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) DefaultBindingFactory(org.pentaho.ui.xul.binding.DefaultBindingFactory) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) PurRepository(org.pentaho.di.repository.pur.PurRepository) UnifiedRepositoryLockService(org.pentaho.di.repository.pur.UnifiedRepositoryLockService) Spoon(org.pentaho.di.ui.spoon.Spoon) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException)

Example 4 with XulMenuitem

use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.

the class SpoonMenuLockController method updateMenu.

public void updateMenu(Document doc) {
    try {
        Spoon spoon = Spoon.getInstance();
        // If we are working with an Enterprise Repository
        if ((spoon != null) && (spoon.getRepository() != null) && (spoon.getRepository() instanceof PurRepository)) {
            ILockService service = getService(spoon.getRepository());
            EngineMetaInterface meta = spoon.getActiveMeta();
            // If (meta is not null) and (meta is either a Transformation or Job)
            if ((meta != null) && (meta instanceof ILockable)) {
                RepositoryLock repoLock = null;
                if (service != null && meta.getObjectId() != null) {
                    if (meta instanceof EEJobMeta) {
                        repoLock = service.getJobLock(meta.getObjectId());
                    } else {
                        repoLock = service.getTransformationLock(meta.getObjectId());
                    }
                }
                // If (there is a lock on this item) and (the UserInfo does not have permission to unlock this file)
                if (repoLock != null) {
                    if (!service.canUnlockFileById(meta.getObjectId())) {
                        // User does not have modify permissions on this file
                        // $NON-NLS-1$
                        ((XulToolbarbutton) doc.getElementById("toolbar-file-save")).setDisabled(true);
                        // $NON-NLS-1$
                        ((XulMenuitem) doc.getElementById("file-save")).setDisabled(true);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : EEJobMeta(org.pentaho.di.repository.pur.model.EEJobMeta) PurRepository(org.pentaho.di.repository.pur.PurRepository) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) Spoon(org.pentaho.di.ui.spoon.Spoon) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) XulToolbarbutton(org.pentaho.ui.xul.components.XulToolbarbutton) KettleException(org.pentaho.di.core.exception.KettleException) ILockable(org.pentaho.di.repository.pur.model.ILockable)

Example 5 with XulMenuitem

use of org.pentaho.ui.xul.components.XulMenuitem in project pentaho-kettle by pentaho.

the class SpoonMenuABSController method updateMenu.

public void updateMenu(Document doc) {
    try {
        Spoon spoon = Spoon.getInstance();
        boolean createPermitted = true;
        boolean executePermitted = true;
        // If we are working with an Enterprise Repository
        if ((spoon != null) && (spoon.getRepository() != null) && (spoon.getRepository() instanceof PurRepository)) {
            Repository repo = spoon.getRepository();
            // Check for ABS Security
            if (repo.hasService(IAbsSecurityProvider.class)) {
                IAbsSecurityProvider securityProvider = (IAbsSecurityProvider) repo.getService(IAbsSecurityProvider.class);
                // Get create & execute permission
                createPermitted = securityProvider.isAllowed(IAbsSecurityProvider.CREATE_CONTENT_ACTION);
                executePermitted = securityProvider.isAllowed(IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
                EngineMetaInterface meta = spoon.getActiveMeta();
                // If (meta is not null) and (meta is either a Transformation or Job)
                if ((meta != null) && ((meta instanceof JobMeta) || (meta instanceof TransMeta))) {
                    // 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);
                }
                // Handle Execute permissions
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("process-run")).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. Disable without execute permissions.
                // $NON-NLS-1$
                ((XulMenu) doc.getElementById("trans-last")).setDisabled(!executePermitted);
                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);
                // Schedule is a plugin
                if (doc.getElementById("trans-schedule") != null) {
                    // $NON-NLS-1$
                    ((XulMenuitem) doc.getElementById("trans-schedule")).setDisabled(!executePermitted);
                }
                TransGraph transGraph = Spoon.getInstance().getActiveTransGraph();
                if (transGraph != null) {
                    XulToolbar toolbar = transGraph.getToolbar();
                    XulToolbarbutton runButton = (XulToolbarbutton) toolbar.getElementById("trans-run");
                    XulToolbarbutton debugButton = (XulToolbarbutton) toolbar.getElementById("trans-debug");
                    XulToolbarbutton previewButton = (XulToolbarbutton) toolbar.getElementById("trans-preview");
                    XulToolbarbutton replayButton = (XulToolbarbutton) toolbar.getElementById("trans-replay");
                    XulToolbarbutton verifyButton = (XulToolbarbutton) toolbar.getElementById("trans-verify");
                    XulToolbarbutton impactButton = (XulToolbarbutton) toolbar.getElementById("trans-impact");
                    XulToolbarbutton generateSqlButton = (XulToolbarbutton) toolbar.getElementById("trans-get-sql");
                    if ((runButton != null) && (runButton.isDisabled() ^ !executePermitted)) {
                        runButton.setDisabled(!executePermitted);
                    }
                    if ((debugButton != null) && (debugButton.isDisabled() ^ !executePermitted)) {
                        debugButton.setDisabled(!executePermitted);
                    }
                    if ((previewButton != null) && (previewButton.isDisabled() ^ !executePermitted)) {
                        previewButton.setDisabled(!executePermitted);
                    }
                    if ((replayButton != null) && (replayButton.isDisabled() ^ !executePermitted)) {
                        replayButton.setDisabled(!executePermitted);
                    }
                    if ((verifyButton != null) && (verifyButton.isDisabled() ^ !executePermitted)) {
                        verifyButton.setDisabled(!executePermitted);
                    }
                    if ((impactButton != null) && (impactButton.isDisabled() ^ !executePermitted)) {
                        impactButton.setDisabled(!executePermitted);
                    }
                    if ((generateSqlButton != null) && (generateSqlButton.isDisabled() ^ !executePermitted)) {
                        generateSqlButton.setDisabled(!executePermitted);
                    }
                }
                JobGraph jobGraph = Spoon.getInstance().getActiveJobGraph();
                if (jobGraph != null) {
                    XulToolbar toolbar = jobGraph.getToolbar();
                    XulToolbarbutton runButton = (XulToolbarbutton) toolbar.getElementById("job-run");
                    XulToolbarbutton generateSqlButton = (XulToolbarbutton) toolbar.getElementById("job-get-sql");
                    if ((runButton != null) && (runButton.isDisabled() ^ !executePermitted)) {
                        runButton.setDisabled(!executePermitted);
                    }
                    if ((generateSqlButton != null) && (generateSqlButton.isDisabled() ^ !executePermitted)) {
                        generateSqlButton.setDisabled(!executePermitted);
                    }
                }
            }
        }
        EESpoonPlugin.updateChangedWarningDialog(createPermitted);
    } catch (Exception e) {
        // don't let this bomb all the way out, otherwise we'll get stuck: PDI-4670
        log.logError(e.getMessage(), e);
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) JobMeta(org.pentaho.di.job.JobMeta) XulToolbar(org.pentaho.ui.xul.containers.XulToolbar) PurRepository(org.pentaho.di.repository.pur.PurRepository) TransMeta(org.pentaho.di.trans.TransMeta) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) XulToolbarbutton(org.pentaho.ui.xul.components.XulToolbarbutton) XulMenu(org.pentaho.ui.xul.containers.XulMenu) Repository(org.pentaho.di.repository.Repository) PurRepository(org.pentaho.di.repository.pur.PurRepository) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) Spoon(org.pentaho.di.ui.spoon.Spoon) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface)

Aggregations

XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)20 KettleException (org.pentaho.di.core.exception.KettleException)6 XulException (org.pentaho.ui.xul.XulException)6 Spoon (org.pentaho.di.ui.spoon.Spoon)5 XulMenu (org.pentaho.ui.xul.containers.XulMenu)5 TransMeta (org.pentaho.di.trans.TransMeta)4 XulComponent (org.pentaho.ui.xul.XulComponent)4 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)3 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 Point (org.pentaho.di.core.gui.Point)3 JobMeta (org.pentaho.di.job.JobMeta)3 PurRepository (org.pentaho.di.repository.pur.PurRepository)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 Document (org.pentaho.ui.xul.dom.Document)3 Action (org.eclipse.jface.action.Action)2 Test (org.junit.Test)2 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)2 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)2 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)2