/** * Returns the manager for the given documents. If <code>force</code> is <code>true</code>, any * existing conflicting managers are canceled, otherwise, the method may return <code>null</code> * if there are conflicts. * * @param documents the documents of interest * @param force whether to kill any conflicting managers * @return a manager able to cover the requested documents, or <code>null</code> if there is a * conflict and <code>force</code> was set to <code>false</code> */ public static LinkedModeManager getLinkedManager(IDocument[] documents, boolean force) { if (documents == null || documents.length == 0) return null; Set mgrs = new HashSet(); LinkedModeManager mgr = null; for (int i = 0; i < documents.length; i++) { mgr = (LinkedModeManager) fgManagers.get(documents[i]); if (mgr != null) mgrs.add(mgr); } if (mgrs.size() > 1) if (force) { for (Iterator it = mgrs.iterator(); it.hasNext(); ) { LinkedModeManager m = (LinkedModeManager) it.next(); m.closeAllEnvironments(); } } else { return null; } if (mgrs.size() == 0) mgr = new LinkedModeManager(); for (int i = 0; i < documents.length; i++) fgManagers.put(documents[i], mgr); return mgr; }
/** * Cancels any linked mode manager for the specified document. * * @param document the document whose <code>LinkedModeManager</code> should be canceled */ public static void cancelManager(IDocument document) { LinkedModeManager mgr = (LinkedModeManager) fgManagers.get(document); if (mgr != null) mgr.closeAllEnvironments(); }