In addition to the layout information
provided, I would suggest reading Extending
the Visual Editor Tutorial: Enabling support for a custom widget
to understand how to extend VE. In
particular, the section The EMF override mechanism
provides information about plugin
extension points and where/how VE picks up the override files for your
plugin.
Regards...
Peter Walker
-------------------------------------
Eclipse VE Development
919-254-1558
Peter Walker/Raleigh/IBM@IBMUS Sent by: ve-dev-bounces@xxxxxxxxxxx
11/03/2005 01:53 PM
Please respond to
Discussions people developing code for the Visual Editor project
To
Discussions people developing
code for the Visual Editor project <ve-dev@xxxxxxxxxxx>
cc
Subject
Re: [ve-dev] Question regarding
Layouts
>My question is ,is there any way i can add my layout type there in
the drop down, in addition to the existing ones,
>so everyone can see the existing as well as new layouts when, they
drop a shell or a composite
Although this is not documented anywhere yet (another tutorial the VE team
needs to write up ;-), there are APIs and the capability to add your own
layout in VE so it will show up in the drop down list in the property sheet
view for the 'layout' property... and if even show up in the (optional)
Customize Layout Window. I will attempt to give you some pointers to classes
and overrides to help you get started.
Overrides
The first place to look is the layout.override file in the org.eclipse.ve.swt
plugin. It's located in the overrides directory. In your plugin,
you will need to create an overrides directory. The directory structure
is the same as the package name for the actual class. For example, layout.override
is for the class org.eclipse.swt.widgets and is in the directory
...override\org\eclipse\swt\widgets. You will need to create an
SWT layout.override file in your plugin (with the same respective
directory structure) and put your layout information in the file. VE will
automatically pickup this override and add the information to VE's layout.override.
BTW... look in the LayoutCellEditor class if you want to see how
it's done. The xmi format for the override file varies depending on whether
you are using VE 1.1 or the current (under development) VE 1.2. If you
use the 1.1 format, you will have to convert it to 1.2 format using a migration
tool later on when you move up to VE 1.2 (which is based on Eclipse 3.2).
Either version there are key/value pairs in the file and you need to add
your layout here. Here's an example of the xmi decorator for RowLayout
(1.2 format):
<objectsToAttach source="org.eclipse.ve.LayoutInfo"
xmi:id="_eAnnotations3" xsi:type="ecore:EAnnotation">
<details key="org.eclipse.ve.internal.swt.layoutClass"
value="org.eclipse.swt.layout.RowLayout"/>
<details key="org.eclipse.ve.internal.swt.layoutDisplayName"
value="RowLayout"/>
</objectsToAttach>
There are two important keys defined here:
1. org.eclipse.ve.internal.swt.layoutClass
- the value is the actual class name (i.e. org.eclipse.swt.layout.RowLayout)
2. org.eclipse.ve.internal.swt.layoutDisplayName
- the value is the display name in the property sheet view drop down list
(i.e. RowLayout)
In addition to the layout.override file, you will also need to create
an override file for the actual layout you have developed and in it you
will point to the layout factory to be used by VE for your layout. Put
this also in the directory structure to what your layout path is. For example,
cool.layouts.MyCoolSWTLayout would be in ...overrides\cool\layouts\MyCoolSWTLayout.override.
A layout factory is an implementation of the class ILayoutPolicyFactory
which has various getter methods that return things like the type of layout
policy to use in the graph viewer, the layout switcher to use when someone
selects your layout, a constraint class that is used if your layout
class uses layout data for the children (e.g. RowData for RowLayout), and
other methods as well... just check out the javadoc. Looking at an example
is the easiest way to find out how to write up your own. Here's the xmi
information for RowLayout.override (located in the ...override\org\eclipse\swt\layout
directory):
<objectsToAttach xmi:id="_eAnnotations" xsi:type="org.eclipse.ve.internal.jcm:BeanDecorator">
<keyedValues key="org.eclipse.ve.internal.java.visual.layoutpolicyfactoryclassnamekey"
value="org.eclipse.ve.swt/org.eclipse.ve.internal.swt.RowLayoutPolicyFactory"
xsi:type="ecore:EStringToStringMapEntry"/>
</objectsToAttach>
The key here is "org.eclipse.ve.internal.java.visual.layoutpolicyfactoryclassnamekey"
and the value will be your own layout policy factory.
Policies
To actually use your layout in VE such that you can create, move, delete,
and manipulate the SWT controls with a Composite, you will need to create
your own edit policy, helper, and container policy... or use some (or all)
of the VE policies if they suit your needs. These policies are used primarily
to create and execute GEF commands. VE uses commands so that operations
can be undone and batched together in a logical manner.
Your layout factory will return the layout policy and policy helper to
be used for this purpose and you will need to write these with the respective
interfaces. You can use one of the VE classes if you find it performs the
behavior you want or you can subclass one of them and just override the
methods you need to. VE provides a layout policy org.eclipse.ve.internal.swt.DefaultLayoutEditPolicy
which provides basic functions similar to RowLayout and FillLayout. This
provides a vertical or horizontal insertion line when dragging controls
in the graph viewer.
You'll may need a policy helper as a common policy for both the beans
viewer and the graph viewer. The layout policy usually forwards requests
onto the helper policy. The CompositeTreeEditPart.createLayoutPolicyHelper()
shows where the helper policy is created. The layout policy also instantiates
them. Or just use VE's UnknownLayoutPolicyHelper
which VE uses for layouts it doesn't know about.
Initially, you may want to just add one of the VE default layout policies
and helpers to get things working in a generic way and then add your own
layout policies. You will need to override various functions (add, delete,
move, create, etc.). The simplest layout to look at is probably FillLayout
or RowLayout. GridLayout and a null layout are much more complex because
of the constraints and feedback mechanisms in place.
Just a little background information that might prove useful in understanding
and debugging layout behavior in the graph viewer, VE uses CompositeGraphicalEditPart
as the general purpose graphical editpart for Composites. In the createLayoutPolicy
method, it gets the 'layout' property and uses some VE utilities to get
the layout factory based on the layout. From the factory, it gets the layout
policy.
Customize Layout Window
If you want to provide your own layout and/or component page (for layout
or layout data, respectively) in the Customize Layout window, you
will need to have your own layout policy and point the customize layout
window to your own pages. For RowLayout, look in RowLayoutEditPolicy.activate().
At the end of the method there is a statement that defines what page to
use for the layout itself:
CustomizeLayoutWindowAction.addLayoutCustomizationPage(getHost().getViewer(),
RowLayoutLayoutPage.class);
Whereas RowLayoutLayoutPage
is the GUI page for change RowLayout properties. If you write your own
you will need to extend VE's CustomizeLayoutPage.
If you have a page for the layout data (for a child of the composite),
you will need to add an additional statement in the activate method of
your layout policy. For example, in GridLayoutEditPolicy, there is a page
for the layout and the component:
CustomizeLayoutWindowAction.addLayoutCustomizationPage(getHost().getViewer(),
GridLayoutLayoutPage.class);
// for the layout itself
CustomizeLayoutWindowAction.addComponentCustomizationPage(getHost().getViewer(),
GridLayoutComponentPage.class);
// for GridData of the child
This layout component page (GridLayoutComponentPage)
also extends VE's CustomizeLayoutPage.
Please pay particular attention to the handleSelectionChanged(ISelection
oldSelection) method which is
called by the VE's Customize window to determine if your page needs to
be shown or not when selection changes in the graph or beans view.
In your layout policy, you also need to implement the interface IActionFilter
which requires a method
public boolean
testAttribute(Object target, String name, String value)
This is a basic test for actions on the popup menu to determine if Customize
Layout... should be added when someone clicks MB2 over a composite
with your layout. You will need to add the statements:
if (name.startsWith(CustomizeLayoutPage.LAYOUT_POLICY_KEY)
&& value.equals(LAYOUT_ID))
return true;
return false;
Whereas the LAYOUT_ID should be your own unique ID for your layout (e.g.
RowLayoutEditPolicy's LAYOUT_ID is "org.eclipse.swt.layout.RowLayout").
Good luck and post here if you have further questions.
Regards...
Peter Walker
-------------------------------------
Eclipse VE Development
919-254-1558
Ameet A Kulkarni/Durham/IBM@IBMUS
Sent by: ve-dev-bounces@xxxxxxxxxxx
11/03/2005 10:11 AM
Please respond to
Discussions people developing code for the Visual Editor project
To
Discussions people
developing code for the Visual Editor project <ve-dev@xxxxxxxxxxx>
cc
Subject
[ve-dev] Question regarding
Layouts
Hi
we are currently using the visual editor capabilities
in our project. So to extend that, with respect to layouts, that Visual
editor provides, like the null, form,grid etc, for the composite /shell
containers .We plan to add our own layout to the existing ones.
So when we create a shell or a composite or container, in the properties
tab, we see the layout property. It is a drop down containing the existing
layouts, My question is ,is there any way i can add my layout type there
in the drop down, in addition to the existing ones,so everyone can see
the existing as well as new layouts when, they drop a shell or a composite
I figured out a way to add my own property in the properties tab and use
it, I am not sure, if new additions can be done to the existing properties..
Thanks
Regards,
Ameet
_____________________________________
Lotus Software
Phone:978-399-5254(tie:333-5254)_______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev _______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev