public IssueWorkflowAction(
            JiraIssue issue, JiraNamedEntity action, JiraIssueListModel model,
            List <JiraField> fields, StatusLabel status, Action onFinish)
        {
            this.issue  = issue;
            this.action = action;
            this.model  = model;
            this.fields = JiraActionFieldType.sortFieldList(fields);

            this.status   = status;
            this.onFinish = onFinish;

            InitializeComponent();

            Text = issue.Key + ": " + action.Name;

            ClientSize = new Size(INITIAL_WIDTH, INITIAL_HEIGHT + buttonOk.Height + 3 * MARGIN);

            buttonOk.Enabled = false;

            StartPosition = FormStartPosition.CenterParent;

            panelThrobber.Visible = true;
            panelContent.Visible  = false;
        }
        private void getMetadata()
        {
            PlvsLogger.log("FieldEditor.getMetadata()");

            object           rawIssueObject = facade.getRawIssueObject(issue);
            List <JiraField> filledFields   = JiraActionFieldType.fillFieldValues(issue, rawIssueObject, new List <JiraField> {
                field
            });

            field = filledFields[0];
            field.setRawIssueObject(rawIssueObject);

            SortedDictionary <string, JiraProject> projects = JiraServerCache.Instance.getProjects(issue.Server);

            if (!projects.ContainsKey(issue.ProjectKey))
            {
                return;
            }

            JiraProject project = projects[issue.ProjectKey];

            // todo: these are not always necessary. refactor to make it more efficient and smart
            List <JiraNamedEntity> versions = facade.getVersions(issue.Server, project);

            versions.Reverse();
            List <JiraNamedEntity> comps = facade.getComponents(issue.Server, project);

            this.safeInvoke(new MethodInvoker(() => createEditorWidget(versions, comps, rawIssueObject)));
        }
Example #3
0
        private static void runAction(Control owner, JiraNamedEntity action, JiraIssueListModel model,
                                      JiraIssue issue, List <JiraField> fields, StatusLabel status, Action onFinish)
        {
            JiraIssue issueWithTime = SmartJiraServerFacade.Instance.getIssue(issue.Server, issue.Key);

            issueWithTime.SecurityLevel = SmartJiraServerFacade.Instance.getSecurityLevel(issue);
            object           rawIssueObject   = SmartJiraServerFacade.Instance.getRawIssueObject(issue);
            List <JiraField> fieldsWithValues = JiraActionFieldType.fillFieldValues(issue, rawIssueObject, fields);

            // PLVS-133 - this should never happen but does?
            if (model == null)
            {
                owner.Invoke(new MethodInvoker(()
                                               =>
                                               PlvsUtils.showError("Issue List Model was null, please report this as a bug",
                                                                   new Exception("IssueActionRunner.runAction()"))));
                model = JiraIssueListModelImpl.Instance;
            }

            if (fieldsWithValues == null || fieldsWithValues.Count == 0)
            {
                runActionWithoutFields(owner, action, model, issue, status, onFinish);
            }
            else
            {
                owner.Invoke(new MethodInvoker(() =>
                                               new IssueWorkflowAction(issue, action, model, fieldsWithValues, status, onFinish).initAndShowDialog()));
            }
        }
        private void fillFields()
        {
            List <JiraField> unsupportedFields = new List <JiraField>();

            foreach (JiraField field in fields)
            {
                JiraFieldEditorProvider editor = null;
                switch (JiraActionFieldType.getFieldTypeForField(field))
                {
                case JiraActionFieldType.WidgetType.SUMMARY:
                    editor = new TextLineFieldEditorProvider(field, field.Values.IsNullOrEmpty() ? "" : field.Values[0], fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.DESCRIPTION:
                    editor = new TextAreaFieldEditorProvider(SmartJiraServerFacade.Instance, issue, field, field.Values.IsNullOrEmpty() ? "" : field.Values[0], fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.ENVIRONMENT:
                    editor = new TextAreaFieldEditorProvider(SmartJiraServerFacade.Instance, issue, field, field.Values.IsNullOrEmpty() ? "" : field.Values[0], fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.ISSUE_TYPE:
                    editor = new NamedEntityComboEditorProvider(issue.Server, field, issue.IssueTypeId, issue.IsSubtask ? subtaskIssueTypes : issueTypes, fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.VERSIONS:
                    editor = new NamedEntityListFieldEditorProvider(field, issue.Versions, versions, fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.FIX_VERSIONS:
                    editor = new NamedEntityListFieldEditorProvider(field, issue.FixVersions, versions, fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.ASSIGNEE:
                    editor = new UserFieldEditorProvider(issue.Server, field, field.Values.IsNullOrEmpty() ? "" : field.Values[0], fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.REPORTER:
                    editor = new UserFieldEditorProvider(issue.Server, field, field.Values.IsNullOrEmpty() ? "" : field.Values[0], fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.DUE_DATE:
                    editor = new DateFieldEditorProvider(issue.ServerLanguage, field, field.Values.IsNullOrEmpty()
                                                                        ? (DateTime?)null
                                                                        : JiraIssueUtils.getDateTimeFromShortString(issue.ServerLanguage, field.Values[0]), fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.COMPONENTS:
                    editor = new NamedEntityListFieldEditorProvider(field, issue.Components, comps, fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.RESOLUTION:
                    SortedDictionary <int, JiraNamedEntity> resolutions = JiraServerCache.Instance.getResolutions(issue.Server);
                    editor = new ResolutionEditorProvider(issue.Server, field, issue.ResolutionId, resolutions != null ? resolutions.Values : null, fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.PRIORITY:
                    editor = new NamedEntityComboEditorProvider(issue.Server, field, issue.PriorityId, JiraServerCache.Instance.getPriorities(issue.Server), fieldValid);
                    break;

                case JiraActionFieldType.WidgetType.TIMETRACKING:
                    editor = new TimeTrackingEditorProvider(field, field.Values.IsNullOrEmpty() ? "" : field.Values[0], fieldValid);
                    break;

// ReSharper disable RedundantCaseLabel
                case JiraActionFieldType.WidgetType.SECURITY:
                case JiraActionFieldType.WidgetType.UNSUPPORTED:
// ReSharper restore RedundantCaseLabel
                default:
                    if (!JiraActionFieldType.isTimeField(field))
                    {
                        unsupportedFields.Add(field);
                    }
                    break;
                }

                if (editor == null)
                {
                    continue;
                }

                addLabel(editor.getFieldLabel(issue, field));

                editor.Widget.Location = new Point(FIELD_X_POS, verticalPosition);
                editor.Widget.TabIndex = tabIndex++;

                panelContent.Controls.Add(editor.Widget);
                verticalPosition += editor.VerticalSkip + MARGIN / 2;
                editors.Add(editor);
            }

            if (unsupportedFields.Count == 0)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("Unsupported fields (existing values copied): ");
            foreach (var field in unsupportedFields)
            {
                sb.Append(field.Name).Append(", ");
            }
            textUnsupported = new TextBox
            {
                Multiline   = true,
                BorderStyle = BorderStyle.None,
                ReadOnly    = true,
                WordWrap    = true,
                Text        = sb.ToString().Substring(0, sb.Length - 2),
            };
        }
        private void createEditorWidget(IEnumerable <JiraNamedEntity> versions, IEnumerable <JiraNamedEntity> comps, object rawIssueObject)
        {
            PlvsLogger.log("FieldEditor.createEditorWidget()");

            switch (JiraActionFieldType.getFieldTypeForFieldId(fieldId))
            {
            case JiraActionFieldType.WidgetType.SUMMARY:
                editorProvider = new TextLineFieldEditorProvider(field, issue.Summary, fieldValid);
                break;

            case JiraActionFieldType.WidgetType.DESCRIPTION:
                string descr = JiraIssueUtils.getRawIssueObjectPropertyValue <string>(rawIssueObject, "description") ?? "";
                editorProvider = new TextAreaFieldEditorProvider(facade, issue, field, descr, fieldValid);
                break;

            case JiraActionFieldType.WidgetType.ENVIRONMENT:
                string env = JiraIssueUtils.getRawIssueObjectPropertyValue <string>(rawIssueObject, "environment") ?? "";
                editorProvider = new TextAreaFieldEditorProvider(facade, issue, field, env, fieldValid);
                break;

            case JiraActionFieldType.WidgetType.VERSIONS:
                editorProvider = new NamedEntityListFieldEditorProvider(field, issue.Versions, versions, fieldValid);
                break;

            case JiraActionFieldType.WidgetType.FIX_VERSIONS:
                editorProvider = new NamedEntityListFieldEditorProvider(field, issue.FixVersions, versions, fieldValid);
                break;

            case JiraActionFieldType.WidgetType.ASSIGNEE:
                editorProvider = new UserFieldEditorProvider(issue.Server, field,
                                                             field.Values.IsNullOrEmpty() ? "" : field.Values[0], fieldValid, true);
                break;

            case JiraActionFieldType.WidgetType.COMPONENTS:
                editorProvider = new NamedEntityListFieldEditorProvider(field, issue.Components, comps, fieldValid);
                break;

            case JiraActionFieldType.WidgetType.PRIORITY:
                editorProvider = new NamedEntityComboEditorProvider(issue.Server, field, issue.PriorityId,
                                                                    JiraServerCache.Instance.getPriorities(issue.Server),
                                                                    fieldValid);
                break;

            case JiraActionFieldType.WidgetType.TIMETRACKING:
                List <JiraField> fields = JiraActionFieldType.fillFieldValues(issue, rawIssueObject, new List <JiraField> {
                    field
                });
                editorProvider = new TimeTrackingEditorProvider(field, fields[0].Values[0], fieldValid);
                break;

            default:
                MessageBox.Show("Unsupported field type selected for editing",
                                Constants.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                break;
            }

            buttonCancel.Enabled = true;
            buttonOk.Enabled     = editorProvider != null ? editorProvider.FieldValid : false;
            if (editorProvider != null)
            {
                addEditorWidget(editorProvider);
            }
        }