Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP select on click: Some improvements #835

Merged
merged 3 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 48 additions & 33 deletions src/OSPSuite.UI/Views/Importer/ColumnMappingControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using OSPSuite.Assets;
using OSPSuite.DataBinding;
using OSPSuite.DataBinding.DevExpress;
using OSPSuite.DataBinding.DevExpress.XtraGrid;
using OSPSuite.Infrastructure.Import.Core.DataFormat;
using OSPSuite.Presentation.Presenters.Importer;
using OSPSuite.Presentation.Views.Importer;
using OSPSuite.UI.Controls;
using OSPSuite.UI.Extensions;
using OSPSuite.UI.RepositoryItems;
using OSPSuite.UI.Services;
using OSPSuite.Utility.Extensions;

namespace OSPSuite.UI.Views.Importer
{
Expand All @@ -35,10 +34,13 @@ public partial class ColumnMappingControl : BaseUserControl, IColumnMappingContr
new UxRepositoryItemButtonImage(ApplicationIcons.UnitInformation, Captions.UnitInformationDescription);

private readonly RepositoryItemButtonEdit _disabledUnitButtonRepository = new UxRepositoryItemButtonImage(ApplicationIcons.EmptyIcon);
private readonly RepositoryItemButtonEdit _addButtonRepository = new UxRepositoryItemButtonImage(ApplicationIcons.Add, Captions.AddInformationDescription);

private readonly RepositoryItemButtonEdit _addButtonRepository =
new UxRepositoryItemButtonImage(ApplicationIcons.Add, Captions.AddInformationDescription);

private readonly RepositoryItemButtonEdit _lloqButtonRepository =
new UxRepositoryItemButtonImage(ApplicationIcons.OutputInterval, Captions.LloqInformationDescription);

private readonly RepositoryItemButtonEdit _disabledLloqButtonRepository = new UxRepositoryItemButtonImage(ApplicationIcons.EmptyIcon);
private readonly RepositoryItemButtonEdit _errorIconRepository = new UxRepositoryItemButtonImage(ApplicationIcons.Exit);
private readonly RepositoryItemButtonEdit _errorUnitIconRepository = new UxRepositoryItemButtonImage(ApplicationIcons.MissingData);
Expand All @@ -52,13 +54,14 @@ public ColumnMappingControl(IImageListRetriever imageListRetriever)
_gridViewBinder = new GridViewBinder<ColumnMappingDTO>(columnMappingGridView);
columnMappingGridView.OptionsView.ShowGroupPanel = false;
columnMappingGridView.OptionsMenu.EnableColumnMenu = false;
columnMappingGridView.CellValueChanged += (s, e) => _presenter.ValidateMapping();
columnMappingGridView.MultiSelect = false;
columnMappingGridView.CellValueChanged += (o, e) => OnEvent(_presenter.ValidateMapping);

columnMappingGridView.OptionsView.ShowButtonMode = ShowButtonModeEnum.ShowOnlyInEditor;
columnMappingGridView.OptionsBehavior.EditorShowMode = EditorShowMode.MouseUp;
columnMappingGridView.MouseDown += onMouseDown;
columnMappingGrid.ToolTipController = new ToolTipController();
columnMappingGrid.ToolTipController.GetActiveObjectInfo += (o, e) => this.DoWithinExceptionHandler(() => onGetActiveObjectInfo(o, e));
columnMappingGridView.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDown;
columnMappingGridView.MouseDown += (o, e) => OnEvent(onMouseDown, o, e);
georgeDaskalakis marked this conversation as resolved.
Show resolved Hide resolved
columnMappingGrid.ToolTipController = new ToolTipController().Initialize(imageListRetriever);
columnMappingGrid.ToolTipController.GetActiveObjectInfo += (o, e) => OnEvent(onGetActiveObjectInfo, o, e);
var unitInformationTip = new SuperToolTip();
unitInformationTip.Items.Add(Captions.UnitInformationDescription);
}
Expand All @@ -68,33 +71,34 @@ public void AttachPresenter(IColumnMappingPresenter presenter)
_presenter = presenter;
}

private RepositoryItemImageComboBox valueRepository(ColumnMappingDTO model)
private RepositoryItem descriptionRepository(ColumnMappingDTO model)
{
var repo = new RepositoryItemImageComboBox
var descriptionRepository = new UxRepositoryItemImageComboBox(columnMappingGridView, _imageListRetriever)
{
AutoComplete = true,
AllowNullInput = DefaultBoolean.True,
CloseUpKey = new KeyShortcut(Keys.Enter)
};
fillComboBoxItems(repo, _presenter.GetAvailableOptionsFor(model));
return repo;
// descriptionRepository.FillComboBoxRepositoryWith(_presenter.GetAvailableOptionsFor(model));
// descriptionRepository.FillImageComboBoxRepositoryWith(_presenter.GetAvailableOptionsFor(model), x => x.IconIndex);
fillComboBoxItems(descriptionRepository, _presenter.GetAvailableOptionsFor(model));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have some predefined function fro all of this. However I am not quite sure what the extra stuff is doing. If we want the UI to behave like the rest of the suite, let see if this is needed or not

return descriptionRepository;
}

private RepositoryItemImageComboBox nameRepository(ColumnMappingDTO model)
{
var repo = new RepositoryItemImageComboBox
var entry = new ColumnMappingOption()
{
AllowNullInput = DefaultBoolean.True
Label = model.MappingName,
IconIndex = model.Icon,
Description = model.MappingName
};
var repo = new UxRepositoryItemImageComboBox(columnMappingGridView, _imageListRetriever) {AllowNullInput = DefaultBoolean.True};
//repo.FillImageComboBoxRepositoryWith(new[] {entry}, x=>x.IconIndex);
fillComboBoxItem
(
repo,
new ColumnMappingOption()
{
Label = model.MappingName,
IconIndex = model.Icon,
Description = model.MappingName
}
repo,
entry
);
return repo;
}
Expand All @@ -104,7 +108,7 @@ public override void InitializeBinding()
base.InitializeBinding();
_gridViewBinder.AddUnboundColumn()
.WithCaption(UIConstants.EMPTY_COLUMN)
.WithShowButton(ShowButtonModeEnum.ShowOnlyInEditor)
.WithShowButton(ShowButtonModeEnum.ShowAlways)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Button should always be visible

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact this is only required for combo box. Otherwise buttons are visible by default

.WithRepository(invalidRepository)
.WithFixedWidth(UIConstants.Size.BUTTON_WIDTH);

Expand All @@ -115,31 +119,32 @@ public override void InitializeBinding()

_gridViewBinder.AutoBind(x => x.Description)
.WithCaption(Captions.Description)
.WithRepository(valueRepository)
.WithOnValueUpdating(onValueChanged)
.WithRepository(descriptionRepository)
.WithOnValueUpdated((o, e) => onValueChanged(o))
.WithShowButton(ShowButtonModeEnum.ShowAlways);

_gridViewBinder.AddUnboundColumn()
.WithCaption(UIConstants.EMPTY_COLUMN)
.WithShowButton(ShowButtonModeEnum.ShowOnlyInEditor)
.WithShowButton(ShowButtonModeEnum.ShowAlways)
.WithRepository(removeRepository)
.WithFixedWidth(UIConstants.Size.BUTTON_WIDTH);

_gridViewBinder.AddUnboundColumn()
.WithCaption(UIConstants.EMPTY_COLUMN)
.WithShowButton(ShowButtonModeEnum.ShowOnlyInEditor)
.WithShowButton(ShowButtonModeEnum.ShowAlways)
.WithRepository(unitRepository)
.WithFixedWidth(UIConstants.Size.BUTTON_WIDTH);

_gridViewBinder.AddUnboundColumn()
.WithCaption(UIConstants.EMPTY_COLUMN)
.WithShowButton(ShowButtonModeEnum.ShowOnlyInEditor)
.WithShowButton(ShowButtonModeEnum.ShowAlways)
.WithRepository(lloqRepository)
.WithFixedWidth(UIConstants.Size.BUTTON_WIDTH);

_removeButtonRepository.ButtonClick += (o, e) =>
{
columnMappingGridView.ActiveEditor.EditValue = ColumnMappingFormatter.Ignored();
columnMappingGridView.CloseEditor();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures that the editor is released. I am not sure why this is required in the first place, probably because of how the objects are updated? not sure

_presenter.ClearRow(_gridViewBinder.FocusedElement);
};
_unitButtonRepository.ButtonClick += (o, e) => _presenter.ChangeUnitsOnRow(_gridViewBinder.FocusedElement);
Expand All @@ -153,7 +158,9 @@ public override void InitializeBinding()

private RepositoryItem removeRepository(ColumnMappingDTO model)
{
return model.Source == null || model.Source is IgnoredDataFormatParameter || model.Source is AddGroupByFormatParameter ? _disabledRemoveButtonRepository : _removeButtonRepository;
return model.Source == null || model.Source is IgnoredDataFormatParameter || model.Source is AddGroupByFormatParameter
? _disabledRemoveButtonRepository
: _removeButtonRepository;
}

private RepositoryItem unitRepository(ColumnMappingDTO model)
Expand All @@ -162,14 +169,17 @@ private RepositoryItem unitRepository(ColumnMappingDTO model)
{
return _unitButtonRepository;
}

if (model.Source is AddGroupByFormatParameter)
{
if (string.IsNullOrEmpty(model.Source.ColumnName))
{
return _disabledUnitButtonRepository;
}

return _addButtonRepository;
}

return _disabledUnitButtonRepository;
}

Expand All @@ -194,12 +204,14 @@ private RepositoryItem lloqRepository(ColumnMappingDTO model)
{
return _lloqButtonRepository;
}

return _disabledLloqButtonRepository;
}

public void Rebind()
{
_gridViewBinder.Rebind();
{
columnMappingGridView.RefreshData();
// _gridViewBinder.Rebind();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to discuss here. Rebind is called quite often. It's required when adding or deleting rows. But when modifying bound date, it is not

}

public void SetMappingSource(IList<ColumnMappingDTO> mappings)
Expand Down Expand Up @@ -265,9 +277,12 @@ private void fillComboBoxItems(RepositoryItemImageComboBox editor, IEnumerable<C

private void onMouseDown(object sender, MouseEventArgs mouseEventArgs)
{
if (mouseEventArgs.Button != MouseButtons.Right) return;
if (!(sender is GridView mv)) return;
if (mouseEventArgs.Button != MouseButtons.Right)
return;

if (!(sender is GridView mv))
return;

var menu = new GridViewColumnMenu(mv);
menu.Items.Clear();
menu.Items.Add(new DXMenuItem(Captions.Importer.ResetMapping, onCreateAutoMappingClick));
Expand All @@ -286,7 +301,7 @@ private static void clearSelectionOnDeleteForComboBoxEdit(object sender, KeyEven
view.ActiveEditor.EditValue = Captions.Importer.NoneEditorNullText;
}

private void onValueChanged(ColumnMappingDTO model, PropertyValueSetEventArgs<string> e)
private void onValueChanged(ColumnMappingDTO model)
{
_presenter.SetDescriptionForRow(model);
}
Expand Down