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;
14  
15  import java.io.File;
16  
17  import org.abstracthorizon.aequo.GlobalContext;
18  import org.abstracthorizon.aequo.gui.InputFolders;
19  import org.abstracthorizon.aequo.util.TaskUtilities;
20  import org.abstracthorizon.aequo.util.filters.Filter;
21  
22  /**
23   * File compare window.
24   *
25   * @author Daniel Sendula
26   */
27  public class FileCompareWindow extends BaseFileCompareWindow {
28  
29      /** Model */
30      protected FilesModel model;
31  
32      /**
33       * Constructor
34       * @param context global context
35       * @param leftFile left file
36       * @param rightFile right file
37       * @param filter filters
38       */
39      public FileCompareWindow(GlobalContext context, File leftFile, File rightFile, Filter filter) {
40          super(context);
41  
42          if (filter == null) {
43              filter = new Filter();
44          }
45          model = new FilesModel(leftFile, rightFile, filter);
46      }
47  
48      /**
49       * Returns window id. 
50       * @return window id
51       */
52      protected String getWindowId() {
53          return "window.file";
54      }
55  
56      /**
57       * Creates components for this window
58       */
59      public void initialise() {
60          InputFolders.addNewSession(context.getPreferences(), model.getData(0), model.getData(1), model.getFilter());
61          super.initialise();
62          model.addRefreshListener(new FilesModel.RefreshListener() {
63  
64              public void currentlyProcessing(FileCompareEntry entry) {
65                  if (entry != null) {
66                      StringBuffer path = new StringBuffer();
67                      while (entry != null) {
68                          if (path.length() > 0) {
69                              path.insert(0, '/');
70                          }
71                          path.insert(0, entry.getData()[0].getName());
72                          entry = entry.parentEntry;
73                      }
74                      path.insert(0, "Processing: ");
75                      ((TableFileComparePanel)comparePanel).bottomStatus.setText(path.toString());
76                  } else {
77                      ((TableFileComparePanel)comparePanel).bottomStatus.setText(" ");
78                  }
79              }
80              
81          });
82          
83          TaskUtilities.invokeLater(new Runnable() {
84              public void run() {
85                  Thread.yield();
86                  model.refresh();
87              }
88          });
89      }
90          
91      /**
92       * Creates compare panel
93       */
94      protected void createComparePanel() {
95          comparePanel = new TableFileComparePanel(context, model);
96          comparePanel.initialise();
97      }
98      
99      /**
100      * Returns left filename
101      * @return left filename
102      */
103     protected String getLeftFileName() {
104         return model.getLeftFile().getAbsolutePath();
105     }
106 
107     /**
108      * Returns right filename
109      * @return right filename
110      */
111     protected String getRightFileName() {
112         return model.getRightFile().getAbsolutePath();
113     }
114 
115 }