default method getting title for Node on DataContentViewer

This commit is contained in:
Greg DiCristofaro 2021-05-25 12:07:22 -04:00
parent 998c86439a
commit 8ae09432f7
3 changed files with 45 additions and 1 deletions

View File

@ -20,13 +20,13 @@ package org.sleuthkit.autopsy.contentviewers;
import java.awt.Component;
import java.awt.Cursor;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import javax.swing.SwingWorker;
import org.apache.commons.lang3.StringUtils;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.ServiceProvider;
@ -36,6 +36,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
import org.sleuthkit.datamodel.BlackboardArtifact.Category;
import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
import org.sleuthkit.datamodel.DataSource;
@ -229,9 +230,32 @@ public class Metadata extends javax.swing.JPanel implements DataContentViewer {
@Override
public String getTitle() {
return getTitle(null);
}
@Messages({
"Metadata_dataArtifactTitle=Source File Metadata"
})
@Override
public String getTitle(Node node) {
if (node != null) {
Collection<? extends BlackboardArtifact> artifacts = node.getLookup().lookupAll(BlackboardArtifact.class);
for (BlackboardArtifact art : artifacts) {
try {
if (art != null && art.getType().getCategory() == Category.DATA_ARTIFACT) {
return Bundle.Metadata_dataArtifactTitle();
}
} catch (TskCoreException ex) {
LOGGER.log(Level.SEVERE, "Unable to get artifact type for artifact with id: " + art.getArtifactID(), ex);
}
}
}
return NbBundle.getMessage(this.getClass(), "Metadata.title");
}
@Override
public String getToolTip() {
return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");

View File

@ -52,6 +52,16 @@ public interface DataContentViewer {
*/
public String getTitle();
/**
* Returns the title of this viewer to display in the tab.
*
* @param node The node to be viewed in the DataContentViewer.
* @return the title of DataContentViewer.
*/
public default String getTitle(Node node) {
return getTitle();
}
/**
* Returns a short description of this viewer to use as a tool tip for its
* tab.

View File

@ -140,6 +140,12 @@ public class DataContentPanel extends javax.swing.JPanel implements DataContent,
// Reset everything
for (int index = 0; index < jTabbedPane1.getTabCount(); index++) {
jTabbedPane1.setEnabledAt(index, false);
String tabTitle = viewers.get(index).getTitle(selectedNode);
tabTitle = tabTitle == null ? "" : tabTitle;
if (!tabTitle.equals(jTabbedPane1.getTitleAt(index))) {
jTabbedPane1.setTitleAt(index, tabTitle);
}
viewers.get(index).resetComponent();
}
@ -266,6 +272,10 @@ public class DataContentPanel extends javax.swing.JPanel implements DataContent,
int isPreferred(Node node) {
return this.wrapped.isPreferred(node);
}
String getTitle(Node node) {
return this.wrapped.getTitle(node);
}
}
/**