public String getRepositoryLocation() throws MalformedRepositoryLocationException { if (tree.getSelectionPath() != null) { Entry selectedEntry = (Entry) tree.getSelectionPath().getLastPathComponent(); RepositoryLocation selectedLocation = selectedEntry.getLocation(); if (selectedEntry instanceof Folder) { if (enforceValidRepositoryEntryName) { selectedLocation = new RepositoryLocation(selectedLocation, locationFieldRepositoryEntry.getText()); } else { selectedLocation = new RepositoryLocation(selectedLocation, locationField.getText()); } } if (RepositoryLocationChooser.this.resolveRelativeTo != null && resolveBox.isSelected()) { return selectedLocation.makeRelative(RepositoryLocationChooser.this.resolveRelativeTo); } else { return selectedLocation.getAbsoluteLocation(); } } else { if (enforceValidRepositoryEntryName) { return locationFieldRepositoryEntry.getText(); } else { return locationField.getText(); } } }
@Override public void enable() { Entry entry = tree.getSelectedEntry(); if (entry.isReadOnly()) { setEnabled(false); } else { setEnabled((Folder.class.isInstance(entry) || ProcessEntry.class.isInstance(entry))); } }
TreePath getPathTo(Entry entry) { if (entry == null) { return new TreePath(root); } if (entry.getContainingFolder() == null) { return new TreePath(root).pathByAddingChild(entry); } else { return getPathTo(entry.getContainingFolder()).pathByAddingChild(entry); } }
private TreeModelEvent makeChangeEvent(Entry entry) { TreePath path = getPathTo(entry.getContainingFolder()); int index; if (entry instanceof Repository) { index = RepositoryManager.getInstance(null).getRepositories().indexOf(entry); } else { index = getIndexOfChild(entry.getContainingFolder(), entry); } return new TreeModelEvent( RepositoryTreeModel.this, path, new int[] {index}, new Object[] {entry}); }
public void restoreExpansionState(JTree tree) { for (int i = 0; i < tree.getRowCount(); i++) { TreePath path = tree.getPathForRow(i); Object entryObject = path.getLastPathComponent(); if (entryObject instanceof Entry) { Entry entry = (Entry) entryObject; String absoluteLocation = entry.getLocation().getAbsoluteLocation(); if (expandedRepositories.contains(absoluteLocation) || expandedNodes.contains(absoluteLocation)) { tree.expandPath(path); } } } restoreSelectionPath(tree); }
public void saveExpansionState(JTree tree) { expandedNodes = new HashSet<String>(); expandedRepositories = new HashSet<String>(); saveSelectionPath(tree.getSelectionPath()); for (int i = 0; i < tree.getRowCount(); i++) { TreePath path = tree.getPathForRow(i); if (tree.isExpanded(path)) { Entry entry = (Entry) path.getLastPathComponent(); String absoluteLocation = entry.getLocation().getAbsoluteLocation(); if (entry instanceof Repository) { expandedRepositories.add(absoluteLocation); } else { expandedNodes.add(absoluteLocation); } } } }