Confirm dialog window when closing a tab - javafx-2

I'm new to JavaFX. I want to create Listener which calls question dialog when user closes a tab into the TabPane. So far I managed to create tabs dynamically and add some custom configuration.
tabAvLabel = new Label(ss);
tabPane.getTabs().add(0, tab); // Place the new tab always first
tabPane.getSelectionModel().select(tab); // Always show the new tab
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); // Add close button to all new tabs
I don't know what event listener I need to use and how to define it. Would you show me how to implement this?

You can try onCloseRequest for Tab class
tab.setOnCloseRequest(new EventHandler<Event>()
{
#Override
public void handle(Event arg0)
{
//your code
}
});

Try this code :
tabAvLabel = new Label(ss);
tabPane.getTabs().add(0, tab); // Place the new tab always first
tabPane.getSelectionModel().select(tab); // Always show the new tab
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); // Add close button to all new tabs
tabPane.getOnClosed(), setOnClosed(new EventHandler<Event>(){
#Override void handle(Event e){
// What you have to do here
}
})
For more information, see http://docs.oracle.com/javafx/2/api/javafx/scene/control/Tab.html#onClosedProperty

I've hacked a similar support you have in jdk8 support into 2.2 (https://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.e4.controls.fx2/src/org/eclipse/fx/e4/controls/fx2)

The answer of #VagrantAI can work. But you have to add the following codes on your 'OK' button click action function:
stage.fireEvent(
new WindowEvent(
stage,
WindowEvent.WINDOW_CLOSE_REQUEST
)
);
While the problem of this approach is the event is triggered when you click 'X' to close the window too. This should not be the purpose normally.
To solve this, add a flag (or static variable) in the class that loads the window. So every time the window is loaded, set the flag to false. When the window is closed, set the flag only when the 'OK' button is clicked. Then you can do your action regarding the value of this flag.

Related

kendo ui angular grid - how to leave row when user hits enter key instead of clicking off of row

Ive got a working grid, using in-line editing thanks to this example
https://www.telerik.com/kendo-angular-ui/components/grid/editing/editing-row-click/
What I need to do now, is force the saving upon a user hitting the enter key, instead of clicking away onto another row or away from the current row. I suppose I could add a "save" button in the header?
You could probably use cellClose event in your html (cellClose)="cellCloseHandler($event)" - API Documentation
You could then write your own code (in typescript) in cellCloseHandler() to modify and save the updated items accordingly.
From Kendo UI for Angular Documentation:
In-Cell Editing
You could capture the Enter key hits and force executing cellCloseHandler() like that:
#HostListener('keydown', ['$event'])
public keydown(event: any): void {
console.log("keydown event", event);
if (event.keyCode === 13) {
this.cellCloseHandler();
}
}
Similar to Giannis answer but with small modifications:
Add keydown event to kendo-grid tag.
Call grid.closeCell() instead of calling the closeHander directly.
Template
<kendo-grid #grid
[data]="data$ | async"
(cellClose)="cellCloseHandler($event)"
(keydown)="onKeydown(grid, $event)"
>
Class
onKeydown(grid: GridComponent, e: KeyboardEvent) {
if (e.key === 'Enter') {
grid.closeCell();
}
}
cellCloseHandler(args: CellCloseEvent) {
const { formGroup, dataItem } = args;
// save to backend etc
}
Calling grid.closeCell(); will make the grid to call cellCloseHandler
You dont have to implement a HostListener for Keydown by yourself. If you set the input navigable to true, the cellClose event will get triggered when pressing Enter while editing a cell or row. This way you get the data of the row in your cellCloseHandler aswell for saving it.
<kendo-grid [navigable]="true" (cellClose)="cellCloseHandler($event)"></kendo-grid>

I have 5 forms and I want to know how to return to the main form after closing 5th form

I have two questions:
1- I have a project that contains 5 forms, So I want to know how to return to the first form when closing the 5th form.
2- I have two buttons, one is visible on the form and the second one is not. What I wanted to do is to display the second button when the first button is clicked.
I added this code on the Form_load event: btn2.Visible= false, and I added this code under btn1_Click: btn2_Visible=true, but it didn't work. Can anyone help me please?
Form4 newform = new Form4(TextBox1.Text,TextBox2.Text);
newform.Show(); // this code is in form1.
this.Hide();
Then I created a button in Form4 to create Form 5 using the same code:
RForm Form5 = new RForm(Label1.Text, Label2.Text);
this.Hide(); // this is in Form 4
Form5.Show();
To return to Form1, I created a button in form5 :
private void c_Button_Click(object sender, EventArgs e)
{
this.Close();
Set the Parent property of your forms. For instance, to open Form4,
Form4 form4 = new Form4();
form4.Parent = this; // Reference to current Form1 instance
this.Hide();
form4.Show();
In the event handler in Form4, check for the parent property and show that.
(form4.Parent as Form1).Show();
this.Close();
You would also want to handle the Closing event if user closes the form any other way than your button.
For the second part, as long as event handlers are wired up properly, this should work. In the event handler, btn2.Visible = true would work.

How to empty textbox befor ModalPopupExtender show?

My code is to insert the text from textbox, I did my code well but I want to empty the textbox before ModalPopupExtender show. I did my code but It didn't work.
protected void Btn_monthlyemployee_Click(object sender, ImageClickEventArgs e)
{
var Comment = (TextBox)((ImageButton)sender).Parent.FindControl("txt_monthlyemployee");
ftier.Addcomment(LblMonthlyPID.Text, LoggedUserID, txt_monthlyemployee.Text, DateTime.Now, DateTime.Now, false);
Comment.Text = string.Empty;
ModelExtenderPost.Show();
}
You don't have provided enough information although i am giving you some good techniques to resolve this
Your code should be work i don't know why its not working
You can have a jquery method
when your button clicked
$('#idofmonthlyeployeed').click(function()
{
$('#commentboxid').val('');
return false;
});
You can see working example here Fiddle
Or you can have a update panel issue if you don't have triggered button of your idofmonthlyeployeed
So please add trigger of idofmonthlyeployeed
I hope this will help you regards.....:)

VS 2012 Start UI Windows from VSPackage

i've started to work with the VS2012 extensibility possibilities. I did the first few Walkthroughs and now I'm trying get further on. What I'm trying is pretty easy I guess... I'm trying to build a simply vspackage which starts an UI window. Actually i do not find any howto or sample code.
Do you have some links with further information about doing something like that ?
Thanks for you help..
Iki
You can find initial information here.
Here is my code for menu item:
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
protected override void Initialize()
{
Debug.WriteLine ("Entering Initialize() of: {0}", this);
base.Initialize();
// Add our command handlers for menu (commands must exist in the .vsct file)
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if ( null != mcs )
{
// Create the command for the menu item.
CommandID menuCommandID = new CommandID(GuidList.guidPackageProject, (int)PkgCmdIDList.Impl);
OleMenuCommand menuItem = new OleMenuCommand(MenuItemCallback, menuCommandID);
mcs.AddCommand( menuItem );
}
}
/// <summary>
/// This function is the callback used to execute a command when the a menu item is clicked.
/// See the Initialize method to see how the menu item is associated to this function using
/// the OleMenuCommandService service and the MenuCommand class.
/// </summary>
private void MenuItemCallback(object sender, EventArgs e)
{
MyForm form = new MyForm();
form.ShowDialog(); // Here your form is opening
}
I have been searching for a solution to this recently as I also needed to start a WPF form from a VSPackage. I have got things working after a couple of hours searching various topics on this and some good ol' trial and error.
I had an existing WPF-Project in a separate solution, which had to be merged into a VSPackage. Here's the steps to get this working:
Create a new Solution of Project type 'Visual Studio Package'
Make sure you select the 'Tool Window' option in the VS Package
Wizard (see the image below)
Now that the Solution has been created, add the already existing
WPF-Project to it (Right-Click 'Solution', Add->Existing Project) NOTE: It might be wise to copy the WPF-project to the Solution folder prior to adding it to the Solution.
Make sure you create a reference to the WPF-Project from your
VSPackage-Project and (if necessary) edit the namespaces of the WPF-Project to meet those of the VSPackage-Project, or the other way around.
Your Solution will now look something like this:
Now, you need to edit MyToolWindow.cs:
// Original:
base.Content = new MyControl();
// Change to:
base.Content = new MainWindow();
Make the following changes to VSPackage1Package.cs (or whatever your *Package.cs file is called)
// Original
private void ShowToolWindow(object sender, EventArgs e)
{
// Get the instance number 0 of this tool window. This window is single instance so this instance
// is actually the only one.
// The last flag is set to true so that if the tool window does not exists it will be created.
ToolWindowPane window = this.FindToolWindow(typeof(MyToolWindow), 0, true);
if ((null == window) || (null == window.Frame))
{
throw new NotSupportedException(Resources.CanNotCreateWindow);
}
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
}
// Change to:
private void ShowToolWindow(object sender, EventArgs e)
{
// Get the instance number 0 of this tool window. This window is single instance so this instance
// is actually the only one.
// The last flag is set to true so that if the tool window does not exists it will be created.
//ToolWindowPane window = this.FindToolWindow(typeof(MyToolWindow), 0, true);
//if ((null == window) || (null == window.Frame))
//{
// throw new NotSupportedException(Resources.CanNotCreateWindow);
//}
//IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
//Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
MainWindow mainwin = new MainWindow();
mainwin.Show();
}
If you get no build errors, you should be fine.
To test if your WPF-form opens, Press 'Start' to run the VSPackage in a new 'Experimental' Visual Studio instance. If everything went OK, you will find and should be able to run your WPF-from from the View->Other Windows menu.
If you don't see your VSPackage listed in the menu, close your 'Experimental' Visual Studio instance. Then Clean en Build your Solution and press 'Start' again. It should show up now.

on(keyPress "<Enter>") in AS2 doesn't work

I have a flash movie I am making that has a search box and a search button. The button has this code:
on (release, keyPress "<Enter>") {
searchbox.execute();
/*the function above processes searches*/
}
Clicking on the button works just fine. Pressing Enter doesn't do a bean! Does anyone know why this is, and any ways I can work around it? I'd prefer not to use listeners if I can possibly avoid it at all.
Using on() is a deprecated AS1 practice, so maybe you should just stop using it. Thanks to the onKeyDown event handler of the MovieClip class, it is possible to use proper code to do it without listeners, so you don't have to worry about them. ;)
Anyway, on with the code. Type this into the timeline which contains the button:
//Enable focus for and set focus to your button
searchButton.focusEnabled = true;
Selection.setFocus(searchButton);
//The onRelease handler for the button
searchButton.onRelease = function(){
//You need this._parent this code belongs to the button
this._parent.searchbox.execute();
}
//The onKeyDown handler for the button
searchButton.onKeyDown = function(){
//Key.getCode() returns the key code of the last key press
//Key.ENTER is a constant equal to the key code of the enter key
if(Key.getCode() == Key.ENTER){
this._parent.searchbox.execute();
}
}

Resources