bug fixed: choose contacts

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@69064 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-02-08 16:31:14 +00:00
parent 9c7fb67f32
commit 96a3f9016c
2 changed files with 35 additions and 14 deletions

View File

@ -111,8 +111,7 @@ public class DialogShareFolder extends Dialog {
}
});
setFocusWidget(txtName);
setFocusWidget(suggestPanel.getBox());
add(txtName);
add(lc);
addListners();
@ -232,9 +231,14 @@ public class DialogShareFolder extends Dialog {
@Override
public void componentSelected(ButtonEvent ce) {
suggestPanel.resetItemSelected();
for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
suggestPanel.addRecipient(infoContactModel.getLogin());
}
suggestPanel.boxSetFocus();
}
});
}

View File

@ -35,7 +35,7 @@ public class MultiValuePanel extends Composite {
FlowPanel panel = new FlowPanel();
// private HandlerManager eventBus;
private HashMap<String, InfoContactModel> users = new HashMap<String, InfoContactModel>();
private BulletList list = new BulletList();
private BulletList listBullet = new BulletList();
private SuggestBox box;
private ContactFetcher userFetch;
private MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
@ -48,14 +48,14 @@ public class MultiValuePanel extends Composite {
this.userFetch = userFetch;
initWidget(panel);
panel.setWidth("100%");
list.setStyleName("multivalue-panel-suggest");
listBullet.setStyleName("multivalue-panel-suggest");
final ListItem item = new ListItem();
final TextBox itemBox = new TextBox();
itemBox.getElement().setAttribute("style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium; border: none;");
box = new SuggestBox(getSuggestions(), itemBox);
item.add(box);
list.add(item);
listBullet.add(item);
// needed to be set on the itemBox instead of the box, otherwise backspace gets executed twice
itemBox.addKeyDownHandler(new KeyDownHandler() {
@ -64,8 +64,8 @@ public class MultiValuePanel extends Composite {
if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
if ("".equals(itemBox.getValue().trim())) {
if(list.getWidgetCount()>2){
ListItem li = (ListItem) list.getWidget(list.getWidgetCount() - 2);
if(listBullet.getWidgetCount()>2){
ListItem li = (ListItem) listBullet.getWidget(listBullet.getWidgetCount() - 2);
if(li.getWidget(0) instanceof Paragraph){
Paragraph p = (Paragraph) li.getWidget(0);
@ -73,7 +73,7 @@ public class MultiValuePanel extends Composite {
itemsSelected.remove(p.getText());
GWT.log("Removing selected item: " + p.getText() + "'");
}
list.remove(li);
listBullet.remove(li);
itemBox.setFocus(true);
}
}
@ -84,18 +84,20 @@ public class MultiValuePanel extends Composite {
box.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
public void onSelection(SelectionEvent<SuggestOracle.Suggestion> selectionEvent) {
chosenContactItem(itemBox, list);
chosenContactItem(itemBox, listBullet);
}
});
panel.add(list);
panel.add(listBullet);
box.getElement().setId("suggestion_box"); //needed for the focus on click
panel.getElement().setAttribute("onclick", "document.getElementById('suggestion_box').focus()");
// box.setFocus(true);
}
public void boxSetFocus(){
box.getElement().focus();
box.setFocus(true);
// panel.getElement().setAttribute("onclick", "document.getElementById('suggestion_box').focus()");
}
public FlowPanel getFlowPanel(){
@ -209,10 +211,20 @@ public class MultiValuePanel extends Composite {
return listUsers;
}
public void resetItemSelected(){
listBullet.clear();
itemsSelected.clear();
ListItem item = new ListItem();
item.add(box);
listBullet.add(item);
}
/**
* insert the attachment item view in the flow panel
*/
public void addRecipient(String fullName) {
if (fullName != null) {
TextBox itemBox = new TextBox();
itemBox.setText(fullName);
@ -224,7 +236,7 @@ public class MultiValuePanel extends Composite {
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeListItem(displayItem, list);
removeListItem(displayItem, listBullet);
}
});
@ -235,13 +247,18 @@ public class MultiValuePanel extends Composite {
itemsSelected.add(itemBox.getValue());
GWT.log("Total: " + itemsSelected);
list.insert(displayItem, list.getWidgetCount());
listBullet.insert(displayItem, listBullet.getWidgetCount());
itemBox.setValue("");
itemBox.setFocus(true);
}
}
public void clearList() {
list.clear();
listBullet.clear();
}
public SuggestBox getBox() {
return box;
}
}