Fix problem on "Select Location" popup
emmanue1
5 years ago
68 | 68 | filteredContainerWrappers.add(new FilteredContainerWrapper(container, getOuterEntries(mapEntry.getValue()))); |
69 | 69 | } |
70 | 70 | |
71 | selectLocationView.show( | |
72 | location, filteredContainerWrappers, entries.size(), | |
73 | new Consumer<URI>() { | |
74 | @Override public void accept(URI uri) { onLocationSelected(filteredContainerWrappers, uri, selectedLocationCallback); } | |
75 | }, | |
76 | closeCallback); | |
71 | Consumer<URI> selectedEntryCallback = uri -> onLocationSelected(filteredContainerWrappers, uri, selectedLocationCallback); | |
72 | ||
73 | selectLocationView.show(location, filteredContainerWrappers, entries.size(), selectedEntryCallback, closeCallback); | |
77 | 74 | } |
78 | 75 | |
79 | 76 | protected Collection<Container.Entry> getOuterEntries(Collection<Container.Entry> entries) { |
13 | 13 | import java.util.*; |
14 | 14 | |
15 | 15 | public class FilteredContainerWrapper implements Container { |
16 | protected static final URI DEFAULT_ROOT_URI = URI.create("file:."); | |
17 | ||
16 | 18 | protected Container container; |
17 | 19 | protected EntryWrapper root; |
18 | 20 | |
47 | 49 | return entryWrapper; |
48 | 50 | } |
49 | 51 | |
50 | protected ContainerWrapper getContainerWrapper(Container.Entry entry) { | |
51 | URI uri = entry.getContainer().getRoot().getUri(); | |
52 | protected ContainerWrapper getContainerWrapper(Container container) { | |
53 | Entry root = container.getRoot(); | |
54 | URI uri = (root == null) ? DEFAULT_ROOT_URI : root.getUri(); | |
52 | 55 | ContainerWrapper containerWrapper = uriToContainerWrapper.get(uri); |
53 | 56 | if (containerWrapper == null) { |
54 | uriToContainerWrapper.put(uri, containerWrapper=new ContainerWrapper(entry.getContainer())); | |
57 | uriToContainerWrapper.put(uri, containerWrapper=new ContainerWrapper(container)); | |
55 | 58 | } |
56 | 59 | return containerWrapper; |
57 | 60 | } |
64 | 67 | this.entry = entry; |
65 | 68 | } |
66 | 69 | |
67 | @Override public Container getContainer() { return getContainerWrapper(entry.getContainer().getRoot()); } | |
70 | @Override public Container getContainer() { return getContainerWrapper(entry.getContainer()); } | |
68 | 71 | @Override public Entry getParent() { return getEntryWrapper(entry.getParent()); } |
69 | 72 | @Override public URI getUri() { return entry.getUri(); } |
70 | 73 | @Override public String getPath() { return entry.getPath(); } |
23 | 23 | import java.util.Iterator; |
24 | 24 | |
25 | 25 | public class GenericContainer implements Container { |
26 | protected static final long TIMESTAMP = System.currentTimeMillis(); | |
27 | ||
28 | protected static long tmpFileCounter = 0; | |
29 | ||
26 | 30 | protected API api; |
27 | 31 | protected int rootNameCount; |
28 | 32 | protected Container.Entry root; |
29 | 33 | |
30 | 34 | public GenericContainer(API api, Container.Entry parentEntry, Path rootPath) { |
31 | this.api = api; | |
32 | this.rootNameCount = rootPath.getNameCount(); | |
33 | this.root = new Entry(parentEntry, rootPath, parentEntry.getUri()) { | |
34 | public Entry newChildEntry(Path fsPath) { | |
35 | return new Entry(parent, fsPath, null); | |
36 | } | |
37 | }; | |
35 | try { | |
36 | URI uri = parentEntry.getUri(); | |
37 | ||
38 | this.api = api; | |
39 | this.rootNameCount = rootPath.getNameCount(); | |
40 | this.root = new Entry(parentEntry, rootPath, new URI(uri.getScheme(), uri.getHost(), uri.getPath() + "!/", null)) { | |
41 | public Entry newChildEntry(Path fsPath) { | |
42 | return new Entry(parent, fsPath, null); | |
43 | } | |
44 | }; | |
45 | } catch (URISyntaxException e) { | |
46 | assert ExceptionUtil.printStackTrace(e); | |
47 | } | |
38 | 48 | } |
39 | 49 | |
40 | 50 | public String getType() { return "generic"; } |
65 | 75 | public URI getUri() { |
66 | 76 | if (uri == null) { |
67 | 77 | try { |
68 | uri = new URI(root.getUri().getScheme(), root.getUri().getHost(), root.getUri().getPath() + "!/" + getPath(), null); | |
78 | URI rootUri = root.getUri(); | |
79 | uri = new URI(rootUri.getScheme(), rootUri.getHost(), rootUri.getPath() + getPath(), null); | |
69 | 80 | } catch (URISyntaxException e) { |
70 | 81 | assert ExceptionUtil.printStackTrace(e); |
71 | 82 | } |
145 | 156 | } |
146 | 157 | |
147 | 158 | protected Collection<Container.Entry> loadChildrenFromFileEntry() throws IOException { |
148 | File tmpFile = File.createTempFile("jd-gui.", "." + fsPath.getFileName().toString()); | |
159 | StringBuilder suffix = new StringBuilder(".").append(TIMESTAMP).append('.').append(tmpFileCounter++).append('.').append(fsPath.getFileName().toString()); | |
160 | File tmpFile = File.createTempFile("jd-gui.tmp.", suffix.toString()); | |
149 | 161 | Path tmpPath = Paths.get(tmpFile.toURI()); |
150 | 162 | |
151 | 163 | tmpFile.delete(); |
165 | 177 | Container container = containerFactory.make(api, this, rootPath); |
166 | 178 | |
167 | 179 | if (container != null) { |
168 | tmpFile.delete(); | |
169 | 180 | return container.getRoot().getChildren(); |
170 | 181 | } |
171 | 182 | } |