Hiding the Accessors in af:tree - oracle-adf

I'm creating af:tree from the pojo using the data control.
The java class has the sub lists to be displayed as the leaf node of the tree.
I'm able to display the tree ,however the accessors,which is nothing but the names of the lists in the java class are also getting displayed in the tree.
I tried hiding the list accessor names by using the following method ,but this hides all the nodes/Leaves in the tree
public void checkIfNodeisAccessor(){
RichTree tree = this.getOrderTree();
JUCtrlHierNodeBinding rootNode = null;
if (tree != null) {
CollectionModel model = (CollectionModel)tree.getValue();
JUCtrlHierBinding treeBinding =
(JUCtrlHierBinding)model.getWrappedData();
rootNode = treeBinding.getRootNodeBinding();
}
getAllHierarichalRowsCount(rootNode);
}
private void getAllHierarichalRowsCount(JUCtrlHierNodeBinding nodeBinding) {
Boolean val = null;
if (nodeBinding != null) {
val = nodeBinding.isAccessorFolderNode();
//Pass the row and get all the child rows
if (nodeBinding.hasChildren() &&
nodeBinding.getChildren() != null) {
int chlidRowsCount = nodeBinding.getChildren().size();
for (int i = 0; i < chlidRowsCount; i++) {
JUCtrlHierNodeBinding childNodeBinding =
(JUCtrlHierNodeBinding)nodeBinding.getChildren().get(i);
val = childNodeBinding.isAccessorFolderNode();
// String val = nodeBinding.getLabel();
setRenderValue(!val);
getAllHierarichalRowsCount(childNodeBinding);
}
}
}
}
Following is my JSPX code :
<af:tree value="#{bindings.orderList1.treeModel}" var="node"
selectionListener="#{bindings.orderList1.treeModel.makeCurrent}"
rowSelection="single" id="t2" clientComponent="true"
binding="#{backingBeanScope.PortalBean.orderTree}">
<f:facet name="nodeStamp">
<af:group id="g1">
<af:commandLink text="#{node}" id="cl1"
actionListener="{backingbeanscope.portalbean.fetchchildnodes}"
clientComponent="true"
rendered="#{backingBeanScope.PortalBean.renderValue}"/>
</af:group>
</f:facet>
</af:tree>
Can Anyone provide any pointers to hiding the Accessor names in the UI

Related

Using ANTLR 4 to parse TSQL Joins in Views, Stored Procedures and Functions

Looking for some validation on the approach to using ANTLR 4 to parse SQL joins.
I have generated a lexer, parser and visitor from the following grammar.
https://github.com/antlr/grammars-v4/tree/master/tsql
I can then create a parse tree (in this example for a view) and I can kick off a walk of tree using a listener I have implemented.
ICharStream stream = CharStreams.fromstring(view);
ITokenSource lexer = new TSqlLexer(stream);
ITokenStream tokens = new CommonTokenStream(lexer);
TSqlParser parser = new TSqlParser(tokens);
parser.BuildParseTree = true;
IParseTree tree = parser.create_view();
TSqlListener listener = new TSqlListener();
ParseTreeWalker.Default.Walk(listener, tree);
My question is. Is my method of extracting the tokens for the joins the 'correct' and most efficient way of doing this.
My implementation is below and i based on listening for a walk of the tree at the join conditions. I need to capture table aliases and relate them to columns so I need to be in the same context when I'm walking the tree. Hence I'm manually descending in a single method.
public void EnterTable_sources([NotNull] TSqlParser.Table_sourcesContext context)
{
var table_sources = context.table_source().ToList();
foreach (var table_source in table_sources)
{
var item = table_source.table_source_item_joined();
if (item != null)
{
//first aliases
var source_item = item.table_source_item();
if (source_item != null)
{
TableAlias tableAlias = new TableAlias();
var table_name = source_item.table_name_with_hint();
if (table_name != null)
{
var fullTableName = table_name.GetText();
if (fullTableName.Contains('.'))
{
var nameParts = fullTableName.Split('.').ToList();
for (int i = 0; i <nameParts.Count; i++)
{
tableAlias.AddParts(nameParts);
}
}
else
{
tableAlias.AddParts(fullTableName);
}
}
var table_alias = source_item.as_table_alias();
if (table_alias != null)
{
tableAlias.Alias = table_alias.GetText();
}
JoinAnalysis.Aliases.Add(tableAlias);
}
var join_parts = item.join_part();
foreach (var join_part in join_parts)
{
var table_source_joins = join_part.table_source();
if (table_source_joins != null)
{
//The join table and alias
var table_source_item_joined = table_source_joins.table_source_item_joined();
if (table_source_item_joined != null)
{
var joinAlias = new TableAlias();
var table_source_item = table_source_item_joined.table_source_item();
var table_name = table_source_item.table_name_with_hint();
if (table_name != null)
{
var fullTableName = table_name.GetText();
if (fullTableName.Contains('.'))
{
var nameParts = fullTableName.Split('.').ToList();
joinAlias.AddParts(nameParts);
}
else
{
joinAlias.AddParts(fullTableName);
}
}
if (table_source_item != null)
{
var table_alias = table_source_item.as_table_alias();
if (table_alias != null)
{
joinAlias.Alias = table_alias.GetText();
}
}
if (joinAlias.Alias != null)
{
JoinAnalysis.Aliases.Add(joinAlias);
}
}
}
var search_condition = join_part.search_condition();
if (search_condition != null)
{
//The join conditions
var conditions = search_condition.search_condition_and();
if (conditions != null)
{
foreach (var condition in conditions)
{
if (condition != null)
{
foreach (var search_condition_not in condition.search_condition_not())
{
JoinCondition joinCondition = new JoinCondition();
joinCondition.LineNumber = search_condition_not.Start.Line;
var conditionText = search_condition_not.GetText();
joinCondition.JoinConditionText = conditionText;
var splitCondition = conditionText.Split("=");
if (splitCondition.Length == 2)
{
joinCondition.LeftPart = splitCondition[0];
joinCondition.RightPart = splitCondition[1];
}
JoinAnalysis.JoinConditions.Add(joinCondition);
}
}
}
}
}
}
}
}
}
Is there a better way to do this using all of the other listener methods that have been generated without manually descending into child nodes? I there some magic that I'm missing that holds context between nodes as they are walked?
Instead of manually drilling down to sub elements in a rule you can simply listen to the the enter/exit calls for these subrules. As an example: you listen to table_sources and descent to table_source_item_joined from there to table_name_with_hint. Instead you could simply override the EnterTable_name_with_hint method.
It is totally ok to write a listener, which only handles very specific parts of the language. Look at this (C++) code in MySQL Workbench, where I created several listeners, each just handling a subpart of a larger construct or individual objects. There are listeners for create table, alter table, column definitions, triggers and more.

How to identify and remove child folders in a list of folders?

Let's say I have a list of folders in an array:
c:\aaa\bbb
d:\aaa\bbb
c:\aaa\bbb\ccc
c:\aaa\bbb\ccc\ddd
My program will carry out some operations recursively for each objects in those folders. But as you can see, some folders in this array have parent-child relationship. So I should remove the nested folders in this array before my process. For the above example, c:\aaa\bbb\ccc\ddd and c:\aaa\bbb\ccc will be removed as they are nested in c:\aaa\bbb. What's the best way to do this?
You could first sort the array in ascending order and visit each of the folders in that order. Then keep track of a "parent" folder, which starts out with an invalid name:
sort folders
parent = '>'
result = []
for each folder in folders:
if folder does not start with parent followed by a slash:
# keep folder, and remember it as potential parent
append folder to result
parent = folder
Here is a JavaScript code example:
var folders = [
'c:\\aaa\\bbb',
'd:\\aaa\\bbb',
'c:\\aaa\\bbb\\ccc',
'c:\\aaa\\bbb\\ccc\\ddd'
];
folders.sort();
let parent = '>';
let result = [];
for (var i = 0; i < folders.length; i++) {
if (folders[i].indexOf(parent + '\\') != 0) {
result.push(folders[i]); // keep it
parent = folders[i]; // and remember this as potential parent
}
}
// Display result
console.log(result.join('\n'));
I don't know if this is the best way to solve your problem, but it is some light at the process to find it.
First of all, the code.
/**
* Created by Zack at 14/January/2017
*/
public class ChildPathRemover {
private final Node mRoot = new Node();
/**
*
* #param path
* #return True if the directory was added, False if is a child directory
*/
public boolean add(String path) {
Node currNode = mRoot;
String[] parts = path.split(Pattern.quote(File.separator));
for (int i = 0; i < parts.length; i++) {
// contains
Node nextNode = currNode.subNodes.get(parts[i]);
if (nextNode != null) {
// Already has a parent
if (nextNode.isLeaf) {
return false;
} // Process the nextNode
else {
currNode = nextNode;
}
} // Reached the end, so we a good to add new path
else {
for (int k = i; k < parts.length; k++) {
Node newNode = new Node();
currNode.subNodes.put(parts[k], newNode);
currNode = newNode;
}
currNode.isLeaf = true;
break;
}
}
// TODO: if the parent were not added first, you will need to rebuild the paths, based on the
// Nodes and then call the Remove Listener
return true;
}
private static class Node {
boolean isLeaf = false;
HashMap<String, Node> subNodes = new HashMap<>();
}
public interface RemoveListener {
void pathRemoved(String path);
}
/**
* Call this method to remove the child paths
*
* #param paths
*/
public static void removeChildPath(List<String> paths) {
// Sort by the length of the path
Collections.sort(paths, new Comparator<String>() {
#Override
public int compare(String o1, String o2) {
return Integer.compare(o1.length(), o2.length());
}
});
ChildPathRemover cpr = new ChildPathRemover();
Iterator<String> itr = paths.iterator();
while (itr.hasNext()) {
if (!cpr.add(itr.next())) {
itr.remove();
}
}
}
}
Example of how to use.
public static void main(String[] args) {
ArrayList<String> paths = new ArrayList<>();
paths.add("d:\\aaa\\bbb");
paths.add("c:\\aaa\\bbb\\ccc");
paths.add("c:\\aaa\\bbb\\ccc\\ddd");
paths.add("c:\\aaa\\bbb");
removeChildPath(paths);
for (String path : paths) {
System.out.println("path = " + path);
}
}
This example will produce
path = d:\aaa\bbb
path = c:\aaa\bbb
Explanation
The idea here is to simulate a tree.
So first we add all the parent folders; this is done by sorting the array by the length of the paths.
Then, every time we add a path with success, it will be marked as leaf. When we try to add another path and it is "bigger", the code will know that it is a child, so we delete it.
EDIT:
Sorry... I did not see that this question was not marked as a Java question...

C# WPF: Create TreeView from text file

I create my TreeViewItems with the class Node . In the example nodes are specified in source code. But how do I do it if the nodes are to be imported from a text file with content like this:
text file content
Any ideas?
I have tried the following.
public MainWindowVM()
{
private ObservableCollection<Node> mRootNodes;
public IEnumerable<Node> RootNodes { get { return mRootNodes; } }
List<string[]> TreeNodes = new List<string[]>();
string[] lines = null;
try
{
lines = System.IO.File.ReadAllLines(MainWindow.TextFilePath , System.Text.Encoding.Default);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
Environment.Exit(0);
}
if (lines == null || lines.Length == 0)
{
MessageBox.Show("Text file has no content!");
Environment.Exit(0);
}
foreach (var line in lines)
{
TreeNodes.Add(line.Split('|'));
}
Node newNode = null;
Node childNode = null;
Node root = new Node() { Name = TreeNodes[0][0] };
if (TreeNodes[0].Length > 1)
{
newNode = new Node() { Name = TreeNodes[0][1] };
root.Children.Add(newNode);
}
for (int s = 2; s < TreeNodes[0].Length; s++)
{
childNode = new Node() { Name = TreeNodes[0][s] };
newNode.Children.Add(childNode);
newNode = childNode;
}
}
but I get only the first two nodes. I do not know how to build the whole TreeView with a loop.
TreeView
input example
Root|A
Root|B|C
Root|B|D
Root|E
the problem with your code is that you only process TreeNodes[0] element. to process a collection of elements you need a loop
public MainWindowVM()
{
private ObservableCollection<Node> mRootNodes;
public IEnumerable<Node> RootNodes { get { return mRootNodes; } }
string[] lines = null;
try
{
lines = System.IO.File.ReadAllLines(MainWindow.TextFilePath , System.Text.Encoding.Default);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
Environment.Exit(0);
}
if (lines == null || lines.Length == 0)
{
MessageBox.Show("Text file has no content!");
Environment.Exit(0);
}
Dictionary<string, Node> nodeCache = new Dictionary<string, Node>();
// processing each line
foreach (var line in lines)
{
Node parentNode = null;
string key = null;
// in each line there are one or more node names, separated by | char
foreach (string childNodeName in line.Split('|'))
{
Node childNode;
// names are not unique, we need a composite key (full node path)
key += "|" + childNodeName;
// each node has unique key
// if key doesn't exists in cache, we need to create new child node
if (false == nodeCache.TryGetValue(key, out childNode))
{
childNode = new Node { Name = childNodeName };
nodeCache.Add(key, childNode);
if (parentNode != null)
// each node (exept root) has a parent
// we need to add a child node to parent ChildRen collection
parentNode.Children.Add(childNode);
else
// root nodes are stored in a separate collection
mRootNodes.Add(childNode);
}
// saving current node for next iteration
parentNode = childNode;
}
}
}

textrange losing textpointer reference?

I've been using some code I found here, to try and change the case of text in a flow document. It changes the text properly however all the formatting is lost (bold, italics, etc) and when I save the document to a XML file all the text ends up in the first Run of the document and all the other Run's are empty.
private void ChangeCase()
{
TextPointer start = mergedDocument.ContentStart;
TextPointer end = mergedDocument.ContentEnd;
List<TextRange> textToChange = SplitToTextRanges(start, end);
ChangeCaseToAllRanges(textToChange);
}
private List<TextRange> SplitToTextRanges(TextPointer start, TextPointer end)
{
List<TextRange> textToChange = new List<TextRange>();
var previousPointer = start;
for (var pointer = start; (pointer != null && pointer.CompareTo(end) <= 0); pointer = pointer.GetPositionAtOffset(1, LogicalDirection.Forward))
{
var contextAfter = pointer.GetPointerContext(LogicalDirection.Forward);
var contextBefore = pointer.GetPointerContext(LogicalDirection.Backward);
if (contextBefore != TextPointerContext.Text && contextAfter == TextPointerContext.Text)
{
previousPointer = pointer;
}
if (contextBefore == TextPointerContext.Text && contextAfter != TextPointerContext.Text && previousPointer != pointer)
{
textToChange.Add(new TextRange(previousPointer, pointer));
previousPointer = null;
}
}
textToChange.Add(new TextRange(previousPointer ?? end, end));
return textToChange;
}
private void ChangeCaseToAllRanges(List<TextRange> textToChange)
{
Func<string, string> caseChanger;
ComboBoxItem cbi = cb_Case.SelectedItem as ComboBoxItem;
var textInfo = CultureInfo.CurrentUICulture.TextInfo;
if (cbi == null || (string)cbi.Tag == "none")
{
return;
}
else if((string)cbi.Tag == "title")
{
caseChanger = (text) => textInfo.ToTitleCase(text);
}
else if ((string)cbi.Tag == "upper")
{
caseChanger = (text) => textInfo.ToUpper(text);
}
else if ((string)cbi.Tag == "lower")
{
caseChanger = (text) => textInfo.ToLower(text);
}
else
return;
foreach (var range in textToChange)
{
if (!range.IsEmpty && !string.IsNullOrWhiteSpace(range.Text))
{
System.Diagnostics.Debug.WriteLine("Casing: " + range.Text);
System.Diagnostics.Debug.WriteLine("\tat: " +
range.Start.GetOffsetToPosition(mergedDocument.ContentStart) +
" ," +
range.End.GetOffsetToPosition(mergedDocument.ContentStart));
range.Text = caseChanger(range.Text);
}
}
}
I can't see any reason why this code isn't working properly. It looks like the textpointers in the textrange object are being redirected to the beginning of the document.
When setting TextRange.Text, it first deletes the selection by telling the TextContainer (the FlowDocument) to delete that content. If that content happened to be an entire Inline with your styling dependency properties then goodbye! So, not only does it get unstyled text, but it sets it
Since you want to keep your existing inline objects you can iterate through the entire FlowDocument to find them and set their text property.
Here is a helper method that only supports Paragraphs and finds all inlines in the entire selection (this logic is a lot simpler if you are always doing Document.ContentStart and Document.ContentEnd). You can expand this to include the inlines inside of Lists, ListItems, and Hyperlinks if you need to (by following a similar pattern).
You should then be able to set the Text property on each of these inlines.
List<Inline> GetInlines(TextRange selection)
{
var inlines = new List<Inline>();
foreach (var block in Document.Blocks.Where(x => selection.Start.CompareTo(x.ContentEnd) < 0 && selection.End.CompareTo(x.ContentStart) > 0))
{
var paragraph = block as Paragraph;
if (paragraph != null)
{
inlines.AddRange(paragraph.Inlines.Where(x => selection.Start.CompareTo(x.ContentEnd) < 0 && selection.End.CompareTo(x.ContentStart) > 0));
}
}
return inlines;
Edit: You will want to cast these to Run or Span to access the text property. You can even just remove Inline and get these types (probably just Run).

Use Kinect to create a digital catalog application

I am creating a WPF application to create digital catalog using kinect v1.8. I am trying to track only a single skeleton using following code:-
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs skeletonFrameReadyEventArgs)
{
// Even though we un-register all our event handlers when the sensor
// changes, there may still be an event for the old sensor in the queue
// due to the way the KinectSensor delivers events. So check again here.
if (this.KinectSensor != sender)
{
return;
}
SkeletonFrame skeletonFrame = skeletonFrameReadyEventArgs.OpenSkeletonFrame();
if (skeletonFrame == null)
return;
Skeleton[] skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
Skeleton skeleton = (from skl in skeletons
where skl.TrackingState == SkeletonTrackingState.Tracked
select skl).FirstOrDefault();
if (skeleton == null)
return;
Skeleton[] s = new Skeleton[1];
s[0] = skeleton;
if (SkeletonTrackingState.Tracked == s[0].TrackingState)
{
//s1.SkeletonStream.ChooseSkeletons(s[0].TrackingId);
var accelerometerReading = this.KinectSensor.AccelerometerGetCurrentReading();
this.interactionStream.ProcessSkeleton(s, accelerometerReading, skeletonFrame.Timestamp);
}
}
I am getting an exception when I run the code and skeleton gets detected as follows:-
on the line "this.interactionStream.ProcessSkeleton(s, accelerometerReading, skeletonFrame.Timestamp);"
I need to detect only one skeleton and use it for further processing like to access the digital catalog applications.
Thanks in advance.
I have Faced Same Problem By using below code I have track only one skeleton Which is closer to the sensor.and directly assign the closest skeleton to the main skeleton stream.
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs skeletonFrameReadyEventArgs)
{
Skeleton[] skeletons = new Skeleton[0];
using (SkeletonFrame skeletonFrame = skeletonFrameReadyEventArgs.OpenSkeletonFrame())
{
if (skeletonFrame != null && this.skeletons != null)
{
//Console.WriteLine(skeletonFrame.SkeletonArrayLength);
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
// Set skeleton datas from skeletonFrame
skeletonFrame.CopySkeletonDataTo(this.skeletons);
TrackClosestSkeleton();
Skeleton[] singleSkeleton = new Skeleton[6];
Skeleton skl=(from mno in this.skeletons where mno.TrackingState==SkeletonTrackingState.Tracked && mno.TrackingId==globalClosestID select mno).FirstOrDefault();
if (skl == null)
return;
//Creating an empty skkeleton
Skeleton emptySkeleton = new Skeleton();
singleSkeleton[0] = skl; //Pass the Tracked skeleton with closestID
singleSkeleton[1] = emptySkeleton; //Passing Empty Skeleton
singleSkeleton[2] = emptySkeleton; //Passing Empty Skeleton
singleSkeleton[3] = emptySkeleton; //Passing Empty Skeleton
singleSkeleton[4] = emptySkeleton; //Passing Empty Skeleton
singleSkeleton[5] = emptySkeleton; //Passing Empty Skeleton
this.snew.SkeletonStream.ChooseSkeletons(globalClosestID);
var accelerometerReading = this.KinectSensor.AccelerometerGetCurrentReading();
this.interactionStream.ProcessSkeleton(singleSkeleton, accelerometerReading, skeletonFrame.Timestamp);
}
}
}
int globalClosestID = 0;
private void TrackClosestSkeleton()
{
if (this.snew != null && this.snew.SkeletonStream != null)
{
if (!this.snew.SkeletonStream.AppChoosesSkeletons)
{
this.snew.SkeletonStream.AppChoosesSkeletons = true; // Ensure AppChoosesSkeletons is set
}
float closestDistance = 10000f; // Start with a far enough distance
int closestID = 0;
foreach (Skeleton skeleton in this.skeletons.Where(s => s.TrackingState != SkeletonTrackingState.NotTracked))
{
if (skeleton.Position.Z < closestDistance)
{
closestID = skeleton.TrackingId;
closestDistance = skeleton.Position.Z;
}
}
if (closestID > 0)
{
this.snew.SkeletonStream.ChooseSkeletons(closestID); // Track this skeleton
globalClosestID = closestID;
}
}
}
check the above code it works for me.It may helpful to you.Here snew is the Kinectsensor.
You should try to track the closest skeleton using this method from MSDN
private void TrackClosestSkeleton()
{
if (this.kinect != null && this.kinect.SkeletonStream != null)
{
if (!this.kinect.SkeletonStream.AppChoosesSkeletons)
{
this.kinect.SkeletonStream.AppChoosesSkeletons = true; // Ensure AppChoosesSkeletons is set
}
float closestDistance = 10000f; // Start with a far enough distance
int closestID = 0;
foreach (Skeleton skeleton in this.skeletonData.Where(s => s.TrackingState != SkeletonTrackingState.NotTracked))
{
if (skeleton.Position.Z < closestDistance)
{
closestID = skeleton.TrackingId;
closestDistance = skeleton.Position.Z;
}
}
if (closestID > 0)
{
this.kinect.SkeletonStream.ChooseSkeletons(closestID); // Track this skeleton
}
}
}
And then in your SkeletonFrameReady
private void SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
Skeleton[] skeletons = new Skeleton[0];
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null && this.skeletonData != null)
{
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
// Set skeleton datas from skeletonFrame
skeletonFrame.CopySkeletonDataTo(this.skeletonData);
TrackClosestSkeleton();
}
}
//Do some stuff here
}

Resources