19 package org.sleuthkit.autopsy.contentviewers;
21 import java.awt.BorderLayout;
22 import java.awt.Component;
23 import java.awt.event.ActionEvent;
24 import java.util.ArrayList;
25 import java.util.List;
27 import java.util.Objects;
28 import javax.swing.AbstractAction;
29 import javax.swing.Action;
30 import javax.swing.JMenu;
31 import javax.swing.JMenuItem;
32 import javax.swing.JPanel;
33 import javax.swing.JTable;
34 import javax.swing.ListSelectionModel;
35 import javax.swing.ScrollPaneConstants;
36 import javax.swing.SwingWorker;
37 import javax.swing.table.TableCellRenderer;
38 import javax.swing.table.TableColumn;
39 import javax.swing.table.TableColumnModel;
40 import org.netbeans.swing.etable.ETableColumn;
41 import org.netbeans.swing.etable.ETableColumnModel;
42 import org.netbeans.swing.outline.Outline;
43 import org.openide.explorer.ExplorerManager;
44 import org.openide.nodes.AbstractNode;
45 import org.openide.nodes.Children;
46 import org.openide.util.NbBundle;
47 import org.openide.util.actions.Presenter;
52 class SQLiteTableView
extends JPanel implements ExplorerManager.Provider {
54 private final org.openide.explorer.view.OutlineView outlineView;
55 private final Outline outline;
56 private final ExplorerManager explorerManager;
65 outlineView =
new org.openide.explorer.view.OutlineView();
66 add(outlineView, BorderLayout.CENTER);
67 outlineView.setPropertyColumns();
68 outlineView.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
69 outlineView.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
71 outline = outlineView.getOutline();
73 outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
74 outline.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
75 outline.setRowSelectionAllowed(
false);
76 outline.setRootVisible(
false);
78 outline.setCellSelectionEnabled(
true);
79 explorerManager =
new ExplorerManager();
87 @NbBundle.Messages({
"SQLiteTableView.DisplayAs.text=Display as",
88 "SQLiteTableView.DisplayAsMenuItem.Date=Date",
89 "SQLiteTableView.DisplayAsMenuItem.RawData=Raw Data"
91 void setupTable(List<Map<String, Object>> tableRows) {
94 if (Objects.isNull(tableRows) || tableRows.isEmpty()) {
95 outlineView.setPropertyColumns();
99 Map<String, Object> row = tableRows.get(0);
100 String[] propStrings =
new String[row.size() * 2];
102 for (Map.Entry<String, Object> col : row.entrySet()) {
103 String colName = col.getKey();
104 propStrings[2 * i] = colName;
105 propStrings[2 * i + 1] = colName;
109 outlineView.setPropertyColumns(propStrings);
113 TableColumnModel columnModel = outline.getColumnModel();
114 ETableColumn column = (ETableColumn) columnModel.getColumn(0);
115 ((ETableColumnModel) columnModel).setColumnHidden(column,
true);
119 new SwingWorker<Boolean, Void>() {
121 protected Boolean doInBackground() throws Exception {
123 List<Action> nodeActions =
new ArrayList<>();
125 nodeActions.add(
new ParseColAction(Bundle.SQLiteTableView_DisplayAs_text(), outline) );
127 explorerManager.setRootContext(
new AbstractNode(Children.create(
new SQLiteTableRowFactory(tableRows, nodeActions),
true)));
132 protected void done() {
141 private void setColumnWidths() {
146 final int rows = Math.min(20, outline.getRowCount());
147 for (
int col = 1; col < outline.getColumnCount(); col++) {
148 int columnWidthLimit = 500;
149 int columnWidth = 50;
151 for (
int row = 0; row < rows; row++) {
152 TableCellRenderer renderer = outline.getCellRenderer(row, col);
153 Component comp = outline.prepareRenderer(renderer, row, col);
155 columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
158 columnWidth += 2 * margin + padding;
159 columnWidth = Math.min(columnWidth, columnWidthLimit);
160 outline.getColumnModel().getColumn(col).setPreferredWidth(columnWidth);
170 @SuppressWarnings(
"unchecked")
172 private
void initComponents() {
174 setLayout(
new java.awt.BorderLayout());
178 public ExplorerManager getExplorerManager() {
179 return explorerManager;
220 final void initMenu() {
222 int selCol = outline.getSelectedColumn();
227 TableColumnModel columnModel = outline.getColumnModel();
228 TableColumn column = columnModel.getColumn(selCol);
230 JMenuItem parseAsEpochItem =
new JMenuItem(Bundle.SQLiteTableView_DisplayAsMenuItem_Date());
231 parseAsEpochItem.addActionListener((ActionEvent evt) -> {
234 parseAsEpochItem.setEnabled(
false);
235 add(parseAsEpochItem);
237 JMenuItem parseAsOriginalItem =
new JMenuItem(Bundle.SQLiteTableView_DisplayAsMenuItem_RawData());
238 parseAsOriginalItem.addActionListener((ActionEvent evt) -> {
241 parseAsOriginalItem.setEnabled(
false);
242 add(parseAsOriginalItem);
245 TableCellRenderer currRenderer = column.getCellRenderer();
247 if (((EpochTimeCellRenderer) currRenderer).isRenderingAsEpoch()) {
248 parseAsOriginalItem.setEnabled(
true);
250 parseAsEpochItem.setEnabled(
true);
254 parseAsEpochItem.setEnabled(
true);
void actionPerformed(ActionEvent e)
JMenuItem getPopupPresenter()