1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.jadira.dependencynavigator.implementations.local;
19
20 import org.jadira.dependencynavigator.implementations.Workspace;
21 import org.jadira.dependencynavigator.implementations.WorkspaceLoader;
22 import org.jadira.dependencynavigator.implementations.local.LocalDiskWorkspace;
23 import org.jadira.dependencynavigator.model.ArtifactInitialisationException;
24 import org.jadira.dependencynavigator.model.RootPom;
25
26 import javax.swing.*;
27 import javax.swing.filechooser.FileFilter;
28 import java.io.File;
29
30 public class LocalDiskWorkspaceLoader implements WorkspaceLoader {
31 private Workspace workspace;
32 private JFrame frame;
33
34 private LocalDiskWorkspace localDiskWorkspace() {
35 if (workspace instanceof LocalDiskWorkspace) {
36 return (LocalDiskWorkspace) workspace;
37 }
38 throw new RuntimeException("Expected workspace of type " + LocalDiskWorkspace.class.getName() + " not " + workspace.getClass().getName());
39 }
40
41 public void loadPom() throws ArtifactInitialisationException {
42
43 JFileChooser fc = new JFileChooser() {
44
45 private static final long serialVersionUID = -3542823132189366492L;
46
47 @Override
48 public void updateUI() {
49
50 putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);
51 super.updateUI();
52 }
53 };
54 fc.setCurrentDirectory(localDiskWorkspace().getWorkspaceDirectory());
55 fc.setFileFilter(new FileFilter() {
56
57 @Override
58 public boolean accept(File f) {
59 return f.isDirectory() || "pom.xml".equals(f.getName());
60 }
61
62 @Override
63 public String getDescription() {
64 return "Maven 2 pom files";
65 }
66
67 });
68 int returnVal = fc.showOpenDialog(frame);
69 if (returnVal == JFileChooser.APPROVE_OPTION) {
70 File file = fc.getSelectedFile();
71 localDiskWorkspace().loadRootPom(file);
72 }
73 }
74
75 public RootPom getRoot() {
76 return workspace.getRoot();
77 }
78
79 public void reloadPom() throws ArtifactInitialisationException {
80 workspace.reloadPomFile();
81 }
82
83 }