View Javadoc

1   /*
2   Copyright (C) 2000 - 2007 Grid Systems, S.A.
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2, as
6   published by the Free Software Foundation.
7   
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17  
18  /*
19   * Project: KernelConfigurator
20   * Created on 09-mar-2004
21   *
22   * Copyright (c)2003 Grid Systems
23   */
24  package com.gridsystems.config.tools.console;
25  
26  import com.gridsystems.config.Configurator;
27  import com.gridsystems.config.ConsoleConfiguratorView;
28  import com.gridsystems.config.app.UI;
29  
30  
31  /**
32   * Special ConsoleViewAction that performs an Apply on this configurator model
33   * and exits from the view.
34   *
35   * @author <a href="mailto:rruiz@gridsystems.com">Rodrigo Ruiz Aguayo</a>
36   * @version 1.0
37   */
38  public class ApplyAction implements ConsoleViewAction {
39    /**
40     * The instance this action will affect to.
41     */
42    private final Configurator configurator;
43  
44    /**
45     * Creates a new instance bound to the specified configurator.
46     *
47     * @param configurator The configurator instance to affect
48     */
49    public ApplyAction(Configurator configurator) {
50      this.configurator = configurator;
51    }
52  
53    /**
54     * {@inheritDoc}
55     */
56    public String getKeyMapping() {
57      return UI.getString("console.apply.key");
58    }
59  
60    /**
61     * {@inheritDoc}
62     */
63    public boolean execute(ConsoleConfiguratorView view) {
64      try {
65        this.configurator.apply();
66      } catch (Exception e) {
67        if (view instanceof AbstractConsoleView) {
68          String[] msg = null;
69          try {
70            msg = new String[] { configurator.getBundle().getString(e.getMessage()) };
71          } catch (Exception e2) {
72            msg = new String[] { e.getMessage() };
73          }
74          ((AbstractConsoleView)view).showError(msg);
75          return true;
76        }
77      }
78      return false;
79    }
80  }