MutiText Input using JFACE with the help of + button - text

I am new to JFACE and was designing a multitext input in the following way.
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Label text1=new Label(composite,SWT.NONE);
text1.setText("Provide The names");
text1.setForeground(darkmagenta);
text1.setFont(boldFont);
noOfTables= new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL );
noOfTables.setLayoutData(new GridData(GridData.FILL_BOTH));
and it is working fine.
However I wanted to know if I could add a muli user input using a + button.
Say a user inputs a name , then if he has one more name to add , he clicks on the + button and another text area opens for him below.
I have looked online for this and didn't come up with anything
Any help/comments would be welcome.
Cheers,
P

It's not hard ... just put a selection listener on your button that invokes a method that creates a new Composite inside your parent Composite and pack the outermost container (Shell) after the new container is added.
Your button listener would look something like this:
public void widgetSelected(SelectionEvent e) {
displays.add(createArea(c));
shell.pack();
}
The createArea method would look something like this:
private Composite createArea(Composite c) {
Composite inner = new Composite(c, SWT.NONE);
inner.setLayout(new GridLayout(2, false));
inner.setLayoutData(new GridData(GridData.FILL, GridData.END, true, false));
GridData gd = new GridData(SWT.FILL, SWT.FILL, true,true);
Label l = new Label(inner, SWT.NONE);
l.setText("Label #" + lCount++);
l.setLayoutData(gd);
Text t = new Text(inner, SWT.NONE);
t.setLayoutData(gd);
return inner;
}

Related

JavaFX2 TreeView menu create

I have a Treeview with menu content, which is working. I am just not sure how can I implement more root menu to add?
Because this code only shows the "File" menu and all of submenus, but not the other roots.
-Also I would like to ask how could I make these submenus to act like links and create mouselisteners to them? Where is the right place to take the listeners?
The code is the following:
TreeItem<String> treeItemRoot1 = new TreeItem<> ("File");
TreeItem<String> treeItemRoot2 = new TreeItem<> ("Edit");
TreeItem<String> treeItemRoot3 = new TreeItem<> ("View");
TreeItem<String> treeItemRoot4 = new TreeItem<> ("Tools");
TreeItem<String> treeItemRoot5 = new TreeItem<> ("Help");
TreeItem<String> nodeItemA = new TreeItem<>("Item A");
TreeItem<String> nodeItemB = new TreeItem<>("Item B");
TreeItem<String> nodeItemC = new TreeItem<>("Item C");
treeItemRoot1.getChildren().addAll(nodeItemA, nodeItemB, nodeItemC);
TreeView<String> treeView = new TreeView<>(treeItemRoot1);
StackPane.getChildren().add(treeView);
The first part of your question is answered here: Set two root nodes for TreeView
For the second part, it depends on exactly what functionality you want. If you want to respond to a change in the selected item in the tree (this would include the user selecting either with the mouse or by using the keyboard), so can add a listener to the tree's selected item:
treeView.getSelectionModel().selectedItemProperty().addListener((obs, oldItem, newItem) -> {
if (newItem == treeItemRoot1) {
// "file" selected...
} else if (newItem == treeItemRoot2) {
// edit selected
} // etc...
});
If you genuinely want a mouse listener, you need to add a listener to the cell. To do this, use a cell factory:
treeView.setCellFactory(tv -> {
TreeCell<String> cell = new TreeCell<>();
cell.textProperty().bind(cell.itemProperty());
cell.setOnMousePressed(event -> {
TreeItem<String> item = cell.getTreeItem();
if (item == treeItemRoot1) {
// "file" clicked...
} else if (item == treeItemRoot2) {
// etc...
}
}
return cell ;
});
You can probably find ways to organize the code a little more cleanly, and avoid the big if-else construct in either case.

Determine which Monotouch.Dialog Checkbox was checked/unchecked

I have a list of people that I want to display with checkboxes next to their names. When an CheckBoxElement (person) is checked or unchecked, I need to handle the event.
List<CheckboxElement> cbPersonElements = new List<CheckboxElement> ();
CheckboxElement tmpCheckbox = new CheckboxElement ("");
foreach (ABPerson itemPerson in _people) {
tmpCheckbox = new CheckboxElement (itemPerson.LastName);
cbPersonElements.Add(tmpCheckbox);
}
And then I add the list when I create the RootElement:
RootElement _rootElement = new RootElement ("People List"){
new Section ("People"){
cbPersonElements
}
How should I add a handler that will allow me to detected which CheckBoxElement was clicked.
I can't attach one to tmpCheckbox, that value changes with each iteration through the loop.
Seems like it should be simple, but I can't see it.
Thanks.
you should be able to use a ValueChanged handler
foreach (ABPerson itemPerson in _people) {
tmpCheckbox = new CheckboxElement (itemPerson.LastName);
tmpCheckbox.ValueChanged += delegate {
// do something here based on tmpCheckbox.Value
};
cbPersonElements.Add(tmpCheckbox);
}

MonoTouch Message Element opes page with string elements

I have the following code:
Section _section = new Section ("Test");
foreach (ExampleData data in Example.data) {
MessageElement Item = new MessageElement (){
Sender = data.Name,
Subject = data.Value,
Body = data.Description,
Date = data.Modified
} ;
_section.Add(Item);
var root = new RootElement("Item Expanded"){
new Section ("test2"){
new StringElement("Field Name", data.FieldName),
new StringElement("Value", data.Value),
new StringElement("Description", data.Description)
}
} ;
_section.Add(root);
} ;
var _rootElement = new RootElement ("Items") {
_section
} ;
I would like this to work in such a way that when a Message Element is tapped it shows the section with ("test2") that has the same data (e.g. the data was added during the same run of the loop.) I realize this will not happen currently, as it seems the Message Element
requires an Action delegate to do anything on a tap event, plus I'm adding everything to the same section. However, is there any way to replicate the behavior of multiple nested root elements and sections with a Message Element? If I create new pages/screens and try to transition that way, it rests the navigation controller and I lose the use of the back button, even if "push" is set to true.
Not sure what you want exactly. Replace your "Item Expanded" root element code with this to push a dialog viewcontoller on the navigation stack with a backbutton. Ofcourse your DialogViewcontroller should be in a UINavigation controller in the first place for this to work
Item.Tapped += delegate(DialogViewController arg1, UITableView arg2, NSIndexPath arg3)
{
var newDialogVC = new DialogViewController(
UITableViewStyle.Grouped,
new RootElement("Item Expanded")
{
new Section ("test2"){
new StringElement("Field Name", "test"),
new StringElement("Value", "test"),
new StringElement("Description", "test")
}
}
, true);
arg1.NavigationController.PushViewController(newDialogVC,true);
};

Adding Layout to Container in loop fires an NullpointerException

I am developing s60 using j2me with LWUIT in Eclipse.
I am writing this method to draw list item and try to create List manually rather than using Lwuit list. Because as i posted in my last question here is LinK.. don't know why but it decreases performance.
So In below method i trying to create in which i'm adding adding two labels to layoutX Container and adding that Conatiner to layoutY Container and Adding that layoutY to BaseContainer so output is looks like list.
Method is here ...
private void drawAgendasListItem(Vector vector) {
Container containerX[] = new Container[vector.size()];
Container containerY[] = new Container[vector.size()];
if (featuredeventsForm.contains(baseContainer)) {
baseContainer.removeAll();
featuredeventsForm.removeComponent(baseContainer);
System.out.println("base Container is removed ");
}
BoxLayout layoutX = new BoxLayout(BoxLayout.X_AXIS);
BoxLayout layoutY = new BoxLayout(BoxLayout.Y_AXIS);
for (int i = 0; i < vector.size(); i++) {
try {
containerX[i].setLayout(layoutX);
containerY[i].setLayout(layoutY);
Label startTime = new Label();
Label description = new Label();
startTime.getStyle().setBgTransparency(0);
startTime.setText("start 10:20 Am");
startTime.getStyle().setMargin(0, 0, 0, 5);
description.getStyle().setBgTransparency(0);
description.setText("decriptionString");
containerX[i].getStyle().setPadding(0, 0, 2, 2);
containerX[i].addComponent(startTime);
containerX[i].addComponent(description);
containerY[i].addComponent(containerX[i]);
baseContainer.addComponent(i, containerX[i]);
System.out.println("Component added to base Container # " + i);
} catch (Exception e) {
System.out.println("Exception in drawAgendaListItem " + e);
}
}
featuredeventsForm.addComponent(baseContainer);
featuredeventsForm.invalidate();
featuredeventsForm.repaint();
System.out.println("All elements added and form repainted");
}
In above method when i try to assign layout to Container it fires an NullPointerException at line
containerX[i].setLayout(layoutX);.
I don't understand why it's happening, I was also try to comment that lines then it fires NullPointerException at line containerX[i].getStyle().setPadding(0, 0, 2, 2);.
please help ....
Based on the source code, my guess is that you think instantiating an array also populates it. That is not the case in Java.
In other word, if you think that containerX looks like:
[new Container, new Container,..., new Container]
in memory, that is incorrect. It actually looks like:
[null,null,...,null]
I think you need to add
containerX[i] = new Container();
containerY[i] = new Container();
at the beginning of the loop.
(Maybe you want to instantiate the contents of the arrays as subclasses of Container)

Highlight the selected cell in a DataGridView?

In my code below, I'm showing a context menu when the user right-clicks on a cell in my DataGridView. I'd also like the cell that the user right-clicks on to change background color so that they can see the cell they've "right-click selected". Is there a way to add something to my code below so that this occurs?
private void dataGridView2_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenu m = new ContextMenu();
MenuItem mnuCopy = new MenuItem("Copy");
mnuCopy.Click += new EventHandler(mnuCopy_Click);
m.MenuItems.Add(mnuCopy);
int currentMouseOverRow = dataGridView2.HitTest(e.X, e.Y).RowIndex;
m.Show(dataGridView2, new Point(e.X, e.Y));
}
}
So obviously you've hacked into my workstation and have seen some of the stuff I've worked on recently. I exaggerate a bit because I didn't do exactly what you're trying to do but with a little bit of tweaking I was able to.
I would modify your MouseClick event to get the DGV's CurrentCell. Once you have it, set the CurrentCell's Style property with the SelectionBackColor you want. Something like this:
// ...
DataGridView.HitTestInfo hti = dataGridView2.HitTest(e.X, e.Y);
if (hti.Type == DataGridViewHitTestType.Cell) {
dataGridView2.CurrentCell = dataGridView2.Rows[hti.RowIndex].Cells[hti.ColumnIndex];
dataGridView2.CurrentCell.Style = new DataGridViewCellStyle { SelectionBackColor = System.Drawing.Color.Yellow};
}
//...
The above is a bit 'air code-y' (in other words I haven't attempted to merge it with your code and run it) but I hope you get the idea. Notice that I check through the hit test that a cell was clicked; if you don't do this and the user does not click a cell you might have some problems.
Now there's the problem that this code will change the SelectionBackColor for the all the cells you right click. That's easy to restore this property in the DGV's CellLeave event:
private void dgvBatches_CellLeave(object sender, DataGridViewCellEventArgs e) {
dataGridView2.CurrentCell.Style = new DataGridViewCellStyle { SelectionBackColor = System.Drawing.SystemColors.Highlight };
}
I'll have to remember this visual affect; thanks for asking the question.

Resources