Esempio n. 1
0
  /* (non-Javadoc)
   * @see javax.swing.TransferHandler#importData(javax.swing.TransferHandler.TransferSupport)
   */
  @Override
  public boolean importData(TransferSupport support) {
    try {
      if (support.getComponent() instanceof JTree) {
        JTree tree = (JTree) support.getComponent();
        Point dropPoint = support.getDropLocation().getDropPoint();
        TreePath path = tree.getPathForLocation(dropPoint.x, dropPoint.y);
        Object node = path.getLastPathComponent();
        if (support.isDataFlavorSupported(ProcessVar.PvDataFlavors[0])) {
          ProcessVar tVar = (ProcessVar) ((PvTreeNode) node).getUserObject();
          ProcessVar chldPv =
              (ProcessVar) support.getTransferable().getTransferData(ProcessVar.PvDataFlavors[0]);

          Object chldKey = chldPv.getKeyValue();
          tVar.put(chldKey, chldPv, PvChangeEvent.PV_ADDED);
          DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
          model.nodeStructureChanged((TreeNode) model.getRoot());
          return true;
        }
      }
    } catch (UnsupportedFlavorException e) {
      ProcessVar.log.error(this.toString() + ":" + e.getMessage());
    } catch (IOException e) {
      ProcessVar.log.error(this.toString() + ":" + e.getMessage());
    }
    // anything else is handled by superclass
    return super.importData(support);
  }
Esempio n. 2
0
 /* (non-Javadoc)
  * @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
  */
 @Override
 protected void exportDone(JComponent c, Transferable t, int action) {
   try {
     if (action == MOVE) {
       ProcessVar pv = (ProcessVar) t.getTransferData(ProcessVar.PvDataFlavors[0]);
       pv.firePvChanged(
           new PvChangeEvent(pv, pv.getKeyAttribute(), pv, PvChangeEvent.PV_ELIMINATED));
     }
   } catch (UnsupportedFlavorException e) {
     ProcessVar.log.error(this.toString() + ":" + e.getMessage());
   } catch (IOException e) {
     ProcessVar.log.error(this.toString() + ":" + e.getMessage());
   }
 }
Esempio n. 3
0
  /**
   * Handle a data transfer into the tree - this can be initiated via dnd or directly. @@TODO DnD -
   * it works but is all messed up and needs doing PROPERLY.
   */
  public boolean doTransfer(Transferable t, int action) {
    try {
      log.debug(t.getTransferDataFlavors()[0]);

      if (t.getTransferDataFlavors()[0].isMimeTypeEqual("application/x-java-file-list")) {
        return doJavaFileTransfer((List) t.getTransferData(DataFlavor.javaFileListFlavor));

      } else {
        return doLocalTransfer(t, action);
      }
    } catch (UnsupportedFlavorException e) {
      log.error(e.getMessage(), e);
    } catch (IOException e) {
      log.error(e.getMessage(), e);
    }

    return false;
  }
Esempio n. 4
0
  public boolean importData(JComponent comp, Transferable tr) {
    // if (log.isDebugEnabled()) log.debug("DnDStringImportHandler.importData ");
    DataFlavor[] flavors = tr.getTransferDataFlavors();

    if (!canImport(comp, flavors)) {
      return false;
    }

    try {
      String data = (String) tr.getTransferData(DataFlavor.stringFlavor);
      JTextField field = (JTextField) comp;
      field.setText(data);
      // Notify listeners drop happened
      field.firePropertyChange("DnDrop", 0, 1);
      return true;
    } catch (UnsupportedFlavorException ufe) {
      log.warn("DnDStringImportHandler.importData: " + ufe.getMessage());
    } catch (IOException ioe) {
      log.warn("DnDStringImportHandler.importData: " + ioe.getMessage());
    }
    return false;
  }