private void updateTree() { if (myFileSystemTree != null) { Disposer.dispose(myFileSystemTree); myFileSystemTree = null; } myFileSystemTree = new FileSystemTreeImpl( null, new FileChooserDescriptor(true, true, true, true, true, false)); AbstractTreeUi ui = myFileSystemTree.getTreeBuilder().getUi(); String path = myModelRoot.getPath() == null ? "" : myModelRoot.getPath(); VirtualFile virtualFile = VirtualFileManager.getInstance() .findFileByUrl(VirtualFileManager.constructUrl("file", path)); if (myModelRoot.getModule() != null && (virtualFile == null || path.isEmpty())) { if (myModelRoot.getModule() instanceof AbstractModule) { virtualFile = VirtualFileManager.getInstance() .findFileByUrl( VirtualFileManager.constructUrl( "file", ((AbstractModule) myModelRoot.getModule()) .getModuleSourceDir() .getPath())); } } if (virtualFile != null) myFileSystemTree.select(virtualFile, null); myFileSystemTree.addListener( new Listener() { @Override public void selectionChanged(List<VirtualFile> selection) { if (selection.size() > 0) { myModelRoot.setPath(FileUtil.getCanonicalPath(selection.get(0).getPath())); myEventDispatcher.getMulticaster().fireDataChanged(); } } }, SModelRootEntry.this); Disposer.register(SModelRootEntry.this, myFileSystemTree); myTreePanel.removeAll(); myTreePanel.add(ui.getTree(), BorderLayout.CENTER); ui.scrollSelectionToVisible(null, true); }
@Override public String getDetailsText() { final StringBuilder messageText = new StringBuilder(); messageText.append("<html>"); messageText.append("Type : ").append(myModelRoot.getType()).append("<br>"); messageText .append("Manager : ") .append( myModelRoot.getModelRoot().getManager() != null ? myModelRoot.getModelRoot().getManager().getClassName() : "Default") .append("<br>"); messageText.append("Path : ").append(myModelRoot.getPath()).append("<br>"); return messageText.toString(); }
public static void addModelRoots( SolutionDescriptor solutionDescriptor, VirtualFile[] roots, ModelRootManager rootMgr) { Set<String> seenPaths = new HashSet<String>(); for (ModelRootDescriptor d : solutionDescriptor.getModelRootDescriptors()) { ModelRoot root = d.getRoot(); if (root != null && EqualUtil.equals(root.getManager(), rootMgr)) { seenPaths.add(root.getPath()); } } for (VirtualFile f : roots) { SModelRoot modelRoot = new SModelRoot(rootMgr); modelRoot.setPath(getLocalPath(f)); if (!seenPaths.add(modelRoot.getPath())) continue; solutionDescriptor.getModelRootDescriptors().add(modelRoot.toDescriptor()); } }
@Override public boolean isValid() { String path = myModelRoot.getPath(); return (new java.io.File(path != null ? path : "")).exists(); }