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.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.groovy.groovyproject.ui.customizer;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47
import java.awt.event.MouseEvent;
49
import java.util.ArrayList;
50
import java.util.Enumeration;
51
import java.util.HashMap;
52
import java.util.Iterator;
53
import java.util.List;
55
import javax.swing.event.ChangeEvent;
56
import javax.swing.event.ChangeListener;
57
import javax.swing.event.DocumentEvent;
58
import javax.swing.event.DocumentListener;
59
import javax.swing.event.ListSelectionEvent;
60
import javax.swing.event.ListSelectionListener;
61
import javax.swing.text.Document;
62
import org.netbeans.api.project.ant.AntArtifact;
63
import org.netbeans.api.project.libraries.Library;
64
import org.openide.DialogDisplayer;
65
import org.openide.NotifyDescriptor;
66
import org.openide.DialogDescriptor;
67
import org.openide.awt.MouseUtils;
68
import org.openide.filesystems.FileObject;
69
import org.openide.util.NbBundle;
71
/** Represents field for main script name and the button to main script chooser.
72
* of classpath editing controls.
74
* @author Jiri Rechtacek
76
final class VisualMainScriptSupport {
78
private final JTextField mainScriptTextField;
79
private final JButton chooseMainScriptButton;
80
private final FileObject sourceRoot;
82
private final ArrayList actionListeners = new ArrayList();
84
public VisualMainScriptSupport (JTextField mainScriptTextField, JButton chooseMainScriptButton, FileObject sourceRoot) {
86
this.mainScriptTextField = mainScriptTextField;
87
this.chooseMainScriptButton = chooseMainScriptButton;
88
this.sourceRoot = sourceRoot;
90
// Register the button listener
91
MainScriptListener actionListener = new MainScriptListener ();
93
chooseMainScriptButton.addActionListener (actionListener);
94
mainScriptTextField.getDocument ().addDocumentListener (actionListener);
97
public void setMainScript (String mainScript) {
98
mainScriptTextField.setText (mainScript);
101
public String getMainScript () {
102
return mainScriptTextField == null ? "" : mainScriptTextField.getText (); // NOI18N
105
/** Action listeners will be informed when the value of the
108
public void addActionListener( ActionListener listener ) {
109
actionListeners.add( listener );
112
public void removeActionListener( ActionListener listener ) {
113
actionListeners.remove( listener );
116
private void fireActionPerformed() {
119
synchronized ( this ) {
120
listeners = new ArrayList( actionListeners );
123
ActionEvent ae = new ActionEvent( this, 0, null );
125
for( Iterator it = listeners.iterator(); it.hasNext(); ) {
126
ActionListener al = (ActionListener)it.next();
127
al.actionPerformed( ae );
132
// Private methods ---------------------------------------------------------
134
// Private innerclasses ----------------------------------------------------
136
private class MainScriptListener implements ActionListener, DocumentListener {
137
private final JButton okButton = new JButton (NbBundle.getMessage (VisualMainScriptSupport.class, "LBL_ChooseMainScript_OK"));
139
// Implementation of ActionListener ------------------------------------
141
/** Handles button events
143
public void actionPerformed( ActionEvent e ) {
145
// only chooseMainScriptButton can be performed
147
final MainScriptChooser panel = new MainScriptChooser (sourceRoot);
148
Object[] options = new Object[] {
150
DialogDescriptor.CANCEL_OPTION
152
panel.addChangeListener (new ChangeListener () {
153
public void stateChanged(ChangeEvent e) {
154
if (e.getSource () instanceof MouseEvent && MouseUtils.isDoubleClick (((MouseEvent)e.getSource ()))) {
155
// click button and finish the dialog with selected class
158
okButton.setEnabled (panel.getSelectedMainScript () != null);
162
okButton.setEnabled (panel.getSelectedMainScript () != null);
163
DialogDescriptor desc = new DialogDescriptor (panel,
164
NbBundle.getMessage (VisualMainScriptSupport.class, "LBL_ChooseMainScript_Title" ),
165
true, options, options[0], DialogDescriptor.BOTTOM_ALIGN, null, null);
166
//desc.setMessageType (DialogDescriptor.INFORMATION_MESSAGE);
167
Dialog dlg = DialogDisplayer.getDefault ().createDialog (desc);
168
dlg.setVisible (true);
169
if (desc.getValue() == options[0]) {
170
mainScriptTextField.setText (panel.getSelectedMainScript ());
175
// Implementation of document listener ---------------------------------
177
public void changedUpdate (DocumentEvent e) {
178
fireActionPerformed ();
181
public void insertUpdate( DocumentEvent e ) {
185
public void removeUpdate( DocumentEvent e ) {