1 26 package org.nightlabs.editor2d.actions; 27 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.eclipse.gef.commands.CompoundCommand; 32 import org.eclipse.jface.util.IPropertyChangeListener; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.ui.actions.ActionFactory; 35 import org.nightlabs.editor2d.AbstractEditor; 36 import org.nightlabs.editor2d.DrawComponent; 37 import org.nightlabs.editor2d.EditorPlugin; 38 import org.nightlabs.editor2d.command.CloneDrawComponentCommand; 39 40 43 public class PasteAction 44 extends AbstractEditorAction 45 { 46 public static final String ID = ActionFactory.PASTE.getId(); 48 49 52 public PasteAction(AbstractEditor part) { 53 super(part); 54 } 55 56 60 public PasteAction(AbstractEditor part, int style) { 61 super(part, style); 62 } 63 64 protected void init() 65 { 66 super.init(); 67 setText(EditorPlugin.getResourceString("action.paste.text")); 68 setToolTipText(EditorPlugin.getResourceString("action.paste.tooltip")); 69 setId(ID); 70 setActionDefinitionId(ID); 71 setAccelerator(SWT.CTRL | 'P'); 72 } 73 74 protected boolean enabled = false; 75 protected boolean calculateEnabled() { 76 return enabled; 77 } 78 79 protected boolean copy = false; 80 protected boolean cut = false; 81 82 protected List clipBoardContent = null; 83 public void run() 84 { 85 CompoundCommand cmd = new CompoundCommand(); 86 if (clipBoardContent != null) 87 { 88 for (Iterator it = clipBoardContent.iterator(); it.hasNext(); ) 89 { 90 DrawComponent dc = (DrawComponent) it.next(); 91 CloneDrawComponentCommand cloneCmd = new CloneDrawComponentCommand(dc, getCurrentLayer()); 92 if (copy) 93 cloneCmd.setCloneName(dc.getName() + getCopyString()); 94 if (cut) 95 cloneCmd.setCloneName(dc.getName()); 96 cmd.add(cloneCmd); 97 } 98 execute(cmd); 99 } 100 } 101 102 public IPropertyChangeListener copyListener = new IPropertyChangeListener() 103 { 104 public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) 105 { 106 if (event.getProperty().equals(EditorActionConstants.PROP_COPY_TO_CLIPBOARD)) 107 { 108 copy = true; 109 cut = false; 110 Object content = event.getNewValue(); 111 if (!content.equals(EditorActionConstants.EMPTY_CLIPBOARD_CONTENT)) 112 { 113 enabled = true; 114 if (content instanceof List ) 115 { 116 clipBoardContent = (List ) content; 117 } 118 } 119 } 120 } 121 }; 122 123 public IPropertyChangeListener cutListener = new IPropertyChangeListener() 124 { 125 public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) 126 { 127 if (event.getProperty().equals(EditorActionConstants.PROP_COPY_TO_CLIPBOARD)) 128 { 129 cut = true; 130 copy = false; 131 Object content = event.getNewValue(); 132 if (!content.equals(EditorActionConstants.EMPTY_CLIPBOARD_CONTENT)) 133 { 134 enabled = true; 135 if (content instanceof List ) 136 { 137 clipBoardContent = (List ) content; 138 } 139 } 140 } 141 } 142 }; 143 144 protected String getCopyString() 145 { 146 return " ("+EditorPlugin.getResourceString("action.copy.text")+")"; 147 } 148 } 149 | Popular Tags |