Diagram configuration option [message #197246] |
Wed, 16 July 2008 05:23  |
Eclipse User |
|
|
|
Hello folks,
I have to store some configuration options (server url,deploy options..)
for the diagram I'm creating with GMF. Is it possible to add a property
sheet to GMF, and moreover is it possible to persist those configuration
values in the diagram file?
Thank you in advance
Nicola
|
|
|
|
|
|
Re: Diagram configuration option [message #197817 is a reply to message #197425] |
Thu, 17 July 2008 12:41   |
Eclipse User |
|
|
|
Hello Alex,
sorry to bother you again but I'm stuck :(
So what I'd like to do is to add a tab to the property view, that allow me
to set some attributes and save them. I cannot save directly in the domain
model because the XML schema is already defined and I cannot modify it.
What I did is:
1) Made a Java file extending Style and marked as @model
2) Generated the Model+Edit
3) Modified the GenModel in order to add a Custom Property configuration
4) Regenerate the code, and now I have the plugin.xml updated and a new
class ConfigurationPropertySection
5) Modified WorkflowTypeViewFactory adding
styles.add(PropertiesFactory.eINSTANCE.createPropertiesStyle ());
At this point I don't know how to continue, I'm learning by example and
unfortunately I haven't found any. I suppose I have to modify the class at
point 4 to get the object I add to the style in point 5, but I have no
idea how to do it. Can you please help me?
Thank you in advance
Nicola
Alex Shatalin wrote:
> Hello Nicola,
>>> - modifying generated code to make your own PropertyTab edting
>>> corresponding property of underlying notation model element
>> Here I suppose I need to modify:
>> protected Object transformSelection(Object selected)
> Well, I'm not sure abot the code generated by GMF will be applicable for
> your custom property tab, so here we usually implement whole property tab
> using custom code.. If you feel it's ok to use GMF-generated content, but
> only change transformSelection() method it's ok.
>> but I really have no clue of what to do. Do I have to define a new
>> model just for the notational style? Please help.
> Yes. In general you have to define your own .ecore model with only one
EClass
> "CustomPropertiesStyle" extending "Style" from notation.ecore. Then you can
> generate code for this model (i think model code is enough). Then you can
> use API generated by EMF to instantiate CustomPropertiesStyle and then you
> can assign this style to the newly created objects (using custom code in
> corresponding ???ViewFactory.createStyles() method).
> In case you have to store some primitive type properties
(String/int/boolean..)
> in a notation model you can use one of existing subclasses of NamedStyle.
> (BooleanValueStyle/StringValueStyle) then you can skip new .ecore notation
> model extension definition + code generation steps.
> BTW, do you really need to store these properties in a notation model? As
> an option you can modify domain model and introduce corresponding properties
> there.
> -----------------
> Alex Shatalin
|
|
|
|
Re: Diagram configuration option [message #197970 is a reply to message #197899] |
Sat, 19 July 2008 10:28   |
Eclipse User |
|
|
|
Hello Alex,
I feel like a dumb! I spent almost two days with trying to add the
property sheet with no result.
This is what I did since the last mail:
1) modified the plugin.xml in this way:
<propertySection id="property.section.conf"
tab="property.tab.conf"
class=" gsoc.ogsadai.model.diagram.sheet.ConfigurationPropertySectio n ">
<input type="gsoc.ogsadai.model.properties.PropertiesStyle">
</input>
<input type="org.eclipse.gmf.runtime.notation.View">
</input>
<input type="org.eclipse.gef.EditPart">
</input>
2) modified the generated class:
public class ConfigurationPropertySection extends AdvancedPropertySection
implements IPropertySourceProvider {
protected EAttribute getFeature() {
return PropertiesPackage.eINSTANCE.getPropertiesStyle_ServerURL();
}
private ModifyListener listener = new ModifyListener() {
public void modifyText(ModifyEvent arg0) {
EditingDomain editingDomain = getEditingDomain();
Object value = text.getText();
editingDomain.getCommandStack().execute(
SetCommand.create(editingDomain, eObject, getFeature(),value));
}
};
protected Object transformSelection(Object selected) {
..
..
for (Object style : styles) {
if (style instanceof PropertiesStyle)
return style;
}
return null;
}
public void createControls(Composite parent,
TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
..
..
text.addModifyListener(listener);
}
Now I have two problems:
1) the call
styles.add(PropertiesFactory.eINSTANCE.createPropertiesStyle ()); seems to
be successful, if a make a new diagram I have
<styles xmi:type="gsoc.ogsadai.model.properties:PropertiesStyle"
xmi:id="_f6v-YFWREd2ksdhDVLHUbA"/>
thus I suppose it's creating and serializing the new style in the diagram.
If I close and reopen it this is what I get:
org.eclipse.core.runtime.AssertionFailedException: null argument:
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:86)
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:74)
at
org.eclipse.gmf.runtime.diagram.ui.internal.services.editpar t.EditPartOperation. <init>(EditPartOperation.java:43)
at
org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateR ootEditPartOperation. <init>(CreateRootEditPartOperation.java:32)
at
org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPar tService.createRootEditPart(EditPartService.java:248)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.confi gureGraphicalViewer(DiagramEditor.java:831)
at
gsoc.ogsadai.model.diagram.part.RequestDiagramEditor.configu reGraphicalViewer(RequestDiagramEditor.java:282)
it should be something related to the load operation, but I have not clue.
The ecore file is serialized using XMI.
2) The editor property editor is not working :) I followed the
http://www.eclipse.org/articles/Article-Tabbed-Properties/ta bbed_properties_view.html
that uses a class implementing IPropertySource. My class is implementing
IPropertySourceProvider but the code automaticaly generated for the
methods getPropertySource return null. Do I have to register my adapter
somewhere?
Sorry again for this question, but I've never used eclipse SWT so far, and
I need to use now for the project I'm working on.
Thanks in advance
Nicola
Alex Shatalin wrote:
> Hello Nicola,
> From the selection you'll receive EditPart instance (most probably). Using
> this EditPart you can get View instance by calling
(org.eclipse.gmf.runtime.notation.View)
> EditPart.GetModel()
> The usign View.getStyle(EClass) or View.getStyles() you'll be able to access
> Style instance attached to the View of WorkflowType on step 5.
> The rest is up to PropertyTab implementation - this is just a set of SWT
> controls, so you can develop any UI using normal eclipse ways to create UI..
> -----------------
> Alex Shatalin
|
|
|
|
|
|
Re: Diagram configuration option [message #198504 is a reply to message #198282] |
Wed, 23 July 2008 07:09   |
Eclipse User |
|
|
|
Hello Alex,
thank you for your last reply! I managed to solve both the problem, in a
magical way but they are solved.
> Well, try putting a breakpoint into DiagramIOUtil.load() to see why diagram
> was not loaded correctly (this method should be called from generated
>???DocumentProvider.setDocumentContent())
The first problem (diagram not loading) was related to a problem with the
properties.ecore file. It start to work when I deleted the EMF Model
plugin and regenerate model.
> If you return custom instance of IPropertySource from this method then where
> is the problem (cust of PropertiesStyle to IAdaptable)?
What I did here, was to implement IAdaptable in PropertiesStyleImpl. Then
I return a CustomProperties in the getPropertySource I return a
CustomProperty implementing IPropertySource. Now the only problem I have
(yes another one) is to access this notational style from the EMF editor.
Any idea?
I don't know if it can be useful but this is all the process I did to add
a notational style with an associated property sheet to a GMF diagram:
1) Made a Java file extending Style and marked as @model
2) Generate the Model+Edit. Be sure that the plugin register FactorImpl..
you should have something like this:
<extension point="org.eclipse.emf.ecore.extension_parser">
<parser type="properties"
class=" gsoc.ogsadai.model.properties.util.PropertiesResourceFactory Impl "/>
</extension>
2.2) modify the model class ???Impl implementing IAdaptable and add the
method:
public Object getAdapter(Class adapter) {
return Platform.getAdapterManager().getAdapter(this, adapter);
}
3) Modified the GenModel in order to add a Custom Property configuration
4) Regenerate the code, and now I have the plugin.xml updated and a new
class ConfigurationPropertySection. Be sure to have some inputs to the
property, otherwise it will not be called (not sure about it)
5) Modified WorkflowTypeViewFactory adding
styles.add(???Factory.eINSTANCE.createPropertiesStyle());
6) Create a class that implements IPropertySource:
final class CustomProperties implements IPropertySource {
PropertiesStyle style;
/**
*
*/
public CustomProperties(Object obj) {
style = (PropertiesStyle) obj;
}
public Object getEditableValue() {
return this;
}
public IPropertyDescriptor[] getPropertyDescriptors() {
IPropertyDescriptor[] propertyDescriptors = { new TextPropertyDescriptor(
style, "Server URL") };
return propertyDescriptors;
}
public Object getPropertyValue(Object id) {
return style.getServerURL();
}
public boolean isPropertySet(Object id) {
return false;
}
public void resetPropertyValue(Object id) {
//
}
public void setPropertyValue(Object id, Object value) {
style.setServerURL((String) value);
}
};
7) Modify the generated ???PropertySection in order to accept the new
style as input and to return the CustomProperty as propertySource:
protected Object transformSelection(Object selected) {
View view = null;
List styles;
if (selected instanceof View) {
view = ((View) selected);
} else if (selected instanceof EditPart) {
Object model = ((EditPart) selected).getModel();
view = ((View) model);
} else if (selected instanceof IAdaptable) {
view = (View) ((IAdaptable) selected).getAdapter(View.class);
}
if (view == null)
return null;
styles = view.getStyles();
for (Object style : styles) {
if (style instanceof PropertiesStyle)
return style;
}
return null;
}
public IPropertySource getPropertySource(Object object) {
if (object instanceof IPropertySource) {
return (IPropertySource) object;
}
AdapterFactory af = getAdapterFactory(object);
if (af != null) {
IItemPropertySource ips = (IItemPropertySource)af.adapt(object,
IItemPropertySource.class);
if (ips != null) {
return new PropertySource(object, ips);
}
}
if (object instanceof IAdaptable) {
//return (IPropertySource) ((IAdaptable) object)
// .getAdapter(IPropertySource.class);
return new CustomProperties(object);
}
return null;
}
And tatan... you should have a working notational style. If there is
anything wrong in the process, tell me.
Thanks again for helping
Cheers
Nicola
Alex Shatalin wrote:
> Hello Nicola,
>> Do you have any working example?
> You can use one of the following ISection implementations as an example:
>
org.eclipse.gmf.runtime.diagram.ui.properties.sections.appea rance.ShapeColorsAndFontsPropertySection
>
org.eclipse.gmf.runtime.diagram.ui.properties.sections.appea rance.DiagramColorsAndFontsPropertySection
>
org.eclipse.gmf.runtime.diagram.ui.properties.sections.grid. RulerGridPropertySection
> -----------------
> Alex Shatalin
|
|
|
|
|
|
|
|
|
|
|
Re: Diagram configuration option [message #199288 is a reply to message #199281] |
Mon, 28 July 2008 12:15  |
Eclipse User |
|
|
|
Hello Nicola,
> In the EMF.Edif having an EObject I will be easy to cast it. The
> problem is that the best I can get is an EClass with
> PropertiesPackage.eINSTANCE.getPropertiesStyle_ServerURL() and
This is a meta-object, but you should be able to access real instance of
the PropertiesStyle interface to set appropriate value on it..
-----------------
Alex Shatalin
|
|
|
Powered by
FUDForum. Page generated in 0.06326 seconds