001 /* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 /* 015 * This file has been modified by Chris Pheby in accordance with Section 4.2 016 * of the Apache Software License 017 */ 018 package org.jadira.dependencynavigator.implementations.local; 019 020 import org.jadira.dependencynavigator.implementations.Workspace; 021 import org.jadira.dependencynavigator.implementations.WorkspaceLoader; 022 import org.jadira.dependencynavigator.implementations.local.LocalDiskWorkspace; 023 import org.jadira.dependencynavigator.model.ArtifactInitialisationException; 024 import org.jadira.dependencynavigator.model.RootPom; 025 026 import javax.swing.*; 027 import javax.swing.filechooser.FileFilter; 028 import java.io.File; 029 030 public class LocalDiskWorkspaceLoader implements WorkspaceLoader { 031 private Workspace workspace; 032 private JFrame frame; 033 034 private LocalDiskWorkspace localDiskWorkspace() { 035 if (workspace instanceof LocalDiskWorkspace) { 036 return (LocalDiskWorkspace) workspace; 037 } 038 throw new RuntimeException("Expected workspace of type " + LocalDiskWorkspace.class.getName() + " not " + workspace.getClass().getName()); 039 } 040 041 public void loadPom() throws ArtifactInitialisationException { 042 043 JFileChooser fc = new JFileChooser() { 044 045 private static final long serialVersionUID = -3542823132189366492L; 046 047 @Override 048 public void updateUI() { 049 // workaround for bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6317789 050 putClientProperty("FileChooser.useShellFolder", Boolean.FALSE); 051 super.updateUI(); 052 } 053 }; 054 fc.setCurrentDirectory(localDiskWorkspace().getWorkspaceDirectory()); 055 fc.setFileFilter(new FileFilter() { 056 057 @Override 058 public boolean accept(File f) { 059 return f.isDirectory() || "pom.xml".equals(f.getName()); 060 } 061 062 @Override 063 public String getDescription() { 064 return "Maven 2 pom files"; 065 } 066 067 }); 068 int returnVal = fc.showOpenDialog(frame); 069 if (returnVal == JFileChooser.APPROVE_OPTION) { 070 File file = fc.getSelectedFile(); 071 localDiskWorkspace().loadRootPom(file); 072 } 073 } 074 075 public RootPom getRoot() { 076 return workspace.getRoot(); 077 } 078 079 public void reloadPom() throws ArtifactInitialisationException { 080 workspace.reloadPomFile(); 081 } 082 083 }