1 19 package org.netbeans.modules.subversion.ui.checkout; 20 21 import java.awt.Dialog ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.File ; 25 import java.util.LinkedList ; 26 import java.util.List ; 27 import javax.swing.Action ; 28 import javax.swing.BorderFactory ; 29 import javax.swing.SwingUtilities ; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.ProjectInformation; 32 import org.netbeans.api.project.ProjectUtils; 33 import org.netbeans.api.project.ui.OpenProjects; 34 import org.netbeans.modules.subversion.client.SvnProgressSupport; 35 import org.netbeans.modules.subversion.SvnModuleConfig; 36 import org.netbeans.modules.subversion.util.SvnUtils; 37 import org.netbeans.spi.project.ui.support.CommonProjectActions; 38 import org.openide.DialogDescriptor; 39 import org.openide.DialogDisplayer; 40 import org.openide.ErrorManager; 41 import org.openide.cookies.InstanceCookie; 42 import org.openide.filesystems.FileObject; 43 import org.openide.filesystems.FileUtil; 44 import org.openide.filesystems.Repository; 45 import org.openide.loaders.DataObject; 46 import org.openide.util.ContextAwareAction; 47 import org.openide.util.HelpCtx; 48 import org.openide.util.Lookup; 49 import org.openide.util.NbBundle; 50 import org.openide.util.lookup.Lookups; 51 52 56 public class CheckoutCompleted implements ActionListener { 57 58 private final File workingFolder; 59 private final boolean openProject; 60 private String [] checkedOutFolders; 61 62 private CheckoutCompletedPanel panel; 63 private Dialog dialog; 64 private Project projectToBeOpened; 65 66 public CheckoutCompleted(File workingFolder, String [] checkedOutFolders, boolean openProject) { 67 this.openProject = openProject; 68 this.checkedOutFolders = checkedOutFolders; 69 this.workingFolder = workingFolder; 70 } 71 72 public void scanForProjects(SvnProgressSupport support) { 73 74 List <Project> checkedOutProjects = new LinkedList <Project>(); 75 File normalizedWorkingFolder = FileUtil.normalizeFile(workingFolder); 76 SvnUtils.refreshRecursively(normalizedWorkingFolder); 78 FileObject fo = FileUtil.toFileObject(normalizedWorkingFolder); 79 if (fo != null) { 80 for (int i = 0; i < checkedOutFolders.length; i++) { 81 if(support!=null && support.isCanceled()) { 82 return; 83 } 84 String module = checkedOutFolders[i]; 85 if (".".equals(module)) { checkedOutProjects = ProjectUtilities.scanForProjects(fo); 87 break; 88 } else { 89 FileObject subfolder = fo.getFileObject(module); 90 if (subfolder != null) { 91 checkedOutProjects.addAll(ProjectUtilities.scanForProjects(subfolder)); 92 } 93 } 94 } 95 } 96 97 panel = new CheckoutCompletedPanel(); 98 panel.openButton.addActionListener(this); 99 panel.createButton.addActionListener(this); 100 panel.closeButton.addActionListener(this); 101 panel.setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); 102 panel.againCheckBox.setVisible(openProject == false); 103 String title = NbBundle.getMessage(CheckoutAction.class, "BK3008"); DialogDescriptor descriptor = new DialogDescriptor(panel, title); 105 descriptor.setModal(true); 106 107 panel.remove(panel.openButton); 109 panel.remove(panel.createButton); 110 panel.remove(panel.closeButton); 111 112 Object [] options = null; 113 if (checkedOutProjects.size() > 1) { 114 String msg = NbBundle.getMessage(CheckoutAction.class, "BK3009", new Integer (checkedOutProjects.size())); panel.jLabel1.setText(msg); 116 options = new Object [] { 117 panel.openButton, 118 panel.closeButton 119 }; 120 } else if (checkedOutProjects.size() == 1) { 121 Project project = (Project) checkedOutProjects.iterator().next(); 122 projectToBeOpened = project; 123 ProjectInformation projectInformation = ProjectUtils.getInformation(project); 124 String projectName = projectInformation.getDisplayName(); 125 String msg = NbBundle.getMessage(CheckoutAction.class, "BK3011", projectName); panel.jLabel1.setText(msg); 127 panel.openButton.setText(NbBundle.getMessage(CheckoutAction.class, "BK3012")); options = new Object [] { 129 panel.openButton, 130 panel.closeButton 131 }; 132 } else { 133 String msg = NbBundle.getMessage(CheckoutAction.class, "BK3010"); panel.jLabel1.setText(msg); 135 options = new Object [] { 136 panel.createButton, 137 panel.closeButton 138 }; 139 140 } 141 142 descriptor.setMessageType(DialogDescriptor.INFORMATION_MESSAGE); 143 descriptor.setOptions(options); 144 descriptor.setClosingOptions(options); 145 descriptor.setHelpCtx(new HelpCtx(CheckoutCompletedPanel.class)); 146 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 147 dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CheckoutAction.class, "ACSD_CheckoutCompleted_Dialog")); 149 if(support!=null && support.isCanceled()) { 150 return; 151 } 152 SwingUtilities.invokeLater(new Runnable () { 153 public void run() { 154 dialog.setVisible(true); 155 } 156 }); 157 } 158 159 public void actionPerformed(ActionEvent e) { 160 Object src = e.getSource(); 161 dialog.setVisible(false); 162 if (panel.openButton.equals(src)) { 163 if (projectToBeOpened == null) { 165 Action a = findAction( "Actions/Project/org-netbeans-modules-project-ui-OpenProject.instance" ); if( null != a ) { 168 a.actionPerformed( e ); 169 } 170 } else { 171 if (projectToBeOpened == null) return; 172 openProject(projectToBeOpened); 173 } 174 175 } else if (panel.createButton.equals(src)) { 176 ProjectUtilities.newProjectWizard(workingFolder); 177 } 178 } 179 180 public static Action findAction( String key ) { 181 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(key); 182 183 if (fo != null && fo.isValid()) { 184 try { 185 DataObject dob = DataObject.find(fo); 186 InstanceCookie ic = (InstanceCookie) dob.getCookie(InstanceCookie.class); 187 188 if (ic != null) { 189 Object instance = ic.instanceCreate(); 190 if (instance instanceof Action ) { 191 Action a = (Action ) instance; 192 return a; 193 } 194 } 195 } catch (Exception e) { 196 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 197 return null; 198 } 199 } 200 return null; 201 } 202 203 private void openProject(Project p) { 204 Project[] projects = new Project[] {p}; 205 OpenProjects.getDefault().open(projects, false); 206 207 ContextAwareAction action = (ContextAwareAction) CommonProjectActions.setAsMainProjectAction(); 209 Lookup ctx = Lookups.singleton(p); 210 Action ctxAction = action.createContextAwareInstance(ctx); 211 ctxAction.actionPerformed(new ActionEvent (this, 0, "")); 212 ProjectUtilities.selectAndExpandProject(p); 213 } 214 } 215 | Popular Tags |