01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.components.views.context;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.layout.FillLayout;
14: import org.eclipse.swt.widgets.Composite;
15: import org.eclipse.swt.widgets.Event;
16: import org.eclipse.swt.widgets.Listener;
17: import org.eclipse.ui.IPageLayout;
18: import org.eclipse.ui.internal.components.framework.ComponentException;
19: import org.eclipse.ui.internal.components.framework.FactoryMap;
20: import org.eclipse.ui.internal.part.Part;
21: import org.eclipse.ui.internal.part.components.services.INameable;
22: import org.eclipse.ui.internal.part.components.services.IWorkbenchPartFactory;
23:
24: /**
25: * @since 3.1
26: */
27: public class HardcodedMultiplexNameView {
28: HardcodedChildNameable view1Nameable;
29: HardcodedChildNameable view2Nameable;
30:
31: Part activePart;
32:
33: private Part view1;
34: private Part view2;
35:
36: private Listener focusListener = new Listener() {
37: /* (non-Javadoc)
38: * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
39: */
40: public void handleEvent(Event e) {
41: if (e.widget == view1.getControl()) {
42: setActivePart(view1);
43: } else if (e.widget == view2.getControl()) {
44: setActivePart(view2);
45: }
46: }
47:
48: };
49:
50: private void setActivePart(Part toActivate) {
51: if (toActivate == view1) {
52: view1Nameable.activate();
53: view2Nameable.deactivate();
54: } else {
55: view2Nameable.activate();
56: view1Nameable.deactivate();
57: }
58: }
59:
60: /**
61: *
62: */
63: public HardcodedMultiplexNameView(Composite parent,
64: IWorkbenchPartFactory factory, INameable name)
65: throws ComponentException {
66:
67: view1Nameable = new HardcodedChildNameable(name, "Resources",
68: null);
69:
70: // Create a resource navigator. Give the navigator a multiplexed INameable, but use
71: // defaults for all of the other interfaces.
72: FactoryMap viewContext1 = new FactoryMap().mapInstance(
73: INameable.class, view1Nameable);
74: view1 = factory.createView(IPageLayout.ID_RES_NAV, parent,
75: null, viewContext1);
76: view1.getControl().addListener(SWT.Activate, focusListener);
77:
78: view2Nameable = new HardcodedChildNameable(name, "Properties",
79: null);
80:
81: // Create property view. Give the properties view a multiplexed INameable, but use
82: // defaults for everything else.
83: FactoryMap viewContext2 = new FactoryMap().mapInstance(
84: INameable.class, view2Nameable);
85: view2 = factory.createView(IPageLayout.ID_PROP_SHEET, parent,
86: null, viewContext2);
87: view2.getControl().addListener(SWT.Activate, focusListener);
88:
89: view1Nameable.activate();
90: activePart = view1;
91:
92: parent.setLayout(new FillLayout());
93: }
94: }
|