Browse Source

Rewrote command handling infrastructure, allowing for dynamic mapping

between actions and commands rather than the original hard-coded
mapping. Associations specified in the actions.properties file under
the "<actionID>.command" property.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268232 13f79535-47bb-0310-9956-ffa450edef68
master
metasim 24 years ago
parent
commit
8785091ee1
25 changed files with 469 additions and 281 deletions
  1. +6
    -0
      src/antidote/TODO
  2. +1
    -0
      src/antidote/build.xml
  3. +80
    -2
      src/antidote/org/apache/tools/ant/gui/ActionManager.java
  4. +24
    -0
      src/antidote/org/apache/tools/ant/gui/AntAction.java
  5. +10
    -0
      src/antidote/org/apache/tools/ant/gui/AppContext.java
  6. +8
    -35
      src/antidote/org/apache/tools/ant/gui/EventResponder.java
  7. +4
    -2
      src/antidote/org/apache/tools/ant/gui/Main.java
  8. +5
    -10
      src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java
  9. +99
    -0
      src/antidote/org/apache/tools/ant/gui/command/AbstractCommand.java
  10. +6
    -12
      src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java
  11. +5
    -12
      src/antidote/org/apache/tools/ant/gui/command/ChangeLookAndFeelCmd.java
  12. +6
    -12
      src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java
  13. +18
    -3
      src/antidote/org/apache/tools/ant/gui/command/Command.java
  14. +36
    -15
      src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java
  15. +6
    -17
      src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java
  16. +4
    -12
      src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java
  17. +19
    -16
      src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java
  18. +2
    -2
      src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java
  19. +9
    -18
      src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java
  20. +97
    -6
      src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java
  21. +7
    -104
      src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java
  22. +1
    -1
      src/antidote/org/apache/tools/ant/gui/event/AntEvent.java
  23. +3
    -1
      src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java
  24. +4
    -1
      src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java
  25. +9
    -0
      src/antidote/org/apache/tools/ant/gui/resources/action.properties

+ 6
- 0
src/antidote/TODO View File

@@ -1,4 +1,10 @@
TODO List:
* Implement some for of refid hyperlinking functionality.

* Provide some sort of class path debugging support.

* Eat own dog food more.

* Dispatch tree node change events when the properties editor changes a
node value. This will make sure that the node gets displayed correctly in
the project navigator.


+ 1
- 0
src/antidote/build.xml View File

@@ -24,6 +24,7 @@
<property name="ant.dist.dir" value="../../../dist/ant"/>

<path id="classpath">
<pathelement location="${lib.dir}/ant.jar"/>
</path>
<property name="packages" value="org.apache.tools.ant.gui.*"/>
<property name="manifest" value="etc/manifest"/>


+ 80
- 2
src/antidote/org/apache/tools/ant/gui/ActionManager.java View File

@@ -1,3 +1,50 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (C) 2000 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Ant" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/

/*
* The Apache Software License, Version 1.1
*
@@ -54,6 +101,7 @@
package org.apache.tools.ant.gui;

import org.apache.tools.ant.gui.event.*;
import org.apache.tools.ant.gui.command.Command;
import javax.swing.*;
import java.util.*;

@@ -106,9 +154,7 @@ public class ActionManager {
// For each action we need to add the reverse event trigger
// lookup.
_mapper.addAction(action);

}

}

/**
@@ -212,6 +258,38 @@ public class ActionManager {
return retval;
}

/**
* Get the command assocaited with the Action with the given id.
*
* @param actionID Id of action to get command for.
* @return Command associated with action, or null if none available.
*/
public Command getActionCommand(String actionID, AppContext context) {
Command retval = null;
AntAction action = (AntAction) _actions.get(actionID);
if(action != null) {
Class clazz = action.getCommandClass();
if(clazz != null) {
try {
retval = (Command) clazz.newInstance();
retval.setContext(context);
}
catch(Exception ex) {
// XXX log me.
ex.printStackTrace();
}
}
}
return retval;
}


/**
* Add tool tip, Mnemonic, etc.
*
* @param button Button to work on.
* @param action Associated action.
*/
private void addNiceStuff(AbstractButton button, AntAction action) {
// Set the action command so that it is consitent
// no matter what language the display is in.


+ 24
- 0
src/antidote/org/apache/tools/ant/gui/AntAction.java View File

@@ -76,6 +76,7 @@ public class AntAction extends AbstractAction {
public static final String ENABLE_ON = "enableOn";
public static final String DISABLE_ON = "disableOn";
public static final String TOGGLE = "toggle";
public static final String COMMAND = "command";

/** Property resources. */
private ResourceBundle _resources = null;
@@ -127,6 +128,19 @@ public class AntAction extends AbstractAction {
_toggle = Boolean.valueOf(toggle).booleanValue();
}

// See if there is a command associated with the action.
String command = getString(COMMAND);
if(command != null) {
try {
Class cmd = Class.forName(command);
putValue(COMMAND, cmd);
}
catch(Exception ex) {
// XXX log me.
ex.printStackTrace();
}
}

// Add an icon if any (which means it'll show up on the tool bar).
String iconName = getString("icon");
if(iconName != null) {
@@ -290,6 +304,16 @@ public class AntAction extends AbstractAction {
return _toggle;
}


/**
* Get the assciated command class.
*
* @return Command class.
*/
public Class getCommandClass() {
return (Class) getValue(COMMAND);
}

/**
* Pass the action on to the EventBus.
*


+ 10
- 0
src/antidote/org/apache/tools/ant/gui/AppContext.java View File

@@ -154,6 +154,16 @@ public class AppContext {
_buildListeners.remove(l);
}

/**
* Determine if the given BuildListener is registered.
*
* @param l Listener to test for.
* @return True if listener has been added, false if unknown.
*/
public boolean isRegisteredBuildListener(BuildListener l) {
return _buildListeners.contains(l);
}

/**
* Get the set of current build listeners.
*


+ 8
- 35
src/antidote/org/apache/tools/ant/gui/EventResponder.java View File

@@ -114,44 +114,17 @@ class EventResponder {
public boolean eventPosted(EventObject event) {
String command = ((ActionEvent)event).getActionCommand();

// XXX turn this switch structure into a command
// lookup using an initialized hash table.
if(command.equals(OpenCmd.ACTION_NAME)) {
new OpenCmd(_context).execute();
}
else if(command.equals(SaveCmd.ACTION_NAME)) {
new SaveCmd(_context).execute();
}
else if(command.equals(SaveAsCmd.ACTION_NAME)) {
new SaveAsCmd(_context).execute();
}
else if(command.equals(BuildCmd.ACTION_NAME)) {
new BuildCmd(_context).execute();
}
else if(command.equals(CloseCmd.ACTION_NAME)) {
new CloseCmd(_context).execute();
}
else if(command.equals(ExitCmd.ACTION_NAME)) {
new ExitCmd(_context).execute();
}
else if(command.equals(AboutCmd.ACTION_NAME)) {
new AboutCmd(_context).execute();
}
else if(command.equals(ChangeLookAndFeelCmd.ACTION_NAME)) {
new ChangeLookAndFeelCmd(_context).execute();
}
else if(command.equals(ChangeLookAndFeelCmd.ACTION_NAME)) {
new ChangeLookAndFeelCmd(_context).execute();
}
else if(command.equals(EmacsNotifyCmd.ACTION_NAME)) {
AbstractButton source = (AbstractButton) event.getSource();
new EmacsNotifyCmd(_context, source.isSelected()).execute();
Command cmd =
_context.getActions().getActionCommand(command, _context);
if(cmd != null) {
cmd.run();
return false;
}
else {
// XXX log me.
System.err.println("Unhandled action: " + command);
return true;
}
return true;
}
}

@@ -186,8 +159,8 @@ class EventResponder {
public boolean eventPosted(EventObject event) {
AntEvent e = (AntEvent) event;
Command cmd = e.createDefaultCmd();
cmd.execute();
return true;
cmd.run();
return cmd instanceof NoOpCmd;
}
}



+ 4
- 2
src/antidote/org/apache/tools/ant/gui/Main.java View File

@@ -96,11 +96,13 @@ public class Main {

f.setVisible(true);


// XXX this will change once full command line argument parsing
// is supported.
if(args.length > 0) {
new LoadFileCmd(context, new File(args[0])).execute();
LoadFileCmd load = new LoadFileCmd();
load.setFile(new File(args[0]));
load.setContext(context);
load.run();
}
}
catch(Exception ex) {


+ 5
- 10
src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java View File

@@ -64,25 +64,20 @@ import java.awt.event.WindowEvent;
* @version $Revision$
* @author Simeon Fitch
*/
public class AboutCmd implements Command {
/** Name of the about command. */
public static final String ACTION_NAME = "about";
/** Application context. */
private AppContext _context = null;
public class AboutCmd extends AbstractCommand {

/**
* Standard constructor.
*
* @param window
*/
public AboutCmd(AppContext context) {
_context = context;
public AboutCmd() {
}

/**
* Show the about box.
*
*/
public void execute() {
new About(_context);
public void run() {
new About(getContext());
}
}

+ 99
- 0
src/antidote/org/apache/tools/ant/gui/command/AbstractCommand.java View File

@@ -0,0 +1,99 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.AppContext;


/**
* Convenience base class for Command implementations.
*
* @version $Revision$
* @author Simeon Fitch
*/
public abstract class AbstractCommand implements Command {
/** Application context. */
private AppContext _context = null;

/**
* Default ctor.
*
*/
protected AbstractCommand() {
}

/**
* Set the application context.
*
* @param context Application context.
*/
public void setContext(AppContext context) {
_context = context;
}

/**
* Get the application context that was provided to setContext();
*
* @return Application context.
*/
protected AppContext getContext() {
return _context;
}

/**
* Run the command. From interface Runnable.
*
*/
public abstract void run();

}

+ 6
- 12
src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java View File

@@ -62,34 +62,28 @@ import org.apache.tools.ant.gui.event.ErrorEvent;
* @version $Revision$
* @author Simeon Fitch
*/
public class BuildCmd implements Command {
/** Name of the action the command maps to. */
public static final String ACTION_NAME = "startBuild";

/** The application context */
private AppContext _context = null;
public class BuildCmd extends AbstractCommand {

/**
* Standard ctor.
*
* @param context Application context.
*/
public BuildCmd(AppContext context) {
_context = context;
public BuildCmd() {
}

/**
* Start the Ant build.
*
*/
public void execute() {
ProjectProxy project = _context.getProject();
public void run() {
ProjectProxy project = getContext().getProject();
if(project != null) {
try {
project.build();
}
catch(Throwable ex) {
_context.getEventBus().postEvent(new ErrorEvent(_context, ex));
getContext().getEventBus().postEvent(
new ErrorEvent(getContext(), ex));
}
}
}


+ 5
- 12
src/antidote/org/apache/tools/ant/gui/command/ChangeLookAndFeelCmd.java View File

@@ -60,28 +60,21 @@ import org.apache.tools.ant.gui.ChangeLookAndFeel;
*
* @version $Revision$
* @author Erik Meade
* @author Simeon Fitch
*/
public class ChangeLookAndFeelCmd implements Command {
/** Name of the action the command maps to. */
public static final String ACTION_NAME = "changeLookAndFeel";

/** The application context */
private AppContext _context = null;

public class ChangeLookAndFeelCmd extends AbstractCommand {
/**
* Standard ctor.
*
* @param context Application context.
*/
public ChangeLookAndFeelCmd(AppContext context) {
_context = context;
public ChangeLookAndFeelCmd() {
}

/**
* Successfully do nothing.
*
*/
public void execute() {
new ChangeLookAndFeel(_context);
public void run() {
new ChangeLookAndFeel(getContext());
}
}

+ 6
- 12
src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java View File

@@ -62,28 +62,22 @@ import org.apache.tools.ant.gui.event.ProjectClosedEvent;
* @version $Revision$
* @author Simeon Fitch
*/
public class CloseCmd implements Command {
/** Name of the exit command. */
public static final String ACTION_NAME = "close";

/** Application context. */
private AppContext _context = null;
public class CloseCmd extends AbstractCommand {

/**
* Standard constructor.
*
* @param window
*/
public CloseCmd(AppContext context) {
_context = context;
public CloseCmd() {
}

/**
* Send a close event to the parent window.
*
*/
public void execute() {
_context.setProject(null);
_context.getEventBus().postEvent(new ProjectClosedEvent(_context));
public void run() {
getContext().setProject(null);
getContext().getEventBus().postEvent(
new ProjectClosedEvent(getContext()));
}
}

+ 18
- 3
src/antidote/org/apache/tools/ant/gui/command/Command.java View File

@@ -52,13 +52,28 @@
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.AppContext;



/**
* Interface for commands. Details TBD
* Interface for commands. Implementation needs to have a default ctor.
* Details TBD
*
* @version $Revision$
* @author Simeon Fitch
*/
public interface Command {
public void execute();
public interface Command extends Runnable {
/**
* Set the application context.
*
* @param context Application context.
*/
public void setContext(AppContext context);

/**
* Run the command. From interface Runnable.
*
*/
public void run();
}

+ 36
- 15
src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java View File

@@ -65,25 +65,28 @@ import java.awt.event.ActionEvent;
* @version $Revision$
* @author Simeon H.K. Fitch
*/
public class DisplayErrorCmd implements Command {
/** The application context */
private AppContext _context = null;
public class DisplayErrorCmd extends AbstractCommand {
/** Text description of error. */
private String _message = null;
/** Throwable associated with the error. */
private Throwable _ex = null;

/**
* Default ctor.
*
*/
public DisplayErrorCmd() {
}

/**
* Standard constuctor.
*
* @param context Application context.
* @param message Error message.
* @param ex Throwable assocated with error.
*/
public DisplayErrorCmd(AppContext context, String message, Throwable ex) {
_context = context;
_message = message;
_ex = ex;
public DisplayErrorCmd(String message, Throwable ex) {
setMessage(message);
setThrowable(_ex);
}

/**
@@ -92,20 +95,38 @@ public class DisplayErrorCmd implements Command {
* @param context Application context.
* @param message Error message.
*/
public DisplayErrorCmd(AppContext context, String message) {
this(context, message, null);
public DisplayErrorCmd(String message) {
this(message, null);
}

/**
* Set the error message.
*
* @param message Error message.
*/
public void setMessage(String message) {
_message = message;
}

/**
* Set the throwable associated with the error.
*
* @param ex Throwable associated with the error.
*/
public void setThrowable(Throwable ex) {
_ex = ex;
}

/**
* Display the error.
*
*/
public void execute() {
// XXX change this so that exceptions can be optionally shown.
String title = _context.getResources().getString(getClass(), "title");
public void run() {
String title = getContext().getResources().
getString(getClass(), "title");

JOptionPane.showMessageDialog(
_context.getParentFrame(), new MsgPanel(),
getContext().getParentFrame(), new MsgPanel(),
title, JOptionPane.ERROR_MESSAGE);
}

@@ -116,7 +137,7 @@ public class DisplayErrorCmd implements Command {
add(new JLabel(_message));
if(_ex != null) {
add(new JLabel(_ex.getMessage()));
JButton b = new JButton(_context.getResources().
JButton b = new JButton(getContext().getResources().
getString(DisplayErrorCmd.class,
"expand"));
b.addActionListener(this);


+ 6
- 17
src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java View File

@@ -62,39 +62,28 @@ import org.apache.tools.ant.gui.ide.EmacsNotifier;
* @version $Revision$
* @author Simeon Fitch
*/
public class EmacsNotifyCmd implements Command {
/** Action command. */
public static final String ACTION_NAME = "notifyEmacs";

public class EmacsNotifyCmd extends AbstractCommand {
/** A global notifier can be used as it stores no state. */
private static EmacsNotifier _notifier = new EmacsNotifier();
/** Application context. */
private AppContext _context = null;
/** State notification should be in. */
private boolean _notify = false;

/**
* Standard ctor.
*
* @param context Application context.
* @param state True if notifying on, false for notifying off.
*/
public EmacsNotifyCmd(AppContext context, boolean state) {
_context = context;
_notify = state;
public EmacsNotifyCmd() {
}

/**
* Turn on or off the notifying of emacs.
*
*/
public void execute() {
if(_notify) {
_context.addBuildListener(_notifier);
public void run() {
if(getContext().isRegisteredBuildListener(_notifier)) {
getContext().removeBuildListener(_notifier);
}
else {
_context.removeBuildListener(_notifier);
getContext().addBuildListener(_notifier);
}
}
}

+ 4
- 12
src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java View File

@@ -65,28 +65,20 @@ import java.awt.event.WindowEvent;
* @version $Revision$
* @author Simeon Fitch
*/
public class ExitCmd implements Command {
/** Name of the exit command. */
public static final String ACTION_NAME = "exit";

/** Window to send close event to. */
private Window _window = null;

public class ExitCmd extends AbstractCommand {
/**
* Standard constructor.
*
* @param context Application context.
*/
public ExitCmd(AppContext context) {
_window = context.getParentFrame();
public ExitCmd() {
}

/**
* Send a close event to the parent window.
*
*/
public void execute() {
public void run() {
// Manually send a window close event to the window.
WindowUtils.sendCloseEvent(_window);
WindowUtils.sendCloseEvent(getContext().getParentFrame());
}
}

+ 19
- 16
src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java View File

@@ -64,20 +64,23 @@ import java.io.IOException;
* @version $Revision$
* @author Simeon Fitch
*/
public class LoadFileCmd implements Command {
/** The application context */
private AppContext _context = null;
public class LoadFileCmd extends AbstractCommand {
/** The file to load. */
private File _file = null;

/**
* Standard ctor.
*
* @param context Application context.
* @param file The file to load.
*/
public LoadFileCmd(AppContext context, File file) {
_context = context;
public LoadFileCmd() {
}

/**
* Set the file to load.
*
* @param file File to load.
*/
public void setFile(File file) {
_file = file;
}

@@ -85,26 +88,26 @@ public class LoadFileCmd implements Command {
* Open the file and load it.
*
*/
public void execute() {
public void run() {
if(!_file.exists()) {
String message = _context.getResources().getMessage(
String message = getContext().getResources().getMessage(
getClass(), "noFile", new Object[] { _file.toString() });

_context.getEventBus().
postEvent(new ErrorEvent(_context, message));
getContext().getEventBus().
postEvent(new ErrorEvent(getContext(), message));
}
else {
try {
ProjectProxy project = new ProjectProxy(_context, _file);
_context.setProject(project);
ProjectProxy project = new ProjectProxy(getContext(), _file);
getContext().setProject(project);
}
catch(Exception ex) {
String message = _context.getResources().getMessage(
String message = getContext().getResources().getMessage(
getClass(), "loadError",
new Object[] { _file.toString() });

_context.getEventBus().
postEvent(new ErrorEvent(_context, message, ex));
getContext().getEventBus().
postEvent(new ErrorEvent(getContext(), message, ex));
}
}
}


+ 2
- 2
src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java View File

@@ -59,10 +59,10 @@ package org.apache.tools.ant.gui.command;
* @version $Revision$
* @author Simeon Fitch
*/
public class NoOpCmd implements Command {
public class NoOpCmd extends AbstractCommand {
/**
* Successfully do nothing.
*
*/
public void execute() {}
public void run() {}
}

+ 9
- 18
src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java View File

@@ -67,23 +67,12 @@ import java.io.File;
* @version $Revision$
* @author Simeon Fitch
*/
public class OpenCmd implements Command {
/** Name of the action the command maps to. */
public static final String ACTION_NAME = "open";

/** The application context */
private AppContext _context = null;
/** Filter for showing only XML files. */
private FileFilter _filter = null;

public class OpenCmd extends AbstractCommand {
/**
* Standard ctor.
*
* @param context Application context.
*/
public OpenCmd(AppContext context) {
_context = context;
_filter = new XMLFileFilter(_context.getResources());
public OpenCmd() {
}

/**
@@ -92,14 +81,16 @@ public class OpenCmd implements Command {
* operation be completed.
*
*/
public void execute() {
public void run() {
FileFilter filter = new XMLFileFilter(getContext().getResources());

JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(_filter);
int val = chooser.showOpenDialog(_context.getParentFrame());
chooser.addChoosableFileFilter(filter);
int val = chooser.showOpenDialog(getContext().getParentFrame());
if(val == JFileChooser.APPROVE_OPTION) {
File selected = chooser.getSelectedFile();
_context.getEventBus().postEvent(
new OpenRequestEvent(_context, selected));
getContext().getEventBus().postEvent(
new OpenRequestEvent(getContext(), selected));
}
}
}

+ 97
- 6
src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java View File

@@ -53,6 +53,15 @@
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.AppContext;
import org.apache.tools.ant.gui.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.XMLFileFilter;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.JOptionPane;


/**
@@ -61,16 +70,98 @@ import org.apache.tools.ant.gui.AppContext;
* @version $Revision$
* @author Simeon Fitch
*/
public class SaveAsCmd extends SaveCmd {
/** Name of the action the command maps to. */
public static final String ACTION_NAME = "saveas";
public class SaveAsCmd extends AbstractCommand {
/** File to save to. */
private File _file = null;

/**
* Standard ctor.
*
* @param context Application context.
*/
public SaveAsCmd(AppContext context) {
super(context, null);
public SaveAsCmd() {
}

/**
* Set the file to save to.
*
* @param file File to save to.
*/
public void setFile(File file) {
_file = file;
}


/**
* Save the project to the current file name.
*
*/
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.
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(filter);
int val = chooser.showSaveDialog(
getContext().getParentFrame());
if(val == JFileChooser.APPROVE_OPTION) {
_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()});
val = JOptionPane.showConfirmDialog(
getContext().getParentFrame(), message, title,
JOptionPane.YES_NO_OPTION);
// If cancelled unset file.
if(val != JOptionPane.YES_OPTION) {
_file = null;
}
}
}
}
if(_file != null) {
project.setFile(_file);
FileWriter out = null;
try {
out = new FileWriter(_file);
project.write(out);
}
catch(IOException ex) {
String message = getContext().getResources().getMessage(
SaveCmd.class, "saveError",
new Object[] { _file.toString() });
getContext().getEventBus().
postEvent(new ErrorEvent(getContext(), message));
}
finally {
if (out != null) {
try {
out.flush();
out.close();
}
catch(IOException ex) {
// Intentionally ignored.
}
}
}
}
}
else {
// We shouldn't ever get here.
String message = getContext().getResources().getString(
SaveCmd.class, "noProject");
getContext().getEventBus().
postEvent(new ErrorEvent(getContext(), message));
}
}

}

+ 7
- 104
src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java View File

@@ -53,15 +53,6 @@
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.AppContext;
import org.apache.tools.ant.gui.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.XMLFileFilter;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.JOptionPane;

/**
* Command to execute the saving of the current build file.
@@ -69,106 +60,18 @@ import javax.swing.JOptionPane;
* @version $Revision$
* @author Simeon Fitch
*/
public class SaveCmd implements Command {
/** Name of the action the command maps to. */
public static final String ACTION_NAME = "save";
public class SaveCmd extends SaveAsCmd {

/** The application context */
private AppContext _context = null;
/** Filter for showing only XML files. */
private FileFilter _filter = null;
/** File to save to. */
private File _file = null;

/**
* Standard ctor with file.
*
* @param context Application context.
* @param file File to save to, or null.
*/
public SaveCmd(AppContext context, File file) {
_context = context;
_filter = new XMLFileFilter(_context.getResources());
_file = file;
public SaveCmd() {
}

/**
* Standard ctor.
*
* @param context Application context.
*/
public SaveCmd(AppContext context) {
this(context, context.getProject() == null ? null :
context.getProject().getFile());
}

/**
* Save the project to the current file name.
* Set the application context.
*
* @param context Application context.
*/
public void execute() {
ProjectProxy project = _context.getProject();
if(project != null) {
if(_file == null) {
// XXX code here to select a file to save to.
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(_filter);
int val = chooser.showSaveDialog(_context.getParentFrame());
if(val == JFileChooser.APPROVE_OPTION) {
_file = chooser.getSelectedFile();
if(_file.exists()) {
String title = _context.getResources().getString(
SaveCmd.class, "title");
String message = _context.getResources().getMessage(
SaveCmd.class, "overwrite",
new Object[] {_file.toString()});
val = JOptionPane.showConfirmDialog(
_context.getParentFrame(), message, title,
JOptionPane.YES_NO_OPTION);
// If cancelled unset file.
if(val != JOptionPane.YES_OPTION) {
_file = null;
}
}
}
}
if(_file != null) {
project.setFile(_file);
FileWriter out = null;
try {
out = new FileWriter(_file);
project.write(out);
}
catch(IOException ex) {
String message = _context.getResources().getMessage(
SaveCmd.class, "saveError",
new Object[] { _file.toString() });
_context.getEventBus().
postEvent(new ErrorEvent(_context, message));
}
finally {
if (out != null) {
try {
out.flush();
out.close();
}
catch(IOException ex) {
// Intentionally ignored.
}
}
}
}
}
else {
// We shouldn't ever get here.
String message = _context.getResources().getString(
SaveCmd.class, "noProject");
_context.getEventBus().
postEvent(new ErrorEvent(_context, message));
}
public void setContext(AppContext context) {
super.setContext(context);
setFile(context.getProject().getFile());
}
}

+ 1
- 1
src/antidote/org/apache/tools/ant/gui/event/AntEvent.java View File

@@ -81,7 +81,7 @@ public abstract class AntEvent extends EventObject {
*
* @return Application context.
*/
protected AppContext getAppContext() {
protected AppContext getContext() {
return (AppContext) getSource();
}



+ 3
- 1
src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java View File

@@ -109,7 +109,9 @@ public class ErrorEvent extends AntEvent {
* @return Command representing an appropriate response to this event.
*/
public Command createDefaultCmd() {
return new DisplayErrorCmd(getAppContext(), _message, _ex);
Command retval = new DisplayErrorCmd(_message, _ex);
retval.setContext(getContext());
return retval;
}

/**


+ 4
- 1
src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java View File

@@ -85,7 +85,10 @@ public class OpenRequestEvent extends AntEvent {
* @return Load command.
*/
public Command createDefaultCmd() {
return new LoadFileCmd(getAppContext(), _file);
LoadFileCmd load = new LoadFileCmd();
load.setFile(_file);
load.setContext(getContext());
return load;
}
}



+ 9
- 0
src/antidote/org/apache/tools/ant/gui/resources/action.properties View File

@@ -14,12 +14,14 @@ open.parentMenuName=File
open.icon=open.gif
open.accelerator=control O
open.enabled=true
open.command=org.apache.tools.ant.gui.command.OpenCmd

save.name=Save
save.shortDescription=Save the current project
save.parentMenuName=File
save.icon=save.gif
save.accelerator=control S
save.command=org.apache.tools.ant.gui.command.SaveCmd
save.enabled=false
save.disableOn= \
org.apache.tools.ant.gui.event.ProjectClosedEvent, \
@@ -31,6 +33,7 @@ save.enableOn= \
saveas.name=Save As...
saveas.shortDescription=Save to a specific file
saveas.parentMenuName=File
saveas.command=org.apache.tools.ant.gui.command.SaveAsCmd
saveas.enabled=false
saveas.disableOn= \
org.apache.tools.ant.gui.event.ProjectClosedEvent, \
@@ -42,6 +45,7 @@ saveas.enableOn= \
close.name=Close
close.shortDescription=Close the current project
close.parentMenuName=File
close.command=org.apache.tools.ant.gui.command.CloseCmd
close.enabled=false
close.disableOn= \
org.apache.tools.ant.gui.event.ProjectClosedEvent, \
@@ -54,6 +58,7 @@ exit.name=Exit
exit.shortDescription=Quit the application
exit.parentMenuName=File
exit.separator=true
exit.command=org.apache.tools.ant.gui.command.ExitCmd
exit.enabled=true

about.name=About...
@@ -61,6 +66,7 @@ about.shortDescription=About this application
about.parentMenuName=Help
about.separator=true;
about.enabled=true
about.command=org.apache.tools.ant.gui.command.AboutCmd

startBuild.name=Start Build
startBuild.shortDescription=Start build of selected target
@@ -68,6 +74,7 @@ startBuild.parentMenuName=Build
startBuild.icon=start.gif
startBuild.separator=true
startBuild.accelerator=control B
startBuild.command=org.apache.tools.ant.gui.command.BuildCmd
startBuild.enabled=false
startBuild.enableOn=\
org.apache.tools.ant.gui.event.NewProjectEvent, \
@@ -90,6 +97,7 @@ stopBuild.disableOn=\
changeLookAndFeel.name=Look and Feel...
changeLookAndFeel.shortDescription=Change the Look and Feel
changeLookAndFeel.parentMenuName=Options
changeLookAndFeel.command=org.apache.tools.ant.gui.command.ChangeLookAndFeelCmd
changeLookAndFeel.enabled=true
changeLookAndFeel.separator=true

@@ -98,3 +106,4 @@ notifyEmacs.shortDescription=\
Send a notification event to Emacs on build errors.
notifyEmacs.parentMenuName=Options
notifyEmacs.toggle=true
notifyEmacs.command=org.apache.tools.ant.gui.command.EmacsNotifyCmd

Loading…
Cancel
Save