Javafx drag and drop TabPane - drag-and-drop

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.

Related

How to access the currently selected item within Wicket Palette

I am trying to override certain features of the Wicket Palette. I have attached a picture of what i am trying to accomplish with Palette. Basically in addition to the select-item-clickbutton-moveToRight functionality of Palette, I also want to know which item has been selected before it is moved. When I select an item in either of the panels and click on a View button, I should be able to display an html page related to the currently selected item from the Palette.
Right now, the button is placed out of the Palette code and as long as I can get the ID of the selected element, I will be able to accomplish my objective.
I am stuck at the point where I need to know which item has been selected within the palette.
Here's what I have tried so far:
1. Adding an onclick listener to the choicesComponent using the AjaxFormComponentUpdatingBehavior
final Palette classFormMapping = new Palette("formsPalette", new ListModel(selectedFormsList),
formsList, new CustomObjectChoiceRenderer(), 8 , false ){
#Override
protected void onBeforeRender() {
super.onBeforeRender();
getChoicesComponent().add(new AjaxFormComponentUpdatingBehavior("onclick"){
#Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("REACHED HERE"+ getFormComponent());
/*
* The code reaches here for each click but I am unable to know which item was selected */
}
});
}
};
Adding a Recorder component to the Palette with an "onclick" listener.
This listener does not get called at all.
final Palette classFormMapping = new Palette("formsPalette", new ListModel(selectedFormsList),
formsList, new CustomObjectChoiceRenderer(), 8 , false ){
protected Recorder newRecorderComponent() {
Recorder recorder = super.newRecorderComponent();
recorder.add(new AjaxFormComponentUpdatingBehavior("onclick") {
private static final long serialVersionUID = 1L;
#Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("reached record on click ");
}
});
return recorder;
}
};
Trying to create this palette with a custom button
Please help. Thanks in advance.
Palette.java javadoc explains how to "Ajax-ify" it: https://github.com/apache/wicket/blob/529db58c413861677f7ff6736f9363edf42ae85a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java#L52-L71
But this won't help you because the selection is done at the client side first and then Wicket is notified:
https://github.com/apache/wicket/blob/529db58c413861677f7ff6736f9363edf42ae85a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js#L118-L127
You need either to register your own JS event listener for 'change' event before the Wicket one or monkey-patch palette.js to override Wicket.Palette.updateRecorder() function.

How to open a filedialog within an Eclipse Wizard

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

GwtBootstrap3 NavBar with submenu

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.

SmartGwt - Removing one tab clears the canvas

I've built a GUI with a SmartGWT TabSet with Tabs that can be dynamically added and removed.
The Tabs share the same canvas which is moved from Tab to Tab at each tab selection like this:
myTabSet.addTabSelectedHandler(new TabSelectedHandler() {
public void onTabSelected(TabSelectedEvent event) {
[...]
myTabs[myTabSet.getSelectedTabNumber()].setPane(myCanvas);
// Then I fill the contained widgets with the tab-specific data
}
}
This works, but when I try to remove a Tab with
myTabSet.removeTab(iToBeDeletedTab);
The tab is removed but the remaining tabs have a blank pane, I can get the content back only by reloading the page. I found that I have to prevent pane destruction with calls to :
myTabSet.setDestroyPanes(false);
and
myTabSet.updateTab(iToBeDeletedTab, null);
//called right before
myTabSet.removeTab(iToBeDeletedTab);
I understand that the canvas/pane is still destroyed, but I cannot figure out how to prevent this.
Has anyone any hint?
Thank you!
Have you tried to call the redraw() method after removing a tab? This usually helps me when loading/reloading data with smartGWT widgets.
Your calls are correct, but now what you've got is the pane completely unnassociated from the TabSet and not drawn (check the Watch Tab in the Developer Console and you'll see this). Now, call updateTab(someOtherTab, pane) to connect the pane to one of the other tabs where it should be showing.
Ok, I've made some test and got the same as you but had some success with the following code:
1°) in the Javadoc I found:
***public void setPane(Canvas pane)
Specifies the pane associated with this tab. You can change the pane associated with a given tab after the TabSet has been created by calling TabSet.updateTab(int, com.smartgwt.client.widgets.Canvas)***
I tried without setting to null the pane of tab1 , it didn't work.
I think it could be arranged in better way but anyway the point is to use the updatePadmethod
public static void testTabDelete(){
final Canvas theCanvas = new Canvas();
final TabSet theTabs = new TabSet();
theTabs.setWidth("80%");
theTabs.setHeight("80%");
final Tab tab1 = new Tab("Tab1");
final Tab tab2 = new Tab("Tab2");
final Tab tab3 = new Tab("Tab3");
IButton btn1 = new IButton("Btn1");
btn1.setLeft(10);
btn1.setTop(100);
btn1.setWidth(80);
theCanvas.addChild(btn1);
IButton btn2 = new IButton("Delete");
btn2.setLeft(100);
btn2.setTop(100);
btn2.setWidth(80);
btn2.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
#Override
public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
theTabs.updateTab(0, null);
theTabs.updateTab(1, theCanvas);
theTabs.selectTab(tab2);
theTabs.removeTab(tab1);
}
});
theCanvas.addChild(btn2);
theTabs.addTab(tab1);
theTabs.addTab(tab2);
theTabs.addTab(tab3);
tab1.setPane(theCanvas);
RootPanel.get("container").add(theTabs);
}

How to kill a Tab in a Tab Panel

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").