}
private void buildAndShowResourceContextMenu(final ResourceTreeNode node,
final ResourceComposite resourceComposite, final ResourceType resourceType) {
final Resource resource = resourceComposite.getResource();
final ResourcePermission resourcePermission = resourceComposite.getResourcePermission();
// resource name
resourceContextMenu.setItems(new MenuItem(resource.getName()));
// 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