001: /**
002: * Name........: LaunchEditor
003: * Description.: Provide convenient editing of a launch step.
004: * Author......: Timothy Wall
005: * E-Mail......: twall@users.sourceforge.net
006: */package abbot.editor.editors;
007:
008: import abbot.editor.widgets.*;
009: import abbot.script.*;
010: import abbot.i18n.*;
011: import abbot.util.*;
012:
013: import javax.swing.*;
014:
015: import java.awt.event.*;
016:
017: import java.lang.reflect.*;
018:
019: import java.util.*;
020:
021: /**
022: * Provide convenient editing of a launch step.
023: */
024: public class LaunchEditor extends CallEditor {
025:
026: public static final String HELP_DESC = Strings.get("FixClassname");
027:
028: private Launch launch;
029:
030: protected ArrayEditor classpath;
031:
032: private JCheckBox thread;
033:
034: private JButton importeclipse;
035:
036: /**
037: * Initializes this editor which is used to edit the supplied step.
038: *
039: * @param launch
040: * The launch step that will be edited.
041: */
042: public LaunchEditor(Launch launch) {
043:
044: super (launch);
045:
046: this .launch = launch;
047:
048: String[] paths = PathClassLoader.convertPathToFilenames(launch
049: .getClasspath());
050:
051: // FIXME extend ArrayEditor to use file choosing buttons instead of
052: // text fields alone
053: classpath = addArrayEditor(Strings.get("Classpath"), paths);
054: classpath.setName(TAG_CLASSPATH);
055:
056: thread = addCheckBox(Strings.get("Thread"), launch.isThreaded());
057: thread.setName(TAG_THREADED);
058:
059: // the stuff used to import an eclipse launch configuration
060: try {
061: Class classobj = Class
062: .forName("abbot.editor.editors.ImportButton");
063: Constructor constructor = classobj
064: .getConstructor(new Class[] { LaunchEditor.class,
065: Launch.class });
066: importeclipse = (JButton) constructor
067: .newInstance(new Object[] { this , launch });
068: add(importeclipse);
069: } catch (Throwable t) {
070: // just don't embed the import button
071: }
072:
073: }
074:
075: /**
076: * Display only the public static member functions.
077: */
078: protected String[] getMethodNames(Method[] mlist) {
079: ArrayList list = new ArrayList();
080: int mask = Modifier.PUBLIC | Modifier.STATIC;
081: for (int i = 0; i < mlist.length; i++) {
082: if ((mlist[i].getModifiers() & mask) == mask) {
083: list.add(mlist[i].getName());
084: }
085: }
086: return (String[]) list.toArray(new String[list.size()]);
087: }
088:
089: /**
090: * {@inheritDoc}
091: */
092: public void actionPerformed(ActionEvent evt) {
093: Object src = evt.getSource();
094: if (src == classpath) {
095: Object[] values = classpath.getValues();
096: String cp = null;
097: if (values.length > 0) {
098: StringBuffer buf = new StringBuffer();
099: for (int i = 0; i < values.length; i++) {
100: if (i > 0) {
101: buf
102: .append(System
103: .getProperty("path.separator"));
104: }
105: String path = (String) values[i];
106: if ("".equals(path)) {
107: path = ".";
108: }
109: buf.append(path);
110: }
111: cp = buf.toString();
112: }
113: launch.setClasspath(cp);
114: // Changing the classpath may affect whether the class/method are
115: // valid.
116: validateTargetClass();
117: validateMethod();
118: fireStepChanged();
119: } else if (src == thread) {
120: launch.setThreaded(!launch.isThreaded());
121: fireStepChanged();
122: } else {
123: super .actionPerformed(evt);
124: }
125:
126: // Remove the default placeholder description
127: if (HELP_DESC.equals(launch.getDescription())) {
128: launch.setDescription(null);
129: fireStepChanged();
130: }
131:
132: }
133:
134: } /* ENDCLASS */
|