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