Skip to content

Commit

Permalink
gwt
Browse files Browse the repository at this point in the history
  • Loading branch information
witek committed May 26, 2011
1 parent 7e9acd6 commit b366102
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
30 changes: 13 additions & 17 deletions src/main/java/ilarkesto/gwt/client/ADropdownViewEditWidget.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/*
* Copyright 2011 Witoslaw Koczewsi <[email protected]>, Artjom Kochtchi
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
* General Public License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
package ilarkesto.gwt.client;

import ilarkesto.core.base.ToHtmlSupport;
import ilarkesto.core.logging.Log;

import java.util.LinkedHashMap;
import java.util.Map;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;
Expand All @@ -41,11 +41,17 @@ protected final Widget onViewerInitialization() {
protected final Widget onEditorInitialization() {
editor = new ListBox();
editor.addChangeHandler(new EditorChangeListener());
editor.addFocusListener(new EditorFocusListener());
editor.addKeyDownHandler(new CancelKeyHandler());
editor.setVisibleItemCount(7);
return editor;
}

@Override
protected void onEditorUpdate() {
Log.DEBUG("----------> ADropdownViewEditWidget.updateEditor()");
editor.setFocus(true);
}

public final void setOptions(String... options) {
Map<String, String> optionsAsKeyLabelMap = new LinkedHashMap<String, String>();
for (String option : options) {
Expand Down Expand Up @@ -100,14 +106,4 @@ public void onChange(ChangeEvent event) {

}

private class EditorFocusListener implements FocusListener {

public void onFocus(Widget sender) {}

public void onLostFocus(Widget sender) {
submitEditor();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected CheckBox createCheckbox(I item) {
return new CheckBox(toHtml(item), true);
}
};
editor.addKeyDownHandler(new CancelKeyHandler());

ToolbarWidget toolbar = new ToolbarWidget();
toolbar.addButton(new AAction() {
Expand Down Expand Up @@ -121,6 +122,7 @@ public final void setViewerItemsAsHtml(Collection<? extends ToHtmlSupport> items

public void setEditorItems(Collection<I> items) {
editor.setItems(items);
editor.setFocus(true);
}

public void setEditorSelectedItems(Collection<I> items) {
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/ilarkesto/gwt/client/MultiSelectionWidget.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright 2011 Witoslaw Koczewsi <[email protected]>, Artjom Kochtchi
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
* General Public License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
Expand All @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FocusListener;
Expand Down Expand Up @@ -103,4 +104,14 @@ public void addFocusListener(FocusListener focusListener) {
panel.addFocusListener(focusListener);
}

public void addKeyDownHandler(KeyDownHandler handler) {
initialize();
panel.addKeyDownHandler(handler);
}

public void setFocus(boolean focus) {
initialize();
panel.setFocus(focus);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright 2011 Witoslaw Koczewsi <[email protected]>, Artjom Kochtchi
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
* General Public License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
Expand Down Expand Up @@ -41,6 +41,7 @@ protected void onViewerUpdate() {

@Override
protected void onEditorUpdate() {

options = model.getOptions();
Map<String, String> optionsMap = new LinkedHashMap<String, String>();
int index = 0;
Expand All @@ -49,14 +50,14 @@ protected void onEditorUpdate() {
index++;
}
setOptions(optionsMap);
super.onEditorUpdate();
}

@Override
protected void onEditorSubmit() {
String selected = getSelectedOption();
int index = Integer.parseInt(selected);
model.changeValue(options.get(index));
// TODO catch exceptions
}

@Override
Expand Down

0 comments on commit b366102

Please sign in to comment.