metasim 01/01/08 11:43:26
Modified: src/antidote/org/apache/tools/ant/gui/command BuildCmd.java
CloseCmd.java EmacsNotifyCmd.java LoadFileCmd.java
SaveAsCmd.java SaveCmd.java
Log:
Added *internal* support multiple projects, and generalized the selection
state mechanism.
Revision Changes Path
1.7 +36 -5
jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java
Index: BuildCmd.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BuildCmd.java 2001/01/03 14:18:18 1.6
+++ BuildCmd.java 2001/01/08 19:43:20 1.7
@@ -53,17 +53,23 @@
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.core.AppContext;
-import org.apache.tools.ant.gui.core.ProjectProxy;
import org.apache.tools.ant.gui.event.ErrorEvent;
+import org.apache.tools.ant.gui.acs.ACSProjectElement;
+import org.apache.tools.ant.gui.acs.ACSTargetElement;
/**
* Starts an Ant build.
*
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
* @author Simeon Fitch
*/
public class BuildCmd extends AbstractCommand {
+ /** Project to build. */
+ private ACSProjectElement _project = null;
+ /** Targets to build. */
+ private ACSTargetElement[] _targets = null;
+
/**
* Standard ctor.
*
@@ -72,15 +78,40 @@
super(context);
}
+ /**
+ * Set the specific project to build (instead of the default).
+ *
+ * @param project Project to build.
+ */
+ public void setProject(ACSProjectElement project) {
+ _project = project;
+ }
+
+ /**
+ * Set the specific targets to build (instead of the default).
+ *
+ * @param targets Array of targets to build.
+ */
+ public void setTargets(ACSTargetElement[] targets) {
+ _targets = targets;
+ }
+
/**
* Start the Ant build.
*
*/
public void run() {
- ProjectProxy project = getContext().getProject();
- if(project != null) {
+ if(_project == null) {
+ _project =
getContext().getSelectionManager().getSelectedProject();
+ }
+
+ if(_targets == null) {
+ _targets =
getContext().getSelectionManager().getSelectedTargets();
+ }
+
+ if(_project != null) {
try {
- project.build();
+ getContext().getProjectManager().build(_project, _targets);
}
catch(Throwable ex) {
getContext().getEventBus().postEvent(
1.7 +31 -4
jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java
Index: CloseCmd.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CloseCmd.java 2001/01/03 14:18:19 1.6
+++ CloseCmd.java 2001/01/08 19:43:21 1.7
@@ -54,16 +54,21 @@
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.core.AppContext;
import org.apache.tools.ant.gui.event.ProjectClosedEvent;
+import org.apache.tools.ant.gui.event.ProjectSelectedEvent;
+import org.apache.tools.ant.gui.acs.ACSProjectElement;
/**
* Handler for the close command.
*
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
* @author Simeon Fitch
*/
public class CloseCmd extends AbstractCommand {
+ /** Project to close. */
+ private ACSProjectElement _project = null;
+
/**
* Standard constructor.
*
@@ -72,13 +77,35 @@
super(context);
}
+ /**
+ * Set the specific project to close (instead of the default).
+ *
+ * @param project Project to close.
+ */
+ public void setProject(ACSProjectElement project) {
+ _project = project;
+ }
+
/**
* Send a close event to the parent window.
*
*/
public void run() {
- getContext().setProject(null);
- getContext().getEventBus().postEvent(
- new ProjectClosedEvent(getContext()));
+ if(_project == null) {
+ _project =
getContext().getSelectionManager().getSelectedProject();
+ }
+
+ if(_project != null) {
+ getContext().getProjectManager().close(_project);
+ getContext().getEventBus().postEvent(
+ new ProjectClosedEvent(getContext()));
+
+ ACSProjectElement[] open =
+ getContext().getProjectManager().getOpen();
+ if(open != null && open.length > 0) {
+ getContext().getEventBus().postEvent(
+ new ProjectSelectedEvent(getContext(), open[0]));
+ }
+ }
}
}
1.6 +5 -4
jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java
Index: EmacsNotifyCmd.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- EmacsNotifyCmd.java 2001/01/03 14:18:19 1.5
+++ EmacsNotifyCmd.java 2001/01/08 19:43:21 1.6
@@ -59,7 +59,7 @@
* Toggle on or off the sending of error events to emacs so that
* it can display the source of the error.
*
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
* @author Simeon Fitch
*/
public class EmacsNotifyCmd extends AbstractCommand {
@@ -80,11 +80,12 @@
*
*/
public void run() {
- if(getContext().isRegisteredBuildListener(_notifier)) {
- getContext().removeBuildListener(_notifier);
+ if(getContext().getProjectManager().
+ isRegisteredBuildListener(_notifier)) {
+ getContext().getProjectManager().removeBuildListener(_notifier);
}
else {
- getContext().addBuildListener(_notifier);
+ getContext().getProjectManager().addBuildListener(_notifier);
}
}
}
1.8 +7 -4
jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java
Index: LoadFileCmd.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- LoadFileCmd.java 2001/01/03 14:18:19 1.7
+++ LoadFileCmd.java 2001/01/08 19:43:22 1.8
@@ -53,15 +53,16 @@
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.core.AppContext;
-import org.apache.tools.ant.gui.core.ProjectProxy;
import org.apache.tools.ant.gui.event.ErrorEvent;
+import org.apache.tools.ant.gui.event.ProjectSelectedEvent;
+import org.apache.tools.ant.gui.acs.ACSProjectElement;
import java.io.File;
import java.io.IOException;
/**
* Command for reading in a build file and initializing the data model.
*
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
* @author Simeon Fitch
*/
public class LoadFileCmd extends AbstractCommand {
@@ -100,8 +101,10 @@
}
else {
try {
- ProjectProxy project = new ProjectProxy(getContext(), _file);
- getContext().setProject(project);
+ ACSProjectElement project =
+ getContext().getProjectManager().open(_file);
+ getContext().getEventBus().postEvent(
+ new ProjectSelectedEvent(getContext(), project));
}
catch(Exception ex) {
String message = getContext().getResources().getMessage(
1.6 +47 -36
jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java
Index: SaveAsCmd.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SaveAsCmd.java 2001/01/03 14:18:19 1.5
+++ SaveAsCmd.java 2001/01/08 19:43:23 1.6
@@ -53,26 +53,28 @@
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.core.AppContext;
-import org.apache.tools.ant.gui.core.ProjectProxy;
import org.apache.tools.ant.gui.event.ErrorEvent;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
+import org.apache.tools.ant.gui.acs.ACSProjectElement;
+import java.io.*;
import org.apache.tools.ant.gui.core.XMLFileFilter;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.JOptionPane;
+import java.net.URL;
+import java.net.MalformedURLException;
/**
* Command for doing a "Save as" type of save.
*
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
* @author Simeon Fitch
*/
public class SaveAsCmd extends AbstractCommand {
/** File to save to. */
- private File _file = null;
+ private URL _location = null;
+ /** Project to save. */
+ private ACSProjectElement _project = null;
/**
* Standard ctor.
@@ -84,14 +86,23 @@
}
/**
- * Set the file to save to.
+ * Set the location to save to
*
- * @param file File to save to.
+ * @param location location to save to.
*/
- public void setFile(File file) {
- _file = file;
+ public void setLocation(URL location) {
+ _location = location;
}
+ /**
+ * Set the specific project to save (instead of the default).
+ *
+ * @param project Project to save.
+ */
+ public void setProject(ACSProjectElement project) {
+ _project = project;
+ }
+
/**
* Save the project to the current file name.
@@ -100,58 +111,58 @@
public void run() {
FileFilter filter = new XMLFileFilter(getContext().getResources());
- ProjectProxy project = getContext().getProject();
- if(project != null) {
- if(_file == null) {
- // XXX code here to select a file to save to.
+ if(_project == null) {
+ _project =
getContext().getSelectionManager().getSelectedProject();
+ }
+
+ if(_project != null) {
+ // If no location is specified, then this truly is a SaveAs
+ // command. Provide the user the UI to select the output.
+ if(_location == null) {
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(filter);
int val = chooser.showSaveDialog(
getContext().getParentFrame());
if(val == JFileChooser.APPROVE_OPTION) {
- _file = chooser.getSelectedFile();
- if(_file.exists()) {
+ File file = chooser.getSelectedFile();
+ if(file.exists()) {
String title = getContext().getResources().
getString(SaveCmd.class, "title");
String message = getContext().getResources().
getMessage(SaveCmd.class, "overwrite",
- new Object[] {_file.toString()});
+ new Object[] { file.toString()});
val = JOptionPane.showConfirmDialog(
getContext().getParentFrame(), message, title,
JOptionPane.YES_NO_OPTION);
// If cancelled unset file.
- if(val != JOptionPane.YES_OPTION) {
- _file = null;
+ if(val == JOptionPane.YES_OPTION) {
+ try {
+ _location = new URL(
+ "file", null, file.getAbsolutePath());
+ }
+ catch(MalformedURLException ex) {
+ // Shouldn't happen. Save will just not
+ // happen.
+ ex.printStackTrace();
+ }
}
}
}
}
- if(_file != null) {
- project.setFile(_file);
- FileWriter out = null;
+ // If a location is now available, do the save operation.
+ if(_location != null) {
try {
- out = new FileWriter(_file);
- project.write(out);
+ getContext().getProjectManager().saveAs(
+ _project, _location);
}
catch(IOException ex) {
String message = getContext().getResources().getMessage(
SaveCmd.class, "saveError",
- new Object[] { _file.toString() });
+ new Object[] { _location.toString() });
getContext().getEventBus().
postEvent(new ErrorEvent(getContext(), message));
- }
- finally {
- if (out != null) {
- try {
- out.flush();
- out.close();
- }
- catch(IOException ex) {
- // Intentionally ignored.
- }
- }
}
}
}
1.6 +7 -2
jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java
Index: SaveCmd.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SaveCmd.java 2001/01/03 14:18:19 1.5
+++ SaveCmd.java 2001/01/08 19:43:23 1.6
@@ -53,11 +53,12 @@
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.core.AppContext;
+import org.apache.tools.ant.gui.acs.ACSProjectElement;
/**
* Command to execute the saving of the current build file.
*
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
* @author Simeon Fitch
*/
public class SaveCmd extends SaveAsCmd {
@@ -69,6 +70,10 @@
*/
public SaveCmd(AppContext context) {
super(context);
- setFile(context.getProject().getFile());
+ ACSProjectElement project =
+ getContext().getSelectionManager().getSelectedProject();
+ if(project != null) {
+ setLocation(project.getLocation());
+ }
}
}