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 @SuppressWarnings(
"PMD.SingularField")
53 class SQLiteTableView extends JPanel implements ExplorerManager.Provider {
55 private final org.openide.explorer.view.OutlineView outlineView;
56 private final Outline outline;
57 private final ExplorerManager explorerManager;
66 outlineView =
new org.openide.explorer.view.OutlineView();
67 add(outlineView, BorderLayout.CENTER);
68 outlineView.setPropertyColumns();
69 outlineView.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
70 outlineView.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
72 outline = outlineView.getOutline();
74 outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
75 outline.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
76 outline.setRowSelectionAllowed(
false);
77 outline.setRootVisible(
false);
79 outline.setCellSelectionEnabled(
true);
80 explorerManager =
new ExplorerManager();
88 @NbBundle.Messages({
"SQLiteTableView.DisplayAs.text=Display as",
89 "SQLiteTableView.DisplayAsMenuItem.Date=Date",
90 "SQLiteTableView.DisplayAsMenuItem.RawData=Raw Data"
92 void setupTable(List<Map<String, Object>> tableRows) {
95 if (Objects.isNull(tableRows) || tableRows.isEmpty()) {
96 outlineView.setPropertyColumns();
100 Map<String, Object> row = tableRows.get(0);
101 String[] propStrings =
new String[row.size() * 2];
103 for (Map.Entry<String, Object> col : row.entrySet()) {
104 String colName = col.getKey();
105 propStrings[2 * i] = colName;
106 propStrings[2 * i + 1] = colName;
110 outlineView.setPropertyColumns(propStrings);
114 TableColumnModel columnModel = outline.getColumnModel();
115 ETableColumn column = (ETableColumn) columnModel.getColumn(0);
116 ((ETableColumnModel) columnModel).setColumnHidden(column,
true);
120 new SwingWorker<Boolean, Void>() {
122 protected Boolean doInBackground() throws Exception {
124 List<Action> nodeActions =
new ArrayList<>();
126 nodeActions.add(
new ParseColAction(Bundle.SQLiteTableView_DisplayAs_text(), outline) );
128 explorerManager.setRootContext(
new AbstractNode(Children.create(
new SQLiteTableRowFactory(tableRows, nodeActions),
true)));
133 protected void done() {
142 private void setColumnWidths() {
147 final int rows = Math.min(20, outline.getRowCount());
148 for (
int col = 1; col < outline.getColumnCount(); col++) {
149 int columnWidthLimit = 500;
150 int columnWidth = 50;
152 for (
int row = 0; row < rows; row++) {
153 TableCellRenderer renderer = outline.getCellRenderer(row, col);
154 Component comp = outline.prepareRenderer(renderer, row, col);
156 columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
159 columnWidth += 2 * margin + padding;
160 columnWidth = Math.min(columnWidth, columnWidthLimit);
161 outline.getColumnModel().getColumn(col).setPreferredWidth(columnWidth);
171 @SuppressWarnings(
"unchecked")
173 private
void initComponents() {
175 setLayout(
new java.awt.BorderLayout());
179 public ExplorerManager getExplorerManager() {
180 return explorerManager;
197 this.outline = outline;
198 this.displayName = displayName;
221 final void initMenu() {
223 int selCol = outline.getSelectedColumn();
228 TableColumnModel columnModel = outline.getColumnModel();
229 TableColumn column = columnModel.getColumn(selCol);
231 JMenuItem parseAsEpochItem =
new JMenuItem(Bundle.SQLiteTableView_DisplayAsMenuItem_Date());
232 parseAsEpochItem.addActionListener((ActionEvent evt) -> {
233 column.setCellRenderer(
new EpochTimeCellRenderer(
true));
235 parseAsEpochItem.setEnabled(
false);
236 add(parseAsEpochItem);
238 JMenuItem parseAsOriginalItem =
new JMenuItem(Bundle.SQLiteTableView_DisplayAsMenuItem_RawData());
239 parseAsOriginalItem.addActionListener((ActionEvent evt) -> {
240 column.setCellRenderer(
new EpochTimeCellRenderer(
false));
242 parseAsOriginalItem.setEnabled(
false);
243 add(parseAsOriginalItem);
246 TableCellRenderer currRenderer = column.getCellRenderer();
247 if (currRenderer instanceof EpochTimeCellRenderer) {
248 if (((EpochTimeCellRenderer) currRenderer).isRenderingAsEpoch()) {
249 parseAsOriginalItem.setEnabled(
true);
251 parseAsEpochItem.setEnabled(
true);
255 parseAsEpochItem.setEnabled(
true);
void actionPerformed(ActionEvent e)
JMenuItem getPopupPresenter()