Merge pull request #3860 from dgrove727/3906_MoveAddViewCommentMenuItem

Moved context menu creation to new provider.
This commit is contained in:
Richard Cordovano 2018-06-18 14:48:23 -04:00 committed by GitHub
commit eda7163fd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 20 deletions

View File

@ -0,0 +1,56 @@
/*
* Central Repository
*
* Copyright 2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.centralrepository;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.Action;
import org.openide.util.Utilities;
import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamArtifactUtil;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider;
import org.sleuthkit.datamodel.AbstractFile;
/**
* This creates a single context menu item for adding or editing a Central
* Repository comment.
*/
@ServiceProvider(service = ContextMenuActionsProvider.class)
public class CentralRepoContextMenuActionsProvider implements ContextMenuActionsProvider {
@Override
public List<Action> getActions() {
ArrayList<Action> actions = new ArrayList<>();
Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
if (selectedFiles.size() != 1) {
return actions;
}
for (AbstractFile file : selectedFiles) {
if (EamDbUtil.useCentralRepo() && EamArtifactUtil.isSupportedAbstractFileType(file) && file.isFile()) {
actions.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file));
}
}
return actions;
}
}

View File

@ -258,21 +258,6 @@ public abstract class AbstractAbstractFileNode<T extends AbstractFile> extends A
map.put(EXTENSION.toString(), content.getNameExtension()); map.put(EXTENSION.toString(), content.getNameExtension());
} }
@Override
public Action[] getActions(boolean context) {
List<Action> actionsList = new ArrayList<>();
actionsList.addAll(Arrays.asList(super.getActions(true)));
// Create the "Add/Edit Central Repository Comment" menu item if the enabled.
AbstractFile file = content;
if (EamDbUtil.useCentralRepo() && EamArtifactUtil.isSupportedAbstractFileType(file) && file.isFile()) {
actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file));
}
return actionsList.toArray(new Action[actionsList.size()]);
}
/** /**
* Used by subclasses of AbstractAbstractFileNode to add the tags property * Used by subclasses of AbstractAbstractFileNode to add the tags property
* to their sheets. * to their sheets.

View File

@ -221,11 +221,6 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
actionsList.addAll(Arrays.asList(super.getActions(context))); actionsList.addAll(Arrays.asList(super.getActions(context)));
AbstractFile file = getLookup().lookup(AbstractFile.class); AbstractFile file = getLookup().lookup(AbstractFile.class);
// Create the "Add/Edit Central Repository Comment" menu item if the enabled.
if (file != null && file.isFile() && EamDbUtil.useCentralRepo()) {
actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file));
}
//if this artifact has a time stamp add the action to view it in the timeline //if this artifact has a time stamp add the action to view it in the timeline
try { try {
if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) { if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {