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);
}
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);
}
}
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());
}
}
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;
}
Aggregations