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.file.action;
14  
15  import java.awt.event.ActionEvent;
16  import java.awt.event.KeyEvent;
17  
18  import javax.swing.Action;
19  import javax.swing.KeyStroke;
20  import javax.swing.ListSelectionModel;
21  
22  import org.abstracthorizon.aequo.file.FileCompareEntry;
23  
24  /**
25   * New session action.
26   *
27   * @author Daniel Sendula
28   */
29  public class RefreshSubtreeAction extends FileBaseAction {
30  
31      public RefreshSubtreeAction() {
32          setName("Refresh");
33          setMessage("Refresh Subtree");
34          setDescription("Refresh Subtree");
35          putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
36          putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
37      }
38  
39      /**
40       * Returns if selection is valid
41       * @return <code>true</code> if selection is valid<
42       */
43      public boolean isEnabled() {
44          return isSelectionValid();
45      }
46      
47      /**
48       * Refreshes all selected files and subtrees of them
49       * 
50       * @param e event 
51       */
52     public void perform(ActionEvent e) {
53          ListSelectionModel selModel = getFilesModel().getSelectionModel();
54          int index = selModel.getMinSelectionIndex();
55          FileCompareEntry entry = getFilesModel().get(index);
56          getFilesModel().refresh(entry, entry.getLevel(), true);
57      }
58  }