private void LoadNewActionData(IResourceAction resourceAction) { ActionObjectDefinition aoDef = new ActionObjectDefinition(resourceAction.Name); aoDef.AssemblyName = resourceAction.Assembly; aoDef.ClassName = resourceAction.ActionClass; aoDef.Precedence = resourceAction.Sequence; aoDef.ActionName = resourceAction.Name; aoDef.AllowTransparent = m_allowTransparent && resourceAction.AllowTransparent; aoDef.PropertySetLayout = resourceAction.PropertySetLayout; if (aoDef.ActionName.Length == 0) { string[] strs = (resourceAction.Name).Split(new Char[] { '.' }); aoDef.ActionName = strs[strs.Length - 1]; } foreach (IResourceActionProperty resourceActionProperty in resourceAction.Properties) { try { ActionDataElement ade = new ActionDataElement(); ade.Override = resourceActionProperty.Override; //false; ade.Visible = resourceActionProperty.Visible; //true; if (resourceActionProperty.MappedSystemProperty != null) { ade.IsDataSource = true; ade.IsSystemProperty = true; ade.MappedSystemProperty = resourceActionProperty.MappedSystemProperty; } else { ade.IsDataSource = false; ade.IsSystemProperty = false; } ade.IsCustomProperty = resourceActionProperty.CustomProperty; ade.Value = resourceActionProperty.Value; ade.Name = resourceActionProperty.Name; ade.DisplayName = resourceActionProperty.DefaultDisplayName; ade.Identifier = Guid.NewGuid(); ade.ShowInUI = ShowPropertyInUIForType(resourceAction.Name, resourceActionProperty.Name); ade.IsCustomDisplayType = resourceActionProperty.DisplayType == PropertyDisplayType.CustomUI; aoDef.ActionProperties[ade.Identifier] = ade; aoDef.AutoExpand = resourceAction.AutoExpand; aoDef.CustomDataTypeUIHandler = resourceAction.CustomDataTypeUI; aoDef.ExecutionOption = resourceAction.ExecutionOption; } catch (ArgumentException ex) { Logger.LogError(string.Format(CultureInfo.CurrentCulture, Properties.Resources.ACTION_UNSUPPORTED_ERROR, ex.Message)); Logger.LogError(ex); ShowUnsupportedTypeMessageBox(); } } AddBaseFileTypes(ref aoDef); m_actions[aoDef.ActionName] = aoDef; }
private void AddBaseFileTypes(ref ActionObjectDefinition aoDef) { ISupportedFilesSet fileTypes = GetSupportedFileCollectionSettingFromResourceActionForType(aoDef.Type); if (fileTypes != null) { foreach (string type in fileTypes.SupportedFiles()) { ActionFileTypeObject aft = new ActionFileTypeObject(); aft.Identifier = Guid.NewGuid(); aft.Filetype = FileTypeBridge.GetFileType(type); aft.Apply = true; aoDef.FileTypes[type] = aft; } } }
/// <summary> /// Updates the check state and visibility of cbProcessTransparently, after a combo selection change /// </summary> /// <param name="def"></param> private void UpdateTransparentCheckbox(ActionObjectDefinition def) { cbProcessTransparently.Checked = false; cbProcessTransparently.Visible = def.AllowTransparent; }
private void UpdateExecutionOptionsCombo(ActionObjectDefinition def) { ExecutionOption = def.ExecutionOption; PopulateExecutionOptionControl(); }
//TODO: fix for unsupported file types private void UpdateFileTypesListView(ActionObjectDefinition aoDef) { fileTypesListView.BeginUpdate(); fileTypesListView.Items.Clear(); IDictionaryEnumerator propEnumerator = aoDef.FileTypes.GetEnumerator(); while (propEnumerator.MoveNext()) { AddFileTypeRow((ActionFileTypeObject)propEnumerator.Value); } fileTypesListView.Columns[0].Width = fileTypesListView.ClientSize.Width - SystemInformation.VerticalScrollBarWidth; //if (GetResourceActionForType(aoDef.Type).SupportedFileCollectionSetting.IsNonSupportedCollection) // fileTypesLabel.Text = Properties.Resources.NON_SUPPORTED_FILES; //else fileTypesLabel.Text = Properties.Resources.SUPPORTED_FILES; fileTypesListView.EndUpdate(); }
private bool ActionHasSelectAllCheckBox(ActionObjectDefinition aoDef) { if (null == aoDef.PropertySetLayout) { return false; } else { return aoDef.PropertySetLayout.ShowSelectAll; } }
private void UpdateComboBoxRunAt(ActionObjectDefinition aoDef) { //TODO: make this more robust RunAt[] runAts = GetRunAtFromResourceActionForType(aoDef.Type); comboBoxRunAt.Items.Clear(); if (1 == runAts.Length) { comboBoxRunAt.Items.Add(ConvertRunAt(runAts[0])); comboBoxRunAt.SelectedIndex = 0; } else if (2 == runAts.Length) { comboBoxRunAt.Items.Add(ConvertRunAt(Workshare.Policy.RunAt.Client)); comboBoxRunAt.Items.Add(ConvertRunAt(Workshare.Policy.RunAt.Server)); comboBoxRunAt.Items.Add(ConvertRunAt(Workshare.Policy.RunAt.Both)); if (OpenForEdit) { switch (aoDef.RunAt) { case RunAt.Client: comboBoxRunAt.SelectedIndex = 0; break; case RunAt.Server: comboBoxRunAt.SelectedIndex = 1; break; case RunAt.Both: comboBoxRunAt.SelectedIndex = 2; break; } } else { comboBoxRunAt.SelectedIndex = 0; } } }
private bool AddCheckAllItem(ActionObjectDefinition aoDef) { Color backColour = DefaultBackColor; int col = 1; int row = 0; ListViewItem item = actionOptionsListView.Items.Add(Properties.Resources.SELECTALL); if(item == null) return false; item.Tag = "Select All";//used internally only not visible to user item.BackColor = backColour; item.UseItemStyleForSubItems = true; item.SubItems.Add("value"); bool selectAllValue = true; bool selectAllOverride = true; bool selectAllVisible = true; foreach (KeyValuePair<Guid, ActionDataElement> kvp in aoDef.ActionProperties) { if (kvp.Value.Value is bool) { if ((bool)kvp.Value.Value == false) { selectAllValue = false; } } if (!kvp.Value.Override) { selectAllOverride = false; } if (!kvp.Value.Visible) { selectAllVisible = false; } if (!selectAllValue && !selectAllOverride && !selectAllVisible) { break; } } Control embeddedControl = actionOptionsListView.AddEmbeddedWithValue(selectAllValue, col, row) as CheckBox; if(embeddedControl != null) embeddedControl.BackColor = backColour; col++; item.SubItems.Add("override"); embeddedControl = actionOptionsListView.AddEmbeddedWithValue(selectAllOverride, col, row); if(embeddedControl != null) embeddedControl.BackColor = backColour; col++; item.SubItems.Add("visible"); embeddedControl = actionOptionsListView.AddEmbeddedWithValue(selectAllVisible, col, row); if(embeddedControl != null) embeddedControl.BackColor = backColour; item = actionOptionsListView.Items.Add("separator"); item.Tag = "Separator"; item.Text = " ";//deliberate ListViewItem.ListViewSubItem lsi = item.SubItems.Add("value"); lsi.Text = " "; lsi = item.SubItems.Add("override"); lsi.Text = " "; lsi = item.SubItems.Add("visible"); lsi.Text = " "; return true; }
private void UpdateActionListView(ActionObjectDefinition aoDef) { actionOptionsListView.BeginUpdate(); m_nonDisplayedActionDataElements.Clear(); m_displayedActionDataElements.Clear(); actionOptionsListView.RemoveAllItemsAndControls(); actionOptionsListView.Items.Clear(); actionOptionsListView.Columns.Clear(); SetColumnsAndWidths(aoDef); int row = 0; //if (aoDef.ActionProperties.Count > 12) // actionOptionsListView.Columns[0].Width -= SystemInformation.VerticalScrollBarWidth; bool checkAllAdded = false; if (ActionHasSelectAllCheckBox(aoDef)) { checkAllAdded = AddCheckAllItem(aoDef); if(checkAllAdded) row += 2; } foreach (Guid key in aoDef.ActionProperties.Keys) { ActionDataElement actionDataElement = aoDef.ActionProperties[key]; if (!actionDataElement.ShowInUI) { //keep a list of non-displayable properties - we need these again when we exit //the form and update the IAction data m_nonDisplayedActionDataElements[aoDef.ActionProperties[key].Identifier] = actionDataElement; continue; } ActionUIItem actionItem = new ActionUIItem(GetResourceActionForType(aoDef.Type)); m_displayedActionDataElements[aoDef.ActionProperties[key].Identifier] = actionDataElement; int col = 0; string name = aoDef.ActionProperties[key].DisplayName; ListViewItem item = actionOptionsListView.Items.Add(name); item.Tag = aoDef.ActionProperties[key].Identifier; item.Text = actionItem.GetTextForProperty(name); col++; if (col < actionOptionsListView.Columns.Count) { item.SubItems.Add("value"); if (aoDef.ActionProperties[key].IsCustomDisplayType) { Control c = actionOptionsListView.AddCustomUIHandlerButton(aoDef.ActionProperties[key], col, row); c.Tag = aoDef; } else actionOptionsListView.AddEmbeddedWithValue(aoDef.ActionProperties[key].Value, col, row); Control embeddedControl = actionOptionsListView.GetEmbeddedControl(col, row); if (embeddedControl.GetType() == typeof(CheckBox)) { ((CheckBox)embeddedControl).CheckedChanged += checkValue_Clicked; } if (embeddedControl.GetType() == typeof(DateTimePicker)) { ((DateTimePicker)embeddedControl).ValueChanged += dateTime_ValueChanged; } if (embeddedControl.GetType() == typeof(TextBox) && item.Text == "Password") { ((TextBox)embeddedControl).TextChanged += password_Changed; } if (embeddedControl.GetType() == typeof(CheckedListBox)) { AdjustRowHeight(); } col++; } if (col < actionOptionsListView.Columns.Count) { item.SubItems.Add("override"); actionOptionsListView.AddEmbeddedWithValue(aoDef.ActionProperties[key].Override, col, row); CheckBox checkBox = actionOptionsListView.GetEmbeddedControl(col, row) as CheckBox; if (checkBox != null) checkBox.CheckedChanged += checkOverride_Clicked; col++; } if (col < actionOptionsListView.Columns.Count) { item.SubItems.Add("visible"); actionOptionsListView.AddEmbeddedWithValue(aoDef.ActionProperties[key].Visible, col, row); CheckBox checkBox = actionOptionsListView.GetEmbeddedControl(col, row) as CheckBox; if (checkBox != null) checkBox.CheckedChanged += checkVisible_Clicked; col++; } row++; } //this is bad, but haven't got time at the moment to make it better... if (actionOptionsListView.Items.Count > 8) { actionOptionsListView.Columns[0].Width -= SystemInformation.VerticalScrollBarWidth; } actionOptionsListView.EndUpdate(); if(checkAllAdded) SetCheckAllEventHandlers(); }
private void SetColumnsAndWidths(ActionObjectDefinition aoDef) { int width = actionOptionsListView.Width - (SystemInformation.Border3DSize.Width * 6); ColumnLayoutStyle colStyle = ColumnLayoutStyle.Default; if (aoDef.PropertySetLayout != null) { colStyle = aoDef.PropertySetLayout.ColumnLayoutStyle; } if (colStyle == ColumnLayoutStyle.Basic) { actionOptionsListView.Columns.AddRange(new ColumnHeader[] { columnName, columnValue}); actionOptionsListView.Columns[0].Width = (width / 3); actionOptionsListView.Columns[1].Width = (width * 2 / 3); } else { actionOptionsListView.Columns.AddRange(new ColumnHeader[] { columnName, columnValue, columnOverride, columnVisible}); actionOptionsListView.Columns[0].Width = (width / 2); actionOptionsListView.Columns[1].Width = (width / 5); actionOptionsListView.Columns[2].Width = (width / 6); actionOptionsListView.Columns[3].Width = (width / 7); } }
private void LoadForEdit() { try { IResourceAction resourceAction = AddActionState.GetResourcesForAction(m_resourceManager, InitialAction); string type = InitialAction[LanguageItemKeys.TYPE].Value; if ( (null == resourceAction) || (string.IsNullOrEmpty(type)) ) { ShowEditActionNotInstalledMessageBox(InitialAction.Name.Value); ExitForm(); return; } ActionObjectDefinition aoDef = new ActionObjectDefinition(type); aoDef.AssemblyName = InitialAction.Assembly; aoDef.ClassName = InitialAction.Class; aoDef.ActionName = InitialAction.Name.Value; aoDef.Precedence = InitialAction.Precedence; aoDef.RunAt = InitialAction.RunAt; //TODO: we shouldn't be reading from the resourceAction as this may have changed since the action was created. //However, Steve C says do it this way for now. aoDef.AllowTransparent = m_allowTransparent && resourceAction.AllowTransparent; aoDef.PropertySetLayout = resourceAction.PropertySetLayout; aoDef.CustomDataTypeUIHandler = resourceAction.CustomDataTypeUI; bool updateCheckBoxAtStart = ActionHasSelectAllCheckBox(aoDef); bool resetValueSelectAll = true; bool resetOverrideSelectAll = true; bool resetVisibleSelectAll = true; foreach (IDataElement property in InitialAction.DataElements) { // Supported File Types is added in as a property but we don't // want to retrieve it here as one. The same applies to 'Transparent' if (property.Name.Value == "SupportedFileTypes" || property.Name.Value == "NonSupportedFileTypes" || property.Name.Value == LanguageItemKeys.TRANSPARENT) continue; if (0 == string.Compare("EXECUTE", property.Name.Value, StringComparison.InvariantCultureIgnoreCase)) { bool executePropValue = (bool)((IDataItem)property.Data).Value; bool allowOverride = property["allowoverride"].Value.ToLower(CultureInfo.InvariantCulture) == "true"; if (allowOverride) { aoDef.ExecutionOption = executePropValue ? ExecutionOption.OverridableDefaultTrue : ExecutionOption.OverridableDefaultFalse; } else { aoDef.ExecutionOption = ExecutionOption.AlwaysExecute; } continue; } ActionDataElement ade = new ActionDataElement(); ade.ShowInUI = ShowPropertyInUIForType(aoDef.Type, property.Name.Value); if (property["icustomdatatypehandler"].Value.ToString() != "") { ade.IsCustomDisplayType = true; } if (property["allowoverride"].Value.ToLower(CultureInfo.InvariantCulture) == "true") { ade.Override = true; } else { ade.Override = false; if (ade.ShowInUI) resetOverrideSelectAll = false; } if (property["visible"].Value.ToLower(CultureInfo.InvariantCulture) == "true") { ade.Visible = true; } else { ade.Visible = false; if (ade.ShowInUI) resetVisibleSelectAll = false; } if (property["iscustomproperty"].Value.ToLower(CultureInfo.InvariantCulture) == "true") { ade.IsCustomProperty = true; } // If the property is a data source then it is assumed to be // a system property if (property.Data is IDataSource) { IDataSource dataSource = property.Data as IDataSource; ade.IsSystemProperty = true; ade.IsDataSource = true; ISystemProperty systemProperty = ResourceManagerFactory.CreateSystemProperty(dataSource.Assembly, typeof(object), dataSource.Class, dataSource.Method.Name.Value, String.Empty // Description - not being populated yet ); ade.MappedSystemProperty = systemProperty; } switch (property.Type) { case DataType.String: foreach (IResourceActionProperty rap in resourceAction.Properties) { if (rap.Name == property.Name.Value) ade.IsCustomDisplayType = rap.DisplayType == PropertyDisplayType.CustomUI; } ade.Value = ((IDataItem)property.Data).Value; break; case DataType.Boolean: { ade.Value = (bool)((IDataItem)property.Data).Value; if ((bool)ade.Value == false && ade.ShowInUI) resetValueSelectAll = false; } break; case DataType.DateTime: { ade.Value = (DateTime)((IDataItem)property.Data).Value; break; } case DataType.Object: ade.Value = property.Data; break; case DataType.StringArray: ade.Value = ConversionUtils.PolicyObjectModelStringArrayToStringArray(property.Data as IPolicyObjectCollection<IDataItem>); break; default: ShowUnsupportedTypeMessageBox(); throw new PolicyDesignerException("Unsupported data element type"); } ade.Identifier = property.Identifier; ade.Name = property.Name.Value; ade.DisplayName = property.DisplayName.Value; aoDef.ActionProperties[property.Identifier] = ade; } if (InitialAction.Filetypes.Count == 0) AddBaseFileTypes(ref aoDef); else { foreach (IActionFiletype ftype in InitialAction.Filetypes) { ActionFileTypeObject aft = new ActionFileTypeObject(); aft.Apply = ftype.Apply; aft.Filetype = ftype.Type; aft.Identifier = ftype.Identifier; aoDef.FileTypes[FileTypeBridge.GetFileType(aft.Filetype)] = aft; } } m_baseAction = aoDef.Type; m_actions[m_baseAction] = aoDef; comboBoxActions.Items.Add(new ActionUIItem(GetResourceActionForType(m_baseAction))); comboBoxActions.SelectedIndex = 0; InitMyNameControl(InitialAction.Name.Value); m_override = InitialAction.Override; Text = Properties.Resources.ACTION_EDIT; cbProcessTransparently.Checked = Transparent; //cbAutoExpand.Checked = AutoExpand; PopulateExecutionOptionControl(); if (updateCheckBoxAtStart) { SetSelectAllCheckBox(actionOptionsListView.Columns.IndexOf(columnValue), resetValueSelectAll); SetSelectAllCheckBox(actionOptionsListView.Columns.IndexOf(columnOverride), resetOverrideSelectAll); SetSelectAllCheckBox(actionOptionsListView.Columns.IndexOf(columnVisible), resetVisibleSelectAll); } } catch (PolicyDesignerException) { DialogResult = DialogResult.Cancel; Close(); } }