Java Code Examples for javax.swing.TransferHandler#TransferSupport

The following examples show how to use javax.swing.TransferHandler#TransferSupport . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScenarioDnD.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();
    JTable table = (JTable) support.getComponent();
    int row = dl.getRow();
    int tcRow = dl.getColumn() - 1;
    if (row == -1) {
        return false;
    }

    Scenario scenario = (Scenario) table.getModel();
    TestCase testCase = scenario.getTestCaseByName(
            table.getValueAt(row, 0).toString());

    if (dropObject instanceof TestCaseDnD) {
        putReusables(testCase, tcRow);
    } else {
        return false;
    }
    return super.importData(support);
}
 
Example 2
Source File: ProjectDnD.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private Boolean importTestCases(List<TestCaseNode> testCaseNodes,
        TransferHandler.TransferSupport ts) {
    Boolean shouldCut = ts.isDrop() ? ts.getDropAction() == MOVE : isCut;
    Object destObject = getDestinationObject(ts);
    ScenarioNode scNode = getScenarioNode(destObject);
    if (scNode != null) {
        copySelectedTestCases(testCaseNodes, scNode, shouldCut);
        return true;
    }
    if (!(destObject instanceof TestPlanNode)
            && destObject instanceof GroupNode) {
        copySelectedTestCases(testCaseNodes, (GroupNode) destObject, shouldCut);
        return true;
    }
    return false;
}
 
Example 3
Source File: JarDropHandler.java    From Cafebabe with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferHandler.TransferSupport info) {
	if (!info.isDrop())
		return false;
	Transferable t = info.getTransferable();
	List<File> data = null;
	try {
		data = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
	} catch (Exception e) {
		return false;
	}
	user.preLoadJars(id);
	for (File jar : data) {
		if (jar.getName().toLowerCase().endsWith(".jar")) {
			user.onJarLoad(id, jar);
			break;
		}
	}
	return true;
}
 
Example 4
Source File: ProjectDnD.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport ts) {
    if (ts.isDataFlavorSupported(TESTCASE_FLAVOR)) {
        try {
            TestCaseDnD testCaseDnD
                    = (TestCaseDnD) ts.getTransferable()
                    .getTransferData(TESTCASE_FLAVOR);
            sourceTreeModel = testCaseDnD.model;
            if (testCaseDnD.isTestCases()) {
                return importTestCases(testCaseDnD.getTestCaseList(), ts);
            } else {
                return importScenarios(testCaseDnD.getScenarioList(), ts);
            }

        } catch (UnsupportedFlavorException | IOException ex) {
            Logger.getLogger(ProjectDnD.class
                    .getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }
    return false;
}
 
Example 5
Source File: TableRowTransferHandler.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport info) {
    JTable target = (JTable) info.getComponent();
    JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation();
    int dropIndex = dl.getRow();
    int max = table.getModel().getRowCount();
    if (dropIndex < 0 || dropIndex > max) {
        dropIndex = max;
    }
    target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    try {
        Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor);
        if (rowFrom != -1 && rowFrom != dropIndex) {
            ((Reorderable)table.getModel()).reorder(rowFrom, dropIndex);
            if (dropIndex > rowFrom) {
                dropIndex--;
            }
            target.getSelectionModel().addSelectionInterval(dropIndex, dropIndex);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 6
Source File: FolderList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport support) {

    if (!support.isDrop()) {
        return false;
    }

    if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        return false;
    }


    boolean actionSupported = (MOVE & support.getSourceDropActions()) == MOVE;
    if (!actionSupported) {
        return false;
    }

    support.setDropAction(MOVE);
    return true;
}
 
Example 7
Source File: JarDropHandler.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferHandler.TransferSupport info) {
  if (!info.isDrop())
    return false;
  Transferable t = info.getTransferable();
  List<File> data = null;
  try {
    data = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
  } catch (Exception e) {
    return false;
  }
  user.preLoadJars(id);
  for (File jar : data) {
    if (jar.getName().toLowerCase().endsWith(".jar")) {
      user.onJarLoad(id, jar);
      break;
    }
  }
  return true;
}
 
Example 8
Source File: DragDropList.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public boolean importData(final TransferHandler.TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }

    final Transferable transferable = support.getTransferable();
    String indexString;
    try {
        indexString = (String) transferable.getTransferData(DataFlavor.stringFlavor);
    } catch (Exception ex) {
        return false;
    }

    final int index = Integer.parseInt(indexString);
    JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
    final int dropTargetIndex = dl.getIndex();

    // Drop the dragged element into the correct place.
    if (index < dropTargetIndex) {
        // If the dragged element is being dropped at a higher target index,
        // add the element at the indicated index, remove the element from the source,
        // and select the dragged element (at a different position due to the removal).
        list.model.addMyElement(dropTargetIndex, list.model.getMyElementAt(index));
        list.model.removeMyElement(index);
        list.setSelectedIndex(dropTargetIndex - 1);
    } else {
        // If the dragged element is being dropped at a lower target index,
        // remove the element from the source, add it at the indicated index,
        // and select it.
        final MyElement element = list.model.removeMyElement(index);
        list.model.addMyElement(dropTargetIndex, element);
        list.setSelectedIndex(dropTargetIndex);
    }

    return true;
}
 
Example 9
Source File: TestCaseTableDnD.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();
    JTable table = (JTable) support.getComponent();
    int row = dl.getRow();
    int column = dl.getColumn();

    if (row == -1) {
        return false;
    }

    if (dropObject instanceof ObjectRepDnD) {
        switch (column) {
            case inputColumn:
                putInput(table, row);
                break;
            case conditionColumn:
                putRelativeObject(table, row);
                break;
            default:
                putWebObjects(table, row);
                break;
        }

    } else if (dropObject instanceof TestDataDetail) {
        putTestData(table, row);
    } else if (dropObject instanceof TestCaseDnD) {
        putReusables(table, row);
    } else {
        return false;
    }
    return super.importData(support);
}
 
Example 10
Source File: InjectScript.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    if (support.getTransferable().isDataFlavorSupported(INDICES)) {
        return reorderProjects(support);
    } else {
        return dropProjects(support);
    }
}
 
Example 11
Source File: LastNodeLowerHalfDrop.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
    if (!support.isDrop()) {
        return false;
    }
    support.setShowDropLocation(true);
    if (!support.isDataFlavorSupported(nodesFlavor)) {
        return false;
    }
    // Do not allow a drop on the drag source selections.
    JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
    JTree tree = (JTree) support.getComponent();
    int dropRow = tree.getRowForPath(dl.getPath());
    int[] selRows = tree.getSelectionRows();
    for (int i = 0; i < selRows.length; i++) {
        if (selRows[i] == dropRow) {
            return false;
        }
    }
    // Do not allow MOVE-action drops if a non-leaf node is
    // selected unless all of its children are also selected.
    int action = support.getDropAction();
    if (action == MOVE) {
        return haveCompleteNode(tree);
    }
    // Do not allow a non-leaf node to be copied to a level
    // which is less than its source level.
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode target = (DefaultMutableTreeNode)
            dest.getLastPathComponent();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode)
            path.getLastPathComponent();
    if (firstNode.getChildCount() > 0
            && target.getLevel() < firstNode.getLevel()) {
        return false;
    }
    return true;
}
 
Example 12
Source File: ScriptTreeTransferHandler.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
    logger.debug("canImport " + support.getComponent().getClass().getCanonicalName());
    TransferHandler th = getTransferHandlerForSelection(support.getComponent());
    if (th != null) {
        return th.canImport(support);
    }

    return false;
}
 
Example 13
Source File: FeatureListTransferHandler.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport support) {
    if (canImport(support)) {
        return dropFeature(support);
    }
    return false;
}
 
Example 14
Source File: FileDropHandler.java    From tracker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
  if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
  		|| (OSPRuntime.isLinux()&&support.isDataFlavorSupported(uriListFlavor))) {
 	if (dropList==null && support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
 		try {
 			Transferable t = support.getTransferable();
 			dropList = getFileList(t);
 			dropComponent = support.getComponent();
 			dropComponent.getDropTarget().addDropTargetListener(dropListener);
		} catch (Exception ex) {
		} 
 	}
		boolean isImport = false;
 	if (dropList!=null && dropComponent instanceof TrackerPanel) {
     if (dropList.size()==1) {
     	File file = (File)dropList.get(0);
     	if (videoFilter.accept(file)) {
     		isImport = true;
     	}
     }
 	}
    if (!isImport) {
      support.setDropAction(TransferHandler.COPY);
    }
    return true;
  }
  return false;
}
 
Example 15
Source File: TableRowTransferHandler.java    From RobotBuilder with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
    boolean b = info.getComponent() == table && info.isDrop() && info.isDataFlavorSupported(localObjectFlavor);
    table.setCursor(b ? DragSource.DefaultMoveDrop : DragSource.DefaultMoveNoDrop);
    return b;
}
 
Example 16
Source File: SampleFractionListDisplayPane.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport info) {

    return true;
}
 
Example 17
Source File: TableRowTransferHandler.java    From PyramidShader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
    boolean b = info.getComponent() == table && info.isDrop() && info.isDataFlavorSupported(localObjectFlavor);
    table.setCursor(b ? DragSource.DefaultMoveDrop : DragSource.DefaultMoveNoDrop);
    return b;
}
 
Example 18
Source File: ZestTreeTransferHandler.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport support) {
    logger.debug("importData " + support.getComponent().getClass().getCanonicalName());

    if (!support.isDrop()) {
        return false;
    }

    JTree tree = (JTree) support.getComponent();

    ScriptNode dragNode = (ScriptNode) tree.getSelectionPath().getLastPathComponent();

    // Get drop location info.
    JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
    int childIndex = dl.getChildIndex();
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) dest.getLastPathComponent();
    boolean cut = (support.getDropAction() & MOVE) == MOVE;

    if (parent.getUserObject() == null) {
        return false;
    } else if (!(parent.getUserObject() instanceof ZestElementWrapper)
            && !(parent.getUserObject() instanceof ZestScriptWrapper)) {
        return false;
    }

    ScriptNode beforeChild = null;
    ScriptNode afterChild = null;

    if (childIndex >= 0) {
        if (childIndex == parent.getChildCount()) {
            afterChild = (ScriptNode) parent.getChildAt(childIndex - 1);
        } else {
            beforeChild = (ScriptNode) parent.getChildAt(childIndex);
        }
    }

    List<ScriptNode> nodes = new ArrayList<ScriptNode>();
    nodes.add(dragNode);

    extension.pasteToNode((ScriptNode) parent, nodes, cut, beforeChild, afterChild);
    return true;
}
 
Example 19
Source File: JarDropHandler.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
  info.setShowDropLocation(false);
  return info.isDrop() && info.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
}
 
Example 20
Source File: DnDTools.java    From wandora with GNU General Public License v3.0 votes vote down vote up
public boolean chainImportData(TransferHandler.TransferSupport support){return false;}