public void run() throws IOException { for (int i = 0; i < categories.size(); i++) { CategoryTreeNode category = categories.get(i); CategoryTreeNode parent = parents.get(i); if (category.isLocal() && parent.isRemote()) throw new IOException("cannot move local category " + category.getName() + " to remote parent " + parent.getName()); if (category.isRemote() && parent.isLocal()) throw new IOException("cannot move remote category " + category.getName() + " to local parent " + parent.getName()); category.getCategory().update(parent.getCategory(), category.getCategory().getName()); } invokeLater(new Runnable() { public void run() { for (int i = 0; i < categories.size(); i++) { CategoryTreeNode category = categories.get(i); CategoryTreeNode parent = parents.get(i); categoryTreeModel.removeNodeFromParent(category); categoryTreeModel.insertNodeInto(category, parent, 0); } if (invokeLaterRunnable != null) invokeLaterRunnable.run(); } }); } });
private static CategoryTreeNode getSubCategory(CategoryTreeNode node, String name) { for (int i = 0; i < node.getChildCount(); i++) { CategoryTreeNode child = (CategoryTreeNode) node.getChildAt(i); if (child.getName().equals(name) || child.isLocalRoot() && LOCAL.equals(name) || child.isRemoteRoot() && REMOTE.equals(name)) return child; } return null; }
public static List<CategoryTreeNode> asParents(List<CategoryTreeNode> categories) { List<CategoryTreeNode> parents = new ArrayList<>(categories.size()); for (CategoryTreeNode categoryTreeNode : categories) { parents.add((CategoryTreeNode) categoryTreeNode.getParent()); } return parents; }
public void run() throws IOException { if (category.isLocalRoot() || category.isRemoteRoot()) throw new IOException("cannot rename category root"); category.getCategory().update(null, name); invokeLater(new Runnable() { public void run() { categoryTreeModel.nodeChanged(category); } }); } });
public static String toString(TreePath treePath) { StringBuilder buffer = new StringBuilder(); for (Object pathElement : treePath.getPath()) { CategoryTreeNode treeNode = (CategoryTreeNode) pathElement; String nodeName = treeNode.getName(); if (treeNode.isLocalRoot()) buffer.append(LOCAL); else if (treeNode.isRemoteRoot()) buffer.append(REMOTE); else if (nodeName != null) buffer.append("/").append(nodeName); } return buffer.toString(); }
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (value instanceof CategoryTreeNode) { CategoryTreeNode categoryTreeNode = (CategoryTreeNode) value; String name = categoryTreeNode.getName(); if (name == null) name = RouteConverter.getBundle().getString("no-name"); else if (categoryTreeNode.isRemoteRoot()) name = RouteConverter.getBundle().getString("remote-catalog"); label.setText(name); if (categoryTreeNode.isLocal()) setClosedIcon(OPEN_ICON); else setClosedIcon(OPEN_REMOTE_ICON); setLeafIcon(getClosedIcon()); } else label.setText(RouteConverter.getBundle().getString("loading")); return label; } }
public static List<String> asNames(List<CategoryTreeNode> categories) { List<String> names = new ArrayList<>(categories.size()); for (CategoryTreeNode categoryTreeNode : categories) { names.add(categoryTreeNode.getName()); } return names; }
public boolean isLocal() { return isLocalRoot() || getParent() != null && ((CategoryTreeNode) getParent()).isLocal(); }
public boolean isRemote() { return isRemoteRoot() || getParent() != null && ((CategoryTreeNode) getParent()).isRemote(); }
public void run() throws IOException { Route route = file != null ? category.getCategory().createRoute(description, file) : category.getCategory().createRoute(description, url); final RouteModel routeModel = new RouteModel(category, route); callback.setRoute(routeModel); invokeLater(new Runnable() { public void run() { routesTableModel.addRoute(routeModel); } }); } });
public void setCurrentCategory(CategoryTreeNode category) { List<Route> routes = category.getRoutes(); List<RouteModel> routeModels = new ArrayList<>(); if (routes != null) { Route[] routesArray = routes.toArray(new Route[0]); sort(routesArray, routeComparator); for (Route route : routesArray) routeModels.add(new RouteModel(category, route)); } getRoutesTableModel().setRoutes(routeModels); }
public void run() { CategoryTreeNode category = getSelectedCategoryTreeNode(tree); if(category == null) return; if(category.isLocalRoot() || category.isRemoteRoot()) { showMessageDialog(WindowHelper.getFrame(), getBundle().getString("rename-category-cannot-rename-root"), WindowHelper.getFrame().getTitle(), ERROR_MESSAGE); return; } String name = (String) showInputDialog(WindowHelper.getFrame(), format(getBundle().getString("rename-category-label"), category.getName()), WindowHelper.getFrame().getTitle(), QUESTION_MESSAGE, null, null, category.getName()); if (trim(name) == null) return; catalogModel.renameCategory(category, name); } }
public CategoryTreeNode getChild(CategoryTreeNode parent, String name) { for (int i = 0; i < getChildCount(parent); i++) { CategoryTreeNode category = (CategoryTreeNode) getChild(parent, i); if (category.getName().equals(name)) return category; } return null; } }
public void run() throws IOException { for (int i = 0; i < parents.size(); i++) { CategoryTreeNode category = categoryTreeModel.getChild(parents.get(i), names.get(i)); if (category.isLocalRoot() || category.isRemoteRoot()) throw new IOException("cannot remove category root"); category.getCategory().delete(); } invokeLater(new Runnable() { public void run() { if (invokeLaterRunnable != null) invokeLaterRunnable.run(); for (int i = 0; i < parents.size(); i++) { CategoryTreeNode category = categoryTreeModel.getChild(parents.get(i), names.get(i)); categoryTreeModel.removeNodeFromParent(category); } } }); } });
public void run() throws IOException { final List<CategoryTreeNode> categories = new ArrayList<>(); for (int i = 0; i < parents.size(); i++) { CategoryTreeNode parent = parents.get(i); Category category = parent.getCategory().create(names.get(i)); categories.add(new CategoryTreeNodeImpl(category)); } invokeLater(new Runnable() { public void run() { for (int i = 0; i < parents.size(); i++) { CategoryTreeNode parent = parents.get(i); CategoryTreeNode category = categories.get(i); categoryTreeModel.insertNodeInto(category, parent, 0); } if (invokeLaterRunnable != null) invokeLaterRunnable.run(); } }); } });
public void run() throws IOException { for (int i = 0; i < routes.size(); i++) { RouteModel route = routes.get(i); CategoryTreeNode parent = parents.get(i); CategoryTreeNode category = route.getCategory(); if (category.isLocal() && parent.isRemote()) throw new IOException("cannot move local route " + route.getName() + " to remote parent " + parent.getName()); if (category.isRemote() && parent.isLocal()) throw new IOException("cannot move remote route " + route.getName() + " to local parent " + parent.getName()); route.getRoute().update(parent.getCategory(), route.getDescription() != null ? route.getDescription() : route.getName()); } invokeLater(new Runnable() { public void run() { for (CategoryTreeNode parent : parents) { setCurrentCategory(parent); } if (invokeLaterRunnable != null) invokeLaterRunnable.run(); } }); } });
CategoryTreeNode category = categories.get(i); if(category.isLocalRoot() || category.isRemoteRoot()) { showMessageDialog(WindowHelper.getFrame(), getBundle().getString("delete-category-cannot-delete-root"), WindowHelper.getFrame().getTitle(), categoryNames.append(category.getName()); if (i < categories.size() - 1) categoryNames.append(", ");
void renameCategory(CategoryTreeNode category, String newName, boolean trackUndo) { String oldName = category.getName(); delegate.renameCategory(category, newName); if (trackUndo) undoManager.addEdit(new RenameCategory(this, category, oldName, newName)); }
private void addFilesToCatalog(CategoryTreeNode category, List<File> files) { if (category == null || category.getParent() == null) { RouteConverter r = RouteConverter.getInstance(); showMessageDialog(r.getFrame(), r.getContext().getBundle().getString("add-file-category-missing"), r.getFrame().getTitle(), ERROR_MESSAGE); return; } for (File file : files) { addFileToCatalog(category, file); } }