Search in sources :

Example 16 with MLinkController

use of org.freeplane.features.link.mindmapmode.MLinkController in project freeplane by freeplane.

the class MNodeDropListener method drop.

public void drop(final DropTargetDropEvent dtde) {
    try {
        final MainView mainView = (MainView) dtde.getDropTargetContext().getComponent();
        final NodeView targetNodeView = mainView.getNodeView();
        final MapView mapView = targetNodeView.getMap();
        mapView.select();
        final NodeModel targetNode = targetNodeView.getModel();
        final Controller controller = Controller.getCurrentController();
        int dropAction = getDropAction(dtde);
        final Transferable t = dtde.getTransferable();
        mainView.setDraggedOver(NodeView.DRAGGED_OVER_NO);
        mainView.repaint();
        if (dtde.isLocalTransfer() && !isDropAcceptable(dtde, dropAction)) {
            dtde.rejectDrop();
            return;
        }
        final boolean dropAsSibling = mainView.dropAsSibling(dtde.getLocation().getX());
        ModeController modeController = controller.getModeController();
        final MMapController mapController = (MMapController) modeController.getMapController();
        if ((dropAction == DnDConstants.ACTION_MOVE || dropAction == DnDConstants.ACTION_COPY)) {
            final NodeModel parent = dropAsSibling ? targetNode.getParentNode() : targetNode;
            if (!mapController.isWriteable(parent)) {
                dtde.rejectDrop();
                final String message = TextUtils.getText("node_is_write_protected");
                UITools.errorMessage(message);
                return;
            }
        }
        final boolean isLeft = mainView.dropLeft(dtde.getLocation().getX());
        if (!dtde.isLocalTransfer()) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY);
            ((MClipboardController) ClipboardController.getController()).paste(t, targetNode, dropAsSibling, isLeft, dropAction);
            dtde.dropComplete(true);
            return;
        }
        dtde.acceptDrop(dropAction);
        if (dropAction == DnDConstants.ACTION_LINK) {
            int yesorno = JOptionPane.YES_OPTION;
            if (controller.getSelection().size() >= 5) {
                yesorno = JOptionPane.showConfirmDialog(controller.getViewController().getCurrentRootComponent(), TextUtils.getText("lots_of_links_warning"), Integer.toString(controller.getSelection().size()) + " links to the same node", JOptionPane.YES_NO_OPTION);
            }
            if (yesorno == JOptionPane.YES_OPTION) {
                for (final NodeModel sourceNodeModel : getNodeObjects(t)) {
                    ((MLinkController) LinkController.getController(modeController)).addConnector(sourceNodeModel, targetNode);
                }
            }
        } else {
            final Collection<NodeModel> selecteds = mapController.getSelectedNodes();
            if (DnDConstants.ACTION_MOVE == dropAction && isFromSameMap(dtde)) {
                final NodeModel[] array = selecteds.toArray(new NodeModel[selecteds.size()]);
                moveNodes(mapController, targetNode, t, dropAsSibling, isLeft);
                if (dropAsSibling || !targetNodeView.isFolded())
                    controller.getSelection().replaceSelection(array);
                else
                    controller.getSelection().selectAsTheOnlyOneSelected(targetNode);
            } else if (DnDConstants.ACTION_COPY == dropAction || DnDConstants.ACTION_MOVE == dropAction) {
                ((MClipboardController) ClipboardController.getController()).paste(t, targetNode, dropAsSibling, isLeft);
                controller.getSelection().selectAsTheOnlyOneSelected(targetNode);
            }
        }
    } catch (final Exception e) {
        LogUtils.severe("Drop exception:", e);
        dtde.dropComplete(false);
        return;
    }
    dtde.dropComplete(true);
}
Also used : MainView(org.freeplane.view.swing.map.MainView) MMapController(org.freeplane.features.map.mindmapmode.MMapController) Transferable(java.awt.datatransfer.Transferable) ModeController(org.freeplane.features.mode.ModeController) NodeView(org.freeplane.view.swing.map.NodeView) ClipboardController(org.freeplane.features.clipboard.ClipboardController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LinkController(org.freeplane.features.link.LinkController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MClipboardController(org.freeplane.features.clipboard.mindmapmode.MClipboardController) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MClipboardController(org.freeplane.features.clipboard.mindmapmode.MClipboardController) MapView(org.freeplane.view.swing.map.MapView)

Aggregations

MLinkController (org.freeplane.features.link.mindmapmode.MLinkController)16 MMapController (org.freeplane.features.map.mindmapmode.MMapController)10 LinkController (org.freeplane.features.link.LinkController)8 NodeModel (org.freeplane.features.map.NodeModel)7 Controller (org.freeplane.features.mode.Controller)6 File (java.io.File)5 URI (java.net.URI)5 ModeController (org.freeplane.features.mode.ModeController)5 MTextController (org.freeplane.features.text.mindmapmode.MTextController)5 MIconController (org.freeplane.features.icon.mindmapmode.MIconController)4 MapModel (org.freeplane.features.map.MapModel)4 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)4 ResourceController (org.freeplane.core.resources.ResourceController)3 AttributeController (org.freeplane.features.attribute.AttributeController)3 MAttributeController (org.freeplane.features.attribute.mindmapmode.MAttributeController)3 ClipboardController (org.freeplane.features.clipboard.ClipboardController)3 MClipboardController (org.freeplane.features.clipboard.mindmapmode.MClipboardController)3 CloudController (org.freeplane.features.cloud.CloudController)3 MCloudController (org.freeplane.features.cloud.mindmapmode.MCloudController)3 EdgeController (org.freeplane.features.edge.EdgeController)3