Search in sources :

Example 1 with Category

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);
    }
}
Also used : Bookmarks(org.cytoscape.property.bookmark.Bookmarks) DataCategory(org.cytoscape.io.DataCategory) Category(org.cytoscape.property.bookmark.Category) Properties(java.util.Properties)

Example 2 with Category

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;
}
Also used : DataCategory(org.cytoscape.io.DataCategory) Category(org.cytoscape.property.bookmark.Category) DataSource(org.cytoscape.property.bookmark.DataSource) DefaultDataSource(org.cytoscape.io.datasource.DefaultDataSource)

Example 3 with Category

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);
            }
        }
    }
}
Also used : Bookmarks(org.cytoscape.property.bookmark.Bookmarks) DataCategory(org.cytoscape.io.DataCategory) MalformedURLException(java.net.MalformedURLException) DataCategory(org.cytoscape.io.DataCategory) Category(org.cytoscape.property.bookmark.Category) BookmarksUtil(org.cytoscape.property.bookmark.BookmarksUtil) DefaultDataSource(org.cytoscape.io.datasource.DefaultDataSource) URL(java.net.URL) DataSource(org.cytoscape.property.bookmark.DataSource) DefaultDataSource(org.cytoscape.io.datasource.DefaultDataSource)

Aggregations

DataCategory (org.cytoscape.io.DataCategory)3 Category (org.cytoscape.property.bookmark.Category)3 DefaultDataSource (org.cytoscape.io.datasource.DefaultDataSource)2 Bookmarks (org.cytoscape.property.bookmark.Bookmarks)2 DataSource (org.cytoscape.property.bookmark.DataSource)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Properties (java.util.Properties)1 BookmarksUtil (org.cytoscape.property.bookmark.BookmarksUtil)1