Example usage for org.eclipse.jgit.transport URIish toPrivateString

List of usage examples for org.eclipse.jgit.transport URIish toPrivateString

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport URIish toPrivateString.

Prototype

public String toPrivateString() 

Source Link

Document

Obtain the string form of the URI, with the password included.

Usage

From source file:com.madgag.agit.GitOperationsService.java

License:Open Source License

public static Intent cloneOperationIntentFor(URIish uri, File directory, boolean bare) {
    Intent intent = new Intent("org.openintents.git.CLONE");
    intent.putExtra("source-uri", uri.toPrivateString());
    intent.putExtra(BARE, bare);//  w ww .  jav  a 2s.c  om
    addDirectoryTo(intent, directory);
    return intent;
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchGerritChangePage.java

License:Open Source License

public void createControl(Composite parent) {
    Clipboard clipboard = new Clipboard(parent.getDisplay());
    String clipText = (String) clipboard.getContents(TextTransfer.getInstance());
    String defaultUri = null;//from w  ww  . j  a  va2s.  co  m
    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();
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchOperationUI.java

License:Open Source License

/**
 * @param repository/*from   www  .ja va  2  s . c o m*/
 * @param uri
 * @param specs
 * @param timeout
 * @param dryRun
 */
public FetchOperationUI(Repository repository, URIish uri, List<RefSpec> specs, int timeout, boolean dryRun) {
    this.repository = repository;
    op = new FetchOperation(repository, uri, specs, timeout, dryRun);
    sourceString = uri.toPrivateString();
}

From source file:org.eclipse.egit.ui.internal.push.PushToGerritPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(3, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    new Label(main, SWT.NONE).setText(UIText.PushToGerritPage_UriLabel);
    uriCombo = new Combo(main, SWT.DROP_DOWN);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(uriCombo);
    uriCombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            checkPage();//from   w w w  .  java  2  s  .  com
        }
    });

    branchTextlabel = new Label(main, SWT.NONE);

    // we visualize the prefix here
    prefixCombo = new Combo(main, SWT.READ_ONLY | SWT.DROP_DOWN);
    prefixCombo.add("refs/for/"); //$NON-NLS-1$
    prefixCombo.add("refs/drafts/"); //$NON-NLS-1$
    prefixCombo.select(0);

    branchTextlabel.setText(UIText.PushToGerritPage_BranchLabel);
    branchText = new Text(main, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText);
    branchText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });

    // give focus to the nameText if label is activated using the mnemonic
    branchTextlabel.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            branchText.setFocus();
            branchText.selectAll();
        }
    });
    addRefContentProposalToText(branchText);

    // 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);
    selectLastUsedUri();
    setLastUsedBranch();
    branchText.setFocus();
    Dialog.applyDialogFont(main);
    setControl(main);
}

From source file:org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    boolean advancedMode = Activator.getDefault().getPreferenceStore().getBoolean(ADVANCED_MODE_PREFERENCE);
    final Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(1, false));
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, SWT.DEFAULT).applyTo(main);

    if (showBranchInfo) {
        Composite branchArea = new Composite(main, SWT.NONE);
        GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).applyTo(branchArea);
        GridDataFactory.fillDefaults().grab(true, false).applyTo(branchArea);

        Label branchLabel = new Label(branchArea, SWT.NONE);
        branchLabel.setText(UIText.SimpleConfigurePushDialog_BranchLabel);
        String branch;/*  ww w.  j ava  2  s.c o  m*/
        try {
            branch = repository.getBranch();
        } catch (IOException e2) {
            branch = null;
        }
        if (branch == null || ObjectId.isId(branch))
            branch = UIText.SimpleConfigurePushDialog_DetachedHeadMessage;
        Text branchText = new Text(branchArea, SWT.BORDER | SWT.READ_ONLY);
        GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText);
        branchText.setText(branch);
    }

    addDefaultOriginWarningIfNeeded(main);

    final Composite sameUriDetails = new Composite(main, SWT.NONE);
    sameUriDetails.setLayout(new GridLayout(4, false));
    GridDataFactory.fillDefaults().grab(true, false).applyTo(sameUriDetails);
    Label commonUriLabel = new Label(sameUriDetails, SWT.NONE);
    commonUriLabel.setText(UIText.SimpleConfigurePushDialog_URILabel);
    commonUriText = new Text(sameUriDetails, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(commonUriText);
    changeCommonUri = new Button(sameUriDetails, SWT.PUSH);
    changeCommonUri.setText(UIText.SimpleConfigurePushDialog_ChangeUriButton);
    changeCommonUri.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUriWizard wiz;
            if (commonUriText.getText().length() > 0)
                wiz = new SelectUriWizard(false, commonUriText.getText());
            else
                wiz = new SelectUriWizard(false);
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
                if (commonUriText.getText().length() > 0)
                    try {
                        config.removeURI(new URIish(commonUriText.getText()));
                    } catch (URISyntaxException ex) {
                        Activator.handleError(ex.getMessage(), ex, true);
                    }
                config.addURI(wiz.getUri());
                updateControls();
            }
        }
    });

    deleteCommonUri = new Button(sameUriDetails, SWT.PUSH);
    deleteCommonUri.setText(UIText.SimpleConfigurePushDialog_DeleteUriButton);
    deleteCommonUri.setEnabled(false);
    deleteCommonUri.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            config.removeURI(config.getURIs().get(0));
            updateControls();
        }
    });

    commonUriText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            deleteCommonUri.setEnabled(commonUriText.getText().length() > 0);
        }
    });

    ExpandableComposite pushUriArea = new ExpandableComposite(main,
            ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(pushUriArea);
    pushUriArea.setExpanded(!config.getPushURIs().isEmpty());
    pushUriArea.addExpansionListener(new ExpansionAdapter() {

        public void expansionStateChanged(ExpansionEvent e) {
            main.layout(true, true);
            main.getShell().pack();
        }
    });
    pushUriArea.setText(UIText.SimpleConfigurePushDialog_PushUrisLabel);
    final Composite pushUriDetails = new Composite(pushUriArea, SWT.NONE);
    pushUriArea.setClient(pushUriDetails);
    pushUriDetails.setLayout(new GridLayout(2, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(pushUriDetails);
    uriViewer = new TableViewer(pushUriDetails, SWT.BORDER | SWT.MULTI);
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 30).applyTo(uriViewer.getTable());
    uriViewer.setContentProvider(ArrayContentProvider.getInstance());

    final Composite uriButtonArea = new Composite(pushUriDetails, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(uriButtonArea);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(uriButtonArea);

    Button addUri = new Button(uriButtonArea, SWT.PUSH);
    addUri.setText(UIText.SimpleConfigurePushDialog_AddPushUriButton);
    GridDataFactory.fillDefaults().applyTo(addUri);
    addUri.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUriWizard wiz = new SelectUriWizard(false);
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
                config.addPushURI(wiz.getUri());
                updateControls();
            }
        }

    });

    final Button changeUri = new Button(uriButtonArea, SWT.PUSH);
    changeUri.setText(UIText.SimpleConfigurePushDialog_ChangePushUriButton);
    GridDataFactory.fillDefaults().applyTo(changeUri);
    changeUri.setEnabled(false);
    changeUri.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            URIish uri = (URIish) ((IStructuredSelection) uriViewer.getSelection()).getFirstElement();
            SelectUriWizard wiz = new SelectUriWizard(false, uri.toPrivateString());
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
                config.removePushURI(uri);
                config.addPushURI(wiz.getUri());
                updateControls();
            }
        }
    });
    final Button deleteUri = new Button(uriButtonArea, SWT.PUSH);
    deleteUri.setText(UIText.SimpleConfigurePushDialog_DeletePushUriButton);
    GridDataFactory.fillDefaults().applyTo(deleteUri);
    deleteUri.setEnabled(false);
    deleteUri.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            URIish uri = (URIish) ((IStructuredSelection) uriViewer.getSelection()).getFirstElement();
            config.removePushURI(uri);
            updateControls();
        }
    });

    uriViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            deleteUri.setEnabled(!uriViewer.getSelection().isEmpty());
            changeUri.setEnabled(((IStructuredSelection) uriViewer.getSelection()).size() == 1);
        }
    });

    final Group refSpecGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, SWT.DEFAULT).applyTo(refSpecGroup);
    refSpecGroup.setText(UIText.SimpleConfigurePushDialog_RefMappingGroup);
    refSpecGroup.setLayout(new GridLayout(2, false));

    specViewer = new TableViewer(refSpecGroup, SWT.BORDER | SWT.MULTI);
    specViewer.setContentProvider(ArrayContentProvider.getInstance());
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 30).applyTo(specViewer.getTable());
    specViewer.getTable().addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.stateMask == SWT.MOD1 && e.keyCode == 'v')
                doPaste();
        }
    });

    final Composite refButtonArea = new Composite(refSpecGroup, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(refButtonArea);
    GridDataFactory.fillDefaults().grab(false, true).minSize(SWT.DEFAULT, SWT.DEFAULT).applyTo(refButtonArea);

    addRefSpec = new Button(refButtonArea, SWT.PUSH);
    addRefSpec.setText(UIText.SimpleConfigurePushDialog_AddRefSpecButton);
    GridDataFactory.fillDefaults().applyTo(addRefSpec);
    addRefSpec.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            RefSpecDialog dlg = new RefSpecDialog(getShell(), repository, config, true);
            if (dlg.open() == Window.OK)
                config.addPushRefSpec(dlg.getSpec());
            updateControls();
        }
    });

    changeRefSpec = new Button(refButtonArea, SWT.PUSH);
    changeRefSpec.setText(UIText.SimpleConfigurePushDialog_ChangeRefSpecButton);
    GridDataFactory.fillDefaults().applyTo(changeRefSpec);
    changeRefSpec.setEnabled(false);
    GridDataFactory.fillDefaults().exclude(!advancedMode).applyTo(changeRefSpec);
    changeRefSpec.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            RefSpec oldSpec = (RefSpec) ((IStructuredSelection) specViewer.getSelection()).getFirstElement();
            RefSpecDialog dlg = new RefSpecDialog(getShell(), repository, config, oldSpec, true);
            if (dlg.open() == Window.OK) {
                config.removePushRefSpec(oldSpec);
                config.addPushRefSpec(dlg.getSpec());
            }
            updateControls();
        }
    });
    final Button deleteRefSpec = new Button(refButtonArea, SWT.PUSH);
    deleteRefSpec.setText(UIText.SimpleConfigurePushDialog_DeleteRefSpecButton);
    GridDataFactory.fillDefaults().applyTo(deleteRefSpec);
    deleteRefSpec.setEnabled(false);
    deleteRefSpec.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            for (Object spec : ((IStructuredSelection) specViewer.getSelection()).toArray())
                config.removePushRefSpec((RefSpec) spec);
            updateControls();
        }
    });

    final Button copySpec = new Button(refButtonArea, SWT.PUSH);
    copySpec.setText(UIText.SimpleConfigurePushDialog_CopyRefSpecButton);
    GridDataFactory.fillDefaults().applyTo(copySpec);
    copySpec.setEnabled(false);
    copySpec.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String toCopy = ((IStructuredSelection) specViewer.getSelection()).getFirstElement().toString();
            Clipboard clipboard = new Clipboard(getShell().getDisplay());
            try {
                clipboard.setContents(new String[] { toCopy },
                        new TextTransfer[] { TextTransfer.getInstance() });
            } finally {
                clipboard.dispose();
            }
        }
    });

    final Button pasteSpec = new Button(refButtonArea, SWT.PUSH);
    pasteSpec.setText(UIText.SimpleConfigurePushDialog_PasteRefSpecButton);
    GridDataFactory.fillDefaults().applyTo(pasteSpec);
    pasteSpec.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doPaste();
        }
    });

    addRefSpecAdvanced = new Button(refButtonArea, SWT.PUSH);
    addRefSpecAdvanced.setText(UIText.SimpleConfigurePushDialog_EditAdvancedButton);
    GridDataFactory.fillDefaults().applyTo(addRefSpecAdvanced);
    addRefSpecAdvanced.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (new WizardDialog(getShell(), new RefSpecWizard(repository, config, true)).open() == Window.OK)
                updateControls();
        }
    });

    specViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) specViewer.getSelection();
            copySpec.setEnabled(sel.size() == 1);
            changeRefSpec.setEnabled(sel.size() == 1);
            deleteRefSpec.setEnabled(!sel.isEmpty());
        }
    });

    applyDialogFont(main);
    return main;
}

From source file:org.eclipse.egit.ui.internal.repository.ConfigureUriPage.java

License:Open Source License

/**
 * Sets the URI (only useful for push use case)
 *
 * @param uri/*ww w. j ava2s  .com*/
 */
public void setURI(URIish uri) {
    myUri = uri;
    uriText.setText(uri.toPrivateString());
    checkPage();
}

From source file:org.eclipse.egit.ui.internal.repository.ConfigureUriPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);

    if (myFetchMode) {
        main.setLayout(new GridLayout(3, false));
        // we only use the first URI
        Label uriLabel = new Label(main, SWT.NONE);
        uriLabel.setText(UIText.ConfigureUriPage_FetchUri_label);
        uriLabel.setToolTipText(UIText.ConfigureUriPage_UriTooltip);
        uriText = new Text(main, SWT.BORDER);
        // manual entry is dangerous, as the validate may wait forever
        uriText.setEnabled(false);//from w ww  .  j av  a 2s  . c  o  m

        Button change = new Button(main, SWT.PUSH);
        change.setText(UIText.ConfigureUriPage_Change_button);
        change.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                SelectUriWizard slwz = new SelectUriWizard(false, uriText.getText());
                WizardDialog dlg = new WizardDialog(getShell(), slwz);
                dlg.setHelpAvailable(false);
                if (dlg.open() == Window.OK) {
                    URIish uri = slwz.getUri();
                    credentials = slwz.getCredentials();
                    uriText.setText(uri.toPrivateString());
                    checkPage();
                }
            }

        });

        if (myConfig != null && !myConfig.getURIs().isEmpty()) {
            uriText.setText(myConfig.getURIs().get(0).toPrivateString());
            checkPage();
        } else {
            setPageComplete(false);
        }

        GridDataFactory.fillDefaults().grab(true, false).applyTo(uriText);

    } else {
        main.setLayout(new GridLayout(2, false));

        Label uriLabel = new Label(main, SWT.NONE);
        uriLabel.setText(UIText.ConfigureUriPage_FetchUri_label);
        uriLabel.setToolTipText(UIText.ConfigureUriPage_UriTooltip);
        uriText = new Text(main, SWT.BORDER);
        GridDataFactory.fillDefaults().grab(true, false).applyTo(uriText);
        // push mode, display only
        uriText.setEnabled(false);

        Label pushLabel = new Label(main, SWT.NONE);
        pushLabel.setText(UIText.ConfigureUriPage_PushUriLabel);
        pushLabel.setToolTipText(UIText.ConfigureUriPage_PushUriTooltip);
        GridDataFactory.fillDefaults().span(2, 1).applyTo(pushLabel);

        tv = new TableViewer(main);

        GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(tv.getTable());

        tv.setLabelProvider(new LabelProvider());
        tv.setContentProvider(ArrayContentProvider.getInstance());

        Composite buttonBar = new Composite(main, SWT.NONE);
        GridDataFactory.fillDefaults().span(2, 1).applyTo(buttonBar);
        buttonBar.setLayout(new RowLayout());
        Button add = new Button(buttonBar, SWT.PUSH);
        add.setText(UIText.ConfigureUriPage_Add_button);

        add.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                SelectUriWizard selectWizard = new SelectUriWizard(false);
                WizardDialog dlg = new WizardDialog(getShell(), selectWizard);
                dlg.setHelpAvailable(false);
                if (dlg.open() == Window.OK) {
                    URIish uri = selectWizard.getUri();
                    if (uri.equals(myUri) || myUris.contains(uri)) {
                        String message = NLS.bind(UIText.ConfigureUriPage_DuplicateUriMessage,
                                uri.toPrivateString());
                        MessageDialog.openInformation(getShell(), UIText.ConfigureUriPage_DuplicateUriTitle,
                                message);
                        return;
                    }
                    credentials = selectWizard.getCredentials();
                    myUris.add(uri);
                    tv.setInput(myUris);
                    checkPage();
                }
            }

        });

        final Button remove = new Button(buttonBar, SWT.PUSH);
        remove.setText(UIText.ConfigureUriPage_Remove_button);
        remove.setEnabled(false);

        remove.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                for (Object o : ((IStructuredSelection) tv.getSelection()).toArray())
                    myUris.remove(o);
                tv.setInput(myUris);
                checkPage();
            }

        });

        tv.addSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent event) {
                remove.setEnabled(!tv.getSelection().isEmpty());

            }
        });

        // to enable keyboard-only operation, let's set the selection upon
        // traverse
        tv.getControl().addTraverseListener(new TraverseListener() {
            public void keyTraversed(TraverseEvent e) {
                if (tv.getTable().getSelection().length == 0) {
                    if (tv.getTable().getItemCount() > 0) {
                        tv.setSelection(new StructuredSelection(tv.getTable().getItem(0)));
                    }
                }
            }
        });

        if (myConfig != null) {
            if (!myConfig.getURIs().isEmpty()) {
                myUri = myConfig.getURIs().get(0);
                uriText.setText(myUri.toPrivateString());
            }
            for (URIish uri : myConfig.getPushURIs())
                myUris.add(uri);
            tv.setInput(myUris);
            checkPage();
        } else {
            setPageComplete(false);
        }
    }

    Dialog.applyDialogFont(main);
    setControl(main);
}

From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider.java

License:Open Source License

public Object[] getChildren(Object parentElement) {

    RepositoryTreeNode node = (RepositoryTreeNode) parentElement;
    Repository repo = node.getRepository();

    switch (node.getType()) {

    case BRANCHES: {
        List<RepositoryTreeNode> nodes = new ArrayList<RepositoryTreeNode>();
        nodes.add(new LocalNode(node, repo));
        nodes.add(new RemoteTrackingNode(node, repo));
        return nodes.toArray();
    }//  w w w . jav a  2  s  .c om

    case LOCAL: {
        if (branchHierarchyMode) {
            BranchHierarchyNode hierNode = new BranchHierarchyNode(node, repo, new Path(Constants.R_HEADS));
            List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
            try {
                for (IPath path : hierNode.getChildPaths()) {
                    children.add(new BranchHierarchyNode(node, node.getRepository(), path));
                }
                for (Ref ref : hierNode.getChildRefs()) {
                    children.add(new RefNode(node, node.getRepository(), ref));
                }
            } catch (IOException e) {
                return handleException(e, node);
            }
            return children.toArray();
        } else {
            List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
            try {
                for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_HEADS)
                        .entrySet()) {
                    if (!refEntry.getValue().isSymbolic())
                        refs.add(new RefNode(node, repo, refEntry.getValue()));
                }
            } catch (IOException e) {
                return handleException(e, node);
            }
            return refs.toArray();
        }
    }

    case REMOTETRACKING: {
        if (branchHierarchyMode) {
            BranchHierarchyNode hierNode = new BranchHierarchyNode(node, repo, new Path(Constants.R_REMOTES));
            List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
            try {
                for (IPath path : hierNode.getChildPaths()) {
                    children.add(new BranchHierarchyNode(node, node.getRepository(), path));
                }
                for (Ref ref : hierNode.getChildRefs()) {
                    children.add(new RefNode(node, node.getRepository(), ref));
                }
            } catch (IOException e) {
                return handleException(e, node);
            }
            return children.toArray();
        } else {
            List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
            try {
                for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_REMOTES)
                        .entrySet()) {
                    if (!refEntry.getValue().isSymbolic())
                        refs.add(new RefNode(node, repo, refEntry.getValue()));
                }
            } catch (IOException e) {
                return handleException(e, node);
            }

            return refs.toArray();
        }
    }

    case BRANCHHIERARCHY: {
        BranchHierarchyNode hierNode = (BranchHierarchyNode) node;
        List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
        try {
            for (IPath path : hierNode.getChildPaths()) {
                children.add(new BranchHierarchyNode(node, node.getRepository(), path));
            }
            for (Ref ref : hierNode.getChildRefs()) {
                children.add(new RefNode(node, node.getRepository(), ref));
            }
        } catch (IOException e) {
            return handleException(e, node);
        }
        return children.toArray();
    }

    case TAGS: {
        List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();

        try {
            for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_TAGS).entrySet()) {
                refs.add(new TagNode(node, repo, refEntry.getValue()));
            }
        } catch (IOException e) {
            return handleException(e, node);
        }

        return refs.toArray();
    }

    case ADDITIONALREFS: {
        List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
        try {
            for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(RefDatabase.ALL).entrySet()) {
                String name = refEntry.getKey();
                if (!(name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_TAGS)
                        || name.startsWith(Constants.R_REMOTES)))
                    refs.add(new AdditionalRefNode(node, repo, refEntry.getValue()));
            }
            for (Ref r : repo.getRefDatabase().getAdditionalRefs())
                refs.add(new AdditionalRefNode(node, repo, r));
        } catch (IOException e) {
            return handleException(e, node);
        }
        return refs.toArray();
    }

    case REMOTES: {
        List<RepositoryTreeNode<String>> remotes = new ArrayList<RepositoryTreeNode<String>>();

        Repository rep = node.getRepository();

        Set<String> configNames = rep.getConfig().getSubsections(RepositoriesView.REMOTE);

        for (String configName : configNames) {
            remotes.add(new RemoteNode(node, repo, configName));
        }

        return remotes.toArray();
    }

    case REPO: {

        List<RepositoryTreeNode<? extends Object>> nodeList = new ArrayList<RepositoryTreeNode<? extends Object>>();

        nodeList.add(new BranchesNode(node, repo));
        nodeList.add(new TagsNode(node, repo));
        nodeList.add(new AdditionalRefsNode(node, repo));
        nodeList.add(new WorkingDirNode(node, repo));
        nodeList.add(new RemotesNode(node, repo));

        return nodeList.toArray();
    }

    case WORKINGDIR: {
        List<RepositoryTreeNode<File>> children = new ArrayList<RepositoryTreeNode<File>>();

        if (node.getRepository().isBare())
            return children.toArray();
        File workingDir = repo.getWorkTree();
        if (workingDir == null || !workingDir.exists())
            return children.toArray();

        File[] childFiles = workingDir.listFiles();
        Arrays.sort(childFiles, new Comparator<File>() {
            public int compare(File o1, File o2) {
                if (o1.isDirectory()) {
                    if (o2.isDirectory()) {
                        return o1.compareTo(o2);
                    }
                    return -1;
                } else if (o2.isDirectory()) {
                    return 1;
                }
                return o1.compareTo(o2);
            }
        });
        for (File file : childFiles) {
            if (file.isDirectory()) {
                children.add(new FolderNode(node, repo, file));
            } else {
                children.add(new FileNode(node, repo, file));
            }
        }

        return children.toArray();
    }

    case FOLDER: {
        List<RepositoryTreeNode<File>> children = new ArrayList<RepositoryTreeNode<File>>();

        File parent = ((File) node.getObject());

        File[] childFiles = parent.listFiles();
        Arrays.sort(childFiles, new Comparator<File>() {
            public int compare(File o1, File o2) {
                if (o1.isDirectory()) {
                    if (o2.isDirectory()) {
                        return o1.compareTo(o2);
                    }
                    return -1;
                } else if (o2.isDirectory()) {
                    return 1;
                }
                return o1.compareTo(o2);
            }
        });
        for (File file : childFiles) {
            if (file.isDirectory()) {
                children.add(new FolderNode(node, repo, file));
            } else {
                children.add(new FileNode(node, repo, file));
            }
        }

        return children.toArray();
    }

    case REMOTE: {

        List<RepositoryTreeNode<String>> children = new ArrayList<RepositoryTreeNode<String>>();

        String remoteName = (String) node.getObject();
        RemoteConfig rc;
        try {
            rc = new RemoteConfig(node.getRepository().getConfig(), remoteName);
        } catch (URISyntaxException e) {
            return handleException(e, node);
        }

        if (!rc.getURIs().isEmpty())
            children.add(new FetchNode(node, node.getRepository(), rc.getURIs().get(0).toPrivateString()));

        int uriCount = rc.getPushURIs().size();
        if (uriCount == 0 && !rc.getURIs().isEmpty())
            uriCount++;

        // show push if either a fetch or push URI is specified and
        // at least one push specification
        if (uriCount > 0 && !rc.getPushRefSpecs().isEmpty()) {
            URIish firstUri;
            if (!rc.getPushURIs().isEmpty())
                firstUri = rc.getPushURIs().get(0);
            else
                firstUri = rc.getURIs().get(0);

            if (uriCount == 1)
                children.add(new PushNode(node, node.getRepository(), firstUri.toPrivateString()));
            else
                children.add(new PushNode(node, node.getRepository(), firstUri.toPrivateString() + "...")); //$NON-NLS-1$
        }
        return children.toArray();

    }

    case FILE:
        // fall through
    case REF:
        // fall through
    case PUSH:
        // fall through
    case TAG:
        // fall through
    case FETCH:
        // fall through
    case ERROR:
        // fall through
    case ADDITIONALREF:
        return null;

    }

    return null;

}

From source file:org.jfrog.hudson.release.scm.git.GitManager.java

License:Apache License

public String getRemoteUrl(String defaultRemoteUrl) {
    if (StringUtils.isBlank(defaultRemoteUrl)) {
        RemoteConfig remoteConfig = getJenkinsScm().getRepositories().get(0);
        URIish uri = remoteConfig.getURIs().get(0);
        return uri.toPrivateString();
    }/* w  w w.  j  a  va  2  s  . c  om*/

    return defaultRemoteUrl;
}