KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > checkout > CheckoutCompleted


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.subversion.ui.checkout;
20
21 import java.awt.Dialog JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.io.File JavaDoc;
25 import java.util.LinkedList JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.Action JavaDoc;
28 import javax.swing.BorderFactory JavaDoc;
29 import javax.swing.SwingUtilities JavaDoc;
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 /**
53  *
54  * @author Tomas Stupka
55  */

56 public class CheckoutCompleted implements ActionListener JavaDoc {
57        
58     private final File JavaDoc workingFolder;
59     private final boolean openProject;
60     private String JavaDoc[] checkedOutFolders;
61     
62     private CheckoutCompletedPanel panel;
63     private Dialog JavaDoc dialog;
64     private Project projectToBeOpened;
65
66     public CheckoutCompleted(File JavaDoc workingFolder, String JavaDoc[] 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 JavaDoc<Project> checkedOutProjects = new LinkedList JavaDoc<Project>();
75         File JavaDoc normalizedWorkingFolder = FileUtil.normalizeFile(workingFolder);
76         // checkout creates new folders and cache must be aware of them
77
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 JavaDoc module = checkedOutFolders[i];
85                 if (".".equals(module)) { // NOI18N
86
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 JavaDoc title = NbBundle.getMessage(CheckoutAction.class, "BK3008"); // NOI18N
104
DialogDescriptor descriptor = new DialogDescriptor(panel, title);
105         descriptor.setModal(true);
106
107         // move buttons from dialog to descriptor
108
panel.remove(panel.openButton);
109         panel.remove(panel.createButton);
110         panel.remove(panel.closeButton);
111
112         Object JavaDoc[] options = null;
113         if (checkedOutProjects.size() > 1) {
114             String JavaDoc msg = NbBundle.getMessage(CheckoutAction.class, "BK3009", new Integer JavaDoc(checkedOutProjects.size())); // NOI18N
115
panel.jLabel1.setText(msg);
116             options = new Object JavaDoc[] {
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 JavaDoc projectName = projectInformation.getDisplayName();
125             String JavaDoc msg = NbBundle.getMessage(CheckoutAction.class, "BK3011", projectName); // NOI18N
126
panel.jLabel1.setText(msg);
127             panel.openButton.setText(NbBundle.getMessage(CheckoutAction.class, "BK3012")); // NOI18N
128
options = new Object JavaDoc[] {
129                 panel.openButton,
130                 panel.closeButton
131             };
132         } else {
133             String JavaDoc msg = NbBundle.getMessage(CheckoutAction.class, "BK3010"); // NOI18N
134
panel.jLabel1.setText(msg);
135             options = new Object JavaDoc[] {
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")); // NOI18N
148

149         if(support!=null && support.isCanceled()) {
150             return;
151         }
152         SwingUtilities.invokeLater(new Runnable JavaDoc() {
153             public void run() {
154                 dialog.setVisible(true);
155             }
156         });
157     }
158     
159     public void actionPerformed(ActionEvent JavaDoc e) {
160         Object JavaDoc src = e.getSource();
161         dialog.setVisible(false);
162         if (panel.openButton.equals(src)) {
163             // show project chooser
164
if (projectToBeOpened == null) {
165                 // et tu, svn? (see #77438)
166
Action JavaDoc a = findAction( "Actions/Project/org-netbeans-modules-project-ui-OpenProject.instance" ); // NOI18N
167
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 JavaDoc findAction( String JavaDoc 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 JavaDoc instance = ic.instanceCreate();
190                     if (instance instanceof Action JavaDoc) {
191                         Action JavaDoc a = (Action JavaDoc) instance;
192                         return a;
193                     }
194                 }
195             } catch (Exception JavaDoc 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         // set as main project and expand
208
ContextAwareAction action = (ContextAwareAction) CommonProjectActions.setAsMainProjectAction();
209         Lookup ctx = Lookups.singleton(p);
210         Action JavaDoc ctxAction = action.createContextAwareInstance(ctx);
211         ctxAction.actionPerformed(new ActionEvent JavaDoc(this, 0, ""));
212         ProjectUtilities.selectAndExpandProject(p);
213     }
214 }
215
Popular Tags