001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.gravy.properties.editors;
043:
044: import java.io.File; /*
045: * ClasspathCustomEditorOperator.java
046: *
047: * Created on 6/13/02 4:40 PM
048: */
049:
050: import java.util.ArrayList;
051: import javax.swing.JDialog;
052: import javax.swing.ListModel;
053: import org.netbeans.jellytools.Bundle;
054: import org.netbeans.modules.visualweb.gravy.NbDialogOperator;
055: import org.netbeans.jemmy.operators.*;
056:
057: /** Class implementing all necessary methods for handling Classpath Custom Editor
058: */
059: public class ClasspathCustomEditorOperator extends NbDialogOperator {
060:
061: /** Creates new ClasspathCustomEditorOperator
062: * @throws TimeoutExpiredException when NbDialog not found
063: * @param title String title of custom editor */
064: public ClasspathCustomEditorOperator(String title) {
065: super (title);
066: }
067:
068: /** Creates new ClasspathCustomEditorOperator
069: * @param wrapper JDialogOperator wrapper for custom editor */
070: public ClasspathCustomEditorOperator(JDialogOperator wrapper) {
071: super ((JDialog) wrapper.getSource());
072: }
073:
074: private JButtonOperator _btAddDirectory;
075: private JButtonOperator _btMoveDown;
076: private JListOperator _lstClasspath;
077: private JButtonOperator _btAddJARZIP;
078: private JButtonOperator _btRemove;
079: private JButtonOperator _btMoveUp;
080:
081: /** Tries to find Add Directory... JButton in this dialog.
082: * @throws TimeoutExpiredException when component not found
083: * @return JButtonOperator
084: */
085: public JButtonOperator btAddDirectory() {
086: if (_btAddDirectory == null) {
087: _btAddDirectory = new JButtonOperator(
088: this ,
089: Bundle
090: .getString(
091: "org.netbeans.core.execution.beaninfo.editors.Bundle",
092: "CTL_AddDirectory"));
093: }
094: return _btAddDirectory;
095: }
096:
097: /** Tries to find "Move Down" JButton in this dialog.
098: * @throws TimeoutExpiredException when component not found
099: * @return JButtonOperator
100: */
101: public JButtonOperator btMoveDown() {
102: if (_btMoveDown == null) {
103: _btMoveDown = new JButtonOperator(
104: this ,
105: Bundle
106: .getString(
107: "org.netbeans.core.execution.beaninfo.editors.Bundle",
108: "CTL_MoveDown"));
109: }
110: return _btMoveDown;
111: }
112:
113: /** Tries to find null JList in this dialog.
114: * @throws TimeoutExpiredException when component not found
115: * @return JListOperator
116: */
117: public JListOperator lstClasspath() {
118: if (_lstClasspath == null) {
119: _lstClasspath = new JListOperator(this );
120: }
121: return _lstClasspath;
122: }
123:
124: /** Tries to find Add JAR/ZIP... JButton in this dialog.
125: * @throws TimeoutExpiredException when component not found
126: * @return JButtonOperator
127: */
128: public JButtonOperator btAddJARZIP() {
129: if (_btAddJARZIP == null) {
130: _btAddJARZIP = new JButtonOperator(
131: this ,
132: Bundle
133: .getString(
134: "org.netbeans.core.execution.beaninfo.editors.Bundle",
135: "CTL_AddJAR"));
136: }
137: return _btAddJARZIP;
138: }
139:
140: /** Tries to find "Remove" JButton in this dialog.
141: * @throws TimeoutExpiredException when component not found
142: * @return JButtonOperator
143: */
144: public JButtonOperator btRemove() {
145: if (_btRemove == null) {
146: _btRemove = new JButtonOperator(
147: this ,
148: Bundle
149: .getString(
150: "org.netbeans.core.execution.beaninfo.editors.Bundle",
151: "CTL_Remove"));
152: }
153: return _btRemove;
154: }
155:
156: /** Tries to find "Move Up" JButton in this dialog.
157: * @throws TimeoutExpiredException when component not found
158: * @return JButtonOperator
159: */
160: public JButtonOperator btMoveUp() {
161: if (_btMoveUp == null) {
162: _btMoveUp = new JButtonOperator(
163: this ,
164: Bundle
165: .getString(
166: "org.netbeans.core.execution.beaninfo.editors.Bundle",
167: "CTL_MoveUp"));
168: }
169: return _btMoveUp;
170: }
171:
172: /** clicks on Add Directory... JButton
173: * @throws TimeoutExpiredException when JButton not found
174: * @return FileCustomEditorOperator of directory selector */
175: public FileCustomEditorOperator addDirectory() {
176: btAddDirectory().pushNoBlock();
177: return new FileCustomEditorOperator(Bundle.getString(
178: "org.netbeans.core.execution.beaninfo.editors.Bundle",
179: "CTL_FileSystemPanel.Local_Dialog_Title"));
180: }
181:
182: /** clicks on "Move Down" JButton
183: * @throws TimeoutExpiredException when JButton not found
184: */
185: public void moveDown() {
186: btMoveDown().push();
187: }
188:
189: /** clicks on Add JAR/ZIP... JButton
190: * @throws TimeoutExpiredException when JButton not found
191: * @return FileCustomEditorOperator of JAR or ZIP file selector */
192: public FileCustomEditorOperator addJARZIP() {
193: btAddJARZIP().pushNoBlock();
194: return new FileCustomEditorOperator(Bundle.getString(
195: "org.netbeans.core.execution.beaninfo.editors.Bundle",
196: "CTL_FileSystemPanel.Jar_Dialog_Title"));
197: }
198:
199: /** adds directory into classpath list
200: * @param directoryPath String directory path to be added */
201: public void addDirectory(String directoryPath) {
202: FileCustomEditorOperator editor = addDirectory();
203: editor.setFileValue(directoryPath);
204: editor.ok();
205: }
206:
207: /** adds JAR or ZIP file into classpath list
208: * @param filePath String path of JAR or ZIP file to be added */
209: public void addJARZIP(String filePath) {
210: FileCustomEditorOperator editor = addJARZIP();
211: editor.setFileValue(filePath);
212: editor.ok();
213: }
214:
215: /** adds directory into classpath list
216: * @param directory File directory to be added */
217: public void addDirectory(File directory) {
218: FileCustomEditorOperator editor = addDirectory();
219: editor.setFileValue(directory);
220: editor.ok();
221: }
222:
223: /** adds JAR or ZIP file into classpath list
224: * @param jarZip File JAR or ZIP to be added */
225: public void addJARZIP(File jarZip) {
226: FileCustomEditorOperator editor = addJARZIP();
227: editor.setFileValue(jarZip);
228: editor.ok();
229: }
230:
231: /** sets complete classpath in custom editor
232: * @param classPathElements File[] array of directories or JAR or ZIP files
233: * to be included in classapth */
234: public void setClasspathValue(File[] classPathElements) {
235: removeAll();
236: for (int i = 0; i < classPathElements.length; i++) {
237: if (classPathElements[i].isFile())
238: addJARZIP(classPathElements[i]);
239: else
240: addDirectory(classPathElements[i]);
241: }
242: }
243:
244: /** sets complete classpath in custom editor
245: * @param classPathElements String[] array of paths of directories or JAR
246: * or ZIP files to be included in classapth */
247: public void setClasspathValue(String[] classPathElements) {
248: removeAll();
249: for (int i = 0; i < classPathElements.length; i++) {
250: String lower = classPathElements[i].toLowerCase();
251: if (lower.endsWith(".jar") || lower.endsWith(".zip"))
252: addJARZIP(classPathElements[i]);
253: else
254: addDirectory(classPathElements[i]);
255: }
256: }
257:
258: /** clicks on "Remove" JButton
259: * @throws TimeoutExpiredException when JButton not found
260: */
261: public void remove() {
262: btRemove().push();
263: }
264:
265: /** clicks on "Move Up" JButton
266: * @throws TimeoutExpiredException when JButton not found
267: */
268: public void moveUp() {
269: btMoveUp().push();
270: }
271:
272: /** removes given item from classpath
273: * @param value String item to be removed */
274: public void remove(String value) {
275: lstClasspath().selectItem(value);
276: remove();
277: }
278:
279: /** removes complete classpath */
280: public void removeAll() {
281: while (lstClasspath().getModel().getSize() > 0) {
282: lstClasspath().selectItem(0);
283: remove();
284: }
285: }
286:
287: /** returns complete class path from editor
288: * @return String[] class paths */
289: public String[] getClasspathValue() {
290: ArrayList data = new ArrayList();
291: ListModel model = lstClasspath().getModel();
292: for (int i = 0; i < model.getSize(); i++)
293: data.add(model.getElementAt(i).toString());
294: return (String[]) data.toArray(new String[data.size()]);
295: }
296:
297: /** Performs verification by accessing all sub-components */
298: public void verify() {
299: btAddDirectory();
300: btAddJARZIP();
301: btMoveDown();
302: btMoveUp();
303: btRemove();
304: lstClasspath();
305: }
306: }
|