Example usage for java.util HashSet iterator

List of usage examples for java.util HashSet iterator

Introduction

In this page you can find the example usage for java.util HashSet iterator.

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:StreamFlusher.java

public Object visit(ASTnum_list_get_sigma_func_call node, Object data) {
    // #@^__getSigma($fst)
    // one daughter
    //      regexp
    // return the sigma as an array of Integer, one for each symbol in
    // the sigma (minus special chars starting "__" that should not be
    // considered when promoting OTHER)

    node.jjtGetChild(0).jjtAccept(this, data);
    Fst fst = (Fst) (stack.pop());//from  www . j  ava2  s  .c o m

    NumList resultList = new NumList();

    String specialSymbolPrefix = "__";
    HashSet<Integer> sigma = fst.getSigma();
    String symbolName = "";

    if (!sigma.isEmpty()) {
        for (Iterator<Integer> iter = sigma.iterator(); iter.hasNext();) {
            int cpv = iter.next().intValue();
            symbolName = symmap.getsym(cpv);
            if (!(symbolName.startsWith(specialSymbolPrefix))) {
                resultList.add(new Long(cpv));
            }
        }
    }

    stack.push(resultList);
    return data;
}

From source file:StreamFlusher.java

private void findDependencies(Fst fst, ArrayList<String> dependencies) {
    String subnetReferencePrefix = "";
    if (isOpenFstRtnConventions()) {
        subnetReferencePrefix = "__$";
    } else {/* w  w w .ja v a2  s. co  m*/
        subnetReferencePrefix = "$";
    }
    HashSet<Integer> sigma = fst.getSigma();
    String symbolName = "";
    String netIdName = "";

    if (!sigma.isEmpty()) {
        for (Iterator<Integer> iter = sigma.iterator(); iter.hasNext();) {
            // the name should look like "a", "b", and perhaps
            // "__$sub" (for OpenFstRtnConventions) or "$sub" (for SapRtnConventions)
            symbolName = symmap.getsym(iter.next().intValue());
            if (symbolName.startsWith(subnetReferencePrefix)) {
                // save the subnet name, minus any prefix
                netIdName = symbolName.substring(symbolName.indexOf("$"));
                // avoid duplicates
                if (!dependencies.contains(netIdName)) {
                    dependencies.add(netIdName);
                }
            }
        }
    }
}

From source file:StreamFlusher.java

public Object visit(ASTnet_start_func_call node, Object data) {
    // syntax:   $^start($>foo)   a built-in function-like regexp
    // Not really implemented as a function, cannot be aliased, i.e.
    // $^debut = $^start  is not legal
    // The value of the statement, if successful, is an Fst.

    // just one daughter: ASTrrprod_id, which includes the name
    // of the start production 
    // (This is constrained syntactically by the parser)
    // Don't evaluate daughter.  Just retrieve the image.
    String rrprod_id = ((ASTrrprod_id) node.jjtGetChild(0)).getImage();

    // The rrprod_id argument to $^start() will be the root of the 
    //      right-linear grammar,
    // but rrprod_id may refer to other productions, which may, 
    //      in turn, refer
    // to other productions, etc.  (even circular references).
    // Need to check that all the RrDependencies ("right-recursive") 
    //      of $>foo are defined,
    // and that all the dependencies of the dependencies are defined,
    // etc.//from w w w .j av a 2s .  co m

    // Check and list dependencies (the productions)
    // for the whole implied grammar, keep them in an ArrayList
    // (I tried to use a HashSet, but this proved to be
    // impossible to iterate through AND increase in size)
    ArrayList<String> dependencies = new ArrayList<String>();
    dependencies.add(rrprod_id);
    // Start with the current rrprod_id (the start); use ArrayList
    // so that dependencies of the overall grammar are added only
    // once (no duplicates).  The order of objects in the ArrayList
    // is constant and starts at index 0

    // Now loop through the ArrayList of dependencies, adding new ones 
    // as they appear
    // (use a for-loop so that the size can grow during iteration--
    // tried to use HashSet, but this proved impossible)
    for (int i = 0; i < dependencies.size(); i++) {
        String dep = dependencies.get(i);
        // Look up the dependency name (getting back an RrProdObject)
        // if successful (i.e. is in the symbol table).
        RrProdObject rrProdObject = (RrProdObject) env.get(dep);
        if (rrProdObject == null) {
            throw new UndefinedIdException("Undefined rrprod_id: " + dep);
        }
        // also check net_id and other _id references? or catch during
        // interpretation?  
        // The dependencies of each defined production are stored 
        // in the symbol table as part of the RrProdObject, 
        // as a HashSet
        HashSet<String> hs = rrProdObject.getRrDependencies();
        if (!hs.isEmpty()) {
            for (Iterator<String> iter = hs.iterator(); iter.hasNext();) {
                String s = iter.next();
                // if the overall list of dependencies does not yet
                // contain s, then add it
                if (!dependencies.contains(s)) {
                    dependencies.add(s);
                }
            }
        }
    }

    // Reaching here, the whole Rr grammar has been defined.
    // (All the required Rr productions are available in the
    // symbol table.)

    // Create an Fst result.
    // Need to copy all the states and arcs of networks 
    //      of the productions
    // into the result network, keeping track of the 
    //      new startStateNum of each network.  
    // (This is a modification of the concatenation
    // algorithm of OpenFst, minus the code that creates an 
    //      epsilon arc from the final state(s) of the first 
    //      network to the start state of the second.
    //
    // Try to compile each network in the grammar.  Initially
    // each right-recursive reference $>foo is treated much 
    // like a multichar-symbol, but with
    // a negative code point value (a negative label value on an arc).
    // These negative code point values should not be added to
    // the sigma.

    Fst resultFst = null;

    // Instead of a HashMap, use two parallel ArrayLists,
    // later converted to int[], to pass easily to a C++ 
    // native function that stitches the network together.

    // ArrayLists expand as necessary; avoid any preconceived
    // size limit.
    ArrayList<Integer> keys = new ArrayList<Integer>();
    ArrayList<Integer> vals = new ArrayList<Integer>();
    //  will have neg ints (representing $>foo refs) mapped 
    // to positive numbers corresponding to start states of the
    // various dependencies (productions) in the overall grammar.

    // Again loop through the list of dependencies (the names
    // of all the productions in the implied grammar);
    // they are "defined" (stored as ASTs) but not yet
    // "evaluated" into FSTs

    for (int i = 0; i < dependencies.size(); i++) {
        String rrprod = dependencies.get(i);

        RrProdObject rrProdObject = (RrProdObject) env.get(rrprod);
        // get the AST (.getRHS()), 
        // and evaluate it to produce an Fst object
        ASTrrProdRHS astRrProdRHS = rrProdObject.getRHS();
        astRrProdRHS.jjtAccept(this, data);
        // should leave an Fst object on the stack, for one production
        Fst fst = (Fst) stack.pop();

        int startStateNum;

        if (i == 0) {
            // the zeroth is the root production
            resultFst = lib.CopyFst(fst);
            startStateNum = lib.StartState(resultFst);
        } else {
            // returns the _new_ start state number of fst
            startStateNum = lib.AddStatesAndArcsInPlace(resultFst, fst);

        }

        // A rrprod_id like $>foo is stored with a NEGATIVE int value
        // on an Fst arc.
        int negcpv = symmap.getint(rrprod);

        // effectively create a Map from neg. int keys 
        //   (right-linear labels)to non-neg.
        // integers that represent the new state number of the start
        // state of this particular Fst (for one of the productions
        // of the overall grammar); 
        keys.add(negcpv); // will be a negative int value
        vals.add(startStateNum);
    }

    // Now need to "stitch" it all together

    lib.RrGrammarLinkInPlace(resultFst, keys, vals);

    stack.push(resultFst);
    return data;
}

From source file:StreamFlusher.java

public Object visit(ASTdelete_all_statement node, Object data) {
    // no children
    // find all networks, productions, etc. defined in 
    // currentFrame and delete them

    Frame currentFrame = env.getCurrentFrame();
    HashSet<String> keySet = currentFrame.keySet();

    boolean inGUI = false;
    PseudoTerminalInternalFrame terminal = null;

    if (((InterpData) data).getInGUI() == true) {
        inGUI = true;// w ww  .ja v a2  s . c o m
        terminal = ((InterpData) data).getGUI().getTerminal();
    }

    for (Iterator<String> i = keySet.iterator(); i.hasNext();) {
        String key = i.next();

        Object obj = currentFrame.get(key);

        // don't try to delete entries where the value is
        // a FreeVariable, indicating that the key would
        // looked up in this scope as a free variable.
        if (!(obj instanceof FreeVariable)) {

            Frame foundFrame = null;
            foundFrame = env.remove(key);

            final String fkey = key;
            final Object fdata = data;
            if (foundFrame == mainFrame) {
                if (inGUI) {
                    if (javax.swing.SwingUtilities.isEventDispatchThread()) {
                        removeFromGUISymtab(fkey, fdata);

                    } else {
                        javax.swing.SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                removeFromGUISymtab(fkey, fdata);
                            }
                        });
                    }
                }
            }
            if (inGUI) {
                final PseudoTerminalInternalFrame fterminal = terminal;
                if (javax.swing.SwingUtilities.isEventDispatchThread()) {
                    fterminal.appendToHistory("// Deleting " + fkey);
                } else {
                    javax.swing.SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            fterminal.appendToHistory("// Deleting " + fkey);
                        }
                    });
                }
            }
        }
    }
    return data;
}

From source file:dao.DirectoryDaoDb.java

/**
 * Deletes directory//from  ww w  .j  a  v  a 2  s  . c o m
 * If the directory contains subdirectories or children or collabrum or urls, then
 * this directory is not deleted.
 * User permissions are checked before the user is allowed to delete directory.
 * If the user is the userid or admin, delete directory.
 * If the user has permission to delete in the permission directory, delete directory.
 * Returns parentId of this directory for controller
 * @param directoryId - the directoryid 
 * @param userId - the user id
 * @param userLogin - user login
 * @return List -> has the parentid used by the controller to throw the viewDirectory
 * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
 */
public List deleteDirectory(String directoryId, String userId, String userLogin) throws BaseDaoException {

    if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) {
        throw new BaseDaoException("params are null");
    }

    //logger.info("deleteDirectory" + directoryId);

    if (!WebUtil.isHomeDirDeleteEnabled()) {
        if (WebUtil.isSanEnabled()) {
            if (isHomeDirectory(directoryId, userLogin, userId)) {
                throw new BaseDaoException("Cannot delete, home directory, directoryId " + directoryId
                        + " userLogin = " + userLogin);
            }
        }
    }

    /**
    * allow files, collabrums to be deleted
    */
    if (!WebUtil.isDirTreeDeleteEnabled()) {
        if (isChildASubDir(directoryId)) {
            throw new BaseDaoException(
                    "Cannot delete, subdirs exist, userId = " + userId + " directoryId = " + directoryId);
        }
    }

    /**
     *  check authority to delete: isDiaryAdmin, isAuthor
     *  We donot check for global scope as the author who has added this entry 
     *  is added as diradmin
     */
    if ((!diaryAdmin.isDiaryAdmin(userLogin)) && (!isAuthor(directoryId, userId))) {
        throw new BaseDaoException("User does not have permission to delete this directory, user = " + userId
                + " directoryId " + directoryId);
    }

    /**
     *  Get scalability datasource for directory - not partitioned
     */
    String sourceName = scalabilityManager.getWriteZeroScalability();
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds null, deleteDirectory() " + sourceName);
    }

    /**
     *  gets the parentid of the directoryid and the result is returned
     */
    List dResult = null;
    try {
        Object[] params = { (Object) directoryId };
        dResult = directoryParentQuery.execute(params);
    } catch (Exception e) {
        throw new BaseDaoException("directoryparentQuery() exception " + directoryParentQuery.getSql(), e);
    }

    Connection conn = null;
    HashSet dirSet = null;
    try {
        conn = ds.getConnection();
        dirSet = listAuthorQuery.run(conn, directoryId);
    } catch (Exception e) {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e1) {
            throw new BaseDaoException("conn.close() exception " + directoryId, e1);
        }
        throw new BaseDaoException("listAuthorQuery, exception " + directoryId, e);
    }

    if (WebUtil.isSanEnabled()) {
        Directory currentDir = viewDirectory(directoryId, userId, userLogin, DbConstants.READ_FROM_SLAVE,
                DbConstants.BLOB_READ_FROM_SLAVE, DbConstants.READ_FROM_SLAVE);

        if (currentDir != null) {
            try {
                getSanUtils();
                //logger.info("commenting deleteAllSanDir for the time being");
                sanUtils.deleteAllSanDir(currentDir.getValue(DbConstants.DIRPATH),
                        currentDir.getValue(DbConstants.DIRNAME), SanConstants.sanPath);
            } catch (SanException e) {
                throw new BaseDaoException("deleteSanDir() deleteDirectory() error, " + directoryId
                        + " error message " + e.getMessage(), e);
            }
        }
    }

    try {
        if (conn == null) {
            conn = ds.getConnection();
        }
        conn.setAutoCommit(false);

        /** delete all children, subdirs */
        if (isChildASubDir(directoryId)) {
            //logger.info("calling deleteNode()");
            deleteNode(directoryId, conn);
        }

        /** 
         * the userId is not required to be checked 
         * as long as the user either the diaryAdmin or is author 
         */
        deleteAllDirectory(directoryId, conn);
        //logger.info("deleteAllDirectory called " + directoryId);

        /*
              directoryDeleteQuery.run(conn, directoryId);
              scopeDeleteQuery.run(conn, directoryId);
              deleteChildQuery.run(conn, directoryId);
              deleteAdminQuery.run(conn, directoryId);
              deleteDirCopyQuery.run(conn, directoryId);
              deleteDirBlockAllQuery.run(conn, directoryId);
              deleteDirAllowUsersAllQuery.run(conn, directoryId);
        */
        //logger.info("completed deleteDirectory queries ");
        /**
         * delete collabrum, delete websites coming soon!
         */
    } catch (Exception e) {
        try {
            conn.rollback();
        } catch (Exception e1) {
            try {
                if (conn != null) {
                    conn.setAutoCommit(true);
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException(
                        "connection close() exception for rollback, delete directory/dirscope/diradmin tables  "
                                + " params (2) " + " directoryId = " + directoryId + " userId = " + userId,
                        e2);
            }
            throw new BaseDaoException("rollback() exception for delete directory/dirscope/diradmin tables  "
                    + " params (2) " + " directoryId = " + directoryId + " userId = " + userId, e1);
        }
    }

    // connection commit
    try {
        conn.commit();
    } catch (Exception e3) {
        throw new BaseDaoException("commit() exception for delete, directory/dirscope/diradmin tables  "
                + " params (2) " + " directoryId = " + directoryId + " userId = " + userId, e3);
    }
    try {
        if (conn != null) {
            conn.setAutoCommit(true);
            conn.close();
        }
    } catch (Exception e4) {
        throw new BaseDaoException(
                "connection close() exception for commit, delete directory/dirscope/diradmin tables  "
                        + " params (2) " + " directoryId = " + directoryId + " userId = " + userId,
                e4);
    }

    /**
     * remove this directory from cache
     */
    Fqn fqn = cacheUtil.fqn(DbConstants.DIRECTORY);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    // check for each parent and remove the parent from cache
    if ((dResult != null) && (dResult.size() > 0)) {
        String parentId = ((Directory) dResult.get(0)).getValue(DbConstants.PARENT_ID);
        if (treeCache.exists(fqn, parentId)) {
            treeCache.remove(fqn, parentId);
        }
    }

    fqn = cacheUtil.fqn(DbConstants.DIR_COBRAND);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    fqn = cacheUtil.fqn(DbConstants.DIR_SCOPE);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    fqn = cacheUtil.fqn(DbConstants.DIR_CAT);
    StringBuffer sb = new StringBuffer(directoryId);
    sb.append("-");
    sb.append(DbConstants.PHOTO_CATEGORY);
    if (treeCache.exists(fqn, sb.toString())) {
        treeCache.remove(fqn, sb.toString());
    }

    sb.delete(0, sb.length());
    sb.append(directoryId);
    sb.append("-");
    sb.append(DbConstants.FILE_CATEGORY);
    if (treeCache.exists(fqn, sb.toString())) {
        treeCache.remove(fqn, sb.toString());
    }

    /*
            fqn = cacheUtil.fqn(DbConstants.DIRECTORY_STREAM_BLOBS);
            if (treeCache.exists(fqn, directoryId)) {
          Object obj = treeCache.get(fqn, directoryId);
          if (obj != null) {
             List entries = (List)obj;
      Fqn streamFqn = cacheUtil.fqn(DbConstants.DIR_STREAM_BLOB);
             //StringBuffer sb = new StringBuffer();
             for (int i = 0; i < entries.size(); i++) {
     String entryId = ((Photo)entries.get(i)).getValue(DbConstants.ENTRYID);
            if (!RegexStrUtil.isNull(entryId)) {
               sb.delete(0, sb.length());        
               sb.append(directoryId);
               sb.append("-");
               sb.append(entryId);
               if (treeCache.exists(streamFqn, sb.toString())) {
      treeCache.remove(streamFqn, sb.toString());
               }
            }
             }
          }
               treeCache.remove(fqn, directoryId);
       }
    */
    if (dirSet != null) {
        Iterator it = dirSet.iterator();
        while (it.hasNext()) {
            Directory directory = (Directory) it.next();
            String adminUser = directory.getValue(DbConstants.LOGIN);
            if (!RegexStrUtil.isNull(adminUser)) {

                fqn = cacheUtil.fqn(DbConstants.USER_PAGE);
                if (treeCache.exists(fqn, adminUser)) {
                    treeCache.remove(fqn, adminUser);
                }

                fqn = cacheUtil.fqn(DbConstants.AUTHORS_LIST);
                if (treeCache.exists(fqn, adminUser)) {
                    treeCache.remove(fqn, adminUser);
                }

                fqn = cacheUtil.fqn(DbConstants.AUTHORS_DIRECTORIES);
                if (treeCache.exists(fqn, adminUser)) {
                    treeCache.remove(fqn, adminUser);
                }

                String adminId = directory.getValue(DbConstants.LOGIN_ID);
                fqn = cacheUtil.fqn(DbConstants.AUTHOR_BLOCKED_DIRS);
                if (treeCache.exists(fqn, adminId)) {
                    treeCache.remove(fqn, adminId);
                }

                fqn = cacheUtil.fqn(DbConstants.DIR_COPY);
                if (treeCache.exists(fqn, adminId)) {
                    treeCache.remove(fqn, adminId);
                }

                fqn = cacheUtil.fqn(DbConstants.DIR_MOVE);
                if (treeCache.exists(fqn, adminId)) {
                    treeCache.remove(fqn, adminId);
                }

                sb.delete(0, sb.length());
                sb.append(directoryId);
                sb.append("-");
                sb.append(adminId);
                String key = sb.toString();
                fqn = cacheUtil.fqn(DbConstants.DIR_AUTHOR);
                if (treeCache.exists(fqn, key)) {
                    treeCache.remove(fqn, key);
                }
            }
        }
    }
    removeUsersFromDirAuthorsCache(directoryId);
    return dResult;
}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

/**
 * Add submission objects if necessary for non-electronic type of assignment
 * @param state/*from  w  w w.  j av  a  2  s.  c o  m*/
 * @param a
 */
private void addRemoveSubmissionsForNonElectronicAssignment(SessionState state, List submissions,
        HashSet<String> addSubmissionForUsers, HashSet<String> removeSubmissionForUsers, Assignment a) {
    // create submission object for those user who doesn't have one yet
    for (Iterator iUserIds = addSubmissionForUsers.iterator(); iUserIds.hasNext();) {
        String userId = (String) iUserIds.next();
        try {
            User u = UserDirectoryService.getUser(userId);
            // only include those users that can submit to this assignment
            if (u != null) {
                // construct fake submissions for grading purpose
                AssignmentSubmissionEdit submission = AssignmentService.addSubmission(a.getContext(), a.getId(),
                        userId);
                if (submission != null) {
                    submission.setTimeSubmitted(TimeService.newTime());
                    submission.setSubmitted(true);
                    submission.setIsUserSubmission(false);
                    submission.setAssignment(a);
                    AssignmentService.commitEdit(submission);
                }
            }
        } catch (Exception e) {
            M_log.warn(this + ":addRemoveSubmissionsForNonElectronicAssignment " + e.toString()
                    + "error adding submission for userId = " + userId);
        }
    }

    // remove submission object for those who no longer in the site
    for (Iterator iUserIds = removeSubmissionForUsers.iterator(); iUserIds.hasNext();) {
        String userId = (String) iUserIds.next();
        String submissionRef = null;
        // TODO: we don't have an efficient way to retrieve specific user's submission now, so until then, we still need to iterate the whole submission list
        for (Iterator iSubmissions = submissions.iterator(); iSubmissions.hasNext() && submissionRef == null;) {
            AssignmentSubmission submission = (AssignmentSubmission) iSubmissions.next();
            if (userId.equals(submission.getSubmitterId())) {
                submissionRef = submission.getReference();
            }
        }
        if (submissionRef != null) {
            AssignmentSubmissionEdit submissionEdit = editSubmission(submissionRef,
                    "addRemoveSubmissionsForNonElectronicAssignment", state);
            if (submissionEdit != null) {
                try {
                    AssignmentService.removeSubmission(submissionEdit);
                } catch (PermissionException e) {
                    addAlert(state, rb.getFormattedMessage("youarenot_removeSubmission",
                            new Object[] { submissionEdit.getReference() }));
                    M_log.warn(this + ":deleteAssignmentObjects " + e.getMessage() + " "
                            + submissionEdit.getReference());
                }
            }
        }
    }

}

From source file:edu.cornell.qatarmed.planrnaseq.AnnotateRNAseqSQL.java

private void initDataAndSubcomponent() {
    rnaseqContainer = createMySQLContainer("study_summary", "dummy");
    bioprojectSummaryTable.setContainerDataSource(rnaseqContainer);
    //   bioprojectSummaryTable.setVisibleColumns(new String[] { studyName });
    bioprojectSummaryTable.setSelectable(true);
    bioprojectSummaryTable.setImmediate(true);
    bioprojectSummaryTable.setColumnReorderingAllowed(true);
    bioprojectSummaryTable.setSortEnabled(true);
    bioprojectSummaryTable.setVisibleColumns(
            new Object[] { "Study", "title", "name", "Numsample", "Numexp", "Numrun", "Avgspots", "avgbases" });
    //bioprojectSummaryTable.setVisibleColumns(new Object[] { "firstName", "lastName", "department", "phoneNumber", "street", "city", "zipCode" });
    studyName.setValue(rnaseqContainer.firstItemId().toString());
    bioprojectSummaryTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        int custom_annotation_counter = 0;

        public void itemClick(ItemClickEvent event) {
            //<editor-fold defaultstate="collapsed" desc="filling study details on right panel">

            Object selectedStudyObject = event.getItemId();
            bioprojectSummaryTable.select(selectedStudyObject);
            tree.removeAllItems();//from   w w  w .j a v  a  2 s.  c  o  m
            rightTopForm.removeAllComponents();
            rightTopAnnotationForm.removeAllComponents();
            myform.removeAllComponents();

            String selectedStudy = selectedStudyObject.toString();
            String studyTitle = (String) bioprojectSummaryTable
                    .getContainerProperty(selectedStudyObject, "title").getValue();
            String studyName = (String) bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "name")
                    .getValue();
            String studyNumsample = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numsample").getValue());
            String studyNumexp = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numexp").getValue());
            String studyNumrun = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numrun").getValue());
            String studyAvgspots = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Avgspots").getValue());
            String studyAvgbases = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "avgbases").getValue());
            tree.addItem(selectedStudy);
            tree.setItemCaption(selectedStudy, "Study: " + selectedStudy);
            SQLContainer tempContainer = createMySQLContainer("study_extdb", selectedStudy); // In this table I will chaeck for the manual annotation status
            String extdbid = tempContainer.getItem(tempContainer.getIdByIndex(0)).getItemProperty("extdb")
                    .getValue().toString();
            Label labelStudyAcc = new Label("<b>SRA Study Accession : </b>" + selectedStudy, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAcc);
            Label labelStudyTitle = new Label("<b>Study Title: </b>" + studyTitle, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyTitle);
            Label labelStudyName = new Label("<b>Study Name: </b>" + studyName, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyName);
            Label labelStudyNumsample = new Label("<b>Total number of samples: </b>" + studyNumsample,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumsample);
            Label labelStudyNumexp = new Label(
                    "<b>Total number of experiments (each experiment uses any one of the samples): </b>"
                            + studyNumexp,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumexp);
            Label labelStudyNumrun = new Label(
                    "<b>Total number of runs ( an experiment can have multiple runs) : </b>" + studyNumrun,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumrun);
            Label labelStudyAvgspots = new Label(
                    "<b>Avg number of spots or reads (per run): </b>" + studyAvgspots, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgspots);
            Label labelStudyAvgbases = new Label("<b>Avg number of bases (per run): </b>" + studyAvgbases,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgbases);
            if (extdbid.startsWith("PRJ")) {
                //<editor-fold defaultstate="collapsed" desc="if PRJ">
                tempContainer = createMySQLContainer("bioproject_details", extdbid);
                String bioproject_accession = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectAccession").getValue().toString();
                String bioproject_id = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectId").getValue().toString();
                String bioproject_name = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Name").getValue().toString();
                String bioproject_title = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Title").getValue().toString();
                String bioproject_description = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Description").getValue().toString();
                String bioproject_capture = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Capture").getValue().toString();
                String bioproject_material = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Material").getValue().toString();
                String bioproject_method = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("MethodType").getValue().toString();
                String bioproject_datatype = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("DataType").getValue().toString();
                String bioproject_sampleScope = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("SampleScope").getValue().toString();
                System.out.println(bioproject_description);
                Label labelBioprojectAccession = new Label(
                        "<b>Bioproject Accession : </b>" + bioproject_accession, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectAccession);
                Label labelBioprojectId = new Label("<b>Bioproject Id : </b>" + bioproject_id,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectId);
                Label labelBioprojectTitle = new Label("<b>Bioproject Title : </b>" + bioproject_title,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectTitle);
                Label labelBioprojectName = new Label("<b>Bioproject Name : </b>" + bioproject_name,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectName);
                Label labelBioprojectDescription = new Label(
                        "<b>Bioproject Description : </b>" + bioproject_description, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDescription);
                Label labelBioprojectCapture = new Label("<b>Bioproject Capture : </b>" + bioproject_capture,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectCapture);
                Label labelBioprojectMaterial = new Label(
                        "<b>Bioproject  Material : </b>" + bioproject_material, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMaterial);
                Label labelBioprojectMethod = new Label("<b>Bioproject Method : </b>" + bioproject_method,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMethod);
                Label labelBioprojectDatatype = new Label(
                        "<b>Bioproject Data Type : </b>" + bioproject_datatype, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDatatype);
                Label labelBioprojectSampleScope = new Label(
                        "<b>Bioproject Sample Scope : </b>" + bioproject_sampleScope, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectSampleScope);

                //</editor-fold>
            }
            if (extdbid.startsWith("GSE")) {
                //<editor-fold defaultstate="collapsed" desc="if GSE">
                tempContainer = createMySQLContainer("study_gse_details", extdbid);
                String gse_accesion = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("gse").getValue().toString();
                String gse_summary = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("summary").getValue().toString();
                String gse_design = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("overall_design").getValue().toString();
                System.out.println(gse_summary);
                Label labelGSE = new Label("<b>GEO Series Accession : </b>" + gse_accesion, ContentMode.HTML);
                rightTopForm.addComponent(labelGSE);
                Label labelGseSummary = new Label("<b>GSE Summary : </b>" + gse_summary, ContentMode.HTML);
                rightTopForm.addComponent(labelGseSummary);
                Label labelGseDesign = new Label("<b>GSE Design : </b>" + gse_design, ContentMode.HTML);
                rightTopForm.addComponent(labelGseDesign);
                //</editor-fold>

            }
            //</editor-fold>
            //SQLContainer tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            //  List<String> list = new ArrayList<String>();
            Map expMap = new HashMap();
            Map<String, String[]> expDetailMap = new HashMap<>();
            Map<String, String[]> platformMap = new HashMap<>();
            Map runMap = new HashMap();
            HashSet<String> biosampleSet = new HashSet<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for loop">

                String docid = tempContainer.getIdByIndex(i).toString();
                String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                biosampleSet.add(biosample);
                String[] b_parts = biosample.split("\\|");

                String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                String[] exp_parts = exp.split("\\|");
                String exp_acc = exp_parts[0];
                expMap.put(exp_acc, b_parts[0]);
                expDetailMap.put(exp_acc, exp_parts);

                String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Platform_InstrumentModel").getValue().toString();
                String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                platformMap.put(exp_acc, sra_plaforms_parts);

                String run = tempContainer.getItem(tempContainer.getIdByIndex(i)).getItemProperty("Runs")
                        .getValue().toString();
                String[] run_parts = run.split("\\|");
                if (run_parts.length > 0) {
                    for (int j = 0; j < run_parts.length; j++) {
                        String temprun = run_parts[j];
                        String[] temprun_parts = temprun.split("\\,");
                        runMap.put(temprun_parts[0], exp_acc);
                    }
                }
                //</editor-fold>
            }

            //<editor-fold defaultstate="collapsed" desc="Manual Annotaion">
            tempContainer = createMySQLContainer("biosample_with_studyacc", selectedStudy);
            int count_cell_line = 0;
            int count_organism_part = 0;
            int count_tissue = 0;
            int count_disease = 0;
            Set<String> cell_lines_set = new HashSet();
            Set<String> organism_part_set = new HashSet();
            Set<String> tissue_set = new HashSet();
            Set<String> disease_set = new HashSet();
            Map<String, Integer> cell_line_stat_map = new HashMap<>();
            Map<String, Integer> organism_part_stat_map = new HashMap<>();
            Map<String, Integer> tissue_stat_map = new HashMap<>();
            Map<String, Integer> disease_stat_map = new HashMap<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for biosample attributes">
                String biosample_attr = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Attributes").getValue().toString();
                String[] biosample_attr_parts = biosample_attr.split("\\:-");
                if (biosample_attr_parts.length > 0) {
                    String[] attr_names = biosample_attr_parts[0].split("\\|");
                    String[] attr_values = new String[] {};
                    if (biosample_attr_parts.length > 1) {
                        attr_values = biosample_attr_parts[1].split("\\|");
                    }
                    int atn_index = 0;
                    for (String atn : attr_names) {
                        if (atn.equalsIgnoreCase("cell line")) {
                            count_cell_line = count_cell_line + 1;
                            if (attr_values.length >= atn_index) {
                                String cell_line_value = attr_values[atn_index];
                                cell_lines_set.add(cell_line_value);
                                if (cell_line_stat_map.containsKey(cell_line_value)) {
                                    cell_line_stat_map.put(cell_line_value,
                                            cell_line_stat_map.get(cell_line_value) + 1);
                                } else {
                                    cell_line_stat_map.put(cell_line_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("organism part")) {
                            count_organism_part = count_organism_part + 1;
                            if (attr_values.length >= atn_index) {
                                String organism_part_value = attr_values[atn_index];
                                organism_part_set.add(organism_part_value);
                                if (organism_part_stat_map.containsKey(organism_part_value)) {
                                    organism_part_stat_map.put(organism_part_value,
                                            organism_part_stat_map.get(organism_part_value) + 1);
                                } else {
                                    organism_part_stat_map.put(organism_part_value, 1);
                                }
                            }

                        }

                        if (atn.contains("disease")) {
                            count_disease = count_disease + 1;
                            if (attr_values.length >= atn_index) {
                                String disease_value = attr_values[atn_index];
                                disease_set.add(disease_value);
                                if (disease_stat_map.containsKey(disease_value)) {
                                    disease_stat_map.put(disease_value,
                                            disease_stat_map.get(disease_value) + 1);
                                } else {
                                    disease_stat_map.put(disease_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("tissue")) {
                            count_tissue = count_tissue + 1;
                            if (attr_values.length >= atn_index) {
                                String tissue_value = attr_values[atn_index];
                                tissue_set.add(tissue_value);
                                if (tissue_stat_map.containsKey(tissue_value)) {
                                    tissue_stat_map.put(tissue_value, tissue_stat_map.get(tissue_value) + 1);
                                } else {
                                    tissue_stat_map.put(tissue_value, 1);
                                }
                            }

                        }
                        atn_index = atn_index + 1;
                    }
                }
                //</editor-fold>

            }

            String suggestion_cell_line = "";
            String suggestion_organism_part = "";
            String suggestion_tissue = "";
            String suggestion_disease = "";
            String samplesType_from_sra = "";
            String cell_line_confidence = "";
            String organism_part_confidence = "";
            String disease_confidence = "";
            String tissue_confidence = "";
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has cell line">
            if (count_cell_line > 0) {
                if (Integer.parseInt(studyNumsample) == count_cell_line) {
                    //good. all samples are from cell lines
                    suggestion_cell_line = "Yes:";
                    String cell_line_value = cell_lines_set.iterator().next();
                    suggestion_cell_line = suggestion_cell_line + cell_line_value;
                    cell_line_confidence = "100%. All " + cell_line_stat_map.get(cell_line_value).toString()
                            + " Samples";
                } else {
                    suggestion_cell_line = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : cell_line_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_cell_line = suggestion_cell_line + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    cell_line_confidence = confidence_percent + "%";
                    for (Iterator<String> it = cell_lines_set.iterator(); it.hasNext();) {
                        String cellLine = it.next();
                        if (cellLine.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_cell_line = suggestion_cell_line + ", " + cellLine + "("
                                    + cell_line_stat_map.get(cellLine).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_cell_line = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has organism part">
            if (count_organism_part > 0) {
                if (Integer.parseInt(studyNumsample) == count_organism_part) {
                    //good. all samples are from cell lines
                    suggestion_organism_part = "Yes:";
                    String organism_part_value = organism_part_set.iterator().next();
                    suggestion_organism_part = suggestion_organism_part + organism_part_value;
                    organism_part_confidence = "100%. All "
                            + organism_part_stat_map.get(organism_part_value).toString() + " Samples";
                } else {
                    suggestion_organism_part = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : organism_part_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_organism_part = suggestion_organism_part + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    organism_part_confidence = confidence_percent + "%";
                    for (Iterator<String> it = organism_part_set.iterator(); it.hasNext();) {
                        String organismPart = it.next();
                        if (organismPart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_organism_part = suggestion_organism_part + ", " + organismPart + "("
                                    + organism_part_stat_map.get(organismPart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_organism_part = " No";
            }
            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has disease">
            if (count_disease > 0) {
                if (Integer.parseInt(studyNumsample) == count_disease) {
                    //good. all samples are from cell lines
                    suggestion_disease = "Yes:";
                    String disease_value = disease_set.iterator().next();
                    suggestion_disease = suggestion_disease + disease_value;
                    disease_confidence = "100%. All " + disease_stat_map.get(disease_value).toString()
                            + " Samples";
                } else {
                    suggestion_disease = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : disease_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_disease = suggestion_disease + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    disease_confidence = confidence_percent + "%";
                    for (Iterator<String> it = disease_set.iterator(); it.hasNext();) {
                        String diseasePart = it.next();
                        if (diseasePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_disease = suggestion_disease + ", " + diseasePart + "("
                                    + disease_stat_map.get(diseasePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_disease = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has tissue">
            if (count_tissue > 0) {
                if (Integer.parseInt(studyNumsample) == count_tissue) {
                    //good. all samples are from cell lines
                    suggestion_tissue = "Yes:";
                    String tissue_value = tissue_set.iterator().next();
                    suggestion_tissue = suggestion_tissue + tissue_value;
                    tissue_confidence = "100%. All " + tissue_stat_map.get(tissue_value).toString()
                            + " Samples";
                } else {
                    suggestion_tissue = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : tissue_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_tissue = suggestion_tissue + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    tissue_confidence = confidence_percent + "%";
                    for (Iterator<String> it = disease_set.iterator(); it.hasNext();) {
                        String tissuePart = it.next();
                        if (tissuePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_tissue = suggestion_tissue + ", " + tissuePart + "("
                                    + tissue_stat_map.get(tissuePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_tissue = " No";
            }

            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="filling right top manual annotation">
            HorizontalLayout diseaseLayout = new HorizontalLayout();
            CheckBox checkboxDiseaseYes = new CheckBox("Yes");
            CheckBox checkboxDiseaseNo = new CheckBox("No");

            String disease_from_biosample_attribute = "";
            if (suggestion_disease.startsWith("Yes")) {
                disease_from_biosample_attribute = "From Biosample: " + suggestion_disease;
            }
            String disease_found = "";
            String disease_text_parsed_confidence = "";
            for (String disease : list_of_diseases) {
                if (StringUtils.containsIgnoreCase(studyName, disease)
                        || StringUtils.containsIgnoreCase(studyTitle, disease)) {
                    checkboxDiseaseYes.setValue(true);
                    disease_found = disease_found + disease + " ";
                    disease_text_parsed_confidence = "keyword found in Study or Title";
                }
            }
            String diseaseLabelString = "";
            if (disease_text_parsed_confidence.length() > 1) {
                diseaseLabelString = "<b><i>Suggestion: </i></b>" + disease_found
                        + " <b> <i> Confidence: <i></b>  " + disease_text_parsed_confidence;
            }
            if (disease_from_biosample_attribute.length() > 1) {
                diseaseLabelString = diseaseLabelString + "<b><i>Suggestion: </i></b>"
                        + disease_from_biosample_attribute + " <b> <i> Confidence: <i></b>  "
                        + disease_confidence;
            }

            Label diseaseLabel = new Label(diseaseLabelString, ContentMode.HTML);
            Label diseaseTitle = new Label("<b>Disease: </b>", ContentMode.HTML);
            diseaseLayout.addComponent(diseaseTitle);
            diseaseLayout.addComponent(checkboxDiseaseNo);
            diseaseLayout.addComponent(checkboxDiseaseYes);
            diseaseLayout.addComponent(diseaseLabel);

            HorizontalLayout caseControlLayout = new HorizontalLayout();
            CheckBox checkboxCaseControlYes = new CheckBox("Yes");
            CheckBox checkboxCaseControlNo = new CheckBox("No");
            checkboxDiseaseYes.setValue(true);
            Label caseControlTitle = new Label("<b>Case-Control: </b>", ContentMode.HTML);
            caseControlLayout.addComponent(caseControlTitle);
            caseControlLayout.addComponent(checkboxCaseControlYes);
            caseControlLayout.addComponent(checkboxCaseControlNo);

            HorizontalLayout timeSeriesLayout = new HorizontalLayout();
            CheckBox checkboxTimeSerieslYes = new CheckBox("Yes");
            CheckBox checkboxTimeSeriesNo = new CheckBox("No");
            checkboxDiseaseYes.setValue(true);
            Label timeSeriesTitle = new Label("<b>Time Series: </b>", ContentMode.HTML);
            timeSeriesLayout.addComponent(timeSeriesTitle);
            timeSeriesLayout.addComponent(checkboxTimeSerieslYes);
            timeSeriesLayout.addComponent(checkboxTimeSeriesNo);

            HorizontalLayout diseaseCategoriesLayout = new HorizontalLayout();
            Label diseaseCategoryLabel = new Label("<b><i>Suggestion: </i></b>" + disease_found
                    + " <b> <i> Confidence: <i></b>  " + disease_confidence, ContentMode.HTML);
            String[] diseaseCategories = new String[] { "Complex Disease", "Rare Disease", "Other",
                    "Not Sure" };
            List<String> diseaseCategoriesList = Arrays.asList(diseaseCategories);
            ComboBox diseaseCategoryComboBox = new ComboBox("Disease Category", diseaseCategoriesList);
            diseaseCategoriesLayout.addComponent(diseaseCategoryComboBox);
            diseaseCategoriesLayout.addComponent(diseaseCategoryLabel);

            String[] platforms = new String[] { "Illumina", "SOLID", "Roche 454", "PacBio", "Helicos",
                    "Complete Genomics" };
            List<String> platformsList = Arrays.asList(platforms);
            ComboBox platformsListComboBox = new ComboBox("Sequencing Platform", platformsList);
            Set<String> matchedPlatformSet = new HashSet();
            String platform_from_sra = "";
            String platorm_confidence = "";
            int matchPlatformCount = 0;
            for (String[] val : platformMap.values()) {
                if (val.length > 1) {
                    for (String pf : platforms) {
                        if (val[0].equalsIgnoreCase(pf)) {
                            matchedPlatformSet.add(pf);
                            matchPlatformCount = matchPlatformCount + 1;
                        }
                    }
                } else {

                }
            }
            if (matchedPlatformSet.isEmpty()) {
                platform_from_sra = "Match Not Found";
            } else {
                if (matchedPlatformSet.size() == matchPlatformCount) {
                    //Ideally this shouldn't be the case. 
                    // This suggests that all experiments of this project are run on different platforms or
                    // it has only one expriment
                    if (matchedPlatformSet.size() == 1) {
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        platformsListComboBox.select(platform_from_sra);
                    } else {
                        platform_from_sra = "Can't predict. All experiment on different Platforms";
                    }
                } else {
                    if (matchedPlatformSet.size() == 1) {
                        // Perfect 
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        platformsListComboBox.select(platform_from_sra);
                        platorm_confidence = "100%";
                    } else {

                    }
                }
            }

            HorizontalLayout platformLayout = new HorizontalLayout();
            Label suggestedPlatformLabel = new Label("<b><i>Suggestion: </i></b>" + platform_from_sra
                    + "<b> <i> Confidence: <i></b>  " + platorm_confidence, ContentMode.HTML);
            platformLayout.addComponent(platformsListComboBox);
            platformLayout.addComponent(suggestedPlatformLabel);

            VerticalLayout sampleTypesLayout = new VerticalLayout();
            CheckBox checkboxSampleTypeCellLine = new CheckBox("Cell Line");
            CheckBox checkboxSampleTypeTissue = new CheckBox("Tissue");
            CheckBox checkboxSampleTypeStemCells = new CheckBox("Stem Cells");
            CheckBox checkboxSampleTypeWholeBlood = new CheckBox("Whole Blood");
            CheckBox checkboxSampleTypePlasma = new CheckBox("Plasma");
            String suggestedCellTypeLabelString = "";
            if (suggestion_cell_line.startsWith("Yes")) {
                //sampleTypesListComboBox.select("Cell Lines");
                checkboxSampleTypeCellLine.setValue(true);
                suggestedCellTypeLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> "
                        + suggestion_cell_line + " <b> <i> Confidence: <i></b>   " + cell_line_confidence;
            }
            Label suggestedCellLineLabel = new Label(suggestedCellTypeLabelString, ContentMode.HTML);
            String suggestedTissueLabelString = "";
            if (suggestion_organism_part.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString + "<b><i>Suggestion: </i></b>"
                        + "Organism part --> " + suggestion_organism_part + " <b> <i> Confidence: <i></b>   "
                        + organism_part_confidence;
            }

            if (suggestion_tissue.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString + "<b><i>Suggestion: </i></b>"
                        + "Tissue --> " + suggestion_tissue + " <b> <i> Confidence: <i></b>   "
                        + tissue_confidence;
            }
            Label suggestedTissueLabel = new Label(suggestedTissueLabelString, ContentMode.HTML);

            String suggestedStemCellString = "";
            /*
             if (suggestion_stem_cell.startsWith("Yes")) {                   
             checkboxSampleTypeStemCells.setValue(true);
             suggestedCellTypeLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_stem_cell + " <b> <i> Confidence: <i></b>   " + stem_cell_confidence;
             }
             */
            Label suggestedStemCellLabel = new Label(suggestedStemCellString, ContentMode.HTML);

            String suggestedWholeBloodLabelString = "";
            /*
             if (suggestion_whole_blood.startsWith("Yes")) {                   
             checkboxSampleTypeWholeBlood.setValue(true);
             suggestedWholeBloodLabelString = "<b><i>Suggestion: </i></b>" + "Whole Blood --> " + suggestion_whole_blood + " <b> <i> Confidence: <i></b>   " + whole_blood_confidence;
             }
             */
            Label suggestedWholeBloodLabel = new Label(suggestedWholeBloodLabelString, ContentMode.HTML);

            String suggestedPlasmaLabelString = "";
            /*
             if (suggestion_plasma.startsWith("Yes")) {                   
             checkboxSampleTypePlasma.setValue(true);
             suggestedPlasmaLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_plasma + " <b> <i> Confidence: <i></b>   " + plasma_confidence;
             }
             */
            Label suggestedPlasmaLabel = new Label(suggestedPlasmaLabelString, ContentMode.HTML);

            HorizontalLayout CellLineLayout = new HorizontalLayout();
            CellLineLayout.addComponent(checkboxSampleTypeCellLine);
            CellLineLayout.addComponent(suggestedCellLineLabel);

            HorizontalLayout TissueLayout = new HorizontalLayout();
            TissueLayout.addComponent(checkboxSampleTypeTissue);
            TissueLayout.addComponent(suggestedTissueLabel);

            HorizontalLayout WholeBloodLayout = new HorizontalLayout();
            WholeBloodLayout.addComponent(checkboxSampleTypeWholeBlood);
            WholeBloodLayout.addComponent(suggestedWholeBloodLabel);

            HorizontalLayout PlasmaLayout = new HorizontalLayout();
            PlasmaLayout.addComponent(checkboxSampleTypePlasma);
            PlasmaLayout.addComponent(suggestedPlasmaLabel);

            sampleTypesLayout.addComponent(CellLineLayout);
            sampleTypesLayout.addComponent(TissueLayout);
            sampleTypesLayout.addComponent(WholeBloodLayout);
            sampleTypesLayout.addComponent(PlasmaLayout);

            Button addCustomAnnoButton = new Button("++ Custom Annotation");
            addCustomAnnoButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    custom_annotation_counter = custom_annotation_counter + 1;
                    HorizontalLayout customLayout = new HorizontalLayout();
                    TextField customAnnoName = new TextField("Custom Name");
                    customAnnoName.setId("customAnnoName" + custom_annotation_counter);
                    TextField customAnnoValue = new TextField("Custom Value");
                    customLayout.addComponent(customAnnoName);
                    customLayout.addComponent(customAnnoValue);
                    customAnnoValue.setId("customAnnoValue" + custom_annotation_counter);
                    int addCustomAnnoButtonIndex = rightTopAnnotationForm
                            .getComponentIndex(addCustomAnnoButton);
                    rightTopAnnotationForm.addComponent(customLayout, addCustomAnnoButtonIndex);

                }
            });

            //<editor-fold defaultstate="collapsed" desc="Replicate Type">
            HorizontalLayout replicatTypesLayout = new HorizontalLayout();
            String replicateType_from_sra = "";
            String replicateType_confidence = "";
            Label suggestedreplicatTypeLabel = new Label("<b><i>Suggestion: </i></b>" + replicateType_from_sra
                    + " <b> <i> Confidence: <i></b>  " + replicateType_confidence, ContentMode.HTML);
            String[] replicatTypes = new String[] { "Biological -- different individuals",
                    "Biological -- same individual but severe treatment to RNA",
                    "Semi Biological/Technical -- mild treatment",
                    "Technical -- machine parameter or buffer (very mild)" };
            List<String> replicatTypesList = Arrays.asList(replicatTypes);
            ComboBox replicatTypesListComboBox = new ComboBox("Replicates Type ", replicatTypesList);
            replicatTypesLayout.addComponent(replicatTypesListComboBox);
            replicatTypesLayout.addComponent(suggestedreplicatTypeLabel);

            //</editor-fold>
            checkboxDiseaseYes.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseNo.setValue(!checkboxDiseaseYes.getValue());
                    diseaseCategoryComboBox.setVisible(true);
                }
            });
            checkboxDiseaseNo.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseYes.setValue(!checkboxDiseaseNo.getValue());
                    diseaseCategoryComboBox.setVisible(false);
                }
            });

            //<editor-fold defaultstate="collapsed" desc="CheckBox Annotation Ongoing or Completed ">
            CheckBox checkboxAnnotaionCompleted = new CheckBox("Annotaion Completed");
            CheckBox checkboxAnnotaionOngoing = new CheckBox("Annotaion Ongoing");
            checkboxAnnotaionOngoing.setValue(true);
            checkboxAnnotaionCompleted.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionOngoing.setValue(!checkboxAnnotaionCompleted.getValue());
                }
            });
            checkboxAnnotaionOngoing.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionCompleted.setValue(!checkboxAnnotaionOngoing.getValue());
                }
            });
            //</editor-fold>

            HorizontalLayout annotationStatusLayout = new HorizontalLayout();
            annotationStatusLayout.addComponent(checkboxAnnotaionOngoing);
            annotationStatusLayout.addComponent(checkboxAnnotaionCompleted);

            Button submitButton = new Button("Submit");
            submitButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    int diseaseBoolean = 0;
                    if (checkboxDiseaseYes.getValue() && !checkboxDiseaseNo.getValue()) {
                        diseaseBoolean = 1;
                    }
                    int caseControlBoolean = 0;
                    if (checkboxCaseControlYes.getValue() && !checkboxCaseControlNo.getValue()) {
                        caseControlBoolean = 1;
                    }
                    for (int j = 1; j <= custom_annotation_counter; j++) {
                        if (findById(rightTopAnnotationForm, "customAnnoName" + j) instanceof TextField) {
                            TextField tempTFname = (TextField) findById(rightTopAnnotationForm,
                                    "customAnnoName" + j);
                            System.out.println(j + "custom name: " + tempTFname.getValue());
                        }
                        if (findById(rightTopAnnotationForm, "customAnnoValue" + j) instanceof TextField) {
                            TextField tempTFvalue = (TextField) findById(rightTopAnnotationForm,
                                    "customAnnoValue" + j);
                            System.out.println(j + "custom value: " + tempTFvalue.getValue());
                        }
                    }

                    //Notification.show("Do not press this button again");
                }
            });

            rightTopAnnotationForm.addComponent(diseaseLayout);
            rightTopAnnotationForm.addComponent(caseControlLayout);
            rightTopAnnotationForm.addComponent(timeSeriesLayout);
            rightTopAnnotationForm.addComponent(diseaseCategoriesLayout);
            rightTopAnnotationForm.addComponent(platformLayout);
            rightTopAnnotationForm.addComponent(sampleTypesLayout);
            rightTopAnnotationForm.addComponent(replicatTypesLayout);
            rightTopAnnotationForm.addComponent(addCustomAnnoButton);
            rightTopAnnotationForm.addComponent(annotationStatusLayout);
            rightTopAnnotationForm.addComponent(submitButton);
            //</editor-fold>
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="fill tree in right bottom">
            Iterator iterator = biosampleSet.iterator();

            // check values
            while (iterator.hasNext()) {
                //  System.out.println("Value: "+ iterator.next() + " ");
                String bsample = iterator.next().toString();
                String[] biosample_parts = bsample.split("\\|");
                String biosample_acc = biosample_parts[0];
                tree.addItem(biosample_acc);
                tree.setParent(biosample_acc, selectedStudy);
                tree.setItemCaption(biosample_acc, "BioSample: " + biosample_acc);
            }
            Set expMap_entrset = expMap.entrySet();
            Iterator it = expMap_entrset.iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
                String[] expParts = expDetailMap.get(me.getKey());
                String expTitle = "";
                if (expParts.length > 3) {
                    expTitle = expParts[3];
                }
                tree.addItem(me.getKey());
                tree.setParent(me.getKey(), me.getValue());
                tree.setItemCaption(me.getKey(), "Experiment: " + me.getKey() + ": " + expTitle);
            }

            Set runMap_entrset = runMap.entrySet();
            Iterator runit = runMap_entrset.iterator();
            while (runit.hasNext()) {
                Map.Entry runEntry = (Map.Entry) runit.next();
                tree.addItem(runEntry.getKey());
                tree.setParent(runEntry.getKey(), runEntry.getValue());
                tree.setItemCaption(runEntry.getKey(), "Run: " + runEntry.getKey());
            }

            tree.expandItemsRecursively(selectedStudy);

            //</editor-fold>
        }
    });

    tree.setSelectable(true);
    tree.setImmediate(true);
    tree.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            Object id = event.getProperty().getValue();
            if (id != null) {
                String selectedTreeId = id.toString();
                String selectedTreeItem = tree.getItemCaption(id).toString();
                System.out.println("Tree event is fired: " + selectedTreeItem);
                if (selectedTreeItem.startsWith("BioSample")) {

                    myform.removeAllComponents();
                    SQLContainer tempContainer = createMySQLContainer("biosample", selectedTreeId);
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String accessType = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("AccessType").getValue().toString();
                        String publicationDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("PublicationDate").getValue().toString();
                        String lastUpdate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("LastUpdate").getValue().toString();
                        String accession = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Accession").getValue().toString();
                        String title = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Title").getValue().toString();
                        String taxonomy_id = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyId").getValue().toString();
                        String taxonomy_name = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyName").getValue().toString();
                        String samplePackage = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Package").getValue().toString();
                        String status = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Status").getValue().toString();
                        String statusTime = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("StatusTime").getValue().toString();
                        String sampleIds = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Ids").getValue().toString();
                        String attributes = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Attributes").getValue().toString();
                        String models = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Models").getValue().toString();
                        String submissionDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("SubmissionDate").getValue().toString();
                        String owner = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Owner").getValue().toString();

                        String[] myfields = new String[] { accessType, publicationDate, lastUpdate, accession,
                                title, taxonomy_id, taxonomy_name, samplePackage, status, statusTime, sampleIds,
                                attributes, models, submissionDate, owner };
                        /*
                         for (String fieldName : myfields) {
                         Label tempLabl = new Label("");
                         }
                         */
                        Label labelAccessType = new Label("Access Type: " + accessType);
                        myform.addComponent(labelAccessType);
                        Label labelPublicationDate = new Label("Publication Date: " + publicationDate);
                        myform.addComponent(labelPublicationDate);
                        Label labelLastUpdate = new Label("Last Update: " + lastUpdate);
                        myform.addComponent(labelLastUpdate);
                        Label labelAccession = new Label("Accession: " + accession);
                        myform.addComponent(labelAccession);
                        Label labelTitle = new Label("<b>Title: </b>" + title, ContentMode.HTML);
                        myform.addComponent(labelTitle);
                        Label labelTaxonomyId = new Label("Taxonomy Id: " + taxonomy_id);
                        myform.addComponent(labelTaxonomyId);
                        Label labelTaxonomyName = new Label("Taxonomy Name: " + taxonomy_name);
                        myform.addComponent(labelTaxonomyName);
                        Label labelPackage = new Label("Package: " + samplePackage);
                        myform.addComponent(labelPackage);
                        Label labelStatus = new Label("Status: " + status);
                        myform.addComponent(labelStatus);
                        Label labelStatusTime = new Label("Status Time: " + statusTime);
                        myform.addComponent(labelStatusTime);
                        Label labelOwner = new Label("Owner: " + owner);
                        myform.addComponent(labelOwner);

                        String[] id_parts = sampleIds.split("\\:\\-");
                        if (id_parts.length > 1) {
                            String[] id_dbs = id_parts[0].split("\\|");
                            String[] id_values = id_parts[1].split("\\|");
                            for (int j = 0; j < id_dbs.length; j++) {
                                Label tempLabel = new Label(id_dbs[j] + ": " + id_values[j]);
                                myform.addComponent(tempLabel);

                            }
                        }

                        String[] attribute_parts = attributes.split("\\:\\-");
                        if (attribute_parts.length > 1) {
                            String[] attribute_names = attribute_parts[0].split("\\|");
                            String[] attribute_values = attribute_parts[1].split("\\|");
                            for (int j = 0; j < attribute_names.length; j++) {
                                Label tempLabel = new Label(
                                        "<b>" + attribute_names[j] + ": </b>" + attribute_values[j],
                                        ContentMode.HTML);
                                myform.addComponent(tempLabel);
                                System.out.println("inside attributes ");

                            }
                        }

                        //   TextField field = new TextField(lastDpdate);
                        // myform.addComponent(field);
                        //field.setWidth("100%");
                    }
                }
                if (selectedTreeItem.startsWith("Experiment")) {
                    SQLContainer tempContainer = createMySQLContainer("sra_rnaseq_exp", selectedTreeId);
                    myform.removeAllComponents();
                    Map expMap = new HashMap();
                    Map<String, String[]> expDetailMap = new HashMap<>();
                    Map<String, String[]> libraryDetailMap = new HashMap<>();
                    Map<String, String[]> platformMap = new HashMap<>();
                    Map runMap = new HashMap();
                    HashSet<String> biosampleSet = new HashSet<>();
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String docid = tempContainer.getIdByIndex(i).toString();
                        String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                        biosampleSet.add(biosample);
                        String[] b_parts = biosample.split("\\|");

                        String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                        String[] exp_parts = exp.split("\\|");
                        String exp_acc = exp_parts[0];
                        expMap.put(exp_acc, b_parts[0]);
                        expDetailMap.put(exp_acc, exp_parts);

                        String library_string = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Library_Name_Strategy_Source_Selection_Layout").getValue()
                                .toString();
                        String[] library_parts = library_string.split("\\|");
                        String library_name = "";
                        String library_strategy = "";
                        String library_source = "";
                        String library_selection = "";
                        String library_layout = "";
                        if (library_parts.length > 0) {
                            library_name = library_parts[0];
                        }
                        if (library_parts.length > 1) {
                            library_strategy = "<b> <i> Strategy </i> </b>" + library_parts[1];
                        }
                        if (library_parts.length > 2) {
                            library_source = "<b> <i> Source </i> </b>" + library_parts[2];
                        }
                        if (library_parts.length > 3) {
                            library_selection = "<b> <i> Selection </i> </b>" + library_parts[3];
                        }
                        if (library_parts.length > 4) {
                            String tempLayout = library_parts[4];
                            tempLayout = tempLayout.replaceAll("<", "");
                            tempLayout = tempLayout.replaceAll("/>", "");
                            library_layout = "<b> <i> Layout </i> </b>" + tempLayout;
                        }
                        String[] tempStringArray = new String[] { library_strategy, library_source,
                                library_selection, library_layout };
                        if (library_name.length() > 1) {
                            libraryDetailMap.put(library_name, tempStringArray);
                        }

                        String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Platform_InstrumentModel").getValue().toString();
                        String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                        platformMap.put(exp_acc, sra_plaforms_parts);

                        String run = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Runs").getValue().toString();
                        String[] run_parts = run.split("\\|");
                        if (run_parts.length > 0) {
                            for (int j = 0; j < run_parts.length; j++) {
                                String temprun = run_parts[j];
                                String[] temprun_parts = temprun.split("\\,");
                                runMap.put(temprun_parts[0], exp_acc);
                            }
                        }
                    }
                    Label labelExperimentAcc = new Label("<b>Experiment Accession: </b>" + selectedTreeId,
                            ContentMode.HTML);
                    myform.addComponent(labelExperimentAcc);
                    String libraryDetails = "";
                    for (Map.Entry<String, String[]> entry : libraryDetailMap.entrySet()) {
                        libraryDetails = libraryDetails + entry.getKey();
                        String[] temp_library_details = entry.getValue();
                        for (String dt : temp_library_details) {
                            libraryDetails = libraryDetails + dt;
                        }
                    }
                    Label labelLibraryDetails = new Label("<b>Library Details: </b>" + libraryDetails,
                            ContentMode.HTML);
                    myform.addComponent(labelLibraryDetails);

                }
            } else {
                System.out.println("id is null");
            }
        }

    });

    bioprojectSummaryTable.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            Object contactId = bioprojectSummaryTable.getValue();

            //Binding data
            //When a contact is selected from the list, we want to show that in our editor on the right. This is nicely done by the FieldGroup that binds all the fields to the corresponding Properties in our contact at once.                                if (contactId != null)
            //                           editorFields.setItemDataSource(bioprojectSummaryTable.getItem(contactId));
            //                  editorLayout.setVisible(contactId != null);
        }
    });

}

From source file:edu.cornell.qatarmed.planrnaseq.AnnotateView.java

private void initDataAndSubcomponent() {
    rnaseqContainer = createMySQLContainer("study_summary", "dummy");
    bioprojectSummaryTable.setContainerDataSource(rnaseqContainer);
    //   bioprojectSummaryTable.setVisibleColumns(new String[] { studyName });
    bioprojectSummaryTable.setSelectable(true);
    bioprojectSummaryTable.setImmediate(true);
    bioprojectSummaryTable.setColumnReorderingAllowed(true);
    bioprojectSummaryTable.setSortEnabled(true);
    bioprojectSummaryTable.setVisibleColumns(
            new Object[] { "Study", "title", "name", "Numsample", "Numexp", "Numrun", "Avgspots", "avgbases" });
    //bioprojectSummaryTable.setVisibleColumns(new Object[] { "firstName", "lastName", "department", "phoneNumber", "street", "city", "zipCode" });
    studyName.setValue(rnaseqContainer.firstItemId().toString());
    bioprojectSummaryTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        int custom_annotation_counter = 0;

        public void itemClick(ItemClickEvent event) {
            //<editor-fold defaultstate="collapsed" desc="filling study details on right panel">

            Object selectedStudyObject = event.getItemId();
            bioprojectSummaryTable.select(selectedStudyObject);
            tree.removeAllItems();//  w  w  w.  j av  a 2s  .com
            rightTopForm.removeAllComponents();
            rightTopAnnotationForm.removeAllComponents();
            myform.removeAllComponents();

            String selectedStudy = selectedStudyObject.toString();
            String studyTitle = (String) bioprojectSummaryTable
                    .getContainerProperty(selectedStudyObject, "title").getValue();
            String studyName = (String) bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "name")
                    .getValue();
            String studyNumsample = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numsample").getValue());
            String studyNumexp = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numexp").getValue());
            String studyNumrun = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numrun").getValue());
            String studyAvgspots = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Avgspots").getValue());
            String studyAvgbases = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "avgbases").getValue());
            tree.addItem(selectedStudy);
            tree.setItemCaption(selectedStudy, "Study: " + selectedStudy);
            SQLContainer tempContainer = createMySQLContainer("study_extdb", selectedStudy); // In this table I will chaeck for the manual annotation status
            String extdbid = tempContainer.getItem(tempContainer.getIdByIndex(0)).getItemProperty("extdb")
                    .getValue().toString();
            Label labelStudyAcc = new Label("<b>SRA Study Accession : </b>" + selectedStudy, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAcc);
            Label labelStudyTitle = new Label("<b>Study Title: </b>" + studyTitle, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyTitle);
            Label labelStudyName = new Label("<b>Study Name: </b>" + studyName, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyName);
            Label labelStudyNumsample = new Label("<b>Total number of samples: </b>" + studyNumsample,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumsample);
            Label labelStudyNumexp = new Label(
                    "<b>Total number of experiments (each experiment uses any one of the samples): </b>"
                            + studyNumexp,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumexp);
            Label labelStudyNumrun = new Label(
                    "<b>Total number of runs ( an experiment can have multiple runs) : </b>" + studyNumrun,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumrun);
            Label labelStudyAvgspots = new Label(
                    "<b>Avg number of spots or reads (per run): </b>" + studyAvgspots, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgspots);
            Label labelStudyAvgbases = new Label("<b>Avg number of bases (per run): </b>" + studyAvgbases,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgbases);
            if (extdbid.startsWith("PRJ")) {
                //<editor-fold defaultstate="collapsed" desc="if PRJ">
                tempContainer = createMySQLContainer("bioproject_details", extdbid);
                String bioproject_accession = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectAccession").getValue().toString();
                String bioproject_id = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectId").getValue().toString();
                String bioproject_name = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Name").getValue().toString();
                String bioproject_title = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Title").getValue().toString();
                String bioproject_description = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Description").getValue().toString();
                String bioproject_capture = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Capture").getValue().toString();
                String bioproject_material = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Material").getValue().toString();
                String bioproject_method = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("MethodType").getValue().toString();
                String bioproject_datatype = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("DataType").getValue().toString();
                String bioproject_sampleScope = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("SampleScope").getValue().toString();
                System.out.println(bioproject_description);
                Label labelBioprojectAccession = new Label(
                        "<b>Bioproject Accession : </b>" + bioproject_accession, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectAccession);
                Label labelBioprojectId = new Label("<b>Bioproject Id : </b>" + bioproject_id,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectId);
                Label labelBioprojectTitle = new Label("<b>Bioproject Title : </b>" + bioproject_title,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectTitle);
                Label labelBioprojectName = new Label("<b>Bioproject Name : </b>" + bioproject_name,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectName);
                Label labelBioprojectDescription = new Label(
                        "<b>Bioproject Description : </b>" + bioproject_description, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDescription);
                Label labelBioprojectCapture = new Label("<b>Bioproject Capture : </b>" + bioproject_capture,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectCapture);
                Label labelBioprojectMaterial = new Label(
                        "<b>Bioproject  Material : </b>" + bioproject_material, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMaterial);
                Label labelBioprojectMethod = new Label("<b>Bioproject Method : </b>" + bioproject_method,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMethod);
                Label labelBioprojectDatatype = new Label(
                        "<b>Bioproject Data Type : </b>" + bioproject_datatype, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDatatype);
                Label labelBioprojectSampleScope = new Label(
                        "<b>Bioproject Sample Scope : </b>" + bioproject_sampleScope, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectSampleScope);

                //</editor-fold>
            }
            if (extdbid.startsWith("GSE")) {
                //<editor-fold defaultstate="collapsed" desc="if GSE">
                tempContainer = createMySQLContainer("study_gse_details", extdbid);
                String gse_accesion = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("gse").getValue().toString();
                String gse_summary = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("summary").getValue().toString();
                String gse_design = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("overall_design").getValue().toString();
                System.out.println(gse_summary);
                Label labelGSE = new Label("<b>GEO Series Accession : </b>" + gse_accesion, ContentMode.HTML);
                rightTopForm.addComponent(labelGSE);
                Label labelGseSummary = new Label("<b>GSE Summary : </b>" + gse_summary, ContentMode.HTML);
                rightTopForm.addComponent(labelGseSummary);
                Label labelGseDesign = new Label("<b>GSE Design : </b>" + gse_design, ContentMode.HTML);
                rightTopForm.addComponent(labelGseDesign);
                //</editor-fold>

            }
            //</editor-fold>
            //SQLContainer tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            //  List<String> list = new ArrayList<String>();
            Map expMap = new HashMap();
            Map<String, String[]> expDetailMap = new HashMap<>();
            Map<String, String[]> platformMap = new HashMap<>();
            Map runMap = new HashMap();
            HashSet<String> biosampleSet = new HashSet<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for loop">

                String docid = tempContainer.getIdByIndex(i).toString();
                String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                biosampleSet.add(biosample);
                String[] b_parts = biosample.split("\\|");

                String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                String[] exp_parts = exp.split("\\|");
                String exp_acc = exp_parts[0];
                expMap.put(exp_acc, b_parts[0]);
                expDetailMap.put(exp_acc, exp_parts);

                String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Platform_InstrumentModel").getValue().toString();
                String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                platformMap.put(exp_acc, sra_plaforms_parts);

                String run = tempContainer.getItem(tempContainer.getIdByIndex(i)).getItemProperty("Runs")
                        .getValue().toString();
                String[] run_parts = run.split("\\|");
                if (run_parts.length > 0) {
                    for (int j = 0; j < run_parts.length; j++) {
                        String temprun = run_parts[j];
                        String[] temprun_parts = temprun.split("\\,");
                        runMap.put(temprun_parts[0], exp_acc);
                    }
                }
                //</editor-fold>
            }

            //<editor-fold defaultstate="collapsed" desc="Manual Annotaion">
            tempContainer = createMySQLContainer("biosample_with_studyacc", selectedStudy);
            int count_cell_line = 0;
            int count_organism_part = 0;
            int count_tissue = 0;
            int count_disease = 0;
            Set<String> cell_lines_set = new HashSet();
            Set<String> organism_part_set = new HashSet();
            Set<String> tissue_set = new HashSet();
            Set<String> disease_set = new HashSet();
            Map<String, Integer> cell_line_stat_map = new HashMap<>();
            Map<String, Integer> organism_part_stat_map = new HashMap<>();
            Map<String, Integer> tissue_stat_map = new HashMap<>();
            Map<String, Integer> disease_stat_map = new HashMap<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for biosample attributes">
                String biosample_attr = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Attributes").getValue().toString();
                String[] biosample_attr_parts = biosample_attr.split("\\:-");
                if (biosample_attr_parts.length > 0) {
                    String[] attr_names = biosample_attr_parts[0].split("\\|");
                    String[] attr_values = new String[] {};
                    if (biosample_attr_parts.length > 1) {
                        attr_values = biosample_attr_parts[1].split("\\|");
                    }
                    int atn_index = 0;
                    for (String atn : attr_names) {
                        if (atn.equalsIgnoreCase("cell line")) {
                            count_cell_line = count_cell_line + 1;
                            if (attr_values.length >= atn_index) {
                                String cell_line_value = attr_values[atn_index];
                                cell_lines_set.add(cell_line_value);
                                if (cell_line_stat_map.containsKey(cell_line_value)) {
                                    cell_line_stat_map.put(cell_line_value,
                                            cell_line_stat_map.get(cell_line_value) + 1);
                                } else {
                                    cell_line_stat_map.put(cell_line_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("organism part")) {
                            count_organism_part = count_organism_part + 1;
                            if (attr_values.length >= atn_index) {
                                String organism_part_value = attr_values[atn_index];
                                organism_part_set.add(organism_part_value);
                                if (organism_part_stat_map.containsKey(organism_part_value)) {
                                    organism_part_stat_map.put(organism_part_value,
                                            organism_part_stat_map.get(organism_part_value) + 1);
                                } else {
                                    organism_part_stat_map.put(organism_part_value, 1);
                                }
                            }

                        }

                        if (atn.contains("disease")) {
                            count_disease = count_disease + 1;
                            if (attr_values.length >= atn_index) {
                                String disease_value = attr_values[atn_index];
                                disease_set.add(disease_value);
                                if (disease_stat_map.containsKey(disease_value)) {
                                    disease_stat_map.put(disease_value,
                                            disease_stat_map.get(disease_value) + 1);
                                } else {
                                    disease_stat_map.put(disease_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("tissue")) {
                            count_tissue = count_tissue + 1;
                            if (attr_values.length >= atn_index) {
                                String tissue_value = attr_values[atn_index];
                                tissue_set.add(tissue_value);
                                if (tissue_stat_map.containsKey(tissue_value)) {
                                    tissue_stat_map.put(tissue_value, tissue_stat_map.get(tissue_value) + 1);
                                } else {
                                    tissue_stat_map.put(tissue_value, 1);
                                }
                            }

                        }
                        atn_index = atn_index + 1;
                    }
                }
                //</editor-fold>

            }

            String suggestion_cell_line = "";
            String suggestion_organism_part = "";
            String suggestion_tissue = "";
            String suggestion_disease = "";
            String samplesType_from_sra = "";
            String cell_line_confidence = "";
            String organism_part_confidence = "";
            String disease_confidence = "";
            String tissue_confidence = "";
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has cell line">
            if (count_cell_line > 0) {
                if (Integer.parseInt(studyNumsample) == count_cell_line) {
                    //good. all samples are from cell lines
                    suggestion_cell_line = "Yes:";
                    String cell_line_value = cell_lines_set.iterator().next();
                    suggestion_cell_line = suggestion_cell_line + cell_line_value;
                    cell_line_confidence = "100%. All " + cell_line_stat_map.get(cell_line_value).toString()
                            + " Samples";
                } else {
                    suggestion_cell_line = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : cell_line_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_cell_line = suggestion_cell_line + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    cell_line_confidence = confidence_percent + "%";
                    for (Iterator<String> it = cell_lines_set.iterator(); it.hasNext();) {
                        String cellLine = it.next();
                        if (cellLine.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_cell_line = suggestion_cell_line + ", " + cellLine + "("
                                    + cell_line_stat_map.get(cellLine).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_cell_line = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has organism part">
            if (count_organism_part > 0) {
                if (Integer.parseInt(studyNumsample) == count_organism_part) {
                    //good. all samples are from cell lines
                    suggestion_organism_part = "Yes:";
                    String organism_part_value = organism_part_set.iterator().next();
                    suggestion_organism_part = suggestion_organism_part + organism_part_value;
                    organism_part_confidence = "100%. All "
                            + organism_part_stat_map.get(organism_part_value).toString() + " Samples";
                } else {
                    suggestion_organism_part = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : organism_part_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_organism_part = suggestion_organism_part + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    organism_part_confidence = confidence_percent + "%";
                    for (Iterator<String> it = organism_part_set.iterator(); it.hasNext();) {
                        String organismPart = it.next();
                        if (organismPart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_organism_part = suggestion_organism_part + ", " + organismPart + "("
                                    + organism_part_stat_map.get(organismPart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_organism_part = " No";
            }
            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has disease">
            if (count_disease > 0) {
                if (Integer.parseInt(studyNumsample) == count_disease) {
                    //good. all samples are from cell lines
                    suggestion_disease = "Yes:";
                    String disease_value = disease_set.iterator().next();
                    suggestion_disease = suggestion_disease + disease_value;
                    disease_confidence = "100%. All " + disease_stat_map.get(disease_value).toString()
                            + " Samples";
                } else {
                    suggestion_disease = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : disease_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_disease = suggestion_disease + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    disease_confidence = confidence_percent + "%";
                    for (Iterator<String> it = disease_set.iterator(); it.hasNext();) {
                        String diseasePart = it.next();
                        if (diseasePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_disease = suggestion_disease + ", " + diseasePart + "("
                                    + disease_stat_map.get(diseasePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_disease = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has tissue">
            if (count_tissue > 0) {
                if (Integer.parseInt(studyNumsample) == count_tissue) {
                    //good. all samples are from cell lines
                    suggestion_tissue = "Yes:";
                    String tissue_value = tissue_set.iterator().next();
                    suggestion_tissue = suggestion_tissue + tissue_value;
                    tissue_confidence = "100%. All " + tissue_stat_map.get(tissue_value).toString()
                            + " Samples";
                } else {
                    suggestion_tissue = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : tissue_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_tissue = suggestion_tissue + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    tissue_confidence = confidence_percent + "%";
                    for (Iterator<String> it = disease_set.iterator(); it.hasNext();) {
                        String tissuePart = it.next();
                        if (tissuePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_tissue = suggestion_tissue + ", " + tissuePart + "("
                                    + tissue_stat_map.get(tissuePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_tissue = " No";
            }

            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="filling right top manual annotation">
            HorizontalLayout diseaseLayout = new HorizontalLayout();
            CheckBox checkboxDiseaseYes = new CheckBox("Yes");
            CheckBox checkboxDiseaseNo = new CheckBox("No");

            String disease_from_biosample_attribute = "";
            if (suggestion_disease.startsWith("Yes")) {
                disease_from_biosample_attribute = "From Biosample: " + suggestion_disease;
            }
            String disease_found = "";
            String disease_text_parsed_confidence = "";
            for (String disease : list_of_diseases) {
                if (StringUtils.containsIgnoreCase(studyName, disease)
                        || StringUtils.containsIgnoreCase(studyTitle, disease)) {
                    checkboxDiseaseYes.setValue(true);
                    disease_found = disease_found + disease + " ";
                    disease_text_parsed_confidence = "keyword found in Study or Title";
                }
            }
            String diseaseLabelString = "";
            if (disease_text_parsed_confidence.length() > 1) {
                diseaseLabelString = "<b><i>Suggestion: </i></b>" + disease_found
                        + " <b> <i> Confidence: <i></b>  " + disease_text_parsed_confidence;
            }
            if (disease_from_biosample_attribute.length() > 1) {
                diseaseLabelString = diseaseLabelString + "<b><i>Suggestion: </i></b>"
                        + disease_from_biosample_attribute + " <b> <i> Confidence: <i></b>  "
                        + disease_confidence;
            }

            Label diseaseLabel = new Label(diseaseLabelString, ContentMode.HTML);
            Label diseaseTitle = new Label("<b>Disease: </b>", ContentMode.HTML);
            diseaseLayout.addComponent(diseaseTitle);
            diseaseLayout.addComponent(checkboxDiseaseNo);
            diseaseLayout.addComponent(checkboxDiseaseYes);
            diseaseLayout.addComponent(diseaseLabel);

            HorizontalLayout caseControlLayout = new HorizontalLayout();
            CheckBox checkboxCaseControlYes = new CheckBox("Yes");
            CheckBox checkboxCaseControlNo = new CheckBox("No");
            checkboxDiseaseYes.setValue(true);
            Label caseControlTitle = new Label("<b>Case-Control: </b>", ContentMode.HTML);
            caseControlLayout.addComponent(caseControlTitle);
            caseControlLayout.addComponent(checkboxCaseControlYes);
            caseControlLayout.addComponent(checkboxCaseControlNo);

            HorizontalLayout timeSeriesLayout = new HorizontalLayout();
            CheckBox checkboxTimeSerieslYes = new CheckBox("Yes");
            CheckBox checkboxTimeSeriesNo = new CheckBox("No");
            checkboxDiseaseYes.setValue(true);
            Label timeSeriesTitle = new Label("<b>Time Series: </b>", ContentMode.HTML);
            timeSeriesLayout.addComponent(timeSeriesTitle);
            timeSeriesLayout.addComponent(checkboxTimeSerieslYes);
            timeSeriesLayout.addComponent(checkboxTimeSeriesNo);

            HorizontalLayout diseaseCategoriesLayout = new HorizontalLayout();
            Label diseaseCategoryLabel = new Label("<b><i>Suggestion: </i></b>" + disease_found
                    + " <b> <i> Confidence: <i></b>  " + disease_confidence, ContentMode.HTML);
            String[] diseaseCategories = new String[] { "Complex Disease", "Rare Disease", "Other",
                    "Not Sure" };
            List<String> diseaseCategoriesList = Arrays.asList(diseaseCategories);
            ComboBox diseaseCategoryComboBox = new ComboBox("Disease Category", diseaseCategoriesList);
            diseaseCategoriesLayout.addComponent(diseaseCategoryComboBox);
            diseaseCategoriesLayout.addComponent(diseaseCategoryLabel);

            String[] platforms = new String[] { "Illumina", "SOLID", "Roche 454", "PacBio", "Helicos",
                    "Complete Genomics" };
            List<String> platformsList = Arrays.asList(platforms);
            ComboBox platformsListComboBox = new ComboBox("Sequencing Platform", platformsList);
            Set<String> matchedPlatformSet = new HashSet();
            String platform_from_sra = "";
            String platorm_confidence = "";
            int matchPlatformCount = 0;
            for (String[] val : platformMap.values()) {
                if (val.length > 1) {
                    for (String pf : platforms) {
                        if (val[0].equalsIgnoreCase(pf)) {
                            matchedPlatformSet.add(pf);
                            matchPlatformCount = matchPlatformCount + 1;
                        }
                    }
                } else {

                }
            }
            if (matchedPlatformSet.isEmpty()) {
                platform_from_sra = "Match Not Found";
            } else {
                if (matchedPlatformSet.size() == matchPlatformCount) {
                    //Ideally this shouldn't be the case. 
                    // This suggests that all experiments of this project are run on different platforms or
                    // it has only one expriment
                    if (matchedPlatformSet.size() == 1) {
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        platformsListComboBox.select(platform_from_sra);
                    } else {
                        platform_from_sra = "Can't predict. All experiment on different Platforms";
                    }
                } else {
                    if (matchedPlatformSet.size() == 1) {
                        // Perfect 
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        platformsListComboBox.select(platform_from_sra);
                        platorm_confidence = "100%";
                    } else {

                    }
                }
            }

            HorizontalLayout platformLayout = new HorizontalLayout();
            Label suggestedPlatformLabel = new Label("<b><i>Suggestion: </i></b>" + platform_from_sra
                    + "<b> <i> Confidence: <i></b>  " + platorm_confidence, ContentMode.HTML);
            platformLayout.addComponent(platformsListComboBox);
            platformLayout.addComponent(suggestedPlatformLabel);

            VerticalLayout sampleTypesLayout = new VerticalLayout();
            CheckBox checkboxSampleTypeCellLine = new CheckBox("Cell Line");
            CheckBox checkboxSampleTypeTissue = new CheckBox("Tissue");
            CheckBox checkboxSampleTypeStemCells = new CheckBox("Stem Cells");
            CheckBox checkboxSampleTypeWholeBlood = new CheckBox("Whole Blood");
            CheckBox checkboxSampleTypePlasma = new CheckBox("Plasma");
            String suggestedCellTypeLabelString = "";
            if (suggestion_cell_line.startsWith("Yes")) {
                //sampleTypesListComboBox.select("Cell Lines");
                checkboxSampleTypeCellLine.setValue(true);
                suggestedCellTypeLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> "
                        + suggestion_cell_line + " <b> <i> Confidence: <i></b>   " + cell_line_confidence;
            }
            Label suggestedCellLineLabel = new Label(suggestedCellTypeLabelString, ContentMode.HTML);
            String suggestedTissueLabelString = "";
            if (suggestion_organism_part.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString + "<b><i>Suggestion: </i></b>"
                        + "Organism part --> " + suggestion_organism_part + " <b> <i> Confidence: <i></b>   "
                        + organism_part_confidence;
            }

            if (suggestion_tissue.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString + "<b><i>Suggestion: </i></b>"
                        + "Tissue --> " + suggestion_tissue + " <b> <i> Confidence: <i></b>   "
                        + tissue_confidence;
            }
            Label suggestedTissueLabel = new Label(suggestedTissueLabelString, ContentMode.HTML);

            String suggestedStemCellString = "";
            /*
             if (suggestion_stem_cell.startsWith("Yes")) {                   
             checkboxSampleTypeStemCells.setValue(true);
             suggestedCellTypeLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_stem_cell + " <b> <i> Confidence: <i></b>   " + stem_cell_confidence;
             }
             */
            Label suggestedStemCellLabel = new Label(suggestedStemCellString, ContentMode.HTML);

            String suggestedWholeBloodLabelString = "";
            /*
             if (suggestion_whole_blood.startsWith("Yes")) {                   
             checkboxSampleTypeWholeBlood.setValue(true);
             suggestedWholeBloodLabelString = "<b><i>Suggestion: </i></b>" + "Whole Blood --> " + suggestion_whole_blood + " <b> <i> Confidence: <i></b>   " + whole_blood_confidence;
             }
             */
            Label suggestedWholeBloodLabel = new Label(suggestedWholeBloodLabelString, ContentMode.HTML);

            String suggestedPlasmaLabelString = "";
            /*
             if (suggestion_plasma.startsWith("Yes")) {                   
             checkboxSampleTypePlasma.setValue(true);
             suggestedPlasmaLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_plasma + " <b> <i> Confidence: <i></b>   " + plasma_confidence;
             }
             */
            Label suggestedPlasmaLabel = new Label(suggestedPlasmaLabelString, ContentMode.HTML);

            HorizontalLayout CellLineLayout = new HorizontalLayout();
            CellLineLayout.addComponent(checkboxSampleTypeCellLine);
            CellLineLayout.addComponent(suggestedCellLineLabel);

            HorizontalLayout TissueLayout = new HorizontalLayout();
            TissueLayout.addComponent(checkboxSampleTypeTissue);
            TissueLayout.addComponent(suggestedTissueLabel);

            HorizontalLayout WholeBloodLayout = new HorizontalLayout();
            WholeBloodLayout.addComponent(checkboxSampleTypeWholeBlood);
            WholeBloodLayout.addComponent(suggestedWholeBloodLabel);

            HorizontalLayout PlasmaLayout = new HorizontalLayout();
            PlasmaLayout.addComponent(checkboxSampleTypePlasma);
            PlasmaLayout.addComponent(suggestedPlasmaLabel);

            sampleTypesLayout.addComponent(CellLineLayout);
            sampleTypesLayout.addComponent(TissueLayout);
            sampleTypesLayout.addComponent(WholeBloodLayout);
            sampleTypesLayout.addComponent(PlasmaLayout);

            Button addCustomAnnoButton = new Button("++ Custom Annotation");
            addCustomAnnoButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    custom_annotation_counter = custom_annotation_counter + 1;
                    HorizontalLayout customLayout = new HorizontalLayout();
                    TextField customAnnoName = new TextField("Custom Name");
                    customAnnoName.setId("customAnnoName" + custom_annotation_counter);
                    TextField customAnnoValue = new TextField("Custom Value");
                    customLayout.addComponent(customAnnoName);
                    customLayout.addComponent(customAnnoValue);
                    customAnnoValue.setId("customAnnoValue" + custom_annotation_counter);
                    int addCustomAnnoButtonIndex = rightTopAnnotationForm
                            .getComponentIndex(addCustomAnnoButton);
                    rightTopAnnotationForm.addComponent(customLayout, addCustomAnnoButtonIndex);

                }
            });

            //<editor-fold defaultstate="collapsed" desc="Replicate Type">
            HorizontalLayout replicatTypesLayout = new HorizontalLayout();
            String replicateType_from_sra = "";
            String replicateType_confidence = "";
            Label suggestedreplicatTypeLabel = new Label("<b><i>Suggestion: </i></b>" + replicateType_from_sra
                    + " <b> <i> Confidence: <i></b>  " + replicateType_confidence, ContentMode.HTML);
            String[] replicatTypes = new String[] { "Biological -- different individuals",
                    "Biological -- same individual but severe treatment to RNA",
                    "Semi Biological/Technical -- mild treatment",
                    "Technical -- machine parameter or buffer (very mild)" };
            List<String> replicatTypesList = Arrays.asList(replicatTypes);
            ComboBox replicatTypesListComboBox = new ComboBox("Replicates Type ", replicatTypesList);
            replicatTypesLayout.addComponent(replicatTypesListComboBox);
            replicatTypesLayout.addComponent(suggestedreplicatTypeLabel);

            //</editor-fold>
            checkboxDiseaseYes.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseNo.setValue(!checkboxDiseaseYes.getValue());
                    diseaseCategoryComboBox.setVisible(true);
                }
            });
            checkboxDiseaseNo.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseYes.setValue(!checkboxDiseaseNo.getValue());
                    diseaseCategoryComboBox.setVisible(false);
                }
            });

            //<editor-fold defaultstate="collapsed" desc="CheckBox Annotation Ongoing or Completed ">
            CheckBox checkboxAnnotaionCompleted = new CheckBox("Annotaion Completed");
            CheckBox checkboxAnnotaionOngoing = new CheckBox("Annotaion Ongoing");
            checkboxAnnotaionOngoing.setValue(true);
            checkboxAnnotaionCompleted.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionOngoing.setValue(!checkboxAnnotaionCompleted.getValue());
                }
            });
            checkboxAnnotaionOngoing.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionCompleted.setValue(!checkboxAnnotaionOngoing.getValue());
                }
            });
            //</editor-fold>

            HorizontalLayout annotationStatusLayout = new HorizontalLayout();
            annotationStatusLayout.addComponent(checkboxAnnotaionOngoing);
            annotationStatusLayout.addComponent(checkboxAnnotaionCompleted);

            Button submitButton = new Button("Submit");
            submitButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    int diseaseBoolean = 0;
                    if (checkboxDiseaseYes.getValue() && !checkboxDiseaseNo.getValue()) {
                        diseaseBoolean = 1;
                    }
                    int caseControlBoolean = 0;
                    if (checkboxCaseControlYes.getValue() && !checkboxCaseControlNo.getValue()) {
                        caseControlBoolean = 1;
                    }
                    for (int j = 1; j <= custom_annotation_counter; j++) {
                        if (findById(rightTopAnnotationForm, "customAnnoName" + j) instanceof TextField) {
                            TextField tempTFname = (TextField) findById(rightTopAnnotationForm,
                                    "customAnnoName" + j);
                            System.out.println(j + "custom name: " + tempTFname.getValue());
                        }
                        if (findById(rightTopAnnotationForm, "customAnnoValue" + j) instanceof TextField) {
                            TextField tempTFvalue = (TextField) findById(rightTopAnnotationForm,
                                    "customAnnoValue" + j);
                            System.out.println(j + "custom value: " + tempTFvalue.getValue());
                        }
                    }

                    //Notification.show("Do not press this button again");
                }
            });

            Button logout = new Button("Logout", new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {

                    // "Logout" the user
                    getSession().setAttribute("user", null);

                    // Refresh this view, should redirect to login view
                    getUI().getNavigator().navigateTo(ANNOTATIONVIEW);
                }
            });
            HorizontalLayout userLayout = new HorizontalLayout();
            userLayout.addComponent(userWelcome);
            userLayout.addComponent(logout);

            rightTopAnnotationForm.addComponent(userLayout);
            rightTopAnnotationForm.addComponent(diseaseLayout);
            rightTopAnnotationForm.addComponent(caseControlLayout);
            rightTopAnnotationForm.addComponent(timeSeriesLayout);
            rightTopAnnotationForm.addComponent(diseaseCategoriesLayout);
            rightTopAnnotationForm.addComponent(platformLayout);
            rightTopAnnotationForm.addComponent(sampleTypesLayout);
            rightTopAnnotationForm.addComponent(replicatTypesLayout);
            rightTopAnnotationForm.addComponent(addCustomAnnoButton);
            rightTopAnnotationForm.addComponent(annotationStatusLayout);
            rightTopAnnotationForm.addComponent(submitButton);
            //</editor-fold>
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="fill tree in right bottom">
            Iterator iterator = biosampleSet.iterator();

            // check values
            while (iterator.hasNext()) {
                //  System.out.println("Value: "+ iterator.next() + " ");
                String bsample = iterator.next().toString();
                String[] biosample_parts = bsample.split("\\|");
                String biosample_acc = biosample_parts[0];
                tree.addItem(biosample_acc);
                tree.setParent(biosample_acc, selectedStudy);
                tree.setItemCaption(biosample_acc, "BioSample: " + biosample_acc);
            }
            Set expMap_entrset = expMap.entrySet();
            Iterator it = expMap_entrset.iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
                String[] expParts = expDetailMap.get(me.getKey());
                String expTitle = "";
                if (expParts.length > 3) {
                    expTitle = expParts[3];
                }
                tree.addItem(me.getKey());
                tree.setParent(me.getKey(), me.getValue());
                tree.setItemCaption(me.getKey(), "Experiment: " + me.getKey() + ": " + expTitle);
            }

            Set runMap_entrset = runMap.entrySet();
            Iterator runit = runMap_entrset.iterator();
            while (runit.hasNext()) {
                Map.Entry runEntry = (Map.Entry) runit.next();
                tree.addItem(runEntry.getKey());
                tree.setParent(runEntry.getKey(), runEntry.getValue());
                tree.setItemCaption(runEntry.getKey(), "Run: " + runEntry.getKey());
            }

            tree.expandItemsRecursively(selectedStudy);

            //</editor-fold>
        }
    });

    tree.setSelectable(true);
    tree.setImmediate(true);
    tree.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            Object id = event.getProperty().getValue();
            if (id != null) {
                String selectedTreeId = id.toString();
                String selectedTreeItem = tree.getItemCaption(id).toString();
                System.out.println("Tree event is fired: " + selectedTreeItem);
                if (selectedTreeItem.startsWith("BioSample")) {

                    myform.removeAllComponents();
                    SQLContainer tempContainer = createMySQLContainer("biosample", selectedTreeId);
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String accessType = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("AccessType").getValue().toString();
                        String publicationDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("PublicationDate").getValue().toString();
                        String lastUpdate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("LastUpdate").getValue().toString();
                        String accession = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Accession").getValue().toString();
                        String title = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Title").getValue().toString();
                        String taxonomy_id = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyId").getValue().toString();
                        String taxonomy_name = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyName").getValue().toString();
                        String samplePackage = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Package").getValue().toString();
                        String status = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Status").getValue().toString();
                        String statusTime = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("StatusTime").getValue().toString();
                        String sampleIds = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Ids").getValue().toString();
                        String attributes = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Attributes").getValue().toString();
                        String models = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Models").getValue().toString();
                        String submissionDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("SubmissionDate").getValue().toString();
                        String owner = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Owner").getValue().toString();

                        String[] myfields = new String[] { accessType, publicationDate, lastUpdate, accession,
                                title, taxonomy_id, taxonomy_name, samplePackage, status, statusTime, sampleIds,
                                attributes, models, submissionDate, owner };
                        /*
                         for (String fieldName : myfields) {
                         Label tempLabl = new Label("");
                         }
                         */
                        Label labelAccessType = new Label("Access Type: " + accessType);
                        myform.addComponent(labelAccessType);
                        Label labelPublicationDate = new Label("Publication Date: " + publicationDate);
                        myform.addComponent(labelPublicationDate);
                        Label labelLastUpdate = new Label("Last Update: " + lastUpdate);
                        myform.addComponent(labelLastUpdate);
                        Label labelAccession = new Label("Accession: " + accession);
                        myform.addComponent(labelAccession);
                        Label labelTitle = new Label("<b>Title: </b>" + title, ContentMode.HTML);
                        myform.addComponent(labelTitle);
                        Label labelTaxonomyId = new Label("Taxonomy Id: " + taxonomy_id);
                        myform.addComponent(labelTaxonomyId);
                        Label labelTaxonomyName = new Label("Taxonomy Name: " + taxonomy_name);
                        myform.addComponent(labelTaxonomyName);
                        Label labelPackage = new Label("Package: " + samplePackage);
                        myform.addComponent(labelPackage);
                        Label labelStatus = new Label("Status: " + status);
                        myform.addComponent(labelStatus);
                        Label labelStatusTime = new Label("Status Time: " + statusTime);
                        myform.addComponent(labelStatusTime);
                        Label labelOwner = new Label("Owner: " + owner);
                        myform.addComponent(labelOwner);

                        String[] id_parts = sampleIds.split("\\:\\-");
                        if (id_parts.length > 1) {
                            String[] id_dbs = id_parts[0].split("\\|");
                            String[] id_values = id_parts[1].split("\\|");
                            for (int j = 0; j < id_dbs.length; j++) {
                                Label tempLabel = new Label(id_dbs[j] + ": " + id_values[j]);
                                myform.addComponent(tempLabel);

                            }
                        }

                        String[] attribute_parts = attributes.split("\\:\\-");
                        if (attribute_parts.length > 1) {
                            String[] attribute_names = attribute_parts[0].split("\\|");
                            String[] attribute_values = attribute_parts[1].split("\\|");
                            for (int j = 0; j < attribute_names.length; j++) {
                                Label tempLabel = new Label(
                                        "<b>" + attribute_names[j] + ": </b>" + attribute_values[j],
                                        ContentMode.HTML);
                                myform.addComponent(tempLabel);
                                System.out.println("inside attributes ");

                            }
                        }

                        //   TextField field = new TextField(lastDpdate);
                        // myform.addComponent(field);
                        //field.setWidth("100%");
                    }
                }
                if (selectedTreeItem.startsWith("Experiment")) {
                    SQLContainer tempContainer = createMySQLContainer("sra_rnaseq_exp", selectedTreeId);
                    myform.removeAllComponents();
                    Map expMap = new HashMap();
                    Map<String, String[]> expDetailMap = new HashMap<>();
                    Map<String, String[]> libraryDetailMap = new HashMap<>();
                    Map<String, String[]> platformMap = new HashMap<>();
                    Map runMap = new HashMap();
                    HashSet<String> biosampleSet = new HashSet<>();
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String docid = tempContainer.getIdByIndex(i).toString();
                        String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                        biosampleSet.add(biosample);
                        String[] b_parts = biosample.split("\\|");

                        String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                        String[] exp_parts = exp.split("\\|");
                        String exp_acc = exp_parts[0];
                        expMap.put(exp_acc, b_parts[0]);
                        expDetailMap.put(exp_acc, exp_parts);

                        String library_string = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Library_Name_Strategy_Source_Selection_Layout").getValue()
                                .toString();
                        String[] library_parts = library_string.split("\\|");
                        String library_name = "";
                        String library_strategy = "";
                        String library_source = "";
                        String library_selection = "";
                        String library_layout = "";
                        if (library_parts.length > 0) {
                            library_name = library_parts[0];
                        }
                        if (library_parts.length > 1) {
                            library_strategy = "<b> <i> Strategy </i> </b>" + library_parts[1];
                        }
                        if (library_parts.length > 2) {
                            library_source = "<b> <i> Source </i> </b>" + library_parts[2];
                        }
                        if (library_parts.length > 3) {
                            library_selection = "<b> <i> Selection </i> </b>" + library_parts[3];
                        }
                        if (library_parts.length > 4) {
                            String tempLayout = library_parts[4];
                            tempLayout = tempLayout.replaceAll("<", "");
                            tempLayout = tempLayout.replaceAll("/>", "");
                            library_layout = "<b> <i> Layout </i> </b>" + tempLayout;
                        }
                        String[] tempStringArray = new String[] { library_strategy, library_source,
                                library_selection, library_layout };
                        if (library_name.length() > 1) {
                            libraryDetailMap.put(library_name, tempStringArray);
                        }

                        String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Platform_InstrumentModel").getValue().toString();
                        String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                        platformMap.put(exp_acc, sra_plaforms_parts);

                        String run = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Runs").getValue().toString();
                        String[] run_parts = run.split("\\|");
                        if (run_parts.length > 0) {
                            for (int j = 0; j < run_parts.length; j++) {
                                String temprun = run_parts[j];
                                String[] temprun_parts = temprun.split("\\,");
                                runMap.put(temprun_parts[0], exp_acc);
                            }
                        }
                    }
                    Label labelExperimentAcc = new Label("<b>Experiment Accession: </b>" + selectedTreeId,
                            ContentMode.HTML);
                    myform.addComponent(labelExperimentAcc);
                    String libraryDetails = "";
                    for (Map.Entry<String, String[]> entry : libraryDetailMap.entrySet()) {
                        libraryDetails = libraryDetails + entry.getKey();
                        String[] temp_library_details = entry.getValue();
                        for (String dt : temp_library_details) {
                            libraryDetails = libraryDetails + dt;
                        }
                    }
                    Label labelLibraryDetails = new Label("<b>Library Details: </b>" + libraryDetails,
                            ContentMode.HTML);
                    myform.addComponent(labelLibraryDetails);

                }
            } else {
                System.out.println("id is null");
            }
        }

    });

    bioprojectSummaryTable.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            Object contactId = bioprojectSummaryTable.getValue();

            //Binding data
            //When a contact is selected from the list, we want to show that in our editor on the right. This is nicely done by the FieldGroup that binds all the fields to the corresponding Properties in our contact at once.                                if (contactId != null)
            //                           editorFields.setItemDataSource(bioprojectSummaryTable.getItem(contactId));
            //                  editorLayout.setVisible(contactId != null);
        }
    });

}

From source file:edu.cornell.qatarmed.planrnaseq.AnnotateViewLogin.java

private void initDataAndSubcomponent() {
    rnaseqContainer = createMySQLContainer("study_summary", "dummy");
    bioprojectSummaryTable.setContainerDataSource(rnaseqContainer);
    //   bioprojectSummaryTable.setVisibleColumns(new String[] { studyName });
    bioprojectSummaryTable.setSelectable(true);
    bioprojectSummaryTable.setImmediate(true);
    bioprojectSummaryTable.setColumnReorderingAllowed(true);
    bioprojectSummaryTable.setSortEnabled(true);
    bioprojectSummaryTable.setVisibleColumns(
            new Object[] { "Study", "title", "name", "Numsample", "Numexp", "Numrun", "Avgspots", "avgbases" });
    //bioprojectSummaryTable.setVisibleColumns(new Object[] { "firstName", "lastName", "department", "phoneNumber", "street", "city", "zipCode" });
    studyName.setValue(rnaseqContainer.firstItemId().toString());
    bioprojectSummaryTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        int custom_annotation_counter = 0;

        public void itemClick(ItemClickEvent event) {
            //<editor-fold defaultstate="collapsed" desc="filling study details on right panel">

            Object selectedStudyObject = event.getItemId();
            bioprojectSummaryTable.select(selectedStudyObject);
            tree.removeAllItems();/*from   w w w.  ja v  a 2 s .  c o  m*/
            rightTopForm.removeAllComponents();
            rightTopAnnotationForm.removeAllComponents();
            myform.removeAllComponents();

            String selectedStudy = selectedStudyObject.toString();
            String studyTitle = (String) bioprojectSummaryTable
                    .getContainerProperty(selectedStudyObject, "title").getValue();
            String studyName = (String) bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "name")
                    .getValue();
            String studyNumsample = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numsample").getValue());
            String studyNumexp = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numexp").getValue());
            String studyNumrun = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numrun").getValue());
            String studyAvgspots = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Avgspots").getValue());
            String studyAvgbases = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "avgbases").getValue());
            tree.addItem(selectedStudy);
            tree.setItemCaption(selectedStudy, "Study: " + selectedStudy);
            SQLContainer tempContainer = createMySQLContainer("study_extdb", selectedStudy); // In this table I will chaeck for the manual annotation status
            String extdbid = tempContainer.getItem(tempContainer.getIdByIndex(0)).getItemProperty("extdb")
                    .getValue().toString();
            Label labelStudyAcc = new Label("<b>SRA Study Accession : </b>" + selectedStudy, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAcc);
            Label labelStudyTitle = new Label("<b>Study Title: </b>" + studyTitle, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyTitle);
            Label labelStudyName = new Label("<b>Study Name: </b>" + studyName, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyName);
            Label labelStudyNumsample = new Label("<b>Total number of samples: </b>" + studyNumsample,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumsample);
            Label labelStudyNumexp = new Label(
                    "<b>Total number of experiments (each experiment uses any one of the samples): </b>"
                            + studyNumexp,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumexp);
            Label labelStudyNumrun = new Label(
                    "<b>Total number of runs ( an experiment can have multiple runs) : </b>" + studyNumrun,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumrun);
            Label labelStudyAvgspots = new Label(
                    "<b>Avg number of spots or reads (per run): </b>" + studyAvgspots, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgspots);
            Label labelStudyAvgbases = new Label("<b>Avg number of bases (per run): </b>" + studyAvgbases,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgbases);
            if (extdbid.startsWith("PRJ")) {
                //<editor-fold defaultstate="collapsed" desc="if PRJ">
                tempContainer = createMySQLContainer("bioproject_details", extdbid);
                String bioproject_accession = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectAccession").getValue().toString();
                String bioproject_id = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectId").getValue().toString();
                String bioproject_name = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Name").getValue().toString();
                String bioproject_title = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Title").getValue().toString();
                String bioproject_description = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Description").getValue().toString();
                String bioproject_capture = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Capture").getValue().toString();
                String bioproject_material = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Material").getValue().toString();
                String bioproject_method = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("MethodType").getValue().toString();
                String bioproject_datatype = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("DataType").getValue().toString();
                String bioproject_sampleScope = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("SampleScope").getValue().toString();
                System.out.println(bioproject_description);
                Label labelBioprojectAccession = new Label(
                        "<b>Bioproject Accession : </b>" + bioproject_accession, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectAccession);
                Label labelBioprojectId = new Label("<b>Bioproject Id : </b>" + bioproject_id,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectId);
                Label labelBioprojectTitle = new Label("<b>Bioproject Title : </b>" + bioproject_title,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectTitle);
                Label labelBioprojectName = new Label("<b>Bioproject Name : </b>" + bioproject_name,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectName);
                Label labelBioprojectDescription = new Label(
                        "<b>Bioproject Description : </b>" + bioproject_description, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDescription);
                Label labelBioprojectCapture = new Label("<b>Bioproject Capture : </b>" + bioproject_capture,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectCapture);
                Label labelBioprojectMaterial = new Label(
                        "<b>Bioproject  Material : </b>" + bioproject_material, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMaterial);
                Label labelBioprojectMethod = new Label("<b>Bioproject Method : </b>" + bioproject_method,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMethod);
                Label labelBioprojectDatatype = new Label(
                        "<b>Bioproject Data Type : </b>" + bioproject_datatype, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDatatype);
                Label labelBioprojectSampleScope = new Label(
                        "<b>Bioproject Sample Scope : </b>" + bioproject_sampleScope, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectSampleScope);

                //</editor-fold>
            }
            if (extdbid.startsWith("GSE")) {
                //<editor-fold defaultstate="collapsed" desc="if GSE">
                tempContainer = createMySQLContainer("study_gse_details", extdbid);
                String gse_accesion = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("gse").getValue().toString();
                String gse_summary = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("summary").getValue().toString();
                String gse_design = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("overall_design").getValue().toString();
                System.out.println(gse_summary);
                Label labelGSE = new Label("<b>GEO Series Accession : </b>" + gse_accesion, ContentMode.HTML);
                rightTopForm.addComponent(labelGSE);
                Label labelGseSummary = new Label("<b>GSE Summary : </b>" + gse_summary, ContentMode.HTML);
                rightTopForm.addComponent(labelGseSummary);
                Label labelGseDesign = new Label("<b>GSE Design : </b>" + gse_design, ContentMode.HTML);
                rightTopForm.addComponent(labelGseDesign);
                //</editor-fold>

            }
            //</editor-fold>
            //SQLContainer tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            //  List<String> list = new ArrayList<String>();
            Map expMap = new HashMap();
            Map<String, String[]> expDetailMap = new HashMap<>();
            Map<String, String[]> platformMap = new HashMap<>();
            Map runMap = new HashMap();
            HashSet<String> biosampleSet = new HashSet<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for loop">

                String docid = tempContainer.getIdByIndex(i).toString();
                String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                biosampleSet.add(biosample);
                String[] b_parts = biosample.split("\\|");

                String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                String[] exp_parts = exp.split("\\|");
                String exp_acc = exp_parts[0];
                expMap.put(exp_acc, b_parts[0]);
                expDetailMap.put(exp_acc, exp_parts);

                String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Platform_InstrumentModel").getValue().toString();
                String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                platformMap.put(exp_acc, sra_plaforms_parts);

                String run = tempContainer.getItem(tempContainer.getIdByIndex(i)).getItemProperty("Runs")
                        .getValue().toString();
                String[] run_parts = run.split("\\|");
                if (run_parts.length > 0) {
                    for (int j = 0; j < run_parts.length; j++) {
                        String temprun = run_parts[j];
                        String[] temprun_parts = temprun.split("\\,");
                        runMap.put(temprun_parts[0], exp_acc);
                    }
                }
                //</editor-fold>
            }

            //<editor-fold defaultstate="collapsed" desc="Manual Annotaion">
            tempContainer = createMySQLContainer("biosample_with_studyacc", selectedStudy);
            int count_cell_line = 0;
            int count_organism_part = 0;
            int count_tissue = 0;
            int count_disease = 0;
            Set<String> cell_lines_set = new HashSet();
            Set<String> organism_part_set = new HashSet();
            Set<String> tissue_set = new HashSet();
            Set<String> disease_set = new HashSet();
            Map<String, Integer> cell_line_stat_map = new HashMap<>();
            Map<String, Integer> organism_part_stat_map = new HashMap<>();
            Map<String, Integer> tissue_stat_map = new HashMap<>();
            Map<String, Integer> disease_stat_map = new HashMap<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for biosample attributes">
                String biosample_attr = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Attributes").getValue().toString();
                String[] biosample_attr_parts = biosample_attr.split("\\:-");
                if (biosample_attr_parts.length > 0) {
                    String[] attr_names = biosample_attr_parts[0].split("\\|");
                    String[] attr_values = new String[] {};
                    if (biosample_attr_parts.length > 1) {
                        attr_values = biosample_attr_parts[1].split("\\|");
                    }
                    int atn_index = 0;
                    for (String atn : attr_names) {
                        if (atn.equalsIgnoreCase("cell line")) {
                            count_cell_line = count_cell_line + 1;
                            if (attr_values.length >= atn_index) {
                                String cell_line_value = attr_values[atn_index];
                                cell_lines_set.add(cell_line_value);
                                if (cell_line_stat_map.containsKey(cell_line_value)) {
                                    cell_line_stat_map.put(cell_line_value,
                                            cell_line_stat_map.get(cell_line_value) + 1);
                                } else {
                                    cell_line_stat_map.put(cell_line_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("organism part")) {
                            count_organism_part = count_organism_part + 1;
                            if (attr_values.length >= atn_index) {
                                String organism_part_value = attr_values[atn_index];
                                organism_part_set.add(organism_part_value);
                                if (organism_part_stat_map.containsKey(organism_part_value)) {
                                    organism_part_stat_map.put(organism_part_value,
                                            organism_part_stat_map.get(organism_part_value) + 1);
                                } else {
                                    organism_part_stat_map.put(organism_part_value, 1);
                                }
                            }

                        }

                        if (atn.contains("disease")) {
                            count_disease = count_disease + 1;
                            if (attr_values.length >= atn_index) {
                                String disease_value = attr_values[atn_index];
                                disease_set.add(disease_value);
                                if (disease_stat_map.containsKey(disease_value)) {
                                    disease_stat_map.put(disease_value,
                                            disease_stat_map.get(disease_value) + 1);
                                } else {
                                    disease_stat_map.put(disease_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("tissue")) {
                            count_tissue = count_tissue + 1;
                            if (attr_values.length >= atn_index) {
                                String tissue_value = attr_values[atn_index];
                                tissue_set.add(tissue_value);
                                if (tissue_stat_map.containsKey(tissue_value)) {
                                    tissue_stat_map.put(tissue_value, tissue_stat_map.get(tissue_value) + 1);
                                } else {
                                    tissue_stat_map.put(tissue_value, 1);
                                }
                            }

                        }
                        atn_index = atn_index + 1;
                    }
                }
                //</editor-fold>

            }

            String suggestion_cell_line = "";
            String suggestion_organism_part = "";
            String suggestion_tissue = "";
            String suggestion_disease = "";
            String samplesType_from_sra = "";
            String cell_line_confidence = "";
            String organism_part_confidence = "";
            String disease_confidence = "";
            String tissue_confidence = "";
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has cell line">
            if (count_cell_line > 0) {
                if (Integer.parseInt(studyNumsample) == count_cell_line) {
                    //good. all samples are from cell lines
                    suggestion_cell_line = "Yes:";
                    String cell_line_value = cell_lines_set.iterator().next();
                    suggestion_cell_line = suggestion_cell_line + cell_line_value;
                    cell_line_confidence = "100%. All " + cell_line_stat_map.get(cell_line_value).toString()
                            + " Samples";
                } else {
                    suggestion_cell_line = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : cell_line_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_cell_line = suggestion_cell_line + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    cell_line_confidence = confidence_percent + "%";
                    for (Iterator<String> it = cell_lines_set.iterator(); it.hasNext();) {
                        String cellLine = it.next();
                        if (cellLine.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_cell_line = suggestion_cell_line + ", " + cellLine + "("
                                    + cell_line_stat_map.get(cellLine).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_cell_line = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has organism part">
            if (count_organism_part > 0) {
                if (Integer.parseInt(studyNumsample) == count_organism_part) {
                    //good. all samples are from cell lines
                    suggestion_organism_part = "Yes:";
                    String organism_part_value = organism_part_set.iterator().next();
                    suggestion_organism_part = suggestion_organism_part + organism_part_value;
                    organism_part_confidence = "100%. All "
                            + organism_part_stat_map.get(organism_part_value).toString() + " Samples";
                } else {
                    suggestion_organism_part = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : organism_part_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_organism_part = suggestion_organism_part + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    organism_part_confidence = confidence_percent + "%";
                    for (Iterator<String> it = organism_part_set.iterator(); it.hasNext();) {
                        String organismPart = it.next();
                        if (organismPart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_organism_part = suggestion_organism_part + ", " + organismPart + "("
                                    + organism_part_stat_map.get(organismPart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_organism_part = " No";
            }
            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has disease">
            if (count_disease > 0) {
                if (Integer.parseInt(studyNumsample) == count_disease) {
                    //good. all samples are from cell lines
                    suggestion_disease = "Yes:";
                    String disease_value = disease_set.iterator().next();
                    suggestion_disease = suggestion_disease + disease_value;
                    disease_confidence = "100%. All " + disease_stat_map.get(disease_value).toString()
                            + " Samples";
                } else {
                    suggestion_disease = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : disease_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_disease = suggestion_disease + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    disease_confidence = confidence_percent + "%";
                    for (Iterator<String> it = disease_set.iterator(); it.hasNext();) {
                        String diseasePart = it.next();
                        if (diseasePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_disease = suggestion_disease + ", " + diseasePart + "("
                                    + disease_stat_map.get(diseasePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_disease = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has tissue">
            if (count_tissue > 0) {
                if (Integer.parseInt(studyNumsample) == count_tissue) {
                    //good. all samples are from cell lines
                    suggestion_tissue = "Yes:";
                    String tissue_value = tissue_set.iterator().next();
                    suggestion_tissue = suggestion_tissue + tissue_value;
                    tissue_confidence = "100%. All " + tissue_stat_map.get(tissue_value).toString()
                            + " Samples";
                } else {
                    suggestion_tissue = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : tissue_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_tissue = suggestion_tissue + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    tissue_confidence = confidence_percent + "%";
                    for (Iterator<String> it = disease_set.iterator(); it.hasNext();) {
                        String tissuePart = it.next();
                        if (tissuePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_tissue = suggestion_tissue + ", " + tissuePart + "("
                                    + tissue_stat_map.get(tissuePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_tissue = " No";
            }

            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="filling right top manual annotation">
            HorizontalLayout diseaseLayout = new HorizontalLayout();
            CheckBox checkboxDiseaseYes = new CheckBox("Yes");
            CheckBox checkboxDiseaseNo = new CheckBox("No");

            String disease_from_biosample_attribute = "";
            if (suggestion_disease.startsWith("Yes")) {
                disease_from_biosample_attribute = "From Biosample: " + suggestion_disease;
            }
            String disease_found = "";
            String disease_text_parsed_confidence = "";
            for (String disease : list_of_diseases) {
                if (StringUtils.containsIgnoreCase(studyName, disease)
                        || StringUtils.containsIgnoreCase(studyTitle, disease)) {
                    checkboxDiseaseYes.setValue(true);
                    disease_found = disease_found + disease + " ";
                    disease_text_parsed_confidence = "keyword found in Study or Title";
                }
            }
            String diseaseLabelString = "";
            if (disease_text_parsed_confidence.length() > 1) {
                diseaseLabelString = "<b><i>Suggestion: </i></b>" + disease_found
                        + " <b> <i> Confidence: <i></b>  " + disease_text_parsed_confidence;
            }
            if (disease_from_biosample_attribute.length() > 1) {
                diseaseLabelString = diseaseLabelString + "<b><i>Suggestion: </i></b>"
                        + disease_from_biosample_attribute + " <b> <i> Confidence: <i></b>  "
                        + disease_confidence;
            }

            Label diseaseLabel = new Label(diseaseLabelString, ContentMode.HTML);
            Label diseaseTitle = new Label("<b>Disease: </b>", ContentMode.HTML);
            diseaseLayout.addComponent(diseaseTitle);
            diseaseLayout.addComponent(checkboxDiseaseNo);
            diseaseLayout.addComponent(checkboxDiseaseYes);
            diseaseLayout.addComponent(diseaseLabel);

            HorizontalLayout caseControlLayout = new HorizontalLayout();
            CheckBox checkboxCaseControlYes = new CheckBox("Yes");
            CheckBox checkboxCaseControlNo = new CheckBox("No");
            checkboxDiseaseYes.setValue(true);
            Label caseControlTitle = new Label("<b>Case-Control: </b>", ContentMode.HTML);
            caseControlLayout.addComponent(caseControlTitle);
            caseControlLayout.addComponent(checkboxCaseControlYes);
            caseControlLayout.addComponent(checkboxCaseControlNo);

            HorizontalLayout timeSeriesLayout = new HorizontalLayout();
            CheckBox checkboxTimeSerieslYes = new CheckBox("Yes");
            CheckBox checkboxTimeSeriesNo = new CheckBox("No");
            checkboxDiseaseYes.setValue(true);
            Label timeSeriesTitle = new Label("<b>Time Series: </b>", ContentMode.HTML);
            timeSeriesLayout.addComponent(timeSeriesTitle);
            timeSeriesLayout.addComponent(checkboxTimeSerieslYes);
            timeSeriesLayout.addComponent(checkboxTimeSeriesNo);

            HorizontalLayout diseaseCategoriesLayout = new HorizontalLayout();
            Label diseaseCategoryLabel = new Label("<b><i>Suggestion: </i></b>" + disease_found
                    + " <b> <i> Confidence: <i></b>  " + disease_confidence, ContentMode.HTML);
            String[] diseaseCategories = new String[] { "Complex Disease", "Rare Disease", "Other",
                    "Not Sure" };
            List<String> diseaseCategoriesList = Arrays.asList(diseaseCategories);
            ComboBox diseaseCategoryComboBox = new ComboBox("Disease Category", diseaseCategoriesList);
            diseaseCategoriesLayout.addComponent(diseaseCategoryComboBox);
            diseaseCategoriesLayout.addComponent(diseaseCategoryLabel);

            String[] platforms = new String[] { "Illumina", "SOLID", "Roche 454", "PacBio", "Helicos",
                    "Complete Genomics" };
            List<String> platformsList = Arrays.asList(platforms);
            ComboBox platformsListComboBox = new ComboBox("Sequencing Platform", platformsList);
            Set<String> matchedPlatformSet = new HashSet();
            String platform_from_sra = "";
            String platorm_confidence = "";
            int matchPlatformCount = 0;
            for (String[] val : platformMap.values()) {
                if (val.length > 1) {
                    for (String pf : platforms) {
                        if (val[0].equalsIgnoreCase(pf)) {
                            matchedPlatformSet.add(pf);
                            matchPlatformCount = matchPlatformCount + 1;
                        }
                    }
                } else {

                }
            }
            if (matchedPlatformSet.isEmpty()) {
                platform_from_sra = "Match Not Found";
            } else {
                if (matchedPlatformSet.size() == matchPlatformCount) {
                    //Ideally this shouldn't be the case. 
                    // This suggests that all experiments of this project are run on different platforms or
                    // it has only one expriment
                    if (matchedPlatformSet.size() == 1) {
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        platformsListComboBox.select(platform_from_sra);
                    } else {
                        platform_from_sra = "Can't predict. All experiment on different Platforms";
                    }
                } else {
                    if (matchedPlatformSet.size() == 1) {
                        // Perfect 
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        platformsListComboBox.select(platform_from_sra);
                        platorm_confidence = "100%";
                    } else {

                    }
                }
            }

            HorizontalLayout platformLayout = new HorizontalLayout();
            Label suggestedPlatformLabel = new Label("<b><i>Suggestion: </i></b>" + platform_from_sra
                    + "<b> <i> Confidence: <i></b>  " + platorm_confidence, ContentMode.HTML);
            platformLayout.addComponent(platformsListComboBox);
            platformLayout.addComponent(suggestedPlatformLabel);

            VerticalLayout sampleTypesLayout = new VerticalLayout();
            CheckBox checkboxSampleTypeCellLine = new CheckBox("Cell Line");
            CheckBox checkboxSampleTypeTissue = new CheckBox("Tissue");
            CheckBox checkboxSampleTypeStemCells = new CheckBox("Stem Cells");
            CheckBox checkboxSampleTypeWholeBlood = new CheckBox("Whole Blood");
            CheckBox checkboxSampleTypePlasma = new CheckBox("Plasma");
            String suggestedCellTypeLabelString = "";
            if (suggestion_cell_line.startsWith("Yes")) {
                //sampleTypesListComboBox.select("Cell Lines");
                checkboxSampleTypeCellLine.setValue(true);
                suggestedCellTypeLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> "
                        + suggestion_cell_line + " <b> <i> Confidence: <i></b>   " + cell_line_confidence;
            }
            Label suggestedCellLineLabel = new Label(suggestedCellTypeLabelString, ContentMode.HTML);
            String suggestedTissueLabelString = "";
            if (suggestion_organism_part.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString + "<b><i>Suggestion: </i></b>"
                        + "Organism part --> " + suggestion_organism_part + " <b> <i> Confidence: <i></b>   "
                        + organism_part_confidence;
            }

            if (suggestion_tissue.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString + "<b><i>Suggestion: </i></b>"
                        + "Tissue --> " + suggestion_tissue + " <b> <i> Confidence: <i></b>   "
                        + tissue_confidence;
            }
            Label suggestedTissueLabel = new Label(suggestedTissueLabelString, ContentMode.HTML);

            String suggestedStemCellString = "";
            /*
             if (suggestion_stem_cell.startsWith("Yes")) {                   
             checkboxSampleTypeStemCells.setValue(true);
             suggestedCellTypeLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_stem_cell + " <b> <i> Confidence: <i></b>   " + stem_cell_confidence;
             }
             */
            Label suggestedStemCellLabel = new Label(suggestedStemCellString, ContentMode.HTML);

            String suggestedWholeBloodLabelString = "";
            /*
             if (suggestion_whole_blood.startsWith("Yes")) {                   
             checkboxSampleTypeWholeBlood.setValue(true);
             suggestedWholeBloodLabelString = "<b><i>Suggestion: </i></b>" + "Whole Blood --> " + suggestion_whole_blood + " <b> <i> Confidence: <i></b>   " + whole_blood_confidence;
             }
             */
            Label suggestedWholeBloodLabel = new Label(suggestedWholeBloodLabelString, ContentMode.HTML);

            String suggestedPlasmaLabelString = "";
            /*
             if (suggestion_plasma.startsWith("Yes")) {                   
             checkboxSampleTypePlasma.setValue(true);
             suggestedPlasmaLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_plasma + " <b> <i> Confidence: <i></b>   " + plasma_confidence;
             }
             */
            Label suggestedPlasmaLabel = new Label(suggestedPlasmaLabelString, ContentMode.HTML);

            HorizontalLayout CellLineLayout = new HorizontalLayout();
            CellLineLayout.addComponent(checkboxSampleTypeCellLine);
            CellLineLayout.addComponent(suggestedCellLineLabel);

            HorizontalLayout TissueLayout = new HorizontalLayout();
            TissueLayout.addComponent(checkboxSampleTypeTissue);
            TissueLayout.addComponent(suggestedTissueLabel);

            HorizontalLayout WholeBloodLayout = new HorizontalLayout();
            WholeBloodLayout.addComponent(checkboxSampleTypeWholeBlood);
            WholeBloodLayout.addComponent(suggestedWholeBloodLabel);

            HorizontalLayout PlasmaLayout = new HorizontalLayout();
            PlasmaLayout.addComponent(checkboxSampleTypePlasma);
            PlasmaLayout.addComponent(suggestedPlasmaLabel);

            sampleTypesLayout.addComponent(CellLineLayout);
            sampleTypesLayout.addComponent(TissueLayout);
            sampleTypesLayout.addComponent(WholeBloodLayout);
            sampleTypesLayout.addComponent(PlasmaLayout);

            Button addCustomAnnoButton = new Button("++ Custom Annotation");
            addCustomAnnoButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    custom_annotation_counter = custom_annotation_counter + 1;
                    HorizontalLayout customLayout = new HorizontalLayout();
                    TextField customAnnoName = new TextField("Custom Name");
                    customAnnoName.setId("customAnnoName" + custom_annotation_counter);
                    TextField customAnnoValue = new TextField("Custom Value");
                    customLayout.addComponent(customAnnoName);
                    customLayout.addComponent(customAnnoValue);
                    customAnnoValue.setId("customAnnoValue" + custom_annotation_counter);
                    int addCustomAnnoButtonIndex = rightTopAnnotationForm
                            .getComponentIndex(addCustomAnnoButton);
                    rightTopAnnotationForm.addComponent(customLayout, addCustomAnnoButtonIndex);

                }
            });

            //<editor-fold defaultstate="collapsed" desc="Replicate Type">
            HorizontalLayout replicatTypesLayout = new HorizontalLayout();
            String replicateType_from_sra = "";
            String replicateType_confidence = "";
            Label suggestedreplicatTypeLabel = new Label("<b><i>Suggestion: </i></b>" + replicateType_from_sra
                    + " <b> <i> Confidence: <i></b>  " + replicateType_confidence, ContentMode.HTML);
            String[] replicatTypes = new String[] { "Biological -- different individuals",
                    "Biological -- same individual but severe treatment to RNA",
                    "Semi Biological/Technical -- mild treatment",
                    "Technical -- machine parameter or buffer (very mild)" };
            List<String> replicatTypesList = Arrays.asList(replicatTypes);
            ComboBox replicatTypesListComboBox = new ComboBox("Replicates Type ", replicatTypesList);
            replicatTypesLayout.addComponent(replicatTypesListComboBox);
            replicatTypesLayout.addComponent(suggestedreplicatTypeLabel);

            //</editor-fold>
            checkboxDiseaseYes.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseNo.setValue(!checkboxDiseaseYes.getValue());
                    diseaseCategoryComboBox.setVisible(true);
                }
            });
            checkboxDiseaseNo.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseYes.setValue(!checkboxDiseaseNo.getValue());
                    diseaseCategoryComboBox.setVisible(false);
                }
            });

            //<editor-fold defaultstate="collapsed" desc="CheckBox Annotation Ongoing or Completed ">
            CheckBox checkboxAnnotaionCompleted = new CheckBox("Annotaion Completed");
            CheckBox checkboxAnnotaionOngoing = new CheckBox("Annotaion Ongoing");
            checkboxAnnotaionOngoing.setValue(true);
            checkboxAnnotaionCompleted.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionOngoing.setValue(!checkboxAnnotaionCompleted.getValue());
                }
            });
            checkboxAnnotaionOngoing.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionCompleted.setValue(!checkboxAnnotaionOngoing.getValue());
                }
            });
            //</editor-fold>

            HorizontalLayout annotationStatusLayout = new HorizontalLayout();
            annotationStatusLayout.addComponent(checkboxAnnotaionOngoing);
            annotationStatusLayout.addComponent(checkboxAnnotaionCompleted);

            Button submitButton = new Button("Submit");
            submitButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    int diseaseBoolean = 0;
                    if (checkboxDiseaseYes.getValue() && !checkboxDiseaseNo.getValue()) {
                        diseaseBoolean = 1;
                    }
                    int caseControlBoolean = 0;
                    if (checkboxCaseControlYes.getValue() && !checkboxCaseControlNo.getValue()) {
                        caseControlBoolean = 1;
                    }
                    for (int j = 1; j <= custom_annotation_counter; j++) {
                        if (findById(rightTopAnnotationForm, "customAnnoName" + j) instanceof TextField) {
                            TextField tempTFname = (TextField) findById(rightTopAnnotationForm,
                                    "customAnnoName" + j);
                            System.out.println(j + "custom name: " + tempTFname.getValue());
                        }
                        if (findById(rightTopAnnotationForm, "customAnnoValue" + j) instanceof TextField) {
                            TextField tempTFvalue = (TextField) findById(rightTopAnnotationForm,
                                    "customAnnoValue" + j);
                            System.out.println(j + "custom value: " + tempTFvalue.getValue());
                        }
                    }

                    //Notification.show("Do not press this button again");
                }
            });

            Button loginButton = new Button("Login");
            HorizontalLayout requestLoginLayout = new HorizontalLayout();
            requestLoginLayout.addComponent(userWelcome);
            requestLoginLayout.addComponent(loginButton);
            rightTopAnnotationForm.addComponent(requestLoginLayout);
            VerticalLayout userPasswordLayout = new VerticalLayout();
            loginButton.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    if (event.getButton() == loginButton) {
                        // Create the user input field
                        user = new TextField("User:");
                        user.setWidth("300px");
                        user.setRequired(true);
                        user.setInputPrompt("Your username (eg. joe@email.com)");
                        user.addValidator(new EmailValidator("Username must be an email address"));
                        user.setInvalidAllowed(false);

                        // Create the password input field
                        password = new PasswordField("Password:");
                        password.setWidth("300px");
                        password.addValidator(new PasswordValidator());
                        password.setRequired(true);
                        password.setValue("");
                        password.setNullRepresentation("");

                        // Create login button
                        loginSubmitButton = new Button("Login", this);

                        // Add both to a panel
                        VerticalLayout fields = new VerticalLayout(user, password, loginSubmitButton);
                        fields.setCaption("Please login to access the application. (test@test.com/passw0rd)");
                        fields.setSpacing(true);
                        fields.setMargin(new MarginInfo(true, true, true, false));
                        fields.setSizeUndefined();

                        // The view root layout
                        userPasswordLayout.addComponent(fields);
                        int addUserLayoutIndex = rightTopAnnotationForm.getComponentIndex(requestLoginLayout);
                        rightTopAnnotationForm.addComponent(userPasswordLayout, addUserLayoutIndex);
                        rightTopAnnotationForm.removeComponent(requestLoginLayout);
                    }

                    loginSubmitButton.addClickListener(new Button.ClickListener() {

                        @Override
                        public void buttonClick(ClickEvent event) {
                            if (event.getButton() == loginSubmitButton) {
                                //
                                // Validate the fields using the navigator. By using validors for the
                                // fields we reduce the amount of queries we have to use to the database
                                // for wrongly entered passwords
                                //
                                if (!user.isValid() || !password.isValid()) {
                                    return;
                                }

                                String username = user.getValue();
                                String entered_password = password.getValue();

                                //
                                // Validate username and password with database here. For examples sake
                                // I use a dummy username and password.
                                //
                                boolean isValid = username.equals("test@test.com")
                                        && entered_password.equals("passw0rd");

                                if (isValid) {
                                    System.out.println("User name and passoword : Both are correct");
                                    // Store the current user in the service session
                                    getSession().setAttribute("user", username);
                                    userWelcome.setValue("Hello " + username);
                                    int userPasswordLayoutIndex = rightTopAnnotationForm
                                            .getComponentIndex(userPasswordLayout);
                                    rightTopAnnotationForm.addComponent(requestLoginLayout,
                                            userPasswordLayoutIndex);
                                    rightTopAnnotationForm.removeComponent(userPasswordLayout);
                                    loginButton.setCaption("Logout");

                                    // Navigate to main view
                                    //     getUI().getNavigator().navigateTo(AnnotateView.ANNOTATIONVIEW);// I guess there is no need to change the view
                                    //  getUI().getNavigator().navigateTo(AnnotateViewLogin.ANNOTATIONVIEW);
                                } else {

                                    // Wrong password clear the password field and refocuses it
                                    password.setValue(null);
                                    password.focus();

                                }
                                // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                            }
                        }
                    });
                }
            });

            /* 
             loginSubmitButton.addClickListener(new Button.ClickListener() {
                    
             @Override
             public void buttonClick(ClickEvent event) {
             if (event.getButton() == loginSubmitButton) {
             //
             // Validate the fields using the navigator. By using validors for the
             // fields we reduce the amount of queries we have to use to the database
             // for wrongly entered passwords
             //
             if (!user.isValid() || !password.isValid()) {
             return;
             }
                    
             String username = user.getValue();
             String entered_password = password.getValue();
                    
             //
             // Validate username and password with database here. For examples sake
             // I use a dummy username and password.
             //
             boolean isValid = username.equals("test@test.com")
             && entered_password.equals("passw0rd");
                    
             if (isValid) {
                    
             // Store the current user in the service session
             getSession().setAttribute("user", username);
                    
             // Navigate to main view
             getUI().getNavigator().navigateTo(AnnotateView.ANNOTATIONVIEW);//
             //   getUI().getNavigator().navigateTo(AnnotateRNAseqSQL);//
                    
             } else {
                    
             // Wrong password clear the password field and refocuses it
             password.setValue(null);
             password.focus();
                    
             }
             throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
             }
             }
             });
             */
            rightTopAnnotationForm.addComponent(diseaseLayout);
            rightTopAnnotationForm.addComponent(caseControlLayout);
            rightTopAnnotationForm.addComponent(timeSeriesLayout);
            rightTopAnnotationForm.addComponent(diseaseCategoriesLayout);
            rightTopAnnotationForm.addComponent(platformLayout);
            rightTopAnnotationForm.addComponent(sampleTypesLayout);
            rightTopAnnotationForm.addComponent(replicatTypesLayout);
            rightTopAnnotationForm.addComponent(addCustomAnnoButton);
            rightTopAnnotationForm.addComponent(annotationStatusLayout);
            rightTopAnnotationForm.addComponent(submitButton);
            //</editor-fold>
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="fill tree in right bottom">
            Iterator iterator = biosampleSet.iterator();

            // check values
            while (iterator.hasNext()) {
                //  System.out.println("Value: "+ iterator.next() + " ");
                String bsample = iterator.next().toString();
                String[] biosample_parts = bsample.split("\\|");
                String biosample_acc = biosample_parts[0];
                tree.addItem(biosample_acc);
                tree.setParent(biosample_acc, selectedStudy);
                tree.setItemCaption(biosample_acc, "BioSample: " + biosample_acc);
            }
            Set expMap_entrset = expMap.entrySet();
            Iterator it = expMap_entrset.iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
                String[] expParts = expDetailMap.get(me.getKey());
                String expTitle = "";
                if (expParts.length > 3) {
                    expTitle = expParts[3];
                }
                tree.addItem(me.getKey());
                tree.setParent(me.getKey(), me.getValue());
                tree.setItemCaption(me.getKey(), "Experiment: " + me.getKey() + ": " + expTitle);
            }

            Set runMap_entrset = runMap.entrySet();
            Iterator runit = runMap_entrset.iterator();
            while (runit.hasNext()) {
                Map.Entry runEntry = (Map.Entry) runit.next();
                tree.addItem(runEntry.getKey());
                tree.setParent(runEntry.getKey(), runEntry.getValue());
                tree.setItemCaption(runEntry.getKey(), "Run: " + runEntry.getKey());
            }

            tree.expandItemsRecursively(selectedStudy);

            //</editor-fold>
        }
    });

    tree.setSelectable(true);
    tree.setImmediate(true);
    tree.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            Object id = event.getProperty().getValue();
            if (id != null) {
                String selectedTreeId = id.toString();
                String selectedTreeItem = tree.getItemCaption(id).toString();
                System.out.println("Tree event is fired: " + selectedTreeItem);
                if (selectedTreeItem.startsWith("BioSample")) {

                    myform.removeAllComponents();
                    SQLContainer tempContainer = createMySQLContainer("biosample", selectedTreeId);
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String accessType = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("AccessType").getValue().toString();
                        String publicationDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("PublicationDate").getValue().toString();
                        String lastUpdate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("LastUpdate").getValue().toString();
                        String accession = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Accession").getValue().toString();
                        String title = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Title").getValue().toString();
                        String taxonomy_id = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyId").getValue().toString();
                        String taxonomy_name = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyName").getValue().toString();
                        String samplePackage = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Package").getValue().toString();
                        String status = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Status").getValue().toString();
                        String statusTime = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("StatusTime").getValue().toString();
                        String sampleIds = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Ids").getValue().toString();
                        String attributes = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Attributes").getValue().toString();
                        String models = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Models").getValue().toString();
                        String submissionDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("SubmissionDate").getValue().toString();
                        String owner = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Owner").getValue().toString();

                        String[] myfields = new String[] { accessType, publicationDate, lastUpdate, accession,
                                title, taxonomy_id, taxonomy_name, samplePackage, status, statusTime, sampleIds,
                                attributes, models, submissionDate, owner };
                        /*
                         for (String fieldName : myfields) {
                         Label tempLabl = new Label("");
                         }
                         */
                        Label labelAccessType = new Label("Access Type: " + accessType);
                        myform.addComponent(labelAccessType);
                        Label labelPublicationDate = new Label("Publication Date: " + publicationDate);
                        myform.addComponent(labelPublicationDate);
                        Label labelLastUpdate = new Label("Last Update: " + lastUpdate);
                        myform.addComponent(labelLastUpdate);
                        Label labelAccession = new Label("Accession: " + accession);
                        myform.addComponent(labelAccession);
                        Label labelTitle = new Label("<b>Title: </b>" + title, ContentMode.HTML);
                        myform.addComponent(labelTitle);
                        Label labelTaxonomyId = new Label("Taxonomy Id: " + taxonomy_id);
                        myform.addComponent(labelTaxonomyId);
                        Label labelTaxonomyName = new Label("Taxonomy Name: " + taxonomy_name);
                        myform.addComponent(labelTaxonomyName);
                        Label labelPackage = new Label("Package: " + samplePackage);
                        myform.addComponent(labelPackage);
                        Label labelStatus = new Label("Status: " + status);
                        myform.addComponent(labelStatus);
                        Label labelStatusTime = new Label("Status Time: " + statusTime);
                        myform.addComponent(labelStatusTime);
                        Label labelOwner = new Label("Owner: " + owner);
                        myform.addComponent(labelOwner);

                        String[] id_parts = sampleIds.split("\\:\\-");
                        if (id_parts.length > 1) {
                            String[] id_dbs = id_parts[0].split("\\|");
                            String[] id_values = id_parts[1].split("\\|");
                            for (int j = 0; j < id_dbs.length; j++) {
                                Label tempLabel = new Label(id_dbs[j] + ": " + id_values[j]);
                                myform.addComponent(tempLabel);

                            }
                        }

                        String[] attribute_parts = attributes.split("\\:\\-");
                        if (attribute_parts.length > 1) {
                            String[] attribute_names = attribute_parts[0].split("\\|");
                            String[] attribute_values = attribute_parts[1].split("\\|");
                            for (int j = 0; j < attribute_names.length; j++) {
                                Label tempLabel = new Label(
                                        "<b>" + attribute_names[j] + ": </b>" + attribute_values[j],
                                        ContentMode.HTML);
                                myform.addComponent(tempLabel);
                                System.out.println("inside attributes ");

                            }
                        }

                        //   TextField field = new TextField(lastDpdate);
                        // myform.addComponent(field);
                        //field.setWidth("100%");
                    }
                }
                if (selectedTreeItem.startsWith("Experiment")) {
                    SQLContainer tempContainer = createMySQLContainer("sra_rnaseq_exp", selectedTreeId);
                    myform.removeAllComponents();
                    Map expMap = new HashMap();
                    Map<String, String[]> expDetailMap = new HashMap<>();
                    Map<String, String[]> libraryDetailMap = new HashMap<>();
                    Map<String, String[]> platformMap = new HashMap<>();
                    Map runMap = new HashMap();
                    HashSet<String> biosampleSet = new HashSet<>();
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String docid = tempContainer.getIdByIndex(i).toString();
                        String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                        biosampleSet.add(biosample);
                        String[] b_parts = biosample.split("\\|");

                        String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                        String[] exp_parts = exp.split("\\|");
                        String exp_acc = exp_parts[0];
                        expMap.put(exp_acc, b_parts[0]);
                        expDetailMap.put(exp_acc, exp_parts);

                        String library_string = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Library_Name_Strategy_Source_Selection_Layout").getValue()
                                .toString();
                        String[] library_parts = library_string.split("\\|");
                        String library_name = "";
                        String library_strategy = "";
                        String library_source = "";
                        String library_selection = "";
                        String library_layout = "";
                        if (library_parts.length > 0) {
                            library_name = library_parts[0];
                        }
                        if (library_parts.length > 1) {
                            library_strategy = "<b> <i> Strategy </i> </b>" + library_parts[1];
                        }
                        if (library_parts.length > 2) {
                            library_source = "<b> <i> Source </i> </b>" + library_parts[2];
                        }
                        if (library_parts.length > 3) {
                            library_selection = "<b> <i> Selection </i> </b>" + library_parts[3];
                        }
                        if (library_parts.length > 4) {
                            String tempLayout = library_parts[4];
                            tempLayout = tempLayout.replaceAll("<", "");
                            tempLayout = tempLayout.replaceAll("/>", "");
                            library_layout = "<b> <i> Layout </i> </b>" + tempLayout;
                        }
                        String[] tempStringArray = new String[] { library_strategy, library_source,
                                library_selection, library_layout };
                        if (library_name.length() > 1) {
                            libraryDetailMap.put(library_name, tempStringArray);
                        }

                        String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Platform_InstrumentModel").getValue().toString();
                        String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                        platformMap.put(exp_acc, sra_plaforms_parts);

                        String run = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Runs").getValue().toString();
                        String[] run_parts = run.split("\\|");
                        if (run_parts.length > 0) {
                            for (int j = 0; j < run_parts.length; j++) {
                                String temprun = run_parts[j];
                                String[] temprun_parts = temprun.split("\\,");
                                runMap.put(temprun_parts[0], exp_acc);
                            }
                        }
                    }
                    Label labelExperimentAcc = new Label("<b>Experiment Accession: </b>" + selectedTreeId,
                            ContentMode.HTML);
                    myform.addComponent(labelExperimentAcc);
                    String libraryDetails = "";
                    for (Map.Entry<String, String[]> entry : libraryDetailMap.entrySet()) {
                        libraryDetails = libraryDetails + entry.getKey();
                        String[] temp_library_details = entry.getValue();
                        for (String dt : temp_library_details) {
                            libraryDetails = libraryDetails + dt;
                        }
                    }
                    Label labelLibraryDetails = new Label("<b>Library Details: </b>" + libraryDetails,
                            ContentMode.HTML);
                    myform.addComponent(labelLibraryDetails);

                }
            } else {
                System.out.println("id is null");
            }
        }

    });

    bioprojectSummaryTable.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            Object contactId = bioprojectSummaryTable.getValue();

            //Binding data
            //When a contact is selected from the list, we want to show that in our editor on the right. This is nicely done by the FieldGroup that binds all the fields to the corresponding Properties in our contact at once.                                if (contactId != null)
            //                           editorFields.setItemDataSource(bioprojectSummaryTable.getItem(contactId));
            //                  editorLayout.setVisible(contactId != null);
        }
    });

}

From source file:edu.cornell.qatarmed.planrnaseq.BrowseAndAnnotate.java

private void initDataAndSubcomponent() {
    //<editor-fold defaultstate="collapsed" desc="populating project/study summary table">      

    rnaseqContainer = createMySQLContainer("study_summary", "dummy");
    bioprojectSummaryTable.setContainerDataSource(rnaseqContainer);
    //   bioprojectSummaryTable.setVisibleColumns(new String[] { studyName });
    bioprojectSummaryTable.setCurrentPageFirstItemIndex(300);
    bioprojectSummaryTable.setSelectable(true);
    bioprojectSummaryTable.setImmediate(true);
    bioprojectSummaryTable.setColumnReorderingAllowed(true);
    bioprojectSummaryTable.setSortEnabled(true);
    bioprojectSummaryTable.setVisibleColumns(
            new Object[] { "Study", "title", "Numsample", "Numexp", "Numrun", "Avgspots", "avgbases", "name" });
    //bioprojectSummaryTable.setVisibleColumns(new Object[] { "firstName", "lastName", "department", "phoneNumber", "street", "city", "zipCode" });
    studyName.setValue(rnaseqContainer.firstItemId().toString());

    bioprojectSummaryTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
        @Override/*w  w  w.j a  v a2 s  .  c om*/
        public String getStyle(Table table, Object itemId, Object propertyId) {
            String mynullreturn = "";
            if (propertyId == null) {
                // Styling for row
                //  Item item = bioprojectSummaryTable.getItem(itemId);
                Item item = table.getItem(itemId);

                String annotatus_status = "";

                if (item == null) { // checking this is important in lazy loading table. Otherwise it produces null pointer exception while scrolling down the table.
                    // System.out.println("It's null");
                    return mynullreturn;
                } else {
                    if (item.getItemProperty("annotation_status").getValue() != null) {
                        annotatus_status = (String) item.getItemProperty("annotation_status").getValue();
                    }
                }

                //               String   annotatus_status =  (String) item.getItemProperty("annotation_status").getValue();
                if (annotatus_status.toLowerCase().startsWith("ongoing")) {
                    // System.out.println(annotatus_status);
                    return "highlight-orange";
                } else if (annotatus_status.toLowerCase().startsWith("completed")) {
                    return "highlight-green";
                } else {
                    return mynullreturn;
                }

            } else {
                // styling for column propertyId
                return mynullreturn;
            }

        }
    });
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Upon clicking any project from the project/study summary table">

    bioprojectSummaryTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        int custom_annotation_counter = 0;

        public void itemClick(ItemClickEvent event) {
            rightTopTabsheet.setSelectedTab(rightTopForm);
            //<editor-fold defaultstate="collapsed" desc="filling study details on right panel">

            Object selectedStudyObject = event.getItemId();
            bioprojectSummaryTable.select(selectedStudyObject);
            tree.removeAllItems();
            rightTopForm.removeAllComponents();
            rightTopAnnotationForm.removeAllComponents();
            myform.removeAllComponents();

            String selectedStudy = selectedStudyObject.toString();
            String studyTitle = (String) bioprojectSummaryTable
                    .getContainerProperty(selectedStudyObject, "title").getValue();
            String studyName = (String) bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "name")
                    .getValue();
            String studyNumsample = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numsample").getValue());
            String studyNumexp = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numexp").getValue());
            String studyNumrun = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Numrun").getValue());
            String studyAvgspots = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "Avgspots").getValue());
            String studyAvgbases = String.valueOf(
                    bioprojectSummaryTable.getContainerProperty(selectedStudyObject, "avgbases").getValue());
            tree.addItem(selectedStudy);
            tree.setItemCaption(selectedStudy, "Study: " + selectedStudy);
            SQLContainer tempContainer = createMySQLContainer("study_extdb", selectedStudy); // In this table I will chaeck for the manual annotation status
            String extdbid = tempContainer.getItem(tempContainer.getIdByIndex(0)).getItemProperty("extdb")
                    .getValue().toString();

            HorizontalLayout studyAccLinkLayout = new HorizontalLayout();
            Label labelStudyAcc = new Label(
                    "<b>SRA Study Accession : </b>" + selectedStudy + "&nbsp;&nbsp;&nbsp;&nbsp;",
                    ContentMode.HTML);
            String ncbi_sra_study_link = "http://www.ncbi.nlm.nih.gov/Traces/sra/?study=" + selectedStudy;
            Link link = new Link("NCBI SRA Link", new ExternalResource(ncbi_sra_study_link));
            // Open the URL in a new window/tab
            link.setTargetName("_blank");
            // Indicate visually that it opens in a new window/tab
            link.setIcon(new ThemeResource("icons/external-link.png"));
            link.addStyleName("icon-after-caption");
            studyAccLinkLayout.addComponent(labelStudyAcc);
            studyAccLinkLayout.addComponent(link);
            rightTopForm.addComponent(studyAccLinkLayout);
            Label labelStudyTitle = new Label("<b>Study Title: </b>" + studyTitle, ContentMode.HTML);

            rightTopForm.addComponent(labelStudyTitle);
            Label labelStudyName = new Label("<b>Study Name: </b>" + studyName, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyName);
            tempContainer = null;
            tempContainer = createMySQLContainer("study_abstracts", selectedStudy); // In this table I will chaeck for the manual annotation status
            if (tempContainer.size() > 0) {
                Item tempItem = tempContainer.getItem(tempContainer.getIdByIndex(0));
                if (!(tempItem.getItemProperty("abstract").getValue() == null)) {
                    String abstr = tempItem.getItemProperty("abstract").getValue().toString();
                    String xref = tempItem.getItemProperty("xref").getValue().toString();
                    if (abstr.length() > 3) {
                        Label labelStudyAbstract = new Label("<b>Abstract: </b>" + abstr, ContentMode.HTML);
                        rightTopForm.addComponent(labelStudyAbstract);
                    }
                    if ((xref.length() > 3) & (xref.contains("pubmed"))) {
                        HorizontalLayout pubLinkLayout = new HorizontalLayout();
                        Label labelPubmed = new Label("<b>Pubmed Id : </b>" + "&nbsp;&nbsp;", ContentMode.HTML);
                        pubLinkLayout.addComponent(labelPubmed);
                        String[] pub = xref.split("\\|");
                        if (pub.length > 0) {
                            for (String p : pub) {
                                String[] pid = p.split("\\:-");
                                if (pid[0].startsWith("pubmed")) {
                                    Label tempPubLabel = new Label("&nbsp;&nbsp;&nbsp;&nbsp;",
                                            ContentMode.HTML);

                                    String pubmed_link = "http://www.ncbi.nlm.nih.gov/pubmed/" + pid[1];
                                    Link linkpub = new Link(pid[1], new ExternalResource(pubmed_link));
                                    linkpub.setTargetName("_blank");
                                    linkpub.setIcon(new ThemeResource("icons/external-link.png"));
                                    linkpub.addStyleName("icon-after-caption");
                                    pubLinkLayout.addComponent(tempPubLabel);
                                    pubLinkLayout.addComponent(linkpub);
                                }
                            }
                        }

                        rightTopForm.addComponent(pubLinkLayout);
                    }
                }
            }

            Label labelStudyNumsample = new Label("<b>Total number of samples: </b>" + studyNumsample,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumsample);
            Label labelStudyNumexp = new Label(
                    "<b>Total number of experiments (each experiment uses any one of the samples): </b>"
                            + studyNumexp,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumexp);
            Label labelStudyNumrun = new Label(
                    "<b>Total number of runs ( an experiment can have multiple runs) : </b>" + studyNumrun,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyNumrun);
            Label labelStudyAvgspots = new Label(
                    "<b>Avg number of spots or reads (per run): </b>" + studyAvgspots, ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgspots);
            Label labelStudyAvgbases = new Label("<b>Avg number of bases (per run): </b>" + studyAvgbases,
                    ContentMode.HTML);
            rightTopForm.addComponent(labelStudyAvgbases);

            if (extdbid.startsWith("PRJ")) {
                //<editor-fold defaultstate="collapsed" desc="if PRJ">
                tempContainer = createMySQLContainer("bioproject_details", extdbid);
                String bioproject_accession = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectAccession").getValue().toString();
                String bioproject_id = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("BioprojectId").getValue().toString();
                String bioproject_name = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Name").getValue().toString();
                String bioproject_title = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Title").getValue().toString();
                String bioproject_description = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Description").getValue().toString();
                String bioproject_capture = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Capture").getValue().toString();
                String bioproject_material = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("Material").getValue().toString();
                String bioproject_method = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("MethodType").getValue().toString();
                String bioproject_datatype = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("DataType").getValue().toString();
                String bioproject_sampleScope = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("SampleScope").getValue().toString();
                System.out.println(bioproject_description);
                Label labelBioprojectAccession = new Label(
                        "<b>Bioproject Accession : </b>" + bioproject_accession, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectAccession);
                Label labelBioprojectId = new Label("<b>Bioproject Id : </b>" + bioproject_id,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectId);
                Label labelBioprojectTitle = new Label("<b>Bioproject Title : </b>" + bioproject_title,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectTitle);
                Label labelBioprojectName = new Label("<b>Bioproject Name : </b>" + bioproject_name,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectName);
                Label labelBioprojectDescription = new Label(
                        "<b>Bioproject Description : </b>" + bioproject_description, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDescription);
                Label labelBioprojectCapture = new Label("<b>Bioproject Capture : </b>" + bioproject_capture,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectCapture);
                Label labelBioprojectMaterial = new Label(
                        "<b>Bioproject  Material : </b>" + bioproject_material, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMaterial);
                Label labelBioprojectMethod = new Label("<b>Bioproject Method : </b>" + bioproject_method,
                        ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectMethod);
                Label labelBioprojectDatatype = new Label(
                        "<b>Bioproject Data Type : </b>" + bioproject_datatype, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectDatatype);
                Label labelBioprojectSampleScope = new Label(
                        "<b>Bioproject Sample Scope : </b>" + bioproject_sampleScope, ContentMode.HTML);
                rightTopForm.addComponent(labelBioprojectSampleScope);

                //</editor-fold>
            }
            if (extdbid.startsWith("GSE")) {
                //<editor-fold defaultstate="collapsed" desc="if GSE">
                tempContainer = createMySQLContainer("study_gse_details", extdbid);
                String gse_accesion = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("gse").getValue().toString();
                String gse_summary = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("summary").getValue().toString();
                String gse_design = tempContainer.getItem(tempContainer.getIdByIndex(0))
                        .getItemProperty("overall_design").getValue().toString();
                // System.out.println(gse_summary);
                Label labelGSE = new Label("<b>GEO Series Accession : </b>" + gse_accesion, ContentMode.HTML);
                rightTopForm.addComponent(labelGSE);
                Label labelGseSummary = new Label("<b>GSE Summary : </b>" + gse_summary, ContentMode.HTML);
                rightTopForm.addComponent(labelGseSummary);
                Label labelGseDesign = new Label("<b>GSE Design : </b>" + gse_design, ContentMode.HTML);
                rightTopForm.addComponent(labelGseDesign);
                //</editor-fold>

            }

            try {
                String search_query = " SELECT * FROM manual_annotation "
                        + "where annotation_status = 'completed' " + " AND studyid =  '" + selectedStudy + "'";

                rnaseqContainer = createMySQLContainer("suggestion_by_manual_annotation", search_query);
                if (rnaseqContainer.getItemIds().size() > 0) {
                    Label ManualAnnotationLabelStart = new Label("<b>Manual Annotaion </b>", ContentMode.HTML);
                    rightTopForm.addComponent(ManualAnnotationLabelStart);

                    for (int i = 0; i < rnaseqContainer.getItemIds().size(); i++) {
                        Item tempItem = rnaseqContainer.getItem(rnaseqContainer.getIdByIndex(i));
                        int annotation_count = i + 1;
                        String stringManualAnnotationDetails = "------------ Manual Annotaion "
                                + annotation_count + "  ------------";
                        System.out.println("Item is " + tempItem);

                        if (!(tempItem.getItemProperty("isDisease").getValue() == null)) {
                            if (tempItem.getItemProperty("isDisease").getValue().toString().equals("1")) {
                                stringManualAnnotationDetails = stringManualAnnotationDetails
                                        + "<br></br> Disease = Yes ";
                            }
                        }
                        String stringStudyTypes = "";
                        if (!(tempItem.getItemProperty("isCaseControl").getValue() == null)) {
                            if (tempItem.getItemProperty("isCaseControl").getValue().toString().equals("1")) {
                                stringStudyTypes = stringStudyTypes + "<br> Case-Control = Yes ";

                            }
                        }

                        if (!(tempItem.getItemProperty("isTimeSeries").getValue() == null)) {
                            if (tempItem.getItemProperty("isTimeSeries").getValue().toString().equals("1")) {
                                stringStudyTypes = stringStudyTypes + "<br> Time Series = Yes ";

                            }
                        }

                        if (!(tempItem.getItemProperty("isTreatment").getValue() == null)) {
                            if (tempItem.getItemProperty("isTreatment").getValue().toString().equals("1")) {
                                stringStudyTypes = stringStudyTypes + "<br> Treatment = Yes ";

                            }
                        }
                        if (stringStudyTypes.length() > 2) {
                            stringManualAnnotationDetails = stringManualAnnotationDetails
                                    + "<br></br> <i> **** Study Types ****</i> " + stringStudyTypes;

                        }
                        String stringSampleTypes = "";
                        if (!(tempItem.getItemProperty("isCellLine").getValue() == null)) {
                            if (tempItem.getItemProperty("isCellLine").getValue().toString().equals("1")) {
                                stringSampleTypes = stringSampleTypes + "<br> Cell Line = Yes ";

                            }
                        }
                        if (!(tempItem.getItemProperty("isPrimaryCells").getValue() == null)) {
                            if (tempItem.getItemProperty("isPrimaryCells").getValue().toString().equals("1")) {
                                stringSampleTypes = stringSampleTypes + "<br> Primary Cells = Yes ";

                            }
                        }

                        if (!(tempItem.getItemProperty("isTissue").getValue() == null)) {
                            if (tempItem.getItemProperty("isTissue").getValue().toString().equals("1")) {
                                stringSampleTypes = stringSampleTypes + "<br> Tissue = Yes ";

                            }
                        }
                        if (!(tempItem.getItemProperty("isWholeBlood").getValue() == null)) {
                            if (tempItem.getItemProperty("isWholeBlood").getValue().toString().equals("1")) {
                                stringSampleTypes = stringSampleTypes + "<br> Blood = Yes ";
                            }
                        }

                        if (!(tempItem.getItemProperty("isPlasma").getValue() == null)) {
                            if (tempItem.getItemProperty("isPlasma").getValue().toString().equals("1")) {
                                stringSampleTypes = stringSampleTypes + "<br> Plasma = Yes ";
                            }
                        }
                        if (stringSampleTypes.length() > 2) {
                            stringManualAnnotationDetails = stringManualAnnotationDetails
                                    + "<br></br> <i>**** Sample Types ****</i> " + stringSampleTypes;

                        }
                        if (!(tempItem.getItemProperty("sequencing_platform").getValue() == null)) {
                            String sequencing_platform = tempItem.getItemProperty("sequencing_platform")
                                    .getValue().toString();
                            String[] annotated_platforms = sequencing_platform.split("\\;");
                            stringManualAnnotationDetails = stringManualAnnotationDetails
                                    + "<br></br> Sequencing Platform = " + sequencing_platform;
                        }

                        if (!(tempItem.getItemProperty("replicate_type").getValue() == null)) {
                            String replicate_type = tempItem.getItemProperty("replicate_type").getValue()
                                    .toString();
                            stringManualAnnotationDetails = stringManualAnnotationDetails
                                    + "<br></br> Replicate Type = " + replicate_type;
                        }

                        if (!(tempItem.getItemProperty("disease_category").getValue() == null)) {
                            String annotated_disease_category = tempItem.getItemProperty("disease_category")
                                    .getValue().toString();
                            String[] annotated_disease_categories = annotated_disease_category.split("\\;");
                            String string_disease_cat = "";
                            for (String cat : annotated_disease_categories) {
                                if (cat.startsWith("complex_disease")) {
                                    String[] cat_parts = cat.split("\\|");
                                    if (string_disease_cat.contains("complex_disease")) {
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(50)
                                                + " ---- " + cat_parts[1];
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(57)
                                                + " ---- " + cat_parts[2];
                                    } else {
                                        string_disease_cat = string_disease_cat
                                                + "&nbsp;&nbsp;Complex Disease ";
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(50)
                                                + " ---- " + cat_parts[1];
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(57)
                                                + " ---- " + cat_parts[2];
                                    }
                                }
                                if (cat.startsWith("rare_disease")) {
                                    String[] cat_parts = cat.split("\\|");
                                    if (string_disease_cat.contains("rare_disease")) {
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(50)
                                                + " ---- " + cat_parts[1];
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(57)
                                                + " ---- " + cat_parts[2];
                                    } else {
                                        if (string_disease_cat.contains("complex_disease")) {
                                            string_disease_cat = string_disease_cat + "<br> ";
                                        } else {
                                            string_disease_cat = string_disease_cat
                                                    + "&nbsp;&nbsp;Rare Disease ";
                                        }
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(50)
                                                + " ---- " + cat_parts[1];
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(57)
                                                + " ---- " + cat_parts[2];
                                    }
                                }
                                if (cat.startsWith("other_disease")) {
                                    String[] cat_parts = cat.split("\\|");
                                    if (string_disease_cat.contains("other_disease")) {
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(50)
                                                + " ---- " + cat_parts[1];
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(57)
                                                + " ---- " + cat_parts[2];
                                    } else {
                                        if (string_disease_cat.contains("complex_disease")
                                                || string_disease_cat.contains("rare_disease")) {
                                            string_disease_cat = string_disease_cat + "<br> ";
                                        } else {
                                            string_disease_cat = string_disease_cat
                                                    + "&nbsp;&nbsp;Other Disease ";
                                        }

                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(50)
                                                + " ---- " + cat_parts[1];
                                        string_disease_cat = string_disease_cat + "<br> " + createHTMLspaces(57)
                                                + " ---- " + cat_parts[2];
                                    }
                                }
                            }
                            stringManualAnnotationDetails = stringManualAnnotationDetails
                                    + "<br></br> Disease Category = " + string_disease_cat;
                        }

                        if (!(tempItem.getItemProperty("annotator").getValue() == null)) {
                            String annotator = tempItem.getItemProperty("annotator").getValue().toString();
                            stringManualAnnotationDetails = stringManualAnnotationDetails
                                    + "<br></br> Annotator = " + annotator;
                        }

                        stringManualAnnotationDetails = stringManualAnnotationDetails
                                + "<br></br>-----------------------------------";
                        Label tempManualAnnotationDetails = new Label(stringManualAnnotationDetails,
                                ContentMode.HTML);

                        rightTopForm.addComponent(tempManualAnnotationDetails);

                    }
                    //  Label ManualAnnotationLabelEnd = new Label("<b>Manual Annotaion </b>", ContentMode.HTML);
                    //    rightTopForm.addComponent(ManualAnnotationLabelEnd);

                }
            } catch (Exception e) {
            }
            //</editor-fold>
            //SQLContainer tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            tempContainer = createMySQLContainer("sra_rnaseq", selectedStudy);
            //  List<String> list = new ArrayList<String>();
            Map expMap = new HashMap();
            Map<String, String[]> expDetailMap = new HashMap<>();
            Map<String, String[]> platformMap = new HashMap<>();
            Map runMap = new HashMap();
            HashSet<String> biosampleSet = new HashSet<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for loop">

                String docid = tempContainer.getIdByIndex(i).toString();
                String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                biosampleSet.add(biosample);
                String[] b_parts = biosample.split("\\|");

                String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                String[] exp_parts = exp.split("\\|");
                String exp_acc = exp_parts[0];
                expMap.put(exp_acc, b_parts[0]);
                expDetailMap.put(exp_acc, exp_parts);

                String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Platform_InstrumentModel").getValue().toString();
                String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                platformMap.put(exp_acc, sra_plaforms_parts);

                String run = tempContainer.getItem(tempContainer.getIdByIndex(i)).getItemProperty("Runs")
                        .getValue().toString();
                String[] run_parts = run.split("\\|");
                if (run_parts.length > 0) {
                    for (int j = 0; j < run_parts.length; j++) {
                        String temprun = run_parts[j];
                        String[] temprun_parts = temprun.split("\\,");
                        runMap.put(temprun_parts[0], exp_acc);
                    }
                }
                //</editor-fold>
            }

            //<editor-fold defaultstate="collapsed" desc="Manual Annotaion">
            tempContainer = createMySQLContainer("biosample_with_studyacc", selectedStudy);
            int count_cell_line = 0;
            int count_organism_part = 0;
            int count_tissue = 0;
            int count_disease = 0;
            Set<String> cell_lines_set = new HashSet();
            Set<String> organism_part_set = new HashSet();
            Set<String> tissue_set = new HashSet();
            Set<String> disease_set = new HashSet();
            Map<String, Integer> cell_line_stat_map = new HashMap<>();
            Map<String, Integer> organism_part_stat_map = new HashMap<>();
            Map<String, Integer> tissue_stat_map = new HashMap<>();
            Map<String, Integer> disease_stat_map = new HashMap<>();
            for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                //<editor-fold defaultstate="collapsed" desc="for biosample attributes">
                String biosample_attr = tempContainer.getItem(tempContainer.getIdByIndex(i))
                        .getItemProperty("Attributes").getValue().toString();
                String[] biosample_attr_parts = biosample_attr.split("\\:-");
                if (biosample_attr_parts.length > 0) {
                    String[] attr_names = biosample_attr_parts[0].split("\\|");
                    String[] attr_values = new String[] {};
                    if (biosample_attr_parts.length > 1) {
                        attr_values = biosample_attr_parts[1].split("\\|");
                    }
                    int atn_index = 0;
                    for (String atn : attr_names) {
                        if (atn.equalsIgnoreCase("cell line")) {
                            count_cell_line = count_cell_line + 1;
                            if (attr_values.length >= atn_index) {
                                String cell_line_value = attr_values[atn_index];
                                cell_lines_set.add(cell_line_value);
                                if (cell_line_stat_map.containsKey(cell_line_value)) {
                                    cell_line_stat_map.put(cell_line_value,
                                            cell_line_stat_map.get(cell_line_value) + 1);
                                } else {
                                    cell_line_stat_map.put(cell_line_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("organism part")) {
                            count_organism_part = count_organism_part + 1;
                            if (attr_values.length >= atn_index) {
                                String organism_part_value = attr_values[atn_index];
                                organism_part_set.add(organism_part_value);
                                if (organism_part_stat_map.containsKey(organism_part_value)) {
                                    organism_part_stat_map.put(organism_part_value,
                                            organism_part_stat_map.get(organism_part_value) + 1);
                                } else {
                                    organism_part_stat_map.put(organism_part_value, 1);
                                }
                            }

                        }

                        if (atn.contains("disease")) {
                            count_disease = count_disease + 1;
                            if (attr_values.length >= atn_index) {
                                String disease_value = attr_values[atn_index];
                                disease_set.add(disease_value);
                                if (disease_stat_map.containsKey(disease_value)) {
                                    disease_stat_map.put(disease_value,
                                            disease_stat_map.get(disease_value) + 1);
                                } else {
                                    disease_stat_map.put(disease_value, 1);
                                }
                            }

                        }
                        if (atn.equalsIgnoreCase("tissue")) {
                            count_tissue = count_tissue + 1;
                            if (attr_values.length >= atn_index) {
                                String tissue_value = attr_values[atn_index];
                                tissue_set.add(tissue_value);
                                if (tissue_stat_map.containsKey(tissue_value)) {
                                    tissue_stat_map.put(tissue_value, tissue_stat_map.get(tissue_value) + 1);
                                } else {
                                    tissue_stat_map.put(tissue_value, 1);
                                }
                            }

                        }
                        atn_index = atn_index + 1;
                    }
                }
                //</editor-fold>

            }

            String suggestion_cell_line = "";
            String suggestion_organism_part = "";
            String suggestion_tissue = "";
            String suggestion_disease = "";
            String samplesType_from_sra = "";
            String cell_line_confidence = "";
            String organism_part_confidence = "";
            String disease_confidence = "";
            String tissue_confidence = "";
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has cell line">
            if (count_cell_line > 0) {
                if (Integer.parseInt(studyNumsample) == count_cell_line) {
                    //good. all samples are from cell lines
                    suggestion_cell_line = "Yes:";
                    String cell_line_value = cell_lines_set.iterator().next();
                    suggestion_cell_line = suggestion_cell_line + cell_line_value;
                    cell_line_confidence = "100%. All " + cell_line_stat_map.get(cell_line_value).toString()
                            + " Samples";
                } else {
                    suggestion_cell_line = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : cell_line_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_cell_line = suggestion_cell_line + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    cell_line_confidence = confidence_percent + "%";
                    for (Iterator<String> it = cell_lines_set.iterator(); it.hasNext();) {
                        String cellLine = it.next();
                        if (cellLine.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_cell_line = suggestion_cell_line + ", " + cellLine + "("
                                    + cell_line_stat_map.get(cellLine).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_cell_line = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has organism part">
            if (count_organism_part > 0) {
                if (Integer.parseInt(studyNumsample) == count_organism_part) {
                    //good. all samples are from cell lines
                    suggestion_organism_part = "Yes:";
                    String organism_part_value = organism_part_set.iterator().next();
                    suggestion_organism_part = suggestion_organism_part + organism_part_value;
                    organism_part_confidence = "100%. All "
                            + organism_part_stat_map.get(organism_part_value).toString() + " Samples";
                } else {
                    suggestion_organism_part = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : organism_part_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_organism_part = suggestion_organism_part + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    organism_part_confidence = confidence_percent + "%";
                    for (Iterator<String> it = organism_part_set.iterator(); it.hasNext();) {
                        String organismPart = it.next();
                        if (organismPart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_organism_part = suggestion_organism_part + ", " + organismPart + "("
                                    + organism_part_stat_map.get(organismPart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_organism_part = " No";
            }
            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has disease">
            if (count_disease > 0) {
                if (Integer.parseInt(studyNumsample) == count_disease) {
                    //good. all samples are from cell lines
                    suggestion_disease = "Yes:";
                    String disease_value = disease_set.iterator().next();
                    suggestion_disease = suggestion_disease + disease_value;
                    disease_confidence = "100%. All " + disease_stat_map.get(disease_value).toString()
                            + " Samples";
                } else {
                    suggestion_disease = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : disease_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_disease = suggestion_disease + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    disease_confidence = confidence_percent + "%";
                    for (Iterator<String> it = disease_set.iterator(); it.hasNext();) {
                        String diseasePart = it.next();
                        if (diseasePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_disease = suggestion_disease + ", " + diseasePart + "("
                                    + disease_stat_map.get(diseasePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_disease = " No";
            }
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="if else biosmaple attr has tissue">
            if (count_tissue > 0) {
                if (Integer.parseInt(studyNumsample) == count_tissue) {
                    //good. all samples are from cell lines
                    suggestion_tissue = "Yes:";
                    String tissue_value = tissue_set.iterator().next();
                    suggestion_tissue = suggestion_tissue + tissue_value;
                    tissue_confidence = "100%. All " + tissue_stat_map.get(tissue_value).toString()
                            + " Samples";
                } else {
                    suggestion_tissue = "Yes:";
                    Map.Entry<String, Integer> maxEntry = null;
                    for (Map.Entry<String, Integer> entry : tissue_stat_map.entrySet()) {
                        if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                            maxEntry = entry;
                        }
                    }
                    suggestion_tissue = suggestion_tissue + maxEntry.getKey() + "("
                            + maxEntry.getValue().toString() + " samples)";
                    int confidence_percent = (int) (maxEntry.getValue() * 100.0f)
                            / (Integer.parseInt(studyNumsample));
                    tissue_confidence = confidence_percent + "%";
                    for (Iterator<String> it = tissue_set.iterator(); it.hasNext();) {
                        String tissuePart = it.next();
                        if (tissuePart.equals(maxEntry.getKey())) {
                            //do nothing
                        } else {
                            suggestion_tissue = suggestion_tissue + ", " + tissuePart + "("
                                    + tissue_stat_map.get(tissuePart).toString() + ")";
                        }
                    }

                }
            } else {
                suggestion_tissue = " No";
            }

            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="filling right top manual annotation">
            //<editor-fold defaultstate="collapsed" desc="disease layout (Manual Annotation">
            HorizontalLayout diseaseLayout = new HorizontalLayout();
            CheckBox checkboxDiseaseYes = new CheckBox("Yes");
            CheckBox checkboxDiseaseNo = new CheckBox("No");

            String disease_from_biosample_attribute = "";
            if (suggestion_disease.startsWith("Yes")) {
                disease_from_biosample_attribute = "From Biosample: " + suggestion_disease;
            }
            String disease_found = "";
            String disease_text_parsed_confidence = "";
            for (String disease : list_of_diseases) {
                if (StringUtils.containsIgnoreCase(studyName, disease)
                        || StringUtils.containsIgnoreCase(studyTitle, disease)) {
                    checkboxDiseaseYes.setValue(true);
                    disease_found = disease_found + disease + " ";
                    disease_text_parsed_confidence = "keyword found in Study or Title";
                }
            }
            String diseaseLabelString = "";
            if (disease_text_parsed_confidence.length() > 1) {
                diseaseLabelString = "<b><i>Suggestion: </i></b>" + disease_found
                        + " <b> <i> Confidence: <i></b>  " + disease_text_parsed_confidence;
            }
            if (disease_from_biosample_attribute.length() > 1) {
                diseaseLabelString = diseaseLabelString + "<b><i>Suggestion: </i></b>"
                        + disease_from_biosample_attribute + " <b> <i> Confidence: <i></b>  "
                        + disease_confidence;
            }

            Label diseaseLabel = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + diseaseLabelString,
                    ContentMode.HTML);
            Label diseaseTitle = new Label("<b>Disease: </b>", ContentMode.HTML);
            diseaseLayout.addComponent(diseaseTitle);
            diseaseLayout.addComponent(checkboxDiseaseNo);
            diseaseLayout.addComponent(checkboxDiseaseYes);
            diseaseLayout.addComponent(diseaseLabel);
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="study types layout (Manual Annotation)">
            Panel studyTypesPanel = new Panel("Sample Types");
            HorizontalLayout studyTypesLayout = new HorizontalLayout();

            HorizontalLayout caseControlLayout = new HorizontalLayout();
            CheckBox checkboxCaseControlYes = new CheckBox("Yes");
            CheckBox checkboxCaseControlNo = new CheckBox("No");
            // checkboxCaseControlYes.setValue(true);
            Label caseControlTitle = new Label("<b>Case-Control: </b>", ContentMode.HTML);
            caseControlLayout.addComponent(caseControlTitle);
            caseControlLayout.addComponent(checkboxCaseControlYes);
            caseControlLayout.addComponent(checkboxCaseControlNo);

            HorizontalLayout timeSeriesLayout = new HorizontalLayout();
            CheckBox checkboxTimeSeriesYes = new CheckBox("Yes");
            CheckBox checkboxTimeSeriesNo = new CheckBox("No");
            //checkboxTimeSeriesYes.setValue(true);
            Label timeSeriesTitle = new Label("<b>Time Series: </b>", ContentMode.HTML);
            timeSeriesLayout.addComponent(timeSeriesTitle);
            timeSeriesLayout.addComponent(checkboxTimeSeriesYes);
            timeSeriesLayout.addComponent(checkboxTimeSeriesNo);

            HorizontalLayout treatementLayout = new HorizontalLayout();
            CheckBox checkboxTreatmentYes = new CheckBox("Yes");
            CheckBox checkboxTreatmentNo = new CheckBox("No");
            //  checkboxTreatmentYes.setValue(true);
            Label treatmentTitle = new Label("<b>Treatment: </b>", ContentMode.HTML);
            treatementLayout.addComponent(treatmentTitle);
            treatementLayout.addComponent(checkboxTreatmentYes);
            treatementLayout.addComponent(checkboxTreatmentNo);

            studyTypesLayout.addComponent(caseControlLayout);
            Label emptyLabel = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
                    ContentMode.HTML);
            studyTypesLayout.addComponent(emptyLabel);
            studyTypesLayout.addComponent(timeSeriesLayout);
            Label emptyLabel0 = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
                    ContentMode.HTML);
            studyTypesLayout.addComponent(emptyLabel0);
            studyTypesLayout.addComponent(treatementLayout);
            studyTypesLayout.setSizeFull();
            studyTypesPanel.setContent(studyTypesLayout);
            studyTypesPanel.setWidth(Sizeable.SIZE_UNDEFINED, Unit.PERCENTAGE);
            studyTypesPanel.addStyleName("panelborder");
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="Disease Category Layout">
            Panel diseaseCategoryPanel = new Panel("Disease Category");
            HorizontalLayout diseaseCategoriesLayout = new HorizontalLayout();
            //Complex Disease
            ListSelect complexDisease = new ListSelect("Complex Disease");
            complexDisease.setMultiSelect(true);

            for (String disease : complexDiseaseArray) {
                complexDisease.addItem(disease);

            }
            diseaseCategoriesLayout.addComponent(complexDisease);
            Label emptyLabel2 = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
                    ContentMode.HTML);
            diseaseCategoriesLayout.addComponent(emptyLabel2);
            // Rare disease
            ListSelect rareDisease = new ListSelect("Rare Diseases");
            rareDisease.setMultiSelect(true);
            for (String disease : rareDiseaseArray) {
                rareDisease.addItem(disease);
            }
            diseaseCategoriesLayout.addComponent(rareDisease);
            Label emptyLabel3 = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
                    ContentMode.HTML);
            diseaseCategoriesLayout.addComponent(emptyLabel3);
            // Other diseases
            ListSelect otherDisease = new ListSelect("Other Diseases");
            otherDisease.setMultiSelect(true);
            for (String disease : otherDiseaseArray) {
                otherDisease.addItem(disease);
            }
            diseaseCategoriesLayout.addComponent(otherDisease);
            //   Label emptyLabel4 = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", ContentMode.HTML);
            //  diseaseCategoriesLayout.addComponent(emptyLabel4);

            diseaseCategoryPanel.setContent(diseaseCategoriesLayout);
            diseaseCategoryPanel.setWidth(Sizeable.SIZE_UNDEFINED, Unit.PERCENTAGE);
            diseaseCategoryPanel.addStyleName("panelborder");

            /*
             HorizontalLayout diseaseCategoriesLayout = new HorizontalLayout();
             Label diseaseCategoryLabel = new Label("<b><i>Suggestion: </i></b>" + disease_found + " <b> <i> Confidence: <i></b>  " + disease_confidence, ContentMode.HTML);
             String[] diseaseCategories = new String[]{"Complex Disease", "Rare Disease", "Other", "Not Sure"};
             List<String> diseaseCategoriesList = Arrays.asList(diseaseCategories);
             ComboBox diseaseCategoryComboBox = new ComboBox("Disease Category", diseaseCategoriesList);
             diseaseCategoriesLayout.addComponent(diseaseCategoryComboBox);
             diseaseCategoriesLayout.addComponent(diseaseCategoryLabel);
             */
            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="platform layout (manual annotation)">
            //  List<String> platformsList = Arrays.asList(platforms);
            //  ComboBox platformsListSelect = new ComboBox("Sequencing Platform", platformsList);
            ListSelect platformsListSelect = new ListSelect("Sequencing Platform");
            platformsListSelect.setMultiSelect(true);
            for (String platform : platforms) {
                platformsListSelect.addItem(platform);
            }
            Set<String> matchedPlatformSet = new HashSet();
            String platform_from_sra = "";
            String platorm_confidence = "";
            int matchPlatformCount = 0;
            for (String[] val : platformMap.values()) {
                if (val.length > 1) {
                    for (String pf : platforms) {
                        if (val[0].equalsIgnoreCase(pf)) {
                            matchedPlatformSet.add(pf);
                            matchPlatformCount = matchPlatformCount + 1;
                        }
                    }
                } else {

                }
            }
            if (matchedPlatformSet.isEmpty()) {
                platform_from_sra = "Match Not Found";
            } else {
                if (matchedPlatformSet.size() == matchPlatformCount) {
                    if (matchedPlatformSet.size() == 1) {
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        for (Iterator i = platformsListSelect.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();
                            if (platform_from_sra.equalsIgnoreCase(temp)) {
                                platformsListSelect.select(iid);
                            }
                        }

                    } else {
                        platform_from_sra = "Can't predict. All experiment on different Platforms";
                    }
                } else {
                    if (matchedPlatformSet.size() == 1) {
                        // Perfect 
                        platform_from_sra = matchedPlatformSet.iterator().next().toString();
                        for (Iterator i = platformsListSelect.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();
                            if (platform_from_sra.equalsIgnoreCase(temp)) {
                                platformsListSelect.select(iid);
                            }
                        }
                        platorm_confidence = "100%";
                    } else {

                    }
                }
            }

            HorizontalLayout platformLayout = new HorizontalLayout();
            Label suggestedPlatformLabel = new Label("<b><i>Suggestion: </i></b>" + platform_from_sra
                    + "<b> <i> Confidence: <i></b>  " + platorm_confidence, ContentMode.HTML);
            platformsListSelect.setHeight(platformsListSelect.size() + 2, Unit.EM);
            platformLayout.addComponent(platformsListSelect);
            platformLayout.addComponent(suggestedPlatformLabel);
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="Sample types Panel (Manual Annotation)">
            Panel sampleTypesPanel = new Panel("Sample Types");
            VerticalLayout sampleTypesLayout = new VerticalLayout();
            CheckBox checkboxSampleTypeCellLine = new CheckBox("Cell Line");
            CheckBox checkboxSampleTypeTissue = new CheckBox("Tissue");
            CheckBox checkboxSampleTypePrimaryCells = new CheckBox("Primary Cells");
            CheckBox checkboxSampleTypeWholeBlood = new CheckBox("Blood");
            CheckBox checkboxSampleTypePlasma = new CheckBox("Plasma");
            String suggestedCellTypeLabelString = "";
            if (suggestion_cell_line.startsWith("Yes")) {
                //sampleTypesListComboBox.select("Cell Lines");
                checkboxSampleTypeCellLine.setValue(true);
                suggestedCellTypeLabelString = "<b><i>&nbsp;&nbsp;&nbsp;&nbsp;Suggestion: </i></b>"
                        + "Cell Lines --> " + suggestion_cell_line + " <b> <i> Confidence: <i></b>   "
                        + cell_line_confidence;
            }
            Label suggestedCellLineLabel = new Label(suggestedCellTypeLabelString, ContentMode.HTML);
            String suggestedTissueLabelString = "";
            if (suggestion_organism_part.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString
                        + "<b><i>&nbsp;&nbsp;&nbsp;&nbsp;Suggestion: </i></b>" + "Organism part --> "
                        + suggestion_organism_part + " <b> <i> Confidence: <i></b>   "
                        + organism_part_confidence;
            }

            if (suggestion_tissue.startsWith("Yes")) {
                checkboxSampleTypeTissue.setValue(true);
                suggestedTissueLabelString = suggestedTissueLabelString
                        + "<b><i>&nbsp;&nbsp;&nbsp;&nbsp;Suggestion: </i></b>" + "Tissue --> "
                        + suggestion_tissue + " <b> <i> Confidence: <i></b>   " + tissue_confidence;
            }
            Label suggestedTissueLabel = new Label(suggestedTissueLabelString, ContentMode.HTML);

            String suggestedStemCellString = "";
            /*
             if (suggestion_stem_cell.startsWith("Yes")) {                   
             checkboxSampleTypeStemCells.setValue(true);
             suggestedCellTypeLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_stem_cell + " <b> <i> Confidence: <i></b>   " + stem_cell_confidence;
             }
             */
            Label suggestedStemCellLabel = new Label(suggestedStemCellString, ContentMode.HTML);

            String suggestedWholeBloodLabelString = "";
            /*
             if (suggestion_whole_blood.startsWith("Yes")) {                   
             checkboxSampleTypeWholeBlood.setValue(true);
             suggestedWholeBloodLabelString = "<b><i>Suggestion: </i></b>" + "Whole Blood --> " + suggestion_whole_blood + " <b> <i> Confidence: <i></b>   " + whole_blood_confidence;
             }
             */
            Label suggestedWholeBloodLabel = new Label(suggestedWholeBloodLabelString, ContentMode.HTML);

            String suggestedPlasmaLabelString = "";
            /*
             if (suggestion_plasma.startsWith("Yes")) {                   
             checkboxSampleTypePlasma.setValue(true);
             suggestedPlasmaLabelString = "<b><i>Suggestion: </i></b>" + "Cell Lines --> " + suggestion_plasma + " <b> <i> Confidence: <i></b>   " + plasma_confidence;
             }
             */
            Label suggestedPlasmaLabel = new Label(suggestedPlasmaLabelString, ContentMode.HTML);

            HorizontalLayout CellLineLayout = new HorizontalLayout();
            CellLineLayout.addComponent(checkboxSampleTypeCellLine);
            CellLineLayout.addComponent(suggestedCellLineLabel);

            HorizontalLayout PrimaryCellsLayout = new HorizontalLayout();
            PrimaryCellsLayout.addComponent(checkboxSampleTypePrimaryCells);
            //  PrimaryCellsLayout.addComponent(suggestedPrimaryCellsLabel);

            HorizontalLayout TissueLayout = new HorizontalLayout();
            TissueLayout.addComponent(checkboxSampleTypeTissue);
            TissueLayout.addComponent(suggestedTissueLabel);

            HorizontalLayout WholeBloodLayout = new HorizontalLayout();
            WholeBloodLayout.addComponent(checkboxSampleTypeWholeBlood);
            WholeBloodLayout.addComponent(suggestedWholeBloodLabel);

            HorizontalLayout PlasmaLayout = new HorizontalLayout();
            PlasmaLayout.addComponent(checkboxSampleTypePlasma);
            PlasmaLayout.addComponent(suggestedPlasmaLabel);

            sampleTypesLayout.addComponent(CellLineLayout);
            sampleTypesLayout.addComponent(PrimaryCellsLayout);
            sampleTypesLayout.addComponent(TissueLayout);
            sampleTypesLayout.addComponent(WholeBloodLayout);
            sampleTypesLayout.addComponent(PlasmaLayout);

            sampleTypesPanel.setContent(sampleTypesLayout);
            sampleTypesPanel.setWidth(Sizeable.SIZE_UNDEFINED, Unit.PERCENTAGE);
            sampleTypesPanel.addStyleName("panelborder");

            //</editor-fold>
            Button addCustomAnnoButton = new Button("++ Custom Annotation");
            addCustomAnnoButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    custom_annotation_counter = custom_annotation_counter + 1;
                    HorizontalLayout customLayout = new HorizontalLayout();
                    TextField customAnnoName = new TextField("Custom Name");
                    customAnnoName.setId("customAnnoName" + custom_annotation_counter);
                    TextField customAnnoValue = new TextField("Custom Value");
                    customLayout.addComponent(customAnnoName);
                    customLayout.addComponent(customAnnoValue);
                    customAnnoValue.setId("customAnnoValue" + custom_annotation_counter);
                    int addCustomAnnoButtonIndex = rightTopAnnotationForm
                            .getComponentIndex(addCustomAnnoButton);
                    rightTopAnnotationForm.addComponent(customLayout, addCustomAnnoButtonIndex);

                }
            });

            //<editor-fold defaultstate="collapsed" desc="Replicate Type">
            HorizontalLayout replicatTypesLayout = new HorizontalLayout();
            String replicateType_from_sra = "";
            String replicateType_confidence = "";
            Label suggestedreplicatTypeLabel = new Label("<b><i>Suggestion: </i></b>" + replicateType_from_sra
                    + " <b> <i> Confidence: <i></b>  " + replicateType_confidence, ContentMode.HTML);
            String[] replicatTypes = new String[] { "Biological -- different individuals",
                    "Biological -- same individual but severe treatment to RNA",
                    "Semi Biological/Technical -- mild treatment",
                    "Technical -- machine parameter or buffer (very mild)" };
            List<String> replicatTypesList = Arrays.asList(replicatTypes);
            ComboBox replicatTypesListComboBox = new ComboBox("Replicates Type ", replicatTypesList);
            replicatTypesLayout.addComponent(replicatTypesListComboBox);
            replicatTypesLayout.addComponent(suggestedreplicatTypeLabel);

            //</editor-fold>
            checkboxCaseControlYes.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    if (checkboxCaseControlYes.getValue()) {
                        checkboxCaseControlNo.setValue(!checkboxCaseControlYes.getValue());
                    }

                }
            });
            checkboxCaseControlNo.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    if (checkboxCaseControlNo.getValue()) {
                        checkboxCaseControlYes.setValue(!checkboxCaseControlNo.getValue());
                    }
                }
            });

            checkboxTimeSeriesYes.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    if (checkboxTimeSeriesYes.getValue()) {
                        checkboxTimeSeriesNo.setValue(!checkboxTimeSeriesYes.getValue());
                    }

                }
            });
            checkboxTimeSeriesNo.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    if (checkboxTimeSeriesNo.getValue()) {
                        checkboxTimeSeriesYes.setValue(!checkboxTimeSeriesNo.getValue());
                    }
                }
            });

            checkboxTreatmentYes.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    if (checkboxTreatmentYes.getValue()) {
                        checkboxTreatmentNo.setValue(!checkboxTreatmentYes.getValue());
                    }

                }
            });
            checkboxTreatmentNo.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    if (checkboxTreatmentNo.getValue()) {
                        checkboxTreatmentYes.setValue(!checkboxTreatmentNo.getValue());
                    }
                }
            });

            checkboxDiseaseYes.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseNo.setValue(!checkboxDiseaseYes.getValue());
                    diseaseCategoryPanel.setVisible(true);
                }
            });
            checkboxDiseaseNo.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxDiseaseYes.setValue(!checkboxDiseaseNo.getValue());
                    diseaseCategoryPanel.setVisible(false);
                }
            });

            //<editor-fold defaultstate="collapsed" desc="Annotation Status Ongoing or Completed ">
            Panel annotationStatusPanel = new Panel("Annotation Status");
            CheckBox checkboxAnnotaionCompleted = new CheckBox("Annotaion Completed");
            CheckBox checkboxAnnotaionOngoing = new CheckBox("Annotaion Ongoing");
            checkboxAnnotaionOngoing.setValue(true);
            checkboxAnnotaionCompleted.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionOngoing.setValue(!checkboxAnnotaionCompleted.getValue());
                }
            });
            checkboxAnnotaionOngoing.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    checkboxAnnotaionCompleted.setValue(!checkboxAnnotaionOngoing.getValue());
                }
            });

            HorizontalLayout annotationStatusLayout = new HorizontalLayout();
            annotationStatusLayout.addComponent(checkboxAnnotaionOngoing);
            Label emptyLabel_1 = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
                    ContentMode.HTML);
            annotationStatusLayout.addComponent(emptyLabel_1);
            annotationStatusLayout.addComponent(checkboxAnnotaionCompleted);
            annotationStatusPanel.setContent(annotationStatusLayout);
            annotationStatusPanel.setWidth(Sizeable.SIZE_UNDEFINED, Unit.PERCENTAGE);
            annotationStatusPanel.addStyleName("panelborder");
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="login, sign in, register, and suggestion by manual annotation if logged ">
            Button loginButton = new Button("Sign In");
            Button registerButton = new Button("Register");

            HorizontalLayout requestLoginLayout = new HorizontalLayout();
            requestLoginLayout.addComponent(userWelcome);
            requestLoginLayout.addComponent(loginButton);
            requestLoginLayout.addComponent(registerButton);
            rightTopAnnotationForm.addComponent(requestLoginLayout);
            VerticalLayout userPasswordLayout = new VerticalLayout();
            VerticalLayout registerLayout = new VerticalLayout();

            loginButton.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    if (event.getButton() == loginButton) {
                        if (loginButton.getCaption() == "Sign In") {

                            // Create the user input field
                            user = new TextField("User:");
                            user.setWidth("300px");
                            user.setRequired(true);
                            user.setInputPrompt("Your username (eg. joe@email.com)");
                            user.addValidator(new EmailValidator("Username must be an email address"));
                            user.setInvalidAllowed(false);

                            // Create the password input field
                            password = new PasswordField("Password:");
                            password.setWidth("300px");
                            password.addValidator(new PasswordValidator());
                            password.setRequired(true);
                            password.setValue("");
                            password.setNullRepresentation("");

                            // Create login button
                            loginSubmitButton = new Button("Login", this);
                            loginSubmitButton.addClickListener(new Button.ClickListener() {

                                @Override
                                public void buttonClick(ClickEvent event) {
                                    if (event.getButton() == loginSubmitButton) {
                                        if (!user.isValid() || !password.isValid()) {
                                            return;
                                        }
                                        String username = user.getValue();
                                        String entered_password = password.getValue();

                                        boolean isChecked = false;
                                        try {
                                            // check user details in the database
                                            SQLContainer checkContainer = createMySQLContainer(
                                                    "annotation_users", "dummy");
                                            Item id = checkContainer
                                                    .getItem(new RowId(new Object[] { username }));
                                            if (id != null) {
                                                user.setCaption("User");
                                                if (entered_password.equals(
                                                        id.getItemProperty("password").getValue().toString())) {
                                                    isChecked = true;
                                                } else {
                                                    password.setCaption("Password (wrong password entered)");
                                                    System.out.println(
                                                            "Password can not be validated. Please re-enter or Register");
                                                    System.out.println(
                                                            "Fetched password for user : " + id.toString()
                                                                    + " is " + id.getItemProperty("password")
                                                                            .getValue().toString());
                                                }
                                            } else {
                                                user.setCaption(
                                                        "User (wrong username entered. Enter your email again or register)");
                                                password.setCaption("Password");
                                                System.out.println(
                                                        "User name can not be validated. Please re-enter or Register");
                                            }

                                        } catch (Exception e) {
                                            isChecked = false;
                                            System.out.println(
                                                    "Problem in validating login details using database. Either user or password is wrong");
                                        }
                                        boolean isValid = username.equals("test@test.com")
                                                && entered_password.equals("passw0rd");

                                        if (isChecked) {
                                            // System.out.println("User name and passoword : Both are correct");
                                            // Store the current user in the service session
                                            getSession().setAttribute("user", username);
                                            userWelcome.setValue("Hello " + username);
                                            int userPasswordLayoutIndex = rightTopAnnotationForm
                                                    .getComponentIndex(userPasswordLayout);
                                            requestLoginLayout.removeComponent(registerButton);
                                            rightTopAnnotationForm.addComponent(requestLoginLayout,
                                                    userPasswordLayoutIndex);
                                            rightTopAnnotationForm.removeComponent(userPasswordLayout);
                                            userPasswordLayout.removeAllComponents();
                                            loginButton.setCaption("Logout");
                                        } else {
                                            // Wrong password clear the password field and refocuses it
                                            password.setValue(null);
                                            password.focus();

                                        }
                                        // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                    }
                                }
                            });

                            // Add both to a panel
                            VerticalLayout fields = new VerticalLayout(user, password, loginSubmitButton);
                            fields.setCaption(
                                    "Please login to access the application. (test@test.com/passw0rd)");
                            fields.setSpacing(true);
                            fields.setMargin(new MarginInfo(true, true, true, false));
                            fields.setSizeUndefined();

                            // The view root layout
                            userPasswordLayout.addComponent(fields);
                            int addUserLayoutIndex = rightTopAnnotationForm
                                    .getComponentIndex(requestLoginLayout);
                            rightTopAnnotationForm.addComponent(userPasswordLayout, addUserLayoutIndex);
                            rightTopAnnotationForm.removeComponent(requestLoginLayout);

                        } else if (loginButton.getCaption() == "Logout") {
                            getSession().setAttribute("user", null);
                            userWelcome.setValue("Anonymous ");
                            loginButton.setCaption("Sign In");
                            requestLoginLayout.addComponent(registerButton);

                        }
                    }

                }
            });

            registerButton.addClickListener(new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    if (event.getButton() == registerButton) {

                        // Create the user input field
                        TextField newUser = new TextField("User:");
                        newUser.setWidth("300px");
                        newUser.setRequired(true);
                        newUser.setInputPrompt("Your username (eg. joe@email.com)");
                        newUser.addValidator(new EmailValidator("Username must be an email address"));
                        newUser.setInvalidAllowed(false);

                        // Create the password input field
                        PasswordField setPassword = new PasswordField("Set Password:");
                        setPassword.setWidth("300px");
                        setPassword.addValidator(new PasswordValidator());
                        setPassword.setRequired(true);
                        setPassword.setValue("");
                        setPassword.setNullRepresentation("");

                        // Create login button
                        Button registerSubmitButton = new Button("Register me", this);
                        registerSubmitButton.addClickListener(new Button.ClickListener() {

                            @Override
                            public void buttonClick(ClickEvent event) {
                                if (event.getButton() == registerSubmitButton) {
                                    if (!newUser.isValid() || !setPassword.isValid()) {
                                        return;
                                    }
                                    String username = newUser.getValue();
                                    String entered_password = setPassword.getValue();
                                    String insert_user = "'" + username + "' , '" + entered_password + "'";

                                    boolean isInserted = true;
                                    try {
                                        // Insert new user details in the database
                                        SQLContainer insertContainer = createMySQLContainer("annotation_users",
                                                insert_user);
                                        Object id = insertContainer.addItem();
                                        insertContainer.getContainerProperty(id, "user").setValue(username);
                                        insertContainer.getContainerProperty(id, "password")
                                                .setValue(entered_password);
                                        insertContainer.commit();
                                    } catch (Exception e) {
                                        isInserted = false;
                                        System.out.println(
                                                "Problem in registering new user while inserting into the database");
                                    }

                                    if (isInserted) {
                                        userWelcome.setValue(
                                                "Registered Successfulle. Please Sign in to annotate. ");
                                        int registerLayoutIndex = rightTopAnnotationForm
                                                .getComponentIndex(registerLayout);
                                        rightTopAnnotationForm.addComponent(requestLoginLayout,
                                                registerLayoutIndex);
                                        rightTopAnnotationForm.removeComponent(registerLayout);
                                        registerLayout.removeAllComponents();
                                        requestLoginLayout.removeComponent(registerButton);
                                    } else {
                                        // Wrong password clear the password field and refocuses it
                                        password.setValue(null);
                                        password.focus();

                                    }
                                    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                }
                            }
                        });

                        // Add both to a panel
                        VerticalLayout registerFields = new VerticalLayout(newUser, setPassword,
                                registerSubmitButton);
                        registerFields
                                .setCaption("Please login to access the application. (test@test.com/passw0rd)");
                        registerFields.setSpacing(true);
                        registerFields.setMargin(new MarginInfo(true, true, true, false));
                        registerFields.setSizeUndefined();

                        registerLayout.addComponent(registerFields);
                        int requestLoginLayoutIndex = rightTopAnnotationForm
                                .getComponentIndex(requestLoginLayout);
                        rightTopAnnotationForm.addComponent(registerLayout, requestLoginLayoutIndex);
                        rightTopAnnotationForm.removeComponent(requestLoginLayout);

                    }
                }
            });
            boolean isLoggedIn = getSession().getAttribute("user") != null;
            if (isLoggedIn) {
                // System.out.println("user attribute" + String.valueOf(getSession().getAttribute("user")));
                String logged_user = String.valueOf(getSession().getAttribute("user"));
                userWelcome.setValue("Hello " + logged_user);
                loginButton.setCaption("Logout");
                requestLoginLayout.removeComponent(registerButton);
                try {

                    String search_query = " SELECT * FROM manual_annotation " + "where annotator = '"
                            + logged_user + "'" + " AND studyid =  '" + selectedStudy + "'";

                    rnaseqContainer = createMySQLContainer("suggestion_by_manual_annotation", search_query);
                    //rnaseqContainer.removeAllContainerFilters();
                    Item lastItem = rnaseqContainer.getItem(rnaseqContainer.lastItemId());
                    System.out.println("Item is " + lastItem);
                    //   String annotated_disease_category = lastItem.getItemProperty("disease_category").getValue().toString();
                    String isDisease = "1";
                    if (!(lastItem.getItemProperty("isDisease").getValue() == null)) {
                        isDisease = lastItem.getItemProperty("isDisease").getValue().toString();
                        // System.out.println("disease is not null" +  isDisease);
                        if (isDisease.equals("1")) {
                            checkboxDiseaseYes.setValue(true);
                        } else if (isDisease.equals("0")) {
                            checkboxDiseaseNo.setValue(true);
                        }
                    } else {
                        checkboxDiseaseYes.setValue(true);
                        //  System.out.println("disease is null");
                    }

                    if (!(lastItem.getItemProperty("isCaseControl").getValue() == null)) {
                        if (lastItem.getItemProperty("isCaseControl").getValue().toString().equals("1")) {
                            checkboxCaseControlYes.setValue(true);
                        } else if (lastItem.getItemProperty("isCaseControl").getValue().toString()
                                .equals("0")) {
                            checkboxCaseControlNo.setValue(true);
                        }
                    }

                    if (!(lastItem.getItemProperty("isTimeSeries").getValue() == null)) {
                        if (lastItem.getItemProperty("isTimeSeries").getValue().toString().equals("1")) {
                            checkboxTimeSeriesYes.setValue(true);
                        } else if (lastItem.getItemProperty("isTimeSeries").getValue().toString().equals("0")) {
                            checkboxTimeSeriesNo.setValue(true);
                        }
                    }

                    if (!(lastItem.getItemProperty("isTreatment").getValue() == null)) {
                        if (lastItem.getItemProperty("isTreatment").getValue().toString().equals("1")) {
                            checkboxTreatmentYes.setValue(true);
                        } else if (lastItem.getItemProperty("isTreatment").getValue().toString().equals("0")) {
                            checkboxTreatmentNo.setValue(true);
                        }
                    }

                    if (!(lastItem.getItemProperty("isCellLine").getValue() == null)) {
                        if (lastItem.getItemProperty("isCellLine").getValue().toString().equals("1")) {
                            checkboxSampleTypeCellLine.setValue(true);
                        } else if (lastItem.getItemProperty("isCellLine").getValue().toString().equals("0")) {
                            checkboxSampleTypeCellLine.setValue(false);
                        }
                    }
                    if (!(lastItem.getItemProperty("isPrimaryCells").getValue() == null)) {
                        if (lastItem.getItemProperty("isPrimaryCells").getValue().toString().equals("1")) {
                            checkboxSampleTypePrimaryCells.setValue(true);
                        } else if (lastItem.getItemProperty("isPrimaryCells").getValue().toString()
                                .equals("0")) {
                            checkboxSampleTypePrimaryCells.setValue(false);
                        }
                    }

                    if (!(lastItem.getItemProperty("isTissue").getValue() == null)) {
                        if (lastItem.getItemProperty("isTissue").getValue().toString().equals("1")) {
                            checkboxSampleTypeTissue.setValue(true);
                        } else if (lastItem.getItemProperty("isTissue").getValue().toString().equals("0")) {
                            checkboxSampleTypeTissue.setValue(false);
                        }
                    }
                    if (!(lastItem.getItemProperty("isWholeBlood").getValue() == null)) {
                        if (lastItem.getItemProperty("isWholeBlood").getValue().toString().equals("1")) {
                            checkboxSampleTypeWholeBlood.setValue(true);
                        } else if (lastItem.getItemProperty("isWholeBlood").getValue().toString().equals("0")) {
                            checkboxSampleTypeWholeBlood.setValue(false);
                        }
                    }

                    if (!(lastItem.getItemProperty("isPlasma").getValue() == null)) {
                        if (lastItem.getItemProperty("isPlasma").getValue().toString().equals("1")) {
                            checkboxSampleTypePlasma.setValue(true);
                        } else if (lastItem.getItemProperty("isPlasma").getValue().toString().equals("0")) {
                            checkboxSampleTypePlasma.setValue(false);
                        }
                    }

                    if (!(lastItem.getItemProperty("sequencing_platform").getValue() == null)) {
                        String sequencing_platform = lastItem.getItemProperty("sequencing_platform").getValue()
                                .toString();
                        String[] annotated_platforms = sequencing_platform.split("\\;");
                        for (Iterator i = platformsListSelect.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();
                            if (annotated_platforms.length > 0) {
                                for (String pf : annotated_platforms) {
                                    if (pf.equalsIgnoreCase(temp)) {
                                        platformsListSelect.select(iid);
                                    }
                                }
                            }

                        }
                    }

                    if (!(lastItem.getItemProperty("replicate_type").getValue() == null)) {
                        String replicate_type = lastItem.getItemProperty("replicate_type").getValue()
                                .toString();
                        for (Iterator i = replicatTypesListComboBox.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();
                            if (replicate_type.equalsIgnoreCase(temp)) {
                                replicatTypesListComboBox.select(iid);
                            }
                        }

                    }

                    if (!(lastItem.getItemProperty("annotation_status").getValue() == null)) {
                        if (lastItem.getItemProperty("annotation_status").getValue().toString()
                                .equals("ongoing")) {
                            checkboxAnnotaionOngoing.setValue(true);
                        } else if (lastItem.getItemProperty("annotation_status").getValue().toString()
                                .equals("completed")) {
                            checkboxAnnotaionCompleted.setValue(true);
                        }
                    }

                    String annotated_disease_category = lastItem.getItemProperty("disease_category").getValue()
                            .toString();
                    String[] annotated_disease_categories = annotated_disease_category.split("\\;");

                    String main_disease = "";
                    for (Iterator i = complexDisease.getItemIds().iterator(); i.hasNext();) {
                        Object iid = (Object) i.next();
                        String selected_disease_category = "";
                        String temp = iid.toString();
                        if (!temp.startsWith("--")) {
                            main_disease = temp;
                        }

                        if (iid.toString().startsWith("--")) { // sub disease is selected
                            if (selected_disease_category.isEmpty()) {
                                selected_disease_category = "complex_disease|" + main_disease + "|" + temp;
                            } else {
                                selected_disease_category = selected_disease_category + "," + "complex_disease|"
                                        + main_disease + "|" + temp;
                            }

                        } else {
                            if (selected_disease_category.isEmpty()) {
                                selected_disease_category = "complex_disease|" + main_disease + "|" + "-- Any";
                            } else {
                                selected_disease_category = selected_disease_category + "," + "complex_disease|"
                                        + main_disease + "|" + "-- Any";
                            }

                        }

                        if (annotated_disease_categories.length > 0) {
                            for (String cat : annotated_disease_categories) {
                                //  System.out.println(cat + selected_disease_category);
                                if (cat.equals(selected_disease_category)) {
                                    complexDisease.select(iid);
                                }
                            }
                        }
                    }

                    main_disease = "";
                    for (Iterator i = rareDisease.getItemIds().iterator(); i.hasNext();) {
                        Object iid = (Object) i.next();
                        String selected_disease_category = "";
                        String temp = iid.toString();
                        if (!temp.startsWith("--")) {
                            main_disease = temp;
                        }

                        if (iid.toString().startsWith("--")) { // sub disease is selected
                            if (selected_disease_category.isEmpty()) {
                                selected_disease_category = "rare_disease|" + main_disease + "|" + temp;
                            } else {
                                selected_disease_category = selected_disease_category + "," + "rare_disease|"
                                        + main_disease + "|" + temp;
                            }

                        } else {
                            if (selected_disease_category.isEmpty()) {
                                selected_disease_category = "rare_disease|" + main_disease + "|" + "-- Any";
                            } else {
                                selected_disease_category = selected_disease_category + "," + "rare_disease|"
                                        + main_disease + "|" + "-- Any";
                            }

                        }

                        if (annotated_disease_categories.length > 0) {
                            for (String cat : annotated_disease_categories) {
                                //  System.out.println(cat + selected_disease_category);
                                if (cat.equals(selected_disease_category)) {
                                    rareDisease.select(iid);
                                }
                            }
                        }
                    }

                    main_disease = "";
                    for (Iterator i = otherDisease.getItemIds().iterator(); i.hasNext();) {
                        Object iid = (Object) i.next();
                        String selected_disease_category = "";
                        String temp = iid.toString();
                        if (!temp.startsWith("--")) {
                            main_disease = temp;
                        }

                        if (iid.toString().startsWith("--")) { // sub disease is selected
                            if (selected_disease_category.isEmpty()) {
                                selected_disease_category = "other_disease|" + main_disease + "|" + temp;
                            } else {
                                selected_disease_category = selected_disease_category + "," + "other_disease|"
                                        + main_disease + "|" + temp;
                            }

                        } else {
                            if (selected_disease_category.isEmpty()) {
                                selected_disease_category = "other_disease|" + main_disease + "|" + "-- Any";
                            } else {
                                selected_disease_category = selected_disease_category + "," + "other_disease|"
                                        + main_disease + "|" + "-- Any";
                            }

                        }

                        if (annotated_disease_categories.length > 0) {
                            for (String cat : annotated_disease_categories) {
                                // System.out.println(cat + selected_disease_category);
                                if (cat.equals(selected_disease_category)) {
                                    otherDisease.select(iid);
                                }
                            }
                        }
                    }

                } catch (Exception e) {
                }

            }
            //</editor-fold>

            Button submitButton = new Button("Submit");
            submit_manual_count = 0;
            Label manualSubmitStatus = new Label("");
            submitButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    if (event.getButton() == submitButton) {
                        submit_manual_count = submit_manual_count + 1;
                        int isDisease = 0;
                        if (checkboxDiseaseYes.getValue() && !checkboxDiseaseNo.getValue()) {
                            isDisease = 1;
                        }
                        String selected_disease_category = "";
                        String main_disease = "";
                        for (Iterator i = complexDisease.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();
                            if (!temp.startsWith("--")) {
                                main_disease = temp;
                            }
                            if (complexDisease.isSelected(iid)) {
                                //  System.out.println("Selected" + temp);

                                if (iid.toString().startsWith("--")) { // sub disease is selected
                                    if (selected_disease_category.isEmpty()) {
                                        selected_disease_category = "complex_disease|" + main_disease + "|"
                                                + temp;
                                    } else {
                                        selected_disease_category = selected_disease_category + ";"
                                                + "complex_disease|" + main_disease + "|" + temp;
                                    }

                                } else { //main disease is selected
                                    //     selected_disease_main = main_disease;
                                    if (selected_disease_category.isEmpty()) {
                                        selected_disease_category = "complex_disease|" + main_disease + "|"
                                                + "Any";
                                    } else {
                                        selected_disease_category = selected_disease_category + ";"
                                                + "complex_disease|" + main_disease + "|" + "Any";
                                    }

                                }
                            }
                        }
                        main_disease = "";
                        for (Iterator i = rareDisease.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();
                            if (!temp.startsWith("--")) {
                                main_disease = temp;
                            }
                            if (rareDisease.isSelected(iid)) {
                                //  System.out.println("Selected" + temp);

                                if (iid.toString().startsWith("--")) { // sub disease is selected
                                    if (selected_disease_category.isEmpty()) {
                                        selected_disease_category = "rare_disease|" + main_disease + "|" + temp;
                                    } else {
                                        selected_disease_category = selected_disease_category + ";"
                                                + "rare_disease|" + main_disease + "|" + temp;
                                    }

                                } else { //main disease is selected
                                    //     selected_disease_main = main_disease;
                                    if (selected_disease_category.isEmpty()) {
                                        selected_disease_category = "rare_disease|" + main_disease + "|"
                                                + "Any";
                                    } else {
                                        selected_disease_category = selected_disease_category + ";"
                                                + "rare_disease|" + main_disease + "|" + "Any";
                                    }

                                }
                            }
                        }
                        main_disease = "";
                        for (Iterator i = otherDisease.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();
                            if (!temp.startsWith("--")) {
                                main_disease = temp;
                            }
                            if (otherDisease.isSelected(iid)) {
                                //  System.out.println("Selected" + temp);

                                if (iid.toString().startsWith("--")) { // sub disease is selected
                                    if (selected_disease_category.isEmpty()) {
                                        selected_disease_category = "other_disease|" + main_disease + "|"
                                                + temp;
                                    } else {
                                        selected_disease_category = selected_disease_category + ";"
                                                + "other_disease|" + main_disease + "|" + temp;
                                    }

                                } else {
                                    if (selected_disease_category.isEmpty()) {
                                        selected_disease_category = "other_disease|" + main_disease + "|"
                                                + "Any";
                                    } else {
                                        selected_disease_category = selected_disease_category + ";"
                                                + "other_disease|" + main_disease + "|" + "Any";
                                    }

                                }
                            }
                        }

                        int isCaseControl = 0;
                        if (checkboxCaseControlYes.getValue() && !checkboxCaseControlNo.getValue()) {
                            isCaseControl = 1;
                        }
                        int isTimeSeries = 0;
                        if (checkboxTimeSeriesYes.getValue() && !checkboxTimeSeriesNo.getValue()) {
                            isTimeSeries = 1;
                        }
                        int isTreatment = 0;
                        if (checkboxTreatmentYes.getValue() && !checkboxTreatmentNo.getValue()) {
                            isTreatment = 1;
                        }
                        int isTissue = 0;
                        if (checkboxSampleTypeTissue.getValue()) {
                            isTissue = 1;
                        }
                        int isCellLine = 0;
                        if (checkboxSampleTypeCellLine.getValue()) {
                            isCellLine = 1;
                        }
                        int isPrimaryCells = 0;
                        if (checkboxSampleTypePrimaryCells.getValue()) {
                            isPrimaryCells = 1;
                        }
                        int isWholeBlood = 0;
                        if (checkboxSampleTypeWholeBlood.getValue()) {
                            isWholeBlood = 1;
                        }
                        int isPlasma = 0;
                        if (checkboxSampleTypePlasma.getValue()) {
                            isPlasma = 1;
                        }

                        String selected_sequencing_platforms = "";
                        for (Iterator i = platformsListSelect.getItemIds().iterator(); i.hasNext();) {
                            Object iid = (Object) i.next();
                            String temp = iid.toString();

                            if (platformsListSelect.isSelected(iid)) {
                                if (selected_sequencing_platforms.isEmpty()) {
                                    selected_sequencing_platforms = temp;
                                } else {
                                    selected_sequencing_platforms = selected_sequencing_platforms + ";" + temp;
                                }

                            }
                        }

                        String annotation_status = "ongoing";
                        if (checkboxAnnotaionCompleted.getValue() && !checkboxAnnotaionOngoing.getValue()) {
                            annotation_status = "completed";
                        }

                        String custom_annotation_value = "";
                        for (int j = 1; j <= custom_annotation_counter; j++) {
                            if (findById(rightTopAnnotationForm, "customAnnoName" + j) instanceof TextField) {
                                TextField tempTFname = (TextField) findById(rightTopAnnotationForm,
                                        "customAnnoName" + j);
                                custom_annotation_value = custom_annotation_value + tempTFname.getValue()
                                        + ":::";
                                //  System.out.println(j + "custom name: " + tempTFname.getValue());
                            }
                            if (findById(rightTopAnnotationForm, "customAnnoValue" + j) instanceof TextField) {
                                TextField tempTFvalue = (TextField) findById(rightTopAnnotationForm,
                                        "customAnnoValue" + j);
                                custom_annotation_value = custom_annotation_value + tempTFvalue.getValue()
                                        + "###";
                                //  System.out.println(j + "custom value: " + tempTFvalue.getValue());
                            }
                        }
                        String annotator = "Anonymous";
                        boolean isLoggedIn = getSession().getAttribute("user") != null;
                        if (isLoggedIn) {
                            annotator = String.valueOf(getSession().getAttribute("user"));
                            //  System.out.println("annotator is " + annotator);
                        }
                        Boolean isInserted = true;
                        try {
                            // Insert new user details in the database
                            SQLContainer insertContainer = createMySQLContainer("manual_annotation", "dummy");
                            Object id = insertContainer.addItem();
                            insertContainer.getContainerProperty(id, "studyId").setValue(selectedStudy);
                            insertContainer.getContainerProperty(id, "isDisease").setValue(isDisease);
                            insertContainer.getContainerProperty(id, "isTimeSeries").setValue(isTimeSeries);
                            insertContainer.getContainerProperty(id, "isTreatment").setValue(isTreatment);
                            insertContainer.getContainerProperty(id, "isCellLine").setValue(isCellLine);
                            insertContainer.getContainerProperty(id, "isPrimaryCells").setValue(isPrimaryCells);
                            insertContainer.getContainerProperty(id, "isCaseControl").setValue(isCaseControl);
                            insertContainer.getContainerProperty(id, "isTissue").setValue(isTissue);
                            insertContainer.getContainerProperty(id, "disease_category")
                                    .setValue(selected_disease_category);
                            insertContainer.getContainerProperty(id, "sequencing_platform")
                                    .setValue(selected_sequencing_platforms);
                            insertContainer.getContainerProperty(id, "replicate_type")
                                    .setValue(replicatTypesListComboBox.getValue());
                            insertContainer.getContainerProperty(id, "isWholeBlood").setValue(isWholeBlood);
                            insertContainer.getContainerProperty(id, "isPlasma").setValue(isPlasma);
                            insertContainer.getContainerProperty(id, "custom_annotation")
                                    .setValue(custom_annotation_value);
                            insertContainer.getContainerProperty(id, "annotation_status")
                                    .setValue(annotation_status);
                            insertContainer.getContainerProperty(id, "annotator").setValue(annotator);
                            insertContainer.commit();
                            manualSubmitStatus.setCaption("Submitted Manual Annotation Successfully");
                            SQLContainer dummyStudyContainer = null;
                            if (annotation_status.equalsIgnoreCase("ongoing")) {
                                dummyStudyContainer = createMySQLContainer("study_summary_ongoing",
                                        selectedStudy);
                            } else if (annotation_status.equalsIgnoreCase("completed")) {
                                dummyStudyContainer = createMySQLContainer("study_summary_completed",
                                        selectedStudy);
                            }

                            //  Object studyid = insertStudyContainer.getItem(new RowId(new Object[]{selectedStudy}));
                            //  System.out.println("selected study is " + selectedStudy);
                            //   System.out.println("selected study id is  " + studyid.toString());
                            //  insertStudyContainer.getContainerProperty(studyid, "annotation_status").setValue(annotation_status);
                            //   insertStudyContainer.commit();
                            if (submit_manual_count > 1) {
                                manualSubmitStatus.setCaption("Submitted Manual Annotation Successfully "
                                        + submit_manual_count + " times");
                            }
                        } catch (Exception e) {
                            isInserted = false;
                            manualSubmitStatus.setCaption(
                                    "Problem occured during submission of Manual Annotation to the database");
                            System.out.println("Problem in inserting manual annotation into the database");
                            //  e.printStackTrace();
                        }
                    }
                }
            });

            rightTopAnnotationForm.addComponent(diseaseLayout);
            rightTopAnnotationForm.addComponent(studyTypesPanel);
            rightTopAnnotationForm.addComponent(diseaseCategoryPanel);
            rightTopAnnotationForm.addComponent(platformLayout);
            rightTopAnnotationForm.addComponent(sampleTypesPanel);
            rightTopAnnotationForm.addComponent(replicatTypesLayout);
            rightTopAnnotationForm.addComponent(addCustomAnnoButton);
            rightTopAnnotationForm.addComponent(annotationStatusPanel);
            rightTopAnnotationForm.addComponent(submitButton);
            rightTopAnnotationForm.addComponent(manualSubmitStatus);
            //</editor-fold>
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="fill tree in right bottom">
            Iterator iterator = biosampleSet.iterator();

            // check values
            int treeBiosampleCount = 0;
            while (iterator.hasNext()) {
                treeBiosampleCount = treeBiosampleCount + 1;
                //  System.out.println("Value: "+ iterator.next() + " ");
                //    if(treeBiosampleCount < 500){
                String bsample = iterator.next().toString();
                String[] biosample_parts = bsample.split("\\|");
                String biosample_acc = biosample_parts[0];
                tree.addItem(biosample_acc);
                tree.setParent(biosample_acc, selectedStudy);
                tree.setItemCaption(biosample_acc, "BioSample: " + biosample_acc);
                //    }
            }
            Set expMap_entrset = expMap.entrySet();
            Iterator it = expMap_entrset.iterator();
            while (it.hasNext()) {

                Map.Entry me = (Map.Entry) it.next();
                String[] expParts = expDetailMap.get(me.getKey());
                String expTitle = "";
                if (expParts.length > 3) {
                    expTitle = expParts[3];
                }
                tree.addItem(me.getKey());
                tree.setParent(me.getKey(), me.getValue());
                tree.setItemCaption(me.getKey(), "Experiment: " + me.getKey() + ": " + expTitle);
            }

            Set runMap_entrset = runMap.entrySet();
            Iterator runit = runMap_entrset.iterator();
            while (runit.hasNext()) {
                Map.Entry runEntry = (Map.Entry) runit.next();
                tree.addItem(runEntry.getKey());
                tree.setParent(runEntry.getKey(), runEntry.getValue());
                tree.setItemCaption(runEntry.getKey(), "Run: " + runEntry.getKey());
            }

            tree.expandItemsRecursively(selectedStudy);
            //</editor-fold>
        }
    });
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Events associated with the Tree (study/Biosample/Experiment/Runs">
    tree.setSelectable(true);
    tree.setImmediate(true);
    tree.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            Object id = event.getProperty().getValue();
            if (id != null) {
                String selectedTreeId = id.toString();
                String selectedTreeItem = tree.getItemCaption(id).toString();
                // System.out.println("Tree event is fired: " + selectedTreeItem);
                if (selectedTreeItem.startsWith("BioSample")) {

                    myform.removeAllComponents();
                    SQLContainer tempContainer = createMySQLContainer("biosample", selectedTreeId);
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String accessType = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("AccessType").getValue().toString();
                        String publicationDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("PublicationDate").getValue().toString();
                        String lastUpdate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("LastUpdate").getValue().toString();
                        String accession = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Accession").getValue().toString();
                        String title = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Title").getValue().toString();
                        String taxonomy_id = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyId").getValue().toString();
                        String taxonomy_name = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("TaxonomyName").getValue().toString();
                        String samplePackage = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Package").getValue().toString();
                        String status = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Status").getValue().toString();
                        String statusTime = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("StatusTime").getValue().toString();
                        String sampleIds = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Ids").getValue().toString();
                        String attributes = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Attributes").getValue().toString();
                        String models = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Models").getValue().toString();
                        String submissionDate = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("SubmissionDate").getValue().toString();
                        String owner = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Owner").getValue().toString();

                        String[] myfields = new String[] { accessType, publicationDate, lastUpdate, accession,
                                title, taxonomy_id, taxonomy_name, samplePackage, status, statusTime, sampleIds,
                                attributes, models, submissionDate, owner };
                        /*
                         for (String fieldName : myfields) {
                         Label tempLabl = new Label("");
                         }
                         */
                        Label labelAccessType = new Label("Access Type: " + accessType);
                        myform.addComponent(labelAccessType);
                        Label labelPublicationDate = new Label("Publication Date: " + publicationDate);
                        myform.addComponent(labelPublicationDate);
                        Label labelLastUpdate = new Label("Last Update: " + lastUpdate);
                        myform.addComponent(labelLastUpdate);
                        Label labelAccession = new Label("Accession: " + accession);
                        myform.addComponent(labelAccession);
                        Label labelTitle = new Label("<b>Title: </b>" + title, ContentMode.HTML);
                        myform.addComponent(labelTitle);
                        Label labelTaxonomyId = new Label("Taxonomy Id: " + taxonomy_id);
                        myform.addComponent(labelTaxonomyId);
                        Label labelTaxonomyName = new Label("Taxonomy Name: " + taxonomy_name);
                        myform.addComponent(labelTaxonomyName);
                        Label labelPackage = new Label("Package: " + samplePackage);
                        myform.addComponent(labelPackage);
                        Label labelStatus = new Label("Status: " + status);
                        myform.addComponent(labelStatus);
                        Label labelStatusTime = new Label("Status Time: " + statusTime);
                        myform.addComponent(labelStatusTime);
                        Label labelOwner = new Label("Owner: " + owner);
                        myform.addComponent(labelOwner);

                        String[] id_parts = sampleIds.split("\\:\\-");
                        if (id_parts.length > 1) {
                            String[] id_dbs = id_parts[0].split("\\|");
                            String[] id_values = id_parts[1].split("\\|");
                            for (int j = 0; j < id_dbs.length; j++) {
                                Label tempLabel = new Label(id_dbs[j] + ": " + id_values[j]);
                                myform.addComponent(tempLabel);

                            }
                        }

                        String[] attribute_parts = attributes.split("\\:\\-");
                        if (attribute_parts.length > 1) {
                            String[] attribute_names = attribute_parts[0].split("\\|");
                            String[] attribute_values = attribute_parts[1].split("\\|");
                            for (int j = 0; j < attribute_names.length; j++) {
                                Label tempLabel = new Label(
                                        "<b>" + attribute_names[j] + ": </b>" + attribute_values[j],
                                        ContentMode.HTML);
                                myform.addComponent(tempLabel);
                                //  System.out.println("inside attributes ");

                            }
                        }

                        //   TextField field = new TextField(lastDpdate);
                        // myform.addComponent(field);
                        //field.setWidth("100%");
                    }
                }
                if (selectedTreeItem.startsWith("Experiment")) {
                    SQLContainer tempContainer = createMySQLContainer("sra_rnaseq_exp", selectedTreeId);
                    myform.removeAllComponents();
                    Map expMap = new HashMap();
                    Map<String, String[]> expDetailMap = new HashMap<>();
                    Map<String, String[]> libraryDetailMap = new HashMap<>();
                    Map<String, String[]> platformMap = new HashMap<>();
                    Map runMap = new HashMap();
                    HashSet<String> biosampleSet = new HashSet<>();
                    for (int i = 0; i < tempContainer.getItemIds().size(); i++) {
                        String docid = tempContainer.getIdByIndex(i).toString();
                        String biosample = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Biosample_Acc_Id_SampleId").getValue().toString();
                        biosampleSet.add(biosample);
                        String[] b_parts = biosample.split("\\|");

                        String exp = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Experiment_Acc_Ver_Status_Name").getValue().toString();
                        String[] exp_parts = exp.split("\\|");
                        String exp_acc = exp_parts[0];
                        expMap.put(exp_acc, b_parts[0]);
                        expDetailMap.put(exp_acc, exp_parts);

                        String library_string = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Library_Name_Strategy_Source_Selection_Layout").getValue()
                                .toString();
                        String[] library_parts = library_string.split("\\|");
                        String library_name = "";
                        String library_strategy = "";
                        String library_source = "";
                        String library_selection = "";
                        String library_layout = "";
                        if (library_parts.length > 0) {
                            library_name = library_parts[0];
                        }
                        if (library_parts.length > 1) {
                            library_strategy = "<b> <i> Strategy </i> </b>" + library_parts[1];
                        }
                        if (library_parts.length > 2) {
                            library_source = "<b> <i> Source </i> </b>" + library_parts[2];
                        }
                        if (library_parts.length > 3) {
                            library_selection = "<b> <i> Selection </i> </b>" + library_parts[3];
                        }
                        if (library_parts.length > 4) {
                            String tempLayout = library_parts[4];
                            tempLayout = tempLayout.replaceAll("<", "");
                            tempLayout = tempLayout.replaceAll("/>", "");
                            library_layout = "<b> <i> Layout </i> </b>" + tempLayout;
                        }
                        String[] tempStringArray = new String[] { library_strategy, library_source,
                                library_selection, library_layout };
                        if (library_name.length() > 1) {
                            libraryDetailMap.put(library_name, tempStringArray);
                        }

                        String sra_plaforms = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Platform_InstrumentModel").getValue().toString();
                        String[] sra_plaforms_parts = sra_plaforms.split("\\|");
                        platformMap.put(exp_acc, sra_plaforms_parts);

                        String run = tempContainer.getItem(tempContainer.getIdByIndex(i))
                                .getItemProperty("Runs").getValue().toString();
                        String[] run_parts = run.split("\\|");
                        if (run_parts.length > 0) {
                            for (int j = 0; j < run_parts.length; j++) {
                                String temprun = run_parts[j];
                                String[] temprun_parts = temprun.split("\\,");
                                runMap.put(temprun_parts[0], exp_acc);
                            }
                        }
                    }
                    //   Label labelExperimentAcc = new Label("<b>Experiment Accession: </b>" + selectedTreeId, ContentMode.HTML);
                    // myform.addComponent(labelExperimentAcc);
                    String libraryDetails = "<b>Experiment Accession: </b>" + selectedTreeId + "<br><br>";
                    for (Map.Entry<String, String[]> entry : libraryDetailMap.entrySet()) {
                        libraryDetails = libraryDetails + "<b>Library Details: </b>" + entry.getKey()
                                + "<br><br>";
                        String[] temp_library_details = entry.getValue();
                        for (String dt : temp_library_details) {
                            libraryDetails = libraryDetails + dt + "<br><br>";
                        }
                    }
                    Label labelLibraryDetails = new Label(libraryDetails, ContentMode.HTML);
                    myform.addComponent(labelLibraryDetails);
                    //   myform.setComponentAlignment(labelExperimentAcc, Alignment.TOP_LEFT);
                    myform.setComponentAlignment(labelLibraryDetails, Alignment.TOP_LEFT);

                }
                if (selectedTreeItem.startsWith("Run")) {
                    myform.removeAllComponents();
                    SQLContainer tempContainer = createMySQLContainer("sra_rnaseq_run", selectedTreeId);
                    if (tempContainer.size() > 0) {
                        Item tempItem = tempContainer.getItem(tempContainer.firstItemId());
                        String runs = tempItem.getItemProperty("Runs").getValue().toString();
                        String[] runs_parts = runs.split("\\|");
                        for (String run : runs_parts) {
                            if (run.contains(selectedTreeId)) {
                                String[] run_details = run.split("\\,");
                                String stringRun = "";
                                if (run_details.length > 0) {
                                    stringRun = stringRun + "<b>Run Accession: </b>" + run_details[0]
                                            + "<br><br>";
                                }
                                if (run_details.length > 1) {
                                    stringRun = stringRun + "<b>Number of spots or reads: </b>" + run_details[1]
                                            + "<br><br>";
                                }
                                if (run_details.length > 1) {
                                    stringRun = stringRun + "<b>Number of bases: </b>" + run_details[2]
                                            + "<br><br>";
                                }
                                Label labelRunDetails = new Label(stringRun, ContentMode.HTML);
                                myform.addComponent(labelRunDetails);
                            }

                        }
                    }
                }
            } else {
                System.out.println("id is null");
            }
        }

    });
    //</editor-fold>

}