Search in sources :

Example 1 with Increment

use of com.centurylink.mdw.plugin.designer.model.Versionable.Increment in project mdw-designer by CenturyLinkCloud.

the class ProcessSaveDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.getShell().setText("Save Process");
    String msg = "'" + process.getName() + "'";
    if (respondingToClose)
        msg += " has been modified.  Save changes?";
    new Label(composite, SWT.NONE).setText(msg);
    // MDW3
    String oldEmbedded = getProcess().getAttribute("process_old_embedded");
    Group radioGroup = new Group(composite, SWT.NONE);
    radioGroup.setText("Process Version to Save");
    GridLayout gl = new GridLayout();
    radioGroup.setLayout(gl);
    GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
    radioGroup.setLayoutData(gd);
    overwriteButton = new Button(radioGroup, SWT.RADIO | SWT.LEFT);
    if (oldEmbedded != null || !allowForceUpdate)
        overwriteButton.setEnabled(false);
    overwriteButton.setText("Overwrite current version: " + process.getVersionString());
    overwriteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            versionButtonSelected(e);
        }
    });
    newMinorButton = new Button(radioGroup, SWT.RADIO | SWT.LEFT);
    newMinorButton.setText("Save as new minor version: " + process.getNewVersionString(false));
    newMinorButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            versionButtonSelected(e);
        }
    });
    newMajorButton = new Button(radioGroup, SWT.RADIO | SWT.LEFT);
    newMajorButton.setText("Save as new major version: " + process.getNewVersionString(true));
    newMajorButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            versionButtonSelected(e);
        }
    });
    if (oldEmbedded != null)
        new Label(composite, SWT.NONE).setText("This process contains MDW 3.* subprocesses.\nYou must save it as a new version.");
    IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
    String prefsIncrement = prefsStore.getString(PreferenceConstants.PREFS_PROCESS_SAVE_INCREMENT);
    boolean rememberSelection = !prefsIncrement.isEmpty();
    if (prefsIncrement.isEmpty())
        prefsIncrement = Increment.Minor.toString();
    Increment increment = Increment.valueOf(prefsIncrement);
    if (increment == Increment.Overwrite)
        overwriteButton.setSelection(true);
    else if (increment == Increment.Major)
        newMajorButton.setSelection(true);
    else
        newMinorButton.setSelection(true);
    rememberSelectionCheckbox = new Button(composite, SWT.CHECK);
    rememberSelectionCheckbox.setText("Remember this selection for future saves");
    rememberSelectionCheckbox.setSelection(rememberSelection);
    enforceValidationCheckbox = new Button(composite, SWT.CHECK);
    enforceValidationCheckbox.setText("Enforce process validation rules");
    enforceValidationCheckbox.setSelection(prefsStore.getBoolean(PreferenceConstants.PREFS_ENFORCE_PROCESS_VALIDATION_RULES));
    if (process.getProject().isFilePersist()) {
        boolean overwrite = overwriteButton.getSelection();
        // override attributes
        carryOverrideAttributesCheckbox = new Button(composite, SWT.CHECK);
        carryOverrideAttributesCheckbox.setText("Carry forward override attributes");
        boolean enabled = process.overrideAttributesApplied() && !overwrite;
        boolean checked = overwrite ? true : process.overrideAttributesApplied();
        enableCarryOverrideAttrs(enabled, checked);
        carryOverrideAttributesCheckbox.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (carryOverrideAttributesCheckbox.getSelection()) {
                    WarningTray tray = getWarningTray();
                    if (tray.getMessage().startsWith("Any override attributes")) {
                        tray.close();
                        getButton(Dialog.OK).setText(respondingToClose ? "Save" : "OK");
                    }
                }
            }
        });
    } else {
        keepLockedCheckbox = new Button(composite, SWT.CHECK);
        keepLockedCheckbox.setText("Keep process locked after saving");
        keepLockedCheckbox.setSelection(prefsStore.getBoolean(PreferenceConstants.PREFS_KEEP_PROCESSES_LOCKED_WHEN_SAVING));
    }
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Increment(com.centurylink.mdw.plugin.designer.model.Versionable.Increment) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 2 with Increment

use of com.centurylink.mdw.plugin.designer.model.Versionable.Increment in project mdw-designer by CenturyLinkCloud.

the class TaskTemplateEditor method saveDialog.

private int saveDialog(boolean closeButton) {
    VersionableSaveDialog saveDlg = new VersionableSaveDialog(getSite().getShell(), taskTemplate, closeButton);
    int result = saveDlg.open();
    if (result == VersionableSaveDialog.CANCEL)
        return result;
    try {
        if (result == VersionableSaveDialog.CLOSE_WITHOUT_SAVE) {
            // refresh from file
            String content = new String(PluginUtil.readFile(taskTemplate.getFile()));
            TaskVO taskVO;
            if (content.trim().startsWith("{")) {
                taskVO = new TaskVO(new JSONObject(content));
            } else {
                TaskTemplateDocument docx = TaskTemplateDocument.Factory.parse(content);
                taskVO = new TaskVO(docx.getTaskTemplate());
            }
            taskVO.setName(taskTemplate.getName());
            taskVO.setTaskId(taskTemplate.getId());
            taskVO.setPackageName(taskTemplate.getPackage().getName());
            taskTemplate.setTaskVO(taskVO);
            taskTemplate.setDirty(false);
            return result;
        } else // save the template
        {
            // clean out units attrs
            taskTemplate.removeAttribute("TaskSLA_UNITS");
            taskTemplate.removeAttribute("ALERT_INTERVAL_UNITS");
            Increment versionIncrement = saveDlg.getVersionIncrement();
            String pkgMeta = taskTemplate.getPackage().getMetaContent();
            if (pkgMeta != null && pkgMeta.trim().startsWith("{")) {
                taskTemplate.setContent(taskTemplate.getTaskVO().getJson().toString(2));
            } else {
                TaskTemplateDocument doc = TaskTemplateDocument.Factory.newInstance();
                doc.setTaskTemplate(taskTemplate.getTaskVO().toTemplate());
                XmlOptions xmlOptions = new XmlOptions().setSaveAggressiveNamespaces();
                xmlOptions.setSavePrettyPrint().setSavePrettyPrintIndent(2);
                taskTemplate.setContent(doc.xmlText(xmlOptions));
            }
            taskTemplate.ensureFileWritable();
            InputStream is = new ByteArrayInputStream(taskTemplate.getContent().getBytes());
            taskTemplate.getAssetFile().setContents(is, true, true, new NullProgressMonitor());
            if (versionIncrement != Increment.Overwrite) {
                taskTemplate.setVersion(versionIncrement == Increment.Major ? taskTemplate.getNextMajorVersion() : taskTemplate.getNextMinorVersion());
                taskTemplate.setRevisionComment(saveDlg.getVersionComment());
                taskTemplate.getProject().getDesignerProxy().saveWorkflowAssetWithProgress(taskTemplate, false);
                taskTemplate.fireElementChangeEvent(ChangeType.VERSION_CHANGE, taskTemplate.getVersion());
            }
            dirtyStateChanged(false);
            if (!taskTemplate.getProject().isRemote())
                taskTemplate.getProject().getDesignerProxy().getCacheRefresh().fireRefresh(false);
            return result;
        }
    } catch (Exception ex) {
        PluginMessages.uiError(getSite().getShell(), ex, "Save Task Template", taskTemplate.getProject());
        return VersionableSaveDialog.CANCEL;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionableSaveDialog(com.centurylink.mdw.plugin.designer.dialogs.VersionableSaveDialog) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Increment(com.centurylink.mdw.plugin.designer.model.Versionable.Increment) XmlOptions(org.apache.xmlbeans.XmlOptions) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException)

Example 3 with Increment

use of com.centurylink.mdw.plugin.designer.model.Versionable.Increment in project mdw-designer by CenturyLinkCloud.

the class ProcessSaveDialog method okPressed.

@Override
protected void okPressed() {
    String warning = null;
    if (overwriteButton.getSelection() && !getButton(Dialog.OK).getText().equals("Force Update") && !getButton(Dialog.OK).getText().equals("Force Save") && hasInstances()) {
        warning = INSTANCES_MESSAGE + "\n\n" + "It is recommended that you increment the version when saving\n" + "rather than overwriting the existing version.  Otherwise Designer\n" + "may not correctly display previous incompatible instances.\n\n" + "To update the existing version, click 'Force Update' to confirm.";
        getButton(Dialog.OK).setText("Force Update");
    } else if (!getButton(Dialog.OK).getText().equals("Force Save") && process.getProject().isProduction()) {
        warning = "This process is for project '" + getProcess().getProject().getSourceProjectName() + "',\nwhich is flagged as a production environment.\n\nPlease click 'Force Save' to confirm.\n\nThis action will be audit logged.";
        getButton(Dialog.OK).setText("Force Save");
    } else if (MdwPlugin.getSettings().isWarnOverrideAttrsNotCarriedForward() && process.getProject().isFilePersist() && !overwriteButton.getSelection() && !carryOverrideAttributesCheckbox.getSelection() && !getButton(Dialog.OK).getText().equals("Save Anyway")) {
        warning = "Any override attributes will not be carried forward";
        if (!process.overrideAttributesApplied())
            warning += "\n(server not running when process loaded).";
        else
            warning += ".";
        getButton(Dialog.OK).setText("Save Anyway");
    }
    if (warning != null) {
        WarningTray tray = getWarningTray();
        tray.setMessage(warning);
        tray.open();
        return;
    }
    if (overwriteButton.getSelection()) {
        if (getButton(Dialog.OK).getText().equals("Force Update"))
            setReturnCode(FORCE_UPDATE);
        else
            setReturnCode(OVERWRITE);
    } else {
        if (newMinorButton.getSelection())
            version = process.getNewVersion(false);
        else if (newMajorButton.getSelection())
            version = process.getNewVersion(true);
        setReturnCode(NEW_VERSION);
    }
    IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
    if (rememberSelectionCheckbox.getSelection()) {
        Increment increment = Increment.Minor;
        if (newMajorButton.getSelection())
            increment = Increment.Major;
        else if (overwriteButton.getSelection())
            increment = Increment.Overwrite;
        prefsStore.setValue(PreferenceConstants.PREFS_PROCESS_SAVE_INCREMENT, increment.toString());
    } else {
        prefsStore.setValue(PreferenceConstants.PREFS_PROCESS_SAVE_INCREMENT, "");
    }
    prefsStore.setValue(PreferenceConstants.PREFS_ENFORCE_PROCESS_VALIDATION_RULES, enforceValidationCheckbox.getSelection());
    if (!process.getProject().isFilePersist())
        prefsStore.setValue(PreferenceConstants.PREFS_KEEP_PROCESSES_LOCKED_WHEN_SAVING, keepLockedCheckbox.getSelection());
    if (carryOverrideAttributesCheckbox != null)
        prefsStore.setValue(PreferenceConstants.PREFS_CARRY_FORWARD_OVERRIDE_ATTRS, carryOverrideAttributesCheckbox.getSelection());
    close();
}
Also used : Increment(com.centurylink.mdw.plugin.designer.model.Versionable.Increment) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

Increment (com.centurylink.mdw.plugin.designer.model.Versionable.Increment)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)1 VersionableSaveDialog (com.centurylink.mdw.plugin.designer.dialogs.VersionableSaveDialog)1 TaskTemplateDocument (com.centurylink.mdw.task.TaskTemplateDocument)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 PartInitException (org.eclipse.ui.PartInitException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1