1 11 package org.eclipse.team.internal.ccvs.ui.repo; 12 13 14 import java.util.Properties ; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.jface.action.*; 18 import org.eclipse.jface.viewers.*; 19 import org.eclipse.jface.wizard.WizardDialog; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.dnd.*; 23 import org.eclipse.swt.events.KeyAdapter; 24 import org.eclipse.swt.events.KeyEvent; 25 import org.eclipse.swt.widgets.*; 26 import org.eclipse.team.core.TeamException; 27 import org.eclipse.team.internal.ccvs.core.*; 28 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; 29 import org.eclipse.team.internal.ccvs.ui.*; 30 import org.eclipse.team.internal.ccvs.ui.model.AllRootsElement; 31 import org.eclipse.team.internal.ccvs.ui.wizards.NewLocationWizard; 32 import org.eclipse.team.internal.core.TeamPlugin; 33 import org.eclipse.team.internal.ui.actions.TeamAction; 34 import org.eclipse.ui.*; 35 import org.eclipse.ui.actions.ActionFactory; 36 import org.eclipse.ui.dialogs.PropertyDialogAction; 37 import org.eclipse.ui.part.PluginTransfer; 38 import org.eclipse.ui.part.PluginTransferData; 39 40 45 public class RepositoriesView extends RemoteViewPart { 46 public static final String VIEW_ID = "org.eclipse.team.ccvs.ui.RepositoriesView"; 48 private AllRootsElement root; 50 51 private IAction removeAction; 53 private Action newAction; 54 private Action newAnonAction; 55 private PropertyDialogAction propertiesAction; 56 private RemoveRootAction removeRootAction; 57 private RemoveDateTagAction removeDateTagAction; 58 59 IRepositoryListener listener = new IRepositoryListener() { 60 public void repositoryAdded(final ICVSRepositoryLocation root) { 61 getViewer().getControl().getDisplay().asyncExec(new Runnable () { 62 public void run() { 63 refreshViewer(); 64 getViewer().setSelection(new StructuredSelection(root)); 65 } 66 }); 67 } 68 public void repositoriesChanged(ICVSRepositoryLocation[] roots) { 69 refresh(); 70 } 71 private void refresh() { 72 Display display = getViewer().getControl().getDisplay(); 73 display.asyncExec(new Runnable () { 74 public void run() { 75 RepositoriesView.this.refreshViewer(); 76 } 77 }); 78 } 79 }; 80 81 private static final class RepositoryDragSourceListener implements DragSourceListener { 82 private IStructuredSelection selection; 83 84 public void dragStart(DragSourceEvent event) { 85 if(selection!=null) { 86 final Object [] array = selection.toArray(); 87 for (int i = 0; i < array.length; i++) { 89 if (array[i] instanceof ICVSRemoteFile) { 90 event.doit = true; 91 return; 92 } 93 } 94 event.doit = false; 95 } 96 } 97 98 public void dragSetData(DragSourceEvent event) { 99 if (selection!=null && CVSResourceTransfer.getInstance().isSupportedType(event.dataType)) { 100 final Object [] array = selection.toArray(); 101 for (int i = 0; i < array.length; i++) { 102 if (array[i] instanceof ICVSRemoteFile) { 103 event.data = array[i]; 104 return; 105 } 106 } 107 } else if (PluginTransfer.getInstance().isSupportedType(event.dataType)) { 108 final Object [] array = selection.toArray(); 109 for (int i = 0; i < array.length; i++) { 110 if (array[i] instanceof ICVSRemoteFile) { 111 event.data = new PluginTransferData("org.eclipse.team.cvs.ui.cvsRemoteDrop", CVSResourceTransfer.getInstance().toByteArray((ICVSRemoteFile) array[i])); return; 113 } 114 } 115 116 } 117 } 118 119 public void dragFinished( DragSourceEvent event) { 120 } 121 122 public void updateSelection( IStructuredSelection selection) { 123 this.selection = selection; 124 } 125 } 126 127 RepositoryDragSourceListener repositoryDragSourceListener; 128 129 133 public RepositoriesView() { 134 super(VIEW_ID); 135 } 136 137 140 protected void contributeActions() { 141 142 final Shell shell = getShell(); 143 144 146 newAction = new Action(CVSUIMessages.RepositoriesView_new, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_NEWLOCATION)) { 148 public void run() { 149 NewLocationWizard wizard = new NewLocationWizard(); 150 wizard.setSwitchPerspectives(false); 151 WizardDialog dialog = new WizardDialog(shell, wizard); 152 dialog.open(); 153 } 154 }; 155 PlatformUI.getWorkbench().getHelpSystem().setHelp(newAction, IHelpContextIds.NEW_REPOSITORY_LOCATION_ACTION); 156 157 if (includeAnonConnection()) { 158 newAnonAction = new Action(CVSUIMessages.RepositoriesView_newAnonCVS, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_NEWLOCATION)) { 159 public void run() { 160 Properties p = new Properties (); 161 p.setProperty("connection", "pserver"); p.setProperty("user", "anonymous"); p.setProperty("host", "dev.eclipse.org"); p.setProperty("root", "/cvsroot/eclipse"); NewLocationWizard wizard = new NewLocationWizard(p); 166 wizard.setSwitchPerspectives(false); 167 WizardDialog dialog = new WizardDialog(shell, wizard); 168 dialog.open(); 169 } 170 }; 171 PlatformUI.getWorkbench().getHelpSystem().setHelp(newAnonAction, IHelpContextIds.NEW_DEV_ECLIPSE_REPOSITORY_LOCATION_ACTION); 172 } 173 174 propertiesAction = new PropertyDialogAction(shell, getViewer()); 176 getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), propertiesAction); 177 IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection(); 178 if (selection.size() == 1 && selection.getFirstElement() instanceof RepositoryRoot) { 179 propertiesAction.setEnabled(true); 180 } else { 181 propertiesAction.setEnabled(false); 182 } 183 getViewer().addSelectionChangedListener(new ISelectionChangedListener() { 184 public void selectionChanged(SelectionChangedEvent event) { 185 IStructuredSelection ss = (IStructuredSelection)event.getSelection(); 186 boolean enabled = ss.size() == 1 && ss.getFirstElement() instanceof RepositoryRoot; 187 propertiesAction.setEnabled(enabled); 188 } 189 }); 190 removeRootAction = new RemoveRootAction(viewer.getControl().getShell(), this); 191 removeRootAction.selectionChanged((IStructuredSelection)null); 192 removeDateTagAction = new RemoveDateTagAction(); 193 removeDateTagAction.selectionChanged( (IStructuredSelection)null); 194 removeAction = new Action(){ 195 public void run(){ 196 if(removeRootAction.isEnabled()){ 197 removeRootAction.run(); 198 } 199 if(removeDateTagAction.isEnabled()){ 200 removeDateTagAction.run(); 201 } 202 } 203 }; 204 PlatformUI.getWorkbench().getHelpSystem().setHelp(removeRootAction, IHelpContextIds.REMOVE_REPOSITORY_LOCATION_ACTION); 205 IActionBars bars = getViewSite().getActionBars(); 206 bars.setGlobalActionHandler(ActionFactory.DELETE.getId(), removeAction); 207 208 super.contributeActions(); 209 } 210 211 215 private boolean includeAnonConnection() { 216 return System.getProperty("eclipse.cvs.anon") != null; } 218 219 222 protected void addWorkbenchActions(IMenuManager manager) { 223 MenuManager sub = new MenuManager(CVSUIMessages.RepositoriesView_newSubmenu, IWorkbenchActionConstants.GROUP_ADD); 225 manager.add(sub); 226 super.addWorkbenchActions(manager); 227 IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection(); 228 229 removeRootAction.selectionChanged(selection); 230 removeDateTagAction.selectionChanged(selection); 231 if(removeRootAction.isEnabled()) { 232 manager.add(removeRootAction); 233 } 234 if(removeDateTagAction.isEnabled()){ 235 manager.add(removeDateTagAction); 236 } 237 if (selection.size() == 1 && selection.getFirstElement() instanceof RepositoryRoot) { 238 manager.add(new Separator()); 239 manager.add(propertiesAction); 240 } 241 sub.add(newAction); 242 if (newAnonAction != null) 243 sub.add(newAnonAction); 244 sub.add(new Separator("group1")); } 246 247 250 public void createPartControl(Composite parent) { 251 super.createPartControl(parent); 252 CVSUIPlugin.getPlugin().getRepositoryManager().addRepositoryListener(listener); 253 } 254 255 258 public void dispose() { 259 CVSUIPlugin.getPlugin().getRepositoryManager().removeRepositoryListener(listener); 260 super.dispose(); 261 } 262 263 266 private void initialize() { 267 root = new AllRootsElement(); 268 } 269 270 protected void initializeListeners() { 271 super.initializeListeners(); 272 viewer.addSelectionChangedListener(removeRootAction); 273 viewer.addSelectionChangedListener(removeDateTagAction); 274 viewer.addSelectionChangedListener(new ISelectionChangedListener(){ 275 public void selectionChanged(SelectionChangedEvent event) { 276 IStructuredSelection selection = (IStructuredSelection)event.getSelection(); 277 handleChange(selection); 278 } 279 }); 280 281 repositoryDragSourceListener = new RepositoryDragSourceListener(); 282 viewer.addDragSupport( DND.DROP_LINK | DND.DROP_DEFAULT, 283 new Transfer[] { CVSResourceTransfer.getInstance(),PluginTransfer.getInstance()}, 284 repositoryDragSourceListener); 285 } 286 287 290 protected Object getTreeInput() { 291 initialize(); 292 return root; 293 } 294 295 298 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 299 String msg = getStatusLineMessage(selection); 300 getViewSite().getActionBars().getStatusLineManager().setMessage(msg); 301 } 302 303 private String getStatusLineMessage(ISelection selection) { 304 if (selection==null || selection.isEmpty()) return ""; if (!(selection instanceof IStructuredSelection)) return ""; IStructuredSelection s = (IStructuredSelection)selection; 307 308 if (s.size() > 1) 309 return NLS.bind(CVSUIMessages.RepositoriesView_NItemsSelected, new String [] { String.valueOf(s.size()) }); 310 Object element = TeamAction.getAdapter(s.getFirstElement(), ICVSResource.class); 311 if (element instanceof ICVSRemoteResource) { 312 ICVSRemoteResource res = (ICVSRemoteResource)element; 313 String name; 314 if (res.isContainer()) { 315 name = res.getRepositoryRelativePath(); 316 } else { 317 try { 318 name = res.getRepositoryRelativePath() + " " + ((ICVSRemoteFile)res).getRevision(); } catch (TeamException e) { 320 TeamPlugin.log(IStatus.ERROR, CVSUIMessages.RepositoriesView_CannotGetRevision, e); 321 name = res.getRepositoryRelativePath(); 322 } 323 } 324 return NLS.bind(CVSUIMessages.RepositoriesView_ResourceInRepository, new String [] { name, res.getRepository().getLocation(true) }); 325 } 326 return CVSUIMessages.RepositoriesView_OneItemSelected; 327 } 328 329 332 protected String getHelpContextId() { 333 return IHelpContextIds.REPOSITORIES_VIEW; 334 } 335 336 339 protected KeyAdapter getKeyListener() { 340 return new KeyAdapter() { 341 public void keyPressed(KeyEvent event) { 342 if (event.keyCode == SWT.F5) { 343 if (WorkbenchUserAuthenticator.USE_ALTERNATE_PROMPTER) { 344 ICVSRepositoryLocation[] locations = KnownRepositories.getInstance().getRepositories(); 345 for (int i = 0; i < locations.length; i++) { 346 locations[i].flushUserInfo(); 347 } 348 } else { 349 refreshAll(); 350 } 351 } else if (event.keyCode == SWT.F9 && WorkbenchUserAuthenticator.USE_ALTERNATE_PROMPTER) { 352 refreshAll(); 353 } 354 } 355 }; 356 } 357 358 private void handleChange(IStructuredSelection selection){ 359 removeRootAction.updateSelection(selection); 360 removeDateTagAction.updateSelection(selection); 361 removeAction.setEnabled(removeRootAction.isEnabled() || removeDateTagAction.isEnabled()); 362 363 repositoryDragSourceListener.updateSelection(selection); 364 } 365 366 } 367 | Popular Tags |