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  import org.abstracthorizon.aequo.file.FilesModel;
24  
25  /**
26   * Compare two sides action. It is global action.
27   *
28   * @author Daniel Sendula
29   */
30  public class ShowComparisonAction extends FileBaseAction {
31  
32      public ShowComparisonAction() {
33          setName("Show Comparison");
34          setMessage("Show Comparison");
35          setDescription("Show Comparison");
36          putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
37          putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
38      }
39  
40      public boolean isEnabled() {
41          ListSelectionModel selModel = getFilesModel().getSelectionModel();
42          int min = selModel.getMinSelectionIndex();
43          int max = selModel.getMaxSelectionIndex();
44          if ((min >= 0) && (min == max)) {
45              FileCompareEntry entry = filesModel.get(min);
46              if (entry.getData(0).isFile() || entry.getData(1).isFile()) {
47                  return true;
48              }
49          }
50          return false;
51      }
52      
53      /**
54       * Compares two files in text comparison tool
55       * 
56       * @param e event 
57       */
58      public void perform(ActionEvent e) {
59          FilesModel filesModel = getFilesModel();
60          int index = filesModel.getSelectionModel().getMinSelectionIndex();
61          if ((index >= 0) && (index == filesModel.getSelectionModel().getMaxSelectionIndex())) {
62              FileCompareEntry entry = filesModel.get(index);
63              org.abstracthorizon.aequo.text.action.ShowComparisonAction compare = new org.abstracthorizon.aequo.text.action.ShowComparisonAction(entry);
64              compare.setGlobalContext(getGlobalContext());
65              compare.actionPerformed(e);
66          }
67      }
68  }