PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/netbeans-7.3/mercurial/src/org/netbeans/modules/mercurial/HgModuleConfig.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 688 lines | 485 code | 94 blank | 109 comment | 79 complexity | d29ffac8b62c1c03afdf1fef0e2a014a MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.mercurial;
  45. import java.awt.Color;
  46. import java.awt.EventQueue;
  47. import java.io.IOException;
  48. import java.net.URISyntaxException;
  49. import java.util.regex.Pattern;
  50. import java.util.*;
  51. import java.util.prefs.Preferences;
  52. import java.io.File;
  53. import java.net.InetAddress;
  54. import java.util.logging.Level;
  55. import org.netbeans.modules.mercurial.config.HgConfigFiles;
  56. import org.netbeans.modules.mercurial.ui.repository.RepositoryConnection;
  57. import org.netbeans.modules.mercurial.util.HgCommand;
  58. import org.netbeans.modules.mercurial.util.HgUtils;
  59. import org.netbeans.modules.versioning.util.KeyringSupport;
  60. import org.openide.util.NbPreferences;
  61. import org.netbeans.modules.versioning.util.TableSorter;
  62. import org.netbeans.modules.versioning.util.Utils;
  63. import org.openide.DialogDisplayer;
  64. import org.openide.NotifyDescriptor;
  65. import org.openide.util.NbBundle;
  66. import org.openide.util.Utilities;
  67. /**
  68. * Stores Mercurial module configuration.
  69. *
  70. * @author Padraig O'Briain
  71. */
  72. public class HgModuleConfig {
  73. public static final String PROP_IGNORED_FILEPATTERNS = "ignoredFilePatterns"; // NOI18N
  74. public static final String PROP_COMMIT_EXCLUSIONS = "commitExclusions"; // NOI18N
  75. public static final String PROP_DEFAULT_VALUES = "defaultValues"; // NOI18N
  76. public static final String PROP_RUN_VERSION = "runVersion"; // NOI18N
  77. public static final String KEY_EXECUTABLE_BINARY = "hgExecBinary"; // NOI18N
  78. public static final String KEY_EXPORT_FILENAME = "hgExportFilename"; // NOI18N
  79. public static final String KEY_EXPORT_FOLDER = "hgExportFolder"; // NOI18N
  80. public static final String KEY_IMPORT_FOLDER = "hgImportFolder"; // NOI18N
  81. public static final String KEY_ANNOTATION_FORMAT = "annotationFormat"; // NOI18N
  82. public static final String SAVE_PASSWORD = "savePassword"; // NOI18N
  83. public static final String KEY_BACKUP_ON_REVERTMODS = "backupOnRevert"; // NOI18N
  84. public static final String KEY_SHOW_HITORY_MERGES = "showHistoryMerges"; // NOI18N
  85. private static final String KEY_SHOW_FILE_INFO = "showFileInfo"; // NOI18N
  86. private static final String AUTO_OPEN_OUTPUT_WINDOW = "autoOpenOutput"; // NOI18N
  87. private static final String CONFIRM_BEFORE_COMMIT_AFTER_MERGE = "confirmBeforeCommitAfterMerge"; //NOI18N
  88. private static final String KEY_INTERNAL_MERGE_TOOL_ENABLED = "hgmerge.internalTool.enabled"; //NOI18N
  89. private static final String PROP_EXCLUDE_NEW_FILES = "excludeNewFiles"; //NOI18N
  90. private static final String KEY_QPATCH_MESSAGE = "qpatch.message."; //NOI18N
  91. private static final String RECENT_URL = "repository.recentURL"; // NOI18N
  92. private static final String SHOW_CLONE_COMPLETED = "cloneCompleted.showCloneCompleted"; // NOI18N
  93. private static final String URL_EXP = "annotator.urlExp"; // NOI18N
  94. private static final String ANNOTATION_EXP = "annotator.annotationExp"; // NOI18N
  95. public static final String TEXT_ANNOTATIONS_FORMAT_DEFAULT = "{DEFAULT}"; // NOI18N
  96. private static final String DEFAULT_EXPORT_FILENAME = "%b_%r_%h"; // NOI18N
  97. private static final HgModuleConfig INSTANCE = new HgModuleConfig();
  98. private static final String KEY_SEARCH_ON_BRANCH = "searchOnBranch.enabled."; //NOI18N
  99. private static final String KEY_REMOVE_NEW_FILES_ON_REVERT = "removeNewFilesOnRevert"; //NOI18N
  100. private static String userName;
  101. public static HgModuleConfig getDefault() {
  102. return INSTANCE;
  103. }
  104. private Set<String> exclusions;
  105. private final Map<String, String> lastCanceledCommitMessages = new HashMap<String, String>(5);
  106. // properties ~~~~~~~~~~~~~~~~~~~~~~~~~
  107. public Preferences getPreferences() {
  108. return NbPreferences.forModule(HgModuleConfig.class);
  109. }
  110. public boolean getShowCloneCompleted() {
  111. return getPreferences().getBoolean(SHOW_CLONE_COMPLETED, true);
  112. }
  113. public Pattern [] getIgnoredFilePatterns() {
  114. return getDefaultFilePatterns();
  115. }
  116. public boolean getShowFileInfo() {
  117. return getPreferences().getBoolean(KEY_SHOW_FILE_INFO, false);
  118. }
  119. public boolean isExcludedFromCommit(String path) {
  120. return getCommitExclusions().contains(path);
  121. }
  122. /**
  123. * @param paths collection of paths, of File.getAbsolutePath()
  124. */
  125. public void addExclusionPaths(Collection<String> paths) {
  126. Set<String> exclusions = getCommitExclusions();
  127. if (exclusions.addAll(paths)) {
  128. Utils.put(getPreferences(), PROP_COMMIT_EXCLUSIONS, new ArrayList<String>(exclusions));
  129. }
  130. }
  131. /**
  132. * @param paths collection of paths, File.getAbsolutePath()
  133. */
  134. public void removeExclusionPaths(Collection<String> paths) {
  135. Set<String> exclusions = getCommitExclusions();
  136. if (exclusions.removeAll(paths)) {
  137. Utils.put(getPreferences(), PROP_COMMIT_EXCLUSIONS, new ArrayList<String>(exclusions));
  138. }
  139. }
  140. public String getExecutableBinaryPath() {
  141. return (String) getPreferences().get(KEY_EXECUTABLE_BINARY, ""); // NOI18N
  142. }
  143. public boolean getBackupOnRevertModifications() {
  144. return getPreferences().getBoolean(KEY_BACKUP_ON_REVERTMODS, true);
  145. }
  146. public void setBackupOnRevertModifications(boolean bBackup) {
  147. getPreferences().putBoolean(KEY_BACKUP_ON_REVERTMODS, bBackup);
  148. }
  149. public boolean getShowHistoryMerges() {
  150. return getPreferences().getBoolean(KEY_SHOW_HITORY_MERGES, true);
  151. }
  152. public void setShowHistoryMerges(boolean bShowMerges) {
  153. getPreferences().putBoolean(KEY_SHOW_HITORY_MERGES, bShowMerges);
  154. }
  155. public void setShowFileInfo(boolean info) {
  156. getPreferences().putBoolean(KEY_SHOW_FILE_INFO, info);
  157. }
  158. public void setExecutableBinaryPath(String path) {
  159. if(Utilities.isWindows() && path.endsWith(HgCommand.HG_COMMAND + HgCommand.HG_WINDOWS_EXE)){
  160. path = path.substring(0, path.length() - (HgCommand.HG_COMMAND + HgCommand.HG_WINDOWS_EXE).length());
  161. }else if(path.endsWith(HgCommand.HG_COMMAND)){
  162. path = path.substring(0, path.length() - HgCommand.HG_COMMAND.length());
  163. }
  164. getPreferences().put(KEY_EXECUTABLE_BINARY, path);
  165. }
  166. public String getExportFolder() {
  167. return (String) getPreferences().get(KEY_EXPORT_FOLDER, System.getProperty("user.home")); // NOI18N
  168. }
  169. public void setExportFolder(String path) {
  170. getPreferences().put(KEY_EXPORT_FOLDER, path);
  171. }
  172. public String getImportFolder() {
  173. return (String) getPreferences().get(KEY_IMPORT_FOLDER, System.getProperty("user.home")); // NOI18N
  174. }
  175. public void setImportFolder(String path) {
  176. getPreferences().put(KEY_IMPORT_FOLDER, path);
  177. }
  178. public String getExportFilename() {
  179. String str = (String) getPreferences().get(KEY_EXPORT_FILENAME, ""); // NOI18N
  180. if (str.trim().length() == 0) str = DEFAULT_EXPORT_FILENAME;
  181. return str;
  182. }
  183. public void setExportFilename(String path) {
  184. getPreferences().put(KEY_EXPORT_FILENAME, path);
  185. }
  186. public boolean getAutoOpenOutput() {
  187. return getPreferences().getBoolean(AUTO_OPEN_OUTPUT_WINDOW, true);
  188. }
  189. public void setAutoOpenOutput(boolean value) {
  190. getPreferences().putBoolean(AUTO_OPEN_OUTPUT_WINDOW, value);
  191. }
  192. public boolean getConfirmCommitAfterMerge () {
  193. return getPreferences().getBoolean(CONFIRM_BEFORE_COMMIT_AFTER_MERGE, false);
  194. }
  195. public void setConfirmCommitAfterMerge (boolean value) {
  196. getPreferences().putBoolean(CONFIRM_BEFORE_COMMIT_AFTER_MERGE, value);
  197. }
  198. /**
  199. * This method returns the username specified in $HOME/.hgrc
  200. * or /etc/mercurial/hgrc
  201. * or a default username if none is found.
  202. */
  203. public String getSysUserName() {
  204. userName = HgConfigFiles.getSysInstance().getSysUserName();
  205. if (userName.length() == 0) {
  206. String userId = System.getProperty("user.name"); // NOI18N
  207. String hostName;
  208. try {
  209. hostName = InetAddress.getLocalHost().getHostName();
  210. } catch (Exception ex) {
  211. hostName = "localhost"; //NOI18N
  212. }
  213. userName = userId + "@" + hostName; // NOI18N
  214. }
  215. return userName;
  216. }
  217. public String getSysPushPath() {
  218. return HgConfigFiles.getSysInstance().getSysPushPath();
  219. }
  220. public String getSysPullPath() {
  221. return HgConfigFiles.getSysInstance().getSysPullPath();
  222. }
  223. public void addHgkExtension() throws IOException {
  224. HgConfigFiles hcf = HgConfigFiles.getSysInstance();
  225. if (hcf.getException() == null) {
  226. hcf.setProperty("hgext.hgk", "");
  227. } else {
  228. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": Cannot set hgext.hgk property"); // NOI18N
  229. Mercurial.LOG.log(Level.INFO, null, hcf.getException());
  230. throw hcf.getException();
  231. }
  232. }
  233. public void setUserName(String name) throws IOException {
  234. HgConfigFiles hcf = HgConfigFiles.getSysInstance();
  235. if (hcf.getException() == null) {
  236. hcf.setUserName(name);
  237. } else {
  238. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": Cannot set username property"); // NOI18N
  239. Mercurial.LOG.log(Level.INFO, null, hcf.getException());
  240. throw hcf.getException();
  241. }
  242. }
  243. public Boolean isUserNameValid(String name) {
  244. if (userName == null) getSysUserName();
  245. if (name.equals(userName)) return true;
  246. return !name.trim().isEmpty();
  247. }
  248. public Boolean isExecPathValid(String name) {
  249. if (name.length() == 0) return true;
  250. File file = new File(name, HgCommand.HG_COMMAND); // NOI18N
  251. // I would like to call canExecute but that requires Java SE 6.
  252. if(file.exists() && file.isFile()) return true;
  253. if (Utilities.isWindows()) {
  254. for (String hgExecutable : HgCommand.HG_WINDOWS_EXECUTABLES) {
  255. file = new File(name, hgExecutable);
  256. if (file.exists() && file.isFile()) {
  257. return true;
  258. };
  259. }
  260. }
  261. return false;
  262. }
  263. /**
  264. *
  265. * @param file
  266. * @return null in case of a parsing error
  267. */
  268. public Properties getProperties(File file) {
  269. Properties props = new Properties();
  270. HgConfigFiles hgconfig = new HgConfigFiles(file);
  271. if (hgconfig.getException() != null) {
  272. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": cannot load configuration file"); // NOI18N
  273. Mercurial.LOG.log(Level.INFO, null, hgconfig.getException());
  274. notifyParsingError();
  275. return null;
  276. }
  277. String name = hgconfig.getUserName(false);
  278. if (name.length() == 0)
  279. name = getSysUserName();
  280. if (name.length() > 0)
  281. props.setProperty("username", name); // NOI18N
  282. else
  283. props.setProperty("username", ""); // NOI18N
  284. name = hgconfig.getDefaultPull(false);
  285. if (name.length() == 0)
  286. name = getSysPullPath();
  287. if (name.length() > 0)
  288. props.setProperty("default-pull", name); // NOI18N
  289. else
  290. props.setProperty("default-pull", ""); // NOI18N
  291. name = hgconfig.getDefaultPush(false);
  292. if (name.length() == 0)
  293. name = getSysPushPath();
  294. if (name.length() > 0)
  295. props.setProperty("default-push", name); // NOI18N
  296. else
  297. props.setProperty("default-push", ""); // NOI18N
  298. return props;
  299. }
  300. public void clearProperties(File file, String section) throws IOException {
  301. HgConfigFiles hcf = getHgConfigFiles(file);
  302. if (hcf.getException() == null) {
  303. hcf.clearProperties(section);
  304. } else {
  305. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": cannot clear properties for {0}", new File[] {file}); // NOI18N
  306. Mercurial.LOG.log(Level.INFO, null, hcf.getException());
  307. throw hcf.getException();
  308. }
  309. }
  310. public void removeProperty(File file, String section, String name) throws IOException {
  311. HgConfigFiles hcf = getHgConfigFiles(file);
  312. if (hcf.getException() == null) {
  313. hcf.removeProperty(section, name);
  314. } else {
  315. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": cannot remove property {0} for {1}", new Object[] {name, file}); // NOI18N
  316. Mercurial.LOG.log(Level.INFO, null, hcf.getException());
  317. throw hcf.getException();
  318. }
  319. }
  320. public void setProperty(File file, String name, String value) throws IOException {
  321. HgConfigFiles hcf = getHgConfigFiles(file);
  322. if (hcf.getException() == null) {
  323. hcf.setProperty(name, value);
  324. } else {
  325. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": cannot set property {0}:{1} for {2}", new Object[] {name, value, file}); // NOI18N
  326. Mercurial.LOG.log(Level.INFO, null, hcf.getException());
  327. throw hcf.getException();
  328. }
  329. }
  330. public void setProperty(File file, String section, String name, String value, boolean allowEmpty) throws IOException {
  331. HgConfigFiles hcf = getHgConfigFiles(file);
  332. if (hcf.getException() == null) {
  333. hcf.setProperty(section, name, value, allowEmpty);
  334. } else {
  335. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": cannot set property {0}:{1} for {2}", new Object[] {name, value, file}); // NOI18N
  336. Mercurial.LOG.log(Level.INFO, null, hcf.getException());
  337. throw hcf.getException();
  338. }
  339. }
  340. public void setProperty(File file, String section, String name, String value) throws IOException {
  341. HgConfigFiles hcf = getHgConfigFiles(file);
  342. if (hcf.getException() == null) {
  343. hcf.setProperty(section, name, value);
  344. } else {
  345. Mercurial.LOG.log(Level.WARNING, this.getClass().getName() + ": cannot set property {0}:{1} for {2}", new Object[] {name, value, file}); // NOI18N
  346. Mercurial.LOG.log(Level.INFO, null, hcf.getException());
  347. throw hcf.getException();
  348. }
  349. }
  350. /*
  351. * Get all properties for a particular section
  352. */
  353. public Properties getProperties(File file, String section) {
  354. return getHgConfigFiles(file).getProperties(section);
  355. }
  356. public boolean getExludeNewFiles () {
  357. return getPreferences().getBoolean(PROP_EXCLUDE_NEW_FILES, false);
  358. }
  359. public void setExcludeNewFiles (boolean excludeNewFiles) {
  360. getPreferences().putBoolean(PROP_EXCLUDE_NEW_FILES, excludeNewFiles);
  361. }
  362. private HgConfigFiles getHgConfigFiles(File file) {
  363. if (file == null) {
  364. return HgConfigFiles.getSysInstance();
  365. } else {
  366. return new HgConfigFiles(file);
  367. }
  368. }
  369. public String getAnnotationFormat() {
  370. return (String) getPreferences().get(KEY_ANNOTATION_FORMAT, getDefaultAnnotationFormat());
  371. }
  372. public String getDefaultAnnotationFormat() {
  373. return "[{" + MercurialAnnotator.ANNOTATION_STATUS + "} {" + MercurialAnnotator.ANNOTATION_FOLDER + "}]"; // NOI18N
  374. }
  375. public void setAnnotationFormat(String annotationFormat) {
  376. getPreferences().put(KEY_ANNOTATION_FORMAT, annotationFormat);
  377. }
  378. public boolean isInternalMergeToolEnabled() {
  379. return getPreferences().getBoolean(KEY_INTERNAL_MERGE_TOOL_ENABLED, true);
  380. }
  381. public void setInternalMergeToolEnabled (boolean enabled) {
  382. getPreferences().putBoolean(KEY_INTERNAL_MERGE_TOOL_ENABLED, enabled);
  383. }
  384. public boolean getSavePassword() {
  385. return getPreferences().getBoolean(SAVE_PASSWORD, true);
  386. }
  387. public void setSavePassword(boolean bl) {
  388. getPreferences().putBoolean(SAVE_PASSWORD, bl);
  389. }
  390. public void setShowCloneCompleted(boolean bl) {
  391. getPreferences().putBoolean(SHOW_CLONE_COMPLETED, bl);
  392. }
  393. public void insertRecentUrl(final RepositoryConnection rc) {
  394. Preferences prefs = getPreferences();
  395. for (String rcOldString : Utils.getStringList(prefs, RECENT_URL)) {
  396. RepositoryConnection rcOld;
  397. try {
  398. rcOld = RepositoryConnection.parse(rcOldString);
  399. } catch (URISyntaxException ex) {
  400. Mercurial.LOG.throwing(getClass().getName(),
  401. "insertRecentUrl", //NOI18N
  402. ex);
  403. continue;
  404. }
  405. if(rcOld.equals(rc)) {
  406. Utils.removeFromArray(prefs, RECENT_URL, rcOldString);
  407. }
  408. }
  409. final char[] password = rc.getUrl().getPassword();
  410. if (password != null) {
  411. Runnable outOfAWT = new Runnable() {
  412. public void run() {
  413. KeyringSupport.save(HgUtils.PREFIX_VERSIONING_MERCURIAL_URL, rc.getUrl().toHgCommandStringWithNoPassword(), password.clone(), null);
  414. }
  415. };
  416. // keyring should be called only in a background thread
  417. if (EventQueue.isDispatchThread()) {
  418. Mercurial.getInstance().getRequestProcessor().post(outOfAWT);
  419. } else {
  420. outOfAWT.run();
  421. }
  422. }
  423. Utils.insert(prefs, RECENT_URL, RepositoryConnection.getString(rc), -1);
  424. }
  425. public List<RepositoryConnection> getRecentUrls() {
  426. Preferences prefs = getPreferences();
  427. List<String> urls = Utils.getStringList(prefs, RECENT_URL);
  428. List<RepositoryConnection> ret = new ArrayList<RepositoryConnection>(urls.size());
  429. List<RepositoryConnection> withPassword = new LinkedList<RepositoryConnection>();
  430. for (String urlString : urls) {
  431. try {
  432. RepositoryConnection conn = RepositoryConnection.parse(urlString);
  433. char[] password = conn.getUrl().getPassword();
  434. if (password != null) {
  435. withPassword.add(conn);
  436. } else {
  437. ret.add(conn);
  438. }
  439. } catch (URISyntaxException ex) {
  440. Mercurial.LOG.throwing(getClass().getName(),
  441. "getRecentUrls", //NOI18N
  442. ex);
  443. }
  444. }
  445. // there's an old-style connection with password set
  446. // rewrite these connections with the new version with no password included
  447. if (withPassword.size() > 0) {
  448. for (RepositoryConnection conn : withPassword) {
  449. insertRecentUrl(conn);
  450. }
  451. return getRecentUrls();
  452. }
  453. return ret;
  454. }
  455. //public void setAnnotationExpresions(List<AnnotationExpression> exps) {
  456. // List<String> urlExp = new ArrayList<String>(exps.size());
  457. // List<String> annotationExp = new ArrayList<String>(exps.size());
  458. // int idx = 0;
  459. // for (Iterator<AnnotationExpression> it = exps.iterator(); it.hasNext();) {
  460. // idx++;
  461. // AnnotationExpression exp = it.next();
  462. // urlExp.add(exp.getUrlExp());
  463. // annotationExp.add(exp.getAnnotationExp());
  464. // }
  465. // Preferences prefs = getPreferences();
  466. // Utils.put(prefs, URL_EXP, urlExp);
  467. // Utils.put(prefs, ANNOTATION_EXP, annotationExp);
  468. //}
  469. //public List<AnnotationExpression> getAnnotationExpresions() {
  470. // Preferences prefs = getPreferences();
  471. // List<String> urlExp = Utils.getStringList(prefs, URL_EXP);
  472. // List<String> annotationExp = Utils.getStringList(prefs, ANNOTATION_EXP);
  473. // List<AnnotationExpression> ret = new ArrayList<AnnotationExpression>(urlExp.size());
  474. // for (int i = 0; i < urlExp.size(); i++) {
  475. // ret.add(new AnnotationExpression(urlExp.get(i), annotationExp.get(i)));
  476. // }
  477. // if(ret.size() < 1) {
  478. // ret = getDefaultAnnotationExpresions();
  479. // }
  480. // return ret;
  481. //}
  482. //public List<AnnotationExpression> getDefaultAnnotationExpresions() {
  483. // List<AnnotationExpression> ret = new ArrayList<AnnotationExpression>(1);
  484. // ret.add(new AnnotationExpression(".*/(branches|tags)/(.+?)/.*", "\\2")); // NOI18N
  485. // return ret;
  486. //}
  487. // TODO: persist state
  488. private TableSorter importTableSorter;
  489. private TableSorter commitTableSorter;
  490. public TableSorter getImportTableSorter() {
  491. return importTableSorter;
  492. }
  493. public void setImportTableSorter(TableSorter sorter) {
  494. importTableSorter = sorter;
  495. }
  496. public TableSorter getCommitTableSorter() {
  497. return commitTableSorter;
  498. }
  499. public void setCommitTableSorter(TableSorter sorter) {
  500. commitTableSorter = sorter;
  501. }
  502. /**
  503. * Notifies user of parsing error.
  504. */
  505. public static void notifyParsingError() {
  506. NotifyDescriptor nd = new NotifyDescriptor(
  507. NbBundle.getMessage(HgModuleConfig.class, "MSG_ParsingError"), // NOI18N
  508. NbBundle.getMessage(HgModuleConfig.class, "LBL_ParsingError"), // NOI18N
  509. NotifyDescriptor.DEFAULT_OPTION,
  510. NotifyDescriptor.ERROR_MESSAGE,
  511. new Object[]{NotifyDescriptor.OK_OPTION, NotifyDescriptor.CANCEL_OPTION},
  512. NotifyDescriptor.OK_OPTION);
  513. if (EventQueue.isDispatchThread()) {
  514. DialogDisplayer.getDefault().notify(nd);
  515. } else {
  516. DialogDisplayer.getDefault().notifyLater(nd);
  517. }
  518. }
  519. public Color getColor(String colorName, Color defaultColor) {
  520. int colorRGB = getPreferences().getInt(colorName, defaultColor.getRGB());
  521. return new Color(colorRGB);
  522. }
  523. public void setColor(String colorName, Color value) {
  524. getPreferences().putInt(colorName, value.getRGB());
  525. }
  526. public String getLastCanceledCommitMessage (String key) {
  527. String lastCanceledCommitMessage = lastCanceledCommitMessages.get(key);
  528. return lastCanceledCommitMessage == null ? "" : lastCanceledCommitMessage; //NOI18N
  529. }
  530. public void setLastCanceledCommitMessage (String key, String message) {
  531. if (message == null || message.isEmpty()) {
  532. lastCanceledCommitMessages.remove(key);
  533. } else {
  534. lastCanceledCommitMessages.put(key, message);
  535. }
  536. }
  537. public String getLastUsedQPatchMessage (String patchName) {
  538. return getPreferences().get(KEY_QPATCH_MESSAGE + patchName, ""); //NOI18N
  539. }
  540. public void setLastUsedQPatchMessage (String patchName, String message) {
  541. if (message == null) {
  542. getPreferences().remove(KEY_QPATCH_MESSAGE + patchName);
  543. } else {
  544. getPreferences().put(KEY_QPATCH_MESSAGE + patchName, message);
  545. }
  546. }
  547. public boolean isSearchOnBranchEnabled (String branchName) {
  548. return getPreferences().getBoolean(KEY_SEARCH_ON_BRANCH + branchName, true);
  549. }
  550. public void setSearchOnBranchEnabled (String branchName, boolean enabled) {
  551. getPreferences().putBoolean(KEY_SEARCH_ON_BRANCH + branchName, enabled);
  552. }
  553. public boolean isRemoveNewFilesOnRevertModifications () {
  554. return getPreferences().getBoolean(KEY_REMOVE_NEW_FILES_ON_REVERT, true);
  555. }
  556. public void setRemoveNewFilesOnRevertModifications (boolean flag) {
  557. getPreferences().putBoolean(KEY_REMOVE_NEW_FILES_ON_REVERT, flag);
  558. }
  559. synchronized Set<String> getCommitExclusions() {
  560. if (exclusions == null) {
  561. exclusions = new HashSet<String>(Utils.getStringList(getPreferences(), PROP_COMMIT_EXCLUSIONS));
  562. }
  563. return exclusions;
  564. }
  565. // private methods ~~~~~~~~~~~~~~~~~~
  566. private static Pattern[] getDefaultFilePatterns() {
  567. return new Pattern [] {
  568. Pattern.compile("cvslog\\..*"), // NOI18N
  569. Pattern.compile("\\.make\\.state"), // NOI18N
  570. Pattern.compile("\\.nse_depinfo"), // NOI18N
  571. Pattern.compile(".*~"), // NOI18N
  572. Pattern.compile("#.*"), // NOI18N
  573. Pattern.compile("\\.#.*"), // NOI18N
  574. Pattern.compile(",.*"), // NOI18N
  575. Pattern.compile("_\\$.*"), // NOI18N
  576. Pattern.compile(".*\\$"), // NOI18N
  577. Pattern.compile(".*\\.old"), // NOI18N
  578. Pattern.compile(".*\\.bak"), // NOI18N
  579. Pattern.compile(".*\\.BAK"), // NOI18N
  580. Pattern.compile(".*\\.orig"), // NOI18N
  581. Pattern.compile(".*\\.rej"), // NOI18N
  582. Pattern.compile(".*\\.del-.*"), // NOI18N
  583. Pattern.compile(".*\\.a"), // NOI18N
  584. Pattern.compile(".*\\.olb"), // NOI18N
  585. Pattern.compile(".*\\.o"), // NOI18N
  586. Pattern.compile(".*\\.obj"), // NOI18N
  587. Pattern.compile(".*\\.so"), // NOI18N
  588. Pattern.compile(".*\\.exe"), // NOI18N
  589. Pattern.compile(".*\\.Z"), // NOI18N
  590. Pattern.compile(".*\\.elc"), // NOI18N
  591. Pattern.compile(".*\\.ln"), // NOI18N
  592. };
  593. }
  594. }