Wicket - create a dynamic label - wicket

I would like to create a dynamic label in a wicket project.
I have the variable x, which is of type boolean. If the value is true, then the label should output "Text 1". Otherwise it should display "Text 2".
I don't want to set the value from the outside, but rather the label should know what kind of value it should display.
Which method do I have to override for this?

You dont have to override any method just put in the proper Model.
new Label("id", () -> x ? "Text 1" : "Text 2");

Related

Text Field name programatically in swift 4

I've below form:-
I've created this form programatically.
The code for this is below:-
let textFiled = UITextField(frame:CGRectMake(87.0, y, 100.0, 20.0))
textFiled.borderStyle = UITextBorderStyle.Line
textFiled.font = UIFont.systemFontOfSize(8)
Now if I set tag for these text field then it'll store Int value. Which is very tough for me to manipulate this form.
I want to set name like IBOutlet for each text field. So that I can easily handle this form.
Is it possible to do it in Swift 4...
I want Your opinion please....
Similar to tag, we have
accessibilityIdentifier
in which you can add String values
you can just say
textFiled.accessibilityIdentifier = "name"
and get value using the below:-
textFiled.accessibilityIdentifier
UPDATE:
I suggest we never use the accessibilityIdentifier as it's for testing, for your case you should subclass UITextField and add a custom property to identify the text field

How can I use ValidationSupport between two textfields?

I would like to use the ValidationSupport to check the content of textfield2 against the content of textfield1. Here is what I tried to do :
validationSupport = new ValidationSupport();
validationSupport.registerValidator(textfield2, false, (Control c, String newValue)
-> ValidationResult
.fromMessageIf(textfield2,
"Should contain texfield",
Severity.WARNING,
!newValue.contains(textfield1.getText())));
validationSupport.initInitialDecoration();
Filling textfield1 first, then texfield2 is working as I expect : the warning decoration is displayed on textfield2 until the textfield1 content is not included in the texfield2 content.
But starting from same content in textfield 1 & 2, and trying to change texfield1 again (hence at this point, textfield1 content differ from textfield2 content), I was expecting the warning decoration to be displayed immediately on texfield2, which is not the case !
Indeed in order to have the validationSupport checked again, I need to update the textfield2 again. Only after the texfield2 content has been updated, then the ValidatorSupport is checked again, and the decoration is updated accordingly !
The only way I found to always get the decoration up to date is to remove the previous registerValidator and to add a listener on textfield1 textProperty to register a new validator for texfield2 each time textfield1 content is changed :
textfield.textProperty().addListener((observable, oldValue, newValue)
-> validationSupport.registerValidator(textfield2, false, (Control c, String str)
-> ValidationResult
.fromMessageIf(textfield2,
"Should contain texfield1",
Severity.WARNING,
!str.contains(textfield.getText()))));
This is working (meaning when I change textfield1, decoration on textfield 2 is updated immediately) but I feel it's not the right solution, but can't find another / better one. Is it the right way to do ? If not, what is the right way ? Any recommendation ? Thanks.

Enterprise Architect: Hide only "top" labels of connectors programmatically

I want to hide the "top" part of all connector labels of a diagram. For this, I tried to set up a script, but it currently hides ALL labels (also the "bottom" labels which I want to preserve):
// Get a reference to the current diagram
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();
if (currentDiagram != null)
{
for (var i = 0; i < currentDiagram.DiagramLinks.Count; i++)
{
var currentDiagramLink as EA.DiagramLink;
currentDiagramLink = currentDiagram.DiagramLinks.GetAt(i);
currentDiagramLink.Geometry = currentDiagramLink.Geometry
.replace(/HDN=0/g, "HDN=1")
.replace(/LLT=;/, "LLT=HDN=1;")
.replace(/LRT=;/, "LRT=HDN=1;");
if (!currentDiagramLink.Update())
{
Session.Output(currentDiagramLink.GetLastError());
}
}
}
When I hide only the top labels manually (context menu of a connector/Visibility/Set Label Visibility), the Geometry property of the DiagramLinks remains unchanged, so I guess the detailed label visibility information must be contained somewhere else in the model.
Does anyone know how to change my script?
Thanks in advance!
EDIT:
The dialog for editing the detailed label visibility looks as follows:
My goal is unchecking the "top label" checkboxes programmatically.
In the Geometry attribute you will find a partial string like
LLT=CX=36:CY=13:OX=0:OY=0:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=1:DIR=0:ROT=0;
So in between LLT and the next semi-colon you need to locate the HDN=0 and replace that with HDN=1. A simple global change like above wont work. You need a wild card like in the regex LLT=([^;]+); to work correctly.

how to set selected value in sap.m.searchfield ui5

I have used a sap.m.SearchField in(SAPUI5),
Now I want to set one of the suggestion item as selected, I mean I want to set a default value to the search field.
How to set selected value in sap.m.SearchField?
While defining SearchField itself you can set the value.
var oSearchField = new sap.m.SearchField({
value: "samplePreText"
});
If you plan to change on some event:
oSearchField.setValue("samplePreText");

How to select an item in SmartGWT SelectItem?

I have a SelectItem object which has a few items. I set a value MAP with:
organizations[0] = "A";
organizations[0] = "B";
selectItem.setValueMap(organizations);
When displayed, the combo box is showing "A" as selected item. Then, I need to programatically select value "B" and select this on the current SelectItem object. I've been looking all over the place with no avail.
Anyone?
If you want any option of selectItem to be manually selected, then you should try following:
selectItem.setValue("B");
After doing this when you open the picklist of the selectItem, value "B" will be highlighted.