View Javadoc

1   /*
2    * Copyright (c) 2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.aequo.text.action;
14  
15  import java.awt.event.ActionEvent;
16  import java.awt.event.KeyEvent;
17  import java.io.IOException;
18  
19  import javax.swing.Action;
20  import javax.swing.KeyStroke;
21  
22  import org.abstracthorizon.aequo.gui.ErrorDialog;
23  import org.abstracthorizon.aequo.text.TextModel;
24  
25  /**
26   * Save side action.
27   *
28   * @author Daniel Sendula
29   */
30  public class SaveAction extends TextBaseAction {
31  
32      /**
33       * Constructor
34       */
35      public SaveAction() {
36          setName("Save");
37          setMessage("Save");
38          setDescription("Save");
39          putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
40          putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
41      }
42      
43      /**
44       * Invokes action
45       * @param e action event
46       */
47      public void perform(ActionEvent e) {
48          TextModel model = getTextModel();
49  
50          String fileName = null;
51          try {
52              if (column == 0) {
53                  fileName = model.getLeftFile().getAbsolutePath();
54                  model.saveLeft();
55              } else {
56                  fileName = model.getRightFile().getAbsolutePath();
57                  model.saveRight();
58              }
59          } catch (IOException ex) {
60              ErrorDialog.showError(null, "Error saving file " + fileName, ex);
61          }
62      }
63  
64  }