Search in sources :

Example 1 with TableColumnStat

use of org.cytoscape.browser.internal.util.TableColumnStat in project cytoscape-impl by cytoscape.

the class AbstractTableBrowser method handleEvent.

@Override
public void handleEvent(SessionAboutToBeSavedEvent e) {
    Map<CyTable, BrowserTable> browserTables = getAllBrowserTablesMap();
    List<TableColumnStat> tableColumnStatList = new ArrayList<>();
    for (CyTable table : browserTables.keySet()) {
        TableColumnStat tcs = new TableColumnStat(table.getTitle());
        BrowserTable browserTable = browserTables.get(table);
        BrowserTableModel model = (BrowserTableModel) browserTable.getModel();
        BrowserTableColumnModel colM = (BrowserTableColumnModel) browserTable.getColumnModel();
        List<String> visAttrs = browserTable.getVisibleAttributeNames();
        colM.setAllColumnsVisible();
        Collection<String> attrs = model.getAllAttributeNames();
        for (String name : attrs) {
            int viewIndex = browserTable.convertColumnIndexToView(model.mapColumnNameToColumnIndex(name));
            tcs.addColumnStat(name, viewIndex, visAttrs.contains(name));
        }
        browserTable.setVisibleAttributeNames(visAttrs);
        tableColumnStatList.add(tcs);
    }
    TableColumnStatFileIO.write(tableColumnStatList, e, appFileName);
}
Also used : CyTable(org.cytoscape.model.CyTable) TableColumnStat(org.cytoscape.browser.internal.util.TableColumnStat) ArrayList(java.util.ArrayList)

Example 2 with TableColumnStat

use of org.cytoscape.browser.internal.util.TableColumnStat in project cytoscape-impl by cytoscape.

the class TableColumnStatFileIO method write.

public static void write(List<TableColumnStat> tableColStats, SessionAboutToBeSavedEvent e, String className) {
    try {
        // Create an empty file on system temp directory
        File tmpFile = new File(System.getProperty("java.io.tmpdir"), className);
        tmpFile.deleteOnExit();
        BufferedWriter writer = new BufferedWriter(new FileWriter(tmpFile));
        for (TableColumnStat tcs : tableColStats) {
            writer.write(tcs.toString());
        }
        writer.close();
        // Add it to the apps list
        List<File> fileList = new ArrayList<File>();
        boolean flag = false;
        if (e.getAppFileListMap().containsKey(APP_NAME)) {
            fileList = e.getAppFileListMap().get(APP_NAME);
            flag = true;
        }
        fileList.add(tmpFile);
        if (!flag)
            e.addAppFiles(APP_NAME, fileList);
    } catch (Exception ex) {
        logger.error("Error adding table browser status files to be saved in the session.", ex);
    }
}
Also used : FileWriter(java.io.FileWriter) TableColumnStat(org.cytoscape.browser.internal.util.TableColumnStat) ArrayList(java.util.ArrayList) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 3 with TableColumnStat

use of org.cytoscape.browser.internal.util.TableColumnStat in project cytoscape-impl by cytoscape.

the class AbstractTableBrowser method handleEvent.

@Override
public void handleEvent(SessionLoadedEvent e) {
    Map<String, TableColumnStat> tscMap = TableColumnStatFileIO.read(e, appFileName);
    if (tscMap == null || tscMap.isEmpty())
        return;
    Map<CyTable, BrowserTable> browserTablesMap = getAllBrowserTablesMap();
    for (CyTable table : browserTablesMap.keySet()) {
        if (!tscMap.containsKey(table.getTitle()))
            continue;
        final TableColumnStat tcs = tscMap.get(table.getTitle());
        final BrowserTable browserTable = getBrowserTable(table);
        BrowserTableModel model = (BrowserTableModel) browserTable.getModel();
        final BrowserTableColumnModel colM = (BrowserTableColumnModel) browserTable.getColumnModel();
        colM.setAllColumnsVisible();
        final List<String> orderedCols = tcs.getOrderedCol();
        for (int i = 0; i < orderedCols.size(); i++) {
            final String colName = orderedCols.get(i);
            colM.moveColumn(browserTable.convertColumnIndexToView(model.mapColumnNameToColumnIndex(colName)), i);
        }
        browserTable.setVisibleAttributeNames(tcs.getVisibleCols());
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) TableColumnStat(org.cytoscape.browser.internal.util.TableColumnStat)

Example 4 with TableColumnStat

use of org.cytoscape.browser.internal.util.TableColumnStat in project cytoscape-impl by cytoscape.

the class TableColumnStatFileIO method read.

public static Map<String, TableColumnStat> read(SessionLoadedEvent e, String className) {
    Map<String, TableColumnStat> tableColStats = new HashMap<String, TableColumnStat>();
    CySession sess = e.getLoadedSession();
    if (sess == null)
        return null;
    Map<String, List<File>> filesMap = sess.getAppFileListMap();
    if (!filesMap.containsKey(APP_NAME))
        return null;
    List<File> files = filesMap.get(APP_NAME);
    if (files == null)
        return null;
    for (File f : files) {
        if (f.getName().endsWith(className)) {
            try {
                InputStream is = new FileInputStream(f);
                final InputStreamReader reader = new InputStreamReader(is);
                final BufferedReader br = new BufferedReader(reader);
                String line = null;
                while ((line = br.readLine()) != null) {
                    String[] split = line.split(",");
                    if (split.length != 4)
                        continue;
                    String tableTitle = split[0];
                    int colIndex = Integer.valueOf(split[1]);
                    String colName = split[2];
                    boolean visible = Boolean.valueOf(split[3]);
                    if (!tableColStats.containsKey(tableTitle))
                        tableColStats.put(tableTitle, new TableColumnStat(tableTitle));
                    TableColumnStat tcs = tableColStats.get(tableTitle);
                    tcs.addColumnStat(colName, colIndex, visible);
                }
                br.close();
            } catch (Exception ex) {
                logger.error("Error reading table browser status files from session.", ex);
            }
            break;
        }
    }
    return tableColStats;
}
Also used : CySession(org.cytoscape.session.CySession) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) TableColumnStat(org.cytoscape.browser.internal.util.TableColumnStat) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

TableColumnStat (org.cytoscape.browser.internal.util.TableColumnStat)4 ArrayList (java.util.ArrayList)3 File (java.io.File)2 CyTable (org.cytoscape.model.CyTable)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CySession (org.cytoscape.session.CySession)1