diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java
index 07ad1673e..c212fc7e8 100644
--- a/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java
+++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java
@@ -114,6 +114,17 @@ public class ACSFactory {
}
+ /**
+ * Get an instance of the factory.
+ *
+ * @return Factory instance.
+ */
+ public static ACSFactory getInstance() {
+ if(_instance == null) {
+ _instance = new ACSFactory();
+ }
+ return _instance;
+ }
/**
* Load a project from the given XML file.
@@ -167,19 +178,33 @@ public class ACSFactory {
return (ACSProjectElement) doc.getDocumentElement();
}
- /**
- * Get an instance of the factory.
- *
- * @return Factory instance.
- */
- public static ACSFactory getInstance() {
- if(_instance == null) {
- _instance = new ACSFactory();
- }
- return _instance;
+ /**
+ * Create a new, empty project.
+ *
+ * @return Empty project.
+ */
+ public ACSProjectElement createProject() {
+ SimpleElementFactory fact = new SimpleElementFactory();
+ fact.addMapping(_elementMap, ACSFactory.class.getClassLoader());
+ XmlDocument doc = new XmlDocument();
+ doc.setElementFactory(fact);
+ return (ACSProjectElement) doc.createElement("project");
}
+ /**
+ * Create a new target.
+ *
+ * @param project Project the target is assigned to.
+ * @return New, unnamed target.
+ */
+ public ACSTargetElement createTarget(ACSProjectElement project) {
+ ACSTargetElement retval = (ACSTargetElement) project.
+ getOwnerDocument().createElement("target");
+ project.appendChild(retval);
+ return retval;
+ }
+
/**
* Test code
*
diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java
index 0edefc6d0..95b1ebe2c 100644
--- a/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java
+++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java
@@ -123,6 +123,8 @@ public abstract class ACSTreeNodeElement extends ACSElement
* Returns the parent TreeNode
of the receiver.
*/
public TreeNode getParent() {
+ // XXX this barfs becase a different "getParent()" is in Node
+ // interface. Need to fix...
return (TreeNode) getParent();
}
diff --git a/src/antidote/org/apache/tools/ant/gui/command/NewProjectCmd.java b/src/antidote/org/apache/tools/ant/gui/command/NewProjectCmd.java
index 0bff54835..e2ca6b484 100644
--- a/src/antidote/org/apache/tools/ant/gui/command/NewProjectCmd.java
+++ b/src/antidote/org/apache/tools/ant/gui/command/NewProjectCmd.java
@@ -53,6 +53,8 @@
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.core.AppContext;
+import org.apache.tools.ant.gui.event.NewProjectEvent;
+import org.apache.tools.ant.gui.acs.ACSProjectElement;
/**
* Command for creating a new project.
@@ -61,6 +63,10 @@ import org.apache.tools.ant.gui.core.AppContext;
* @author Simeon Fitch
*/
public class NewProjectCmd extends AbstractCommand {
+ /** New project count for this session. Used to create default names,
+ * numbered as a convenience. */
+ private static int _count = 1;
+
/**
* Standard ctor.
*
@@ -77,17 +83,12 @@ public class NewProjectCmd extends AbstractCommand {
*
*/
public void run() {
-/*
- FileFilter filter = new XMLFileFilter(getContext().getResources());
-
- JFileChooser chooser = new JFileChooser();
- chooser.addChoosableFileFilter(filter);
- int val = chooser.showOpenDialog(getContext().getParentFrame());
- if(val == JFileChooser.APPROVE_OPTION) {
- File selected = chooser.getSelectedFile();
- getContext().getEventBus().postEvent(
- new OpenRequestEvent(getContext(), selected));
- }
-*/
+ ACSProjectElement project =
+ getContext().getProjectManager().createNew();
+ project.setName(getContext().getResources().
+ getString(getClass(), "defName") + " " + _count++);
+ getContext().getEventBus().postEvent(
+ new NewProjectEvent(getContext(), project));
+
}
}
diff --git a/src/antidote/org/apache/tools/ant/gui/core/ProjectManager.java b/src/antidote/org/apache/tools/ant/gui/core/ProjectManager.java
index 9f97229e4..226bbf052 100644
--- a/src/antidote/org/apache/tools/ant/gui/core/ProjectManager.java
+++ b/src/antidote/org/apache/tools/ant/gui/core/ProjectManager.java
@@ -120,17 +120,32 @@ public class ProjectManager {
location = project.getLocation();
}
if(location == null) {
- // xxx Fix me.
- throw new IOException("xxx need a file name xxx");
+ // This shouldn't happen.
+ throw new IOException("Logic error: Save location mising.");
}
Writer out = null;
try {
- URLConnection connection = location.openConnection();
- connection.setDoInput(false);
- connection.setDoOutput(true);
- out = new OutputStreamWriter(connection.getOutputStream());
+ // XXX for some reason the URLConnection for protocol type "file"
+ // doesn't support output (at least that is what the exception
+ // says. I don't know if I'm doing something wrong or not, but
+ // since we need to handle files differently (which is fine
+ // right now since files are all we really support anyway.
+ if(location.getProtocol().equals("file")) {
+ out = new FileWriter(location.getFile());
+ }
+ else {
+ // XXX This is here for future support of FTP/HTTP and
+ // the like. JDBC will have to be dealt with differently.
+ URLConnection connection = location.openConnection();
+ connection.setDoInput(false);
+ connection.setDoOutput(true);
+ out = new OutputStreamWriter(connection.getOutputStream());
+ }
+
+ // Persist the project.
project.write(out);
+ out.flush();
project.setLocation(location);
}
finally {
@@ -170,7 +185,8 @@ public class ProjectManager {
* @return Unpopulated project.
*/
public ACSProjectElement createNew() {
- ACSProjectElement retval = null;
+ ACSProjectElement retval = ACSFactory.getInstance().createProject();
+ _projects.add(retval);
return retval;
}
diff --git a/src/antidote/org/apache/tools/ant/gui/core/ProjectSelectionMenu.java b/src/antidote/org/apache/tools/ant/gui/core/ProjectSelectionMenu.java
index 4fe53c8ac..a3b83f69d 100644
--- a/src/antidote/org/apache/tools/ant/gui/core/ProjectSelectionMenu.java
+++ b/src/antidote/org/apache/tools/ant/gui/core/ProjectSelectionMenu.java
@@ -59,6 +59,8 @@ import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
+import java.beans.PropertyChangeEvent;
+
/**
* Specialization of JMenu providing selectability of the currently
* open projects.
@@ -153,8 +155,12 @@ public class ProjectSelectionMenu extends JMenu {
/** Filter for project related events. */
private static class Filter implements BusFilter {
public boolean accept(EventObject event) {
+ // We want events related to projects.
return event instanceof ProjectSelectedEvent ||
- event instanceof ProjectClosedEvent;
+ event instanceof ProjectClosedEvent ||
+ (event instanceof PropertyChangeEvent &&
+ ((PropertyChangeEvent)event).getSource()
+ instanceof ACSProjectElement);
}
}
diff --git a/src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java b/src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java
index d24c388d7..5647e2563 100644
--- a/src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java
+++ b/src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java
@@ -168,6 +168,45 @@ public class ResourceManager {
}
}
+ /**
+ * Get the boolean resource for the given name. Case
+ * insensitive values of "yes" or "true" evaluate to TRUE.
+ * All others, including undefined resources evaluate to FALSE.
+ *
+ * @param name Name of the boolean resource.
+ * @return True if defined as true, false otherwise.
+ */
+ public boolean getBoolean(String name) {
+ return getBoolean(null, name);
+ }
+
+ /**
+ * Get the boolean resource for the given class. Case
+ * insensitive values of "yes" or "true" evaluate to TRUE.
+ * All others, including undefined resources evaluate to FALSE.
+ *
+ * @param clazz Class to get resource for.
+ * @param name Name of the boolean resource.
+ * @return True if defined as true, false otherwise.
+ */
+ public boolean getBoolean(Class clazz, String name) {
+ if(name == null) {
+ return false;
+ }
+
+ String key = getKey(clazz, name);
+
+ String value = "";
+ try {
+ value = _resources.getString(key);
+ }
+ catch(MissingResourceException ex) {
+ // Ignore missing resources as they imply false.
+ }
+
+ return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes");
+ }
+
/**
* Generate a composit key from the given class and key name.
*
diff --git a/src/antidote/org/apache/tools/ant/gui/resources/action.properties b/src/antidote/org/apache/tools/ant/gui/resources/action.properties
index 414a71905..298466a2a 100644
--- a/src/antidote/org/apache/tools/ant/gui/resources/action.properties
+++ b/src/antidote/org/apache/tools/ant/gui/resources/action.properties
@@ -3,7 +3,7 @@ menus=File, Build, Projects, Help
# Declare the list of known actions.
actions=\
- open, save, saveas, close, exit, about, \
+ new, open, save, saveas, close, exit, about, \
newTarget, newTask, newProperty \
startBuild, stopBuild
diff --git a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties
index 61e84576c..f0ab1d10a 100644
--- a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties
+++ b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties
@@ -1,5 +1,7 @@
# This is the general properties file for the Antidote application.
+#debug=true
+
# The following four module properties configure those properties that
# should be initialized and displayed by default by the GUI. If more
# than one module is configured for a property (as indicated providing
@@ -90,6 +92,7 @@ org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.xmlString=XML Code
org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.icon=task.gif
+org.apache.tools.ant.gui.command.NewProjectCmd.defName=New Project
#----------------------------------------------------------------------------
# About Description (NB: this is only a temporary approach).
@@ -105,8 +108,6 @@ org.apache.tools.ant.gui.About.message=\
Version: | {0} |
Date: | {1} |
Contributors: | \ -{2} |
Icons Copyright © 1998 Dean S. Jones (deansjones@hotmail.com)
\