001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.subversion.ui.checkout;
042:
043: import java.awt.Dialog;
044: import java.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046: import java.io.File;
047: import java.io.IOException;
048: import java.util.LinkedList;
049: import java.util.List;
050: import java.util.logging.Level;
051: import javax.swing.BorderFactory;
052: import javax.swing.JFileChooser;
053: import javax.swing.SwingUtilities;
054: import org.netbeans.api.project.Project;
055: import org.netbeans.api.project.ProjectInformation;
056: import org.netbeans.api.project.ProjectManager;
057: import org.netbeans.api.project.ProjectUtils;
058: import org.netbeans.api.project.ui.OpenProjects;
059: import org.netbeans.modules.subversion.Subversion;
060: import org.netbeans.modules.subversion.client.SvnProgressSupport;
061: import org.netbeans.modules.subversion.util.SvnUtils;
062: import org.netbeans.spi.project.ui.support.ProjectChooser;
063: import org.openide.DialogDescriptor;
064: import org.openide.DialogDisplayer;
065: import org.openide.filesystems.FileObject;
066: import org.openide.filesystems.FileUtil;
067: import org.openide.util.HelpCtx;
068: import org.openide.util.NbBundle;
069:
070: /**
071: *
072: * @author Tomas Stupka
073: */
074: public class CheckoutCompleted implements ActionListener {
075:
076: private final File workingFolder;
077: private final boolean openProject;
078: private String[] checkedOutFolders;
079:
080: private CheckoutCompletedPanel panel;
081: private Dialog dialog;
082: private Project projectToBeOpened;
083:
084: public CheckoutCompleted(File workingFolder,
085: String[] checkedOutFolders, boolean openProject) {
086: this .openProject = openProject;
087: this .checkedOutFolders = checkedOutFolders;
088: this .workingFolder = workingFolder;
089: }
090:
091: public void scanForProjects(SvnProgressSupport support) {
092:
093: List<Project> checkedOutProjects = new LinkedList<Project>();
094: File normalizedWorkingFolder = FileUtil
095: .normalizeFile(workingFolder);
096: // checkout creates new folders and cache must be aware of them
097: SvnUtils.refreshParents(normalizedWorkingFolder);
098: FileObject fo = FileUtil.toFileObject(normalizedWorkingFolder);
099: if (fo != null) {
100: for (int i = 0; i < checkedOutFolders.length; i++) {
101: if (support != null && support.isCanceled()) {
102: return;
103: }
104: String module = checkedOutFolders[i];
105: if (".".equals(module)) { // NOI18N
106: checkedOutProjects = ProjectUtilities
107: .scanForProjects(fo);
108: break;
109: } else {
110: FileObject subfolder = fo.getFileObject(module);
111: if (subfolder != null) {
112: checkedOutProjects.addAll(ProjectUtilities
113: .scanForProjects(subfolder));
114: }
115: }
116: }
117: }
118:
119: panel = new CheckoutCompletedPanel();
120: panel.openButton.addActionListener(this );
121: panel.createButton.addActionListener(this );
122: panel.closeButton.addActionListener(this );
123: panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
124: panel.againCheckBox.setVisible(openProject == false);
125: String title = NbBundle.getMessage(CheckoutAction.class,
126: "BK3008"); // NOI18N
127: DialogDescriptor descriptor = new DialogDescriptor(panel, title);
128: descriptor.setModal(true);
129:
130: // move buttons from dialog to descriptor
131: panel.remove(panel.openButton);
132: panel.remove(panel.createButton);
133: panel.remove(panel.closeButton);
134:
135: Object[] options = null;
136: if (checkedOutProjects.size() > 1) {
137: String msg = NbBundle.getMessage(CheckoutAction.class,
138: "BK3009", new Integer(checkedOutProjects.size())); // NOI18N
139: panel.jLabel1.setText(msg);
140: options = new Object[] { panel.openButton,
141: panel.closeButton };
142: } else if (checkedOutProjects.size() == 1) {
143: Project project = (Project) checkedOutProjects.iterator()
144: .next();
145: projectToBeOpened = project;
146: ProjectInformation projectInformation = ProjectUtils
147: .getInformation(project);
148: String projectName = projectInformation.getDisplayName();
149: String msg = NbBundle.getMessage(CheckoutAction.class,
150: "BK3011", projectName); // NOI18N
151: panel.jLabel1.setText(msg);
152: panel.openButton.setText(NbBundle.getMessage(
153: CheckoutAction.class, "BK3012")); // NOI18N
154: options = new Object[] { panel.openButton,
155: panel.closeButton };
156: } else {
157: String msg = NbBundle.getMessage(CheckoutAction.class,
158: "BK3010"); // NOI18N
159: panel.jLabel1.setText(msg);
160: options = new Object[] { panel.createButton,
161: panel.closeButton };
162: }
163:
164: descriptor.setMessageType(DialogDescriptor.INFORMATION_MESSAGE);
165: descriptor.setOptions(options);
166: descriptor.setClosingOptions(options);
167: descriptor
168: .setHelpCtx(new HelpCtx(CheckoutCompletedPanel.class));
169: dialog = DialogDisplayer.getDefault().createDialog(descriptor);
170: dialog.getAccessibleContext().setAccessibleDescription(
171: NbBundle.getMessage(CheckoutAction.class,
172: "ACSD_CheckoutCompleted_Dialog")); // NOI18N
173: if (support != null && support.isCanceled()) {
174: return;
175: }
176: SwingUtilities.invokeLater(new Runnable() {
177:
178: public void run() {
179: dialog.setVisible(true);
180: }
181: });
182: }
183:
184: public void actionPerformed(ActionEvent e) {
185: Object src = e.getSource();
186: dialog.setVisible(false);
187: if (panel.openButton.equals(src)) {
188: // show project chooser
189: if (projectToBeOpened == null) {
190: JFileChooser chooser = ProjectChooser.projectChooser();
191: chooser.setCurrentDirectory(workingFolder);
192: chooser.setMultiSelectionEnabled(true);
193: chooser.showOpenDialog(dialog);
194: File[] projectDirs = chooser.getSelectedFiles();
195: for (int i = 0; i < projectDirs.length; i++) {
196: File projectDir = projectDirs[i];
197: FileObject projectFolder = FileUtil
198: .toFileObject(projectDir);
199: if (projectFolder != null) {
200: try {
201: Project p = ProjectManager.getDefault()
202: .findProject(projectFolder);
203: if (p != null) {
204: openProject(p);
205: }
206: } catch (IOException e1) {
207: Subversion.LOG.log(Level.SEVERE, NbBundle
208: .getMessage(CheckoutAction.class,
209: "BK1014", projectFolder),
210: e1); // NOI18N
211: }
212: }
213: }
214: } else {
215: if (projectToBeOpened == null) {
216: return;
217: }
218: openProject(projectToBeOpened);
219: }
220: } else if (panel.createButton.equals(src)) {
221: ProjectUtilities.newProjectWizard(workingFolder);
222: }
223: }
224:
225: private void openProject(Project p) {
226: Project[] projects = new Project[] { p };
227: OpenProjects.getDefault().open(projects, false);
228:
229: // set as main project and expand
230: OpenProjects.getDefault().setMainProject(p);
231: ProjectUtilities.selectAndExpandProject(p);
232: }
233: }
|