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]"
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
.wizards
;
44 import java
.awt
.Component
;
45 import java
.util
.HashSet
;
46 import java
.util
.Iterator
;
48 import javax
.swing
.SwingUtilities
;
49 import javax
.swing
.event
.ChangeEvent
;
50 import javax
.swing
.event
.ChangeListener
;
51 import javax
.swing
.event
.DocumentEvent
;
52 import javax
.swing
.event
.DocumentListener
;
53 import org
.openide
.WizardDescriptor
;
54 import org
.openide
.util
.HelpCtx
;
56 public class ClonePathsWizardPanel
implements WizardDescriptor
.Panel
, DocumentListener
{
59 * The visual component that displays this panel. If you need to access the
60 * component from this class, just use getComponent().
62 private ClonePathsPanel component
;
63 private boolean valid
;
64 private String errorMessage
;
65 private String repositoryOrig
;
66 // Get the visual component for the panel. In this template, the component
67 // is kept separate. This can be more efficient: if the wizard is created
68 // but never displayed, or not all panels are displayed, it is better to
69 // create only those which really need to be visible.
70 public Component
getComponent() {
71 if (component
== null) {
72 component
= new ClonePathsPanel();
78 public HelpCtx
getHelp() {
79 return new HelpCtx(ClonePathsWizardPanel
.class);
82 //public boolean isValid() {
83 // If it is always OK to press Next or Finish, then:
85 // If it depends on some condition (form filled out...), then:
86 // return someCondition();
87 // and when this condition changes (last form field filled in...) then:
89 // and uncomment the complicated stuff below.
92 public void insertUpdate(DocumentEvent e
) {
96 public void removeUpdate(DocumentEvent e
) {
100 public void changedUpdate(DocumentEvent e
) {
104 private void textChanged(final DocumentEvent e
) {
105 // repost later to AWT otherwise it can deadlock because
106 // the document is locked while firing event and we try
107 // synchronously access its content
108 Runnable awt
= new Runnable() {
110 if (e
.getDocument() == component
.defaultPullPathField
.getDocument () ||
111 e
.getDocument() == component
.defaultPushPathField
.getDocument()) {
112 if (component
.isValid()) {
113 valid(component
.getMessage());
115 invalid(component
.getMessage());
120 SwingUtilities
.invokeLater(awt
);
123 private final Set
<ChangeListener
> listeners
= new HashSet
<ChangeListener
>(1); // or can use ChangeSupport in NB 6.0
124 public final void addChangeListener(ChangeListener l
) {
125 synchronized (listeners
) {
129 public final void removeChangeListener(ChangeListener l
) {
130 synchronized (listeners
) {
134 protected final void fireChangeEvent() {
135 Iterator
<ChangeListener
> it
;
136 synchronized (listeners
) {
137 it
= new HashSet
<ChangeListener
>(listeners
).iterator();
139 ChangeEvent ev
= new ChangeEvent(this);
140 while (it
.hasNext()) {
141 it
.next().stateChanged(ev
);
145 protected final void valid() {
146 setValid(true, null);
149 protected final void valid(String extErrorMessage
) {
150 setValid(true, extErrorMessage
);
153 protected final void invalid(String message
) {
154 setValid(false, message
);
157 public final boolean isValid() {
161 public final String
getErrorMessage() {
165 private void setValid(boolean valid
, String errorMessage
) {
166 boolean fire
= this.valid
!= valid
;
167 fire
|= errorMessage
!= null && (errorMessage
.equals(this.errorMessage
) == false);
169 this.errorMessage
= errorMessage
;
175 // You can use a settings object to keep track of state. Normally the
176 // settings object will be the WizardDescriptor, so you can use
177 // WizardDescriptor.getProperty & putProperty to store information entered
179 public void readSettings(Object settings
) {
180 if (settings
instanceof WizardDescriptor
) {
181 String repository
= (String
) ((WizardDescriptor
) settings
).getProperty("repository"); // NOI18N
182 boolean repoistoryChanged
= repositoryOrig
== null || !repository
.equals(repositoryOrig
);
183 repositoryOrig
= repository
;
185 if(repoistoryChanged
|| component
.defaultPullPathField
.getText().equals(""))
186 component
.defaultPullPathField
.setText(repository
);
187 if(repoistoryChanged
|| component
.defaultPushPathField
.getText().equals(""))
188 component
.defaultPushPathField
.setText(repository
);
191 public void storeSettings(Object settings
) {
192 if (settings
instanceof WizardDescriptor
) {
193 ((WizardDescriptor
) settings
).putProperty("defaultPullPath", ((ClonePathsPanel
) component
).getPullPath()); // NOI18N
194 ((WizardDescriptor
) settings
).putProperty("defaultPushPath", ((ClonePathsPanel
) component
).getPushPath()); // NOI18N