[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: Diagram configuration option

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.PropertiesResourceFactoryImpl"/>
</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.appearance.ShapeColorsAndFontsPropertySection

org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.DiagramColorsAndFontsPropertySection

org.eclipse.gmf.runtime.diagram.ui.properties.sections.grid.RulerGridPropertySection

-----------------
Alex Shatalin