1.1 --- a/subversion/src/org/netbeans/modules/subversion/ui/copy/BranchPicker.java Thu Oct 27 13:02:25 2011 +0200
1.2 +++ b/subversion/src/org/netbeans/modules/subversion/ui/copy/BranchPicker.java Fri Nov 04 11:17:49 2011 +0100
1.3 @@ -83,11 +83,13 @@
1.4 private static final String PREFIX_BRANCHES = "branches"; //NOI18N
1.5 private static final String PREFIX_TAGS = "tags"; //NOI18N
1.6 private SvnProgressSupport loadingSupport;
1.7 + private final String branchesFolderPrefix;
1.8
1.9 - public BranchPicker (RepositoryFile repositoryFile) {
1.10 + public BranchPicker (RepositoryFile repositoryFile, String branchesFolderPrefix) {
1.11 this.repositoryFile = repositoryFile;
1.12 + this.branchesFolderPrefix = branchesFolderPrefix;
1.13 this.panel = new BranchPickerPanel();
1.14 - this.panel.lstBranches.setCellRenderer(new Renderer());
1.15 + this.panel.lstBranches.setCellRenderer(new Renderer(branchesFolderPrefix));
1.16 }
1.17
1.18 boolean openDialog () {
1.19 @@ -144,7 +146,7 @@
1.20 return;
1.21 }
1.22 try {
1.23 - entries.put(pathName, client.getList(repositoryFile.getRepositoryUrl().appendPath(pathName), SVNRevision.HEAD, false));
1.24 + entries.put(pathName, client.getList(repositoryFile.getRepositoryUrl().appendPath(branchesFolderPrefix + pathName), SVNRevision.HEAD, false));
1.25 } catch (SVNClientException ex) {
1.26 if (SvnClientExceptionHandler.isWrongURLInRevision(ex.getMessage())) {
1.27 entries.put(pathName, new ISVNDirEntry[0]);
1.28 @@ -161,12 +163,12 @@
1.29 DefaultListModel model = new DefaultListModel();
1.30 model.addElement(ITEM_BRANCHES);
1.31 for (ISVNDirEntry e : entries.get(PREFIX_BRANCHES)) {
1.32 - model.addElement(PREFIX_BRANCHES + "/" + e.getPath()); //NOI18N
1.33 + model.addElement(branchesFolderPrefix + PREFIX_BRANCHES + "/" + e.getPath()); //NOI18N
1.34 }
1.35 model.addElement(ITEM_SEP);
1.36 model.addElement(ITEM_TAGS);
1.37 for (ISVNDirEntry e : entries.get(PREFIX_TAGS)) {
1.38 - model.addElement(PREFIX_TAGS + "/" + e.getPath()); //NOI18N
1.39 + model.addElement(branchesFolderPrefix + PREFIX_TAGS + "/" + e.getPath()); //NOI18N
1.40 }
1.41 panel.lstBranches.setModel(model);
1.42 }
1.43 @@ -177,20 +179,26 @@
1.44 }
1.45 }
1.46 };
1.47 - supp.start(Subversion.getInstance().getRequestProcessor(repositoryFile.getRepositoryUrl()), repositoryFile.getRepositoryUrl(),
1.48 + // null as the repository root prevents logging in the output window
1.49 + supp.start(Subversion.getInstance().getRequestProcessor(repositoryFile.getRepositoryUrl()), null,
1.50 NbBundle.getMessage(BranchPicker.class, "BranchPickerPanel.loading.progress")); //NOI18N
1.51 loadingSupport = supp;
1.52 }
1.53
1.54 private static class Renderer extends DefaultListCellRenderer {
1.55 + private final String branchesFolderPrefix;
1.56
1.57 + public Renderer (String branchesFolderPrefix) {
1.58 + this.branchesFolderPrefix = branchesFolderPrefix;
1.59 + }
1.60 +
1.61 @Override
1.62 public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
1.63 if (value == ITEM_BRANCHES || value == ITEM_TAGS) {
1.64 value = "<html><strong>" + value + "</strong></html>"; //NOI18N
1.65 } else {
1.66 String sValue = (String) value;
1.67 - for (String pref : new String[] { PREFIX_BRANCHES + "/", PREFIX_TAGS + "/" }) {
1.68 + for (String pref : new String[] { branchesFolderPrefix + PREFIX_BRANCHES + "/", branchesFolderPrefix + PREFIX_TAGS + "/" }) {
1.69 if (sValue.startsWith(pref)) {
1.70 value = "<html>" + pref + "<strong>" + sValue.substring(pref.length()) + "</strong></html>"; //NOI18N
1.71 }
2.1 --- a/subversion/src/org/netbeans/modules/subversion/ui/copy/CopyDialog.java Thu Oct 27 13:02:25 2011 +0200
2.2 +++ b/subversion/src/org/netbeans/modules/subversion/ui/copy/CopyDialog.java Fri Nov 04 11:17:49 2011 +0100
2.3 @@ -86,7 +86,8 @@
2.4 private DialogDescriptor dialogDescriptor;
2.5 private JButton okButton, cancelButton;
2.6 private JPanel panel;
2.7 - private static final Pattern TEMPLATE_PATTERN = Pattern.compile("^(branches|tags)/(.+?)(/.*)+$"); //NOI18N
2.8 + private static final Pattern TEMPLATE_PATTERN_BRANCH = Pattern.compile("^(.*/)*?((?:branches|tags)/(?:.+?))(/.*)+$"); //NOI18N
2.9 + private static final Pattern TEMPLATE_PATTERN_TRUNK = Pattern.compile("^(.*/)*?(trunk)(/.*)+$"); //NOI18N
2.10 private static final String BRANCHES_FOLDER = "branches"; //NOI18N
2.11 private static final String TRUNK_FOLDER = "trunk"; //NOI18N
2.12 private static final String BRANCH_TEMPLATE = "[BRANCH_NAME]"; //NOI18N
2.13 @@ -116,9 +117,6 @@
2.14 }
2.15 List<String> recentFolders = new LinkedList<String>(Utils.getStringList(SvnModuleConfig.getDefault().getPreferences(), CopyDialog.class.getName()));
2.16 Map<String, String> comboItems = setupModel(cbo, repositoryFile, recentFolders);
2.17 - SelectionListener list = new SelectionListener(repositoryFile, cbo);
2.18 - cbo.addActionListener(list);
2.19 - cbo.addPopupMenuListener(list);
2.20 cbo.setRenderer(new LocationRenderer(comboItems));
2.21 getUrlComboBoxes().add(cbo);
2.22 }
2.23 @@ -188,15 +186,17 @@
2.24 TreeMap<String, String> branchLocations = new TreeMap<String, String>(comparator);
2.25 String relativePath = SVNUrlUtils.getRelativePath(repositoryFile.getRepositoryUrl(), repositoryFile.getFileUrl());
2.26 String fileName = repositoryFile.getName();
2.27 - String pathInBranch = getPathInBranch(relativePath);
2.28 + String[] branchPathSegments = getBranchPathSegments(relativePath);
2.29 + String pathInBranch = branchPathSegments[2];
2.30 String preselectedPath = null;
2.31 for (String recentUrl : recentFolders) {
2.32 if (pathInBranch != null && branchLocations.size() < 10) {
2.33 // repository seems to have the recommended branch structure
2.34 - String branchPrefix = getBranchOrTagPrefix(recentUrl);
2.35 - if (branchPrefix != null) {
2.36 - // this is a branch or a tag, so get the branch ot tag name and build the url relevant for the given file
2.37 - String loc = branchPrefix + "/" + pathInBranch;
2.38 + String[] pathSegments = getBranchPathSegments(recentUrl);
2.39 + if (branchPathSegments[0].equals(pathSegments[0]) && !TRUNK_FOLDER.equals(pathSegments[1])) {
2.40 + // this is a branch or a tag, so get the branch or tag name and build the url relevant for the given file
2.41 + String branchPrefix = pathSegments[0] + pathSegments[1];
2.42 + String loc = branchPrefix + '/' + pathInBranch;
2.43 // we also emphasize branch/tag name in the renderer, so build the rendered string
2.44 branchLocations.put(loc, getHtmlVersion(branchPrefix, pathInBranch));
2.45 if (preselectedPath == null) {
2.46 @@ -215,8 +215,12 @@
2.47 if (pathInBranch != null) {
2.48 // now let's do some corrections
2.49 // add the single item to cat 1
2.50 - String loc = TRUNK_FOLDER + "/" + pathInBranch;
2.51 - locations.put(loc, getHtmlVersion(TRUNK_FOLDER, pathInBranch));
2.52 + String pref = TRUNK_FOLDER;
2.53 + if (branchPathSegments[0] != null) {
2.54 + pref = branchPathSegments[0] + pref;
2.55 + }
2.56 + String loc = pref + "/" + pathInBranch;
2.57 + locations.put(loc, getHtmlVersion(pref, pathInBranch));
2.58 model.add(loc);
2.59 model.add(SEP);
2.60 // add cat 2 to the model
2.61 @@ -224,15 +228,22 @@
2.62 locations.putAll(branchLocations);
2.63 model.add(MORE_BRANCHES);
2.64 if (preselectedPath == null) {
2.65 - preselectedPath = BRANCHES_FOLDER + "/" + BRANCH_TEMPLATE + "/" + pathInBranch; //NOI18N
2.66 + pref = BRANCHES_FOLDER;
2.67 + if (branchPathSegments[0] != null) {
2.68 + pref = branchPathSegments[0] + pref;
2.69 + }
2.70 + preselectedPath = pref + "/" + BRANCH_TEMPLATE + "/" + pathInBranch; //NOI18N
2.71 }
2.72 - }
2.73 - if (!model.isEmpty() && !relatedLocations.isEmpty()) {
2.74 - model.add(SEP);
2.75 + SelectionListener list = new SelectionListener(repositoryFile, cbo, branchPathSegments[0]);
2.76 + cbo.addActionListener(list);
2.77 + cbo.addPopupMenuListener(list);
2.78 }
2.79 // do not duplicate entries, so remove all items from (3) that are already in (2)
2.80 relatedLocations.keySet().removeAll(locations.keySet());
2.81 locations.putAll(relatedLocations);
2.82 + if (!model.isEmpty() && !relatedLocations.isEmpty()) {
2.83 + model.add(SEP);
2.84 + }
2.85 model.addAll(relatedLocations.keySet());
2.86
2.87 ComboBoxModel rootsModel = new DefaultComboBoxModel(model.toArray(new String[model.size()]));
2.88 @@ -242,7 +253,8 @@
2.89 comp.setText(preselectedPath);
2.90 if (pathInBranch != null) {
2.91 // select the branch name in the offered text - for easy editing
2.92 - String branchPrefix = getBranchOrTagPrefix(preselectedPath);
2.93 + String[] pathSegments = getBranchPathSegments(preselectedPath);
2.94 + String branchPrefix = pathSegments[0] + pathSegments[1];
2.95 int pos = branchPrefix.lastIndexOf('/') + 1;
2.96 if (pos > 0) {
2.97 comp.setCaretPosition(pos);
2.98 @@ -253,27 +265,36 @@
2.99 return locations;
2.100 }
2.101
2.102 - private static String getPathInBranch (String relativePath) {
2.103 + /**
2.104 + * Splits a given relative path into segments:
2.105 + * <ol>
2.106 + * <li>folder prefix where branches/tags/trunk lies in the repository. <code>null</code> for url where trunk/branches/tags are directly in the root folder</li>
2.107 + * <li>name of a branch or tag prefixed with the branches or tags prefix, or just simply "trunk" if the url is part of the trunk</li>
2.108 + * <li>path to the resource inside trunk/branch/tag</li>
2.109 + * </ol>
2.110 + * @param relativePath
2.111 + * @return
2.112 + */
2.113 + private static String[] getBranchPathSegments (String relativePath) {
2.114 + String prefix = null;
2.115 String path = null;
2.116 - Matcher m = TEMPLATE_PATTERN.matcher(relativePath);
2.117 - if (m.matches()) {
2.118 - path = m.group(3);
2.119 - if (path != null) {
2.120 - path = path.substring(1);
2.121 + String branchName = null;
2.122 + for (Pattern p : new Pattern[] { TEMPLATE_PATTERN_BRANCH, TEMPLATE_PATTERN_TRUNK}) {
2.123 + Matcher m = p.matcher(relativePath);
2.124 + if (m.matches()) {
2.125 + prefix = m.group(1);
2.126 + if (prefix == null) {
2.127 + prefix = ""; //NOI18N
2.128 + }
2.129 + branchName = m.group(2);
2.130 + path = m.group(3);
2.131 + break;
2.132 }
2.133 - } else if (relativePath.startsWith(TRUNK_FOLDER + "/")) { //NOI18N
2.134 - path = relativePath.substring(TRUNK_FOLDER.length() + 1);
2.135 }
2.136 - return path;
2.137 - }
2.138 -
2.139 - private static String getBranchOrTagPrefix (String relativePath) {
2.140 - String prefix = null;
2.141 - Matcher m = TEMPLATE_PATTERN.matcher(relativePath);
2.142 - if (m.matches()) {
2.143 - prefix = relativePath.substring(0, m.start(3));
2.144 + if (path != null) {
2.145 + path = path.substring(1);
2.146 }
2.147 - return prefix;
2.148 + return new String[] { prefix, branchName, path };
2.149 }
2.150
2.151 private static String getHtmlVersion (String branchPrefix, String relativePathInBranch) {
2.152 @@ -307,10 +328,12 @@
2.153 private final RepositoryFile repositoryFile;
2.154 private final JComboBox combo;
2.155 private boolean popupOn;
2.156 + private final String branchesFolderPath;
2.157
2.158 - public SelectionListener (RepositoryFile repositoryFile, JComboBox combo) {
2.159 + public SelectionListener (RepositoryFile repositoryFile, JComboBox combo, String branchesFolderPath) {
2.160 this.repositoryFile = repositoryFile;
2.161 this.combo = combo;
2.162 + this.branchesFolderPath = branchesFolderPath;
2.163 }
2.164
2.165 @Override
2.166 @@ -322,10 +345,10 @@
2.167 if (!popupOn && (combo.getSelectedItem() == SEP || combo.getSelectedItem() == MORE_BRANCHES)) {
2.168 String text = ""; //NOI18N
2.169 if (combo.getSelectedItem() == MORE_BRANCHES) {
2.170 - BranchPicker picker = new BranchPicker(repositoryFile);
2.171 + BranchPicker picker = new BranchPicker(repositoryFile, branchesFolderPath);
2.172 if (picker.openDialog()) {
2.173 String relativePath = SVNUrlUtils.getRelativePath(repositoryFile.getRepositoryUrl(), repositoryFile.getFileUrl());
2.174 - text = picker.getSelectedPath() + "/" + getPathInBranch(relativePath); //NOI18N
2.175 + text = picker.getSelectedPath() + "/" + getBranchPathSegments(relativePath)[2]; //NOI18N
2.176 }
2.177 }
2.178 ((JTextComponent) combo.getEditor().getEditorComponent()).setText(text); //NOI18N