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.action.IAction; 25 import org.eclipse.jface.resource.ImageDescriptor; 26 import org.eclipse.jface.viewers.ISelection; 27 import org.eclipse.jface.viewers.ISelectionProvider; 28 import org.eclipse.ui.IWorkbenchPart; 29 30 import org.eclipse.emf.common.command.Command; 31 import org.eclipse.emf.common.command.CommandStackListener; 32 import org.eclipse.emf.common.command.CommandWrapper; 33 import org.eclipse.emf.edit.command.CommandActionDelegate; 34 import org.eclipse.emf.edit.command.CommandParameter; 35 import org.eclipse.emf.edit.domain.EditingDomain; 36 import org.eclipse.emf.edit.ui.action.CommandAction; 37 import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; 38 import org.eclipse.emf.mapping.MappingPlugin; 39 import org.eclipse.emf.mapping.command.CreateMappingCommand; 40 import org.eclipse.emf.mapping.domain.MappingDomain; 41 import org.eclipse.emf.mapping.presentation.IComposedSelection; 42 import org.eclipse.emf.mapping.provider.MappingItemProvider; 43 44 45 47 public class CreateMappingAction extends CommandAction implements CommandStackListener 48 { 49 public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart) 50 { 51 if (editingDomain != null) 52 { 53 editingDomain.getCommandStack().removeCommandStackListener(this); 54 } 55 56 super.setActiveWorkbenchPart(workbenchPart); 57 58 if (editingDomain != null) 59 { 60 editingDomain.getCommandStack().addCommandStackListener(this); 61 } 62 } 63 64 public void commandStackChanged(EventObject event) 65 { 66 selectionChanged(action, ((ISelectionProvider)workbenchPart).getSelection()); 67 } 68 69 public void selectionChanged(IAction action, ISelection selection) 70 { 71 if (selection instanceof IComposedSelection) 72 { 73 super.selectionChanged(action,((IComposedSelection)selection).getCombinedSelection()); 74 } 75 else 76 { 77 super.selectionChanged(action, selection); 78 } 79 } 80 81 84 protected Object getDefaultImage() 85 { 86 return MappingPlugin.getPlugin().getImage("full/etool16/CreateOneToOneMapping"); 87 } 88 89 public static class DelegateCommand extends CommandWrapper implements CommandActionDelegate 90 { 91 protected MappingDomain mappingDomain; 92 protected Collection collection; 93 94 public DelegateCommand(EditingDomain editingDomain, CommandParameter commandParameter) 95 { 96 super(CreateMappingCommand.create((MappingDomain)editingDomain, commandParameter.getCollection())); 97 mappingDomain = (MappingDomain)editingDomain; 98 collection = commandParameter.getCollection(); 99 } 100 101 104 public Object getImage() 105 { 106 return "Placeholder"; 107 } 108 109 public String getText() 110 { 111 return getLabel(); 112 } 113 114 117 public String getToolTipText() 118 { 119 return getDescription(); 120 } 121 } 122 123 protected ImageDescriptor objectToImageDescriptor(Object object) 124 { 125 MappingDomain mappingDomain = (MappingDomain)editingDomain; 126 127 ((Action)action).setHoverImageDescriptor 128 (ExtendedImageRegistry.getInstance().getImageDescriptor 129 (MappingItemProvider.getImage(mappingDomain.getMappingRoot(), "full/ctool16/Create", collection, true))); 130 131 ((Action)action).setDisabledImageDescriptor 132 (ExtendedImageRegistry.getInstance().getImageDescriptor 133 (MappingItemProvider.getImage(mappingDomain.getMappingRoot(), "full/dtool16/Create", collection, true))); 134 135 ImageDescriptor result= 136 (ExtendedImageRegistry.getInstance().getImageDescriptor 137 (MappingItemProvider.getImage(mappingDomain.getMappingRoot(), "full/etool16/Create", collection, true))); 138 139 ((Action)action).setEnabled(!action.isEnabled()); 140 ((Action)action).setImageDescriptor(result); 141 ((Action)action).setEnabled(!action.isEnabled()); 142 143 return result; 144 } 145 146 149 protected Command createActionCommand(EditingDomain editingDomain, Collection collection) 150 { 151 return editingDomain.createCommand(DelegateCommand.class, new CommandParameter(null, null, collection)); 152 } 153 } 154 | Popular Tags |