1 package org.columba.mail.gui.table; 17 18 import java.awt.datatransfer.Clipboard ; 19 import java.awt.datatransfer.DataFlavor ; 20 import java.awt.datatransfer.Transferable ; 21 import java.awt.event.InputEvent ; 22 import java.util.logging.Logger ; 23 24 import javax.swing.JComponent ; 25 import javax.swing.TransferHandler ; 26 27 import org.columba.api.gui.frame.IFrameMediator; 28 import org.columba.core.command.CommandProcessor; 29 import org.columba.core.facade.DialogFacade; 30 import org.columba.mail.command.IMailFolderCommandReference; 31 import org.columba.mail.folder.IMailbox; 32 import org.columba.mail.folder.command.CopyMessageCommand; 33 import org.columba.mail.folder.command.MoveMessageCommand; 34 import org.columba.mail.gui.frame.MailFrameMediator; 35 36 44 public class TableViewTransferHandler extends TransferHandler { 45 private IFrameMediator frameController; 46 47 48 private static final Logger LOG = Logger 49 .getLogger("org.columba.mail.gui.table"); 50 51 54 private boolean isDragOperation; 55 56 60 private boolean isClipboardOperation; 61 62 65 private int action; 66 67 73 public TableViewTransferHandler(IFrameMediator cont) { 74 frameController = cont; 75 76 isDragOperation = false; 77 isClipboardOperation = false; 78 79 } 80 81 82 public boolean canImport(JComponent comp, DataFlavor [] transferFlavors) { 83 return false; 84 } 85 86 87 protected Transferable createTransferable(JComponent c) { 88 MessageReferencesTransfer transferable = null; 89 90 if (c instanceof TableView) { 91 transferable = new MessageReferencesTransfer( 92 ((MailFrameMediator) frameController).getTableSelection()); 93 94 transferable.setClipboardOperation(isClipboardOperation); 95 transferable.setDragOperation(isDragOperation); 96 transferable.setAction(action); 97 } 98 99 return transferable; 100 } 101 102 103 protected void exportDone(JComponent source, Transferable data, int action) { 104 105 110 111 117 134 135 } 136 137 138 public int getSourceActions(JComponent c) { 139 int action = TransferHandler.NONE; 140 141 if (c instanceof TableView) { 142 action = TransferHandler.COPY_OR_MOVE; 143 } 144 145 return action; 146 } 147 148 149 public boolean importData(JComponent source, Transferable transferProxy) { 150 boolean dataWasImported = false; 151 152 if (source instanceof TableView) { 153 TableView tableView = (TableView) source; 154 155 try { 156 DataFlavor [] dataFlavors = transferProxy 157 .getTransferDataFlavors(); 158 159 for (int i = 0; (i < dataFlavors.length) && (!dataWasImported); i++) { 160 if (dataFlavors[i].equals(MessageReferencesTransfer.FLAVOR)) { 161 MessageReferencesTransfer messageTransferable = (MessageReferencesTransfer) transferProxy 162 .getTransferData(MessageReferencesTransfer.FLAVOR); 163 dataWasImported = importMessageReferences(tableView, 164 messageTransferable); 165 } 166 } 167 } catch (Exception e) { DialogFacade.showExceptionDialog(e); 169 } 170 } 171 172 return dataWasImported; 173 } 174 175 186 private boolean importMessageReferences(TableView tableView, 187 MessageReferencesTransfer transferable) { 188 boolean dataWasImported = false; 189 190 196 IMailbox destFolder = (IMailbox) ((MailFrameMediator) frameController) 197 .getTableSelection().getSourceFolder(); 198 202 203 IMailFolderCommandReference result = transferable.getFolderReferences(); 204 result.setDestinationFolder(destFolder); 205 206 if (transferable.getAction() == TransferHandler.MOVE) { 207 MoveMessageCommand command = new MoveMessageCommand(result); 209 CommandProcessor.getInstance().addOp(command); 210 } else { 211 CopyMessageCommand command = new CopyMessageCommand(result); 213 CommandProcessor.getInstance().addOp(command); 214 } 215 dataWasImported = true; 216 217 return dataWasImported; 218 } 219 220 226 public void exportAsDrag(JComponent comp, InputEvent e, int action) { 227 this.isDragOperation = true; 228 this.action = action; 229 230 super.exportAsDrag(comp, e, action); 231 } 232 233 240 public void exportToClipboard(JComponent comp, Clipboard clip, int action) 241 throws IllegalStateException { 242 243 this.isClipboardOperation = true; 244 this.action = action; 245 246 if (action == TransferHandler.MOVE) { 247 LOG 248 .info("Selected messages will be moved, when selecting \"Paste\""); 249 frameController 250 .fireStatusMessageChanged("Selected messages will be moved, when selecting \"Paste\""); 251 } else if (action == TransferHandler.COPY) { 252 LOG 253 .info("Selected messages will be copied, when selecting \"Paste\""); 254 frameController 255 .fireStatusMessageChanged("Selected messages will be copied, when selecting \"Paste\""); 256 } 257 258 super.exportToClipboard(comp, clip, action); 259 } 260 } | Popular Tags |