// resource type name
resourceContextMenu.addItem(new MenuItem(MSG.view_tree_common_contextMenu_type_name_label(resourceType
.getName())));
// separator
resourceContextMenu.addItem(new MenuItemSeparator());
// refresh node
MenuItem refresh = new MenuItem(MSG.common_button_refresh());
refresh.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
contextMenuRefresh(treeGrid, node, false);
}
});
resourceContextMenu.addItem(refresh);
// separator
resourceContextMenu.addItem(new MenuItemSeparator());
// child resources
MenuItem childResources = new MenuItem(MSG.view_tabs_common_child_resources());
boolean childResourcesEnabled = resourceType.getChildResourceTypes() != null
&& !resourceType.getChildResourceTypes().isEmpty();
childResources.setEnabled(childResourcesEnabled);
if (childResourcesEnabled) {
childResources.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
CoreGUI.goToView(LinkManager.getResourceTabLink(resource.getId(), "Inventory", "Children"));
}
});
}
resourceContextMenu.addItem(childResources);
// plugin config
MenuItem pluginConfiguration = new MenuItem(MSG.view_tabs_common_connectionSettings());
boolean pluginConfigEnabled = resourceType.getPluginConfigurationDefinition() != null;
pluginConfiguration.setEnabled(pluginConfigEnabled);
if (pluginConfigEnabled) {
pluginConfiguration.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
CoreGUI.goToView(LinkManager.getResourceTabLink(resource.getId(), "Inventory", "ConnectionSettings"));
}
});
}
resourceContextMenu.addItem(pluginConfiguration);
// resource config
MenuItem resourceConfiguration = new MenuItem(MSG.view_tree_common_contextMenu_resourceConfiguration());
boolean resourceConfigEnabled = resourcePermission.isConfigureRead()
&& resourceType.getResourceConfigurationDefinition() != null;
resourceConfiguration.setEnabled(resourceConfigEnabled);
if (resourceConfigEnabled) {
resourceConfiguration.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
CoreGUI.goToView(LinkManager.getResourceTabLink(resource.getId(), "Configuration", "Current"));
}
});
}
resourceContextMenu.addItem(resourceConfiguration);
// separator
resourceContextMenu.addItem(new MenuItemSeparator());
// Operations Menu
MenuItem operations = new MenuItem(MSG.common_title_operations());
boolean operationsEnabled = (resourcePermission.isControl() && (resourceType.getOperationDefinitions() != null) && !resourceType
.getOperationDefinitions().isEmpty());
operations.setEnabled(operationsEnabled);
if (operationsEnabled) {
Menu opSubMenu = new Menu();
//sort the display items alphabetically
TreeSet<String> ordered = new TreeSet<String>();
Map<String, OperationDefinition> definitionMap = new HashMap<String, OperationDefinition>();
for (OperationDefinition o : resourceType.getOperationDefinitions()) {
ordered.add(o.getDisplayName());
definitionMap.put(o.getDisplayName(), o);
}
for (String displayName : ordered) {
final OperationDefinition operationDefinition = definitionMap.get(displayName);
MenuItem operationItem = new MenuItem(operationDefinition.getDisplayName());
operationItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
String viewPath = LinkManager.getResourceTabLink(resource.getId(),
ResourceDetailView.Tab.Operations.NAME, "Schedules") + "/0/" + operationDefinition.getId();
CoreGUI.goToView(viewPath);
}
});
opSubMenu.addItem(operationItem);
}
operations.setSubmenu(opSubMenu);
}
resourceContextMenu.addItem(operations);
// this menu item will be the last one
final OpenSupportCaseMenuItem openSupportCase = new OpenSupportCaseMenuItem(resourceComposite);
// Create Child Menu and Manual Import Menu
final Set<ResourceType> creatableChildTypes = getCreatableChildTypes(resourceType);
final Set<ResourceType> importableChildTypes = getImportableChildTypes(resourceType);
final boolean hasCreatableTypes = !creatableChildTypes.isEmpty();
final boolean hasImportableTypes = !importableChildTypes.isEmpty();
boolean canCreate = resourcePermission.isCreateChildResources();
Integer[] singletonChildTypes = getSingletonChildTypes(resourceType);
// To properly filter Create Child and Import menus we need existing singleton child resources. If the
// user has created permission and the parent type has singleton child types and creatable or importable child
// types, perform an async call to fetch the singleton children.
if (canCreate && singletonChildTypes.length > 0 && (hasCreatableTypes || hasImportableTypes)) {
ResourceCriteria criteria = new ResourceCriteria();
criteria.addFilterParentResourceId(resource.getId());
criteria.addFilterResourceTypeIds(singletonChildTypes);
GWTServiceLookup.getResourceService().findResourcesByCriteria(criteria,
new AsyncCallback<PageList<Resource>>() {
@Override
public void onSuccess(PageList<Resource> singletonChildren) {
if (hasCreatableTypes) {
Map<String, ResourceType> displayNameMap = getDisplayNames(creatableChildTypes);
addMenu(MSG.common_button_create_child(), true, singletonChildren, resource,
displayNameMap, true);
}
if (hasImportableTypes) {
Map<String, ResourceType> displayNameMap = getDisplayNames(importableChildTypes);
addMenu(MSG.common_button_import(), true, singletonChildren, resource, displayNameMap,
false);
}
if (openSupportCase.isToBeIncluded()) {
resourceContextMenu.addItem(new MenuItemSeparator());
resourceContextMenu.addItem(openSupportCase);
}
resourceContextMenu.showContextMenu();
}
@Override
public void onFailure(Throwable caught) {
Log.error("Error resources with parentId:" + resource.getId(), caught);
if (openSupportCase.isToBeIncluded()) {
resourceContextMenu.addItem(new MenuItemSeparator());
resourceContextMenu.addItem(openSupportCase);
}
resourceContextMenu.showContextMenu();
}
});
} else if (canCreate && singletonChildTypes.length == 0 && (hasCreatableTypes || hasImportableTypes)) {
if (hasCreatableTypes) {
Map<String, ResourceType> displayNameMap = getDisplayNames(creatableChildTypes);
addMenu(MSG.common_button_create_child(), true, null, resource, displayNameMap, true);
}
if (hasImportableTypes) {
Map<String, ResourceType> displayNameMap = getDisplayNames(importableChildTypes);
addMenu(MSG.common_button_import(), true, null, resource, displayNameMap, false);
}
if (openSupportCase.isToBeIncluded()) {
resourceContextMenu.addItem(new MenuItemSeparator());
resourceContextMenu.addItem(openSupportCase);
}
resourceContextMenu.showContextMenu();
} else {
if (!canCreate && hasCreatableTypes) {
addMenu(MSG.common_button_create_child(), false, null, null, null, true);
}
if (!canCreate && hasImportableTypes) {
addMenu(MSG.common_button_import(), false, null, null, null, false);
}
if (openSupportCase.isToBeIncluded()) {
resourceContextMenu.addItem(new MenuItemSeparator());
resourceContextMenu.addItem(openSupportCase);
}
resourceContextMenu.showContextMenu();
}
}