Removed unused ServeAction.
[nbgit.git] / src / org / netbeans / modules / git / ui / clone / CloneCompleted.java
blobb611aac6ef70ff87918e9692417f338f63d36b75
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git.ui.clone;
44 import java.awt.Dialog;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.io.File;
48 import java.io.IOException;
49 import java.util.LinkedList;
50 import java.util.List;
51 import java.util.logging.Level;
52 import javax.swing.BorderFactory;
53 import javax.swing.JFileChooser;
54 import javax.swing.SwingUtilities;
55 import org.netbeans.api.project.Project;
56 import org.netbeans.api.project.ProjectInformation;
57 import org.netbeans.api.project.ProjectManager;
58 import org.netbeans.api.project.ProjectUtils;
59 import org.netbeans.api.project.ui.OpenProjects;
60 import org.netbeans.modules.git.Git;
61 import org.netbeans.modules.git.GitProgressSupport;
62 import org.netbeans.spi.project.ui.support.ProjectChooser;
63 import org.openide.DialogDescriptor;
64 import org.openide.DialogDisplayer;
65 import org.openide.filesystems.FileObject;
66 import org.openide.filesystems.FileUtil;
67 import org.openide.util.HelpCtx;
68 import org.openide.util.NbBundle;
71 /**
73 * @author Tomas Stupka
75 public class CloneCompleted implements ActionListener {
77 private final File workingFolder;
78 private final boolean openProject;
80 private CloneCompletedPanel panel;
81 private Dialog dialog;
82 private Project projectToBeOpened;
84 public CloneCompleted(File workingFolder) {
85 this.openProject = true;
86 this.workingFolder = workingFolder;
89 public void scanForProjects(GitProgressSupport support) {
91 List<Project> clonedProjects = new LinkedList<Project>();
92 File normalizedWorkingFolder = FileUtil.normalizeFile(workingFolder);
93 FileObject fo = FileUtil.toFileObject(normalizedWorkingFolder);
94 if (fo != null) {
95 clonedProjects = ProjectUtilities.scanForProjects(fo);
98 panel = new CloneCompletedPanel();
99 panel.openButton.addActionListener(this);
100 panel.createButton.addActionListener(this);
101 panel.closeButton.addActionListener(this);
102 panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
103 panel.againCheckBox.setVisible(openProject == false);
104 String title = NbBundle.getMessage(CloneAction.class, "BK3008"); // NOI18N
105 DialogDescriptor descriptor = new DialogDescriptor(panel, title);
106 descriptor.setModal(true);
108 // move buttons from dialog to descriptor
109 panel.remove(panel.openButton);
110 panel.remove(panel.createButton);
111 panel.remove(panel.closeButton);
113 Object[] options = null;
114 if (clonedProjects.size() > 1) {
115 String msg = NbBundle.getMessage(CloneAction.class, "BK3009", new Integer(clonedProjects.size())); // NOI18N
116 panel.jLabel1.setText(msg);
117 options = new Object[]{panel.openButton, panel.closeButton};
118 } else if (clonedProjects.size() == 1) {
119 Project project = (Project) clonedProjects.iterator().next();
120 projectToBeOpened = project;
121 ProjectInformation projectInformation = ProjectUtils.getInformation(project);
122 String projectName = projectInformation.getDisplayName();
123 String msg = NbBundle.getMessage(CloneAction.class, "BK3011", projectName); // NOI18N
124 panel.jLabel1.setText(msg);
125 panel.openButton.setText(NbBundle.getMessage(CloneAction.class, "BK3012")); // NOI18N
126 options = new Object[]{panel.openButton, panel.closeButton};
127 } else {
128 String msg = NbBundle.getMessage(CloneAction.class, "BK3010"); // NOI18N
129 panel.jLabel1.setText(msg);
130 options = new Object[]{panel.createButton, panel.closeButton};
133 descriptor.setMessageType(DialogDescriptor.INFORMATION_MESSAGE);
134 descriptor.setOptions(options);
135 descriptor.setClosingOptions(options);
136 descriptor.setHelpCtx(new HelpCtx(CloneCompletedPanel.class));
137 dialog = DialogDisplayer.getDefault().createDialog(descriptor);
138 dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CloneAction.class, "ACSD_CloneCompleted_Dialog")); // NOI18N
139 if (support != null && support.isCanceled()) {
140 return;
142 SwingUtilities.invokeLater(new Runnable() {
144 public void run() {
145 dialog.setVisible(true);
150 public void actionPerformed(ActionEvent e) {
151 Object src = e.getSource();
152 dialog.setVisible(false);
153 if (panel.openButton.equals(src)) {
154 // show project chooser
155 if (projectToBeOpened == null) {
156 JFileChooser chooser = ProjectChooser.projectChooser();
157 chooser.setCurrentDirectory(workingFolder);
158 chooser.setMultiSelectionEnabled(true);
159 chooser.showOpenDialog(dialog);
160 File[] projectDirs = chooser.getSelectedFiles();
161 for (int i = 0; i < projectDirs.length; i++) {
162 File projectDir = projectDirs[i];
163 FileObject projectFolder = FileUtil.toFileObject(projectDir);
164 if (projectFolder != null) {
165 try {
166 if(projectFolder != null){
167 Project p = ProjectManager.getDefault().findProject(projectFolder);
168 openProject(p);
170 } catch (IOException e1) {
171 Throwable cause = new Throwable(NbBundle.getMessage(CloneAction.class, "BK1014", projectFolder));
172 e1.initCause(cause);
173 Git.LOG.log(Level.INFO, null, e1);
177 } else {
178 openProject(projectToBeOpened);
180 } else if (panel.createButton.equals(src)) {
181 ProjectUtilities.newProjectWizard(workingFolder);
185 private void openProject(Project p) {
186 if(p == null) return;
188 Project[] projects = new Project[]{p};
189 OpenProjects.getDefault().open(projects, false);
191 // set as main project and expand
192 OpenProjects.getDefault().setMainProject(p);
193 ProjectUtilities.selectAndExpandProject(p);