public static boolean hasPossibleChildren(Datatype datatype) { if (datatype instanceof TestEngineConfiguration) { return getPossibleChildrenTypes((TestEngineConfiguration) datatype).length > 0; } else if (datatype instanceof ProxyConfiguration) { return getPossibleChildrenTypes((ProxyConfiguration) datatype).length > 0; } else if (datatype instanceof ConfigurationProperty) { return false; } else { Activator.getDefault() .logError( "Error. No children-mapping for type '" + datatype.getClass() + "' in " + EngineDataModelManager.class.getCanonicalName() + " found."); return false; } }
@SuppressWarnings("unchecked") public static Class<? extends Datatype>[] getPossibleChildrenTypes(Datatype datatype) { Class<? extends Datatype>[] result; // Determine allowed types if (datatype instanceof TestEngineConfiguration) { result = getPossibleChildrenTypes((TestEngineConfiguration) datatype); } else if (datatype instanceof ProxyConfiguration) { result = getPossibleChildrenTypes((ProxyConfiguration) datatype); } else if (datatype instanceof ConfigurationProperty) { result = new Class[] {}; } else { Activator.getDefault() .logError( "Error. No children-mapping for type '" + datatype.getClass() + "' in " + EngineDataModelManager.class.getCanonicalName() + " found."); result = new Class[] {}; } return result; }
public static Menu getContextMenu( ISelection selection, TreeViewer treeViewer, EngineMaintenanceMultiPageEditViewModelHandlerImpl modelHandler) { Menu result = new Menu(treeViewer.getTree()); TreeSelection treeSelection = (TreeSelection) selection; Object firstElement = treeSelection.getFirstElement(); if (firstElement instanceof MasterDetailTreeNode) { MasterDetailTreeNode treeNode = (MasterDetailTreeNode) firstElement; Datatype datatype = treeNode.getDatatype(); // Menu 'new' Menu newElementMenu = createMenu( result, EngineMaintenanceMultiPageEditViewModelHandlerImpl.ID + NEW_ELEMENT, "icons/add.png"); if (datatype instanceof TestEngineConfiguration) { Class<? extends Datatype>[] possibleChildrenTypes = getPossibleChildrenTypes((TestEngineConfiguration) datatype); addMenuItemsNew(newElementMenu, possibleChildrenTypes, treeNode, treeViewer, modelHandler); // Menu 'clone' Menu cloneElementMenu = createMenu( result, EngineMaintenanceMultiPageEditViewModelHandlerImpl.ID + CLONE_ELEMENT, "icons/copy.png"); addMenuItemsClone( cloneElementMenu, possibleChildrenTypes, treeNode, treeViewer, modelHandler); } else if (datatype instanceof ProxyConfiguration) { Class<? extends Datatype>[] possibleChildrenTypes = getPossibleChildrenTypes((ProxyConfiguration) datatype); addMenuItemsNew(newElementMenu, possibleChildrenTypes, treeNode, treeViewer, modelHandler); } else if (datatype instanceof ConfigurationProperty) { } else { Activator.getDefault() .logError( "Error. No children-mapping for type '" + datatype.getClass() + "' in " + EngineDataModelManager.class.getCanonicalName() + " found."); } if (newElementMenu.getItemCount() == 0) { newElementMenu.getParentItem().setEnabled(false); } // If not root case if (treeNode.getParent() != null) { // Separator new MenuItem(result, SWT.SEPARATOR); // Remove Image image = ImageProvider.createImage("icons/delete.png"); new RemoveDatatypeMenuItem( result, treeNode, modelHandler, treeViewer, EngineMaintenanceMultiPageEditViewModelHandlerImpl.ID + REMOVE, null, image); } } return result; }