1 17 package org.eclipse.emf.mapping.action; 18 19 20 import java.util.Collection ; 21 import java.util.EventObject ; 22 23 import org.eclipse.jface.action.Action; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.viewers.ISelectionProvider; 26 import org.eclipse.ui.IWorkbenchPart; 27 28 import org.eclipse.emf.common.command.Command; 29 import org.eclipse.emf.common.command.CommandStackListener; 30 import org.eclipse.emf.common.command.CommandWrapper; 31 import org.eclipse.emf.edit.command.CommandActionDelegate; 32 import org.eclipse.emf.edit.command.CommandParameter; 33 import org.eclipse.emf.edit.domain.EditingDomain; 34 import org.eclipse.emf.edit.ui.action.CommandAction; 35 import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; 36 import org.eclipse.emf.mapping.MappingPlugin; 37 import org.eclipse.emf.mapping.command.CreateMappingCommand; 38 import org.eclipse.emf.mapping.domain.MappingDomain; 39 import org.eclipse.emf.mapping.provider.MappingItemProvider; 40 41 42 44 public class CreateOneSidedMappingAction extends CommandAction implements CommandStackListener 45 { 46 public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart) 47 { 48 if (editingDomain != null) 49 { 50 editingDomain.getCommandStack().removeCommandStackListener(this); 51 } 52 53 super.setActiveWorkbenchPart(workbenchPart); 54 55 if (editingDomain != null) 56 { 57 editingDomain.getCommandStack().addCommandStackListener(this); 58 } 59 } 60 61 public void commandStackChanged(EventObject event) 62 { 63 selectionChanged(action, ((ISelectionProvider)workbenchPart).getSelection()); 64 } 65 66 69 protected Object getDefaultImage() 70 { 71 return MappingPlugin.getPlugin().getImage("full/etool16/CreateOneToOneMapping"); 72 } 73 74 public static class DelegateCommand extends CommandWrapper implements CommandActionDelegate 75 { 76 protected MappingDomain mappingDomain; 77 protected Collection collection; 78 79 public DelegateCommand(EditingDomain editingDomain, CommandParameter commandParameter) 80 { 81 super(CreateMappingCommand.create((MappingDomain)editingDomain, commandParameter.getCollection())); 82 mappingDomain = (MappingDomain)editingDomain; 83 collection = commandParameter.getCollection(); 84 } 85 86 89 public Object getImage() 90 { 91 return "Placeholder"; 92 } 93 94 public String getText() 95 { 96 return getLabel(); 97 } 98 99 102 public String getToolTipText() 103 { 104 return getDescription(); 105 } 106 } 107 108 109 protected ImageDescriptor objectToImageDescriptor(Object object) 110 { 111 MappingDomain mappingDomain = (MappingDomain)editingDomain; 112 113 ((Action)action).setHoverImageDescriptor 114 (ExtendedImageRegistry.getInstance().getImageDescriptor 115 (MappingItemProvider.getImage(mappingDomain.getMappingRoot(), "full/ctool16/Create", collection, true))); 116 117 ((Action)action).setDisabledImageDescriptor 118 (ExtendedImageRegistry.getInstance().getImageDescriptor 119 (MappingItemProvider.getImage(mappingDomain.getMappingRoot(), "full/dtool16/Create", collection, true))); 120 121 ((Action)action).setEnabled(!action.isEnabled()); 122 ((Action)action).setEnabled(!action.isEnabled()); 123 124 ImageDescriptor result= 125 ExtendedImageRegistry.getInstance().getImageDescriptor 126 (MappingItemProvider.getImage(mappingDomain.getMappingRoot(), "full/etool16/Create", collection, true)); 127 128 ((Action)action).setEnabled(!action.isEnabled()); 129 ((Action)action).setImageDescriptor(result); 130 ((Action)action).setEnabled(!action.isEnabled()); 131 132 return result; 133 } 134 135 138 protected Command createActionCommand(EditingDomain editingDomain, Collection collection) 139 { 140 return editingDomain.createCommand(DelegateCommand.class, new CommandParameter(null, null, collection)); 141 } 142 } 143 | Popular Tags |