KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > services > ChildSelectionHandler


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.part.services;
12
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.ui.internal.components.framework.ComponentException;
15 import org.eclipse.ui.internal.components.framework.IServiceProvider;
16 import org.eclipse.ui.internal.part.Part;
17 import org.eclipse.ui.internal.part.components.services.ISelectionHandler;
18 import org.eclipse.ui.internal.part.multiplexer.INestedComponent;
19 import org.eclipse.ui.internal.part.multiplexer.ISharedContext;
20
21 /**
22  * Multiplexed version of the ISelectionHandler interface
23  *
24  * @since 3.1
25  */

26 public class ChildSelectionHandler implements ISelectionHandler, INestedComponent {
27
28     private ISelectionHandler parent;
29     private ISelection selection;
30     private boolean isActive = false;
31     
32     public ChildSelectionHandler(ISharedContext shared) throws ComponentException {
33         
34         IServiceProvider parentContainer = shared.getSharedComponents();
35         // Get access to the shared ISelectionHandler being multiplexed (we should
36
// only modify it when we're the active child)
37
this.parent = (ISelectionHandler)parentContainer.getService(ISelectionHandler.class);
38     }
39     
40     /* (non-Javadoc)
41      * @see org.eclipse.ui.internal.part.components.interfaces.INestedComponent#activate()
42      */

43     public void activate(Part newActivePart) {
44         // Forward our stored selection to the shared interface
45
parent.setSelection(selection);
46         isActive = true;
47     }
48     
49     /* (non-Javadoc)
50      * @see org.eclipse.ui.internal.part.components.interfaces.INestedComponent#deactivate()
51      */

52     public void deactivate(Object JavaDoc newActive) {
53         isActive = false;
54     }
55     
56     /* (non-Javadoc)
57      * @see org.eclipse.ui.internal.part.components.interfaces.ISelectionHandler#setSelection(org.eclipse.jface.viewers.ISelection)
58      */

59     public void setSelection(ISelection newSelection) {
60         // Remember the child's new selection
61
selection = newSelection;
62         if (isActive) {
63             // If we're active, forward the selection directly to the shared
64
// interface
65
parent.setSelection(newSelection);
66         }
67     }
68     
69 }
70
Popular Tags