Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to control the Tab selection(I want to control the tab selection according to some conditions)
How to control the Tab selection [message #512965] Mon, 08 February 2010 13:11 Go to next message
Ricky Ru is currently offline Ricky RuFriend
Messages: 14
Registered: February 2010
Junior Member
Hi friends,

I have a page in which there are several tabs. Each tab has its control(Tab.setControl()) within which there are some common components like Text fields, Combo Box for user to input information.

The code to init the i_tabFolder in the page:
public void createControl(Composite parent)
{
i_tabFolder = new TabFolder(parent, SWT.NONE);
i_tabFolder.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e)
{
doSelectionChanged(i_part, i_part1);
}
});
//create the Tabitems and their controls, Each control's parent is the i_tabFolder.
createPropertyPages(i_tabFolder);
}


I have a validation logic in the component Text field which resides in Tab1. My requirement is if user type an invalid value into it, I will warn this by showing a MessageBox and do not leave the focus on the Text field until its value is valid.
i_locationText.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
String location = i_locationText.getText();
if (condition)
{
MessageBox messageBox = new MessageBox(i_com.getShell(), SWT.OK|SWT.ICON_WARNING);
messageBox.setMessage("invalid location");messageBox.setText("~Title");messageBox.open();

((TabFolder)(i_com.getParent().getParent())).setSelection(3) ;
//may be I need to add some code here to implement my requirement? i_locationText.setFocus();
}
}
});

Actually, the code works. But the only situation is if the user types an invalid value and trys to select Tab2, although he gets the message box, the focus leave the text field and goes to Tab2.
So, how can I stop user going to Tab2? Does anyone has suggestion about that?

Thanks and regards,
Ricky

Re: How to control the Tab selection [message #513035 is a reply to message #512965] Mon, 08 February 2010 15:54 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

There's not currently support for vetoing a tab change, so I think the only
way currently is to set the selection back to the tab with the invalid
value. There is an existing request for the ability to do this in
CTabFolder in https://bugs.eclipse.org/bugs/show_bug.cgi?id=193064 (I don't
see a similar request for TabFolder). I don't know the history of why this
does not already exist on TabFolder, because it seems like it would be
useful. If there is not native support for it then perhaps at least
CTabFolder could offer it as an alternative. I'll ask about this, and in
the meantime I would suggest CC'ing yourself to the CTabFolder bug above,
since it's more likely to be addressed sooner.

Grant


"Ricky Ru" <sky.eclipse@yahoo.com.cn> wrote in message
news:hkp2ht$qus$1@build.eclipse.org...
> Hi friends,
>
> I have a page in which there are several tabs. Each tab has its
control(Tab.setControl()) within which there are some common components like
Text fields, Combo Box for user to input information.
>
> The code to init the i_tabFolder in the page:
> public void createControl(Composite parent)
> {
> i_tabFolder = new TabFolder(parent, SWT.NONE);
> i_tabFolder.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e)
> {
> doSelectionChanged(i_part, i_part1);
> }
> });
> //create the Tabitems and their controls, Each control's parent is
the i_tabFolder.
> createPropertyPages(i_tabFolder);
> }
>
>
> I have a validation logic in the component Text field which resides in
Tab1. My requirement is if user type an invalid value into it, I will warn
this by showing a MessageBox and do not leave the focus on the Text field
until its value is valid.
> i_locationText.addFocusListener(new FocusAdapter()
> {
> public void focusLost(FocusEvent e)
> {
> String location = i_locationText.getText();
> if (condition)
> {
> MessageBox messageBox = new MessageBox(i_com.getShell(),
SWT.OK|SWT.ICON_WARNING);
> messageBox.setMessage("invalid
location");messageBox.setText("~Title");messageBox.open();
>
> ((TabFolder)(i_com.getParent().getParent())).setSelection(3) ;
> //may be I need to add some code here to implement my requirement?
i_locationText.setFocus();
> }
> }
> });
>
> Actually, the code works. But the only situation is if the user types an
invalid value and trys to select Tab2, although he gets the message box, the
focus leave the text field and goes to Tab2.
> So, how can I stop user going to Tab2? Does anyone has suggestion about
that?
>
> Thanks and regards,
> Ricky
>
>
Re: How to control the Tab selection [message #513111 is a reply to message #512965] Mon, 08 February 2010 16:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jann.schneider.googlemail.com

i_locationText.setFocus(); ??

I think this should force the focus back to ur control then..

cheers

Am 08.02.2010 14:11, schrieb Ricky Ru:
> Hi friends,
>
> I have a page in which there are several tabs. Each tab has its
> control(Tab.setControl()) within which there are some common components
> like Text fields, Combo Box for user to input information.
>
> The code to init the i_tabFolder in the page:
> public void createControl(Composite parent)
> {
> i_tabFolder = new TabFolder(parent, SWT.NONE);
> i_tabFolder.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e)
> {
> doSelectionChanged(i_part, i_part1);
> }
> });
> //create the Tabitems and their controls, Each control's parent is the
> i_tabFolder.
> createPropertyPages(i_tabFolder); }
>
> I have a validation logic in the component Text field which resides in
> Tab1. My requirement is if user type an invalid value into it, I will
> warn this by showing a MessageBox and do not leave the focus on the Text
> field until its value is valid.
> i_locationText.addFocusListener(new FocusAdapter() {
> public void focusLost(FocusEvent e)
> {
> String location = i_locationText.getText();
> if (condition)
> {
> MessageBox messageBox = new MessageBox(i_com.getShell(),
> SWT.OK|SWT.ICON_WARNING);
> messageBox.setMessage("invalid
> location");messageBox.setText("~Title");messageBox.open();
>
> ((TabFolder)(i_com.getParent().getParent())).setSelection(3) ;
> //may be I need to add some code here to implement my requirement?
> i_locationText.setFocus();
> }
> }
> });
>
> Actually, the code works. But the only situation is if the user types an
> invalid value and trys to select Tab2, although he gets the message box,
> the focus leave the text field and goes to Tab2.
> So, how can I stop user going to Tab2? Does anyone has suggestion about
> that?
> Thanks and regards,
> Ricky
>
>
Re: How to control the Tab selection [message #513138 is a reply to message #513111] Tue, 09 February 2010 02:41 Go to previous message
Ricky Ru is currently offline Ricky RuFriend
Messages: 14
Registered: February 2010
Junior Member
You can see I have already used the call, but it did not work

[Updated on: Tue, 09 February 2010 02:42]

Report message to a moderator

Previous Topic:Set clipping within PaintListener.paintControl
Next Topic:DragSource and Composite
Goto Forum:
  


Current Time: Thu Dec 26 10:28:57 GMT 2024

Powered by FUDForum. Page generated in 0.03283 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top