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 java.text.MessageFormat;
13:
14: import org.eclipse.jface.viewers.ISelection;
15: import org.eclipse.jface.viewers.IStructuredSelection;
16: import org.eclipse.swt.layout.FillLayout;
17: import org.eclipse.swt.widgets.Composite;
18: import org.eclipse.ui.IPageLayout;
19: import org.eclipse.ui.internal.components.framework.ComponentException;
20: import org.eclipse.ui.internal.components.framework.FactoryMap;
21: import org.eclipse.ui.internal.part.Part;
22: import org.eclipse.ui.internal.part.components.services.INameable;
23: import org.eclipse.ui.internal.part.components.services.ISelectionHandler;
24: import org.eclipse.ui.internal.part.components.services.IWorkbenchPartFactory;
25:
26: /**
27: * View that demonstrates how to override a specific dependency of a child part.
28: * In this case, we create a nested problems view and property view. The
29: * problems view is given a custom ISelectionHandler that displays the number of selected
30: * problems in the parent's content description.
31: *
32: * @since 3.1
33: */
34: public class OverrideInstanceView {
35:
36: /**
37: * Component constructor. Do not invoke directly.
38: */
39: public OverrideInstanceView(Composite parent,
40: IWorkbenchPartFactory factory, final INameable name)
41: throws ComponentException {
42: FactoryMap viewContext1 = new FactoryMap();
43:
44: // Add an ISelectionHandler to the view's context. Whenever the view changes its selection,
45: // display the number of selected items in the content description
46: viewContext1.mapInstance(ISelectionHandler.class,
47: new ISelectionHandler() {
48: /* (non-Javadoc)
49: * @see org.eclipse.ui.internal.part.components.services.ISelectionHandler#setSelection(org.eclipse.jface.viewers.ISelection)
50: */
51: public void setSelection(ISelection newSelection) {
52: if (newSelection instanceof IStructuredSelection) {
53: IStructuredSelection sel = (IStructuredSelection) newSelection;
54: int selectionSize = sel.size();
55:
56: name
57: .setContentDescription(MessageFormat
58: .format(
59: "{0} problems selected",
60: new String[] { Integer
61: .toString(selectionSize) }));
62: }
63: }
64: });
65:
66: // Create a problem view
67: Part view1 = factory.createView(IPageLayout.ID_PROBLEM_VIEW,
68: parent, null, viewContext1);
69:
70: // Create property view
71: FactoryMap viewContext2 = new FactoryMap();
72: Part view2 = factory.createView(IPageLayout.ID_PROP_SHEET,
73: parent, null, viewContext2);
74:
75: parent.setLayout(new FillLayout());
76: }
77: }
|