ADF Invoke operation manually from code - oracle-adf

I want to execute a data control operation (CreateInsert and Delete) from a buttons ActionListener. I am aware a data control button can be inserted from the Data Controls menu, but for various reasons I need to do it this way, a prominent one being I need to perform extra runtime checks.
I found the following code:
OperationBinding operation = bindings.getOperationBinding("operation_name");
operation.getParamsMap().put("parameter_name", parameterValue);
operation.execute();
But don't know which variables to use for myself. First of all, I don't know which binding I should use. Then, the operation name should, as far as I know, be CreateInsert, and for the next button, CreateInsert1. Thats whats used for UIBinding now (which I will remove).
The Data control I want to use the operation of is 'ARNG1'.
So in short, I need to know how to manually invoke this Data control's CreateInsert operation.
Thanks in advance.

See if this will help you:
https://blogs.oracle.com/shay/entry/doing_two_declarative_operatio

the code you want to execute an operation behind a actionlistener:
public BindingContainer getBindings() {
if (this.bindings == null) {
FacesContext fc = FacesContext.getCurrentInstance();
this.bindings = (BindingContainer)fc.getApplication().
evaluateExpressionGet(fc, "#{bindings}", BindingContainer.class);
}
return this.bindings;
}
BindingContainer bindings = getBindings();
OperationBinding operationBinding =
bindings.getOperationBinding("doQueryResultReset");
operationBinding.execute();

Similar to Joe's answer but does not use EL Expression evaluator and uses direct access instead to get the BindingContainer
//Get binding container
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
// get an Action or MethodAction
OperationBinding method = bindings.getOperationBinding("methodAction");
method.execute();
List errors = method.getErrors();

Related

Concurrency Error WinForms Binding Source Navigator

I have a form with customer info that needs to be processed one transaction per page. I'm using the binding navigator to manage my pagination.
It works in all but some cases. In the cases where it doesn't work, I have to open a different window to look up information and return it to the main form. Here is the code for that:
// save current work
updateDataTable();
// Open a window and get new customer info
// CurrentCustomer is returned from the opened window
using (SqlConnection cx = new SqlConnection(GetConnectionString()))
{
DataRowView dataRow = (DataRowView)procBindingSource.Current;
dataRow.BeginEdit();
dataRow["CUSTOMER"] = CurrentCustomer;
dataRow.EndEdit();
updateDataItems();
SqlCommand cmd = new SqlCommand(
#" select acct_no from cust_processing where id = #id ", cx);
cmd.Parameters.AddWithValue("#id", (int)dataRow["ID"]);
cx.Open();
var results = cmd.ExecuteScalar();
if (results != null)
{
dataRow.BeginEdit();
dataRow["ACCT_NO"] = results.ToString();
dataRow.EndEdit();
updateDataItems(); <------ CONCURRENCY ERROR
}
}
The error I am getting is a concurrency error. I think that I have more than one version of the row possibly ? I thought I was making sure that I was on the most recent version of the row by calling updateDataTable(). I am the only user so I know I am creating the problem myself.
Here is my update method which is called when I change pages or save and exit or want to write the commit the data:
void updateDataItems()
{
this.procBindingSource.EndEdit();
this.procTableAdapter.Update(xyzDataSet);
xyzDataSet.AcceptChanges();
}
I have tried executing updateDataItems from various places such as after I assign dataRow["ACCT_NO"] = results.ToString() or before and after assigning that.
I'm pretty much down to guess and check so any thoughts, help and advice will be appreciated and +1.
Okay -- so the problem was that I was trying to update the current row from the program and also using the binding navigator. They were not working together properly.
The solution was to add a text box to the form in the forms designer and set visible = false and bind it to ACCT_NO. Once I got the results from my other form, I just needed to set the .text property of the ACCT_NO textbox to the new value and the binding navigator managed all my updates for me correctly.
txtAcct_No.text = results.ToString();

Xceed DataGrid: Filtering Details

I've got a Master/Detail DataGrid and I want to filter the details.
Here's my DataGridCollectionViewSource:
<xcdg:DataGridCollectionViewSource x:Key="Features"
Filter="ExampleFilter"
Source="{Binding Path=ItemUnderEdit.Features}"
AutoCreateDetailDescriptions="False"
AutoCreateItemProperties="False">
<xcdg:DataGridCollectionViewSource.DetailDescriptions>
<xcdg:PropertyDetailDescription RelationName="Settings"
AutoCreateDetailDescriptions="False"
AutoCreateItemProperties="False">
</xcdg:PropertyDetailDescription>
</xcdg:DataGridCollectionViewSource.DetailDescriptions>
</xcdg:DataGridCollectionViewSource>
As you can see I'm filtering it with ExampleFilter, but this only filters the master. I put a breakpoint and it never sees any details.
I cant add a filter to the Detail Descriptions in the same way. Is there any way to filter the details? Any help would be much appreciated!
I went up against this problem today - I had a simple filter for both the master and detail sections that gets turned on / off via code. For the master section, it was a simple matter of code like:
((DataGridCollectionView)grid.ItemsSource).FilterCriteriaMode = FilterCriteriaMode.None; // Off
((DataGridCollectionView)grid.ItemsSource).FilterCriteriaMode = FilterCriteriaMode.And; // On
((DataGridCollectionView)grid.ItemsSource).Refresh(); // Re-run filter.
For the details section, it should have been as simple as the following code (it wasn't though):
MyDetailDescription.FilterCriteriaMode = FilterCriteriaMode.None; // Off
MyDetailDescription.FilterCriteriaMode = FilterCriteriaMode.And; // On
Turns out, doing that will enable the new filter for any new detail sections that get generated, but not existing ones. New detail sections are generated when the master row is expanded. To get around this it turned out I needed a simple foreach loop such as:
foreach (DataGridContext context in grid.GetChildContexts()) {
((DataGridCollectionViewBase)(context.Items)).FilterCriteriaMode = PetsDetailDescriptions.FilterCriteriaMode;
}
Here's my complete(ish) code for all that:
public bool ShowDeleted {
set {
if ((grid.ItemsSource != null) && (grid.ItemsSource.GetType() == DataGridCollectionView));
DataGridCollectionView v = ((DataGridCollectionView)(grid.ItemsSource));
if (value) {
v.FilterCriteriaMode = FilterCriteriaMode.None;
MyDetailDescription.FilterCriteriaMode = FilterCriteriaMode.None;
}
else {
v.FilterCriteriaMode = FilterCriteriaMode.And;
MyDetailDescription.FilterCriteriaMode = FilterCriteriaMode.And;
}
foreach (DataGridContext context in grid.GetChildContexts()) {
((DataGridCollectionViewBase)(context.Items)).FilterCriteriaMode = PetsDetailDescriptions.FilterCriteriaMode;
}
v.Refresh();
}
}
}
I'm using that in-conjunction with a simple predefined filter criterion in the XAML. IE:
<g:DataGridItemProperty Name="IsDeleted"
DataType="{x:Type sys:Boolean}">
<g:DataGridItemProperty.FilterCriterion>
<g:EqualToFilterCriterion>
<sys:Boolean>False</sys:Boolean>
</g:EqualToFilterCriterion>
</g:DataGridItemProperty.FilterCriterion>
</g:DataGridItemProperty>
I recommend using the Xaml FilterCriterions, because if you absolutely need the Filter event, it's going to get a bit more messy. For that route, you need to do the following steps:
Tap into the event when a new child DataGridContext is added to the control.
Add a predicate reference to the context.Items.Filter property (in the code state, this is a property expecting predicate, not an event).
Write your filter code in the predicate function.
I'm not 100% sure how to achieve #1 above (as I didn't need to go that route). However, a good place to possible start is the DetailsExpanding and DetailsExpanded events of the DataGridControl. For the expanding, I'm not sure if the child DataGridContext exists yet (as there is an option to cancel the expanding). So you might have to wait until after the expanded event.
I hope this helps point you in the right direction.

Dynamically populate GraphSource through PopulateGraphSource method - RadDiagram

I am facing an issue where my graph is tree layout and looks fine initially. However, if I choose to change GraphSource upon user input/ clicks using PopulateGraphSource like in the OrgChart example, I get all the nodes stacked on top of each other with no links and all in corner.
I tried resetting graphSource by creating a new one
this.graphSource = new GraphSource();
I also tried to use the Clear method for GraphSource. Neither did solve the problem, I keep having the same issue.
I am using
ObservableCollection<Node> hierarchicalDataSource;
to fill up my GraphSource object.
All I do is create a new one and then call
PopulateGraphSource();
method.
Similar issues: question in telerik support , telerik support different question
Try calling the Layout method on the diagram control. Here is a little fragment of code
TreeLayoutSettings settings = new TreeLayoutSettings()
{
TreeLayoutType = TreeLayoutType.TreeDown,
VerticalSeparation = 60,
HorizontalSeparation=30
};
if (this.diagram.Shapes.Count > 0)
{
settings.Roots.Add(this.diagram.Shapes[0]);
this.diagram.Layout(LayoutType.Tree, settings);
this.diagram.AutoFit();
//this.diagram.Zoom = 1;
}

Create widget array using Qt Designer?

In Qt Designer I'm creating multiple labels (for instance):
my_label1
my_label2
my_label3
...
my_label n
Then if I want to hide them I do this:
ui->my_label1->hide();
ui->my_label2->hide();
ui->my_label3->hide();
...
ui->my_labeln->hide();
However I would like to define the labels like
my_label[n]
So then I would be able to do this:
for(i=0;i<n;i++)
{
ui->my_label[n]->hide();
}
I read that I can define the widget like:
QLabel* my_label[5];
but is there any way to do the same from Qt Designer?
Thanks in advance!
Finally I decided to do direct assignment:
QLabel* my_label_array[5];
my_label_array[0] = ui->my_label1;
my_label_array[1] = ui->my_label2;
my_label_array[2] = ui->my_label3;
my_label_array[3] = ui->my_label4;
my_label_array[4] = ui->my_label5;
Then I can do for instance:
for(idx=0;idx<6;idx++) my_label_array[idx]->show();
for(idx=0;idx<6;idx++) my_label_array[idx]->hide();
for(idx=0;idx<6;idx++) my_label_array[idx]->setEnabled(1);
for(idx=0;idx<6;idx++) my_label_array[idx]->setDisabled(1);
etc...
Then I was able to perform iterations. I believe is not the cleanest way to do it but given my basic knowledge of Qt is ok for me.
Thank you very much for your answers and your support! This is a great site with great people.
Instead of creating an explicit array, you may be able to name your widgets using a particular scheme and then use QObject::findChildren() on the parent widget to get a list of the widgets you are after.
If you only want to hide widgets, you can put all the widgets you want to hide in an invisible QFrame (set frameShape to NoFrame) and hide them all by calling setVisible(false) on the QFrame. This may cause some unwanted side effects with layouts so you may have to tweak some size policy settings.
In case you are wanting to hide controls so that you can simulate a wizard type UI, you may want to check into QStackedWidget.
I have another dirty workaround for this:
in header file
// .hpp
class UiBlabla : public QWidget {
...
QLabel** labels;
};
in source file
// constructor
ui->setupUi(this);
labels = new QLabel*[10]{ui->label_0, ui->label_1, ui->label_2, ui->label_3,
ui->label_4, ui->label_5, ui->label_6,
ui->label_7, ui->label_8, ui->label_9};
I haven't seen anything in QtDesigner to do that, but there are a couple of relatively easy ways to get that behavior.
1) Simply store the my_labelx pointers (from QtDesigner) in an array (or better, a QVector):
QVector<QLabel*> my_labels;
my_labels.push_back(ui->my_label1);
my_labels.push_back(ui->my_label2);
Then you can iterate through the QVector.
for(int i=0; i < my_labels.size(); ++i) {
my_labels[i]-> hide();
}
// or with QFOREACH
foreach(QLabel* label, my_labels)
label->hide();
There is a little setup needed in terms of adding all the labels to the QVector, but on the plus side you only do that once.
2) Depending on the layout of your gui, you could have all your labels be children of a container object and iterate through the children

Why is this method executing twice each time I call it?

I have the following method that is executing twice every time it is called:
public static void ChangeToRepository(RepositoryTextBox textBox, int repositoryNumber)
{
MessageBox.Show("you");
int indexOfLastRepository = (textBox.RepositoryCollection.Count - 1);
if (repositoryNumber > indexOfLastRepository)
{
AddTextRepositoriesThrough(textBox, repositoryNumber, indexOfLastRepository);
}
textBox.RepositoryCollection[textBox.CurrentRepositoryNumber].CurrentText = textBox.Text;
textBox.PreviousRepositoryNumber = textBox.CurrentRepositoryNumber;
textBox.CurrentRepositoryNumber = repositoryNumber;
textBox.Text = textBox.RepositoryCollection[textBox.CurrentRepositoryNumber].CurrentText;
}
The first time that the method executes, it executes all of the code except for its last line:
textBox.Text = textBox.RepositoryCollection[textBox.CurrentRepositoryNumber].CurrentText;
The second time, it executes all of the code. What's up?
When you assign to CurrentRepositoryNumber on the text box, it probably triggers an event handler that calls back to this function again. This seems likely because the property name suggests that it controls the current repository, which this method then is responsible for displaying somehow.
You might want to temporary delist, assign to the property and then re-enlist that event handler. Or maybe you need more of a redesign to get the responsibilities clear - often with GUI frameworks that is hard to do, and the simplest option is to just delist, assign, re-enlist, with this kind of pattern:
textBox.TextChange -= YourHandler;
textBox.Text = newValue;
textBox.TextChange += YourHandler;

Resources