### Eclipse Workspace Patch 1.0 #P org.eclipse.team.tests.cvs.core Index: src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java,v retrieving revision 1.7 diff -u -r1.7 TestsUserAuthenticator.java --- src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java 10 May 2006 18:10:43 -0000 1.7 +++ src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java 20 Apr 2007 15:33:25 -0000 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.team.tests.ccvs.core; +import java.util.Map; + import org.eclipse.team.internal.ccvs.core.*; /** @@ -40,4 +42,8 @@ public boolean promptForHostKeyChange(ICVSRepositoryLocation location) { return false; } + + public Object promptForAlternativeRepository(Map alternativeMap) { + return null; + } } #P org.eclipse.team.cvs.core Index: src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java,v retrieving revision 1.18 diff -u -r1.18 CVSProjectSetCapability.java --- src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java 10 Apr 2007 16:24:47 -0000 1.18 +++ src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java 20 Apr 2007 15:33:26 -0000 @@ -14,14 +14,7 @@ import java.io.File; import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; +import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; @@ -122,13 +115,36 @@ // Confirm the projects to be loaded Map infoMap = new HashMap(referenceStrings.length); - IProject[] projects = asProjects(referenceStrings, infoMap); - projects = confirmOverwrite(context, projects); - if (projects == null) - throw new OperationCanceledException(); + IProject[] projects = asProjects(referenceStrings, infoMap); + + projects = confirmOverwrite(context, projects); + if (projects == null) + return new IProject[0]; + + Map alternativeMap = new HashMap(); + if (isAlternativeRepositoryNeeded(projects, infoMap, alternativeMap)) { + Object alternativeRespositoriesMap = promptForAlternativeRespository(alternativeMap); + // replace repositoryLocations in infoMap to the ones from prompter + if (alternativeRespositoriesMap != null) { + for (Iterator iterator = infoMap.values().iterator(); iterator + .hasNext();) { + LoadInfo loadInfoForProject = (LoadInfo) iterator.next(); + ICVSRepositoryLocation selectedAlternativeRepository = (ICVSRepositoryLocation) ((Map) alternativeRespositoriesMap) + .get(loadInfoForProject.repositoryLocation + .getLocation(false)); + // TODO: final modifier removed for repositoryLocation :/ + // (create a copy of LoadInfo?) + loadInfoForProject.repositoryLocation = selectedAlternativeRepository; + } + } else { + // operation canceled + return new IProject[0]; + } + } + + // Load the projects + return checkout(projects, infoMap, monitor); - // Load the projects - return checkout(projects, infoMap, monitor); } /** @@ -198,7 +214,7 @@ * Internal class for adding projects to the workspace */ class LoadInfo { - private final ICVSRepositoryLocation repositoryLocation; + private ICVSRepositoryLocation repositoryLocation; private final String module; private final IProject project; private final CVSTag tag; @@ -276,7 +292,8 @@ } } // No existing location was found so add this location to the list of known repositories - KnownRepositories.getInstance().addRepository(newLocation, true); + // TODO: commented out (if we add repository here we won't be able to check for alternatives) + // KnownRepositories.getInstance().addRepository(newLocation, true); return newLocation; } @@ -578,5 +595,109 @@ return null; } } + + private static boolean isAlternativeRepositoryNeeded( + IProject[] projects, final Map infoMap, Map alternativeMap) { + + List confirmedProjectsList = Arrays.asList(projects); + + if (infoMap == null) + return false; + + Set projectSetRepositories = new HashSet(); + for (Iterator iterator = infoMap.keySet().iterator(); iterator + .hasNext();) { + IProject project = (IProject) iterator.next(); + if (confirmedProjectsList.contains(project)) { + LoadInfo loadInfo = (LoadInfo) infoMap.get(project); + projectSetRepositories.add(loadInfo.repositoryLocation); + } + } + + // none of projects from project sets is confirmed to overwrite + if (projectSetRepositories.isEmpty()) { + return false; + } + + List knownRepositories = Arrays.asList(KnownRepositories.getInstance() + .getRepositories()); + + if (knownRepositories.isEmpty()) { + // there are no known repositories so use repository location from + // the project set + for (Iterator iterator = projectSetRepositories.iterator(); iterator + .hasNext();) { + ICVSRepositoryLocation projectSetRepositoryLocation = (ICVSRepositoryLocation) iterator + .next(); + ArrayList alternativeList = new ArrayList(1); + alternativeList.add(projectSetRepositoryLocation); + alternativeMap.put(projectSetRepositoryLocation, + alternativeList); + } + } else if (!knownRepositories.containsAll(projectSetRepositories)) { + // not all repositories from the project set are known + for (Iterator iterator = projectSetRepositories.iterator(); iterator + .hasNext();) { + ICVSRepositoryLocation projectSetRepositoryLocation = (ICVSRepositoryLocation) iterator + .next(); + + if (knownRepositories.contains(projectSetRepositoryLocation)) { + // hey, we know you + ArrayList alternativeList = new ArrayList(1); + alternativeList.add(projectSetRepositoryLocation); + alternativeMap.put(projectSetRepositoryLocation, + alternativeList); + } else { + ArrayList alternativeList = new ArrayList(); + boolean compatibleFound = false; + for (Iterator iterator2 = knownRepositories.iterator(); iterator2 + .hasNext();) { + ICVSRepositoryLocation knownRepositoryLocation = (ICVSRepositoryLocation) iterator2 + .next(); + if (isCompatible(knownRepositoryLocation, + projectSetRepositoryLocation)) { + // compatible repositories first + alternativeList.add(0, knownRepositoryLocation); + compatibleFound = true; + } else { + alternativeList.add(knownRepositoryLocation); + } + + // if no compatible repository found add the one from + // the project set at the beginning + } + + if (!compatibleFound) + alternativeList.add(0, projectSetRepositoryLocation); + + alternativeMap.put(projectSetRepositoryLocation, + alternativeList); + } + } + } + + return !alternativeMap.isEmpty(); + } + + /** + * Same test as in org.eclipse.team.internal.ccvs.ui.CVSProjectPropertiesPage + * + * @see org.eclipse.team.internal.ccvs.ui.CVSProjectPropertiesPage#isCompatible + * + * @param location A location from known repositories collection + * @param oldLocation A location to check c + * @return Are given locations compatible + */ + private static boolean isCompatible(ICVSRepositoryLocation location, ICVSRepositoryLocation oldLocation) { + if (!location.getHost().equals(oldLocation.getHost())) return false; + if (!location.getRootDirectory().equals(oldLocation.getRootDirectory())) return false; + if (location.equals(oldLocation)) return false; + return true; + } + + private Object promptForAlternativeRespository(Map alternativeMap) { + IUserAuthenticator prompter = CVSRepositoryLocation.getAuthenticator(); + return prompter.promptForAlternativeRepository(alternativeMap); + } } Index: src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java,v retrieving revision 1.12 diff -u -r1.12 IUserAuthenticator.java --- src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java 10 May 2006 18:42:10 -0000 1.12 +++ src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java 20 Apr 2007 15:33:27 -0000 @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.team.internal.ccvs.core; +import java.util.Map; + /** * IUserAuthenticators are used to ensure that the user * is validated for access to a given repository. The @@ -130,4 +132,16 @@ * @return true if new host key should be accepted */ public boolean promptForHostKeyChange(ICVSRepositoryLocation location); + + /** + * @param alternativeMap + * a map of CVS repository locations form the project set (as + * keys) and a list of suggested alternative CVS repository + * locations (as values) + * @return a map of CVS repository locations from the project set (as keys) + * and confirmed CVS repository locations to be used during checkout + * (as values) or null if the operation is to be + * canceled + */ + public abstract Object promptForAlternativeRepository(Map alternativeMap); } #P org.eclipse.team.cvs.ui Index: src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java,v retrieving revision 1.69 diff -u -r1.69 CVSUIMessages.java --- src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 18 Apr 2007 20:27:08 -0000 1.69 +++ src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 20 Apr 2007 15:33:28 -0000 @@ -336,6 +336,13 @@ public static String CommitWizardFileTypePage_0; public static String CommitWizardFileTypePage_2; public static String CommitWizardFileTypePage_3; + + public static String AlternativeRepositoryWizard_title; + public static String AlternativeRepositoryWizard_message; + public static String AlternativeRepositoryWizard_createLocation; + public static String AlternativeRepositoryWizard_createLocationTooltip; + public static String AlternativeRepositoryWizard_column0; + public static String AlternativeRepositoryWizard_column1; public static String CommitSyncAction_questionRelease; public static String CommitSyncAction_titleRelease; @@ -493,6 +500,14 @@ public static String NewLocationWizard_validationFailedText; public static String NewLocationWizard_validationFailedTitle; public static String NewLocationWizard_exception; + + public static String AlternativeLocationWizard_title; + public static String AlternativeLocationWizard_heading; + public static String AlternativeLocationWizard_description; + public static String AlternativeLocationWizard_validationFailedText; + public static String AlternativeLocationWizard_validationFailedTitle; + public static String AlternativeLocationWizard_exception; + public static String OpenLogEntryAction_deletedTitle; public static String OpenLogEntryAction_deleted; Index: src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java,v retrieving revision 1.32 diff -u -r1.32 WorkbenchUserAuthenticator.java --- src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java 23 Mar 2007 19:54:53 -0000 1.32 +++ src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java 20 Apr 2007 15:33:28 -0000 @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.team.internal.ccvs.ui; +import java.util.Map; + import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.jface.dialogs.*; import org.eclipse.jface.window.Window; @@ -321,4 +323,32 @@ } return openConfirm[0]; } + + /* + * (non-Javadoc) + * + * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#promptForAlternativeRepository(java.util.Map) + */ + public Object promptForAlternativeRepository(final Map alternativeMap) { + + final Object[] result = new Object[1]; + Display display = Display.getCurrent(); + if (display != null) { + result[0] = openAlternativeRepositoryDialog(alternativeMap); + } else { + // sync exec in default thread + Display.getDefault().syncExec(new Runnable() { + public void run() { + result[0] = openAlternativeRepositoryDialog(alternativeMap); + } + }); + } + return result[0]; + } + + private Object openAlternativeRepositoryDialog(Map alternativeMap) { + AlternativeRepositoryDialog dialog = new AlternativeRepositoryDialog(null, alternativeMap); + int result = dialog.open(); + return result==1?null:dialog.getSelected(); + } } Index: src/org/eclipse/team/internal/ccvs/ui/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties,v retrieving revision 1.517 diff -u -r1.517 messages.properties --- src/org/eclipse/team/internal/ccvs/ui/messages.properties 20 Apr 2007 14:18:16 -0000 1.517 +++ src/org/eclipse/team/internal/ccvs/ui/messages.properties 20 Apr 2007 15:33:29 -0000 @@ -285,6 +285,13 @@ CommitWizardFileTypePage_2=Unknown new files detected. CommitWizardFileTypePage_3=New files with the following unknown names or extensions have been detected in the workspace. Please specify whether these files should be stored as text or binary and whether this decision should be remembered. +AlternativeRepositoryWizard_title=Select alternative repository +AlternativeRepositoryWizard_message=Select an alternative repository or create new based on a existing one +AlternativeRepositoryWizard_createLocation=Create Location +AlternativeRepositoryWizard_createLocationTooltip=Creates Location from a selected alternative repository +AlternativeRepositoryWizard_column0=Repository Location from the project set +AlternativeRepositoryWizard_column1=Alternative Repository Location + CommitSyncAction_questionRelease=You have changes that conflict with the server. Release those changes? CommitSyncAction_titleRelease=Confirm Overwrite CommitSyncAction_releaseAll=Release all changes, overriding any conflicting changes on the server. @@ -449,6 +456,13 @@ NewLocationWizard_validationFailedTitle=Unable to Validate NewLocationWizard_exception=Unable to create repository location +AlternativeLocationWizard_title=Configure CVS Repository +AlternativeLocationWizard_heading=Configure an alternative CVS Repository +AlternativeLocationWizard_description=Configure an alternative CVS Repository +AlternativeLocationWizard_validationFailedText=Error validating location: "{0}"\n\nUse location anyway? +AlternativeLocationWizard_validationFailedTitle=Unable to Validate +AlternativeLocationWizard_exception=Unable to create repository location + OpenLogEntryAction_deletedTitle=Resource is Deleted OpenLogEntryAction_deleted=The selected revision represents a deletion. It cannot be opened. Index: src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java,v retrieving revision 1.28 diff -u -r1.28 NewLocationWizard.java --- src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java 26 Jun 2006 19:31:25 -0000 1.28 +++ src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java 20 Apr 2007 15:33:29 -0000 @@ -32,8 +32,8 @@ public class NewLocationWizard extends Wizard implements IWorkbenchWizard { - private ConfigurationWizardMainPage mainPage; - private Properties properties = null; + protected ConfigurationWizardMainPage mainPage; + protected Properties properties = null; private boolean switchPerspectives = true; /** Index: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java diff -N src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,290 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.team.internal.ccvs.ui; + +import java.util.*; +import java.util.List; + +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TableEditor; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.widgets.*; +import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; +import org.eclipse.team.internal.ui.SWTUtils; + + +public class AlternativeRepositoryTable implements ICellModifier, IStructuredContentProvider, ITableLabelProvider { + + private static final class AlternativeRepositoryComparator extends + ViewerComparator { + + public AlternativeRepositoryComparator() { + } + + private int getCategory(Object element) { + if (element instanceof RepositoryLocationItem) { + return 0; + } + return 2; + } + + public int compare(Viewer viewer, Object e1, Object e2) { + final int compare = getCategory(e1) - getCategory(e2); + if (compare != 0) + return compare; + return super.compare(viewer, ((Item) e1).location, + ((Item) e2).location); + } + } + + public abstract static class Item implements Comparable { + public final String location; + public List alternativeList; + public int selected; + + public Item(String name, List alternative) { + this.location = name; + this.alternativeList = alternative; + this.selected = 0; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object o) { + return location.compareTo(((Item) o).location); + } + } + + public static class RepositoryLocationItem extends Item { + public RepositoryLocationItem(CVSRepositoryLocation repo, + List repositoryLocation) { + super(repo.getLocation(), repositoryLocation); + } + } + + protected static final String ITEM = "item"; //$NON-NLS-1$ + protected static final String PROPERTY_ALTERNATIVE_LIST = "alternativeList"; //$NON-NLS-1$ + + private final TableViewer fTableViewer; + private final List fItems; + + private CellEditor[] cellEditors; + + private TextCellEditor dummyAlternativeRepositoryEditor; + + private final Table table; + + public AlternativeRepositoryTable(final Composite composite, List items) { + + fItems = items; + + /** + * Create a table. + */ + table = new Table(composite, SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); + table.setLayoutData(SWTUtils.createHVFillGridData()); + table.setLinesVisible(true); + table.setHeaderVisible(true); + table.addListener(SWT.MeasureItem, new Listener() { + public void handleEvent(Event event) { +// int clientWidth = table.getClientArea().width; + event.height = event.gc.getFontMetrics().getHeight() + 5; +// event.width = clientWidth * 2; + } + }); + + /** + * The 'Project Set repository location' column + */ + final TableColumn projectSetRepositoryColumn = new TableColumn(table, SWT.NONE, 0); + projectSetRepositoryColumn.setText(CVSUIMessages.AlternativeRepositoryWizard_column0); + + /** + * The 'Alternative repository locations' column + */ + final TableColumn alternativeRepositoryColums = new TableColumn(table, SWT.NONE, 1); + alternativeRepositoryColums.setText(CVSUIMessages.AlternativeRepositoryWizard_column1); + + composite.addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + Rectangle area = composite.getClientArea(); + Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); + ScrollBar vBar = table.getVerticalBar(); + int width = area.width - table.computeTrim(0,0,0,0).width - vBar.getSize().x; + if (size.y > area.height + table.getHeaderHeight()) { + // Subtract the scrollbar width from the total column width + // if a vertical scrollbar will be required + Point vBarSize = vBar.getSize(); + width -= vBarSize.x; + } + Point oldSize = table.getSize(); + if (oldSize.x > area.width) { + // table is getting smaller so make the columns + // smaller first and then resize the table to + // match the client area width + projectSetRepositoryColumn.setWidth(width/2); + alternativeRepositoryColums.setWidth(width - projectSetRepositoryColumn.getWidth()); + table.setSize(area.width, area.height); + } else { + // table is getting bigger so make the table + // bigger first and then make the columns wider + // to match the client area width + table.setSize(area.width, area.height); + projectSetRepositoryColumn.setWidth(width/2); + alternativeRepositoryColums.setWidth(width - projectSetRepositoryColumn.getWidth()); + } + } + }); + + /** + * Create a viewer for the table. + */ + fTableViewer = new TableViewer(table); + fTableViewer.setContentProvider(this); + fTableViewer.setLabelProvider(this); + fTableViewer.setComparator(new AlternativeRepositoryComparator()); + + /** + * Add a cell editor in the 'Alternative repository locations' column + */ + new TableEditor(table); + + cellEditors = new CellEditor[2]; + cellEditors[0] = null; + // to enable cell editing, create a dummy cell editor + cellEditors[1] = dummyAlternativeRepositoryEditor = new TextCellEditor(table, SWT.READ_ONLY); + + fTableViewer.setCellEditors(cellEditors); + fTableViewer.setColumnProperties(new String [] { ITEM, PROPERTY_ALTERNATIVE_LIST }); + fTableViewer.setCellModifier(this); + fTableViewer.setInput(fItems); + } + + + public Object getValue(Object element, String property) { + + final Item item = (Item)element; + + if (PROPERTY_ALTERNATIVE_LIST.equals(property)) { + return new Integer(item.selected); + } + return null; + } + + public boolean canModify(Object element, String property) { + // set the correct cell editor for this element + cellEditors[1] = getCellEditor(element); + // only allow modification for editable elements + return PROPERTY_ALTERNATIVE_LIST.equals(property); + } + + private CellEditor getCellEditor(Object element) { + + if (element instanceof RepositoryLocationItem) { + + // create combo-box list of alternative repositories + List alternativeList = ((RepositoryLocationItem) element).alternativeList; + String[] alternativeNames = new String[alternativeList.size()]; + int i = 0; + for (Iterator iterator = alternativeList.iterator(); iterator.hasNext();) { + CVSRepositoryLocation repo = (CVSRepositoryLocation) iterator.next(); + alternativeNames[i++] = repo.getLocation(); + } + return new ComboBoxCellEditor(table, alternativeNames, + SWT.READ_ONLY); + } + return dummyAlternativeRepositoryEditor; + } + + + public void modify(Object element, String property, Object value) { + + final IStructuredSelection selection = (IStructuredSelection)fTableViewer.getSelection(); + final Item item = (Item)selection.getFirstElement(); + if (item == null) + return; + + final int comboIndex = ((Integer)value).intValue(); + + if (PROPERTY_ALTERNATIVE_LIST.equals(property)) { + item.selected = comboIndex; + } + fTableViewer.refresh(item); + } + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + + final Item item = (Item) element; + + if (columnIndex == 0) { + return item.location; + } + + if (columnIndex == 1) { + return ((CVSRepositoryLocation) item.alternativeList + .get(item.selected)).getLocation(); + } + return null; + } + + public void addListener(ILabelProviderListener listener) {} + + public void dispose() {} + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) {} + + public Object[] getElements(Object inputElement) { + return ((Collection)inputElement).toArray(); + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + public IStructuredSelection getSelection() { + return (IStructuredSelection)fTableViewer.getSelection(); + } + + public TableViewer getViewer() { + return fTableViewer; + } + + public CVSRepositoryLocation getSelectedAlternativeRepository() { + RepositoryLocationItem firstElement = (RepositoryLocationItem) getSelection() + .getFirstElement(); + return (CVSRepositoryLocation) firstElement.alternativeList + .get(firstElement.selected); + } + + public void addAlternativeRepositoryToSelection( + ICVSRepositoryLocation location) { + RepositoryLocationItem firstElement = (RepositoryLocationItem) getSelection() + .getFirstElement(); + // put new alternative repository at first position + firstElement.alternativeList.add(0, location); + firstElement.selected = 0; + fTableViewer.refresh(firstElement); + } +} Index: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java diff -N src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui; + +import java.util.*; +import java.util.List; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.viewers.*; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; +import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.ui.wizards.AlternativeLocationWizard; + +public class AlternativeRepositoryDialog extends TitleAreaDialog { + + private List fAlternatives; + private Image dlgTitleImage; + private final static String windowTitle = CVSUIMessages.AlternativeRepositoryWizard_title; + private final static String title = CVSUIMessages.AlternativeRepositoryWizard_title; + private final static String message = CVSUIMessages.AlternativeRepositoryWizard_message; + + /** + * Creates a new AlternativeRepositoryDialog. + * + * @param parentShell the parent shell + * @param alternativesMap the default user name + * @param message a message to display to the user + */ + public AlternativeRepositoryDialog(Shell parentShell, Map alternativesMap) { + super(parentShell); + setShellStyle(getShellStyle() | SWT.RESIZE); + fAlternatives = new ArrayList(); + for (Iterator iterator = alternativesMap.entrySet().iterator(); iterator.hasNext();) { + Map.Entry entry = (Map.Entry) iterator.next(); + fAlternatives + .add(new AlternativeRepositoryTable.RepositoryLocationItem( + (CVSRepositoryLocation) entry.getKey(), + (List) entry.getValue())); + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.TitleAreaDialog#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + Control contents = super.createContents(parent); + setTitle(title); + setMessage(message); + dlgTitleImage = CVSUIPlugin.getPlugin().getImageDescriptor( + ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION).createImage(); + setTitleImage(dlgTitleImage); + return contents; + } + + public boolean close() { + if (dlgTitleImage != null) { + dlgTitleImage.dispose(); + } + return super.close(); + } + + /* + * (non-Javadoc) Method declared in Window. + */ + protected void configureShell(Shell shell) { + super.configureShell(shell); + if (windowTitle != null) { + shell.setText(windowTitle); + } + } + + /** + * @see Dialog#createDialogArea + */ + protected Control createDialogArea(Composite parent) { + initializeDialogUnits(parent); + + final Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(1, false)); + + // TODO: help + + GridData childData = new GridData(GridData.FILL_BOTH); + composite.setLayoutData(childData); + + final AlternativeRepositoryTable table = new AlternativeRepositoryTable(composite, fAlternatives); + + final Button createLocationButton = new Button(composite, SWT.PUSH); + createLocationButton.setText(CVSUIMessages.AlternativeRepositoryWizard_createLocation); + createLocationButton.setToolTipText(CVSUIMessages.AlternativeRepositoryWizard_createLocationTooltip); + createLocationButton.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + + CVSRepositoryLocation selectedAlternativeRepository = table.getSelectedAlternativeRepository(); + + Properties properties = new Properties(); + properties.put("connection", selectedAlternativeRepository.getMethod()); //$NON-NLS-1$ + properties.put("user", selectedAlternativeRepository.getUsername()); //$NON-NLS-1$ + //TODO: +// properties.put("password", ""); //$NON-NLS-1$ + properties.put("host", selectedAlternativeRepository.getHost()); //$NON-NLS-1$ + int port = selectedAlternativeRepository.getPort(); + if (port != ICVSRepositoryLocation.USE_DEFAULT_PORT) + properties.put("port", String.valueOf(port)); //$NON-NLS-1$ + properties.put("root", selectedAlternativeRepository.getRootDirectory()); //$NON-NLS-1$ + + AlternativeLocationWizard wizard = new AlternativeLocationWizard(properties); + wizard.setSwitchPerspectives(false); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + dialog.open(); + + ICVSRepositoryLocation location = wizard.getLocation(); + if (location != null) + table.addAlternativeRepositoryToSelection(location); + } + }); + createLocationButton.setEnabled(table.getSelection().getFirstElement() != null); + + table.getViewer().addSelectionChangedListener( + new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection sel = (IStructuredSelection) event + .getSelection(); + Object firstElement = sel.getFirstElement(); + createLocationButton.setEnabled(firstElement != null); + } + }); + + return composite; + } + + protected Point getInitialSize() { + //TODO: read/write using memento + return new Point(600, 500); + } + + public Map getSelected() { + Map map = new HashMap(); + for (Iterator iterator = fAlternatives.iterator(); iterator.hasNext();) { + AlternativeRepositoryTable.RepositoryLocationItem rli = (AlternativeRepositoryTable.RepositoryLocationItem) iterator + .next(); + map.put(rli.location, rli.alternativeList.get(rli.selected)); + } + return map; + } +} Index: src/org/eclipse/team/internal/ccvs/ui/wizards/AlternativeLocationWizard.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/ui/wizards/AlternativeLocationWizard.java diff -N src/org/eclipse/team/internal/ccvs/ui/wizards/AlternativeLocationWizard.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/ui/wizards/AlternativeLocationWizard.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui.wizards; + +import java.lang.reflect.InvocationTargetException; +import java.util.Properties; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.osgi.util.NLS; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; +import org.eclipse.team.internal.ccvs.ui.*; + +public class AlternativeLocationWizard extends NewLocationWizard { + + private ICVSRepositoryLocation location; + + public boolean performFinish() { + final ICVSRepositoryLocation[] location = new ICVSRepositoryLocation[] { null }; + boolean useLocation = true; + try { + // Create a handle to a repository location + location[0] = mainPage.getLocation(); + // Add the location quitely so we can validate + location[0] = KnownRepositories.getInstance().addRepository(location[0], false /* don't tell anybody */); + + if (mainPage.getValidate()) { + try { + getContainer().run(true, true, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + location[0].validateConnection(monitor); + } catch (TeamException e) { + throw new InvocationTargetException(e); + } + } + }); + } catch (InterruptedException e) { + // Cancelled by user. Fall through to dispose of location + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + if (t instanceof TeamException) { + throw (TeamException)t; + } else if (t instanceof Exception) { + throw CVSException.wrapException((Exception)t); + } else { + throw CVSException.wrapException(e); + } + } + } + } catch (TeamException e) { + if (location[0] == null) { + // Exception creating the root, we cannot continue + CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_exception, null, e); + return false; + } else { + // Exception validating. We can continue if the user wishes. + IStatus error = e.getStatus(); + if (error.isMultiStatus() && error.getChildren().length == 1) { + error = error.getChildren()[0]; + } + + if (error.isMultiStatus()) { + CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, null, e); + } else { + useLocation = MessageDialog.openQuestion(getContainer().getShell(), + CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, + NLS.bind(CVSUIMessages.AlternativeLocationWizard_validationFailedText, (new Object[] {error.getMessage()}))); + } + } + } + + KnownRepositories.getInstance().disposeRepository(location[0]); + + this.location = useLocation ? location[0] : null; + return true; + } + + public AlternativeLocationWizard(Properties initialProperties) { + super(initialProperties); + } + + /** + * Creates the wizard pages + */ + public void addPages() { + mainPage = new ConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.AlternativeLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ + if (properties != null) { + mainPage.setProperties(properties); + } + mainPage.setShowValidate(true); + mainPage.setDescription(CVSUIMessages.AlternativeLocationWizard_description); + mainPage.setDialogSettings(getDialogSettings()); + addPage(mainPage); + } + + public ICVSRepositoryLocation getLocation() { + return location; + } + +}