Мастера JFace's Eclipse

Использовать метод сериализации .

data :   $("form").serialize()

13
задан Manuel Selva 5 June 2009 в 06:01
поделиться

2 ответа

Подход правильный, если у вас есть несколько других страниц, которые

  • полностью отличаются друг от друга
  • в зависимости от предыдущего выбора, сделанного на предыдущей странице

Тогда вы можете добавить следующую страницу динамически (также как описано здесь )

Но если у вас есть только следующая страница с динамическим содержимым, вы сможете создать это содержимое в onEnterPage () метод

public void createControl(Composite parent)
{
    //
    // create the composite to hold the widgets
    //
    this.composite = new Composite(parent, SWT.NONE);

    //
    // create the desired layout for this wizard page
    //
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    this.composite.setLayout(layout);

    // set the composite as the control for this page
    setControl(this.composite);
}

void onEnterPage()
{
    final MacroModel model = ((MacroWizard) getWizard()).model;
    String selectedKey = model.selectedKey;
    String[] attrs = (String[]) model.macroMap.get(selectedKey);

    for (int i = 0; i < attrs.length; i++)
    {
        String attr = attrs[i];
        Label label = new Label(this.composite, SWT.NONE);
        label.setText(attr + ":");

        new Text(this.composite, SWT.NONE);
    }
    pack();
}

Как показано в статье eclipse corner Создание мастеров JFace :

Мы можем изменить порядок страниц мастера, перезаписав метод getNextPage любой страницы мастера. Перед тем как покинуть страницу, мы сохраняем в модели значения, выбранные пользователем. В нашем примере, в зависимости от выбора путешествия, пользователь далее увидит либо страницу с рейсами, либо страницу путешествия на машине.

9
ответ дан 2 December 2019 в 00:19
поделиться

Если вы хотите запустить новый мастер на основе вашего выбора на первой странице, вы можете использовать базовый класс JFace org.eclipse.jface.wizard.WizardSelectionPage .

В приведенном ниже примере показан список доступных мастеров, определенных точкой расширения. Когда вы нажимаете Next , запускается выбранный мастер.

public class ModelSetupWizardSelectionPage extends WizardSelectionPage {

private ComboViewer providerViewer;
private IConfigurationElement selectedProvider;

public ModelSetupWizardSelectionPage(String pageName) {
    super(pageName);
}

private class WizardNode implements IWizardNode {
    private IWizard wizard = null;
    private IConfigurationElement configurationElement;

    public WizardNode(IConfigurationElement c) {
        this.configurationElement = c;
    }

    @Override
    public void dispose() {

    }

    @Override
    public Point getExtent() {
        return new Point(-1, -1);
    }

    @Override
    public IWizard getWizard() {
        if (wizard == null) {
            try {
                wizard = (IWizard) configurationElement
                        .createExecutableExtension("wizardClass");
            } catch (CoreException e) {

            }
        }
        return wizard;
    }

    @Override
    public boolean isContentCreated() {
        // TODO Auto-generated method stub
        return wizard != null;
    }

}

@Override
public void createControl(Composite parent) {
    setTitle("Select model provider");
    Composite main = new Composite(parent, SWT.NONE);
    GridLayout gd = new GridLayout(2, false);
    main.setLayout(gd);
    new Label(main, SWT.NONE).setText("Model provider");
    Combo providerList = new Combo(main, SWT.NONE);
    providerViewer = new ComboViewer(providerList);
    providerViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof IConfigurationElement) {
                IConfigurationElement c = (IConfigurationElement) element;
                String result = c.getAttribute("name");
                if (result == null || result.length() == 0) {
                    result = c.getAttribute("class");
                }
                return result;
            }
            return super.getText(element);
        }

    });
    providerViewer
            .addSelectionChangedListener(new ISelectionChangedListener() {
                @Override
                public void selectionChanged(SelectionChangedEvent event) {
                    ISelection selection = event.getSelection();
                    if (!selection.isEmpty()
                            && selection instanceof IStructuredSelection) {
                        Object o = ((IStructuredSelection) selection)
                                .getFirstElement();
                        if (o instanceof IConfigurationElement) {
                            selectedProvider = (IConfigurationElement) o;
                            setMessage(selectedProvider.getAttribute("description"));
                            setSelectedNode(new WizardNode(selectedProvider));
                        }
                    }

                }
            });
    providerViewer.setContentProvider(new ArrayContentProvider());
    List<IConfigurationElement> providers = new ArrayList<IConfigurationElement>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint extensionPoint = registry
            .getExtensionPoint(<your extension point namespace>,<extension point name>);
    if (extensionPoint != null) {
        IExtension extensions[] = extensionPoint.getExtensions();
        for (IExtension extension : extensions) {
            IConfigurationElement configurationElements[] = extension
                    .getConfigurationElements();
            for (IConfigurationElement c : configurationElements) {
                providers.add(c);
            }
        }
    }
    providerViewer.setInput(providers);
    setControl(main);

}

Соответствующий класс мастера выглядит так:

 public class ModelSetupWizard extends Wizard {

private ModelSetupWizardSelectionPage wizardSelectionPage;

public ModelSetupWizard() {
    setForcePreviousAndNextButtons(true);
}

@Override
public boolean performFinish() {
            // Do what you have to do to finish the wizard
    return true;
}

@Override
public void addPages() {
    wizardSelectionPage = new ModelSetupWizardSelectionPage("Select a wizard");
    addPage(wizardSelectionPage);

}
}
5
ответ дан 2 December 2019 в 00:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: