use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class MClipboardController method paste.
void paste(final Transferable t, final IDataFlavorHandler handler, final NodeModel target, final boolean asSibling, final boolean isLeft, int dropAction) {
if (handler == null) {
return;
}
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
if (asSibling && !mapController.isWriteable(target.getParentNode()) || !asSibling && !mapController.isWriteable(target)) {
final String message = TextUtils.getText("node_is_write_protected");
UITools.errorMessage(message);
return;
}
try {
Controller.getCurrentController().getViewController().setWaitingCursor(true);
if (newNodes == null) {
newNodes = new LinkedList<NodeModel>();
}
newNodes.clear();
handler.paste(t, target, asSibling, isLeft, dropAction);
final ModeController modeController = Controller.getCurrentModeController();
if (!asSibling && modeController.getMapController().isFolded(target) && ResourceController.getResourceController().getBooleanProperty(RESOURCE_UNFOLD_ON_PASTE)) {
modeController.getMapController().unfoldAndScroll(target);
}
for (final NodeModel child : newNodes) {
AttributeController.getController().performRegistrySubtreeAttributes(child);
}
} finally {
Controller.getCurrentController().getViewController().setWaitingCursor(false);
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class MClipboardController method processTransferable.
@SuppressWarnings("unchecked")
private void processTransferable(final Transferable transferable, final NodeModel target, Operation operation) {
try {
final Collection<NodeModel> clonedNodes;
final boolean asSingleNodes;
if (operation == Operation.CLONE && transferable.isDataFlavorSupported(MindMapNodesSelection.mindMapNodeSingleObjectsFlavor)) {
clonedNodes = (Collection<NodeModel>) transferable.getTransferData(MindMapNodesSelection.mindMapNodeSingleObjectsFlavor);
asSingleNodes = true;
} else if (transferable.isDataFlavorSupported(MindMapNodesSelection.mindMapNodeObjectsFlavor)) {
clonedNodes = (Collection<NodeModel>) transferable.getTransferData(MindMapNodesSelection.mindMapNodeObjectsFlavor);
asSingleNodes = false;
} else
return;
final List<NodeModel> movedNodes = new ArrayList<NodeModel>(clonedNodes.size());
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
for (NodeModel clonedNode : clonedNodes) {
if (clonedNode.getParentNode() == null || !clonedNode.getMap().equals(target.getMap()))
return;
if (!clonedNode.isRoot() && !clonedNode.subtreeContainsCloneOf(target)) {
switch(operation) {
case CLONE:
try {
final NodeModel clone = asSingleNodes ? clonedNode.cloneContent() : clonedNode.cloneTree();
mapController.addNewNode(clone, target, target.getChildCount(), target.isNewChildLeft());
} catch (CloneEncryptedNodeException e) {
UITools.errorMessage(TextUtils.getText("can_not_clone_encrypted_node"));
}
break;
case MOVE:
movedNodes.add(clonedNode);
break;
}
}
}
switch(operation) {
case MOVE:
mapController.moveNodesAsChildren(movedNodes, target, target.isNewChildLeft(), true);
break;
default:
break;
}
} catch (Exception e) {
LogUtils.severe(e);
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class NodeProxy method sortChildrenBy.
@Override
public void sortChildrenBy(Closure<Comparable<Object>> closure) {
getScriptContext().accessNode(getDelegate());
NodeModel node = getDelegate();
final ArrayList<NodeModel> children = new ArrayList<NodeModel>(node.getChildren());
Collections.sort(children, comparatorByClosureResult(closure));
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
int i = 0;
for (final NodeModel child : children) {
((FreeNode) Controller.getCurrentModeController().getExtension(FreeNode.class)).undoableDeactivateHook(child);
mapController.moveNode(child, i++);
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class ImportBranchAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final NodeModel parent = Controller.getCurrentModeController().getMapController().getSelectedNode();
if (parent == null) {
return;
}
final JFileChooser chooser = new JFileChooser();
final FileFilter fileFilter = ((MFileManager) UrlManager.getController()).getFileFilter();
if (fileFilter != null) {
chooser.addChoosableFileFilter(fileFilter);
}
final int returnVal = chooser.showOpenDialog(Controller.getCurrentController().getViewController().getCurrentRootComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
final MapModel map = parent.getMap();
final URL url = map.getURL();
final NodeModel node = ((MFileManager) UrlManager.getController()).loadTree(map, chooser.getSelectedFile());
map.setURL(url);
PersistentNodeHook.removeMapExtensions(node);
((MMapController) Controller.getCurrentModeController().getMapController()).insertNode(node, parent);
} catch (final Exception ex) {
UrlManager.getController().handleLoadingException(ex);
}
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class ImportExplorerFavoritesAction method importExplorerFavorites.
public boolean importExplorerFavorites(final File folder, final NodeModel target, final boolean redisplay) {
boolean favoritesFound = false;
final File[] list = folder.listFiles();
if (list != null) {
for (int i = 0; i < list.length; i++) {
if (list[i].isDirectory()) {
final String nodeContent = list[i].getName();
final NodeModel node = addNode(target, nodeContent);
final boolean favoritesFoundInSubfolder = importExplorerFavorites(list[i], node, false);
if (favoritesFoundInSubfolder) {
favoritesFound = true;
} else {
((MMapController) Controller.getCurrentModeController().getMapController()).deleteNode(node);
}
}
}
for (int i = 0; i < list.length; i++) {
if (!list[i].isDirectory() && FileUtils.getExtension(list[i]).equals("url")) {
favoritesFound = true;
BufferedReader in = null;
try {
final NodeModel node = addNode(target, FileUtils.removeExtension(list[i].getName()));
in = new BufferedReader(new FileReader(list[i]));
String line = null;
while ((line = in.readLine()) != null) {
if (line.startsWith("URL=")) {
final String link = line.substring(4);
((MLinkController) LinkController.getController()).setLink(node, LinkController.createURI(link), LinkController.LINK_ABSOLUTE);
break;
}
}
} catch (final Exception e) {
LogUtils.severe(e);
} finally {
try {
if (in != null) {
in.close();
}
} catch (final IOException e) {
LogUtils.warn(e);
}
}
}
}
}
if (redisplay) {
Controller.getCurrentModeController().getMapController().nodeChanged(target);
}
return favoritesFound;
}
Aggregations