Search in sources :

Example 11 with PublicationInfo

use of org.vcell.util.document.PublicationInfo in project vcell by virtualcell.

the class VcmlOmexConverter method getMetadata.

private static String getMetadata(String vcmlName, BioModel bioModel) {
    String ret = "";
    String ns = DefaultNameSpaces.EX.uri;
    Graph graph = new HashGraph();
    Graph schema = new HashGraph();
    // recover the bioModelInfo
    // we first assume that vcml name is the model id
    BioModelInfo bioModelInfo = bioModelInfoMap.get(vcmlName);
    if (bioModelInfo == null) {
        // if not, we try based on biomodel name
        bioModelInfo = bioModelInfoMap2.get(vcmlName);
    }
    if (bioModelInfo == null) {
        // perhaps it's not public, in which case is not in the map
        // make an empty rdf file
        String description = "http://omex-library.org/" + vcmlName + ".omex";
        URI descriptionURI = ValueFactoryImpl.getInstance().createURI(description);
        graph.add(descriptionURI, RDF.TYPE, PubMet.Description);
        try {
            Map<String, String> nsMap = DefaultNameSpaces.defaultMap.convertToMap();
            ret = SesameRioUtil.writeRDFToString(graph, nsMap, RDFFormat.RDFXML);
            SesameRioUtil.writeRDFToStream(System.out, graph, nsMap, RDFFormat.RDFXML);
        } catch (RDFHandlerException e) {
            e.printStackTrace();
        }
        return ret;
    }
    PublicationInfo[] publicationInfos = bioModelInfo.getPublicationInfos();
    if (publicationInfos == null || publicationInfos.length == 0) {
        // we may not have PublicationInfo
        // make an empty rdf file
        String description = "http://omex-library.org/" + vcmlName + ".omex";
        URI descriptionURI = ValueFactoryImpl.getInstance().createURI(description);
        graph.add(descriptionURI, RDF.TYPE, PubMet.Description);
        try {
            Map<String, String> nsMap = DefaultNameSpaces.defaultMap.convertToMap();
            ret = SesameRioUtil.writeRDFToString(graph, nsMap, RDFFormat.RDFXML);
            SesameRioUtil.writeRDFToStream(System.out, graph, nsMap, RDFFormat.RDFXML);
        } catch (RDFHandlerException e) {
            e.printStackTrace();
        }
        return ret;
    }
    PublicationInfo publicationInfo = publicationInfos[0];
    String bioModelName = bioModel.getName();
    Version version = bioModelInfo.getVersion();
    String[] creators = publicationInfo.getAuthors();
    String citation = publicationInfo.getCitation();
    String doi = publicationInfo.getDoi();
    Date pubDate = publicationInfo.getPubDate();
    String pubmedid = publicationInfo.getPubmedid();
    String sTitle = publicationInfo.getTitle();
    String url = publicationInfo.getUrl();
    List<String> contributors = new ArrayList<>();
    contributors.add("Dan Vasilescu");
    contributors.add("Michael Blinov");
    contributors.add("Ion Moraru");
    // "http://omex-library.org/biomodel_12345678.omex";
    String description = "http://omex-library.org/" + vcmlName + ".omex";
    URI descriptionURI = ValueFactoryImpl.getInstance().createURI(description);
    Literal descTitle = OntUtil.createTypedString(schema, sTitle);
    // <rdf:Description rdf:about='http://omex-library.org/Monkeyflower_pigmentation_v2.omex'>
    graph.add(descriptionURI, RDF.TYPE, PubMet.Description);
    graph.add(descriptionURI, PubMet.Title, descTitle);
    try {
        Map<String, String> nsMap = DefaultNameSpaces.defaultMap.convertToMap();
        ret = SesameRioUtil.writeRDFToString(graph, nsMap, RDFFormat.RDFXML);
    // SesameRioUtil.writeRDFToStream(System.out, graph, nsMap, RDFFormat.RDFXML);
    } catch (RDFHandlerException e) {
        e.printStackTrace();
    }
    String end = "\n\n" + ret.substring(ret.indexOf(PubMet.EndDescription0));
    ret = ret.substring(0, ret.indexOf(PubMet.EndDescription0));
    ret += PubMet.CommentTaxon;
    ret += PubMet.CommentOther;
    ret += PubMet.StartIs;
    ret += PubMet.StartDescription;
    ret += PubMet.StartIdentifier;
    ret += PubMet.ResourceIdentifier;
    String isLabel = "vcell:" + version.getVersionKey();
    ret += isLabel;
    ret += PubMet.EndIdentifier;
    ret += PubMet.StartLabel;
    ret += isLabel;
    ret += PubMet.EndLabel;
    ret += PubMet.EndDescription;
    ret += PubMet.EndIs;
    ret += PubMet.StartIsDescribedBy;
    ret += PubMet.StartDescription;
    ret += PubMet.StartIdentifier;
    ret += PubMet.ResourceIdentifier;
    String pubmed = "pubmed:" + pubmedid;
    ret += pubmed;
    ret += PubMet.EndIdentifier;
    ret += PubMet.StartLabel;
    ret += pubmed;
    ret += PubMet.EndLabel;
    ret += PubMet.EndDescription;
    ret += PubMet.EndIsDescribedBy;
    ret += PubMet.CommentCreator;
    for (String creator : creators) {
        ret += PubMet.StartCreator;
        ret += PubMet.StartDescription;
        ret += PubMet.StartName;
        ret += creator;
        ret += PubMet.EndName;
        ret += PubMet.StartLabel;
        ret += creator;
        ret += PubMet.EndLabel;
        ret += PubMet.EndDescription;
        ret += PubMet.EndCreator;
    }
    ret += PubMet.CommentContributor;
    for (String contributor : contributors) {
        ret += PubMet.StartContributor;
        ret += PubMet.StartDescription;
        ret += PubMet.StartName;
        ret += contributor;
        ret += PubMet.EndName;
        ret += PubMet.StartLabel;
        ret += contributor;
        ret += PubMet.EndLabel;
        ret += PubMet.EndDescription;
        ret += PubMet.EndContributor;
    }
    ret += PubMet.CommentCitations;
    ret += PubMet.StartIsDescribedBy;
    ret += PubMet.StartDescription;
    ret += PubMet.StartIdentifier;
    ret += PubMet.ResourceIdentifier;
    String sdoi = "doi:" + doi;
    ret += sdoi;
    ret += PubMet.EndIdentifier;
    ret += PubMet.StartLabel;
    ret += citation;
    ret += PubMet.EndLabel;
    ret += PubMet.EndDescription;
    ret += PubMet.EndIsDescribedBy;
    ret += PubMet.CommentLicense;
    ret += PubMet.StartLicense;
    ret += PubMet.StartDescription;
    ret += PubMet.StartIdentifier;
    ret += PubMet.ResourceIdentifier;
    String lic = "spdx:" + "CC0-1.0";
    ret += lic;
    ret += PubMet.EndIdentifier;
    ret += PubMet.StartLabel;
    ret += "CC0-1.0";
    ret += PubMet.EndLabel;
    ret += PubMet.EndDescription;
    ret += PubMet.EndLicense;
    String sPubDate = new SimpleDateFormat("yyyy-MM-dd").format(pubDate);
    ret += PubMet.CommentCreated;
    ret += PubMet.StartCreated;
    ret += PubMet.StartDescription;
    ret += PubMet.PrefixCreated;
    ret += new SimpleDateFormat("yyyy-MM-dd").format(pubDate);
    ret += PubMet.SuffixCreated;
    ret += PubMet.EndDescription;
    ret += PubMet.EndCreated;
    Calendar calendar = Calendar.getInstance();
    Date today = calendar.getTime();
    ret += PubMet.CommentModified;
    ret += PubMet.StartModified;
    ret += PubMet.StartDescription;
    ret += PubMet.PrefixModified;
    ret += new SimpleDateFormat("yyyy-MM-dd").format(today);
    ret += PubMet.SuffixModified;
    ret += PubMet.EndDescription;
    ret += PubMet.EndModified;
    ret += end;
    System.out.println(ret);
    System.out.println("");
    return (ret);
}
Also used : PublicationInfo(org.vcell.util.document.PublicationInfo) Calendar(java.util.Calendar) BioModelInfo(org.vcell.util.document.BioModelInfo) ArrayList(java.util.ArrayList) URI(org.openrdf.model.URI) Date(java.util.Date) Graph(org.openrdf.model.Graph) HashGraph(org.sbpax.impl.HashGraph) HashGraph(org.sbpax.impl.HashGraph) RDFHandlerException(org.openrdf.rio.RDFHandlerException) Version(org.vcell.util.document.Version) Literal(org.openrdf.model.Literal) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with PublicationInfo

use of org.vcell.util.document.PublicationInfo in project vcell by virtualcell.

the class BioModelInfoCellRenderer method getTreeCellRendererComponent.

/**
 * Insert the method's description here.
 * Creation date: (7/27/2000 6:41:57 PM)
 * @return java.awt.Component
 */
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    // 
    if (!leaf && expanded) {
        setIcon(fieldFolderOpenIcon);
    } else if (!leaf && !expanded) {
        setIcon(fieldFolderClosedIcon);
    }
    try {
        if (value instanceof BioModelNode) {
            BioModelNode node = (BioModelNode) value;
            boolean bLoaded = false;
            // 
            if (node.getUserObject() instanceof String && "Geometry".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Geometry");
                component.setText(label);
                setIcon(fieldGeometryIcon);
            } else if (node.getUserObject() instanceof String && "Applications".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Applications List");
                component.setText("<html><b>" + label + "</b></html>");
                setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof String && "SimulationContext".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Application");
                component.setText(label);
                if (MathType.RuleBased.getDescription().equals(node.getRenderHint("appType"))) {
                    setIcon(VCellIcons.appRbmNonspIcon);
                } else if (MathType.Stochastic.getDescription().equals(node.getRenderHint("appType"))) {
                    if ("0".equals(node.getRenderHint("dimension"))) {
                        setIcon(VCellIcons.appStoNonspIcon);
                    } else {
                        setIcon(VCellIcons.appStoSpatialIcon);
                    }
                } else if (MathType.Deterministic.getDescription().equals(node.getRenderHint("appType"))) {
                    if ("0".equals(node.getRenderHint("dimension"))) {
                        setIcon(VCellIcons.appDetNonspIcon);
                    } else {
                        setIcon(VCellIcons.appDetSpatialIcon);
                    }
                } else {
                    // don't know what it is, use old "generic" icon
                    setIcon(fieldSimulationContextIcon);
                }
            } else if (node.getUserObject() instanceof String && "Simulation".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Simulation");
                component.setText(label);
                setIcon(fieldSimulationIcon);
            } else if (node.getUserObject() instanceof String && "AppType".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Simulation");
                component.setText(label);
                setIcon(fieldAppTypeIcon);
            } else if (node.getUserObject() instanceof String && "Provenance".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Provenance");
                component.setText("<html><b>" + label + "</b></html>");
                setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof Annotation) {
                String label = ((Annotation) node.getUserObject()).toString();
                component.setToolTipText("Version Annotation");
                component.setText(label);
                setIcon(null);
            } else if (node.getUserObject() instanceof String && "PublicationsInfo".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Publications Info");
                component.setText("<html><b>" + label + "</b></html>");
                setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoTitle".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("Title");
                String text = "<b>" + info.getTitle() + "</b>";
                component.setText("<html>" + text + "</html>");
                setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoAuthors".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("Authors");
                String text = "";
                int count = 0;
                for (String author : info.getAuthors()) {
                    if (count > 0) {
                        text += "; ";
                    }
                    text += author;
                    count++;
                }
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoCitation".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("Citation");
                String text = "";
                text += info.getCitation();
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoDoi".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("DOI");
                String text = "<a href=\"" + BeanUtils.getDynamicClientProperties().getProperty(PropertyLoader.DOI_URL) + info.getDoi() + "\">" + "DOI: " + info.getDoi() + "</a>";
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoUrl".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("PMID");
                // we know from the tree model that this is not null or empty
                String pmid = info.getUrl();
                if (pmid.contains("list_uids=")) {
                    // ex: http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&dopt=Citation&list_uids=12644446
                    pmid = pmid.substring(pmid.lastIndexOf("list_uids=") + "list_uids=".length());
                } else if (pmid.contains("pubmed/")) {
                    // ex: http://www.ncbi.nlm.nih.gov/pubmed/23093806
                    pmid = pmid.substring(pmid.lastIndexOf("/") + 1);
                } else if (pmid.contains("pubmed.ncbi")) {
                    // ex: https://pubmed.ncbi.nlm.nih.gov/34360784/
                    if (pmid.endsWith("/")) {
                        pmid = pmid.substring(0, pmid.length() - 1);
                    }
                    pmid = pmid.substring(pmid.lastIndexOf("/") + 1);
                } else {
                    // something that we don't know how to parse
                    pmid = "?";
                }
                String text = "<a href=\"" + info.getUrl() + "\">" + "PubMed PMID: " + pmid + "</a>";
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof String && "GeneralFileInfo".equals(node.getRenderHint("type"))) {
                component.setToolTipText("Database File Info");
                String text = "<b>" + (String) node.getUserObject() + "</b>";
                component.setText("<html>" + text + "</html>");
                setIcon(fieldDatabaseIcon);
            } else if (node.getUserObject() instanceof String && "ModelName".equals(node.getRenderHint("type"))) {
                component.setToolTipText("BioModel Name");
                String text = "<b>" + (String) node.getUserObject() + "</b>";
                component.setText("<html>" + text + "</html>");
            // setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof KeyValue && "VCellIdentifier".equals(node.getRenderHint("type"))) {
                component.setToolTipText("Virtual Cell Identifier");
                KeyValue key = (KeyValue) node.getUserObject();
                String text = "biomodel-" + key;
                component.setText("<html>" + text + "</html>");
                setIcon(fieldDatabaseModelKeyIcon);
            } else if (node.getUserObject() instanceof User && "ModelOwner".equals(node.getRenderHint("type"))) {
                String label = ((User) node.getUserObject()).getName();
                component.setToolTipText("Model Owner");
                component.setText("<html>" + label + "</html>");
                setIcon(fieldUserIcon);
            } else if (node.getUserObject() instanceof Date && "ModelDate".equals(node.getRenderHint("type"))) {
                Date date = (Date) node.getUserObject();
                component.setToolTipText("Last Modified");
                component.setText("<html>" + date + "</html>");
                setIcon(fieldCalendarIcon);
            } else if (node.getUserObject() instanceof String && "Permissions".equals(node.getRenderHint("type"))) {
                component.setToolTipText("Permissions");
                String text = (String) node.getUserObject();
                component.setText("<html>" + text + "</html>");
                setIcon(fieldPermissionsIcon);
            } else if (node.getUserObject() instanceof String && "Annotations".equals(node.getRenderHint("type"))) {
                // deprecated; we don't show annotation icon(s), neither for notes nor for links
                component.setToolTipText("Text Annotation");
                String text = (String) node.getUserObject();
                component.setText("<html>" + text + "</html>");
                setIcon(VCellIcons.noteIcon);
            } else {
                setComponentProperties(component, node.getUserObject());
            }
            if (selectedFont == null && component.getFont() != null) {
                selectedFont = component.getFont().deriveFont(Font.BOLD);
            }
            if (unselectedFont == null && component.getFont() != null) {
                unselectedFont = component.getFont().deriveFont(Font.PLAIN);
            }
            if (bLoaded) {
                component.setFont(selectedFont);
            } else {
                component.setFont(unselectedFont);
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    // 
    return component;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) PublicationInfo(org.vcell.util.document.PublicationInfo) JLabel(javax.swing.JLabel) Date(java.util.Date)

Example 13 with PublicationInfo

use of org.vcell.util.document.PublicationInfo in project vcell by virtualcell.

the class PublicationInfoNodeTreeModel method createVersionSubTree.

private BioModelNode createVersionSubTree(BioModelNode publicationsInfoNode) throws DataAccessException {
    BioModelNode versionNode = new BioModelNode("Root", true);
    Object uo = publicationsInfoNode.getUserObject();
    if (!(uo instanceof PublicationInfo)) {
        String title = "PublicationInfo missing";
        publicationNode = new BioModelNode(title, false);
        versionNode.add(publicationNode);
        return versionNode;
    }
    publicationNode = null;
    modelsNode = null;
    PublicationInfo pi = (PublicationInfo) uo;
    publicationNode = new BioModelNode("Publication", true);
    publicationNode.setRenderHint("type", "PublicationsInfo");
    BioModelNode piTitleNode = new BioModelNode(pi, true);
    piTitleNode.setRenderHint("type", "PublicationInfoTitle");
    publicationNode.add(piTitleNode);
    BioModelNode piAuthorsNode = new BioModelNode(pi, false);
    piAuthorsNode.setRenderHint("type", "PublicationInfoAuthors");
    piTitleNode.add(piAuthorsNode);
    BioModelNode piCitationNode = new BioModelNode(pi, false);
    piCitationNode.setRenderHint("type", "PublicationInfoCitation");
    piTitleNode.add(piCitationNode);
    BioModelNode piDoiNode = new BioModelNode(pi, false);
    piDoiNode.setRenderHint("type", "PublicationInfoDoi");
    piTitleNode.add(piDoiNode);
    if (pi.getUrl() != null && !pi.getUrl().isEmpty()) {
        if (pi.getUrl().contains("pubmed") || pi.getUrl().contains("PubMed")) {
            BioModelNode piUrlNode = new BioModelNode(pi, false);
            piUrlNode.setRenderHint("type", "PublicationInfoUrl");
            piTitleNode.add(piUrlNode);
        }
    }
    versionNode.add(publicationNode);
    String name = publicationsInfoNode.getChildCount() > 1 ? "Models" : "Model";
    modelsNode = new BioModelNode(name, true);
    modelsNode.setRenderHint("type", "ModelsList");
    for (int i = 0; i < publicationsInfoNode.getChildCount(); i++) {
        TreeNode child = publicationsInfoNode.getChildAt(i);
        if (!(child instanceof BioModelNode)) {
            versionNode.add(modelsNode);
            return versionNode;
        }
        BioModelNode modelNode = (BioModelNode) child;
        uo = modelNode.getUserObject();
        if (!(uo instanceof VCDocumentInfoNode)) {
            versionNode.add(modelsNode);
            return versionNode;
        }
        VCDocumentInfoNode din = (VCDocumentInfoNode) uo;
        Version version = din.getVCDocumentInfo().getVersion();
        BioModelNode mNameNode = new BioModelNode(version.getName(), true);
        mNameNode.setRenderHint("type", "ModelName");
        VCDocumentInfo di = din.getVCDocumentInfo();
        if (di instanceof BioModelInfo) {
            mNameNode.setRenderHint("category", "BioModel");
        } else if (di instanceof MathModelInfo) {
            mNameNode.setRenderHint("category", "MathModel");
        } else if (di instanceof GeometryInfo) {
            mNameNode.setRenderHint("category", "Geometry");
        }
        modelsNode.add(mNameNode);
        BioModelNode mOwnerNode = new BioModelNode(version.getOwner(), true);
        mOwnerNode.setRenderHint("type", "ModelOwner");
        mNameNode.add(mOwnerNode);
        BioModelNode mDateNode = new BioModelNode(version.getDate(), true);
        mDateNode.setRenderHint("type", "ModelDate");
        mNameNode.add(mDateNode);
    }
    versionNode.add(modelsNode);
    return versionNode;
}
Also used : Version(org.vcell.util.document.Version) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) PublicationInfo(org.vcell.util.document.PublicationInfo) TreeNode(javax.swing.tree.TreeNode) BioModelInfo(org.vcell.util.document.BioModelInfo) GeometryInfo(cbit.vcell.geometry.GeometryInfo) VCDocumentInfoNode(cbit.vcell.desktop.VCellBasicCellRenderer.VCDocumentInfoNode) MathModelInfo(org.vcell.util.document.MathModelInfo)

Example 14 with PublicationInfo

use of org.vcell.util.document.PublicationInfo in project vcell by virtualcell.

the class BioModelDbTreePanel method treeSelection.

/**
 * Comment
 */
protected void treeSelection() {
    TreePath treePath = getJTree1().getSelectionPath();
    if (treePath == null) {
        setSelectedVersionInfo(null);
        return;
    }
    BioModelNode bioModelNode = (BioModelNode) treePath.getLastPathComponent();
    Object object = bioModelNode.getUserObject();
    if (object instanceof PublicationInfo) {
        setSelectedVersionInfo(null);
        setSelectedPublicationInfo(bioModelNode);
    } else if (object instanceof BioModelInfo) {
        setSelectedVersionInfo((VersionInfo) object);
    } else if (object instanceof VCDocumentInfoNode && bioModelNode.getChildCount() > 0 && ((BioModelNode) bioModelNode.getChildAt(0)).getUserObject() instanceof BioModelInfo) {
        BioModelInfo bioModelInfo = (BioModelInfo) ((BioModelNode) bioModelNode.getChildAt(0)).getUserObject();
        setSelectedVersionInfo(bioModelInfo);
    } else if (object instanceof BioModelMetaData) {
        BioModelInfo bioModelInfo = (BioModelInfo) ((BioModelNode) bioModelNode.getParent()).getUserObject();
        setSelectedVersionInfo(bioModelInfo);
    } else {
        setSelectedVersionInfo(null);
    }
}
Also used : VersionInfo(org.vcell.util.document.VersionInfo) TreePath(javax.swing.tree.TreePath) PublicationInfo(org.vcell.util.document.PublicationInfo) BioModelInfo(org.vcell.util.document.BioModelInfo) VCDocumentInfoNode(cbit.vcell.desktop.VCellBasicCellRenderer.VCDocumentInfoNode) BioModelMetaData(cbit.vcell.biomodel.BioModelMetaData)

Example 15 with PublicationInfo

use of org.vcell.util.document.PublicationInfo in project vcell by virtualcell.

the class BioModelCellRenderer method getTreeCellRendererComponent.

/**
 * Insert the method's description here.
 * Creation date: (7/27/2000 6:41:57 PM)
 * @return java.awt.Component
 */
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    // 
    try {
        if (value instanceof DateNode) {
            DateNode dateNode = (DateNode) value;
            AnnotationQualifier qualifier = dateNode.getDateQualifier();
            String colorString = (sel) ? "white" : "black";
            component.setText("<html>" + qualifier.getDescription() + "&nbsp;<font color=\"" + colorString + "\">" + dateNode.getDate().getDateString() + "</font></html>");
        } else if (value instanceof LinkNode) {
            LinkNode ln = (LinkNode) value;
            String link = ln.getLink();
            String text = ln.getText();
            MIRIAMQualifier mQualifier = ln.getMiriamQualifier();
            String qualifier = "";
            if (mQualifier.equals(MIRIAMQualifier.MODEL_isDescribedBy)) {
                String colorString = (sel) ? "white" : "black";
                qualifier = "<font color=\"" + colorString + "\">" + mQualifier.getDescription() + "</font>";
            } else {
                String colorString = (sel) ? "white" : "#8B0000";
                qualifier = "<font color=\"" + colorString + "\">" + mQualifier.getDescription() + "</font>";
            }
            if (link != null) {
                String colorString = (sel) ? "white" : "blue";
                component.setToolTipText("Double-click to open link");
                component.setText("<html>" + qualifier + "&nbsp;<font color=\"" + colorString + "\"><a href=" + link + ">" + text + "</a></font></html>");
            } else {
                String colorString = (sel) ? "white" : "black";
                component.setText("<html>" + qualifier + "&nbsp;<font color=\"" + colorString + "\">" + text + "</font></html>");
            }
        } else if (value instanceof PublicationInfoNode) {
            BioModelNode node = (PublicationInfoNode) value;
            PublicationInfo pi = (PublicationInfo) node.getUserObject();
            String label = pi.getTitle();
            String name = "";
            if (pi.getAuthors() != null && pi.getAuthors().length > 0) {
                name = pi.getAuthors()[0];
            }
            if (name.contains(",")) {
                name = name.substring(0, name.indexOf(","));
            }
            int year = Integer.parseInt((new SimpleDateFormat("yyyy")).format(pi.getPubDate()));
            String label2 = name + " " + year + " " + label;
            int maxLen = MaxPublicationLabelLength + (node.getChildCount() > 1 ? 0 : 4);
            if (label2.length() > maxLen) {
                label2 = label2.substring(0, maxLen) + "...";
            }
            if (node.getChildCount() > 1) {
                String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                String suffix = sel ? "" : "</span>";
                label += prefix + " (" + node.getChildCount() + ")" + suffix;
                label2 += prefix + " (" + node.getChildCount() + ")" + suffix;
            }
            component.setText("<html>" + label2 + "</html>");
            component.setToolTipText("<html>" + label + "</html>");
            if (pi.getPubDate().compareTo(Calendar.getInstance().getTime()) > 0) {
                // sanity check
                setIcon(fieldFolderWarningIcon);
            } else if (pi.getDoi() == null) {
                setIcon(fieldFolderWarningIcon);
            } else if (name.contains(" ")) {
                setIcon(fieldFolderWarningIcon);
            } else {
                // publications have their own icon
                setIcon(fieldPublishedPublicationIcon);
            }
        } else if (value instanceof UserNameNode) {
            UserNameNode node = (UserNameNode) value;
            String label = (String) node.getUserObject();
            String qualifier = "";
            if (sessionUser != null && sessionUser.getName().contentEquals(label)) {
                String colorString = (sel) ? "white" : "#8B0000";
                qualifier = "<font color=\"" + colorString + "\"><b>" + label + "</b></font>";
            } else {
                String colorString = (sel) ? "white" : "black";
                qualifier = "<font color=\"" + colorString + "\">" + label + "</font>";
            }
            component.setToolTipText(label);
            component.setText("<html>" + qualifier + " (" + node.getChildCount() + ")" + "</html>");
            component.setIcon(fieldFolderUserIcon);
        } else if (value instanceof BioModelNode) {
            BioModelNode node = (BioModelNode) value;
            Object userObject = node.getUserObject();
            if (userObject instanceof User) {
                String label = null;
                if (sessionUser != null && sessionUser.compareEqual((User) userObject)) {
                    label = "My BioModels (" + ((User) userObject).getName() + ") (" + node.getChildCount() + ")";
                } else {
                    label = ((User) userObject).getName() + "(abcdefghijklmnopq)(000000)";
                }
                component.setToolTipText(label);
                component.setText(label);
            } else if (userObject instanceof BioModelInfo) {
                BioModelInfo biomodelInfo = (BioModelInfo) userObject;
                if (biomodelInfo.getPublicationInfos() != null && biomodelInfo.getPublicationInfos().length > 0) {
                    if (biomodelInfo.getVersion().getFlag().compareEqual(org.vcell.util.document.VersionFlag.Published)) {
                        component.setText("(Published) " + component.getText());
                    } else {
                        component.setText("(Curated) " + component.getText());
                    }
                } else if (biomodelInfo.getVersion().getFlag().compareEqual(org.vcell.util.document.VersionFlag.Archived)) {
                    component.setText("(Archived) " + component.getText());
                }
                String str = component.getToolTipText();
                if (str != null && !str.isEmpty()) {
                    component.setToolTipText(str + " " + biomodelInfo.getVersion().getVersionKey());
                }
                // we change color of version if it's in the Other folder (Uncurated) and belongs to login user
                Object pNode = node.getParent();
                if (pNode instanceof BioModelNode) {
                    pNode = ((BioModelNode) pNode).getParent();
                    if (pNode instanceof BioModelNode && ((BioModelNode) pNode).getUserObject() instanceof String) {
                        str = (String) ((BioModelNode) pNode).getUserObject();
                        if (str.equals(VCDocumentDbTreeModel.ModelBricks) && sessionUser.getName().contentEquals(VCDocumentDbTreeModel.USER_modelBricks)) {
                            // GRAY
                            String prefix = sel ? "" : "<span style=\"color:#808080\">";
                            String suffix = sel ? "" : "</span>";
                            String str1 = prefix + component.getText() + suffix;
                            setText("<html>" + str1 + "</html>");
                        } else {
                            pNode = ((BioModelNode) pNode).getParent();
                            if (((BioModelNode) pNode).getUserObject() instanceof String && str.equalsIgnoreCase(sessionUser.getName())) {
                                str = (String) ((BioModelNode) pNode).getUserObject();
                                if (str.equals(VCDocumentDbTreeModel.Other_BioModels)) {
                                    // GRAY
                                    String prefix = sel ? "" : "<span style=\"color:#808080\">";
                                    String suffix = sel ? "" : "</span>";
                                    String str1 = prefix + component.getText() + suffix;
                                    setText("<html>" + str1 + "</html>");
                                }
                            }
                        }
                    }
                }
            } else if (userObject instanceof Geometry) {
                Geometry geo = (Geometry) userObject;
                String label = "";
                // geomety info, when spatial--shows name+1D/2D/3D
                if (geo.getDimension() > 0) {
                    label = geo.getName() + " (" + geo.getDimension() + "D)";
                } else {
                    label = BioModelChildSummary.COMPARTMENTAL_GEO_STR;
                }
                component.setToolTipText("Geometry");
                component.setText(label);
                setIcon(fieldGeometryIcon);
            } else if (userObject instanceof String && "AppType".equals(node.getRenderHint("type"))) {
                String label = (String) userObject;
                component.setToolTipText("Application type");
                component.setText(label);
                setIcon(VCellIcons.mathTypeIcon);
            } else if (userObject instanceof VCDocumentInfoNode) {
                VCDocumentInfoNode infonode = (VCDocumentInfoNode) userObject;
                User nodeUser = infonode.getVCDocumentInfo().getVersion().getOwner();
                String modelName = infonode.getVCDocumentInfo().getVersion().getName();
                String username = nodeUser.getName();
                if (username.equals(VCDocumentDbTreeModel.USER_tutorial) || // || username.equals(VCDocumentDbTreeModel.USER_Education)
                username.equals(VCDocumentDbTreeModel.USER_tutorial610) || username.equals(VCDocumentDbTreeModel.USER_tutorial611)) {
                    if (node.getParent() instanceof BioModelNode && ((BioModelNode) node.getParent()).getUserObject() instanceof String) {
                        String pName = (String) ((BioModelNode) node.getParent()).getUserObject();
                        if (pName.equals(VCDocumentDbTreeModel.Curated_BioModels)) {
                            // we add the user name to Curated
                            setText("<html><b>" + nodeUser.getName() + " </b> : " + modelName + "</html>");
                        } else {
                            // keep it simple for Education and Tutorial
                            component.setText(modelName);
                        }
                    } else {
                        component.setText(modelName);
                    }
                } else if (username.equals(VCDocumentDbTreeModel.USER_modelBricks)) {
                    if (node.getParent() instanceof UserNameNode && sessionUser.getName().contentEquals(VCDocumentDbTreeModel.USER_modelBricks)) {
                        // login user is ModelBrick, must gray everything in the Other (Uncurated) folder
                        // ATTANTION: the Uncurated folder is populated with bricks only in the versions of vCell where the ModelBricks
                        // folder is missing !!!
                        String toolTip = modelName;
                        // GRAY
                        String prefix = sel ? "" : "<span style=\"color:#808080\">";
                        String suffix = sel ? "" : "</span>";
                        String str1 = prefix + modelName + suffix;
                        component.setText("<html>" + str1 + "</html>");
                        component.setToolTipText(toolTip);
                    } else if (node.getParent() instanceof BioModelNode && ((BioModelNode) node.getParent()).getUserObject() instanceof String && sessionUser.getName().contentEquals(VCDocumentDbTreeModel.USER_modelBricks) && ((String) ((BioModelNode) node.getParent()).getUserObject()).equals(VCDocumentDbTreeModel.ModelBricks)) {
                        // login user is ModelBrick, and the model Bricks folder is present -> we must gray everything in it
                        // do exactly what we did for the "Other" folder, just above
                        String toolTip = modelName;
                        // GRAY
                        String prefix = sel ? "" : "<span style=\"color:#808080\">";
                        String suffix = sel ? "" : "</span>";
                        String str1 = prefix + modelName + suffix;
                        component.setText("<html>" + str1 + "</html>");
                        component.setToolTipText(toolTip);
                    } else if (node.getParent() instanceof BioModelNode && ((BioModelNode) node.getParent()).getUserObject() instanceof String) {
                        String pName = (String) ((BioModelNode) node.getParent()).getUserObject();
                        String toolTip = modelName;
                        if (!sessionUser.getName().contentEquals(VCDocumentDbTreeModel.USER_modelBricks) && modelName.contains(VCDocumentDbTreeModel.ModelBricksNameSeparator)) {
                            modelName = modelName.substring(modelName.indexOf(VCDocumentDbTreeModel.ModelBricksNameSeparator) + VCDocumentDbTreeModel.ModelBricksNameSeparator.length());
                            String prefix = toolTip.substring(0, toolTip.indexOf(VCDocumentDbTreeModel.ModelBricksNameSeparator));
                            toolTip = "id: " + prefix + ", name: " + modelName;
                        }
                        if (pName.equals(VCDocumentDbTreeModel.Curated_BioModels)) {
                            // we add the user name to Curated
                            setText("<html><b>" + nodeUser.getName() + " </b> : " + modelName + "</html>");
                            component.setToolTipText(toolTip);
                        } else if (pName.equals(VCDocumentDbTreeModel.ModelBricks)) {
                            component.setText(modelName);
                            component.setToolTipText(toolTip);
                        } else {
                            String str = modelName;
                            if (node.getChildCount() > 1) {
                                String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                                String suffix = sel ? "" : "</span>";
                                str += prefix + " (" + node.getChildCount() + ")" + suffix;
                            }
                            component.setText("<html>" + str + "</html>");
                            component.setToolTipText(toolTip);
                        }
                    } else {
                        component.setText(modelName);
                    }
                } else if (nodeUser.compareEqual(sessionUser)) {
                    Object pNode = node.getParent();
                    if (pNode instanceof BioModelNode) {
                        BioModelNode parent = (BioModelNode) pNode;
                        // TODO: do this differently
                        if (parent.getUserObject() instanceof String) {
                            // the Published, Curated and Other folders are the only
                            // ones where the user object is a String
                            String str = (String) parent.getUserObject();
                            if (str.equals(VCDocumentDbTreeModel.Published_BioModels) || str.equals(VCDocumentDbTreeModel.Curated_BioModels)) /*|| str.equals(VCDocumentDbTreeModel.Other_BioModels)*/
                            {
                                String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                                String suffix = sel ? "" : "</span>";
                                setText("<html><b>" + prefix + nodeUser.getName() + suffix + "</b>  : " + modelName + "</html>");
                            } else {
                                // in the Other folder / owner folder
                                // GRAY
                                String prefix = sel ? "" : "<span style=\"color:#808080\">";
                                String suffix = sel ? "" : "</span>";
                                String str1 = prefix + modelName + suffix;
                                if (node.getChildCount() > 1) {
                                    prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                                    suffix = sel ? "" : "</span>";
                                    str1 += prefix + " (" + node.getChildCount() + ")" + suffix;
                                }
                                // the name of the model container - which holds the versions
                                setText("<html>" + str1 + "</html>");
                            }
                        } else if (parent.getUserObject() instanceof PublicationInfo) {
                            String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                            String suffix = sel ? "" : "</span>";
                            setText("<html><b>" + prefix + nodeUser.getName() + suffix + "</b>  : " + modelName + "</html>");
                        } else {
                            String str = modelName;
                            if (node.getChildCount() > 1) {
                                String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                                String suffix = sel ? "" : "</span>";
                                str += prefix + " (" + node.getChildCount() + ")" + suffix;
                            }
                            setText("<html>" + str + "</html>");
                        }
                    } else {
                        // unreachable
                        setText(modelName);
                    }
                } else {
                    Object pNode = node.getParent();
                    if (pNode instanceof UserNameNode) {
                        // if we are inside an UserName folder (like Shared or Uncurated public),
                        // don't prefix again the model with the user name
                        String str = modelName;
                        if (node.getChildCount() > 1) {
                            String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                            String suffix = sel ? "" : "</span>";
                            str += prefix + " (" + node.getChildCount() + ")" + suffix;
                        }
                        setText("<html>" + str + "</html>");
                    } else {
                        // content of "Published" folder
                        setText("<html><b>" + nodeUser.getName() + " </b> : " + modelName + "</html>");
                    }
                }
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    // 
    if (component.getToolTipText() == null || component.getToolTipText().length() == 0) {
        component.setToolTipText(component.getText());
    }
    return component;
}
Also used : UserNameNode(cbit.vcell.desktop.BioModelNode.UserNameNode) DateNode(cbit.vcell.xml.gui.MiriamTreeModel.DateNode) User(org.vcell.util.document.User) PublicationInfo(org.vcell.util.document.PublicationInfo) BioModelInfo(org.vcell.util.document.BioModelInfo) JLabel(javax.swing.JLabel) Geometry(cbit.vcell.geometry.Geometry) AnnotationQualifier(org.vcell.sybil.models.AnnotationQualifier) LinkNode(cbit.vcell.xml.gui.MiriamTreeModel.LinkNode) MIRIAMQualifier(org.vcell.sybil.models.miriam.MIRIAMQualifier) SimpleDateFormat(java.text.SimpleDateFormat) PublicationInfoNode(cbit.vcell.desktop.BioModelNode.PublicationInfoNode)

Aggregations

PublicationInfo (org.vcell.util.document.PublicationInfo)15 User (org.vcell.util.document.User)7 BioModelInfo (org.vcell.util.document.BioModelInfo)6 Date (java.util.Date)5 JLabel (javax.swing.JLabel)5 KeyValue (org.vcell.util.document.KeyValue)5 VCDocumentInfoNode (cbit.vcell.desktop.VCellBasicCellRenderer.VCDocumentInfoNode)4 SimpleDateFormat (java.text.SimpleDateFormat)4 MathModelInfo (org.vcell.util.document.MathModelInfo)4 VersionInfo (org.vcell.util.document.VersionInfo)4 PublicationInfoNode (cbit.vcell.desktop.BioModelNode.PublicationInfoNode)3 UserNameNode (cbit.vcell.desktop.BioModelNode.UserNameNode)3 GeometryInfo (cbit.vcell.geometry.GeometryInfo)3 BigDecimal (java.math.BigDecimal)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 RecordChangedException (cbit.sql.RecordChangedException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Set (java.util.Set)2