I'm starting to use the GWTBoostrap3 and my greatest need is to create a menu that contains submenus, and this menu needs to be dynamic, so need to do in Java. It would be something like Gwt MenuBar
my attempts....
final ListDropDown listDropDown = new ListDropDown();
AnchorButton anchorButton = new AnchorButton(ButtonType.INFO);
anchorButton.setText("btn1");
DropDownMenu dropDownMenu = new DropDownMenu();
AnchorListItem anchorListItemd = new AnchorListItem("Item 1");
dropDownMenu.add(anchorListItemd);
anchorButton.setDataToggle(Toggle.DROPDOWN);
listDropDown.add(anchorButton);
listDropDown.add(dropDownMenu);
final ListDropDown listDropDown2 = new ListDropDown();
final AnchorButton anchorButton2 = new AnchorButton(ButtonType.INFO);
anchorButton2.setText("Item 2");
DropDownMenu dropDownMenu2 = new DropDownMenu();
dropDownMenu2.setStyleName("dropdown-submenu");
dropDownMenu2.add(new AnchorListItem("Item 1"));
HTML child = new HTML();
child.addStyleName("caret");
anchorButton2.add(child);
anchorButton2.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
anchorButton2.removeStyleName("dropdown-toggle");
listDropDown.addStyleName("open");
if(!listDropDown2.getStyleName().contains("open")){
listDropDown2.addStyleName("open");
}else{
listDropDown2.removeStyleName("open");
}
}
});
listDropDown2.add(anchorButton2);
anchorButton2.removeStyleName("dropdown-toggle");
listDropDown2.add(dropDownMenu2);
dropDownMenu.add(listDropDown2);
Bootstrap 3 does not support submenus. This is because Bootstrap 3 is a mobile first framework and submenus don't make sense on mobile.
If you still want to use submenus, you can easily add them yourself. You'll have to add the CSS referenced there somewhere in your app where it will be included and create a DropDownSubmenu widget, very similar to DropDownMenu, but using the style dropdown-submenu, instead of dropdown-menu.
Related
I have a smartGwt DynamicForm with a FormItem
FormItem item = createTextItem();
form.setFields(item);
After creating the and setting fields, I need to dynamically set an editor type for the item. I have to do it dynamically based on some conditions.
I'm calling item.setEditorType(new PasswordItem());
just after I call form.editRecord(record); so that the new editor type should appear. But it is not working.
Tried calling item.redraw() and is not working.
My goal is to set the editor type dynamically based on the record that is edited.Please help.
Try with Custom Data Binding (see page 23 for more details). What you tried won't work, AFAIK, because the ListGridField has already been created with the initial custom editor, and it can't be changed dynamically with setEditorCustomizer.
Take a look at this sample (based on this showcase demo), which does what you want to do to the password field when it is being edited in the DynamicForm, and after the changes have been saved (please pay attention to the comments, as without some of these settings it won't work as expected):
public void onModuleLoad() {
final DataSource dataSource = ItemSupplyLocalDS.getInstance();
final DynamicForm form = new DynamicForm();
form.setIsGroup(true);
form.setNumCols(4);
form.setDataSource(dataSource);
// very important for not having to set all fields all over again
// when the target field is customized
form.setUseAllDataSourceFields(true);
final ListGrid listGrid = new ListGrid();
listGrid.setWidth100();
listGrid.setHeight(200);
listGrid.setDataSource(dataSource);
listGrid.setAutoFetchData(true);
IButton editButton = new IButton("Edit");
editButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.editRecord(listGrid.getSelectedRecord());
// when the button is clicked, the password field is rendered with
// a plain text item editor, for easy verification of values entered
FormItem passwordField = new FormItem("passwordFieldName");
passwordField.setEditorProperties(new TextItem());
form.setFields(passwordField);
form.markForRedraw();
}
});
IButton saveButton = new IButton("Save");
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.saveData();
// when the button is clicked, the password field is rendered with
// a password editor, for added privacy/security
FormItem passwordField = new FormItem("passwordFieldName");
passwordField.setEditorProperties(new PasswordItem());
form.setFields(passwordField);
form.markForRedraw();
}
});
VLayout layout = new VLayout(15);
layout.setWidth100();
layout.setHeight100();
layout.addMember(listGrid);
layout.addMember(editButton);
layout.addMember(form);
layout.addMember(saveButton);
layout.draw();
}
I'm writing an Eclipseplugin, which has to create a new project. This works so far, but i need to copy an external file into the projectfolder. I intend to have a 'Browse' button on one of my WizardPages, which opens a filedialog, where the user can browse to the file and after closing the dialog i can use the path to this file for various actions. My problem is that the dialog window never opens. Right now i'm trying it that way (snippet from my wizardpage):
public void createControl(Composite composite) {
this.container = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
this.container.setLayout(layout);
layout.numColumns = 2;
Button browseButton = new Button(this.container, SWT.PUSH);
browseButton.setText("Browse");
browseButton.addSelectionListener(new SelectionListener() {
#Override
public void widgetDefaultSelected(SelectionEvent arg0) {
FileDialog fileDialog = new FileDialog(DataPage.this.container.getShell(), SWT.OPEN);
fileDialog.setText("JZOS created File");
String path = fileDialog.open();
DataPage.this.setJzosCreatedName(path);
}
});
I tried several implementations, that i have seen in examples and tutorials but nothing did work. I'm assuming a problem with the Shell that i give to the filedialog. I tried to open a new Shell within the widgetDefaultSelected function but it didn't work either. Any Suggestions?
You should be using the widgetSelected method of SelectionListener not widgetDefaultSelected
I have (in a JavaFx app) a tabpane with different tabs. I want to implement a drag and drop functionality to drag a tab outside the stage. So that it can generate a new window (like in Google Chrome).
Thanks for the help.
You should check the solution by Tom Schindl shown at his Blog
Here is an aproach, its just the part of taking the content out into a new window, but its a start.
private Tab createTab(String text) {
final Tab tab = new Tab();
final Label label = new Label(text);
tab.setGraphic(label);
label.setOnDragDone(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
if (event.getAcceptedTransferMode() == null) {
final StackPane content = (StackPane) tab.getContent();
tab.setContent(null);
Stage stage = new Stage();
stage.setScene(new Scene(content));
stage.show();
tab.getTabPane().getTabs().remove(tab);
event.consume();
}
}
});
}
Basically you must create the tab with this method, and if the receiver of the event does not support draging, that is to say, if it does not do anything specific, then you create a new stackPane with the content of the tab.
*By the way is suposed the content of the pane was a StackPane.
As per my requirement I have written a custom panel which will display three ListBoxes to enable user to select date from this custom list boxes.These three list boxes are responsible for showing month,day,year value. Now I would like to make my three list boxes are editable and at the same time selectable. I mean I would like to provide a user preferences that date can editable and at the same time selectable. How can I do this in GWT. Here I am using GWT2.0. Any one please give an idea.
A browser does not provide such a control. Neither does GWT. You will need to code your own. EXT-GWT(not free) ComboBox has this functionality. http://www.extjs.com/examples/
So does Smart GWT (also not free) http://www.smartclient.com/smartgwt/showcase/#styled_combobox_category
If you were to roll your own, you would start with a Composite which has a TextBox and a VerticalPanel that is shown when a TextBox (or part of it) is clicked. Your panel would contain the clickable items.
You could work that out using a suggestBox instead of the list box. But user would have to start typing to display the list.
You can use absolute panel to achive the same ...
Below is the code snippet.
Hide the selectbox using textbox adjust the width and location of textbox so that it should cover dropdown list...
final AbsolutePanel absolute_panel_edit_list = new AbsolutePanel();
final TextBox onhold_textbox = new TextBox();
final ListBox onhold = new ListBox();
for (int onholdcount = 0; onholdcount < onHoldTypes.length; onholdcount++)
{
onhold.addItem(onHoldTypes[onholdcount]);
}
onhold.addKeyPressHandler(new KeyPressHandler()
{
#Override
public void onKeyPress(KeyPressEvent event)
{
onhold_textbox.setStyleName("onhold_textbox");
absolute_panel_edit_list.add(onhold,0,8);
absolute_panel_edit_list.add(onhold_textbox,1,10);
absolute_panel_edit_list.setSize("142px", "35px");
flex_row4.removeCell(4, 9);
flex_row4.setWidget(4, 9, absolute_panel_edit_list);
onhold_textbox.addMouseOutHandler(new MouseOutHandler()
{
#Override
public void onMouseOut(MouseOutEvent event)
{
String customized_time = onhold_textbox.getText();
int no_of_elements = onhold.getItemCount();
onhold.addItem(customized_time);
onhold.setSelectedIndex(no_of_elements);
flex_row4.removeCell(4, 9);
flex_row4.setWidget(4, 9, onhold);
flex_row4.setWidget(4, 11, completed_togglebutton);
flex_row4.setWidget(4, 13, completed_label);
}
});
}
});
I have created a Tab panel where additional tabs can be added on clicking a button.
What I cannot figure out is how to remove a tab that is not the one that was added last.
Here's where I am....
TabPanel tp = new TabPanel();
HorizontalPanel tabPanel = new HorizontalPanel();
Label textLabel = new Label("Some Filename");
Button killButton = new Button("x");
tabPanel.add(textLabel);
tabPanel.add(killButton);
tp.add(new HTML("Some Content"), tabPanel);//Body and header
killButton.addClickHandler( new ClickHandler(){
public void onClick(ClickEvent event){
//Decide the Tab index that contains this button
//Remove this tab based on index
}
});//End of addClickHandler method
When I try to use the getWidgetIndex() method to return the index of a particular tab I get -1 everytime.
How do I correctly return an index of a tab?
please help as I am going insane!!!
:-(
to remove a tab you need either a reference to the Widget you added as the content of the tab, or you need the tab index for the tab you need to remove. Part of your above example would be like
final TabPanel tp = new TabPanel();
final HTML someContent1 = new HTML("Page A");
...
public void onClick(ClickEvent event){
tp.remove(someContent1);
// or just remove the tab it self
//tp.getTabBar().removeTab(0);
}
NingZhang.info
getWidgetIndex needs the content widget instead of the tab widget as argument. So for example in your case that would be the widget created with new HTML("Some Content").