-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from gglogowski/handle-obsolete-schema-in-swq…
…l-studio Add Filtering based on obsolete metadata. Filtering code refactoring.
- Loading branch information
Showing
22 changed files
with
470 additions
and
207 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SwqlStudio.Metadata | ||
{ | ||
public interface IObsoleteMetadata | ||
{ | ||
bool IsObsolete { get; set; } | ||
string ObsolescenceReason { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
| ||
namespace SwqlStudio.Metadata | ||
{ | ||
public class Property : ITypedMetadata | ||
public class Property : ITypedMetadata, IObsoleteMetadata | ||
{ | ||
public string Name { get; set; } | ||
public string Type { get; set; } | ||
public bool IsNavigable { get; set; } | ||
public bool IsInherited { get; set; } | ||
public bool IsKey { get; set; } | ||
public string Summary { get; set; } | ||
|
||
public bool IsObsolete { get; set; } | ||
public string ObsolescenceReason { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Src/SwqlStudio/ObjectExplorer/Filtering/INodeFilterStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows.Forms; | ||
|
||
namespace SwqlStudio.Filtering | ||
{ | ||
internal interface INodeFilterStrategy | ||
{ | ||
void Initialize(TreeNode node); | ||
VisibilityStatus GetVisibility(TreeNode node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using SwqlStudio.Metadata; | ||
using SwqlStudio.Properties; | ||
|
||
namespace SwqlStudio.Filtering | ||
{ | ||
internal class NodeFilter | ||
{ | ||
private readonly List<INodeFilterStrategy> _filters = new List<INodeFilterStrategy>(); | ||
private const int _limitOfExpandedNodes = 5000; | ||
private int _visibleNodesCount; | ||
|
||
public NodeFilter(TreeView treeData, string filter) | ||
{ | ||
InitializeFilters(treeData, filter); | ||
} | ||
|
||
private void InitializeFilters(TreeView treeData, string filter) | ||
{ | ||
if (!Settings.Default.ShowObsolete) | ||
{ | ||
_filters.Add(new ObsoleteNodeFilter()); | ||
} | ||
if (filter != null) | ||
{ | ||
_filters.Add(new SearchNodeFilter(filter)); | ||
} | ||
|
||
TreeNodeUtils.IterateNodes(treeData, node => _filters.ForEach(strategy => strategy.Initialize(node))); | ||
|
||
TreeNodeUtils.IterateNodes(treeData, node => | ||
{ | ||
if (FilterAction(node)) _visibleNodesCount++; | ||
}); | ||
} | ||
|
||
private VisibilityStatus NodeVisibility(TreeNode node) => _filters.Aggregate(VisibilityStatus.None, (current, filter) => current | filter.GetVisibility(node)); | ||
|
||
internal bool FilterAction(TreeNode node) => !NodeVisibility(node).HasFlag(VisibilityStatus.NotVisible); | ||
|
||
internal void UpdateAction(TreeNode data, TreeNode display) | ||
{ | ||
var nodeVisibility = NodeVisibility(data); | ||
|
||
if (nodeVisibility.HasFlag(VisibilityStatus.ChildVisible)) | ||
// this one is not directly visible, gray it out | ||
display.ForeColor = Color.LightBlue; | ||
|
||
else if (nodeVisibility.HasFlag(VisibilityStatus.ParentVisible)) | ||
// this one is not directly visible, gray it out | ||
display.ForeColor = Color.DarkGray; | ||
|
||
// this one is visible directly, ensure it is visible (parents are expanded). | ||
// it's children are visible as well, but may be not expanded | ||
else if (nodeVisibility.HasFlag(VisibilityStatus.Visible)) | ||
{ | ||
//expand parents of visible node | ||
if (_visibleNodesCount < _limitOfExpandedNodes) | ||
{ | ||
display.EnsureVisible(); | ||
} | ||
//If too many objects are visible, treeView performance drops dramatically. | ||
//In case of many object only entity level is expanded | ||
else | ||
{ | ||
if (data.Tag is Entity) | ||
{ | ||
display.EnsureVisible(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.