Search in sources :

Example 6 with IWizardContainer

use of org.eclipse.jface.wizard.IWizardContainer in project egit by eclipse.

the class FetchGerritChangePage method createControl.

@Override
public void createControl(Composite parent) {
    parent.addDisposeListener(event -> {
        for (ChangeList l : changeRefs.values()) {
            l.cancel(ChangeList.CancelMode.INTERRUPT);
        }
        changeRefs.clear();
    });
    Clipboard clipboard = new Clipboard(parent.getDisplay());
    String clipText = (String) clipboard.getContents(TextTransfer.getInstance());
    clipboard.dispose();
    String defaultUri = null;
    String defaultCommand = null;
    String defaultChange = null;
    Change candidateChange = null;
    if (clipText != null) {
        Matcher matcher = GERRIT_FETCH_PATTERN.matcher(clipText);
        if (matcher.matches()) {
            defaultUri = matcher.group(1);
            defaultChange = matcher.group(2);
            defaultCommand = matcher.group(3);
        } else {
            candidateChange = determineChangeFromString(clipText.trim());
        }
    }
    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) {
            String uriText = uriCombo.getText();
            ChangeList list = changeRefs.get(uriText);
            if (list != null) {
                list.cancel(ChangeList.CancelMode.INTERRUPT);
            }
            list = new ChangeList(repository, uriText);
            changeRefs.put(uriText, list);
            preFetch(list);
        }
    });
    new Label(main, SWT.NONE).setText(UIText.FetchGerritChangePage_ChangeLabel);
    refText = new Text(main, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(refText);
    contentProposer = addRefContentProposalToText(refText);
    refText.addVerifyListener(event -> {
        event.text = event.text.replaceAll("\\v", // $NON-NLS-1$ //$NON-NLS-2$
        " ").trim();
    });
    final Group checkoutGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    checkoutGroup.setLayout(new GridLayout(3, false));
    GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(checkoutGroup);
    checkoutGroup.setText(UIText.FetchGerritChangePage_AfterFetchGroup);
    // radio: create local branch
    createBranch = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(1, 1).applyTo(createBranch);
    createBranch.setText(UIText.FetchGerritChangePage_LocalBranchRadio);
    createBranch.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPage();
        }
    });
    branchCheckoutButton = new Button(checkoutGroup, SWT.CHECK);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.END, SWT.CENTER).applyTo(branchCheckoutButton);
    branchCheckoutButton.setFont(JFaceResources.getDialogFont());
    branchCheckoutButton.setText(UIText.FetchGerritChangePage_LocalBranchCheckout);
    branchCheckoutButton.setSelection(true);
    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).align(SWT.FILL, SWT.CENTER).applyTo(branchText);
    branchText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            branchTextEdited = true;
        }
    });
    branchText.addVerifyListener(event -> {
        if (event.text.isEmpty()) {
            branchTextEdited = false;
        }
    });
    branchText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    BranchNameNormalizer normalizer = new BranchNameNormalizer(branchText);
    normalizer.setVisible(false);
    branchEditButton = new Button(checkoutGroup, SWT.PUSH);
    branchEditButton.setFont(JFaceResources.getDialogFont());
    branchEditButton.setText(UIText.FetchGerritChangePage_BranchEditButton);
    branchEditButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent selectionEvent) {
            String txt = branchText.getText();
            // $NON-NLS-1$
            String refToMark = "".equals(txt) ? null : Constants.R_HEADS + txt;
            AbstractBranchSelectionDialog dlg = new BranchEditDialog(checkoutGroup.getShell(), repository, refToMark);
            if (dlg.open() == Window.OK) {
                branchText.setText(Repository.shortenRefName(dlg.getRefName()));
                branchTextEdited = true;
            } else {
                // force calling branchText's modify listeners
                branchText.setText(branchText.getText());
            }
        }
    });
    GridDataFactory.defaultsFor(branchEditButton).exclude(false).applyTo(branchEditButton);
    // radio: create tag
    createTag = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(3, 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.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            tagTextEdited = true;
        }
    });
    tagText.addVerifyListener(event -> {
        if (event.text.isEmpty()) {
            tagTextEdited = false;
        }
    });
    tagText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    BranchNameNormalizer tagNormalizer = new BranchNameNormalizer(tagText, UIText.BranchNameNormalizer_TooltipForTag);
    tagNormalizer.setVisible(false);
    // radio: checkout FETCH_HEAD
    checkoutFetchHead = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(checkoutFetchHead);
    checkoutFetchHead.setText(UIText.FetchGerritChangePage_CheckoutRadio);
    checkoutFetchHead.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPage();
        }
    });
    // radio: don't checkout
    updateFetchHead = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(updateFetchHead);
    updateFetchHead.setText(UIText.FetchGerritChangePage_UpdateRadio);
    updateFetchHead.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPage();
        }
    });
    if ("checkout".equals(defaultCommand)) {
        // $NON-NLS-1$
        checkoutFetchHead.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);
    ActionUtils.setGlobalActions(refText, ActionUtils.createGlobalAction(ActionFactory.PASTE, () -> doPaste(refText)));
    refText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            Change change = determineChangeFromString(refText.getText());
            // $NON-NLS-1$
            String suggestion = "";
            if (change != null) {
                Object ps = change.getPatchSetNumber();
                if (ps == null) {
                    ps = SIMPLE_TIMESTAMP.format(new Date());
                }
                suggestion = NLS.bind(UIText.FetchGerritChangePage_SuggestedRefNamePattern, change.getChangeNumber(), ps);
            }
            if (!branchTextEdited) {
                branchText.setText(suggestion);
            }
            if (!tagTextEdited) {
                tagText.setText(suggestion);
            }
            checkPage();
        }
    });
    if (defaultChange != null) {
        refText.setText(defaultChange);
    } else if (candidateChange != null) {
        String ref = candidateChange.getRefName();
        if (ref != null) {
            refText.setText(ref);
        } else {
            refText.setText(candidateChange.getChangeNumber().toString());
        }
    }
    // get all available Gerrit URIs from the repository
    SortedSet<String> uris = new TreeSet<>();
    try {
        for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository.getConfig())) {
            if (GerritUtil.isGerritFetch(rc)) {
                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);
        changeRefs.put(aUri, new ChangeList(repository, aUri));
    }
    if (defaultUri != null) {
        uriCombo.setText(defaultUri);
    } else {
        selectLastUsedUri();
    }
    String currentUri = uriCombo.getText();
    ChangeList list = changeRefs.get(currentUri);
    if (list == null) {
        list = new ChangeList(repository, currentUri);
        changeRefs.put(currentUri, list);
    }
    preFetch(list);
    refText.setFocus();
    Dialog.applyDialogFont(main);
    setControl(main);
    if (candidateChange != null) {
        // Launch content assist when the page is displayed
        final IWizardContainer container = getContainer();
        if (container instanceof IPageChangeProvider) {
            ((IPageChangeProvider) container).addPageChangedListener(new IPageChangedListener() {

                @Override
                public void pageChanged(PageChangedEvent event) {
                    if (event.getSelectedPage() == FetchGerritChangePage.this) {
                        // Only the first time: remove myself
                        event.getPageChangeProvider().removePageChangedListener(this);
                        getControl().getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                Control control = getControl();
                                if (control != null && !control.isDisposed()) {
                                    contentProposer.openProposalPopup();
                                }
                            }
                        });
                    }
                }
            });
        }
    }
    checkPage();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) Matcher(java.util.regex.Matcher) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) URISyntaxException(java.net.URISyntaxException) AbstractBranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.AbstractBranchSelectionDialog) KeyEvent(org.eclipse.swt.events.KeyEvent) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) BranchNameNormalizer(org.eclipse.egit.ui.internal.components.BranchNameNormalizer) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) TreeSet(java.util.TreeSet) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) BranchEditDialog(org.eclipse.egit.ui.internal.dialogs.BranchEditDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) Date(java.util.Date) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 7 with IWizardContainer

use of org.eclipse.jface.wizard.IWizardContainer in project webtools.servertools by eclipse.

the class TaskWizardPage method update.

public void update() {
    if (!isCreated)
        return;
    final IWizardContainer container = getContainer();
    getShell().getDisplay().syncExec(new Runnable() {

        public void run() {
            fragment.updateChildFragments();
            ((TaskWizard) getWizard()).updatePages();
            if (container.getCurrentPage() != null)
                container.updateButtons();
        }
    });
}
Also used : IWizardContainer(org.eclipse.jface.wizard.IWizardContainer)

Example 8 with IWizardContainer

use of org.eclipse.jface.wizard.IWizardContainer in project n4js by eclipse.

the class NpmExportWizard method setContainer.

@Override
public void setContainer(IWizardContainer wizardContainer) {
    IWizardContainer oldContainer = this.getContainer();
    if (oldContainer instanceof WizardDialog) {
        ((WizardDialog) oldContainer).removePageChangedListener(pageListener);
    }
    if (wizardContainer instanceof WizardDialog) {
        WizardDialog wizDialog = (WizardDialog) wizardContainer;
        wizDialog.addPageChangedListener(pageListener);
    }
    super.setContainer(wizardContainer);
}
Also used : IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 9 with IWizardContainer

use of org.eclipse.jface.wizard.IWizardContainer in project hale by halestudio.

the class ConfigurationWizardPage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    IWizardContainer container = getContainer();
    if (container instanceof IPageChangeProvider) {
        ((IPageChangeProvider) container).addPageChangedListener(new IPageChangedListener() {

            @Override
            public void pageChanged(PageChangedEvent event) {
                if (currentPage == ConfigurationWizardPage.this) {
                    // try to apply current configuration
                    updateConfiguration(getWizard().getConfiguration());
                    onHidePage();
                }
                currentPage = event.getSelectedPage();
                if (event.getSelectedPage() == ConfigurationWizardPage.this) {
                    onShowPage();
                }
            }
        });
    }
    createContent(parent);
}
Also used : IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent)

Example 10 with IWizardContainer

use of org.eclipse.jface.wizard.IWizardContainer in project hale by halestudio.

the class WorkspaceConfigurationPage method createContent.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createContent(Composite page) {
    Composite main = new Composite(page, SWT.NONE);
    main.setLayout(new GridLayout(3, false));
    Composite tableParent = new Composite(main, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    tableParent.setLayout(layout);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 2);
    gridData.minimumHeight = 150;
    tableParent.setLayoutData(gridData);
    workspaceTableViewer = new TableViewer(tableParent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    workspaceTableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 2));
    workspaceTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    workspaceTableViewer.getTable().setHeaderVisible(true);
    workspaceTableViewer.getTable().setLinesVisible(true);
    // disable selection on table viewer
    workspaceTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            // prevent selection
            if (!event.getSelection().isEmpty()) {
                workspaceTableViewer.setSelection(StructuredSelection.EMPTY);
            }
        }
    });
    TableViewerColumn nameColumn = new TableViewerColumn(workspaceTableViewer, SWT.NONE);
    layout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(2, true));
    nameColumn.setLabelProvider(new WorkspaceNameLabelProvider());
    nameColumn.getColumn().setText("Name");
    nameColumn.setEditingSupport(new WorkspaceNameEditingSupport(workspaceTableViewer));
    TableViewerColumn isolatedColumn = new TableViewerColumn(workspaceTableViewer, SWT.NONE);
    layout.setColumnData(isolatedColumn.getColumn(), new ColumnWeightData(1, true));
    isolatedColumn.setLabelProvider(new WorkspaceIsolatedLabelProvider());
    isolatedColumn.getColumn().setText("Isolated");
    isolatedColumn.setEditingSupport(new WorkspaceIsolatedEditingSupport(workspaceTableViewer));
    TableViewerColumn namespaceColumn = new TableViewerColumn(workspaceTableViewer, SWT.NONE);
    layout.setColumnData(namespaceColumn.getColumn(), new ColumnWeightData(3, true));
    namespaceColumn.setLabelProvider(new WorkspaceNamespaceLabelProvider());
    namespaceColumn.getColumn().setText("Namespace");
    TableViewerColumn featuresColumn = new TableViewerColumn(workspaceTableViewer, SWT.NONE);
    layout.setColumnData(featuresColumn.getColumn(), new ColumnWeightData(3, true));
    featuresColumn.setLabelProvider(new WorkspaceFeaturesLabelProvider());
    featuresColumn.getColumn().setText("Features");
    IWizardContainer container = getContainer();
    if (container instanceof WizardDialog) {
        changeListener = new IPageChangingListener() {

            @Override
            public void handlePageChanging(PageChangingEvent event) {
                Object currentPage = event.getCurrentPage();
                Object targetPage = event.getTargetPage();
                if ((currentPage instanceof FeatureChainingConfigurationPage || currentPage instanceof ChainPage) && targetPage instanceof WorkspaceConfigurationPage) {
                    goingBack = false;
                } else if (currentPage instanceof AppSchemaDataStoreConfigurationPage && targetPage instanceof WorkspaceConfigurationPage) {
                    goingBack = true;
                }
            }
        };
        WizardDialog dialog = (WizardDialog) container;
        dialog.addPageChangingListener(changeListener);
    } else {
        changeListener = null;
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IPageChangingListener(org.eclipse.jface.dialogs.IPageChangingListener) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) ChainPage(eu.esdihumboldt.hale.io.appschema.ui.FeatureChainingConfigurationPage.ChainPage) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) PageChangingEvent(org.eclipse.jface.dialogs.PageChangingEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

IWizardContainer (org.eclipse.jface.wizard.IWizardContainer)19 IPageChangeProvider (org.eclipse.jface.dialogs.IPageChangeProvider)5 IPageChangedListener (org.eclipse.jface.dialogs.IPageChangedListener)5 PageChangedEvent (org.eclipse.jface.dialogs.PageChangedEvent)5 WizardDialog (org.eclipse.jface.wizard.WizardDialog)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Composite (org.eclipse.swt.widgets.Composite)4 URISyntaxException (java.net.URISyntaxException)3 IPageChangingListener (org.eclipse.jface.dialogs.IPageChangingListener)3 PageChangingEvent (org.eclipse.jface.dialogs.PageChangingEvent)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 Button (org.eclipse.swt.widgets.Button)3 Group (org.eclipse.swt.widgets.Group)3 Label (org.eclipse.swt.widgets.Label)3 Text (org.eclipse.swt.widgets.Text)3 Date (java.util.Date)2 TreeSet (java.util.TreeSet)2 Matcher (java.util.regex.Matcher)2 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)2