GT-2705 - File Import - review fixes; updated transient project dialogs

to not have copy/paste actions etc
This commit is contained in:
dragonmacher 2019-03-28 18:25:09 -04:00
parent 84c16c2b27
commit f3ef6956c9
20 changed files with 201 additions and 134 deletions

View File

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +15,12 @@
*/
package ghidra.app.plugin.core.datamgr;
import java.util.ArrayList;
import java.util.List;
import javax.swing.tree.TreePath;
import docking.widgets.tree.GTreeNode;
import ghidra.app.context.ProgramActionContext;
import ghidra.app.plugin.core.datamgr.archive.ProjectArchive;
import ghidra.app.plugin.core.datamgr.tree.DataTypeArchiveGTree;
@ -24,13 +29,6 @@ import ghidra.framework.main.datatable.DomainFileProvider;
import ghidra.framework.model.DomainFile;
import ghidra.program.model.listing.Program;
import java.util.ArrayList;
import java.util.List;
import javax.swing.tree.TreePath;
import docking.widgets.tree.GTreeNode;
public class DataTypesActionContext extends ProgramActionContext implements DomainFileProvider {
private final GTreeNode clickedNode;
private final boolean isToolbarAction;

View File

@ -26,6 +26,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import docking.*;
import docking.event.mouse.GMouseListenerAdapter;
import docking.widgets.tree.support.GTreeSelectionEvent;
import docking.widgets.tree.support.GTreeSelectionListener;
import ghidra.framework.main.datatree.ClearCutAction;
@ -40,7 +41,7 @@ import ghidra.util.layout.PairLayout;
* Dialog to open or save domain data items to a new location or name.
*/
public class DataTreeDialog extends DialogComponentProvider
implements GTreeSelectionListener, ActionListener {
implements GTreeSelectionListener, ActionListener {
/**
* Dialog type for opening domain data files.
@ -540,10 +541,11 @@ implements GTreeSelectionListener, ActionListener {
protected void addTreeListeners() {
if (type == OPEN) {
treePanel.addTreeMouseListener(new MouseAdapter() {
treePanel.addTreeMouseListener(new GMouseListenerAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2 && okButton.isEnabled()) {
public void doubleClickTriggered(MouseEvent e) {
if (okButton.isEnabled()) {
okCallback();
}
}
@ -671,7 +673,7 @@ implements GTreeSelectionListener, ActionListener {
// populate the combo box
DefaultComboBoxModel<String> model =
(DefaultComboBoxModel<String>) projectComboBox.getModel();
(DefaultComboBoxModel<String>) projectComboBox.getModel();
model.removeAllElements();
Set<String> map = new HashSet<>();

View File

@ -47,7 +47,12 @@ public class ActionContext {
}
/**
* For Testing
* Constructor
*
* @param provider the ComponentProvider that generated this context.
* @param contextObject an optional contextObject that the ComponentProvider can provide
* @param sourceObject an optional source object; this can be anything that actions wish to
* later retrieve
*/
public ActionContext(ComponentProvider provider, Object contextObject, Object sourceObject) {
this(provider, contextObject);
@ -55,8 +60,8 @@ public class ActionContext {
}
/**
* Returns the {@link #ComponentProvider} that generated this ActionContext
* @return
* Returns the {@link ComponentProvider} that generated this ActionContext
* @return the provider
*/
public ComponentProvider getComponentProvider() {
return provider;

View File

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,69 +18,75 @@ package docking.widgets.tree.support;
import java.awt.datatransfer.*;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import docking.widgets.tree.GTreeNode;
/**
* A transferable for sharing data via drag/drop and clipboard operations for GTrees.
* A transferable for sharing data via drag/drop and clipboard operations for GTrees
*/
public class GTreeNodeTransferable implements Transferable {
private final List<GTreeNode> selectedData;
private final GTreeTransferHandler transferHandler;
private final List<GTreeNode> selectedData;
private final GTreeTransferHandler transferHandler;
/**
* Creates this transferable based upon the selected data and uses the given transfer
* handler to perform {@link Transferable} operations.
* @param handler the handler used to perform transfer operations.
* @param selectedData The
*/
public GTreeNodeTransferable( GTreeTransferHandler handler, List<GTreeNode> selectedData) {
this.selectedData = selectedData;
this.transferHandler = handler;
}
/**
* Returns all of the original selected data contained by this transferable.
* @return all of the original selected data contained by this transferable
*/
public List<GTreeNode> getAllData() {
return selectedData;
}
/**
* Gets the transfer data from the selection based upon the given flavor.
* @param transferNodes The nodes from which to get the data.
* @param flavor The flavor of data to retreive from the given selection.
* @return the transfer data from the selection based upon the given flavor.
* @throws UnsupportedFlavorException if the given flavor is not one of the supported flavors
* returned by {@link #getSupportedDataFlavors(List)}.
*/
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
return transferHandler.getTransferData(selectedData, flavor);
}
/**
* Returns the DataFlavors for the types of data that this transferable supports, based upon
* the given selection.
* @param transferNodes The nodes to base the DataFlavor selection upon.
* @return the DataFlavors for the types of data that this transferable supports, based upon
* the given selection.
/**
* Creates this transferable based upon the selected data and uses the given transfer
* handler to perform {@link Transferable} operations
*
* @param handler the handler used to perform transfer operations
* @param selectedData The selected tree nodes
*/
public DataFlavor[] getTransferDataFlavors() {
return transferHandler.getSupportedDataFlavors(selectedData);
}
public GTreeNodeTransferable(GTreeTransferHandler handler, List<GTreeNode> selectedData) {
this.transferHandler = Objects.requireNonNull(handler);
this.selectedData = Objects.requireNonNull(selectedData);
}
/**
* A convenience method to determine if this transferable supports the given flavor.
* @return true if this transferable supports the given flavor.
*/
public boolean isDataFlavorSupported(DataFlavor flavor) {
DataFlavor[] flavors = transferHandler.getSupportedDataFlavors(selectedData);
for(int i=0;i<flavors.length;i++) {
if (flavors[i].equals(flavor)) {
return true;
}
}
return false;
}
/**
* Returns all of the original selected data contained by this transferable.
* @return all of the original selected data contained by this transferable
*/
public List<GTreeNode> getAllData() {
return selectedData;
}
/**
* Gets the transfer data from the selection based upon the given flavor
* @param flavor The flavor of data to retrieve from the given selection.
* @return the transfer data from the selection based upon the given flavor.
* @throws UnsupportedFlavorException if the given flavor is not one of the supported flavors
* returned by {@link #getTransferDataFlavors()}
*/
@Override
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
return transferHandler.getTransferData(selectedData, flavor);
}
/**
* Returns the DataFlavors for the types of data that this transferable supports, based upon
* the given selection
*
* @return the DataFlavors for the types of data that this transferable supports, based upon
* the given selection
*/
@Override
public DataFlavor[] getTransferDataFlavors() {
return transferHandler.getSupportedDataFlavors(selectedData);
}
/**
* A convenience method to determine if this transferable supports the given flavor
* @return true if this transferable supports the given flavor
*/
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
DataFlavor[] flavors = transferHandler.getSupportedDataFlavors(selectedData);
for (DataFlavor f : flavors) {
if (f.equals(flavor)) {
return true;
}
}
return false;
}
}

View File

@ -30,6 +30,7 @@ public class ProjectDataActionContext extends ActionContext implements DomainFil
private Component comp;
private boolean isActiveProject;
private ProjectData projectData;
private boolean isTransient;
public ProjectDataActionContext(ComponentProvider provider, ProjectData projectData,
Object contextObject, List<DomainFolder> selectedFolders,
@ -112,4 +113,20 @@ public class ProjectDataActionContext extends ActionContext implements DomainFil
}
return false;
}
/**
* Transient data is that which will appear in a temporary project dialog
* @param isTransient true if transient
*/
public void setTransient(boolean isTransient) {
this.isTransient = isTransient;
}
/**
* Transient data is that which will appear in a temporary project dialog
* @return true if transient
*/
public boolean isTransient() {
return isTransient;
}
}

View File

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,20 +25,42 @@ public abstract class ProjectDataContextAction extends DockingAction {
}
@Override
public final boolean isEnabledForContext(ActionContext actionContext) {
public boolean isEnabledForContext(ActionContext actionContext) {
if (!(actionContext instanceof ProjectDataActionContext)) {
return false;
}
ProjectDataActionContext context = (ProjectDataActionContext) actionContext;
if (ignoreTransientProject(context)) {
return false;
}
return isEnabledForContext(context);
}
protected boolean ignoreTransientProject(ProjectDataActionContext context) {
if (supportsTransientProjectData()) {
return false;
}
return context.isTransient();
}
/**
* Signals that this action can work on normal project data, as well as transient data.
* Transient data is that which will appear in a temporary project dialog.
*
* @return true if this action works on transient project data
*/
protected boolean supportsTransientProjectData() {
return false;
}
protected boolean isEnabledForContext(ProjectDataActionContext context) {
return context.hasOneOrMoreFilesAndFolders();
}
@Override
public final void actionPerformed(ActionContext context) {
public void actionPerformed(ActionContext context) {
actionPerformed((ProjectDataActionContext) context);
}
@ -59,7 +80,7 @@ public abstract class ProjectDataContextAction extends DockingAction {
@Override
public boolean isAddToPopup(ActionContext context) {
if (!(context instanceof ProjectDataActionContext)) {
if (!isEnabledForContext(context)) {
return false;
}
return isAddToPopup((ProjectDataActionContext) context);

View File

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,10 +29,32 @@ public abstract class ProjectDataContextToggleAction extends ToggleDockingAction
if (!(actionContext instanceof ProjectDataActionContext)) {
return false;
}
ProjectDataActionContext context = (ProjectDataActionContext) actionContext;
if (ignoreTransientProject(context)) {
return false;
}
return isEnabledForContext(context);
}
protected boolean ignoreTransientProject(ProjectDataActionContext context) {
if (supportsTransientProjectData()) {
return false;
}
return context.isTransient();
}
/**
* Signals that this action can work on normal project data, as well as transient data.
* Transient data is that which will appear in a temporary project dialog.
*
* @return true if this action works on transient project data
*/
protected boolean supportsTransientProjectData() {
return false;
}
protected boolean isEnabledForContext(ProjectDataActionContext context) {
return context.hasOneOrMoreFilesAndFolders();
}

View File

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,9 +15,9 @@
*/
package ghidra.framework.main.datatable;
import ghidra.framework.main.datatree.ProjectDataTreeActionContext;
import docking.ActionContext;
import docking.action.DockingAction;
import ghidra.framework.main.datatree.ProjectDataTreeActionContext;
public abstract class ProjectDataTreeContextAction extends DockingAction {
@ -31,10 +30,32 @@ public abstract class ProjectDataTreeContextAction extends DockingAction {
if (!(actionContext instanceof ProjectDataTreeActionContext)) {
return false;
}
ProjectDataTreeActionContext context = (ProjectDataTreeActionContext) actionContext;
if (ignoreTransientProject(context)) {
return false;
}
return isEnabledForContext(context);
}
protected boolean ignoreTransientProject(ProjectDataActionContext context) {
if (supportsTransientProjectData()) {
return false;
}
return context.isTransient();
}
/**
* Signals that this action can work on normal project data, as well as transient data.
* Transient data is that which will appear in a temporary project dialog.
*
* @return true if this action works on transient project data
*/
protected boolean supportsTransientProjectData() {
return false;
}
protected boolean isEnabledForContext(ProjectDataTreeActionContext context) {
return context.hasOneOrMoreFilesAndFolders();
}
@ -60,7 +81,7 @@ public abstract class ProjectDataTreeContextAction extends DockingAction {
@Override
public boolean isAddToPopup(ActionContext context) {
if (!(context instanceof ProjectDataTreeActionContext)) {
if (!isEnabledForContext(context)) {
return false;
}
return isAddToPopup((ProjectDataTreeActionContext) context);

View File

@ -23,6 +23,7 @@ import javax.swing.tree.TreePath;
import docking.dnd.GClipboard;
import docking.widgets.tree.GTreeNode;
import docking.widgets.tree.support.GTreeNodeTransferable;
import ghidra.util.Msg;
/**
@ -35,14 +36,8 @@ public class DataTreeClipboardUtils {
* Static instance of a callback handler that is notified when the clipboard is changed
* and our data is discarded.
*/
private static final ClipboardOwner DATATREE_CLIPBOARD_OWNER = new ClipboardOwner() {
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
// This is called when something other than this class modifies the clipboard
// and our data is discarded.
clearCuttables(contents);
}
};
private static final ClipboardOwner DATATREE_CLIPBOARD_OWNER =
(clipboard, contents) -> clearCuttables(contents);
/**
* Pushes the GTreeNodes in the specified TreePath array to the clipboard.
@ -59,8 +54,9 @@ public class DataTreeClipboardUtils {
GTreeNode node = (GTreeNode) element.getLastPathComponent();
list.add(node);
}
DataTreeNodeTransferable contents =
new DataTreeNodeTransferable(tree.getDragNDropHandler(), list);
GTreeNodeTransferable contents =
new GTreeNodeTransferable(tree.getDragNDropHandler(), list);
try {
clipboard.setContents(contents, DATATREE_CLIPBOARD_OWNER);

View File

@ -1,30 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* 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 ghidra.framework.main.datatree;
import java.util.List;
import docking.widgets.tree.GTreeNode;
import docking.widgets.tree.support.GTreeNodeTransferable;
import docking.widgets.tree.support.GTreeTransferHandler;
public class DataTreeNodeTransferable extends GTreeNodeTransferable {
public DataTreeNodeTransferable(GTreeTransferHandler handler, List<GTreeNode> selectedData) {
super(handler, selectedData);
}
}

View File

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,14 +15,13 @@
*/
package ghidra.framework.main.datatree;
import ghidra.framework.main.datatable.ProjectDataActionContext;
import ghidra.framework.model.*;
import java.util.List;
import javax.swing.tree.TreePath;
import docking.ComponentProvider;
import ghidra.framework.main.datatable.ProjectDataActionContext;
import ghidra.framework.model.*;
public class ProjectDataTreeActionContext extends ProjectDataActionContext {
@ -52,7 +50,7 @@ public class ProjectDataTreeActionContext extends ProjectDataActionContext {
return selectionPaths;
}
public DataTree getDataTree() {
public DataTree getTree() {
return tree;
}
}

View File

@ -337,8 +337,11 @@ public class ProjectDataTreePanel extends JPanel {
}
}
return new ProjectDataTreeActionContext(provider, projectData, selectionPaths,
domainFolderList, domainFileList, tree, isActiveProject);
ProjectDataTreeActionContext context = new ProjectDataTreeActionContext(provider,
projectData, selectionPaths, domainFolderList, domainFileList, tree, isActiveProject);
boolean isTransient = tool == null; // null for stand-alone dialog, not the project's tree
context.setTransient(isTransient);
return context;
}
public DataTree getDataTree() {

View File

@ -33,7 +33,7 @@ public class ProjectDataCollapseAction extends ProjectDataTreeContextAction {
@Override
protected void actionPerformed(ProjectDataTreeActionContext context) {
DataTree tree = context.getDataTree();
DataTree tree = context.getTree();
TreePath[] paths = context.getSelectionPaths();
collapse(tree, paths[0]);
}

View File

@ -40,7 +40,7 @@ public class ProjectDataCopyAction extends ProjectDataCopyCutBaseAction {
protected void actionPerformed(ProjectDataTreeActionContext context) {
TreePath[] paths = adjustSelectionPaths(context.getSelectionPaths());
DataTreeClipboardUtils.setClipboardContents(context.getDataTree(), paths);
DataTreeClipboardUtils.setClipboardContents(context.getTree(), paths);
}

View File

@ -40,7 +40,7 @@ public class ProjectDataCutAction extends ProjectDataCopyCutBaseAction {
protected void actionPerformed(ProjectDataTreeActionContext context) {
TreePath[] paths = adjustSelectionPaths(context.getSelectionPaths());
DataTreeClipboardUtils.setClipboardContents(context.getDataTree(), paths);
DataTreeClipboardUtils.setClipboardContents(context.getTree(), paths);
markNodesCut(paths);
}

View File

@ -33,7 +33,7 @@ public class ProjectDataExpandAction extends ProjectDataTreeContextAction {
@Override
protected void actionPerformed(ProjectDataTreeActionContext context) {
DataTree tree = context.getDataTree();
DataTree tree = context.getTree();
TreePath[] paths = context.getSelectionPaths();
expand(tree, paths[0]);
}

View File

@ -41,6 +41,12 @@ public class ProjectDataNewFolderAction extends ProjectDataContextAction {
markHelpUnnecessary();
}
@Override
protected boolean supportsTransientProjectData() {
// we allow the user to create new folders even in transient projects
return true;
}
@Override
protected void actionPerformed(ProjectDataActionContext context) {
createNewFolder(context);

View File

@ -44,7 +44,7 @@ public class ProjectDataPasteAction extends ProjectDataCopyCutBaseAction {
GTreeNode node = (GTreeNode) context.getContextObject();
DomainFolderNode destNode = getFolderForNode(node);
paste(context.getDataTree(), destNode);
paste(context.getTree(), destNode);
}
@Override

View File

@ -50,6 +50,10 @@ public class ProjectDataReadOnlyAction extends ProjectDataContextToggleAction {
if (context.getFolderCount() != 0 || context.getFileCount() != 1) {
return false;
}
if (ignoreTransientProject(context)) {
return false;
}
DomainFile domainFile = context.getSelectedFiles().get(0);
setSelected(domainFile.isReadOnly());
return true;

View File

@ -36,7 +36,7 @@ public class ProjectDataSelectAction extends ProjectDataTreeContextAction {
@Override
protected void actionPerformed(ProjectDataTreeActionContext context) {
DataTree tree = context.getDataTree();
DataTree tree = context.getTree();
TreePath[] paths = context.getSelectionPaths();
GTreeNode node = (GTreeNode) paths[0].getLastPathComponent();
selectAllChildren(tree, node);