CoreServlet.getServlet().getPolicyDatabase().registerResourceType(Sample.SAMPLE_RESOURCE_TYPE);
Sample.SAMPLE_RESOURCE_TYPE.addPermission(PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN);
Sample.SAMPLE_RESOURCE_TYPE.addPermission(PolicyConstants.PERM_EDIT_AND_ASSIGN);
Sample.SAMPLE_RESOURCE_TYPE.addPermission(PolicyConstants.PERM_DELETE);
} catch (Exception e) {
throw new PluginException("Failed to register resource type.", e);
}
// Add the new items to the main menu
MenuTree tree = NavigationManager.getMenuTree(CoreMenuTree.MENU_ITEM_MENU_TREE);
tree.addMenuItem("resources", new MenuItem("userSamples", "sample", "/showUserSamples.do", 50, true, null,
SessionInfo.USER_CONSOLE_CONTEXT, null, null, Sample.SAMPLE_RESOURCE_TYPE));
tree.addMenuItem("globalResources", new MenuItem("managementSamples", "sample", "/showSamples.do", 50, true, null,
SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, Sample.SAMPLE_RESOURCE_TYPE, new Permission[] {
PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_EDIT_AND_ASSIGN,
PolicyConstants.PERM_DELETE }, Sample.SAMPLE_RESOURCE_TYPE));
// Add the new page tasks
MenuTree pageTasks = NavigationManager.getMenuTree(PageTaskMenuTree.PAGE_TASK_MENU_TREE);
pageTasks.addMenuItem(null, new MenuItem("showSamples", null, null, 100, false, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT));
pageTasks.addMenuItem("showSamples", new MenuItem("createSample", "sample", "/sampleDefaultDetails.do", 100, true, "_self",
SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, Sample.SAMPLE_RESOURCE_TYPE,
new Permission[] { PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN }));
// This demonstrates listening for events. In this case we will look for
// 'sample created' events and display a message on the console
CoreServlet.getServlet().addCoreListener(new CoreListener() {
public void coreEvent(CoreEvent evt) {
if (evt.getId() == SamplePlugin.EVT_SAMPLE_CREATED) {
System.err.println("****************************************");
System.err.println("* Someone just created a sample!!! *");
System.err.println("****************************************");
}
}
});
/*
* The following code demonstrates the registering user attribute
* definitions. See the message resources for how to provide the
* titles and descriptions for attributes and categories.
*/
try {
CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
new UserAttributeDefinition(
UserAttributeDefinition.TYPE_STRING,
"sample1", "", 20000, "", "",
UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE,
10, "sample", false, "", "", true, true));
CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
new UserAttributeDefinition(
UserAttributeDefinition.TYPE_STRING,
"sample2", "", 20000, "", "",
UserAttributeDefinition.USER_VIEWABLE_ATTRIBUTE,
20, "sample", false, "Default Sample 2 Value", "", true, true));
CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
new UserAttributeDefinition(
UserAttributeDefinition.TYPE_STRING,
"sample3", "", 20001, "", "",
UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE,
20, "sample", false, "Default Sample 2 Value", "", true, true));
}
catch(Exception e) {
throw new PluginException("Failed to register user attribute definitions.", e);
}
}