Search in sources :

Example 1 with SaveProgressDialog

use of org.pentaho.di.ui.spoon.dialog.SaveProgressDialog in project pentaho-kettle by pentaho.

the class Spoon method saveToRepositoryConfirmed.

public boolean saveToRepositoryConfirmed(EngineMetaInterface meta) throws KettleException {
    if (!Utils.isEmpty(meta.getName()) && rep != null) {
        ObjectId existingId = null;
        if (meta instanceof TransMeta) {
            existingId = rep.getTransformationID(meta.getName(), meta.getRepositoryDirectory());
        }
        if (meta instanceof JobMeta) {
            existingId = rep.getJobId(meta.getName(), meta.getRepositoryDirectory());
        }
        boolean saved = false;
        if (meta.getObjectId() == null) {
            meta.setObjectId(existingId);
        }
        try {
            shell.setCursor(cursor_hourglass);
            // created and or modified...
            if (meta.getCreatedDate() == null) {
                meta.setCreatedDate(new Date());
                if (capabilities.supportsUsers()) {
                    meta.setCreatedUser(rep.getUserInfo().getLogin());
                }
            }
            // Keep info on who & when this transformation was
            // changed...
            meta.setModifiedDate(new Date());
            if (capabilities.supportsUsers()) {
                meta.setModifiedUser(rep.getUserInfo().getLogin());
            }
            boolean versioningEnabled = true;
            boolean versionCommentsEnabled = true;
            String fullPath = getJobTransfFullPath(meta);
            RepositorySecurityProvider repositorySecurityProvider = rep != null && rep.getSecurityProvider() != null ? rep.getSecurityProvider() : null;
            if (repositorySecurityProvider != null && fullPath != null) {
                versioningEnabled = repositorySecurityProvider.isVersioningEnabled(fullPath);
                versionCommentsEnabled = repositorySecurityProvider.allowsVersionComments(fullPath);
            }
            // Finally before saving, ask for a version comment (if
            // applicable)
            // 
            String versionComment = null;
            boolean versionOk;
            if (!versioningEnabled || !versionCommentsEnabled) {
                versionOk = true;
                versionComment = "";
            } else {
                versionOk = false;
            }
            while (!versionOk) {
                versionComment = RepositorySecurityUI.getVersionComment(shell, rep, meta.getName(), fullPath, false);
                // if the version comment is null, the user hit cancel, exit.
                if (rep != null && rep.getSecurityProvider() != null && rep.getSecurityProvider().allowsVersionComments(fullPath) && versionComment == null) {
                    return false;
                }
                if (Utils.isEmpty(versionComment) && rep.getSecurityProvider().isVersioningEnabled(fullPath) && rep.getSecurityProvider().isVersionCommentMandatory()) {
                    if (!RepositorySecurityUI.showVersionCommentMandatoryDialog(shell)) {
                        // no, I don't want to enter a
                        return false;
                    // version comment and yes,
                    // it's mandatory.
                    }
                } else {
                    versionOk = true;
                }
            }
            if (versionOk) {
                SaveProgressDialog spd = new SaveProgressDialog(shell, rep, meta, versionComment);
                if (spd.open()) {
                    saved = true;
                    if (!props.getSaveConfirmation()) {
                        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "Spoon.Message.Warning.SaveOK"), null, BaseMessages.getString(PKG, "Spoon.Message.Warning.TransformationWasStored"), MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "Spoon.Message.Warning.OK") }, 0, BaseMessages.getString(PKG, "Spoon.Message.Warning.NotShowThisMessage"), props.getSaveConfirmation());
                        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
                        md.open();
                        props.setSaveConfirmation(md.getToggleState());
                    }
                    // Handle last opened files...
                    props.addLastFile(meta.getFileType(), meta.getName(), meta.getRepositoryDirectory().getPath(), true, getRepositoryName(), getUsername(), null);
                    saveSettings();
                    addMenuLast();
                    setShellText();
                }
            }
        } finally {
            shell.setCursor(null);
        }
        return saved;
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        // "There is no repository connection available."
        mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Message"));
        // "No repository available."
        mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Title"));
        mb.open();
    }
    return false;
}
Also used : RepositorySecurityProvider(org.pentaho.di.repository.RepositorySecurityProvider) JobMeta(org.pentaho.di.job.JobMeta) SaveProgressDialog(org.pentaho.di.ui.spoon.dialog.SaveProgressDialog) ObjectId(org.pentaho.di.repository.ObjectId) TransMeta(org.pentaho.di.trans.TransMeta) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Date(java.util.Date) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

Date (java.util.Date)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 JobMeta (org.pentaho.di.job.JobMeta)1 ObjectId (org.pentaho.di.repository.ObjectId)1 RepositorySecurityProvider (org.pentaho.di.repository.RepositorySecurityProvider)1 TransMeta (org.pentaho.di.trans.TransMeta)1 SaveProgressDialog (org.pentaho.di.ui.spoon.dialog.SaveProgressDialog)1