Model a New Document Subclass
Now you will use Java Annotations provided by Windchill’s Information Modeler to create a document subclass with a new integer attribute.
1. From the Windows Start menu open a Windchill Shell and change to the src directory.
2. The new class will be in the package called com.acme. Change directory to com/acme, creating the directories if necessary.
3. Create a new source file called AcmeModeledDoc.java in the acme directory. Here are the contents for the source file:
package com.acme;

import wt.doc.WTDocument;
import wt.util.WTException;
import com.ptc.windchill.annotations.metadata.*;

@GenAsPersistable(superClass=WTDocument.class,
properties={
@GeneratedProperty(name="sizeC",
type=Integer.class, initialValue="3",
javaDoc="Integer value to represent the size of C.")},

iconProperties=@IconProperties(standardIcon="netmarkets/images/stop.gif",
openIcon="netmarkets/images/stop.gif")
)
public class AcmeModeledDoc extends _AcmeModeledDoc {

static final long serialVersionUID = 1;

public static AcmeModeledDoc newAcmeModeledDoc()
throws WTException {
AcmeModeledDoc instance = new AcmeModeledDoc();
instance.initialize();
return instance;
}
}
The name of the icon is not meaningful, but it is a distinctive image that you will be able to pick out in the UI later.
4. Now go back to the command prompt and compile your file with this command:
tools class -Dclass.includes=com\acme\*
You will find the compiled class file and generated ClassInfo.ser file (that contains meta data about the new class) here:..\Windchill\codebase\com\acme\
5. Now you will generate the SQL scripts for your new document class. Enter this command in the Windchill Shell:
tools -Dgen.input=com.acme.* sql_script
This will generate the SQL commands necessary to create the database schema for your new subclass. You will find the generated schema here: ..Windchill\db\sql\com\acme\create_AcmeModeledDoc_Table.sql
6. You can inspect the sql files to see what was generated.
7. Now you will create the table and associated database artifacts for your new document class. To do this, from within sqlplus, you will execute two scripts:
..\Windchill\db\sql\com\Make_pkg_com_Table.sql..\Windchill\db\sql\com\Make_pkg_com_Index.sql
8. From the Windchill Shell, login to sqlplus.
sqlplus <db_user>/<db_user_pw>@<sid>
9. At the “SQL” prompt execute the two scripts using full path names similar to this:
@<Windchill>\db\sql\com\Make_pkg_com_Table.sql@<Windchill>\db\sql\com\Make_pkg_com_Index.sql
10. Now execute a describe command to see the columns in the new table for your class. Note that there is a “SIZEC” column for the attribute you added directly to the class.
describe AcmeModeledDoc
You may also want count the number of rows in the table to confirm that it is empty:select count(*) from AcmeModeledDoc;
11. Restart the method server.
12. As the Organization Administrator, open the Type and Attribute Management. You will now see your modeled document subclass in the type hierarchy. Note the red flag “stop” icon that you specified for your subclass in the model
13. We must now change the display name for the sizeC attribute and add it to a group in each layout. Edit your type, and change the default name of the sizeC attribute to “Size C”. Select Save
14. Select the “Create layout”. Drag the “Size C” attribute to the Attributes column and Save.
15. Select the “More attributes layout”. Drag the “Size C” attribute to the Attributes column and Save and OK.
War dies hilfreich?