[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI - Modifying class forms via the API
FYI, I was able
to get my prior question below working, creating a metaclass and adding some
slots via the api, and also arranging how it should look in the form viewer via
the api. Below is the code if anyone is interested.
The only question
i still have, after running this code, when going to the forms tab and selecting
the metaclass created below, the form displays in a default layout. If I
dbl-click on an empty area of the form bringing up the config dialog, click ok
without doing anything else, then the form gets displayed correctly. If i
go to the classes tab (even before going to the form tab), look at any class
created with the custom metaclass, the form comes up the way it should look
without having to do anything. Any ideas on that one?
Thanks again
-
Derrick
/**
* Create the metaclass we will use when
*
importing concepts into Protege
*/
private Cls
getDtsMetaclass()
{
Cls metaClass =
currentKb.getCls(META_CLS);
if(metaClass==null)
{
Cls standardClass =
currentKb.getCls(":STANDARD-CLASS");
metaClass
=
currentKb.createCls(META_CLS,Collections.singleton(standardClass));
ClsWidget widget =
currentKb.getProject().getDesignTimeClsWidget(metaClass);
WidgetDescriptor wd = widget.getDescriptor();
wd.setDirectlyCustomizedByUser(true);
Slot nameSlot =
currentKb.createSlot(SLOT_NAME);
nameSlot.setValueType(ValueType.STRING);
nameSlot.setAllowsMultipleValues(false);
metaClass.addDirectTemplateSlot(nameSlot);
Slot codeSlot =
currentKb.createSlot(SLOT_CODE);
codeSlot.setValueType(ValueType.STRING);
codeSlot.setAllowsMultipleValues(false);
metaClass.addDirectTemplateSlot(codeSlot);
Slot idSlot =
currentKb.createSlot(SLOT_ID);
idSlot.setValueType(ValueType.STRING);
idSlot.setAllowsMultipleValues(false);
metaClass.addDirectTemplateSlot(idSlot);
Slot propSlot =
currentKb.createSlot(SLOT_PROPS);
propSlot.setValueType(ValueType.STRING);
propSlot.setAllowsMultipleValues(true);
metaClass.addDirectTemplateSlot(propSlot);
Slot roleSlot =
currentKb.createSlot(SLOT_ROLES);
roleSlot.setValueType(ValueType.STRING);
roleSlot.setAllowsMultipleValues(true);
metaClass.addDirectTemplateSlot(roleSlot);
// Modify the form, arrange the slots we
added in
// the order and placement we want
them, hide all
// other standard
slots.
PropertyList list =
currentKb.getProject().getClsWidgetPropertyList(metaClass);
Collection names = list.getNames();
Iterator
it = names.iterator();
WidgetDescriptor desc2
= null;
while(it.hasNext())
{
String name =
(String)it.next();
Rectangle rect
= new Rectangle();
if(name.equalsIgnoreCase(SLOT_NAME))
{
desc2 =
list.getWidgetDescriptor(name);
rect.setBounds(0,0,600,60);
desc2.setBounds(rect);
desc2.setVisible(true);
desc2.setDirectlyCustomizedByUser(true);
}
else
if(name.equalsIgnoreCase(SLOT_CODE))
{
desc2 =
list.getWidgetDescriptor(name);
rect.setBounds(0,60,400,60);
desc2.setBounds(rect);
desc2.setVisible(true);
desc2.setDirectlyCustomizedByUser(true);
}
else
if(name.equalsIgnoreCase(SLOT_ID))
{
desc2 =
list.getWidgetDescriptor(name);
rect.setBounds(400,60,200,60);
desc2.setBounds(rect);
desc2.setVisible(true);
desc2.setDirectlyCustomizedByUser(true);
}
else
if(name.equalsIgnoreCase(SLOT_ROLES))
{
desc2 =
list.getWidgetDescriptor(name);
rect.setBounds(0,120,600,200);
desc2.setBounds(rect);
desc2.setVisible(true);
System.out.println(desc2.getWidgetClassName());
desc2.setDirectlyCustomizedByUser(true);
desc2.setWidgetClassName("com.apelon.dts.protege.RolePropViewer");
}
else
if(name.equalsIgnoreCase(SLOT_PROPS))
{
desc2 =
list.getWidgetDescriptor(name);
rect.setBounds(0,320,600,200);
desc2.setBounds(rect);
desc2.setVisible(true);
desc2.setDirectlyCustomizedByUser(true);
desc2.setWidgetClassName("com.apelon.dts.protege.RolePropViewer");
}
else
{
if(!name.equalsIgnoreCase("layout
properties"))
{
desc2 =
list.getWidgetDescriptor(name);
if(desc2!=null)
{
desc2.setDirectlyCustomizedByUser(true);
desc2.setIncluded(false);
desc2.setWidgetClassName(null);
}
}
}
}
}
return metaClass;
}
Hi All
-
I have another
API question though if anyone could give me a suggestion. The plugin I'm
writing imports "concepts" from our knowledgebase representation into
Protege. I have code working that creates a custom metaclass for our
imported concepts (they get imported as classes) adds a few template slots, and
is able to fill in all slot values when importing our concepts. The last
thing I'm trying to get working is to be able to modify the look of the form via
the API, for the metaclass I create. Below is the code I currently have
that does create metaclass with template slots, the second half of the code does
not seem to effect the form's appearance though, it comes up in a default
layout. Any ideas?
Thanks in advance
for any suggestions or help!
Derrick
private static final
String ROOT_CLS = "Imported
Concepts";
private static final String META_CLS = "My_Metaclass";
private static final
String SLOT_NAME = "Concept Name";
private static final String
SLOT_CODE = "Concept Code";
private static final String SLOT_ID =
"Concept ID";
private static final String SLOT_PROPS = "Concept
Properties";
private static final String SLOT_ROLES = "Concept
Roles";
...
private
Cls getCustomMetaclass()
{
Cls metaClass =
currentKb.getCls(META_CLS);
if(metaClass==null)
{
Cls standardClass =
currentKb.getCls(":STANDARD-CLASS");
metaClass
=
currentKb.createCls(META_CLS,Collections.singleton(standardClass));
Slot nameSlot =
currentKb.createSlot(SLOT_NAME);
nameSlot.setValueType(ValueType.STRING);
nameSlot.setAllowsMultipleValues(false);
metaClass.addDirectTemplateSlot(nameSlot);
Slot codeSlot =
currentKb.createSlot(SLOT_CODE);
codeSlot.setValueType(ValueType.STRING);
codeSlot.setAllowsMultipleValues(false);
metaClass.addDirectTemplateSlot(codeSlot);
Slot idSlot =
currentKb.createSlot(SLOT_ID);
idSlot.setValueType(ValueType.STRING);
idSlot.setAllowsMultipleValues(false);
metaClass.addDirectTemplateSlot(idSlot);
Slot propSlot =
currentKb.createSlot(SLOT_PROPS);
propSlot.setValueType(ValueType.STRING);
propSlot.setAllowsMultipleValues(true);
metaClass.addDirectTemplateSlot(propSlot);
Slot roleSlot =
currentKb.createSlot(SLOT_ROLES);
roleSlot.setValueType(ValueType.STRING);
roleSlot.setAllowsMultipleValues(true);
metaClass.addDirectTemplateSlot(roleSlot);
ClsWidget widget =
currentKb.getProject().getDesignTimeClsWidget(metaClass);
WidgetDescriptor desc =
widget.getDescriptor();
PropertyList list =
desc.getPropertyList();
WidgetDescriptor desc2
= null;
Collection names =
list.getNames();
Iterator it =
names.iterator();
while(it.hasNext())
{
String name =
(String)it.next();
Rectangle rect
= new Rectangle();
if(name.equalsIgnoreCase(SLOT_NAME))
{
desc2 =
list.createWidgetDescriptor(name);
rect.setBounds(0,300,200,60);
desc2.setBounds(rect);
desc2.setVisible(true);
}
else
if(name.equalsIgnoreCase(SLOT_CODE))
{
desc2 =
list.createWidgetDescriptor(name);
rect.setBounds(0,400,100,60);
list.setRectangle(name,rect);
desc2.setBounds(rect);
desc2.setVisible(true);
}
else
if(name.equalsIgnoreCase(SLOT_ID))
{
desc2 =
list.createWidgetDescriptor(name);
rect.setBounds(150,400,100,60);
list.setRectangle(name,rect);
desc2.setBounds(rect);
desc2.setVisible(true);
}
else
if(name.equalsIgnoreCase(SLOT_ROLES))
{
desc2 =
list.createWidgetDescriptor(name);
rect.setBounds(0,500,200,200);
list.setRectangle(name,rect);
desc2.setBounds(rect);
desc2.setVisible(true);
}
else
if(name.equalsIgnoreCase(SLOT_PROPS))
{
desc2 =
list.createWidgetDescriptor(name);
rect.setBounds(0,750,200,200);
list.setRectangle(name,rect);
desc2.setBounds(rect);
desc2.setVisible(true);
}
}
//desc.setPropertyList(list);
widget.setup(desc,true,currentKb.getProject(),metaClass);
}
return metaClass;
}
-----Original Message-----
From: Derrick Butler
[mailto:dbutler@apelon.com]
Sent: Wednesday, August 21, 2002 11:22
AM
To: Protege Discussion (E-mail)
Subject: API Question -
SlotWidgets
I have a custom SlotWidget that
displays on Class forms. When a user selects a value, i would like to get
the class instance, and set other class instance slot values, and have the form
updated. Is there any sample code out there that shows how to do
this?
Thanks in advance
-
Derrick