Removed unused ServeAction.
[nbgit.git] / src / org / netbeans / modules / git / ui / properties / GitProperties.java
blobc9eb327ee689f3d053f6edf1b5d0c23ee345be1d
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git.ui.properties;
44 import java.awt.Font;
45 import java.io.File;
46 import java.util.Enumeration;
47 import java.util.Properties;
48 import javax.swing.ListSelectionModel;
49 import javax.swing.event.ListSelectionEvent;
50 import javax.swing.event.ListSelectionListener;
51 import org.netbeans.modules.git.Git;
52 import org.netbeans.modules.git.GitModuleConfig;
53 import org.netbeans.modules.git.GitProgressSupport;
54 import org.netbeans.modules.git.util.GitRepositoryContextCache;
55 import org.openide.util.RequestProcessor;
57 /**
59 * @author Padraig O'Briain
61 public class GitProperties implements ListSelectionListener {
63 public static final String GITPROPNAME_USERNAME = "username"; // NOI18N
64 public static final String GITPROPNAME_DEFAULT_PULL = "default-pull"; // NOI18N
65 public static final String GITPROPNAME_DEFAULT_PUSH = "default-push"; // NOI18N
67 private PropertiesPanel panel;
68 private File root;
69 private PropertiesTable propTable;
70 private GitProgressSupport support;
71 private File loadedValueFile;
72 private Font fontTextArea;
74 /** Creates a new instance of GitProperties */
75 public GitProperties(PropertiesPanel panel, PropertiesTable propTable, File root) {
76 this.panel = panel;
77 this.propTable = propTable;
78 this.root = root;
79 propTable.getTable().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
80 propTable.getTable().getSelectionModel().addListSelectionListener(this);
82 refreshProperties();
85 public PropertiesPanel getPropertiesPanel() {
86 return panel;
89 public void setPropertiesPanel(PropertiesPanel panel) {
90 this.panel = panel;
93 public File getRoot() {
94 return root;
97 public void setRoot(File root) {
98 this.root = root;
101 protected String getPropertyValue() {
102 return panel.txtAreaValue.getText();
105 protected void refreshProperties() {
106 RequestProcessor rp = Git.getInstance().getRequestProcessor(root.getAbsolutePath());
107 try {
108 support = new GitProgressSupport() {
109 protected void perform() {
110 Properties props = GitModuleConfig.getDefault().getProperties(root);
111 GitPropertiesNode[] gitProps = new GitPropertiesNode[props.size()];
112 int i = 0;
114 for (Enumeration e = props.propertyNames(); e.hasMoreElements() ; ) {
115 String name = (String) e.nextElement();
116 String tmp = props.getProperty(name);
117 String value = tmp != null ? tmp : ""; // NOI18N
118 gitProps[i] = new GitPropertiesNode(name, value);
119 i++;
121 propTable.setNodes(gitProps);
124 support.start(rp, root.getAbsolutePath(), org.openide.util.NbBundle.getMessage(GitProperties.class, "LBL_Properties_Progress")); // NOI18N
125 } finally {
126 support = null;
130 public void setProperties() {
131 RequestProcessor rp = Git.getInstance().getRequestProcessor(root.getAbsolutePath());
132 try {
133 support = new GitProgressSupport() {
134 protected void perform() {
135 GitModuleConfig.getDefault().clearProperties(root, "paths"); // NOI18N
136 GitModuleConfig.getDefault().removeProperty(root, "ui", GITPROPNAME_USERNAME); // NOI18N
137 GitPropertiesNode[] gitPropertiesNodes = propTable.getNodes();
138 for (int i = 0; i < gitPropertiesNodes.length; i++) {
139 String gitPropertyName = gitPropertiesNodes[i].getName();
140 String gitPropertyValue = gitPropertiesNodes[i].getValue();
141 if (gitPropertyValue.trim().length() > 0 ) {
142 GitModuleConfig.getDefault().setProperty(root, gitPropertyName, gitPropertyValue);
145 GitRepositoryContextCache.resetPullDefault();
146 GitRepositoryContextCache.resetPushDefault();
149 support.start(rp, root.getAbsolutePath(), org.openide.util.NbBundle.getMessage(GitProperties.class, "LBL_Properties_Progress")); // NOI18N
150 } finally {
151 support = null;
155 private int lastIndex = -1;
158 public void updateLastSelection () {
159 GitPropertiesNode[] gitPropertiesNodes = propTable.getNodes();
160 if (lastIndex >= 0) {
161 gitPropertiesNodes[lastIndex].setValue(getPropertyValue());
165 public void valueChanged (ListSelectionEvent e) {
166 int index = propTable.getTable().getSelectedRow();
167 if (index < 0) {
168 lastIndex = -1;
169 return;
171 GitPropertiesNode[] gitPropertiesNodes = propTable.getNodes();
172 if (lastIndex >= 0) {
173 gitPropertiesNodes[lastIndex].setValue(getPropertyValue());
175 panel.txtAreaValue.setText(gitPropertiesNodes[index].getValue());
176 lastIndex = index;