Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fb04f213613a63b31de64b0de2f628cc841a6741 (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
/*
 * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
 *    Eike Stepper - initial API and implementation
 *    Martin Fluegge - initial API and implementation
 */
package org.eclipse.net4j.internal.ui.container;

import org.eclipse.net4j.internal.jvm.JVMAcceptorFactory;
import org.eclipse.net4j.internal.ui.bundle.OM;
import org.eclipse.net4j.jvm.IJVMAcceptor;
import org.eclipse.net4j.util.factory.ProductCreationException;
import org.eclipse.net4j.util.ui.container.ElementWizard;
import org.eclipse.net4j.util.ui.container.ElementWizardFactory;

import org.eclipse.spi.net4j.ConnectorFactory;
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.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Eike Stepper
 * @author Martin Fluegge
 * @since 4.0
 */
public class JVMConnectorWizard extends ElementWizard
{
  public JVMConnectorWizard()
  {
  }

  @Override
  protected void create(Composite parent)
  {
    List<String> choices = new ArrayList<String>();

    try
    {
      Object[] elements = getContainer().getElements(JVMAcceptorFactory.PRODUCT_GROUP, JVMAcceptorFactory.TYPE);
      for (Object object : elements)
      {
        if (object instanceof IJVMAcceptor)
        {
          IJVMAcceptor acceptor = (IJVMAcceptor)object;
          choices.add(acceptor.getName());
        }
      }
    }
    catch (NoClassDefFoundError error)
    {
      OM.LOG.error(error);
    }

    if (!choices.isEmpty())
    {
      Collections.sort(choices);

      final Combo acceptorCombo = addCombo(parent, "Acceptor:", choices);
      acceptorCombo.addSelectionListener(new SelectionAdapter()
      {
        @Override
        public void widgetSelected(SelectionEvent e)
        {
          String acceptorName = acceptorCombo.getText();
          setResultDescription(acceptorName);
        }
      });

      String description = getDefaultDescription();
      if (description != null)
      {
        acceptorCombo.setText(description);
      }
    }
    else
    {
      final Text acceptorNameText = addText(parent, "Acceptor Name:");
      acceptorNameText.addModifyListener(new ModifyListener()
      {
        public void modifyText(ModifyEvent e)
        {
          String acceptorName = acceptorNameText.getText();
          if (acceptorName.length() == 0)
          {
            setValidationError(acceptorNameText, "Acceptor name is empty.");
            return;
          }

          setResultDescription(acceptorName);
          setValidationError(acceptorNameText, null);
        }
      });

      String description = getDefaultDescription();
      if (description != null)
      {
        acceptorNameText.setText(description);
      }
    }
  }

  /**
   * @author Eike Stepper
   */
  public static class Factory extends ElementWizardFactory
  {
    public Factory()
    {
      super(ConnectorFactory.PRODUCT_GROUP, "jvm");
    }

    @Override
    public JVMConnectorWizard create(String description) throws ProductCreationException
    {
      return new JVMConnectorWizard();
    }
  }
}

Back to the top