Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7ae69dbd666b5ff84420cc4088bddaa1d7c680e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal.wizards;

import java.util.List;


import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.wst.wsdl.Service;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.contentgenerator.AbstractGenerator;
import org.eclipse.wst.wsdl.ui.internal.contentgenerator.ContentGeneratorExtension;
import org.eclipse.wst.wsdl.ui.internal.contentgenerator.PortGenerator;
import org.eclipse.wst.wsdl.ui.internal.contentgenerator.ui.ContentGeneratorOptionsPage;
import org.eclipse.wst.wsdl.ui.internal.util.ComponentReferenceUtil;
import org.eclipse.wst.wsdl.ui.internal.util.NameUtil;
import org.eclipse.wst.wsdl.ui.internal.widgets.ProtocolComponentControl;

public class PortWizard extends Wizard
{
  protected final static int STYLE_NEW_BINDING = 1;
  protected final static int STYLE_EXISTING_BINDING = 1 << 1;
  protected final static int STYLE_DEFAULT = STYLE_NEW_BINDING | STYLE_EXISTING_BINDING;

  protected PortGenerator portGenerator;
  protected PortWizardOptionsPage specifyBindingPage;
  protected int style;

  /**
   * Constructor for PortWizard.
   */
  public PortWizard(Service service)
  {
    this(service, 0);
  }

  public PortWizard(Service service, int style)
  {
    super();
    portGenerator = new PortGenerator(service);
    setWindowTitle(WSDLEditorPlugin.getWSDLString("_UI_PORT_WIZARD")); //$NON-NLS-1$
    //setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(WSDLEditorPlugin.class, "icons/NewXML.gif"));
  }

  /**
   * Return true if wizard setup is successful, false otherwise
   */
  public boolean setup()
  {
    return true;
  }

  public void addPages()
  {
    specifyBindingPage = new PortWizardOptionsPage(style);
    addPage(specifyBindingPage);
  }

  public boolean performFinish()
  {
    portGenerator.generate();

    try
    {
      Object object = portGenerator.getNewComponent();
      if (object != null)
      {
        IEditorPart editorPart = WSDLEditorPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        ISelectionProvider selectionProvider = (ISelectionProvider) editorPart.getAdapter(ISelectionProvider.class);
        if (selectionProvider != null)
        {
          selectionProvider.setSelection(new StructuredSelection(object));
        }
      }
    }
    catch (Exception e)
    {
    }
    return true;
  }

  class PortWizardOptionsPage extends WizardPage
  {

    protected ProtocolComponentControl protocolComponentControl;

    public PortWizardOptionsPage(int style)
    {
      super("SpecifyPortPage");
      setTitle(WSDLEditorPlugin.getWSDLString("_UI_SPECIFY_PORT_DETAILS"));
      setDescription(WSDLEditorPlugin.getWSDLString("_UI_SPECIFY_PORT_DETAILS_TO_BE_CREATED"));
    }

    public AbstractGenerator getGenerator()
    {
      return portGenerator;
    }

    public void createControl(Composite parent)
    {
      ProtocolComponentControl protocolComponentControl = new PortProtocolComponentControl(parent, portGenerator);
      protocolComponentControl.initFields();
      setControl(protocolComponentControl);
    }
  }

  class PortProtocolComponentControl extends ProtocolComponentControl
  {

    public PortProtocolComponentControl(Composite parent, AbstractGenerator generator)
    {
      super(parent, generator, false);
    }

    public String getRefNameLabelText()
    {
      return WSDLEditorPlugin.getWSDLString("_UI_BINDING");
    }

    public List getRefNames()
    {
      return new ComponentReferenceUtil(portGenerator.getDefinition()).getBindingNames();
    }

    public String getDefaultName()
    {
      Service service = portGenerator.getService();
      return NameUtil.buildUniquePortName(service, null);
    }

    public ContentGeneratorOptionsPage createContentGeneratorOptionsPage(String protocol)
    {
      ContentGeneratorOptionsPage optionsPage = null;
      ContentGeneratorExtension extension = WSDLEditorPlugin.getInstance().getContentGeneratorExtensionRegistry().getContentGeneratorExtension(protocol);
      if (extension != null)
      {
        optionsPage = extension.createPortContentGeneratorOptionsPage();
      }
      return optionsPage;
    }
  }
}

Back to the top