1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.diff; 21 22 import org.netbeans.api.diff.StreamSource; 23 import org.netbeans.api.diff.DiffView; 24 import org.netbeans.modules.versioning.system.cvss.*; 25 import org.netbeans.lib.cvsclient.admin.Entry; 26 import org.openide.util.NbBundle; 27 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.util.*; 31 import java.text.MessageFormat ; 32 33 38 public final class Setup { 39 40 public static final int DIFFTYPE_LOCAL = 0; 41 public static final int DIFFTYPE_REMOTE = 1; 42 public static final int DIFFTYPE_ALL = 2; 43 44 public static final String REVISION_CURRENT = VersionsCache.REVISION_CURRENT; 45 public static final String REVISION_HEAD = VersionsCache.REVISION_HEAD; 46 47 private final File baseFile; 48 private final String firstRevision; 49 private final String secondRevision; 50 51 private DiffStreamSource firstSource; 52 private DiffStreamSource secondSource; 53 54 private DiffView view; 55 56 private String title; 57 58 public Setup(File baseFile, int type) { 59 this.baseFile = baseFile; 60 FileInformation info = CvsVersioningSystem.getInstance().getStatusCache().getStatus(baseFile); 61 int status = info.getStatus(); 62 Entry entry = info.getEntry(baseFile); 63 String revision = entry != null ? entry.getRevision() : null; 64 if (revision != null && revision.charAt(0) == '-') revision = revision.substring(1); 65 66 ResourceBundle loc = NbBundle.getBundle(Setup.class); 67 String firstTitle; 68 String secondTitle; 69 if (type == DIFFTYPE_ALL && status == FileInformation.STATUS_VERSIONED_MERGE) { 70 firstRevision = REVISION_HEAD; 71 firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object [] { revision }); 72 } else if ( 73 status == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY || 74 status == FileInformation.STATUS_VERSIONED_ADDEDLOCALLY || 75 status == FileInformation.STATUS_VERSIONED_NEWINREPOSITORY 76 ) { 77 firstRevision = null; 78 firstTitle = loc.getString("MSG_DiffPanel_NoBaseRevision"); 79 } else { 80 firstRevision = revision; 81 firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_BaseRevision"), new Object [] { revision }); 82 } 83 84 if (status == FileInformation.STATUS_VERSIONED_CONFLICT) { 85 secondRevision = REVISION_CURRENT; 86 secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_LocalConflict"), new Object [] { revision }); 87 } else if (status == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY || status == FileInformation.STATUS_VERSIONED_ADDEDLOCALLY) { 88 secondRevision = REVISION_CURRENT; 89 secondTitle = loc.getString("MSG_DiffPanel_LocalNew"); 90 } else if (status == FileInformation.STATUS_VERSIONED_DELETEDLOCALLY || status == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY) { 91 secondRevision = null; 92 secondTitle = loc.getString("MSG_DiffPanel_LocalDeleted"); 93 } else if (status == FileInformation.STATUS_VERSIONED_NEWINREPOSITORY) { 94 secondRevision = REVISION_HEAD; 95 secondTitle = loc.getString("MSG_DiffPanel_RemoteNew"); 96 } else if (status == FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY) { 97 secondRevision = null; 98 secondTitle = loc.getString("MSG_DiffPanel_RemoteDeleted"); 99 } else if (status == FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY) { 100 secondRevision = REVISION_HEAD; 101 secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object [] { revision }); 102 } else if (type == DIFFTYPE_REMOTE) { 103 secondRevision = REVISION_HEAD; 104 secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object [] { revision }); 105 } else { 106 secondRevision = REVISION_CURRENT; 107 secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_LocalModified"), new Object [] { revision }); 108 } 109 110 firstSource = new DiffStreamSource(baseFile, firstRevision, firstTitle); 111 secondSource = new DiffStreamSource(baseFile, secondRevision, secondTitle); 112 title = "<html>" + CvsVersioningSystem.getInstance().getAnnotator().annotateNameHtml(baseFile, info); } 114 115 120 public Setup(File baseFile, String firstRevision, String secondRevision) { 121 this.baseFile = baseFile; 122 this.firstRevision = firstRevision; 123 this.secondRevision = secondRevision; 124 firstSource = new DiffStreamSource(baseFile, firstRevision, firstRevision); 125 secondSource = new DiffStreamSource(baseFile, secondRevision, secondRevision); 126 } 127 128 public File getBaseFile() { 129 return baseFile; 130 } 131 132 public void setView(DiffView view) { 133 this.view = view; 134 } 135 136 public DiffView getView() { 137 return view; 138 } 139 140 public StreamSource getFirstSource() { 141 return firstSource; 142 } 143 144 public StreamSource getSecondSource() { 145 return secondSource; 146 } 147 148 public String toString() { 149 return title; 150 } 151 152 static String getDisplayedRevision(File baseFile, String revision) { 153 if (revision == REVISION_CURRENT) { 154 FileInformation info = CvsVersioningSystem.getInstance().getStatusCache().getStatus(baseFile); 155 return NbBundle.getMessage(Setup.class, "MSG_LocalRevision", info.getEntry(baseFile).getRevision()); 156 } else { 157 return revision; 158 } 159 } 160 161 165 void initSources(ExecutorGroup group) throws IOException { 166 if (firstSource != null) firstSource.init(group); 167 if (secondSource != null) secondSource.init(group); 168 } 169 } 170 | Popular Tags |