diff options
author | Matthias Sohn | 2013-05-19 00:19:19 +0000 |
---|---|---|
committer | Matthias Sohn | 2013-05-19 00:44:53 +0000 |
commit | a199322e4a2755ac3451bb41efa6f37e408e47d9 (patch) | |
tree | efa2312ade0d3d0bb543c4b8df71ec9512af6170 /org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal | |
parent | fba31ed7bb17b78cfefc347c2a1ce5c1ea1dc937 (diff) | |
download | egit-a199322e4a2755ac3451bb41efa6f37e408e47d9.tar.gz egit-a199322e4a2755ac3451bb41efa6f37e408e47d9.tar.xz egit-a199322e4a2755ac3451bb41efa6f37e408e47d9.zip |
Move implementation of import feature to o.e.egit.ui bundle
Since the oldest release EGit will support with 3.0 is Juno we can move
the implementation for importing a git repository from an installed
bundle with a Eclipse-SourceReferences header in its manifest to the
org.eclipse.egit.ui bundle and remove the indigo target platform.
Change-Id: I7acaf5b26aa9f305d23f828459ecd272ed13fbdc
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal')
3 files changed, 275 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java index 961fc951f2..37644de31f 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java @@ -4770,6 +4770,21 @@ public class UIText extends NLS { /** */ public static String GitModelSynchronizeParticipant_noCachedSourceVariant; + /** */ + public static String GitScmUrlImportWizardPage_title; + + /** */ + public static String GitScmUrlImportWizardPage_description; + + /** */ + public static String GitScmUrlImportWizardPage_importMaster; + + /** */ + public static String GitScmUrlImportWizardPage_importVersion; + + /** */ + public static String GitScmUrlImportWizardPage_counter; + static { initializeMessages(BUNDLE_NAME, UIText.class); } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/importing/GitScmUrlImportWizardPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/importing/GitScmUrlImportWizardPage.java new file mode 100644 index 0000000000..4ab18cae50 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/importing/GitScmUrlImportWizardPage.java @@ -0,0 +1,254 @@ +/******************************************************************************* + * Copyright (c) 2012 Tomasz Zarna 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: + * Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> - initial implementation + *******************************************************************************/ +package org.eclipse.egit.ui.internal.importing; + +import java.net.URI; + +import org.eclipse.egit.core.internal.GitURI; +import org.eclipse.egit.ui.internal.SWTUtils; +import org.eclipse.egit.ui.internal.UIText; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.StyledCellLabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.team.core.ScmUrlImportDescription; +import org.eclipse.team.ui.IScmUrlImportWizardPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; + +/** + * Wizard page that allows the user to import repositories with SCM URLs. + */ +public class GitScmUrlImportWizardPage extends WizardPage implements + IScmUrlImportWizardPage { + + private ScmUrlImportDescription[] descriptions; + private Label counterLabel; + private TableViewer bundlesViewer; + private Button useMaster; + + private static final String GIT_PAGE_USE_MASTER = "org.eclipse.team.egit.ui.import.page.master"; //$NON-NLS-1$ + + static class GitLabelProvider extends StyledCellLabelProvider implements ILabelProvider { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) + */ + public Image getImage(Object element) { + return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + return getStyledText(element).getString(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell) + */ + public void update(ViewerCell cell) { + StyledString string = getStyledText(cell.getElement()); + cell.setText(string.getString()); + cell.setStyleRanges(string.getStyleRanges()); + cell.setImage(getImage(cell.getElement())); + super.update(cell); + } + + private StyledString getStyledText(Object element) { + StyledString styledString = new StyledString(); + if (element instanceof ScmUrlImportDescription) { + ScmUrlImportDescription description = (ScmUrlImportDescription) element; + String project = description.getProject(); + URI scmUrl = description.getUri(); + String version = getTag(scmUrl); + String host = getServer(scmUrl); + styledString.append(project); + if (version != null) { + styledString.append(' '); + styledString.append(version, StyledString.DECORATIONS_STYLER); + } + styledString.append(' '); + styledString.append('[', StyledString.DECORATIONS_STYLER); + styledString.append(host, StyledString.DECORATIONS_STYLER); + styledString.append(']', StyledString.DECORATIONS_STYLER); + return styledString; + } + styledString.append(element.toString()); + return styledString; + } + } + + /** + * Constructs the page. + */ + public GitScmUrlImportWizardPage() { + super("git", UIText.GitScmUrlImportWizardPage_title, null); //$NON-NLS-1$ + setDescription(UIText.GitScmUrlImportWizardPage_description); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + Composite comp = SWTUtils.createHVFillComposite(parent, SWTUtils.MARGINS_NONE, 1); + Composite group = SWTUtils.createHFillComposite(comp, SWTUtils.MARGINS_NONE, 1); + + Button versions = SWTUtils.createRadioButton(group, + UIText.GitScmUrlImportWizardPage_importVersion); + useMaster = SWTUtils.createRadioButton(group, + UIText.GitScmUrlImportWizardPage_importMaster); + SelectionListener listener = new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + bundlesViewer.refresh(true); + } + }; + versions.addSelectionListener(listener); + useMaster.addSelectionListener(listener); + + Table table = new Table(comp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 200; + gd.widthHint = 225; + table.setLayoutData(gd); + + bundlesViewer = new TableViewer(table); + bundlesViewer.setLabelProvider(new GitLabelProvider()); + bundlesViewer.setContentProvider(new ArrayContentProvider()); + bundlesViewer.setComparator(new ViewerComparator()); + counterLabel = new Label(comp, SWT.NONE); + counterLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + setControl(comp); + setPageComplete(true); + + // Initialize versions versus master + // TODO: temporarily disabled, until bug 367712 is fixed + // IDialogSettings settings = getWizard().getDialogSettings(); + // boolean useHEAD = settings != null + // && settings.getBoolean(GIT_PAGE_USE_MASTER); + // useHead.setSelection(useHEAD); + // versions.setSelection(!useHEAD); + useMaster.setSelection(true); + versions.setEnabled(false); + + if (descriptions != null) { + bundlesViewer.setInput(descriptions); + updateCount(); + } + + } + + public boolean finish() { + boolean head = false; + if (getControl() != null) { + head = useMaster.getSelection(); + // store settings + IDialogSettings settings = getWizard().getDialogSettings(); + if (settings != null) + settings.put(GIT_PAGE_USE_MASTER, head); + } else { + // use whatever was used last time + IDialogSettings settings = getWizard().getDialogSettings(); + if (settings != null) + head = settings.getBoolean(GIT_PAGE_USE_MASTER); + } + + if (head && descriptions != null) + // modify tags on bundle import descriptions + for (int i = 0; i < descriptions.length; i++) { + URI scmUri = descriptions[i].getUri(); + descriptions[i].setUrl(removeTag(scmUri)); + } + + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.IScmUrlImportWizardPage#getSelection() + */ + public ScmUrlImportDescription[] getSelection() { + return descriptions; + } + + public void setSelection(ScmUrlImportDescription[] descriptions) { + this.descriptions = descriptions; + // fill viewer + if (bundlesViewer != null) { + bundlesViewer.setInput(descriptions); + updateCount(); + } + } + + /** + * Updates the count of bundles that will be imported + */ + private void updateCount() { + counterLabel.setText(NLS.bind(UIText.GitScmUrlImportWizardPage_counter, + Integer.valueOf(descriptions.length))); + counterLabel.getParent().layout(); + } + + private static String getTag(URI scmUri) { + GitURI gitURI = new GitURI(scmUri); + return gitURI.getTag(); + } + + /** + * Remove tag attributes from the given URI reference. Results in the URI + * pointing to HEAD. + * + * @param scmUri + * a SCM URI reference to modify + * @return Returns the content of the stripped URI as a string. + */ + private static String removeTag(URI scmUri) { + StringBuffer sb = new StringBuffer(); + sb.append(scmUri.getScheme()).append(':'); + String ssp = scmUri.getSchemeSpecificPart(); + int j = ssp.indexOf(';'); + if (j != -1) { + sb.append(ssp.substring(0, j)); + String[] params = ssp.substring(j).split(";"); //$NON-NLS-1$ + for (int k = 0; k < params.length; k++) + // PDE way of providing tags + if (params[k].startsWith("tag=")) { //$NON-NLS-1$ + // ignore + } else if (params[k].startsWith("version=")) { //$NON-NLS-1$ + // ignore + } else if (params[k]!=null && !params[k].equals("")) //$NON-NLS-1$ + sb.append(";").append(params[k]); //$NON-NLS-1$ + } else + sb.append(ssp); + return sb.toString(); + } + + private static String getServer(URI scmUri) { + GitURI gitURI = new GitURI(scmUri); + return gitURI.getRepository().toString(); + } +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties index de17338434..5cdfc96147 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties @@ -1676,3 +1676,9 @@ RepositoryStatistics_PackedObjects=Packed objects GitModelSynchronizeParticipant_initialScopeName=Git GitModelSynchronizeParticipant_noCachedSourceVariant=Could not locate cached source variant for resource: {0} + +GitScmUrlImportWizardPage_title=Import Projects from Git +GitScmUrlImportWizardPage_description=Import Git projects corresponding to plug-ins and fragments in the file system. +GitScmUrlImportWizardPage_importMaster=Import from &master +GitScmUrlImportWizardPage_importVersion=Import the indicated &version +GitScmUrlImportWizardPage_counter=Total: {0}
\ No newline at end of file |