Skip to content

Commit

Permalink
fixed null pointer on session close and back button on disk space ana…
Browse files Browse the repository at this point in the history
…lyzer
  • Loading branch information
subhra74 committed Apr 20, 2020
1 parent d79f816 commit c2b2fcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ public void close() {
e.printStackTrace();
}
App.removePendingTransfers(this.getActiveSessionId());
this.backgroundTransferPool.shutdownNow();
if (this.backgroundTransferPool != null) {
this.backgroundTransferPool.shutdownNow();
}

EXECUTOR.submit(() -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ public DiskspaceAnalyzer(SessionContentPanel holder) {
}

private Component createResultPanel() {
treeModel = new DefaultTreeModel(
new DefaultMutableTreeNode("results", true), true);
treeModel = new DefaultTreeModel(new DefaultMutableTreeNode("results", true), true);
resultTree = new JTree(treeModel);
resultTree.getSelectionModel()
.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
resultTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

JButton btnStart = new JButton("Start another analysis");
btnStart.addActionListener(e -> {
Expand Down Expand Up @@ -106,8 +104,7 @@ private Component createFirstPanel() {
cardLayout.show(this, "volPanel");
listVolumes();
} else {
String text = OptionPaneUtils.showInputDialog(this,
"Please enter folder path to analyze", "Input");
String text = OptionPaneUtils.showInputDialog(this, "Please enter folder path to analyze", "Input");
if (text != null) {
cardLayout.show(this, "resultPanel");
analyze(text);
Expand Down Expand Up @@ -154,8 +151,7 @@ private Component createVolumesPanel() {
table.setAutoCreateRowSorter(true);
table.setDefaultRenderer(Object.class, r1);
table.setDefaultRenderer(Double.class, r2);
table.setRowHeight(Math.max(r1.getPreferredSize().height,
r2.getPreferredSize().height));
table.setRowHeight(Math.max(r1.getPreferredSize().height, r2.getPreferredSize().height));
table.setSelectionForeground(App.SKIN.getDefaultSelectionForeground());
JScrollPane jsp = new SkinnedScrollPane(table);

Expand All @@ -170,12 +166,15 @@ private Component createVolumesPanel() {
cardLayout.show(this, "resultPanel");
analyze(model.get(r).getMountPoint());
} else {
JOptionPane.showMessageDialog(this,
"Please select a partition");
JOptionPane.showMessageDialog(this, "Please select a partition");
return;
}
});

btnBack.addActionListener(e -> {
cardLayout.show(this, "firstPanel");
});

Box bottomBox = Box.createHorizontalBox();
bottomBox.add(btnReload);
bottomBox.add(Box.createHorizontalGlue());
Expand Down Expand Up @@ -212,9 +211,7 @@ public String getText() {
private void listPartitions(AtomicBoolean stopFlag) {
try {
StringBuilder output = new StringBuilder();
if (holder.getRemoteSessionInstance().exec(
"export POSIXLY_CORRECT=1;df -P -k", stopFlag,
output) == 0) {
if (holder.getRemoteSessionInstance().exec("export POSIXLY_CORRECT=1;df -P -k", stopFlag, output) == 0) {
List<PartitionEntry> list = new ArrayList<>();
boolean first = true;
for (String line : output.toString().split("\n")) {
Expand All @@ -228,10 +225,8 @@ private void listPartitions(AtomicBoolean stopFlag) {
String[] arr = line.split("\\s+");
if (arr.length < 6)
continue;
PartitionEntry ent = new PartitionEntry(arr[0], arr[5],
Long.parseLong(arr[1].trim()) * 1024,
Long.parseLong(arr[2].trim()) * 1024,
Long.parseLong(arr[3].trim()) * 1024,
PartitionEntry ent = new PartitionEntry(arr[0], arr[5], Long.parseLong(arr[1].trim()) * 1024,
Long.parseLong(arr[2].trim()) * 1024, Long.parseLong(arr[3].trim()) * 1024,
Double.parseDouble(arr[4].replace("%", "").trim()));
list.add(ent);
}
Expand Down Expand Up @@ -270,8 +265,7 @@ private void analyze(String path) {
SwingUtilities.invokeLater(() -> {
if (res != null) {
System.out.println("Result found");
DefaultMutableTreeNode root = new DefaultMutableTreeNode(
res, true);
DefaultMutableTreeNode root = new DefaultMutableTreeNode(res, true);
root.setAllowsChildren(true);
createTree(root, res);
treeModel.setRoot(root);
Expand All @@ -284,16 +278,13 @@ private void analyze(String path) {
holder.EXECUTOR.submit(task);
}

private void createTree(DefaultMutableTreeNode treeNode,
DiskUsageEntry entry) {
private void createTree(DefaultMutableTreeNode treeNode, DiskUsageEntry entry) {
// DefaultMutableTreeNode node = new DefaultMutableTreeNode(entry);
Collections.sort(entry.getChildren(), (a, b) -> {
return a.getSize() < b.getSize() ? 1
: (a.getSize() > b.getSize() ? -1 : 0);
return a.getSize() < b.getSize() ? 1 : (a.getSize() > b.getSize() ? -1 : 0);
});
for (DiskUsageEntry ent : entry.getChildren()) {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(ent,
true);
DefaultMutableTreeNode child = new DefaultMutableTreeNode(ent, true);
child.setAllowsChildren(true);
treeNode.add(child);
createTree(child, ent);
Expand Down

0 comments on commit c2b2fcc

Please sign in to comment.