Original Question
I have this expandable folder UIObject that I need to be able to expand to show all the subfolders. It can not be double clicked as this does not expand the folders. I saw from this documentation, https://admhelp.microfocus.com/leanft/en/14.02/NetSDKReference/HP.LFT.SDK~HP.LFT.SDK.Java.ITreeView.html as well as some others that there is a concept of an ITreeView and an ITreeViewNode.
How can I expand this element? I really just need some examples in code of how we can take an object, defeine it as a ITreeView and ITreeView node and expand it.
Result
Even though it is not the best solution, it is possible to do this using the Workaround suggested below and this is the method that made it happen
public void ExpandFolder(int index)
{
IUiObject folder = ViewPage.FolderExplorer.Describe<IUiObject>(new UiObjectDescription
{
ObjectName = "TreeViewItem",
Index = (uint)index
});
var expandButton = folder.AbsoluteLocation;
expandButton.X = expandButton.X + 2;
expandButton.Y = expandButton.Y + 4;
Mouse.Click(expandButton);
GeneralUtilities.Sleep(1);
}
In this case, there was a small drop down arrow to the left of the element. I couldn't identify that, so I identified the folder and manipulated the click. If anyone stumbles upon this and knows a more direct way to do this using LeanFT I would very much like to see an example. If not, and you are here trying to find help - I hope this helps you!
The theory
In order to Expand and Collapse a Java ITreeView, these are the steps:
Describe the ITreeView:
ITreeView treeView = Desktop.Describe<IWindow>(new WindowDescription())
.Describe<ITreeView>(new TreeViewDescription()
{
AttachedText = "Etc"
});
Get one of it's nodes:
ITreeViewNode treeViewNode = treeView.GetNode("someNode");
Expand or collapse it:
treeViewNode.Expand(); treeViewNode.Collapse();
The only expandable object is the ITreeViewNode (that is, this is the one that has the .Expand method), and the only way to get to the node is via an ITreeView, as shown above.
In practice...
You want to take an UIObject (I suspect this is what object identification center identified, right?) as an ITreeView, so that you can call Expand and Collapse on it?
This is not possible.
In these SDKs, every description is a generic element. In Java it's a UIObject, in Web it's a WebElement, etc..
Those more unique, like a tree view, extend the generic one (UIObject) and adds one more identification property in the process
In the ITreeView case, most probably it's the UIObject with NativeClass set as "javax.swing.JTree"
If Object Identification Center didn't identify the expandable object as an ITreeView, it's because it isn't.
Workaround
If your goal is just to expand, and manually double clicking works, then you can:
Identify the UIObject;
Calculate the coordinates of the point you manually double click, relative to the upper left pixel of the UIObject. (E.G. 5 pixels down, 5 to the right)
You can approximate it, go for a try and error, or use tools that can help.
Use HP.LFT.SDK.Mouse class to double click that exact location:
var loc = theUiButton.AbsoluteLocation;
var p = new System.Drawing.Point(loc.X + 5, loc.Y + 5);
Mouse.DoubleClick(p, MouseButton.Left);
The reason why it doesn't work right now is because .DoubleClick, by default, performs double click in the center of the UIObject, and I have a hunch that's not where the expandable object is - so you need to provide fine tuning parameters.
Related
Given a SyntaxNode instance, how can I open appropriate source code file and place cursor at position where the node resides?
I'm writing some simple analyzer. I'm able start it on demand and get a syntax node from current cursor position. But I can't figure out how do I get back to editor from result syntax node. I see the node has a Span property but other than that I don't see any info. The Node I want to show can be in some other file that may not be even opened.
I would like to have behavior similar to "go to..." command for the result of my search.
I spend whole day on this but finally got it.
private void selectNodeInEditor(SyntaxNode n) {
var cm = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var tm = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));
var ws = (Workspace)cm.GetService<VisualStudioWorkspace>();
var did = ws.CurrentSolution.GetDocumentId(n.SyntaxTree);
ws.OpenDocument(did);
tm.GetActiveView(1, null, out var av);
var sp = n.GetLocation().GetMappedLineSpan().StartLinePosition;
var ep = n.GetLocation().GetMappedLineSpan().EndLinePosition;
av.SetSelection(sp.Line, sp.Character, ep.Line, ep.Character);
}
Syntax nodes have a GetLocation() method, which returns a Microsoft.CodeAnalysis.Location for that syntax node, so that's one way to get a location object from the SyntaxNode.
var nodeLocation = syntaxNode.GetLocation();
You can also get location information from a symbol using the Locations property on the ISymbol interface, if you happen to need the symbol as well. From the docs:
Gets the locations where the symbol was originally defined, either in source or metadata. Some symbols (for example, partial classes) may be defined in more than one location.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.isymbol?view=roslyn-dotnet
This may be prefereable, as depending on the type of the SyntaxNode, you may want to get the symbol's original definition rather than the symbol itself e.g. you could get a class declaration from a field's type. This can be done with the OriginalDefinition property.
// assumes there's a SemanticModel in scope and your node is called synatxNode
var syntaxNodeSymbol = semanticModel.GetSymbolInfo(syntaxNode).Symbol;
// make sure syntaxNodeSymbol is null checked
var nodeLocation = syntaxNodeSymbol.Locations[0];
var originalNodeLocation = syntaxNodeSymbol.OriginalDefinition.Locations[0];
As for actually jumping to the node, this question would probably be a good place to start:
Go to definition from text position with roslyn
However, this is already possible in Visual Studio by double clicking on the message in the error list panel. Furthermore, any code fixes you want to make at that location will show up in the code fix window.
I've been developing a Word-AddIn (Office 365 version 1706, Windows 10) which basically stores data in charts so they could be fed updated data from our servelets and ultimately the chart updates itself with all the data it needs.
This works perfectly fine EXCEPT when I alter the layout options for a chart from the default "In Line with Text" to "With Text Wrapping" to have multiple charts next to each other for example.
How this works, as long as you don't alter the layout options, is by accessing the Microsoft.Office.Interop.Word.Application COM object, which has a Selection object, which furthermore has InlineShapes, is like so:
var inlineShapes = Application.Selection.InlineShapes;
if(inlineShapes > 0)
{
for(var i = 1; i < inlineShapes.Count + 1; i++)
{
if (inlShape.HasChart == MsoTriState.msoTrue)
return new WordChart(inlShape);
}
}
For sake of simplicity I spared you the whole ordeal of dealing with COM objects.
Again, this works if you don't tamper with the layout options of the chart, but as soon as the layout has been altered to say "Behind Text" I can't find that chart in any InlineShape.
Has anyone experienced this before?
I've combed through the Application.Selection object and couldn't find anything.
However the InlineShape is still in the Application.InlineShapes object itself, but how would I know which one is to be selected?
I would really appreciate ANY input, because as of now I have no idea on what to do anymore.
Ok, I finally found those little charts!
This Stackoverflow post helped me:
How to check which shapes/objects are selected/active?
More details to what solved my problem:
Once I changed the the layout options (see original question) I wouldn't be able to find Charts as InlineShapes anymore.
Instead they would be listed under Selection.ShapeRange.get_Item(i) (I checked for Shapes/InlineShapes, so I didn't see items as what a chart could be).
Now you could either convert them to InlineShapes, which does exactly that, in Word as well, which you don't want, or convert that Shape to your VSTO.WordChart, which I did.
I recently started to work with C# and I have to import a Visio file that is including a flow-chart with different path.
I load the file with this code.
public Container loadFile(string fileName)
{
Microsoft.Office.Interop.Visio.Application app = new Microsoft.Office.Interop.Visio.Application();
app.Visible = false;
Documents docs = app.Documents;
Document doc = docs.Open(fileName);
Microsoft.Office.Interop.Visio.Page page = doc.Pages[1];
Container container = printProperties(page.Shapes);
return container;
}
public Container printProperties(Microsoft.Office.Interop.Visio.Shapes shapes)
{
Container container = new Container("Visio Import");
container.setParent(null);
// Look at each shape in the collection.
foreach (Microsoft.Office.Interop.Visio.Shape shape in shapes)
{
// traverse
}
return container;
}
I want to traverse through every possible (!) path of the flow-chart and print the process names. E.g.
Path 1:
- Enter PIN
- Select Account
- Select Amount
- Print Receipt
- Take Money
Path 2:
- Enter PIN
- Select Account
- Check Money
- Abort
Can you tell me how to check the connections between the single processes and traverse it? Thank you very much for your help!
I have code that does this, but I cannot share it, since it's part of a commercial product.
However, I can tell you that the way I coped with doing this within Visio was, I first wrote a set of very generic directed graph classes in VBA: one for nodes, one for edges, and one for the graph as a whole. I built circular path checks into the graph class, as well as the code for finding all paths in the graph.
Then I had some code that would read the Visio page and populate this simple graph representation, and call the appropriate code.
I think this would probably be good for you to do, too, since the Visio side of things will inevitably be messier than a simple directed graph implementation. I didn't use the ConnectedShapes part of the API since I have to support down to Visio 2003, so I actually look at the Connects and FromConnects objects on my shapes to see what OneD connectors are attached to a shape, and determine whether a shape is at the head or tail of an arrow. This is another reason to break the graph part away from the Visio part, since the way we read the Visio page is subject to change over time, but the graph theory will stay the same.
The path-finding algorithm works by first finding all the terminal nodes in the graph, and I mean those nodes with no Downstream nodes. For each of these I add a list called DownstreamPaths, which is just empty since there is nothing downstream. Then for each node in the graph I call a recursive function that populates all the downstream paths for the current node, and basically all it does is builds a DownstreamPaths list on each node. This list is a list of lists, so you just look at each downstream node, and append that node on the head of its own DownstreamPaths list, and add that into the current node's path list.
When that's all done, you find all the starting nodes, with nothing upstream, and collate all the downstream paths lists on those, and you get your list of paths.
You could use shape.ConnectedShapes (Visio 2010+) to find which shapes are connected to the current one. Thus, you will be able to build a graph (model) out of the flowchart.
Check out also this article which explains things about Visio connectivity:
http://blogs.msdn.com/b/visio/archive/2009/09/22/the-visio-2010-connectivity-api.aspx
Finding all paths in that graph is a different story though, the solution may depend of what kind of flowchart you analyze; for example, if the flowchart has a cycle, there will be infinite number of paths in fact... Also, the number of possible paths may grow exponentially for relatively simple acyclic graphs. You could try "finding all paths in directed graph" search.
I'm building an Orchard content part for location data which include latitude and longitude fields. Whenever content is saved (created or updated), I would like to compute the bounding lat/lng for various max distances (20 miles, 50 miles, etc.) and save for later reference to search within a given radius of a specific location.
I already have all the necessary calculations for geolocation. The problem at hand is actually computing the derived value upon save (create/update), and setting the derived values to new fields on the content part before persisting to its repository.
I have a feeling adding filters like OnCreated in the associated ContentHandler might be a step in the right direction, but wasn't able to quickly locate any discussion related to a similar use case. So, I just wanted to reach out to the community and hear your thoughts on this particular problem before I proceed.
Thanks all!
You are on the right track with adding an OnCreated filter!
You could use OnUpdateEditorShape if you are only bothered about detecting when the content item is updated via the dashboard (or more generally, when the content item is updated using IContentManager.UpdateEditor(...)).
OnVersioning/OnVersioned will give you access to the "before" and "after" versions of a content item when it is updated, if your record class inherits from ContentPartVersionRecord (this will work with ContentPartRecord, but the "before" and "after" parameters will be the same).
You might want to look at this similar question.
Edit: "before" and "after" versions are called Existing and Building in VersionContentContext.
I have a school assignment, visualization of sorting algorithms (mergesort, bubblesort). I looked at libraries like Processing, JsAnim, cake and couple of others but not sure whether they will be useful for my application (visualizing sort algorithms).
I am familiar with C# and little javascript. any libraries that would be appropriate for my need?
Thanks a lot
You haven't clarified what language you want to use. I will assume its java because of your tags. If you are allowed to site outside resources you could use an object written by Dr. Robert Sedgewick and Dr. Kevin Wayne of Princeton University. It is called StdDraw and is from their book Algorithms, 4th Edition. The URL for source code is here:
http://algs4.cs.princeton.edu/stdlib/StdDraw.java.html
If you cannot use outside sources I would recommend Java Swing Package.
I had such task when was writing parallel sorting. I used C# ZedGraph library:
ZedGraph tutorial
The main idea was to represent the value of sort element like a vertical line with appropriate height( like a histogram).
This how it looks before sotring:
And after:
So we see that all elements is sorted.
To visualize every step of process I changed values of zedgraph control and refresh it. In my code it looked like:
private static void CreateGraph3(ZedGraphControl zgc)
{
// get a reference to the GraphPane
GraphPane pane = zgc.GraphPane;
// Set the Titles
pane.Title.Text = "Sorting";
//Clear current values
pane.CurveList.Clear();
// histogram high
double[] values = new double[n];
//fill values
for (int i = 0; i < n; i++)
{
values[i] = A1[i]; //A1 is an array that is currently sort
}
//create histogram
BarItem curve = pane.AddBar("Elements", null, values, Color.Blue);
pane.BarSettings.MinClusterGap = 0.0F; //set columns references
// update axis
zgc.AxisChange();
// update graph
zgc.Invalidate();
}
I call this function every time some values has been sorted, so we see a video of whole process of sorting.
To include current library to your project you need to:
1) Right click on your toolbox
2) Choose (or add) items
3) Browse, Select ZedGraph.DLL and press OK
4) ZedGraphControl will be added to your toolbox and you can use it like another controls.
So this is it, good luck
If you don't mind excluding old or crappy browsers, you could use CSS3 animations. Just set up a bunch of lis representing the items in your list, give them position:absolute and manipulate each li's top attribute to shuffle them around.
The web doesn't seem to have grown a good, definitive reference guide yet, but some examples of CSS3 animations are here.
Processing should be great for visualising sort algorithms.
An example: http://www.openprocessing.org/sketch/29208