# HG changeset patch # Parent 34119008b8dbe0c65593234436739979151a1fe1 # User Ondrej Vrabec listening on connect/disconnect actions diff --git a/git/src/org/netbeans/modules/git/Annotator.java b/git/src/org/netbeans/modules/git/Annotator.java --- a/git/src/org/netbeans/modules/git/Annotator.java +++ b/git/src/org/netbeans/modules/git/Annotator.java @@ -63,6 +63,8 @@ import org.netbeans.libs.git.GitTag; import org.netbeans.modules.git.FileInformation.Status; import org.netbeans.modules.git.ui.actions.AddAction; +import org.netbeans.modules.git.ui.actions.ConnectAction; +import org.netbeans.modules.git.ui.actions.DisconnectAction; import org.netbeans.modules.git.ui.blame.AnnotateAction; import org.netbeans.modules.git.ui.commit.CommitAction; import org.netbeans.modules.git.ui.commit.ExcludeFromCommitAction; @@ -135,9 +137,15 @@ if (destination.equals(ActionDestination.MainMenu)) { if (noneVersioned) { addAction("org-netbeans-modules-git-ui-clone-CloneAction", context, actions, true); - addAction("org-netbeans-modules-git-ui-init-InitAction", context, actions, true); + ConnectAction connectAction = SystemAction.get(ConnectAction.class); + if (!connectAction.isEnabled()) { + addAction("org-netbeans-modules-git-ui-init-InitAction", context, actions, true); + } actions.add(null); actions.add(SystemAction.get(RepositoryBrowserAction.class)); + if (connectAction.isEnabled()) { + actions.add(connectAction); + } } else { actions.add(SystemAction.get(StatusAction.class)); actions.add(SystemAction.get(AddAction.class)); @@ -164,8 +172,6 @@ } } actions.add(null); - actions.add(SystemAction.get(RepositoryBrowserAction.class)); - actions.add(null); actions.add(new BranchMenu(ActionDestination.MainMenu, null)); actions.add(new TagMenu(ActionDestination.MainMenu, null)); actions.add(new CheckoutMenu(ActionDestination.MainMenu, null)); @@ -182,6 +188,16 @@ actions.add(new RemoteMenu(ActionDestination.MainMenu, null)); actions.add(SystemAction.get(SearchHistoryAction.class)); actions.add(SystemAction.get(AnnotateAction.class)); + actions.add(null); + actions.add(SystemAction.get(RepositoryBrowserAction.class)); + ConnectAction connectAction = SystemAction.get(ConnectAction.class); + if (connectAction.isEnabled()) { + actions.add(connectAction); + } + } + DisconnectAction disconnectAction = SystemAction.get(DisconnectAction.class); + if (disconnectAction.isEnabled()) { + actions.add(disconnectAction); } Utils.setAcceleratorBindings(ACTIONS_PATH_PREFIX, actions.toArray(new Action[actions.size()])); } else { diff --git a/git/src/org/netbeans/modules/git/Bundle.properties b/git/src/org/netbeans/modules/git/Bundle.properties --- a/git/src/org/netbeans/modules/git/Bundle.properties +++ b/git/src/org/netbeans/modules/git/Bundle.properties @@ -87,4 +87,4 @@ the IDE had to disable all third-party Git version control plugins. LBL_LookingUp=Looking up moved file... -LBL_LookingUpAtRevision=Looking up moved file {0} at revision {1} \ No newline at end of file +LBL_LookingUpAtRevision=Looking up moved file {0} at revision {1} diff --git a/git/src/org/netbeans/modules/git/Git.java b/git/src/org/netbeans/modules/git/Git.java --- a/git/src/org/netbeans/modules/git/Git.java +++ b/git/src/org/netbeans/modules/git/Git.java @@ -61,17 +61,21 @@ import org.netbeans.libs.git.GitException; import org.netbeans.modules.git.client.CredentialsCallback; import org.netbeans.modules.git.client.GitClient; +import org.netbeans.modules.git.ui.actions.ConnectAction; +import org.netbeans.modules.git.ui.actions.DisconnectAction; import org.netbeans.modules.git.ui.shelve.ShelveChangesAction; import org.netbeans.modules.git.utils.GitUtils; import org.netbeans.modules.versioning.shelve.ShelveChangesActionsRegistry; import org.netbeans.modules.versioning.spi.VCSAnnotator; import org.netbeans.modules.versioning.spi.VersioningSupport; +import org.netbeans.modules.versioning.util.DisconnectedRepositoriesManager; import org.netbeans.modules.versioning.util.RootsToFile; import org.netbeans.modules.versioning.util.Utils; import org.netbeans.modules.versioning.util.VCSHyperlinkProvider; import org.openide.util.Lookup; import org.openide.util.Lookup.Result; import org.openide.util.RequestProcessor; +import org.openide.util.actions.SystemAction; /** * @@ -139,6 +143,8 @@ @Override public void run () { ShelveChangesActionsRegistry.getInstance().registerAction(gitVCS, ShelveChangesAction.getProvider()); + DisconnectedRepositoriesManager.getInstance().addPropertyChangeListener(SystemAction.get(ConnectAction.class)); + DisconnectedRepositoriesManager.getInstance().addPropertyChangeListener(SystemAction.get(DisconnectAction.class)); } }); } @@ -306,7 +312,11 @@ File parent = getKnownParent(file); if(parent != null) { LOG.log(Level.FINE, " getTopmostManagedParent returning known parent {0}", parent); - return parent; + if (DisconnectedRepositoriesManager.getInstance().isDisconnected(Git.class.getName(), parent.getAbsolutePath())) { + return null; + } else { + return parent; + } } if (GitUtils.isPartOfGitMetadata(file)) { @@ -329,6 +339,7 @@ LOG.log(Level.FINE, " found managed parent {0}", new Object[] { file }); done.clear(); // all folders added before must be removed, they ARE in fact managed by git topmost = file; + addRepository(topmost); if (topmost.getParentFile() == null) { LOG.log(Level.WARNING, "found managed root folder {0}", file); //NOI18N } @@ -348,6 +359,9 @@ } if(topmost != null) { knownRoots.add(topmost); + if (DisconnectedRepositoriesManager.getInstance().isDisconnected(Git.class.getName(), topmost.getAbsolutePath())) { + topmost = null; + } } return topmost; @@ -396,4 +410,13 @@ } return historyProvider; } + + private void addRepository (final File repository) { + getRequestProcessor().post(new Runnable() { + @Override + public void run () { + GitRepositories.getInstance().add(repository); + } + }); + } } diff --git a/git/src/org/netbeans/modules/git/GitRepositories.java b/git/src/org/netbeans/modules/git/GitRepositories.java --- a/git/src/org/netbeans/modules/git/GitRepositories.java +++ b/git/src/org/netbeans/modules/git/GitRepositories.java @@ -66,6 +66,9 @@ return instance; } + private GitRepositories () { + } + void add (File repository) { boolean added; if (Utils.isAncestorOrEqual(new File(System.getProperty("java.io.tmpdir")), repository)) { //NOI18N diff --git a/git/src/org/netbeans/modules/git/options/Bundle.properties b/git/src/org/netbeans/modules/git/options/Bundle.properties --- a/git/src/org/netbeans/modules/git/options/Bundle.properties +++ b/git/src/org/netbeans/modules/git/options/Bundle.properties @@ -54,3 +54,4 @@ #Files ignored by NetBeans (as dist or build folder) will be automatically ignored in .gitignore file GitOptionsPanel.cbIgnoreNotSharableFiles.text=Permanently i&gnore non-sharable folders KW_Colors=colors +GitOptionsPanel.jLabel1.text=Disconnected Repositories diff --git a/git/src/org/netbeans/modules/git/options/GitOptionsPanel.form b/git/src/org/netbeans/modules/git/options/GitOptionsPanel.form --- a/git/src/org/netbeans/modules/git/options/GitOptionsPanel.form +++ b/git/src/org/netbeans/modules/git/options/GitOptionsPanel.form @@ -17,16 +17,30 @@ - + - + + + + + - - - + + + + + + + + + + + + + - + @@ -43,6 +57,18 @@ + + + + + + + + + + + + @@ -88,6 +114,7 @@ + @@ -103,5 +130,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/git/src/org/netbeans/modules/git/options/GitOptionsPanel.java b/git/src/org/netbeans/modules/git/options/GitOptionsPanel.java --- a/git/src/org/netbeans/modules/git/options/GitOptionsPanel.java +++ b/git/src/org/netbeans/modules/git/options/GitOptionsPanel.java @@ -48,19 +48,25 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import javax.swing.GroupLayout; import org.netbeans.api.options.OptionsDisplayer; import org.netbeans.modules.git.GitModuleConfig; +import org.netbeans.modules.git.GitVCS; +import org.netbeans.modules.versioning.util.DisconnectedRepositoriesManager; import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.NbBundle; -@OptionsPanelController.Keywords(keywords={"git", "#GitOptionsPanel.kw1", "#GitOptionsPanel.kw2", "#GitOptionsPanel.kw3", "#GitOptionsPanel.kw4"}, +@OptionsPanelController.Keywords(keywords={"git", "#GitOptionsPanel.kw1", + "#GitOptionsPanel.kw2", "#GitOptionsPanel.kw3", "#GitOptionsPanel.kw4", + "#GitOptionsPanel.kw5"}, location=OptionsDisplayer.ADVANCED, tabTitle="#CTL_OptionsPanel.title") @NbBundle.Messages({ "CTL_OptionsPanel.title=Versioning", "GitOptionsPanel.kw1=versioning", "GitOptionsPanel.kw2=exclude new files from commit", "GitOptionsPanel.kw3=signed-off-by line", - "GitOptionsPanel.kw4=non-sharable folders" + "GitOptionsPanel.kw4=non-sharable folders", + "GitOptionsPanel.kw5=disconnected repositories" }) final class GitOptionsPanel extends javax.swing.JPanel { @@ -68,7 +74,7 @@ private String[] keywords; GitOptionsPanel(GitOptionsPanelController controller) { - this.controller = controller; + this.controller = controller; initComponents(); } @@ -106,6 +112,10 @@ cbOpenOutputWindow = new javax.swing.JCheckBox(); excludeNewFiles = new javax.swing.JCheckBox(); cbIgnoreNotSharableFiles = new javax.swing.JCheckBox(); + jLabel1 = new javax.swing.JLabel(); + jSeparator1 = new javax.swing.JSeparator(); + jPanel1 = new javax.swing.JPanel(); + jPanel2 = new javax.swing.JPanel(); cbOpenOutputWindow.setSelected(true); org.openide.awt.Mnemonics.setLocalizedText(cbOpenOutputWindow, org.openide.util.NbBundle.getMessage(GitOptionsPanel.class, "GitOptionsPanel.cbOpenOutputWindow.text")); // NOI18N @@ -115,10 +125,41 @@ excludeNewFiles.setToolTipText(org.openide.util.NbBundle.getMessage(GitOptionsPanel.class, "GitOptionsPanel.excludeNewFiles.toolTipText")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(signOffCheckBox, org.openide.util.NbBundle.getMessage(GitOptionsPanel.class, "GitOptionsPanel.signOffCheckBox.text")); // NOI18N + signOffCheckBox.setVerticalTextPosition(javax.swing.SwingConstants.TOP); org.openide.awt.Mnemonics.setLocalizedText(cbIgnoreNotSharableFiles, org.openide.util.NbBundle.getMessage(GitOptionsPanel.class, "GitOptionsPanel.cbIgnoreNotSharableFiles.text")); // NOI18N cbIgnoreNotSharableFiles.setToolTipText(org.openide.util.NbBundle.getMessage(GitOptionsPanel.class, "GitOptionsPanel.cbIgnoreNotSharableFiles.toolTipText")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(GitOptionsPanel.class, "GitOptionsPanel.jLabel1.text")); // NOI18N + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 0, Short.MAX_VALUE) + ); + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 100, Short.MAX_VALUE) + ); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(0, 0, 0) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(0, 0, 0)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(0, 0, 0) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(0, 0, 0)) + ); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -126,13 +167,23 @@ .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(signOffCheckBox) + .addGroup(layout.createSequentialGroup() + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + .addComponent(signOffCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(excludeNewFiles) - .addComponent(cbOpenOutputWindow) - .addComponent(cbIgnoreNotSharableFiles)) - .addGap(0, 0, Short.MAX_VALUE)))) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSeparator1)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(excludeNewFiles) + .addComponent(cbOpenOutputWindow) + .addComponent(cbIgnoreNotSharableFiles)) + .addGap(0, 0, Short.MAX_VALUE))) + .addGap(12, 12, 12)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -145,6 +196,15 @@ .addComponent(signOffCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(cbIgnoreNotSharableFiles) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(18, 18, 18) + .addComponent(jLabel1)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(31, 31, 31) + .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -158,6 +218,8 @@ excludeNewFiles.setSelected(GitModuleConfig.getDefault().getExludeNewFiles()); signOffCheckBox.setSelected(GitModuleConfig.getDefault().getSignOff()); cbIgnoreNotSharableFiles.setSelected(GitModuleConfig.getDefault().getAutoIgnoreFiles()); + ((GroupLayout) jPanel1.getLayout()).replace(jPanel1.getComponent(0), + DisconnectedRepositoriesManager.getInstance().getOptionsPanel(GitVCS.class.getName())); } void store() { @@ -175,6 +237,10 @@ private javax.swing.JCheckBox cbIgnoreNotSharableFiles; private javax.swing.JCheckBox cbOpenOutputWindow; private javax.swing.JCheckBox excludeNewFiles; + private javax.swing.JLabel jLabel1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JSeparator jSeparator1; final javax.swing.JCheckBox signOffCheckBox = new javax.swing.JCheckBox(); // End of variables declaration//GEN-END:variables diff --git a/git/src/org/netbeans/modules/git/ui/actions/Bundle.properties b/git/src/org/netbeans/modules/git/ui/actions/Bundle.properties --- a/git/src/org/netbeans/modules/git/ui/actions/Bundle.properties +++ b/git/src/org/netbeans/modules/git/ui/actions/Bundle.properties @@ -39,7 +39,12 @@ # Portions Copyrighted 2010 Sun Microsystems, Inc. LBL_Progress.RefreshingStatuses=Refreshing file statuses -#StatusAction +#AddAction LBL_AddAction_Name = &Add LBL_AddAction.popupName = Add -LBL_AddProgress = Git Add \ No newline at end of file +LBL_AddProgress = Git Add +#DisconnectAction +LBL_DisconnectAction_Name = Disconnect +#ConnectAction +LBL_ConnectAction_Name = Connect +LBL_ConnectAction_Name.popupName = Connect to Git diff --git a/git/src/org/netbeans/modules/git/ui/actions/ConnectAction.java b/git/src/org/netbeans/modules/git/ui/actions/ConnectAction.java new file mode 100644 --- /dev/null +++ b/git/src/org/netbeans/modules/git/ui/actions/ConnectAction.java @@ -0,0 +1,96 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.git.ui.actions; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import org.netbeans.modules.git.Git; +import org.netbeans.modules.git.GitVCS; +import org.netbeans.modules.versioning.spi.VCSContext; +import org.netbeans.modules.git.utils.GitUtils; +import org.netbeans.modules.versioning.util.DisconnectedRepositoriesManager; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.nodes.Node; + +@ActionID(id = "org.netbeans.modules.git.ui.actions.ConnectAction", category = "Git") +@ActionRegistration(displayName = "#LBL_ConnectAction_Name") +public class ConnectAction extends GitAction implements PropertyChangeListener { + + @Override + protected boolean enable (Node[] nodes) { + VCSContext context = getCurrentContext(nodes); + return isDisconnected(context); + } + + @Override + protected void performContextAction (Node[] nodes) { + VCSContext context = getCurrentContext(nodes); + if (isDisconnected(context)) { + File root = context.getRootFiles().iterator().next(); + File repository = Git.getInstance().getRepositoryRoot(root); + DisconnectedRepositoriesManager.getInstance().connectRepository( + GitVCS.class.getName(), repository.getAbsolutePath()); + } + } + + void refreshEnabled () { + setEnabled(false); + } + + private boolean isDisconnected (VCSContext context) { + return context.getRootFiles().size() == 1 && GitUtils.isFromGitRepository(context) + && DisconnectedRepositoriesManager.getInstance().isDisconnected( + GitVCS.class.getName(), context.getRootFiles().iterator().next().getAbsolutePath()); + } + + @Override + public void propertyChange (PropertyChangeEvent evt) { + if (DisconnectedRepositoriesManager.PROP_CONNECTED_ROOTS_CHANGED.equals(evt.getPropertyName())) { + refreshEnabled(); + } + } + +} diff --git a/git/src/org/netbeans/modules/git/ui/actions/DisconnectAction.java b/git/src/org/netbeans/modules/git/ui/actions/DisconnectAction.java new file mode 100644 --- /dev/null +++ b/git/src/org/netbeans/modules/git/ui/actions/DisconnectAction.java @@ -0,0 +1,113 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.git.ui.actions; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import org.netbeans.modules.git.Git; +import org.netbeans.modules.git.GitVCS; +import org.netbeans.modules.versioning.spi.VCSContext; +import org.netbeans.modules.git.utils.GitUtils; +import org.netbeans.modules.versioning.util.DisconnectedRepositoriesManager; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; + +@ActionID(id = "org.netbeans.modules.git.ui.actions.DisconnectAction", category = "Git") +@ActionRegistration(displayName = "#LBL_DisconnectAction_Name") +public class DisconnectAction extends GitAction implements PropertyChangeListener { + + @Override + protected boolean enable (Node[] nodes) { + VCSContext context = getCurrentContext(nodes); + return isConnected(context); + } + + @Override + @NbBundle.Messages({ + "# {0} - repository root name", + "MSG_DisconnectAction.confirmation.text=Do you want to disconnect {0} from Git?\n" + + "The folder will no longer be controlled by Git in the IDE.\n\n" + + "You will be able to reconnect the folder to the system\n" + + "with the Connect action available from the Main menu.", + "LBL_DisconnectAction.confirmation.title=Disconnect From Git" + }) + protected void performContextAction (Node[] nodes) { + VCSContext context = getCurrentContext(nodes); + if (isConnected(context)) { + File root = context.getRootFiles().iterator().next(); + File repository = Git.getInstance().getRepositoryRoot(root); + NotifyDescriptor nd = new NotifyDescriptor.Confirmation( + Bundle.MSG_DisconnectAction_confirmation_text(repository.getName()), + Bundle.LBL_DisconnectAction_confirmation_title(), + NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE); + if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) { + DisconnectedRepositoriesManager.getInstance().disconnectRepository( + GitVCS.class.getName(), repository.getAbsolutePath()); + } + } + } + + void refreshEnabled () { + setEnabled(false); + } + + private boolean isConnected (VCSContext context) { + return context.getRootFiles().size() == 1 && GitUtils.isFromGitRepository(context) + && !DisconnectedRepositoriesManager.getInstance().isDisconnected( + GitVCS.class.getName(), context.getRootFiles().iterator().next().getAbsolutePath()); + } + + @Override + public void propertyChange (PropertyChangeEvent evt) { + if (DisconnectedRepositoriesManager.PROP_CONNECTED_ROOTS_CHANGED.equals(evt.getPropertyName())) { + refreshEnabled(); + } + } + +} diff --git a/git/src/org/netbeans/modules/git/ui/repository/RepositoryBrowserPanel.java b/git/src/org/netbeans/modules/git/ui/repository/RepositoryBrowserPanel.java --- a/git/src/org/netbeans/modules/git/ui/repository/RepositoryBrowserPanel.java +++ b/git/src/org/netbeans/modules/git/ui/repository/RepositoryBrowserPanel.java @@ -85,6 +85,7 @@ import org.netbeans.libs.git.SearchCriteria; import org.netbeans.modules.git.Git; import org.netbeans.modules.git.GitRepositories; +import org.netbeans.modules.git.GitVCS; import org.netbeans.modules.git.client.GitProgressSupport; import org.netbeans.modules.git.ui.branch.CreateBranchAction; import org.netbeans.modules.git.ui.branch.DeleteBranchAction; @@ -95,6 +96,7 @@ import org.netbeans.modules.git.ui.tag.CreateTagAction; import org.netbeans.modules.git.ui.tag.ManageTagsAction; import org.netbeans.modules.git.utils.GitUtils; +import org.netbeans.modules.versioning.util.DisconnectedRepositoriesManager; import org.netbeans.modules.versioning.util.Utils; import org.openide.explorer.ExplorerManager; import org.openide.explorer.ExplorerManager.Provider; @@ -396,28 +398,30 @@ @Override @SuppressWarnings("unchecked") public void propertyChange (PropertyChangeEvent evt) { - final Set oldValues = (Set) evt.getOldValue(); - final Set newValues = (Set) evt.getNewValue(); - if (oldValues.size() > newValues.size()) { - oldValues.removeAll(newValues); - removeAll(oldValues); - } else if (oldValues.size() < newValues.size()) { - newValues.removeAll(oldValues); - RP.post(new Runnable () { - @Override - public void run () { - java.util.Map nodes = new HashMap(); - for (File r : newValues) { - RepositoryInfo info = RepositoryInfo.getInstance(r); - if (info == null) { - LOG.log(Level.INFO, "RepositoriesChildren.propertyChange() : Null info for {0}", r); //NOI18N - } else { - nodes.put(r, new RepositoryNode(r, info)); + if (GitRepositories.PROP_REPOSITORIES.equals(evt.getPropertyName())) { + final Set oldValues = (Set) evt.getOldValue(); + final Set newValues = (Set) evt.getNewValue(); + if (oldValues.size() > newValues.size()) { + oldValues.removeAll(newValues); + removeAll(oldValues); + } else if (oldValues.size() < newValues.size()) { + newValues.removeAll(oldValues); + RP.post(new Runnable () { + @Override + public void run () { + java.util.Map nodes = new HashMap(); + for (File r : newValues) { + RepositoryInfo info = RepositoryInfo.getInstance(r); + if (info == null) { + LOG.log(Level.INFO, "RepositoriesChildren.propertyChange() : Null info for {0}", r); //NOI18N + } else { + nodes.put(r, new RepositoryNode(r, info)); + } } + putAll(nodes); } - putAll(nodes); - } - }); + }); + } } } }, GitRepositories.getInstance())); @@ -435,8 +439,8 @@ } private class RepositoryNode extends RepositoryBrowserNode implements PropertyChangeListener { - private PropertyChangeListener list; private final File repository; + private boolean disconnected; public RepositoryNode (final File repository, RepositoryInfo info) { super(new RepositoryChildren(), repository); @@ -452,14 +456,16 @@ LOG.log(Level.INFO, "RepositoryNode() : Null info for {0}", repository); //NOI18N } else { setName(info); - info.addPropertyChangeListener(list = WeakListeners.propertyChange(RepositoryNode.this, info)); + info.addPropertyChangeListener(WeakListeners.propertyChange(RepositoryNode.this, info)); } } }); } else { setName(info); - info.addPropertyChangeListener(list = WeakListeners.propertyChange(this, info)); + info.addPropertyChangeListener(WeakListeners.propertyChange(this, info)); } + DisconnectedRepositoriesManager.getInstance().addPropertyChangeListener( + WeakListeners.propertyChange(this, DisconnectedRepositoriesManager.getInstance())); } private void setName (RepositoryInfo info) { @@ -501,6 +507,12 @@ public void propertyChange (PropertyChangeEvent evt) { if (evt.getSource() instanceof RepositoryInfo) { setName((RepositoryInfo) evt.getSource()); + } else if (DisconnectedRepositoriesManager.PROP_CONNECTED_ROOTS_CHANGED.equals(evt.getPropertyName()) + && repository.getAbsolutePath().equals(evt.getNewValue())) { + if (disconnected != DisconnectedRepositoriesManager.getInstance().isDisconnected( + GitVCS.class.getName(), repository.getAbsolutePath())) { + setDisconnected(!disconnected); + } } } @@ -524,6 +536,11 @@ public String getShortDescription () { return repository.getAbsolutePath(); } + + private void setDisconnected (boolean b) { + this.disconnected = b; + ((RepositoryChildren) getChildren()).refreshKeys(true); + } } private class RepositoryChildren extends Children.Keys { @@ -533,20 +550,7 @@ @Override protected void addNotify () { super.addNotify(); - if (!initialized) { - initialized = true; - List keys = new LinkedList(); - if (options.contains(Option.DISPLAY_BRANCHES_LOCAL) || options.contains(Option.DISPLAY_BRANCHES_REMOTE)) { - keys.add(new BranchesTopNode(((RepositoryNode) getNode()).getRepository())); - } - if (options.contains(Option.DISPLAY_TAGS)) { - keys.add(new TagsNode(((RepositoryNode) getNode()).getRepository())); - } - if (options.contains(Option.DISPLAY_REMOTES)) { - keys.add(new RemotesNode(((RepositoryNode) getNode()).getRepository())); - } - setKeys(keys); - } + refreshKeys(false); } @Override @@ -560,6 +564,25 @@ return new Node[] { key }; } + private void refreshKeys (boolean force) { + if (force || !initialized) { + initialized = true; + List keys = new LinkedList(); + if (!((RepositoryNode) getNode()).disconnected) { + if (options.contains(Option.DISPLAY_BRANCHES_LOCAL) || options.contains(Option.DISPLAY_BRANCHES_REMOTE)) { + keys.add(new BranchesTopNode(((RepositoryNode) getNode()).getRepository())); + } + if (options.contains(Option.DISPLAY_TAGS)) { + keys.add(new TagsNode(((RepositoryNode) getNode()).getRepository())); + } + if (options.contains(Option.DISPLAY_REMOTES)) { + keys.add(new RemotesNode(((RepositoryNode) getNode()).getRepository())); + } + } + setKeys(keys); + } + } + } // diff --git a/versioning.core/src/org/netbeans/modules/versioning/core/Bundle.properties b/versioning.core/src/org/netbeans/modules/versioning/core/Bundle.properties --- a/versioning.core/src/org/netbeans/modules/versioning/core/Bundle.properties +++ b/versioning.core/src/org/netbeans/modules/versioning/core/Bundle.properties @@ -54,14 +54,6 @@ CTL_MenuItem_LocalHistory=Local History CTL_MenuItem_Initializing=Initializing... -CTL_DisconnectAction.name=Dis&connect... -CTL_ConnectAction.name=&Connect -CTL_ConnectAction.name.vcs=Connect To {0} -LBL_ConnectAction.confirmation.title=Disconnect From Version Control System -MSG_ConnectAction.confirmation.text=Do you want to disconnect {0} from {1}?\n\ -The folder will no longer be controlled by {1} in the IDE.\n\n\ -You will be able to reconnect the folder to the system\n\ -with the Connect action available from the Main menu. LBL_NoneAvailable=None available CTL_LocalHistoryMenuName=History CTL_LocalHistoryMenuNameLoc=&History \ No newline at end of file diff --git a/versioning.core/src/org/netbeans/modules/versioning/core/ProjectMenuItem.java b/versioning.core/src/org/netbeans/modules/versioning/core/ProjectMenuItem.java --- a/versioning.core/src/org/netbeans/modules/versioning/core/ProjectMenuItem.java +++ b/versioning.core/src/org/netbeans/modules/versioning/core/ProjectMenuItem.java @@ -151,26 +151,12 @@ private Action [] createVersioningSystemActions (VersioningSystem vs, Node[] nodes, boolean displayConnectAction) { VCSContext ctx = VCSContext.forNodes(nodes); Action [] actions = null; - if (displayConnectAction && ctx.getRootFiles().size() == 1) { - // we have only one root. If it's disconnected, display only the Connect action instead of other actions (import, init etc. do not make sense) - VCSFileProxy root = vs.getTopmostManagedAncestor(ctx.getRootFiles().iterator().next()); - if (root != null) { - if (VersioningConfig.getDefault().isDisconnected(vs, root)) { - // repository is indeed disconnected, display only Connect action - String displayName = vs.getMenuLabel(); - actions = new Action[] { new VersioningMainMenu.ConnectAction(vs, root, NbBundle.getMessage(ProjectMenuItem.class, "CTL_ConnectAction.name.vcs", displayName)) }; //NOI18N - } - } - } - if (actions == null) { - // repository is connected or the context not yet versioned - if (vs instanceof DelegatingVCS) { - actions = ((DelegatingVCS) vs).getInitActions(ctx); - } else { - VCSAnnotator an = vs.getVCSAnnotator(); - if (an == null) return null; - actions = an.getActions(ctx, VCSAnnotator.ActionDestination.PopupMenu); - } + if (vs instanceof DelegatingVCS) { + actions = ((DelegatingVCS) vs).getInitActions(ctx); + } else { + VCSAnnotator an = vs.getVCSAnnotator(); + if (an == null) return null; + actions = an.getActions(ctx, VCSAnnotator.ActionDestination.PopupMenu); } return actions; } diff --git a/versioning.core/src/org/netbeans/modules/versioning/core/VersioningConfig.java b/versioning.core/src/org/netbeans/modules/versioning/core/VersioningConfig.java --- a/versioning.core/src/org/netbeans/modules/versioning/core/VersioningConfig.java +++ b/versioning.core/src/org/netbeans/modules/versioning/core/VersioningConfig.java @@ -43,20 +43,8 @@ */ package org.netbeans.modules.versioning.core; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; import org.openide.util.NbPreferences; - import java.util.prefs.Preferences; -import org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem; -import org.netbeans.modules.versioning.core.api.VCSFileProxy; /** * Stores Versioning manager configuration. @@ -66,13 +54,8 @@ public class VersioningConfig { private static final VersioningConfig INSTANCE = new VersioningConfig(); - private static final Logger LOG = Logger.getLogger(VersioningConfig.class.getName()); - private final Map> allDisconnectedRepositories; - private static final String SEP = "###"; //NOI18N - private static final String PREF_KEY = "disconnectedFolders"; //NOI18N private VersioningConfig () { - allDisconnectedRepositories = initializeDisconnectedRepositories(); } public static VersioningConfig getDefault() { @@ -80,135 +63,7 @@ } public Preferences getPreferences() { - return getPrefs(); - } - - private static Preferences getPrefs () { return NbPreferences.root().node("org/netbeans/modules/versioning"); // NOI18N } - /** - * Tests whether the given repository is disconnected from the given versioning system. - * @param vs - * @param repository - * @return - */ - boolean isDisconnected (VersioningSystem vs, VCSFileProxy repository) { - boolean disconnected = false; - String className = vs.getDelegate().getClass().getName(); - synchronized (allDisconnectedRepositories) { - Set disconnectedRepositories = allDisconnectedRepositories.get(className); - if (disconnectedRepositories != null) { - for (String disconnectedRepository : disconnectedRepositories) { - if (disconnectedRepository.equals(repository.getPath())) { - disconnected = true; - LOG.log(Level.FINE, "isDisconnected: Folder is disconnected from {0}: {1}, disconnected root: {2}", new Object[] { className, repository, disconnectedRepository }); //NOI18N - break; - } - } - } - } - return disconnected; - } - - /** - * Reconnects the given repository to the given versioning system - * @param vs - * @param repository - */ - public void connectRepository (VersioningSystem vs, VCSFileProxy repository) { - connectRepository(vs, repository.getPath()); - } - - public void connectRepository (VersioningSystem vs, String path) { - String className = vs.getDelegate().getClass().getName(); - synchronized (allDisconnectedRepositories) { - Set disconnectedRepos = allDisconnectedRepositories.get(className); - if (disconnectedRepos != null) { - boolean changed = false; - for (Iterator it = disconnectedRepos.iterator(); it.hasNext(); ) { - String disconnectedRepository = it.next(); - if (disconnectedRepository.equals(path)) { - LOG.log(Level.FINE, "connectRepository: Connecting repository to {0}: {1}", new Object[] { className, path }); //NOI18N - it.remove(); - changed = true; - break; - } - } - if (changed) { - saveDisconnectedRepositories(); - } - } - } - } - - /** - * Disconnects the given repository from the given version control system - * @param vs - * @param repository - */ - public void disconnectRepository (VersioningSystem vs, VCSFileProxy repository) { - disconnectRepository(vs, repository.getPath()); - } - - public void disconnectRepository (VersioningSystem vs, String path) { - String className = vs.getDelegate().getClass().getName(); - synchronized (allDisconnectedRepositories) { - Set disconnectedRepos = allDisconnectedRepositories.get(className); - if (disconnectedRepos == null) { - disconnectedRepos = new HashSet(); - allDisconnectedRepositories.put(className, disconnectedRepos); - } - boolean added = disconnectedRepos.add(path); - if (!added) { - LOG.log(Level.FINE, "disconnectRepository: Repository already disconnected for {0}: {1}", new Object[] { className, path }); //NOI18N - } else { - saveDisconnectedRepositories(); - } - } - } - - public String[] getDisconnectedRoots (VersioningSystem vs) { - String className = vs.getDelegate().getClass().getName(); - String[] paths; - synchronized (allDisconnectedRepositories) { - Set disconnectedRepos = allDisconnectedRepositories.get(className); - if (disconnectedRepos == null) { - paths = new String[0]; - } else { - paths = disconnectedRepos.toArray(new String[disconnectedRepos.size()]); - } - } - return paths; - } - - private static Map> initializeDisconnectedRepositories () { - Map> disconnectedFolders = new HashMap>(5); - List list = Utils.getStringList(getPrefs(), PREF_KEY); - for (String s : list) { - String[] disconnectedFolder = s.split(SEP); - if (disconnectedFolder.length == 2) { - Set files = disconnectedFolders.get(disconnectedFolder[0]); - if (files == null) { - files = new HashSet(); - disconnectedFolders.put(disconnectedFolder[0], files); - } - files.add(disconnectedFolder[1]); - } - } - return disconnectedFolders; - } - - private void saveDisconnectedRepositories () { - List list = new LinkedList(); - synchronized (allDisconnectedRepositories) { - for (Map.Entry> e : allDisconnectedRepositories.entrySet()) { - String vsKey = e.getKey(); - for (String f : e.getValue()) { - list.add(vsKey + SEP + f); - } - } - } - Utils.put(getPreferences(), PREF_KEY, list); - } } diff --git a/versioning.core/src/org/netbeans/modules/versioning/core/VersioningMainMenu.java b/versioning.core/src/org/netbeans/modules/versioning/core/VersioningMainMenu.java --- a/versioning.core/src/org/netbeans/modules/versioning/core/VersioningMainMenu.java +++ b/versioning.core/src/org/netbeans/modules/versioning/core/VersioningMainMenu.java @@ -54,10 +54,7 @@ import javax.swing.event.MenuEvent; import java.awt.event.ActionEvent; import java.util.*; -import org.netbeans.modules.versioning.core.api.VCSFileProxy; import org.netbeans.modules.versioning.core.spi.VCSAnnotator; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; import org.openide.util.NbBundle; /** @@ -100,7 +97,6 @@ List systemItems = actionsToItems(vs[0].getVCSAnnotator().getActions(ctx, VCSAnnotator.ActionDestination.MainMenu)); items.addAll(systemItems); } - items.addAll(actionsToItems(appendAdditionalActions(ctx, vs[0], new Action[0]))); items.add(Utils.createJSeparator()); } else if (vs.length > 1) { JMenuItem dummy = new JMenuItem(""); @@ -121,7 +117,7 @@ if (system.isLocalHistory()) { localHistory = system; } else if (!"".equals(system.getMenuLabel())) { //NOI18N - JMenu menu = createVersioningSystemMenu(system, true); + JMenu menu = createVersioningSystemMenu(system); items.add(menu); } } @@ -132,13 +128,13 @@ if (localHistory != null) { items.add(Utils.createJSeparator()); - items.add(createVersioningSystemMenu(localHistory, false)); + items.add(createVersioningSystemMenu(localHistory)); } } return items.toArray(new JComponent[items.size()]); } - private JMenu createVersioningSystemMenu(final VersioningSystem system, final boolean isRegularVCS) { + private JMenu createVersioningSystemMenu(final VersioningSystem system) { final JMenu menu = new JMenu(); String menuText = VersioningManager.getInstance().isLocalHistory(system) ? @@ -151,7 +147,7 @@ if (menu.getItemCount() != 0) return; // context should be cached while the menu is displayed VCSContext ctx = VCSContext.forNodes(TopComponent.getRegistry().getActivatedNodes()); - constructMenu(menu, system, ctx, isRegularVCS); + constructMenu(menu, system, ctx); } @Override @@ -165,15 +161,12 @@ return menu; } - private void constructMenu (JMenu menu, VersioningSystem system, VCSContext ctx, boolean isRegularVCS) { + private void constructMenu (JMenu menu, VersioningSystem system, VCSContext ctx) { Action[] actions = null; if (system.getVCSAnnotator() != null) { actions = system.getVCSAnnotator().getActions(ctx, VCSAnnotator.ActionDestination.MainMenu); } - if (isRegularVCS) { - actions = appendAdditionalActions(ctx, system, actions); - } - if(actions != null && actions.length > 0) { + if (actions != null && actions.length > 0) { List systemItems = actionsToItems(actions); for (JComponent systemItem : systemItems) { menu.add(systemItem); @@ -206,71 +199,4 @@ return a.getDisplayName().compareTo(b.getDisplayName()); } } - - static class ConnectAction extends AbstractAction { - private final VCSFileProxy root; - private final VersioningSystem vs; - - public ConnectAction (VersioningSystem vs, VCSFileProxy root, String name) { - super(name == null ? NbBundle.getMessage(VersioningMainMenu.class, "CTL_ConnectAction.name") : name); //NOI18N - this.vs = vs; - this.root = root; - } - - @Override - public void actionPerformed (ActionEvent e) { - VersioningConfig.getDefault().connectRepository(vs, root); - VersioningManager.getInstance().versionedRootsChanged(); - } - } - - // should be available only from the main menu - private static class DisconnectAction extends AbstractAction { - private final VCSFileProxy root; - private final VersioningSystem vs; - - public DisconnectAction (VersioningSystem vs, VCSFileProxy root) { - super(NbBundle.getMessage(VersioningMainMenu.class, "CTL_DisconnectAction.name")); //NOI18N - this.vs = vs; - this.root = root; - } - - @Override - public void actionPerformed (ActionEvent e) { - NotifyDescriptor nd = new NotifyDescriptor.Confirmation( - NbBundle.getMessage(VersioningMainMenu.class, "MSG_ConnectAction.confirmation.text", new Object[] { root.getName(), vs.getDisplayName() }), //NOI18N - NbBundle.getMessage(VersioningMainMenu.class, "LBL_ConnectAction.confirmation.title"), //NOI18N - NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE); - if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) { - VersioningConfig.getDefault().disconnectRepository(vs, root); - VersioningManager.getInstance().versionedRootsChanged(); - } - } - } - - /** - * appends connect/disconnect actions to given actions - * @param ctx - * @param system - * @param actions initial actions - * @return enhanced actions - */ - private Action[] appendAdditionalActions (VCSContext ctx, VersioningSystem system, Action[] actions) { - if (ctx.getRootFiles().size() == 1) { - // can connect or disconnect just one root - VCSFileProxy root = system.getTopmostManagedAncestor(ctx.getRootFiles().iterator().next()); - if (root != null) { - Action a; - // adding connect/disconnect actions to the main menu - if (VersioningConfig.getDefault().isDisconnected(system, root)) { - actions = new Action[] { new ConnectAction(system, root, null) }; - } else { - actions = actions == null ? new Action[2] : Arrays.copyOf(actions, actions.length + 2); - actions[actions.length - 2] = null; - actions[actions.length - 1] = new DisconnectAction(system, root); - } - } - } - return actions; - } } diff --git a/versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java b/versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java --- a/versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java +++ b/versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java @@ -433,15 +433,9 @@ VCSFileProxy topmost = system.getTopmostManagedAncestor(folder); LOG.log(Level.FINE, " {0} returns {1} ", new Object[] { system.getClass().getName(), topmost }) ; if (topmost != null && (closestParent == null || Utils.isAncestorOrEqual(closestParent, topmost))) { - if (VersioningConfig.getDefault().isDisconnected(system, topmost)) { - // repository root is disconnected from this vcs - LOG.log(Level.FINE, " skipping disconnected owner = {0} for {1}", new Object[] { - system.getClass().getName(), topmost }) ; - } else { - LOG.log(Level.FINE, " owner = {0}", new Object[] { system.getClass().getName() }) ; - owner = system; - closestParent = topmost; - } + LOG.log(Level.FINE, " owner = {0}", new Object[] { system.getClass().getName() }) ; + owner = system; + closestParent = topmost; } } } diff --git a/versioning.core/src/org/netbeans/modules/versioning/core/util/Utils.java b/versioning.core/src/org/netbeans/modules/versioning/core/util/Utils.java --- a/versioning.core/src/org/netbeans/modules/versioning/core/util/Utils.java +++ b/versioning.core/src/org/netbeans/modules/versioning/core/util/Utils.java @@ -47,7 +47,6 @@ import javax.swing.Action; import org.netbeans.modules.versioning.core.*; import org.netbeans.modules.versioning.core.api.VCSFileProxy; -import org.netbeans.modules.versioning.core.filesystems.VCSFileProxyOperations; import org.netbeans.modules.versioning.core.spi.VCSHistoryProvider; import org.netbeans.modules.versioning.core.spi.VCSHistoryProvider.HistoryEntry; import org.netbeans.modules.versioning.core.spi.VCSHistoryProvider.MessageEditProvider; @@ -94,38 +93,6 @@ } /** - * Stop managing the given path by the given versioning system - * - * @param versioningSystem the versioning system to stop manage for the given path - * @param absolutePath the path to stop managed by the given versioning system - * @see #connectRepository(org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem, java.lang.String) - */ - public static void disconnectRepository(VersioningSystem versioningSystem, String absolutePath) { - VersioningConfig.getDefault().disconnectRepository(versioningSystem, absolutePath); - } - - /** - * Start again to manage the given path by the given versioning system - * - * @param versioningSystem the versioning system to stop manage for the given path - * @param absolutePath the path to stop managed by the given versioning system - * @see #disconnectRepository(org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem, java.lang.String) - */ - public static void connectRepository(VersioningSystem versioningSystem, String absolutePath) { - VersioningConfig.getDefault().connectRepository(versioningSystem, absolutePath); - } - - /** - * Returns all paths marked as not to managed by the given system - * - * @param versioningSystem the versioning system - * @return path not managed by the given versioning system - */ - public static String[] getDisconnectedRoots(VersioningSystem versioningSystem) { - return VersioningConfig.getDefault().getDisconnectedRoots(versioningSystem); - } - - /** * Empties the file owner cache */ public static void flushNullOwners() { diff --git a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/Bundle.properties b/versioning.ui/src/org/netbeans/modules/versioning/ui/options/Bundle.properties --- a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/Bundle.properties +++ b/versioning.ui/src/org/netbeans/modules/versioning/ui/options/Bundle.properties @@ -38,17 +38,6 @@ # # Portions Copyrighted 2011 Sun Microsystems, Inc. -AdvancedOption_DisplayName=General -AdvancedOption_Tooltip=General Versioning Options -GeneralOptionsPanel.jLabel1.text=&Versioning System -LBL_OptionsPanel.disconnectedFolders.title=Disconnected Repositories -GeneralOptionsPanel.jLabel2.text=Disconnected &Folders -GeneralOptionsPanel.btnRemove.text=&Remove -GeneralOptionsPanel.btnRemove.TTtext=Removes selected folder from the list of disconnected folders and reconnects the folder to the selected version control system -GeneralOptionsPanel.btnAdd.toolTipText=Allows you to select a folder to disconnect -GeneralOptionsPanel.btnAdd.text=&Add... -LBL_DisconnectingFolder.title=Disconnecting Folder - HistoryOptions.displayName=History HistoryOptions.toolTip=History Options ACSN_LocalHistoryOptionsPanel.daysTextField.text=Keep Local History Files diff --git a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralAdvancedOption.java b/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralAdvancedOption.java deleted file mode 100644 --- a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralAdvancedOption.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.versioning.ui.options; - -import org.netbeans.spi.options.AdvancedOption; -import org.netbeans.spi.options.OptionsPanelController; -import org.openide.util.NbBundle; - -public final class GeneralAdvancedOption extends AdvancedOption { - - @Override - public String getDisplayName() { - return NbBundle.getMessage(GeneralAdvancedOption.class, "AdvancedOption_DisplayName"); // NOI18N - } - - @Override - public String getTooltip() { - return NbBundle.getMessage(GeneralAdvancedOption.class, "AdvancedOption_Tooltip"); // NOI18N - } - - @Override - public OptionsPanelController create() { - return new GeneralOptionsPanelController(); - } - -} diff --git a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanelController.java b/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanelController.java deleted file mode 100644 --- a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanelController.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.versioning.ui.options; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import javax.swing.JComponent; -import org.netbeans.modules.versioning.util.VCSOptionsKeywordsProvider; -import org.netbeans.spi.options.OptionsPanelController; -import org.openide.util.HelpCtx; -import org.openide.util.Lookup; - -final class GeneralOptionsPanelController extends OptionsPanelController implements VCSOptionsKeywordsProvider { - - private GeneralOptionsPanel panel; - private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - private boolean changed; - - public GeneralOptionsPanelController() { } - - @Override - public void update() { - getPanel().load(); - changed = false; - } - - @Override - public void applyChanges() { - if (!validateFields()) return; - getPanel().store(); - changed = false; - } - - @Override - public void cancel() { - // need not do anything special, if no changes have been persisted yet - } - - @Override - public boolean isValid() { - return getPanel().valid(); - } - - @Override - public boolean isChanged() { - return changed; - } - - @Override - public HelpCtx getHelpCtx() { - return new HelpCtx(OptionsPanelController.class); - } - - @Override - public JComponent getComponent(Lookup masterLookup) { - return getPanel(); - } - - @Override - public void addPropertyChangeListener(PropertyChangeListener l) { - pcs.addPropertyChangeListener(l); - } - - @Override - public void removePropertyChangeListener(PropertyChangeListener l) { - pcs.removePropertyChangeListener(l); - } - - @Override - public boolean acceptKeywords (List keywords) { - Set allKeywords = new HashSet(panel.getKeywords()); - allKeywords.retainAll(keywords); - return !allKeywords.isEmpty(); - } - - private Boolean validateFields() { - - return true; - } - - private GeneralOptionsPanel getPanel() { - if (panel == null) { - panel = new GeneralOptionsPanel(this); - } - return panel; - } - - void changed() { - if (!changed) { - changed = true; - pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); - } - pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); - } - -} diff --git a/versioning.util/src/org/netbeans/modules/versioning/util/DisconnectedRepositoriesManager.java b/versioning.util/src/org/netbeans/modules/versioning/util/DisconnectedRepositoriesManager.java new file mode 100644 --- /dev/null +++ b/versioning.util/src/org/netbeans/modules/versioning/util/DisconnectedRepositoriesManager.java @@ -0,0 +1,229 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.versioning.util; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.prefs.Preferences; +import javax.swing.JPanel; +import org.netbeans.modules.versioning.spi.VersioningSupport; +import org.netbeans.modules.versioning.util.options.DisconnectedRepositoriesPanel; +import org.openide.util.NbPreferences; + +/** + * + * @author Ondrej Vrabec + */ +public final class DisconnectedRepositoriesManager { + + private static DisconnectedRepositoriesManager instance; + private static final Logger LOG = Logger.getLogger(DisconnectedRepositoriesManager.class.getName()); + private final Map> allDisconnectedRepositories; + private static final String SEP = "###"; //NOI18N + private static final String PREF_KEY = "disconnectedFolders"; //NOI18N + public static final String PROP_CONNECTED_ROOTS_CHANGED = "versioning.util.connectedRoots"; //NOI18N + private final PropertyChangeSupport support; + + private DisconnectedRepositoriesManager () { + allDisconnectedRepositories = initializeDisconnectedRepositories(); + support = new PropertyChangeSupport(this); + } + + public static synchronized DisconnectedRepositoriesManager getInstance () { + if (instance == null) { + instance = new DisconnectedRepositoriesManager(); + } + return instance; + } + + /** + * Stop managing the given path by the given versioning system + * + * @param versioningSystem the versioning system to stop manage for the given path + * @param absolutePath the path to stop managed by the given versioning system + * @see #connectRepository(org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem, java.lang.String) + */ + public void disconnectRepository(String versioningSystemKey, String absolutePath) { + synchronized (allDisconnectedRepositories) { + Set disconnectedRepos = allDisconnectedRepositories.get(versioningSystemKey); + if (disconnectedRepos == null) { + disconnectedRepos = new HashSet(); + allDisconnectedRepositories.put(versioningSystemKey, disconnectedRepos); + } + boolean added = disconnectedRepos.add(absolutePath); + if (!added) { + LOG.log(Level.FINE, "disconnectRepository: Repository already disconnected for {0}: {1}", new Object[] { versioningSystemKey, absolutePath }); //NOI18N + } else { + saveDisconnectedRepositories(); + VersioningSupport.versionedRootsChanged(); + support.firePropertyChange(PROP_CONNECTED_ROOTS_CHANGED, null, absolutePath); + } + } + } + + /** + * Start again to manage the given path by the given versioning system + * + * @param versioningSystem the versioning system to stop manage for the given path + * @param absolutePath the path to stop managed by the given versioning system + * @see #disconnectRepository(org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem, java.lang.String) + */ + public void connectRepository(String versioningSystemKey, String absolutePath) { + synchronized (allDisconnectedRepositories) { + Set disconnectedRepos = allDisconnectedRepositories.get(versioningSystemKey); + if (disconnectedRepos != null) { + boolean changed = false; + for (Iterator it = disconnectedRepos.iterator(); it.hasNext(); ) { + String disconnectedRepository = it.next(); + if (disconnectedRepository.equals(absolutePath)) { + LOG.log(Level.FINE, "connectRepository: Connecting repository to {0}: {1}", new Object[] { versioningSystemKey, absolutePath }); //NOI18N + it.remove(); + changed = true; + break; + } + } + if (changed) { + saveDisconnectedRepositories(); + VersioningSupport.versionedRootsChanged(); + support.firePropertyChange(PROP_CONNECTED_ROOTS_CHANGED, null, absolutePath); + } + } + } + } + + /** + * Returns all paths marked as not to managed by the given system + * + * @param versioningSystem the versioning system + * @return path not managed by the given versioning system + */ + public String[] getDisconnectedRoots (String versioningSystemKey) { + String[] paths; + synchronized (allDisconnectedRepositories) { + Set disconnectedRepos = allDisconnectedRepositories.get(versioningSystemKey); + if (disconnectedRepos == null) { + paths = new String[0]; + } else { + paths = disconnectedRepos.toArray(new String[disconnectedRepos.size()]); + } + } + return paths; + } + + /** + * Tests whether the given repository is disconnected from the given versioning system. + * @param vs + * @param repository + * @return + */ + public boolean isDisconnected (String key, String path) { + boolean disconnected = false; + synchronized (allDisconnectedRepositories) { + Set disconnectedRepositories = allDisconnectedRepositories.get(key); + if (disconnectedRepositories != null) { + for (String disconnectedRepository : disconnectedRepositories) { + if (disconnectedRepository.equals(path)) { + disconnected = true; + LOG.log(Level.FINE, "isDisconnected: Folder is disconnected from {0}: {1}, disconnected root: {2}", new Object[] { key, path, disconnectedRepository }); //NOI18N + break; + } + } + } + } + return disconnected; + } + + public JPanel getOptionsPanel (String versioningSystemKey) { + return new DisconnectedRepositoriesPanel(versioningSystemKey); + } + + public void addPropertyChangeListener (PropertyChangeListener list) { + support.addPropertyChangeListener(list); + } + + public void removePropertyChangeListener (PropertyChangeListener list) { + support.removePropertyChangeListener(list); + } + + private static Map> initializeDisconnectedRepositories () { + Map> disconnectedFolders = new HashMap>(5); + List list = Utils.getStringList(getPrefs(), PREF_KEY); + for (String s : list) { + String[] disconnectedFolder = s.split(SEP); + if (disconnectedFolder.length == 2) { + Set files = disconnectedFolders.get(disconnectedFolder[0]); + if (files == null) { + files = new HashSet(); + disconnectedFolders.put(disconnectedFolder[0], files); + } + files.add(disconnectedFolder[1]); + } + } + return disconnectedFolders; + } + + private void saveDisconnectedRepositories () { + List list = new LinkedList(); + synchronized (allDisconnectedRepositories) { + for (Map.Entry> e : allDisconnectedRepositories.entrySet()) { + String vsKey = e.getKey(); + for (String f : e.getValue()) { + list.add(vsKey + SEP + f); + } + } + } + Utils.put(getPrefs(), PREF_KEY, list); + } + + private static Preferences getPrefs () { + return NbPreferences.forModule(DisconnectedRepositoriesManager.class); + } +} diff --git a/versioning.util/src/org/netbeans/modules/versioning/util/options/Bundle.properties b/versioning.util/src/org/netbeans/modules/versioning/util/options/Bundle.properties --- a/versioning.util/src/org/netbeans/modules/versioning/util/options/Bundle.properties +++ b/versioning.util/src/org/netbeans/modules/versioning/util/options/Bundle.properties @@ -45,3 +45,8 @@ AnnotationColorsPanel.btnResetToDefaults.TTtext=Resets colors to their default values KW_AnnotationColorsPanel=versioning, colors +DisconnectedRepositoriesPanel.jLabel2.text=Disconnected &Folders +DisconnectedRepositoriesPanel.btnRemove.text=&Remove +DisconnectedRepositoriesPanel.btnRemove.TTtext=Removes selected folder from the list of disconnected folders and reconnects the folder to the selected version control system +DisconnectedRepositoriesPanel.btnAdd.text=&Add... +DisconnectedRepositoriesPanel.btnAdd.toolTipText=Allows you to select a folder to disconnect diff --git a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanel.form b/versioning.util/src/org/netbeans/modules/versioning/util/options/DisconnectedRepositoriesPanel.form rename from versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanel.form rename to versioning.util/src/org/netbeans/modules/versioning/util/options/DisconnectedRepositoriesPanel.form --- a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanel.form +++ b/versioning.util/src/org/netbeans/modules/versioning/util/options/DisconnectedRepositoriesPanel.form @@ -17,30 +17,15 @@ - + - - - - - - - - - - - - - - - - + + + + + - - - - - + @@ -49,17 +34,7 @@ - - - - - - - - - - @@ -74,30 +49,13 @@ - - - - - - - - - - - - - - - - - - + @@ -120,31 +78,22 @@ - + - + - + - + - - - - - - - - - diff --git a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanel.java b/versioning.util/src/org/netbeans/modules/versioning/util/options/DisconnectedRepositoriesPanel.java rename from versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanel.java rename to versioning.util/src/org/netbeans/modules/versioning/util/options/DisconnectedRepositoriesPanel.java --- a/versioning.ui/src/org/netbeans/modules/versioning/ui/options/GeneralOptionsPanel.java +++ b/versioning.util/src/org/netbeans/modules/versioning/util/options/DisconnectedRepositoriesPanel.java @@ -42,82 +42,34 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.modules.versioning.ui.options; +package org.netbeans.modules.versioning.util.options; -import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import javax.swing.DefaultComboBoxModel; -import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; -import javax.swing.JList; -import org.netbeans.api.options.OptionsDisplayer; -import org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem; -import org.netbeans.modules.versioning.core.api.VCSFileProxy; -import org.netbeans.modules.versioning.core.util.Utils; -import org.netbeans.spi.options.OptionsPanelController; +import org.netbeans.modules.versioning.util.DisconnectedRepositoriesManager; import org.openide.filesystems.FileChooserBuilder; -import org.openide.util.Lookup; import org.openide.util.NbBundle; -import org.openide.util.RequestProcessor; -@OptionsPanelController.Keywords(keywords={"#GeneralOptionsPanel.kw1", "#GeneralOptionsPanel.kw3", "#GeneralOptionsPanel.kw3"}, location=OptionsDisplayer.ADVANCED, tabTitle="#CTL_OptionsPanel.tabName") -@NbBundle.Messages({ - "CTL_OptionsPanel.tabName=Versioning", - "GeneralOptionsPanel.kw1=general", - "GeneralOptionsPanel.kw2=versioning", - "GeneralOptionsPanel.kw3=disconnected repositories" -}) -final class GeneralOptionsPanel extends javax.swing.JPanel implements ActionListener { +public final class DisconnectedRepositoriesPanel extends javax.swing.JPanel implements ActionListener { + private final String key; - private final GeneralOptionsPanelController controller; - private String[] keywords; - - GeneralOptionsPanel (GeneralOptionsPanelController controller) { - this.controller = controller; + public DisconnectedRepositoriesPanel (String versioningSystemKey) { + this.key = versioningSystemKey; initComponents(); - cmbVersioningSystems.setRenderer(new Renderer()); - cmbVersioningSystems.addActionListener(this); btnRemove.addActionListener(this); btnAdd.addActionListener(this); - } - - @Override - public void addNotify() { - super.addNotify(); - } - - @Override - public void removeNotify() { - super.removeNotify(); - } - - Collection getKeywords () { - if (keywords == null) { - keywords = new String[] { - Bundle.GeneralOptionsPanel_kw1().toUpperCase(), - Bundle.GeneralOptionsPanel_kw2().toUpperCase(), - Bundle.GeneralOptionsPanel_kw3().toUpperCase() - }; - } - return Collections.unmodifiableList(Arrays.asList(keywords)); + fillDisconnectedFolders (); } private void fillDisconnectedFolders () { - if (cmbVersioningSystems.getSelectedItem() instanceof VersioningSystem) { - String[] disconnected = Utils.getDisconnectedRoots(((VersioningSystem) cmbVersioningSystems.getSelectedItem())); - DefaultListModel model = new DefaultListModel(); - for (String f : disconnected) { - model.addElement(f); - } - lstDisconnectedFolders.setModel(model); + String[] disconnected = DisconnectedRepositoriesManager.getInstance().getDisconnectedRoots(key); + DefaultListModel model = new DefaultListModel(); + for (String f : disconnected) { + model.addElement(f); } + lstDisconnectedFolders.setModel(model); } /** This method is called from within the constructor to @@ -128,31 +80,22 @@ // //GEN-BEGIN:initComponents private void initComponents() { - jLabel1 = new javax.swing.JLabel(); - cmbVersioningSystems = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); lstDisconnectedFolders = new javax.swing.JList(); btnRemove = new javax.swing.JButton(); btnAdd = new javax.swing.JButton(); - jLabel3 = new javax.swing.JLabel(); - jSeparator1 = new javax.swing.JSeparator(); - - jLabel1.setLabelFor(cmbVersioningSystems); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.jLabel1.text")); // NOI18N jLabel2.setLabelFor(lstDisconnectedFolders); - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.jLabel2.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DisconnectedRepositoriesPanel.class, "DisconnectedRepositoriesPanel.jLabel2.text")); // NOI18N jScrollPane1.setViewportView(lstDisconnectedFolders); - org.openide.awt.Mnemonics.setLocalizedText(btnRemove, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.btnRemove.text")); // NOI18N - btnRemove.setToolTipText(org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.btnRemove.TTtext")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(btnRemove, org.openide.util.NbBundle.getMessage(DisconnectedRepositoriesPanel.class, "DisconnectedRepositoriesPanel.btnRemove.text")); // NOI18N + btnRemove.setToolTipText(org.openide.util.NbBundle.getMessage(DisconnectedRepositoriesPanel.class, "DisconnectedRepositoriesPanel.btnRemove.TTtext")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(btnAdd, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.btnAdd.text")); // NOI18N - btnAdd.setToolTipText(org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.btnAdd.toolTipText")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_OptionsPanel.disconnectedFolders.title")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(btnAdd, org.openide.util.NbBundle.getMessage(DisconnectedRepositoriesPanel.class, "DisconnectedRepositoriesPanel.btnAdd.text")); // NOI18N + btnAdd.setToolTipText(org.openide.util.NbBundle.getMessage(DisconnectedRepositoriesPanel.class, "DisconnectedRepositoriesPanel.btnAdd.toolTipText")); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); @@ -161,37 +104,18 @@ .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) .addGroup(layout.createSequentialGroup() - .addGap(12, 12, 12) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cmbVersioningSystems, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addComponent(btnRemove) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnAdd)) - .addComponent(jScrollPane1))) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel3) + .addComponent(btnRemove) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSeparator1))) + .addComponent(btnAdd)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel3) - .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 4, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(cmbVersioningSystems, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -202,81 +126,29 @@ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents - - void load () { - fillVersioningSystems(); - } - - void store() { - - } - - boolean valid() { - return true; - } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAdd; private javax.swing.JButton btnRemove; - private javax.swing.JComboBox cmbVersioningSystems; - private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JSeparator jSeparator1; private javax.swing.JList lstDisconnectedFolders; // End of variables declaration//GEN-END:variables - private void fillVersioningSystems () { - List systems = new LinkedList(); - for (VersioningSystem system : Lookup.getDefault().lookupAll(VersioningSystem.class)) { - systems.add(system); - } - cmbVersioningSystems.setModel(new DefaultComboBoxModel(systems.toArray(new VersioningSystem[systems.size()]))); - } - @Override + @NbBundle.Messages("LBL_DisconnectingFolder.title=Disconnecting Folder") public void actionPerformed (ActionEvent e) { - if (e.getSource() == cmbVersioningSystems) { + if (e.getSource() == btnRemove) { + String f = (String) lstDisconnectedFolders.getSelectedValue(); + DisconnectedRepositoriesManager.getInstance().connectRepository(key, f); fillDisconnectedFolders(); - } else if (e.getSource() == btnRemove) { - if (cmbVersioningSystems.getSelectedItem() instanceof VersioningSystem && lstDisconnectedFolders.getSelectedValue() != null) { - String f = (String) lstDisconnectedFolders.getSelectedValue(); - Utils.connectRepository((VersioningSystem) cmbVersioningSystems.getSelectedItem(), f); + } else if (e.getSource() == btnAdd) { + File f = new FileChooserBuilder("VersioningOptions.disconnected").setTitle(Bundle.LBL_DisconnectingFolder_title()) //NOI18N + .setDirectoriesOnly(true).setFileHiding(true).showOpenDialog(); + if (f != null) { + DisconnectedRepositoriesManager.getInstance().disconnectRepository(key, f.getAbsolutePath()); fillDisconnectedFolders(); - refreshSystems(); - } - } else if (e.getSource() == btnAdd) { - if (cmbVersioningSystems.getSelectedItem() instanceof VersioningSystem) { - VersioningSystem vcs = (VersioningSystem) cmbVersioningSystems.getSelectedItem(); - File f = new FileChooserBuilder("VersioningOptions.disconnected").setTitle(NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_DisconnectingFolder.title")) //NOI18N - .setDirectoriesOnly(true).setFileHiding(true).showOpenDialog(); - if (f != null && (vcs.getTopmostManagedAncestor(VCSFileProxy.createFileProxy(f)) != null)) { - Utils.disconnectRepository(vcs, f.getAbsolutePath()); - fillDisconnectedFolders(); - refreshSystems(); - } } } } - - private void refreshSystems () { - RequestProcessor.getDefault().post(new Runnable() { - @Override - public void run () { - Utils.versionedRootsChanged(); - } - }).schedule(100); - } - - private static class Renderer extends DefaultListCellRenderer { - - @Override - public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - if (value instanceof VersioningSystem) { - value = ((VersioningSystem) value).getDisplayName(); - } - return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - } - } } diff --git a/versioning/src/org/netbeans/modules/versioning/Bundle.properties b/versioning/src/org/netbeans/modules/versioning/Bundle.properties --- a/versioning/src/org/netbeans/modules/versioning/Bundle.properties +++ b/versioning/src/org/netbeans/modules/versioning/Bundle.properties @@ -44,21 +44,3 @@ OpenIDE-Module-Display-Category=Versioning OpenIDE-Module-Short-Description=Support module for Versioning systems. OpenIDE-Module-Long-Description=Support module for Versioning systems. - -Actions/Versioning=Versioning -Menu/Versioning=Tea&m -Menu/Window/Versioning=&Versioning - -CTL_MenuItem_ShowTextAnnotations = Show &Versioning Labels -CTL_MenuItem_VersioningMenu = Versioning -CTL_MenuItem_LocalHistory=Local History -CTL_MenuItem_Initializing=Initializing... - -CTL_DisconnectAction.name=Dis&connect... -CTL_ConnectAction.name=&Connect -CTL_ConnectAction.name.vcs=Connect To {0} -LBL_ConnectAction.confirmation.title=Disconnect From Version Control System -MSG_ConnectAction.confirmation.text=Do you want to disconnect {0} from {1}?\n\ -The folder will no longer be controlled by {1} in the IDE.\n\n\ -You will be able to reconnect the folder to the system\n\ -with the Connect action available from the Main menu. \ No newline at end of file