1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.diff; 21 22 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 23 import org.openide.windows.TopComponent; 24 import org.openide.util.NbBundle; 25 import org.openide.util.HelpCtx; 26 import org.openide.awt.UndoRedo; 27 import org.netbeans.modules.versioning.system.cvss.*; 28 import org.netbeans.modules.versioning.system.cvss.util.Context; 29 30 import javax.swing.*; 31 import java.awt.BorderLayout ; 32 import java.io.*; 33 import java.util.List ; 34 import java.util.ArrayList ; 35 import java.util.Collection ; 36 37 44 public class DiffExecutor { 45 46 private final Context context; 47 private final String contextName; 48 49 public DiffExecutor(Context context, String contextName) { 50 this.context = context; 51 this.contextName = contextName; 52 } 53 54 public DiffExecutor(String contextName) { 55 this.contextName = contextName; 56 this.context = null; 57 } 58 59 63 public void showRemoteDiff(ExecutorGroup group) { 64 showDiff(Setup.DIFFTYPE_REMOTE, group); 65 } 66 67 71 public void showAllDiff(ExecutorGroup group) { 72 showDiff(Setup.DIFFTYPE_ALL, group); 73 } 74 75 79 public void showLocalDiff(ExecutorGroup group) { 80 showDiff(Setup.DIFFTYPE_LOCAL, group); 81 } 82 83 public void showDiff(File file, String rev1, String rev2) { 84 DiffMainPanel panel = new DiffMainPanel(file, rev1, rev2); 85 openDiff(panel, null); 86 } 87 88 private void showDiff(int type, ExecutorGroup group) { 89 VersionsCache.getInstance().purgeVolatileRevisions(); 90 DiffMainPanel panel = new DiffMainPanel(context, type, contextName, group); openDiff(panel, group); 92 } 93 94 private void openDiff(final JComponent c, final ExecutorGroup group) { 95 SwingUtilities.invokeLater(new Runnable () { 96 public void run() { 97 DiffTopComponent tc = new DiffTopComponent(c); 98 tc.setName(NbBundle.getMessage(DiffExecutor.class, "CTL_DiffPanel_Title", contextName)); 99 tc.open(); 100 tc.requestActive(); 101 tc.setGroup(group); 102 } 103 }); 104 } 105 106 114 public static File [] getModifiedFiles(Context context, int includeStatus) { 115 CvsFileTableModel model = CvsVersioningSystem.getInstance().getFileTableModel(context, includeStatus); 116 CvsFileNode [] nodes = model.getNodes(); 117 List <File> files = new ArrayList <File>(); 118 for (int i = 0; i < nodes.length; i++) { 119 File file = nodes[i].getFile(); 120 if (CvsModuleConfig.getDefault().isExcludedFromCommit(file) == false) { 121 files.add(file); 122 } 123 } 124 FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); 126 File [] rootFiles = context.getRootFiles(); 127 for (int i = 0; i < rootFiles.length; i++) { 128 File file = rootFiles[i]; 129 if (file.isFile() && (cache.getStatus(file).getStatus() & includeStatus) != 0 && !files.contains(file)) { 130 files.add(file); 131 } 132 } 133 return (File[]) files.toArray(new File[files.size()]); 134 } 135 136 private static class DiffTopComponent extends TopComponent implements DiffSetupSource { 137 138 public DiffTopComponent() { 139 } 140 141 public DiffTopComponent(JComponent c) { 142 setLayout(new BorderLayout ()); 143 c.putClientProperty(TopComponent.class, this); 144 add(c, BorderLayout.CENTER); 145 getAccessibleContext().setAccessibleName(NbBundle.getMessage(DiffTopComponent.class, "ACSN_Diff_Top_Component")); getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DiffTopComponent.class, "ACSD_Diff_Top_Component")); } 148 149 public UndoRedo getUndoRedo() { 150 DiffMainPanel mainPanel = ((DiffMainPanel) getComponent(0)); 151 return mainPanel.getUndoRedo(); 152 } 153 154 public int getPersistenceType(){ 155 return TopComponent.PERSISTENCE_NEVER; 156 } 157 158 protected void componentClosed() { 159 ((DiffMainPanel) getComponent(0)).componentClosed(); 160 super.componentClosed(); 161 } 162 163 protected String preferredID(){ 164 return "DiffExecutorTopComponent"; } 166 167 public HelpCtx getHelpCtx() { 168 return new HelpCtx(getClass()); 169 } 170 171 protected void componentActivated() { 172 super.componentActivated(); 173 DiffMainPanel mainPanel = ((DiffMainPanel) getComponent(0)); 174 mainPanel.requestActive(); 175 } 176 177 public Collection <Setup> getSetups() { 178 DiffSetupSource mainPanel = ((DiffSetupSource) getComponent(0)); 179 return mainPanel.getSetups(); 180 } 181 182 public String getSetupDisplayName() { 183 DiffSetupSource mainPanel = ((DiffSetupSource) getComponent(0)); 184 return mainPanel.getSetupDisplayName(); 185 186 } 187 188 public void setGroup(ExecutorGroup group) { 189 DiffMainPanel mainPanel = ((DiffMainPanel) getComponent(0)); 190 mainPanel.setGroup(group); 191 } 192 } 193 194 } 195 | Popular Tags |