/** * Constructor. * * @param createTool The tool to do some other actions * @param editingDomain The transactional editing domain * @param tableCommandFactory The EMF command factory */ public CreateToolItemAction( final TreeItemCreationTool createTool, final TransactionalEditingDomain editingDomain, final ITreeCommandFactory tableCommandFactory) { super( new IdentifiedElementQuery(createTool).getLabel(), CreateToolItemAction.findImageDescriptor(createTool), editingDomain, tableCommandFactory, createTool); }
private static ImageDescriptor findImageDescriptor(TreeItemCreationTool createTool) { ImageDescriptor descriptor = DTreeViewerManager.getImageRegistry() .getDescriptor(DTreeViewerManager.CREATE_TREE_ITEM_IMG); EObject created = null; Iterator<CreateInstance> createInstances = Iterators.filter(createTool.eAllContents(), CreateInstance.class); while (created == null && createInstances.hasNext()) { CreateInstance map = createInstances.next(); created = CreateToolItemAction.tryToInstanciateType(createTool, created, map.getTypeName()); } Iterator<TreeItemMapping> it = createTool.getMapping().iterator(); while (created == null && it.hasNext()) { TreeItemMapping map = it.next(); created = CreateToolItemAction.tryToInstanciateType(createTool, created, map.getDomainClass()); } if (created != null) { final IItemLabelProvider labelProvider = (IItemLabelProvider) TreeUIPlugin.getPlugin() .getItemProvidersAdapterFactory() .adapt(created, IItemLabelProvider.class); if (labelProvider != null) { ImageDescriptor semanticDescriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(created)); if (semanticDescriptor != null) { descriptor = semanticDescriptor; } } } return descriptor; }