8291823: IGV: Fix "Save selected groups"
Reviewed-by: rcastanedalo, kvn, thartmann
This commit is contained in:
parent
504a626597
commit
b0d6952811
src/utils/IdealGraphVisualizer/Coordinator/src/main/java/com/sun/hotspot/igv/coordinator
@ -59,6 +59,10 @@ public class FolderNode extends AbstractNode {
|
||||
folder.getChangedEvent().addListener(this);
|
||||
}
|
||||
|
||||
public Folder getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node[] createNodes(FolderElement e) {
|
||||
if (e instanceof InputGraph) {
|
||||
@ -137,6 +141,11 @@ public class FolderNode extends AbstractNode {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRootNode() {
|
||||
Folder folder = getFolder();
|
||||
return (folder != null && folder instanceof GraphDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getOpenedIcon(int i) {
|
||||
return getIcon(i);
|
||||
@ -149,4 +158,8 @@ public class FolderNode extends AbstractNode {
|
||||
public static GraphNode getGraphNode(InputGraph graph) {
|
||||
return graphNode.get(graph);
|
||||
}
|
||||
|
||||
public Folder getFolder() {
|
||||
return children.getFolder();
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,7 @@ import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.Serializable;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import org.openide.ErrorManager;
|
||||
import org.openide.actions.GarbageCollectAction;
|
||||
@ -71,6 +70,9 @@ public final class OutlineTopComponent extends TopComponent implements ExplorerM
|
||||
private FolderNode root;
|
||||
private Server server;
|
||||
private Server binaryServer;
|
||||
private SaveAllAction saveAllAction;
|
||||
private RemoveAllAction removeAllAction;
|
||||
|
||||
|
||||
private OutlineTopComponent() {
|
||||
initComponents();
|
||||
@ -94,25 +96,37 @@ public final class OutlineTopComponent extends TopComponent implements ExplorerM
|
||||
}
|
||||
|
||||
private void initToolbar() {
|
||||
|
||||
Toolbar toolbar = new Toolbar();
|
||||
Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
|
||||
toolbar.setBorder(b);
|
||||
this.add(toolbar, BorderLayout.NORTH);
|
||||
|
||||
toolbar.add(ImportAction.get(ImportAction.class));
|
||||
|
||||
toolbar.add(((NodeAction) SaveAsAction.get(SaveAsAction.class)).createContextAwareInstance(this.getLookup()));
|
||||
toolbar.add(SaveAllAction.get(SaveAllAction.class));
|
||||
|
||||
saveAllAction = SaveAllAction.get(SaveAllAction.class);
|
||||
saveAllAction.setEnabled(false);
|
||||
toolbar.add(saveAllAction);
|
||||
|
||||
toolbar.add(((NodeAction) RemoveAction.get(RemoveAction.class)).createContextAwareInstance(this.getLookup()));
|
||||
toolbar.add(RemoveAllAction.get(RemoveAllAction.class));
|
||||
|
||||
removeAllAction = RemoveAllAction.get(RemoveAllAction.class);
|
||||
removeAllAction.setEnabled(false);
|
||||
toolbar.add(removeAllAction);
|
||||
|
||||
toolbar.add(GarbageCollectAction.get(GarbageCollectAction.class).getToolbarPresenter());
|
||||
|
||||
for (Toolbar tb : ToolbarPool.getDefault().getToolbars()) {
|
||||
tb.setVisible(false);
|
||||
}
|
||||
|
||||
document.getChangedEvent().addListener(g -> documentChanged());
|
||||
}
|
||||
|
||||
private void documentChanged() {
|
||||
boolean enableButton = !document.getElements().isEmpty();
|
||||
saveAllAction.setEnabled(enableButton);
|
||||
removeAllAction.setEnabled(enableButton);
|
||||
}
|
||||
|
||||
private void initReceivers() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
package com.sun.hotspot.igv.coordinator.actions;
|
||||
|
||||
import com.sun.hotspot.igv.coordinator.FolderNode;
|
||||
import javax.swing.Action;
|
||||
import org.openide.nodes.Node;
|
||||
import org.openide.util.HelpCtx;
|
||||
@ -72,6 +73,14 @@ public final class RemoveAction extends NodeAction {
|
||||
|
||||
@Override
|
||||
protected boolean enable(Node[] nodes) {
|
||||
return nodes.length > 0;
|
||||
if (nodes.length > 0) {
|
||||
for (Node n : nodes) {
|
||||
if ((n instanceof FolderNode) && ((FolderNode) n).isRootNode()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,6 +24,9 @@
|
||||
|
||||
package com.sun.hotspot.igv.coordinator.actions;
|
||||
|
||||
import com.sun.hotspot.igv.coordinator.FolderNode;
|
||||
import com.sun.hotspot.igv.coordinator.OutlineTopComponent;
|
||||
import com.sun.hotspot.igv.data.Folder;
|
||||
import com.sun.hotspot.igv.data.GraphDocument;
|
||||
import com.sun.hotspot.igv.data.Group;
|
||||
import com.sun.hotspot.igv.data.serialization.Printer;
|
||||
@ -49,13 +52,18 @@ public final class SaveAsAction extends NodeAction {
|
||||
|
||||
@Override
|
||||
protected void performAction(Node[] activatedNodes) {
|
||||
|
||||
final OutlineTopComponent component = OutlineTopComponent.findInstance();
|
||||
GraphDocument doc = new GraphDocument();
|
||||
for (Node n : activatedNodes) {
|
||||
Group group = n.getLookup().lookup(Group.class);
|
||||
doc.addElement(group);
|
||||
for (Node node : activatedNodes) {
|
||||
if (node instanceof FolderNode) {
|
||||
FolderNode folderNode = (FolderNode) node;
|
||||
Folder folder = folderNode.getFolder();
|
||||
if (folder instanceof Group) {
|
||||
Group group = (Group) folder;
|
||||
doc.addElement(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
save(doc);
|
||||
}
|
||||
|
||||
@ -115,12 +123,14 @@ public final class SaveAsAction extends NodeAction {
|
||||
|
||||
@Override
|
||||
protected boolean enable(Node[] nodes) {
|
||||
|
||||
int cnt = 0;
|
||||
for (Node n : nodes) {
|
||||
cnt += n.getLookup().lookupAll(Group.class).size();
|
||||
if (nodes.length > 0) {
|
||||
for (Node n : nodes) {
|
||||
if (!(n instanceof FolderNode) || ((FolderNode) n).isRootNode()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return cnt > 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user