Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DefaultCellModel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.function.Function;
25 import java.util.function.Supplier;
26 
30 public class DefaultCellModel<T> implements GuiCellModel, ExcelCellModel {
31 
32  private final T data;
33  private final String text;
34  private String tooltip;
36  private List<MenuItem> popupMenu;
37  private Supplier<List<MenuItem>> menuItemSupplier;
38  private final String excelFormatString;
39 
45  public DefaultCellModel(T data) {
46  this(data, null, null);
47  }
48 
56  public DefaultCellModel(T data, Function<T, String> stringConverter) {
57  this(data, stringConverter, null);
58  }
59 
72  public DefaultCellModel(T data, Function<T, String> stringConverter, String excelFormatString) {
73  this.data = data;
74  this.excelFormatString = excelFormatString;
75 
76  if (stringConverter == null) {
77  text = this.data == null ? "" : this.data.toString();
78  } else {
79  text = stringConverter.apply(this.data);
80  }
81  this.tooltip = text;
82  }
83 
84  @Override
85  public T getData() {
86  return this.data;
87  }
88 
89  @Override
90  public String getExcelFormatString() {
91  return this.excelFormatString;
92  }
93 
94  @Override
95  public String getText() {
96  return text;
97  }
98 
99  @Override
100  public String getTooltip() {
101  return tooltip;
102  }
103 
111  public DefaultCellModel<T> setTooltip(String tooltip) {
112  this.tooltip = tooltip;
113  return this;
114  }
115 
116  @Override
118  return horizontalAlignment;
119  }
120 
129  this.horizontalAlignment = alignment;
130  return this;
131  }
132 
133  @Override
134  public List<MenuItem> getPopupMenu() {
135  if (popupMenu != null) {
136  return Collections.unmodifiableList(popupMenu);
137  }
138  if (menuItemSupplier != null) {
139  return this.menuItemSupplier.get();
140  }
141  return null;
142  }
143 
151  public DefaultCellModel<T> setPopupMenuRetriever(Supplier<List<MenuItem>> menuItemSupplier) {
152  this.menuItemSupplier = menuItemSupplier;
153  return this;
154  }
155 
163  public DefaultCellModel<T> setPopupMenu(List<MenuItem> popupMenu) {
164  this.popupMenu = popupMenu == null ? null : new ArrayList<>(popupMenu);
165  return this;
166  }
167 
168  @Override
169  public String toString() {
170  return getText();
171  }
172 }
DefaultCellModel< T > setPopupMenuRetriever(Supplier< List< MenuItem >> menuItemSupplier)
DefaultCellModel(T data, Function< T, String > stringConverter)
DefaultCellModel< T > setHorizontalAlignment(CellModel.HorizontalAlign alignment)
DefaultCellModel(T data, Function< T, String > stringConverter, String excelFormatString)
DefaultCellModel< T > setPopupMenu(List< MenuItem > popupMenu)

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.