[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.gmf] Re: property with File Browser Dialog (actual solution!!!)
|
OK, I have to say sorry for leading you down the wrong path ealier:-(
This is what I have found out by piecing together what was suggested
earlier in this thread and also other postings(including one by Mischael
today)
Starting from just the plain generated code we can do this in 3 easy
steps.
Let's assume you have an application called MyApplication, an element
called MyElement, and a property of MyElement called MyProperty that you
want to override with a custom dialog for the PropertiesView.
Let's start from the bottom up.
1. You need a DialogCellEditor either custom or built-in.
Here's a sample of a custom DialogCellEditor that simply ask for a text
input:
public class CustomDialogCellEditor extends DialogCellEditor {
public CustomDialogCellEditor(Composite parent) {
super(parent);
}
protected Object openDialogBox(Control cellEditorWindow) {
/*
* Here you can instantiate any built-in or custom Dialog you want
*/
InputDialog dialog = new InputDialog(null, "New Value", "Enter
a new value", getValue().toString(), null);
/*
* Only if the user clicks OK in your dialog do you return the
new value otherwise return the original value
*/
return (InputDialog.OK == dialog.open()) ? dialog.getValue():
getValue();
}
}
=======================================================================
2. You need a subclass of EMFCompositeSourcePropertyDescriptor which
uses your CustomDialogCellEditor. Here's a sample:
public class CustomPropertyDescriptor extends
EMFCompositeSourcePropertyDescriptor {
public CustomPropertyDescriptor(Object object,
IItemPropertyDescriptor itemPropertyDescriptor, String category) {
super(object, itemPropertyDescriptor, category);
}
protected CellEditor doCreateEditor(Composite composite) {
/*
* The features for your element will be fed in one at a time
* Here you will override just the one(s) you want
*/
if
(MyApplication.eINSTANCE.getMyElement_MyProperty().equals(getFeature())) {
return new CustomDialogCellEditor(composite);
}
return super.doCreateEditor(composite);
}
}
====================================================================
3. Finally, you need to override createPropertySource() in your
...diagram.providers.MyApplicationPropertyProvider to use your
CustomPropertyDescriptor.
protected ICompositePropertySource createPropertySource(Object object,
IItemPropertySource itemPropertySource) {
/*
* If it's an instance of your element then return your
CustomPropertyDescriptor
*/
if (object instanceof MyElement) {
return new EMFCompositePropertySource(object,
itemPropertySource, "EMF") {
protected IPropertyDescriptor
newPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor) {
return new CustomPropertyDescriptor(object,
itemPropertyDescriptor, getCategory());
}
};
}
return super.createPropertySource(object, itemPropertySource);
}
And that should be it; I should have researched into this more
thoroughly before:-(.
-- Khai --
Khai M Nguyen wrote:
Sorry but looking at the GMF code the approach used for EMF as suggested
previously will not work because GMF employs a lot of encapsulation and
dynamic binding of the properties which basically buries the code so
deep that any changes to the normal behavior (using the suggestions
below) seems like major surgery:-(
I'll look into it some more to see if I can figure out a simple way to
modify its normal behavior... but I'm not too optimistic:-(
-- Khai --
Atanas wrote:
Excuse me for my poor description :(. I extend
org.eclipse.gmf.runtime.diagram.ui.properties.sections.AdvancedPropertySection
method getPropertySourceProvider().
Then make my custom CustomAdapterFactoryProvider to return
CustomPropertySource in case if I have File.class to return Property
Descriptor - ColorPropertyDescriptor.
The problem is when I create with "ColorPropertyDescriptor(object,
"Property Name"); " and here I can not get "Property Name" because in
object I have only value (description for type of property) for
example : if you have property in "Advanced" section with name - "Font
Style" and user choose value for this property - "normal" and this
property appears in category - "EMF" then object which I get from
"getPropertySource(Object object)" contains only value "normal" and
there is no way to get name -"Font Style" and category - "EMF".
This is the all code :
---------------------------------------------------------------------------------
public class CustomAdvancedPropertySection extends
AdvancedPropertySection {
protected IPropertySourceProvider getPropertySourceProvider() {
return new CustomAdapterFactoryProvider();
}
}
final class CustomAdapterFactoryProvider extends
PropertiesServiceAdapterFactory
{
@Override
public IPropertySource getPropertySource(Object object) {
if (object instanceof Color.class) {
return new CustomPropertySource(object);
} else
return super.getPropertySource(object);
}
}
final class CustomPropertySource implements IPropertySource
{
// Property Descriptors
static protected IPropertyDescriptor[] propertyDescriptors = new
IPropertyDescriptor[1];
private Object object;
public CustomPropertySource(Object object)
{
this.object = object;
}
public Object getEditableValue() {
// TODO Auto-generated method stub
return object;
}
public IPropertyDescriptor[] getPropertyDescriptors() {
ColorPropertyDescriptor descriptor;
descriptor = new ColorPropertyDescriptor(object, "Property
Name");
//descriptor.setCategory("EMF"); //Hardcoded
propertyDescriptors[0] = descriptor;
return propertyDescriptors;
}
public Object getPropertyValue(Object id) {
// TODO Auto-generated method stub
return null;
}
public boolean isPropertySet(Object id) {
// TODO Auto-generated method stub
return false;
}
public void resetPropertyValue(Object id) {
// TODO Auto-generated method stub
}
public void setPropertyValue(Object id, Object value) {
// TODO Auto-generated method stub
}
}
Thank you in advance !!!
Regards Atanas.
Khai M Nguyen wrote:
Hi, Atanas, I don't understand what you are asking:-(
Maybe it will help if you describe a little more on what you have done,
and more specifically in which class/classes are the 2 methods below;
these methods are found all over the place so which one are you
referring to?.
-- Khai --
Atanas wrote:
Thanks Khai, I use your advise and now I can change Property
Descriptors, but I have a problem because the object in
"IPropertySource getPropertySource(Object object)" represents value
of property in sheet property page (for example object of type
Integer or other depends of type value) and later in section :
"public IPropertyDescriptor[] getPropertyDescriptors() {
ColorPropertyDescriptor descriptor;
descriptor = new ColorPropertyDescriptor(object,
PropertyName); ",
and I can not get the name of the property and category !!
I do not know how to do it.
Regards, Atanas.
Khai M Nguyen wrote:
This is a bit of a stretch because I haven't implemented any of
this but
this is what I think you'd need to do for the GMF Properties View.
GMF uses tabbed sheets and sections... in your case specifically
org.eclipse.gmf.runtime.diagram.ui.properties.sections.AdvancedPropertySection
It's this class that you would need to extend and override; the method
getPropertySourceProvider() is where you would return your custom
provider.
The rest of the information mentioned earlier in this thread should
still be applicable.
Additionally you would have to override the contribution in the
plugin.xml to use your 'custom' AdvancedPropertySection.
There is a thread in this same newsgroup under "Adding underline
and strikethrough in appereance" where I'd posted some suggestions
on how to
override the default contributions.
Hopes this help.
-- Khai --
Atanas wrote:
I have the same problem,
John did you find some solution to problem ?
Regards,
Atanas.
Ed Merks wrote:
John,
That's sounds like a GMF question I don't know the answer to...
John Watson wrote:
Hi Ed,
Thank you for the link. I tryed to use some of the solutions but
it didn't help me very much.
For example:
The editor has this:
propertySheetPage.setPropertySourceProvider(new
AdapterFactoryContentProvider(adapterFactory));
so you can override the the content provider to create a derived
property source:
protected IPropertySource createPropertySource(Object object,
IItemPropertySource itemPropertySource)
{
return new PropertySource(object, itemPropertySource);
}
and you can override the property source to create a derived
property
descriptor:
protected IPropertyDescriptor
createPropertyDescriptor(IItemPropertyDescriptor
itemPropertyDescriptor)
{
return new PropertyDescriptor(object, itemPropertyDescriptor);
}
And there you can implement whatever logic you want to produce
alternative cell editors in whatever situations they would be
appropriate.
I change the propertySheetPage.setPropertySourceProviderto use
my own class (new
CustomAdapterFactoryContentProvider(adapterFactory));
But it's not called from Diagram. I noticed that GMF uses
%Model%PropertyProvider extends GenericEMFPropertiesProvider
and only the addImagePropertyDescriptor
{itemPropertyDescriptors.add(..)} from ItemProvider
and I don't know how to chnage that method to achieve the
desired result
Ed Merks wrote:
John,
Try searching the EMF newsgroup like this:
http://www.eclipse.org/search/search.cgi?q=custom+cell+editor+file+dialog&cmd=Search%21&form=extended&wf=574a74&ps=10&m=all&t=5&ul=%2Fnewslists%2Fnews.eclipse.tools.emf&wm=wrd&t=News&t=Mail
<http://www.eclipse.org/search/search.cgi?q=custom+cell+editor+file+dialog&cmd=Search%21&form=extended&wf=574a74&ps=10&m=all&t=5&ul=%2Fnewslists%2Fnews.eclipse.tools.emf&wm=wrd&t=News&t=Mail>
John Watson wrote:
Hi,
I need a property where to store filename. How can I make
choose the file by file browser dialog?
Thanks in advance!
John