Search in sources :

Example 1 with PurRepositoryDialog

use of org.pentaho.di.ui.repository.pur.PurRepositoryDialog in project pentaho-kettle by pentaho.

the class EESpoonPlugin method warnClosingOfOpenTabsBasedOnPerms.

private void warnClosingOfOpenTabsBasedOnPerms(Spoon spoon) throws KettleException {
    Class<PurRepositoryDialog> PKG = PurRepositoryDialog.class;
    // Check to see if there are any open jobs/trans
    Repository repository = spoon.getRepository();
    if (spoon.getActiveMeta() == null) {
        return;
    }
    String warningTitle = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Title");
    String warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message");
    String additionalWarningText = "";
    int buttons = SWT.OK;
    IAbsSecurityProvider absSecurityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
    if (absSecurityProvider != null) {
        boolean createPerms = false;
        boolean executePerms = false;
        boolean readPerms = false;
        try {
            createPerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.CREATE_CONTENT_ACTION);
            executePerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
            readPerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.READ_CONTENT_ACTION);
        } catch (KettleException e) {
        // No nothing - we are just checking perms
        }
        // Check to see if display of warning dialog has been disabled
        if (readPerms && createPerms && executePerms) {
            warningTitle = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Title");
            warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Message");
            buttons = SWT.YES | SWT.NO | SWT.ICON_INFORMATION;
        } else {
            warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Message");
            if (createPerms) {
                additionalWarningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForceAdditional.Connect.Message");
                buttons = SWT.YES | SWT.NO | SWT.ICON_WARNING;
            } else {
                additionalWarningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message");
                buttons = SWT.OK | SWT.ICON_WARNING;
            }
        }
    }
    MessageBox mb = new MessageBox(spoon.getShell(), buttons);
    mb.setMessage(additionalWarningText.length() != 0 ? warningText + "\n\n" + additionalWarningText : warningText);
    mb.setText(warningTitle);
    final int isCloseAllFiles = mb.open();
    // Otherwise, we force close the tabs
    if ((isCloseAllFiles == SWT.YES) || (isCloseAllFiles == SWT.OK)) {
        spoon.closeAllFiles();
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) KettleException(org.pentaho.di.core.exception.KettleException) PurRepository(org.pentaho.di.repository.pur.PurRepository) Repository(org.pentaho.di.repository.Repository) PurRepositoryDialog(org.pentaho.di.ui.repository.pur.PurRepositoryDialog) XulMessageBox(org.pentaho.ui.xul.components.XulMessageBox) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

MessageBox (org.eclipse.swt.widgets.MessageBox)1 KettleException (org.pentaho.di.core.exception.KettleException)1 Repository (org.pentaho.di.repository.Repository)1 PurRepository (org.pentaho.di.repository.pur.PurRepository)1 PurRepositoryDialog (org.pentaho.di.ui.repository.pur.PurRepositoryDialog)1 IAbsSecurityProvider (org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider)1 XulMessageBox (org.pentaho.ui.xul.components.XulMessageBox)1