Bug 193064 - [CTabFolder] CtabItem pre-closure/pre-selection changed
Summary: [CTabFolder] CtabItem pre-closure/pre-selection changed
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 minor with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact: Kevin Barnes CLA
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 193066
  Show dependency tree
 
Reported: 2007-06-18 02:27 EDT by mirko fucci CLA
Modified: 2020-08-08 06:56 EDT (History)
8 users (show)

See Also:


Attachments
patch with code changes (4.56 KB, patch)
2009-04-03 09:55 EDT, Lakshmi P Shanmugam CLA
no flags Details | Diff
patch using Page Manager (4.55 KB, patch)
2009-04-03 10:08 EDT, Lakshmi P Shanmugam CLA
no flags Details | Diff
example to show how to use the page manager (1.87 KB, text/java)
2009-04-03 10:31 EDT, Lakshmi P Shanmugam CLA
no flags Details
patch based on option2 (3.57 KB, patch)
2010-03-03 03:27 EST, Lakshmi P Shanmugam CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mirko fucci CLA 2007-06-18 02:27:55 EDT
Execute some validation controls before CtabItem switching.
it's only possible saving old page index and restoring the selection, it provokes flickering problems.

thanks
Comment 1 mirko fucci CLA 2007-06-19 01:54:12 EDT
More information:

i've tried to solve it as i've explained in
http://dev.eclipse.org/newslists/news.eclipse.platform/msg65483.html
Comment 2 Lakshmi P Shanmugam CLA 2009-03-25 17:26:15 EDT
(In reply to comment #1)

> i've tried to solve it as i've explained in
> http://dev.eclipse.org/newslists/news.eclipse.platform/msg65483.html

Hi Mirko, 
I guess this is the right link for your message -->
http://dev.eclipse.org/newslists/news.eclipse.platform/msg65482.html

I looked at your code in the message, but didn't find the implementation of canLeaveThePage() of CTabItemPageManager. What are you trying to do in the canLeaveThePage()?

Comment 3 mirko fucci CLA 2009-03-26 05:06:28 EDT
hi,

i wanted only provide a mechanism to customize validation controls before tab switching (maybe index parameters passed to canLeavethePage isn't really useful), consider this example (not tested because my goal was use this mechanisn in FormPage class)

i hope following example can help you:

public class MyComposite extends Composite implements CTabItemPageManager{
	
	private Button agreeLicenseButton=null;
	
	public MyCTabItem(CTabFolder parent, int style) {
		super(parent, style);

	}
	
	public boolean canLeaveThePage(int index) {
		if (agreeLicenseButton.getSelection())
			return true;
		return false;
	}

	
	...
	...
	...
	...
	
}


CTabItem  my = new CTabItem ();
Composite myComposite= new MyComposite();
...
...
my.setPageManager(myComposite);
my.setControl(myComposite);

Comment 4 Lakshmi P Shanmugam CLA 2009-04-03 09:53:11 EDT
(In reply to comment #3)
Thank you for the example, I understood the requirement.
Comment 5 Lakshmi P Shanmugam CLA 2009-04-03 09:55:26 EDT
Created attachment 130832 [details]
patch with code changes

I think it will be better to have a common Page Manager for the CTabFolder, instead of having a separate Page Manager for each tab-item. 
The old and new index values in the canLeaveThePage method can be used to validate the tab-items before leaving a page with old index or before selecting a page with new index.
Comment 6 Lakshmi P Shanmugam CLA 2009-04-03 10:08:13 EDT
Created attachment 130834 [details]
patch using Page Manager
Comment 7 Lakshmi P Shanmugam CLA 2009-04-03 10:31:55 EDT
Created attachment 130838 [details]
example to show how to use the page manager

Created an example to show the use of the Page Manager for validation  before switching tabs.
Comment 8 Lakshmi P Shanmugam CLA 2009-04-03 10:44:20 EDT
There is a bug 193453 for requirement of a CTabFolder Pre-Selection Listener. Though the patch doesn't create a listener, I think it can solve the problem of validation before tab-switching which is common in both the bugs.
Comment 9 Lakshmi P Shanmugam CLA 2010-01-18 09:12:57 EST
Hi Silenio,
This bug requests for a PageManager for Ctabfolder to do some validation before tab-switching. There is another bug 193453 requesting for a PreSelection listener to do the same thing (also it has few votes). I think fixing any one of them will fix the problem of validation before tab-switiching. 
Please suggest which way to go.
(I have attached patch for the PageManger approach here. It uses the canLeavepage() similar to FormPage.canLeaveThePage())
Comment 10 Silenio Quarti CLA 2010-02-08 13:51:25 EST
CTabItem pre-closure already exists (the doit flag of CTabFolderEvent can be set to false in CTabFolderListener.close()). This is how other events are avoided as well (SWT.Traverse, SWT.KeyDown, SWT.Close, etc).

I believe the solution for pre-selection should be similar. I personally do not like the manager class, since it is a new concept that SWT does not have so far.

Some options:

1) change the selection event for CTabFolder to run before the item is selected and look at the doit flag. This may break current users. 
2) add another general untyped event (SWT.PreSelection or SWT.Selecting). We would have to see if we would add the typed event/listener as well. 
3) add yet another CTabFolerListener (CTabFolder3Listener). Do we have any other feature requests that require new events? I would hate to add another listener with only one method.
Comment 11 Carolyn MacLeod CLA 2010-02-08 14:45:42 EST
Re: comment 10

Option 1 is best because it matches current SWT API, but as you say it may break people. Do we have any way of determining whether or not it really does? (Other than releasing the change early in 3.7 and waiting for bugs...  ;)

Option 2 (untyped) isn't bad, and it could possibly be reused if there are ever any other controls that need to allow selection event cancellation.

Option 3 is CTabFolder-specific, so I would first ask whether or not we think any other control would ever need this feature (I don't know, like maybe TabFolder? Or a Button "isn't ready to be selected"? <g> Or a single-line Text field wants to prevent defaultSelection for some reason? (instead of using Verify)). Option 3 is also "the most different" from current SWT API, so I don't like this option.
Comment 12 Lakshmi P Shanmugam CLA 2010-02-17 08:20:04 EST
Hi Carolyn & Silenio,

I tried out option1 in my workspace. If we use option1, then
 - we have to add a new field in Event like Event.oldItem to hold the current selection. Event.item contains the new selection. We can't change this since because existing user code uses this field and expects it to be the newly selected tab item. 
 - we would send the Selection event before the tab-item is selected. Only on selecting the tab, its control is set as visible. When the tab-item is not selected, the control's visibility will be set to false.  So, if there is existing user code in the selection event handler that depends on the control's visibility then it may break. 
For eg, I tried a testcase where calling setFocus() on the item's control in the selection listener doesn't work anymore. 

I like (option2) where we can have a separate event like SWT.PreSelection for Selections that can be canceled. Users can handle the PreSelection event only when they want to or can cancel the Selection on the control. And the existing user code for SWT.Selection event handler can remain as it is.
Comment 13 Lakshmi P Shanmugam CLA 2010-03-03 03:27:01 EST
Created attachment 160744 [details]
patch based on option2

details of the patch based on option2:
Added a new event SWT.PreSelection. The event.item will hold the item on which the event occurred, i.e, the item about to be selected. event.index holds the index to this item.
User can query for the item which is currently selected by calling CTabFolder.getSelectionIndex() and getSelection() in the listener. I'm not sure if we need to store this index value in the detail field. I'll remove it in case it is not required.
Comment 14 Lakshmi P Shanmugam CLA 2010-03-03 03:44:37 EST
snippet using PreSelection event:

public class Test
{
    public static void main(String[] args)
    {
	Display display = new Display();
        final Shell shell = new Shell();
        shell.setLayout(new FillLayout());
        final CTabFolder cTabFolder = new CTabFolder(shell, SWT.BORDER);

        for (int i = 0; i <4; i++)
        {
           CTabItem cTabItem = new CTabItem(cTabFolder, SWT.CLOSE, i);
           cTabItem.setText("item&" + i);
           Text control = new Text(cTabFolder, SWT.MULTI);
           cTabItem.setControl(control);
           control.setText("text for item " + i);
        }
        
        final CTabItem specialItem = cTabFolder.getItem(0);
        cTabFolder.addListener(SWT.PreSelection, new Listener() {
	    public void handleEvent(Event event) {
		System.out.println("Preselection event " + event);
		System.out.println("selection index before selection " + cTabFolder.getSelectionIndex());
		System.out.println("item to be selected is " + event.index);
		if (event.item == specialItem) event.doit = false;
	    }
	});
        cTabFolder.addListener(SWT.Selection, new Listener() {
	    public void handleEvent(Event event) {
		System.out.println("Selection event " + event);
		System.out.println("selection index after selection " + cTabFolder.getSelectionIndex());
	    }
	});
        shell.pack();
        shell.open();
        while(!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
    }
}
Comment 15 Mark Peters CLA 2018-05-07 17:39:14 EDT
Any update on this?
Comment 16 Eclipse Genie CLA 2020-08-08 06:56:39 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.