1 11 package org.eclipse.team.ui.synchronize; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.compare.*; 16 import org.eclipse.compare.structuremergeviewer.ICompareInput; 17 import org.eclipse.compare.structuremergeviewer.IDiffContainer; 18 import org.eclipse.core.resources.*; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.team.core.TeamException; 24 import org.eclipse.team.core.synchronize.SyncInfo; 25 import org.eclipse.team.internal.ui.*; 26 import org.eclipse.team.internal.ui.synchronize.SyncInfoModelElement; 27 import org.eclipse.team.internal.ui.synchronize.SynchronizePageConfiguration; 28 import org.eclipse.ui.progress.UIJob; 29 30 47 public final class SyncInfoCompareInput extends SaveableCompareEditorInput implements IResourceChangeListener { 48 49 private MyDiffNode node; 50 private String description; 51 private IResource resource; 52 private ISynchronizeParticipant participant; 53 private ISynchronizePageConfiguration synchronizeConfiguration; 54 55 61 private static class MyDiffNode extends SyncInfoModelElement { 62 public MyDiffNode(IDiffContainer parent, SyncInfo info) { 63 super(parent, info); 64 } 65 public void fireChange() { 66 super.fireChange(); 67 } 68 } 69 70 77 public SyncInfoCompareInput(String description, SyncInfo sync) { 78 super(getDefaultCompareConfiguration(), null); 79 Assert.isNotNull(sync); 80 Assert.isNotNull(description); 81 this.description = description; 82 this.resource = sync.getLocal(); 83 this.node = new MyDiffNode(null, sync); 84 setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, new String [] { sync.getLocal().getName() })); 85 } 86 87 97 public SyncInfoCompareInput(ISynchronizeParticipant participant, SyncInfo sync) { 98 this(participant.getName(), sync); 99 this.participant = participant; 100 } 101 102 public SyncInfoCompareInput(ISynchronizePageConfiguration configuration, 103 SyncInfo info) { 104 this(configuration.getParticipant(), info); 105 this.synchronizeConfiguration = configuration; 106 } 107 108 111 protected void handleDispose() { 112 super.handleDispose(); 113 if (synchronizeConfiguration != null) { 114 ICompareNavigator navigator = (ICompareNavigator)synchronizeConfiguration.getProperty(SynchronizePageConfiguration.P_INPUT_NAVIGATOR); 115 if (navigator != null && navigator == super.getNavigator()) { 116 synchronizeConfiguration.setProperty(SynchronizePageConfiguration.P_INPUT_NAVIGATOR, new CompareNavigator() { 117 protected INavigatable[] getNavigatables() { 118 return new INavigatable[0]; 119 } 120 }); 121 } 122 } 123 } 124 127 public Object getAdapter(Class adapter) { 128 if (IFile.class.equals(adapter) && resource.getType() == IResource.FILE) { 129 return (IFile)resource; 130 } 131 return super.getAdapter(adapter); 132 } 133 134 private static CompareConfiguration getDefaultCompareConfiguration() { 135 CompareConfiguration cc = new CompareConfiguration(); 136 return cc; 138 } 139 140 144 public void resourceChanged(IResourceChangeEvent event) { 145 IResourceDelta delta = event.getDelta(); 146 if (delta != null) { 147 IResourceDelta resourceDelta = delta.findMember(resource.getFullPath()); 148 if (resourceDelta != null) { 149 UIJob job = new UIJob("") { public IStatus runInUIThread(IProgressMonitor monitor) { 151 if (!isSaveNeeded()) { 152 } 154 return Status.OK_STATUS; 155 } 156 }; 157 job.setSystem(true); 158 job.schedule(); 159 } 160 } 161 } 162 163 166 protected ICompareInput prepareCompareInput(IProgressMonitor monitor) 167 throws InvocationTargetException , InterruptedException { 168 setTitle(getTitle()); 171 monitor.beginTask(TeamUIMessages.SyncInfoCompareInput_3, 100); 172 monitor.setTaskName(TeamUIMessages.SyncInfoCompareInput_3); 173 try { 174 if (participant != null) { 175 participant.prepareCompareInput(node, getCompareConfiguration(), Policy.subMonitorFor(monitor, 100)); 176 } else { 177 Utils.updateLabels(node.getSyncInfo(), getCompareConfiguration()); 178 node.cacheContents(Policy.subMonitorFor(monitor, 100)); 179 } 180 } catch (TeamException e) { 181 throw new InvocationTargetException (e); 182 } finally { 183 monitor.done(); 184 } 185 return node; 186 } 187 188 192 public String getToolTipText() { 193 return NLS.bind(TeamUIMessages.SyncInfoCompareInput_tooltip, new String [] { Utils.shortenText(30, description), node.getResource().getFullPath().toString() }); 194 } 195 196 200 public boolean equals(Object other) { 201 if (other == this) 202 return true; 203 if (other instanceof SyncInfoCompareInput) { 204 SyncInfo otherSyncInfo = ((SyncInfoCompareInput) other).getSyncInfo(); 205 SyncInfo thisSyncInfo = getSyncInfo(); 206 return thisSyncInfo.equals(otherSyncInfo) 209 && node.getLeft().equals(((SyncInfoCompareInput) other).node.getLeft()); 210 } 211 return false; 212 } 213 214 public SyncInfo getSyncInfo() { 215 return node.getSyncInfo(); 216 } 217 218 221 public boolean canRunAsJob() { 222 return true; 223 } 224 225 228 public synchronized ICompareNavigator getNavigator() { 229 if (synchronizeConfiguration != null && isSelectedInSynchronizeView()) { 230 ICompareNavigator nav = (ICompareNavigator)synchronizeConfiguration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR); 231 synchronizeConfiguration.setProperty(SynchronizePageConfiguration.P_INPUT_NAVIGATOR, super.getNavigator()); 232 return nav; 233 } 234 return super.getNavigator(); 235 } 236 237 private boolean isSelectedInSynchronizeView() { 238 if (synchronizeConfiguration != null) { 239 ISelection s = synchronizeConfiguration.getSite().getSelectionProvider().getSelection(); 240 if (s instanceof IStructuredSelection) { 241 IStructuredSelection ss = (IStructuredSelection) s; 242 Object element = ss.getFirstElement(); 243 if (element instanceof SyncInfoModelElement) { 244 SyncInfoModelElement sime = (SyncInfoModelElement) element; 245 return sime.getSyncInfo().getLocal().equals(resource); 246 } 247 } 248 } 249 return false; 250 } 251 252 255 protected void fireInputChange() { 256 node.fireChange(); 257 } 258 } 259 | Popular Tags |