
org.xmind.core.internal.dom.WorkbookComponentRefCounter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xmindjbehaveplugin Show documentation
Show all versions of xmindjbehaveplugin Show documentation
Plugin that manages JBehave stories storage in XMind mindmap file, which allows design jBehave tests right after the brainstorm
The newest version!
/* ******************************************************************************
* Copyright (c) 2006-2012 XMind Ltd. and others.
*
* This file is a part of XMind 3. XMind releases 3 and
* above are dual-licensed under the Eclipse Public License (EPL),
* which is available at http://www.eclipse.org/legal/epl-v10.html
* and the GNU Lesser General Public License (LGPL),
* which is available at http://www.gnu.org/licenses/lgpl.html
* See http://www.xmind.net/license.html for details.
*
* Contributors:
* XMind Ltd. - initial API and implementation
*******************************************************************************/
package org.xmind.core.internal.dom;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.xmind.core.IWorkbook;
import org.xmind.core.IWorkbookComponentRefManager;
import org.xmind.core.event.ICoreEventListener;
import org.xmind.core.event.ICoreEventRegistration;
import org.xmind.core.event.ICoreEventSource;
import org.xmind.core.event.ICoreEventSupport;
/**
*
* @author Frank Shaka
*/
public class WorkbookComponentRefCounter implements
IWorkbookComponentRefManager, ICoreEventSource {
private static final Collection EMPTY = Collections.emptySet();
private WorkbookImpl workbook;
private Map> source2targets;
private Map> target2sources;
public WorkbookComponentRefCounter(WorkbookImpl workbook) {
this.workbook = workbook;
}
public IWorkbook getWorkbook() {
return workbook;
}
public void increaseRef(String source, String target) {
if (source2targets == null)
source2targets = new HashMap>();
Collection targets = source2targets.get(source);
if (targets == null) {
targets = new HashSet();
source2targets.put(source, targets);
}
targets.add(target);
if (target2sources == null)
target2sources = new HashMap>();
Collection sources = target2sources.get(target);
if (sources == null) {
sources = new HashSet();
target2sources.put(target, sources);
}
sources.add(target);
}
public void decreaseRef(String source, String target) {
if (source2targets != null) {
Collection targets = source2targets.get(source);
if (targets != null) {
targets.remove(target);
if (targets.isEmpty())
source2targets.remove(source);
}
}
if (target2sources != null) {
Collection sources = target2sources.get(target);
if (sources != null) {
sources.remove(source);
if (sources.isEmpty())
target2sources.remove(target);
}
}
}
public Collection getSources() {
return source2targets == null ? EMPTY : source2targets.keySet();
}
public Collection getSources(String target) {
if (target2sources != null) {
Collection sources = target2sources.get(target);
if (sources != null)
return sources;
}
return EMPTY;
}
public Collection getTargets() {
return target2sources == null ? EMPTY : target2sources.keySet();
}
public Collection getTargets(String source) {
if (source2targets != null) {
Collection targets = source2targets.get(source);
if (targets != null)
return targets;
}
return EMPTY;
}
// protected void postIncreaseRef(String resourceId, Object resource) {
// if (this.oldValue != null) {
// Collection oldValue = this.oldValue;
// Collection newValue = new ArrayList(
// getCountedRefs());
// this.oldValue = null;
// fireValueChange(Core.ResourceRefs, oldValue, newValue);
// }
// }
//
// public void decreaseRef(String resourceId) {
// oldValue = new ArrayList(getCountedRefs());
// super.decreaseRef(resourceId);
// }
//
// protected void postDecreaseRef(String resourceId, Object resource) {
// if (this.oldValue != null) {
// Collection oldValue = this.oldValue;
// Collection newValue = new ArrayList(
// getCountedRefs());
// this.oldValue = null;
// fireValueChange(Core.ResourceRefs, oldValue, newValue);
// }
// }
public ICoreEventSupport getCoreEventSupport() {
return workbook.getCoreEventSupport();
}
public ICoreEventRegistration registerCoreEventListener(String type,
ICoreEventListener listener) {
return getCoreEventSupport().registerCoreEventListener(this, type,
listener);
}
// private void fireValueChange(String eventType, Object oldValue,
// Object newValue) {
// getCoreEventSupport().dispatchValueChange(this, eventType, oldValue,
// newValue);
// }
// public void loadTopicHyperlink() {
// List sheets = workbook.getSheets();
// for (ISheet sheet : sheets) {
// ITopic rootTopic = sheet.getRootTopic();
// loadTopic(rootTopic);
// }
// }
//
// private void loadTopic(ITopic topic) {
// String hyperlink = topic.getHyperlink();
// if (hyperlink != null && hyperlink.startsWith("xmind:#")) { //$NON-NLS-1$
// String targetId = hyperlink.substring(7);
// registryTopicLinks(targetId, topic.getId());
// }
// List children = topic.getAllChildren();
// if (children != null && !children.isEmpty()) {
// for (ITopic child : children)
// loadTopic(child);
// }
// }
//
//// public void modifyTargetLink(String oldTargetId, String newTargetId) {
//// List list = registry.get(oldTargetId);
//// if (list == null || list.isEmpty())
//// return;
//// registry.put(newTargetId, list);
//// }
//
//// public void modifyTopicLinks(String oldTargetId, String newTargetId,
//// String sourceId) {
//// if (oldTargetId == null && newTargetId != null) { //add TopicHyprelink , or change WebHyperlink/FileHyperlink to TopicHyperlink
//// registryTopicLinks(newTargetId, sourceId);
//// } else if (oldTargetId != null && newTargetId == null) {//remove TopicHyperlink , or change TopicHyperlink to WebHyperlink/FileHyperlink
//// List list = registry.get(oldTargetId);
//// if (list != null && !list.isEmpty())
//// list.remove(sourceId);
//// } else if (oldTargetId != null && newTargetId != null) {//modify TopicHyperlink (change TopicHyperlink to another TopicHyperlink)
//// List list = registry.get(oldTargetId);
//// if (list != null && !list.isEmpty())
//// list.remove(sourceId);
//// registryTopicLinks(newTargetId, sourceId);
//// }
//// }
//
// public void registryTopicLinks(String targetId, String sourceId) {
// List list = registry.get(targetId);
// if (list == null) {
// List newList = new ArrayList();
// newList.add(sourceId);
// registry.put(targetId, newList);
// } else
// list.add(sourceId);
// }
//
// public List getLinkTopics(String targetId) {
// List list = registry.get(targetId);
// if (list != null && !list.isEmpty()) {
// return toTopics(list);
// }
// return null;
// }
//
//// public void removeTopicLinks(String targetId) {
//// registry.remove(targetId);
//// }
//
// public String getOldTargetId(ITopic topic) {
// String id = topic.getId();
// for (Entry> entry : registry.entrySet()) {
// List values = entry.getValue();
// for (String value : values) {
// if (id.equals(value))
// return entry.getKey();
// }
// }
// return null;
// }
//
// public void setNewTargetId(ITopic topic, String newTargetId) {
// String oldTargetId = getOldTargetId(topic);
// String sourceId = topic.getId();
// removeTopicLink(oldTargetId, sourceId);
// if (newTargetId != null)
// registryTopicLinks(newTargetId, sourceId);
// }
//
// private void removeTopicLink(String oldTargetId, String sourceId) {
// if (registry != null) {
// List list = registry.get(oldTargetId);
// if (list != null && !list.isEmpty()) {
// list.remove(sourceId);
// }
// if (list == null || list.isEmpty())
// registry.remove(oldTargetId);
// }
// }
//
// private List toTopics(List list) {
// List topics = new ArrayList();
// for (String id : list) {
// ITopic topic = getWorkbook().findTopic(id);
// topics.add(topic);
// }
// return topics;
// }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy