The Eclipse Tabbed Properties View
IntroductionThe Eclipse workbench provides a properties view, which is described in detail in the article Take control of your properties. The default user interface is table with property and value pairs, and the value being modified using a standard dialog cell editor. The workbench provides extensions to define a custom user interface for the properties view. By making use of thise extensions, the tabbed properties view has been created. The tabbed properties view allows you to create any user interface for your properties. In addition, you can create user interfaces for elements that do not implement an IPropertySource. Indeed the properties view can be extended to view any data for the selection in your workbench part. As an example, here was the properties view for the example in the Take control of your properties. The tabbed properties view can be used to create a different user interface. HistoryThe tabbed properties view was authored by IBM and was used internally in the IBM Rational Software Architect, IBM WebSphere Integration Developer, and other IBM products based on the Eclipse platform. The tabbed properties view was contributed to Eclipse open source and became part of the Eclipse Web Tools Platform project. With Eclipse 3.2 M5, the tabbed properties view has moved to the Eclipse core platform. The Tabbed Properties View is implemented using the ExamplesHere are some other examples of the tabbed properties view in action. This example comes from the XML Schema Editor available in Eclipse WTP version 0.7 This example comes from the Logic Shapes example available in Eclipse GMF version 1.0 M4. This example comes from the UML Modeler available in IBM Rational Software Architect version 6.0 This example comes from the BPEL Editor available in IBM WebSphere Integration Developer version 6.0 This example comes from the HTML Editor available in IBM Rational Web Software Developer for WebSphere Software version 6.0 The Tabbed Properties View Extension PointsThe tabbed properties view is configured by implementing three extension. Each tabbed properties view is composed of a property contributor who contributes one or more property tabs. Each property tab is filled with one or more sections. The highlighted example below illustrates how they are organized. For the current selection, the property contributor has enabled two tabs in the tabbed properties view, Button and Advanced. The Button tab is highlighted and is the active tab. The Button tab has enabled three active sections highlighted on the right. A section is simply a widget or a composite containing a group of widgets that maps to one property, multiple properties or some concept independent of the properties of a selection. Property ContributorThe Note that a property contributor can be shared among several workbench parts. For example, an application may have an explorer view, editor and outline whose selections share a common set of properties. In this case, all three workbench parts can share the same tabbed properties view as identified by the unique contributor identifier. A workbench part cannot make use of two or more property
contributors. It can identify a single property contributor by
implementing the The
Property TabsThe A
Property SectionsThe The The
The Implementing the Tabbed Properties ViewLet us now take the example from Take control of your properties and make it use the tabbed property view, as we first showed at the start of this article. The source code for this example can be found the CVS repository. Before proceeding, we add the dependency to the Updating the Sample ViewA workbench part that provides a tabbed property view needs to implement the public String getContributorId() { return getSite().getId(); } We also need to tell the workbench to use the tabbed property view.
Each workbench part can define its own custom property sheet page by
providing an adaptable for public Object getAdapter(Class adapter) { if (adapter == IPropertySheetPage.class) return new TabbedPropertySheetPage(this); return super.getAdapter(adapter); } Add a PropertyContributor extensionNext we add the <extension point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
At this point we can now run our plug-in and when you look at the properties view, you will see "Properties are not available". The tabbed property sheet page has successfully been implemented. The page took the unique identifier and looked up the tabs and sections that match the current selection ("button") and did not find any to display. So you see the message "Properties are not available". The next stage is to define tabs and sections. Add a PropertyTabs extensionThe first thing we need to do before adding tabs is to define a property category in our <extension point="org.eclipse.ui.views.properties.tabbed.propertyContributor"> <propertyContributor contributorId="mview.views.SampleView">
Next we can add the <extension point="org.eclipse.ui.views.properties.tabbed.propertyTabs"> <propertyTabs contributorId="mview.views.SampleView"> <propertyTab We have defined two tabs in our example by providing two We must provide the tab id, category and label for each tab. Our tabs are named button (
Add a PropertySections extensionFinally we can add the PropertySections extension point to our plug-in. <extension point="org.eclipse.ui.views.properties.tabbed.propertySections"> <propertySections contributorId="mview.views.SampleView"> <propertySection class="mview.views.LabelSection" id="mview.LabelSection" tab="mview.ButtonTab"> <input type="mview.views.ButtonElement"/> </propertySection> <propertySection afterSection="mview.LabelSection" class="mview.views.SizeSection" id="mview.SizeSection" tab="mview.ButtonTab"> <input type="mview.views.ButtonElement"/> </propertySection> <propertySection afterSection="mview.SizeSection" class="mview.views.FontSection" id="mview.FontSection" tab="mview.ButtonTab"> <input type="mview.views.ButtonElement"/> </propertySection> <propertySection class="org.eclipse.ui.views.properties.tabbed.AdvancedPropertySection" id="mview.AdvancedSection" tab="mview.AdvancedTab"> <input type="mview.views.ButtonElement"/> </propertySection> </propertySections> </extension> All our sections apply to the input type ButtonElement. The button tab is given three sections, the advanced tab one section. Each section has the tab identifier, unique identifier for the section and the class that implements the section. Property SectionHere is the code for our label section. /******************************************************************************* * Copyright (c) 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www./legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package mview.views; import org.eclipse.jface.util.Assert; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; /** * The Label section on the Button tab. * * @author Anthony Hunter */ public class LabelSection extends AbstractPropertySection { private Text labelText; private ButtonElement buttonElement; private ModifyListener listener = new ModifyListener() { public void modifyText(ModifyEvent arg0) { ButtonElementProperties properties = (ButtonElementProperties) buttonElement .getAdapter(IPropertySource.class); properties.setPropertyValue(ButtonElementProperties.PROPERTY_TEXT, labelText.getText()); } }; A section in a tab is represented by the When implementing a section, there are three methods a section must implement:
Section LayoutStandard Eclipse SWT widgets are used in Clients should take advantage of the widget factory provided by the
framework to achieve a common look between property sections. The
widget factory is available from
In our example, we had three sections, button, size and font. Since
sections are not aware of each other, it is difficult to know how to
line up the labels for sections on the left hand side of the composite.
For this reason, we make use of We make use of
Lifecycle of a SectionThe lifecycle of a section is as follows:
Implementers of this class should be aware that a section instance
might be reused for different input objects (as long as they are valid
section inputs). It means that When an input change event occurs, such as a tab selection or a workbench selection change, a section is sent:
When a part activation event occurs, such as the workbench part activation event, a section is sent:
This is because both a tab selection event and an input selection event have occurred. Model ListenersWhen a property sheet page is visible, the model could be changed
outside of the property view. In this case we want to add a listener so
that we can update the visible controls based on new model values. This
is done using
Since the controls are not yet visible in The listener when receiving a change event should make use of Advanced SectionWhen we have complex applications with multiple As an example, here is the advanced tab for our exampling showing the "original" properties view from the Take control of your properties. Additional OptionsType MapperThe When a set of objects are selected in the workbench part, the tabbed properties view matches the type of these objects with the An example for a type mapper for public class TypeMapper extends AbstractTypeMapper { public Class mapType(Object object) { if (object instanceof TreeNode) { return ((TreeNode) object).getValue().getClass(); } return super.mapType(object); } } A second example of a type mapper can be found in the tabbed properties logic example based on Eclipse GEF. Elements on a diagram are all public class LogicElementTypeMapper extends AbstractTypeMapper { public Class mapType(Object object) { if (object instanceof EditPart) { return ((EditPart) object).getModel().getClass(); } return super.mapType(object); } } Section FilteringThe Note that a filter is used to override the type mapper and input for
the selection. When a filter is specified, the type mapper and input
are ignored for that section. In the case where Title BarThe Tab OrderingTabs are ordered by the categories defined by the Section OrderingWhen there is more than one section on a tab, sections are sorted using the Section Selection Count EnablementThe Alternate Property Configuration for a SelectionClients can extend the property configuration for a workbench part by implementing tab and section extensions in their plug-in. There are times when it is desirable for clients provide a top level property contributor configuration as well. For example, a project explorer may have multiple clients contributing elements to a tree. The core project explorer will define a properties configuration with a unique contributor identifier. Clients can add tabs and sections by using the same contributor identifier in their plug-in. If a client already has tabs and sections with a different contributor identifier that matches their editor, it would not be desirable to have to copy all the extensions to display when its custom tree nodes are selected It is possible to have the elements in a selection implement or adapt to the
|
|
来自: zjxnew > 《eclipse rcp》