DoubleClick on a row in JfaceTable to get the details of object on that row - swt

In eclipse e4.
On double clicking on a row in jface table I want to see the data on that row as a dialog.
Existing Code
orgTable.addDoubleClickListener(new IDoubleClickListener() {
#Override
public void doubleClick(DoubleClickEvent event) {
System.out.println("Double CLikc works");
}
});

OrgTable.addDoubleClickListener(new IDoubleClickListener() {
#Override
public void doubleClick(DoubleClickEvent event) {
System.out.println("Double CLikc works");
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
OrgDetails org = (OrgDetails) sel.getFirstElement();
if(org != null){
System.out.println("Double-click on : "+ org.getOrgName()+ " " + org.getTin());
}
System.out.println(orgTable.getElementAt());
}
});

Related

i want after editing of tableview cell textfield ,when i type i want auto suggestion of word

this code contain basically how to edit the textfield of tableview column ,like tableview column is in textfield format and i need to edit it and when i will type i need auto suggestion but my auto suggestion code is not working ,so can anyone suggest me or help to overcome my auto suggestion of word problem with the same procedure ,in createfield after commitedit i called learnword function as well but that is not happening.
class EditingCell extends TableCell<File, String> {
Set<String> possibleWordSet= new HashSet<>();
private AutoCompletionBinding<String> autoCompletionBinding;
public TextField textField;
//private Object possibleWordSet;
#Override
public void startEdit() {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
setGraphic(textField);
System.out.println(textField.getCaretPosition() + "caret position");
}
}
#Override
public void cancelEdit() {
super.cancelEdit();
setText(getItem());
setGraphic(null);
}
#Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
System.out.println("I am in update function");
setText(null);
setGraphic(null);
} else {
if (isEditing()) {
if (textField != null) {
textField.setText(item);
}
setText(null);
setGraphic(textField);
} else {
setText(item);
setGraphic(null);
}
}
}
// Instantiates the text field.
public void createTextField() {
textField = new TextField(getItem());
System.out.println("hello i am inside the createtextfield");
textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
autoCompletionBinding = TextFields.bindAutoCompletion(textField, possibleWordSet); /tion/for auto suuges
textField.setOnKeyReleased(new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent t) {
if (t.getCode() == KeyCode.ENTER) {
commitEdit(textField.getText());//on enter event editing of textfield
learnword(textField.getText());//for auto suggestion call learnword method.
} else if (t.getCode() == KeyCode.ESCAPE) {
cancelEdit();
}
}
});
textField.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
int caretPosition = textField.getCaretPosition();
GUIFXMLDocumentController fx = new GUIFXMLDocumentController();
fx.setCaretPos(caretPosition);
System.out.println(caretPosition + "caretPosition");
fx.setTextField(textField);
}
});
textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
#Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
if (!arg2) {
System.out.println(textField.getText() + "Inside changeListener------------------");
GUIFXMLDocumentController.tv_new.getFocusModel().focusNext();
commitEdit(textField.getText());
learnword(textField.getText());
}
}
});
}
public void learnword(String text) {
possibleWordSet.add(text);
if(autoCompletionBinding!=null){
autoCompletionBinding.dispose();
}
autoCompletionBinding = TextFields.bindAutoCompletion(textField, possibleWordSet);
}
}
enter code here

Why does setText in the TextField doesn't work?

Why does this method doesn't save the new selected categories. is there something wrong with my codes?
catCon = new TextField();
rowEditing.addEditor(catConfig, catCon);
this is the code for setting the catCon:
TextButton save = new TextButton("Save");
save.addSelectHandler(new SelectEvent.SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
selectedItems = new LinkedList<Short>();
for (int i = 0; i < toCat.size(); i++) {
selectedItems.add(toCat.get(i).getIDCategory());
}
Collections.sort(selectedItems);
newSelectedItems = selectedItems.toString().replace(",", "-").replace("[", "").replace("]", "").replace(" ", "");
msg = new MessageBox("SELECTED ITEMSSSSSSSSS: " + selectedItems.size() + " " + newSelectedItems);;
msg.show();
catCon.setText(newSelectedItems);
hide();
}
});
and this is where the saving of the commited changes:
rowEditing.getSaveButton().addSelectHandler(new SelectEvent.SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
store.commitChanges();
service.saveUserRights(store.get(index), new AsyncCallback<Boolean>() {
#Override
public void onFailure(Throwable caught) {
msg = new MessageBox("Error", caught.getMessage());
msg.show();
}
#Override
public void onSuccess(Boolean result) {
if (result) {
msg = new MessageBox("Information", "Changes saved.");
msg.show();
service.getURListGrid(new AsyncCallback<List<UserRights>>() {
#Override
public void onFailure(Throwable caught) {
MessageBox msg = new MessageBox("Error", caught.getMessage());
msg.show();
}
#Override
public void onSuccess(List<UserRights> result) {
store = new ListStore<UserRights>(properties.idRight());
store.addAll(result);
grid.reconfigure(store, cm);
}
});
} else {
msg = new MessageBox("Error", "Failed to save changes.");
msg.show();
}
}
});
}
});
When I am going to set the catCon there will no be changes of the data but when I manually type the categories there will be a change. Can somebody help me?
In order for me to save the current categories is to get the index of the store and set the category to the newSelectedItem
store.get(index).setCategories(newSelectedItems);
I hope this will help to the people who has the same problem as mine.

How can we get the item on which i am doing the drop on a treeviewer

I have created a jface treeviewer and i am adding drag and drop of elements into the treeviewer.So the items should be added on the the subchild of a tree.How can i get the subchildname on which i am dropping a element.
for eg:
tree->
A->
1
2
B
C
so when I drag and drop on 1 it should get the selecteditem as 1 how can we do it.
the code for drop is as follows
int operationsn = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transferType = new Transfer[]{TestTransfer.getInstance()};
DropTarget targetts = new DropTarget(treeComposite, operationsn);
targetts.setTransfer(new Transfer[] { TestTransfer.getInstance() });
targetts.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
System.out.println("dragEnter in target ");
if (event.detail == DND.DROP_DEFAULT) {
if ((event.operations & DND.DROP_COPY) != 0) {
event.detail = DND.DROP_COPY;
} else {
event.detail = DND.DROP_NONE;
}
}
}
public void dragOver(DropTargetEvent event) {
System.out.println("dragOver in target ");
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
}
public void dragOperationChanged(DropTargetEvent event) {
System.out.println("dragOperationChanged in target ");
if (event.detail == DND.DROP_DEFAULT) {
if ((event.operations & DND.DROP_COPY) != 0) {
event.detail = DND.DROP_COPY;
} else {
event.detail = DND.DROP_NONE;
}
}
}
public void dragLeave(DropTargetEvent event) {
System.out.println("dragLeave in target ");
}
public void dropAccept(DropTargetEvent event) {
System.out.println("dropAccept in target ");
}
public void drop(DropTargetEvent event) {
//if (textTransfer.isSupportedType(event.currentDataType))
if (event.data != null) {
Test tsType = (Test) event.data;
addItem(tsType);
System.out.println("test step name is" +tsType);
}
}
});
Here in the addItem function I have written the code to add item to the treeviewer on the selecteditem.but while dropping the item I am not able to select the item so how can we selected the item while dropping the elements into the tree.
When using JFace Viewers you can use the JFace ViewDropAdapter class rather than DropTargetListener.
This class does more work for you and has a getCurrentTarget() method to return the current target element.
More details on this here

Items does not sets disabled after first click on ListBox in Chrome

Here is my code:
listbox.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
serv.getSlotStatusesStrings(clientFactory.getWorkspaceId(), new AsyncCallback<SlotStatusGwtStruct>() {
#Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
#Override
public void onSuccess(SlotStatusGwtStruct result) {
List<String> statusList = Arrays.asList(result.styleName);
int emtyCounter = 0;
boolean passFlag = false;
boolean failFlag = false;
for(String status : statusList){
if(status.equals("empty")){
emtyCounter++;
}else if(status.equals("pass")){
passFlag = true;
}else if(status.equals("fail")){
failFlag = true;
}
}
if(emtyCounter == statusList.size()){
listbox.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
}
if(passFlag == false){
listbox.getElement().<SelectElement>cast().getOptions().getItem(1).setDisabled(true);
}
if(failFlag == false){
listbox.getElement().<SelectElement>cast().getOptions().getItem(2).setDisabled(true);
}
}
});
}
});
}
In Firefox it works ok, but in Chrome browser when I click on listbox at the first time all my items are enabled (by condition they should be disabled), and after I made one more click I have the expected result.
Could yo please give me some advice how to resolve this issue.

Drag & Drop in JavaFX table?

I am using a JavaFX 2 table for some kind of playlist and I want to be able to drag & drop rows in the table, e.g. drag row 3 before row 2, like the drag & drop stuff you know from the playlists in typical media players like e.g. Winamp, AIMP...
Is that possible? Any code samples for that? Thank you very much!
try this one :)
#FXML
TableView<String> tableView;
private ObservableList<String> tableContent = FXCollections.observableArrayList();
//...
tableView.setOnMouseClicked(new EventHandler<MouseEvent>() { //click
#Override
public void handle(MouseEvent event) {
if(event.getClickCount()==2){ // double click
String selected = tableView.getSelectionModel().getSelectedItem();
if(selected !=null){
System.out.println("select : "+selected);
...
}
}
}
});
tableView.setOnDragDetected(new EventHandler<MouseEvent>() { //drag
#Override
public void handle(MouseEvent event) {
// drag was detected, start drag-and-drop gesture
String selected = tableView.getSelectionModel().getSelectedItem();
if(selected !=null){
Dragboard db = tableView.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.putString(selected);
db.setContent(content);
event.consume();
}
}
});
tableView.setOnDragOver(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
// data is dragged over the target
Dragboard db = event.getDragboard();
if (event.getDragboard().hasString()){
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
event.consume();
}
});
tableView.setOnDragDropped(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
Dragboard db = event.getDragboard();
boolean success = false;
if (event.getDragboard().hasString()) {
String text = db.getString();
tableContent.add(text);
tableView.setItems(tableContent);
success = true;
}
event.setDropCompleted(success);
event.consume();
}
});