Search in sources :

Example 1 with SelectUriWizard

use of org.eclipse.egit.ui.internal.repository.SelectUriWizard in project egit by eclipse.

the class AbstractConfigureRemoteDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite main = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(main);
    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.AbstractConfigureRemoteDialog_BranchLabel);
        String branch;
        try {
            branch = getRepository().getBranch();
        } catch (IOException e) {
            branch = null;
        }
        if (branch == null || ObjectId.isId(branch)) {
            branch = UIText.AbstractConfigureRemoteDialog_DetachedHeadMessage;
        }
        Text branchText = new Text(branchArea, SWT.BORDER | SWT.READ_ONLY);
        GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText);
        branchText.setText(branch);
        addDefaultOriginWarning(main);
    }
    final Composite sameUriDetails = new Composite(main, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(4).equalWidth(false).applyTo(sameUriDetails);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(sameUriDetails);
    Label commonUriLabel = new Label(sameUriDetails, SWT.NONE);
    commonUriLabel.setText(UIText.AbstractConfigureRemoteDialog_UriLabel);
    commonUriText = new Text(sameUriDetails, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(commonUriText);
    changeCommonUriAction = new Action(UIText.AbstractConfigureRemoteDialog_ChangeUriLabel) {

        @Override
        public void run() {
            SelectUriWizard wiz;
            if (!commonUriText.getText().isEmpty()) {
                wiz = new SelectUriWizard(true, commonUriText.getText());
            } else {
                wiz = new SelectUriWizard(true);
            }
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
                if (!commonUriText.getText().isEmpty()) {
                    try {
                        getConfig().removeURI(new URIish(commonUriText.getText()));
                    } catch (URISyntaxException ex) {
                        Activator.handleError(ex.getMessage(), ex, true);
                    }
                }
                getConfig().addURI(wiz.getUri());
                updateControls();
            }
        }
    };
    deleteCommonUriAction = new Action(UIText.AbstractConfigureRemoteDialog_DeleteUriLabel) {

        @Override
        public void run() {
            getConfig().removeURI(getConfig().getURIs().get(0));
            updateControls();
        }
    };
    createActionButton(sameUriDetails, SWT.PUSH, changeCommonUriAction);
    createActionButton(sameUriDetails, SWT.PUSH, deleteCommonUriAction).setEnabled(false);
    commonUriText.addModifyListener(event -> deleteCommonUriAction.setEnabled(!commonUriText.getText().isEmpty()));
    createAdditionalUriArea(main);
    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.AbstractConfigureRemoteDialog_RefMappingGroup);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(refSpecGroup);
    specViewer = new TableViewer(refSpecGroup, SWT.BORDER | SWT.MULTI);
    specViewer.setContentProvider(ArrayContentProvider.getInstance());
    GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 150).minSize(SWT.DEFAULT, 30).grab(true, true).applyTo(specViewer.getTable());
    addRefSpecAction = new Action(UIText.AbstractConfigureRemoteDialog_AddRefSpecLabel) {

        @Override
        public void run() {
            doAddRefSpec();
        }
    };
    changeRefSpecAction = new Action(UIText.AbstractConfigureRemoteDialog_ChangeRefSpecLabel) {

        @Override
        public void run() {
            doChangeRefSpec();
        }
    };
    addRefSpecAdvancedAction = new Action(UIText.AbstractConfigureRemoteDialog_EditAdvancedLabel) {

        @Override
        public void run() {
            doAdvanced();
        }
    };
    IAction deleteRefSpecAction = ActionUtils.createGlobalAction(ActionFactory.DELETE, () -> doDeleteRefSpecs());
    IAction copyRefSpecAction = ActionUtils.createGlobalAction(ActionFactory.COPY, () -> doCopy());
    IAction pasteRefSpecAction = ActionUtils.createGlobalAction(ActionFactory.PASTE, () -> doPaste());
    IAction selectAllRefSpecsAction = ActionUtils.createGlobalAction(ActionFactory.SELECT_ALL, () -> {
        specViewer.getTable().selectAll();
        // selectAll doesn't fire a "selection changed" event
        specViewer.setSelection(specViewer.getSelection());
    });
    Composite buttonArea = new Composite(refSpecGroup, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(buttonArea);
    GridDataFactory.fillDefaults().grab(false, true).minSize(SWT.DEFAULT, SWT.DEFAULT).applyTo(buttonArea);
    createActionButton(buttonArea, SWT.PUSH, addRefSpecAction);
    createActionButton(buttonArea, SWT.PUSH, changeRefSpecAction);
    createActionButton(buttonArea, SWT.PUSH, deleteRefSpecAction);
    createActionButton(buttonArea, SWT.PUSH, copyRefSpecAction);
    createActionButton(buttonArea, SWT.PUSH, pasteRefSpecAction);
    createActionButton(buttonArea, SWT.PUSH, addRefSpecAdvancedAction);
    MenuManager contextMenu = new MenuManager();
    contextMenu.setRemoveAllWhenShown(true);
    contextMenu.addMenuListener(manager -> {
        specViewer.getTable().setFocus();
        if (addRefSpecAction.isEnabled()) {
            manager.add(addRefSpecAction);
        }
        if (changeRefSpecAction.isEnabled()) {
            manager.add(changeRefSpecAction);
        }
        if (deleteRefSpecAction.isEnabled()) {
            manager.add(deleteRefSpecAction);
        }
        manager.add(new Separator());
        manager.add(copyRefSpecAction);
        manager.add(pasteRefSpecAction);
        manager.add(selectAllRefSpecsAction);
    });
    specViewer.getTable().setMenu(contextMenu.createContextMenu(specViewer.getTable()));
    ActionUtils.setGlobalActions(specViewer.getTable(), deleteRefSpecAction, copyRefSpecAction, pasteRefSpecAction, selectAllRefSpecsAction);
    specViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) specViewer.getSelection();
            copyRefSpecAction.setEnabled(sel.size() == 1);
            changeRefSpecAction.setEnabled(sel.size() == 1);
            deleteRefSpecAction.setEnabled(!sel.isEmpty());
            selectAllRefSpecsAction.setEnabled(specViewer.getTable().getItemCount() > 0 && sel.size() != specViewer.getTable().getItemCount());
        }
    });
    specViewer.addDoubleClickListener(event -> doChangeRefSpec());
    // Initial action enablement (no selection in the specViewer):
    copyRefSpecAction.setEnabled(false);
    changeRefSpecAction.setEnabled(false);
    deleteRefSpecAction.setEnabled(false);
    applyDialogFont(main);
    return main;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Group(org.eclipse.swt.widgets.Group) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Composite(org.eclipse.swt.widgets.Composite) IAction(org.eclipse.jface.action.IAction) SelectUriWizard(org.eclipse.egit.ui.internal.repository.SelectUriWizard) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MenuManager(org.eclipse.jface.action.MenuManager) WizardDialog(org.eclipse.jface.wizard.WizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) Separator(org.eclipse.jface.action.Separator)

Example 2 with SelectUriWizard

use of org.eclipse.egit.ui.internal.repository.SelectUriWizard in project egit by eclipse.

the class SimpleConfigurePushDialog method createAdditionalUriArea.

@Override
protected Control createAdditionalUriArea(Composite parent) {
    ExpandableComposite pushUriArea = new ExpandableComposite(parent, ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(pushUriArea);
    pushUriArea.setExpanded(!getConfig().getPushURIs().isEmpty());
    pushUriArea.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            parent.layout(true, true);
            parent.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) {
                getConfig().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) {
                getConfig().removePushURI(uri);
                getConfig().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();
            getConfig().removePushURI(uri);
            updateControls();
        }
    });
    uriViewer.addSelectionChangedListener(event -> {
        deleteUri.setEnabled(!uriViewer.getSelection().isEmpty());
        changeUri.setEnabled(((IStructuredSelection) uriViewer.getSelection()).size() == 1);
    });
    return pushUriArea;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectUriWizard(org.eclipse.egit.ui.internal.repository.SelectUriWizard) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

SelectUriWizard (org.eclipse.egit.ui.internal.repository.SelectUriWizard)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 URIish (org.eclipse.jgit.transport.URIish)2 Composite (org.eclipse.swt.widgets.Composite)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UIText (org.eclipse.egit.ui.internal.UIText)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Group (org.eclipse.swt.widgets.Group)1