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 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 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(); }
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 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(); } }); } });
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)); }
public void run() { final CategoryTreeNode category = getSelectedCategoryTreeNode(tree); if (category == null) return; final String name = showInputDialog(WindowHelper.getFrame(), format(getBundle().getString("add-category-label"), category.getName()), WindowHelper.getFrame().getTitle(), QUESTION_MESSAGE); if (trim(name) == null) return; catalogModel.addCategories(singletonList(category), singletonList(name), new Runnable() { public void run() { selectCategory(tree, catalogModel.getCategoryTreeModel().getChild(category, name)); } }); } }
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 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 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(); } }); } });
categoryNames.append(category.getName()); if (i < categories.size() - 1) categoryNames.append(", ");
getRootPane().setDefaultButton(buttonAdd); labelLabel.setText(format(RouteConverter.getBundle().getString("add-url-label"), category.getName())); textFieldDescription.setText(description); textFieldUrl.setText(url);
labelLabel.setText(format(RouteConverter.getBundle().getString("add-file-label"), categoryTreeNode.getName())); textFieldFile.setText(createReadablePath(file)); if (length != null)