/**
* Copyright 1999-2009 The Pegadi Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pegadi.storysketch.views;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
public class ArticleListTransferHandler extends TransferHandler {
DataFlavor rdfFlavor;
private final Logger log = LoggerFactory.getLogger(getClass());
String localRDFItemType = DataFlavor.javaJVMLocalObjectMimeType +
";class=pegadi.storysketch.views.RDFItem";
public ArticleListTransferHandler() {
try {
rdfFlavor = new DataFlavor(localRDFItemType);
} catch (ClassNotFoundException e) {
log.error("RDFTransferHandler: unable to create data flavor", e);
}
}
public boolean canImport(JComponent c, DataFlavor[] flavors) {
return true;
}
public boolean importData(JComponent c, Transferable t) {
if (canImport(c, t.getTransferDataFlavors())) {
if(c instanceof RDFTable) {
RDFTable table = (RDFTable) c;
RDFTableModel model = (RDFTableModel) table.getModel();
try {
RDFItem item = (RDFItem)t.getTransferData(rdfFlavor);
if(!model.contains(item)) {
model.addItem(item);
return true;
} else {
return false;
}
} catch (UnsupportedFlavorException ufe) {
log.error("importData: unsupported data flavor", ufe);
} catch (java.io.IOException ioe) {
log.error("importData: I/O exception", ioe);
}
}
}
return false;
}
}