Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5ba70945a811b6737297b04620a2b10e2f7f32f0 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package org.eclipse.emf.cdo.internal.ui.wizards.old;

import org.eclipse.core.internal.resources.Container;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;

import java.util.Set;

public class NewSessionWizardPage extends WizardPage
{
  private Button existingConnectorButton;

  private Button newConnectorButton;

  private List connectorList;

  private Text connectorText;

  private Text repositoryText;

  private ISelection selection;

  public NewSessionWizardPage(ISelection selection)
  {
    super("wizardPage");
    setTitle("Multi-page Editor File");
    setDescription("This wizard creates a new file with *.mpe extension that can be opened by a multi-page editor.");
    this.selection = selection;
  }

  public void createControl(Composite parent)
  {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 1;
    layout.verticalSpacing = 9;

    Group connectorGroup = new Group(container, SWT.None);
    connectorGroup.setText("Connector");
    connectorGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    connectorGroup.setLayout(new GridLayout(2, false));

    existingConnectorButton = new Button(connectorGroup, SWT.RADIO);
    existingConnectorButton.setText("Existing connector:");
    existingConnectorButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    existingConnectorButton.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        dialogChanged();
      }
    });

    connectorList = new List(connectorGroup, SWT.BORDER | SWT.SINGLE);
    connectorList.setSize(300, 100);
    connectorList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    connectorList.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        dialogChanged();
      }
    });

    newConnectorButton = new Button(connectorGroup, SWT.RADIO);
    newConnectorButton.setText("New connector:");
    newConnectorButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    newConnectorButton.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        dialogChanged();
      }
    });

    connectorText = new Text(connectorGroup, SWT.BORDER);
    connectorText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    connectorText.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        dialogChanged();
      }
    });

    Group repositoryGroup = new Group(container, SWT.None);
    repositoryGroup.setText("Repository");
    repositoryGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    repositoryGroup.setLayout(new GridLayout(2, false));

    Label label = new Label(repositoryGroup, SWT.NULL);
    label.setText("&Name:");

    repositoryText = new Text(repositoryGroup, SWT.BORDER);
    repositoryText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    repositoryText.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        dialogChanged();
      }
    });

    initialize();
    dialogChanged();
    setControl(container);
  }

  public void setVisible(boolean visible)
  {
    super.setVisible(visible);
    if (visible)
    {
      setFocus();
    }
  }

  private void setFocus()
  {
    if (existingConnectorButton.getSelection())
    {
      connectorList.setFocus();
    }
    else
    {
      connectorText.setFocus();
    }
  }

  private String[] getConnectorDescriptions()
  {
    Container container = ContainerManager.INSTANCE.getContainer();
    Set<String> keySet = container.getConnectorRegistry().keySet();
    return keySet.toArray(new String[keySet.size()]);
  }

  private void initialize()
  {
    String[] descriptions = getConnectorDescriptions();
    if (descriptions.length != 0)
    {
      existingConnectorButton.setSelection(true);
      connectorList.setItems(descriptions);
      connectorList.select(0);
    }
    else
    {
      existingConnectorButton.setEnabled(false);
      newConnectorButton.setSelection(true);
    }
  }

  private void dialogChanged()
  {
    connectorList.setEnabled(existingConnectorButton.getSelection());
    connectorText.setEnabled(newConnectorButton.getSelection());

    if (connectorList.isEnabled() && connectorList.getSelectionCount() == 0)
    {
      updateStatus("Select an existing connector from the list.");
      return;
    }

    if (connectorText.isEnabled() && connectorText.getText().length() == 0)
    {
      updateStatus("Enter a description to create a new connector.");
      return;
    }

    if (repositoryText.getText().length() == 0)
    {
      updateStatus("Enter the name of a remote repository.");
      return;
    }

    updateStatus(null);
  }

  private void updateStatus(String message)
  {
    setErrorMessage(message);
    setPageComplete(message == null);
  }

  public String getRepositoryName()
  {
    return repositoryText.getText();
  }

  public String getConnectorDescription()
  {
    if (existingConnectorButton.getSelection())
    {
      return connectorList.getSelection()[0];
    }

    return connectorText.getText();
  }
}

Back to the top