/** * Returns all the remote configs from the given repository. * * @param repository the repository to retrieve the remote configs of * @return the remote configs that are available on the repository * @throws CoreException */ public static List<RemoteConfig> getAllRemoteConfigs(Repository repository) throws CoreException { if (repository == null) { return Collections.emptyList(); } try { return RemoteConfig.getAllRemoteConfigs(repository.getConfig()); } catch (URISyntaxException e) { throw new CoreException( createStatus( e, "Could not get all remote repositories for repository \"{0}\"", repository.toString())); } }
public void createControl(Composite parent) { Clipboard clipboard = new Clipboard(parent.getDisplay()); String clipText = (String) clipboard.getContents(TextTransfer.getInstance()); String defaultUri = null; String defaultCommand = null; String defaultChange = null; if (clipText != null) { final String pattern = "git fetch (\\w+:\\S+) (refs/changes/\\d+/\\d+/\\d+) && git (\\w+) FETCH_HEAD"; //$NON-NLS-1$ Matcher matcher = Pattern.compile(pattern).matcher(clipText); if (matcher.matches()) { defaultUri = matcher.group(1); defaultChange = matcher.group(2); defaultCommand = matcher.group(3); } } Composite main = new Composite(parent, SWT.NONE); main.setLayout(new GridLayout(2, false)); GridDataFactory.fillDefaults().grab(true, true).applyTo(main); new Label(main, SWT.NONE).setText(UIText.FetchGerritChangePage_UriLabel); uriCombo = new Combo(main, SWT.DROP_DOWN); GridDataFactory.fillDefaults().grab(true, false).applyTo(uriCombo); uriCombo.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { changeRefs = null; } }); new Label(main, SWT.NONE).setText(UIText.FetchGerritChangePage_ChangeLabel); refText = new Text(main, SWT.BORDER); if (defaultChange != null) refText.setText(defaultChange); GridDataFactory.fillDefaults().grab(true, false).applyTo(refText); addRefContentProposalToText(refText); Group checkoutGroup = new Group(main, SWT.SHADOW_ETCHED_IN); checkoutGroup.setLayout(new GridLayout(2, false)); GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(checkoutGroup); checkoutGroup.setText(UIText.FetchGerritChangePage_AfterFetchGroup); // radio: create local branch createBranch = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(createBranch); createBranch.setText(UIText.FetchGerritChangePage_LocalBranchRadio); createBranch.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); branchTextlabel = new Label(checkoutGroup, SWT.NONE); GridDataFactory.defaultsFor(branchTextlabel).exclude(false).applyTo(branchTextlabel); branchTextlabel.setText(UIText.FetchGerritChangePage_BranchNameText); branchText = new Text(checkoutGroup, SWT.SINGLE | SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText); branchText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { checkPage(); } }); // radio: create tag createTag = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(createTag); createTag.setText(UIText.FetchGerritChangePage_TagRadio); createTag.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); tagTextlabel = new Label(checkoutGroup, SWT.NONE); GridDataFactory.defaultsFor(tagTextlabel).exclude(true).applyTo(tagTextlabel); tagTextlabel.setText(UIText.FetchGerritChangePage_TagNameText); tagText = new Text(checkoutGroup, SWT.SINGLE | SWT.BORDER); GridDataFactory.fillDefaults().exclude(true).grab(true, false).applyTo(tagText); tagText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { checkPage(); } }); // radio: checkout FETCH_HEAD checkout = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(checkout); checkout.setText(UIText.FetchGerritChangePage_CheckoutRadio); checkout.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); // radio: don't checkout dontCheckout = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(checkout); dontCheckout.setText(UIText.FetchGerritChangePage_UpdateRadio); dontCheckout.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); if ("checkout".equals(defaultCommand)) // $NON-NLS-1$ checkout.setSelection(true); else createBranch.setSelection(true); warningAdditionalRefNotActive = new Composite(main, SWT.NONE); GridDataFactory.fillDefaults() .span(2, 1) .grab(true, false) .exclude(true) .applyTo(warningAdditionalRefNotActive); warningAdditionalRefNotActive.setLayout(new GridLayout(2, false)); warningAdditionalRefNotActive.setVisible(false); activateAdditionalRefs = new Button(warningAdditionalRefNotActive, SWT.CHECK); activateAdditionalRefs.setText(UIText.FetchGerritChangePage_ActivateAdditionalRefsButton); activateAdditionalRefs.setToolTipText( UIText.FetchGerritChangePage_ActivateAdditionalRefsTooltip); refText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { Change change = Change.fromRef(refText.getText()); if (change != null) { branchText.setText( NLS.bind( UIText.FetchGerritChangePage_SuggestedRefNamePattern, change.getChangeNumber(), change.getPatchSetNumber())); tagText.setText(branchText.getText()); } else { branchText.setText(""); // $NON-NLS-1$ tagText.setText(""); // $NON-NLS-1$ } checkPage(); } }); // get all available URIs from the repository SortedSet<String> uris = new TreeSet<String>(); try { for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository.getConfig())) { if (rc.getURIs().size() > 0) uris.add(rc.getURIs().get(0).toPrivateString()); for (URIish u : rc.getPushURIs()) uris.add(u.toPrivateString()); } } catch (URISyntaxException e) { Activator.handleError(e.getMessage(), e, false); setErrorMessage(e.getMessage()); } for (String aUri : uris) uriCombo.add(aUri); if (defaultUri != null) uriCombo.setText(defaultUri); else selectLastUsedUri(); refText.setFocus(); Dialog.applyDialogFont(main); setControl(main); checkPage(); }