use of org.cytoscape.property.bookmark.Category in project cytoscape-impl by cytoscape.
the class BookmarksUtilImpl method saveBookmark.
public void saveBookmark(Bookmarks pBookmarks, String pCategoryName, DataSource pDataSource, String pProvider) {
if (pBookmarks == null) {
pBookmarks = new Bookmarks();
}
List<Category> theCategoryList = pBookmarks.getCategory();
// if the category does not exist, create it
if (theCategoryList.size() == 0) {
Category theCategory = new Category();
theCategory.setName(pCategoryName);
theCategoryList.add(theCategory);
}
Category theCategory = getCategory(pCategoryName, theCategoryList);
if (theCategory == null) {
Category newCategory = new Category();
newCategory.setName(pCategoryName);
theCategoryList.add(newCategory);
theCategory = newCategory;
}
List<Object> theObjList = theCategory.getCategoryOrDataSource();
if (!theObjList.contains(pDataSource))
theObjList.add(pDataSource);
org.cytoscape.io.datasource.DataSource data = convertToDataSource(pBookmarks, pCategoryName, pDataSource, pProvider);
if (data != null && !dataSourceMap.containsKey(pDataSource)) {
register.registerService(data, org.cytoscape.io.datasource.DataSource.class, new Properties());
dataSourceMap.put(pDataSource, data);
}
}
use of org.cytoscape.property.bookmark.Category in project cytoscape-impl by cytoscape.
the class BookmarksUtilImpl method deleteBookmark.
/*
* (non-Javadoc)
*
* @see
* org.cytoscape.property.internal.bookmark.BookmarksUtil#deleteBookmark
* (org.cytoscape.properties.bookmark.Bookmarks, java.lang.String,
* org.cytoscape.properties.bookmark.DataSource)
*/
public boolean deleteBookmark(Bookmarks pBookmarks, String pCategoryName, DataSource pDataSource) {
org.cytoscape.io.datasource.DataSource data = null;
if (!containsBookmarks(pBookmarks, pCategoryName, pDataSource)) {
return false;
}
List<Category> theCategoryList = pBookmarks.getCategory();
Category theCategory = getCategory(pCategoryName, theCategoryList);
List<Object> theObjList = theCategory.getCategoryOrDataSource();
for (int i = 0; i < theObjList.size(); i++) {
Object obj = theObjList.get(i);
if (obj instanceof DataSource) {
DataSource theDataSource = (DataSource) obj;
if (theDataSource.getName().equalsIgnoreCase(pDataSource.getName())) {
if (dataSourceMap.containsKey(pDataSource)) {
register.unregisterService(dataSourceMap.get(pDataSource), org.cytoscape.io.datasource.DataSource.class);
dataSourceMap.remove(pDataSource);
}
theObjList.remove(i);
}
}
}
return true;
}
use of org.cytoscape.property.bookmark.Category in project cytoscape-impl by cytoscape.
the class BookmarkDataSourceBuilder method buildDataSource.
private void buildDataSource() {
final BookmarksUtil bookmarksUtil = serviceRegistrar.getService(BookmarksUtil.class);
final Bookmarks bookMarks = (Bookmarks) serviceRegistrar.getService(CyProperty.class, "(cyPropertyName=bookmarks)").getProperties();
final List<Category> categoryList = bookMarks.getCategory();
for (final Category category : categoryList) {
final DataCategory dataType = CONVERSION_MAP.get(category.getName());
if (dataType == null)
continue;
final List<DataSource> theDataSourceList = bookmarksUtil.getDataSourceList(category.getName(), categoryList);
if (theDataSourceList != null) {
for (final DataSource ds : theDataSourceList) {
final String location = ds.getHref();
final String name = ds.getName();
final String description = "From Bookmarks";
final String provider = "Example";
URL url = null;
try {
url = new URL(location);
} catch (MalformedURLException e) {
logger.warn("Bookmark file coniatin invalid URL: " + location);
continue;
}
final org.cytoscape.io.datasource.DataSource dataSource = new DefaultDataSource(name, provider, description, dataType, url);
datasourceSet.add(dataSource);
}
}
}
}
Aggregations