Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0e60799cc9faa1bea9c13be260623e40c9929a88 (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
package org.eclipse.ecf.examples.remoteservices.quotes.consumer;

import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainerInstantiator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.FillLayout;
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.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.remainsoftware.osgilloscope.OSGilloscope;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class ConsumerUI extends Shell {
	private Text servers;
	private Label lblBehindAFirewall;
	private StyledText styledText;
	private OSGilloscope gilloscope;
	private Dispatcher dispatcher;
	private Text info;

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public void main(String args[]) {
		try {
			// Display display = Display.getDefault();
			// ConsumerUI shell = new ConsumerUI(display);
			getShell().open();
			getShell().layout();
			while (!getShell().isDisposed()) {
				if (!getDisplay().readAndDispatch()) {
					getDisplay().sleep();
				}
			}
			getDisplay().dispose();
		} catch (Exception e) {
		}
	}

	/**
	 * Create the shell.
	 * 
	 * @param display
	 */
	public ConsumerUI(Display display) {
		super(display, SWT.SHELL_TRIM);
		setLayout(new FillLayout(SWT.HORIZONTAL));

		Composite composite = new Composite(this, SWT.NONE);
		composite.setLayout(new GridLayout(3, false));

		Label lblCommaSeperatedList = new Label(composite, SWT.NONE);
		lblCommaSeperatedList.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
				false, false, 1, 1));
		lblCommaSeperatedList.setText("Servers");

		servers = (new Text(composite, SWT.BORDER));
		servers.setToolTipText("Enter a host or a comma\r\nseparated list of hosts.");
		getServers().setText("yazafatutu.com");
		getServers().setLayoutData(
				new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		Button btnConnect = new Button(composite, SWT.NONE);
		btnConnect.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				startZookeeper();
			}
		});
		btnConnect.setText("Connect");
																		
																		TabFolder tabFolder = new TabFolder(composite, SWT.BOTTOM);
																		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
																		
																		TabItem tbtmUi = new TabItem(tabFolder, SWT.NONE);
																		tbtmUi.setText("UI");
																		
																		Composite composite_2 = new Composite(tabFolder, SWT.NONE);
																		tbtmUi.setControl(composite_2);
																		composite_2.setLayout(new GridLayout(1, false));
																		
																				gilloscope = new OSGilloscope(composite_2, SWT.NONE);
																				GridData gd_gilloscope = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
																				gd_gilloscope.heightHint = 100;
																				gilloscope.setLayoutData(gd_gilloscope);
																				
																						Composite composite_1 = new Composite(composite_2, SWT.BORDER);
																						composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
																						composite_1.setLayout(new GridLayout(1, false));
																						
																								lblBehindAFirewall = (new Label(composite_1, SWT.NONE));
																								getLabel().setAlignment(SWT.CENTER);
																								getLabel().setFont(new Font(null, "Segoe UI", 15, SWT.BOLD));
																								getLabel().setLayoutData(
																										new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
																								getLabel().setText("Behind a Firewall?");
																								
																										styledText = (new StyledText(composite_1, SWT.BORDER | SWT.WRAP));
																										styledText.setText("Ports 2181 needs to be opened for the Zookeeper Discovery to work and port 3282 is needed by the ECF distribution provider. You can change the ports if you run this in your own environment.");
																										styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
																										styledText.setEditable(false);
																										
																										TabItem tbtmInfo = new TabItem(tabFolder, SWT.NONE);
																										tbtmInfo.setText("Info");
																										
																										Composite composite_3 = new Composite(tabFolder, SWT.NONE);
																										tbtmInfo.setControl(composite_3);
																										composite_3.setLayout(new FillLayout(SWT.HORIZONTAL));
																										
																										info =new Text(composite_3, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
		createContents();
	}

	protected void startZookeeper() {

		IContainer zooContainer = null;
		try {
			zooContainer = ContainerFactory.getDefault().createContainer(
					ZooDiscoveryContainerInstantiator.NAME);
		} catch (ContainerCreateException e1) {
		}

		if (zooContainer.getConnectedID() != null)
			zooContainer.disconnect();

		try {
			String flavor = "centralized";
			if (getServers().getText().split(",").length > 1)
				flavor = "standalone";
			zooContainer.connect(
					zooContainer.getConnectNamespace().createInstance(
							new String[] { "zoodiscovery.flavor." + flavor + "=" + getServers().getText() }), null);
		} catch (Exception e) {
			getLabel().setText(e.getLocalizedMessage());
			getStyledText().setText(e.getCause().toString());
		}
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("ECF Zookeeper Quote Service Consumer");
		setSize(450, 381);

		dispatcher = new Dispatcher() {

			@Override
			public void setValue(int value) {
				if (isSoundRequired())
					clipper.playClip(getActiveSoundfile(), 0);

				getGilloscope().setValues(OSGilloscope.HEARTBEAT);

			}

			public OSGilloscope getGilloscope() {
				return gilloscope;
			};

			@Override
			public boolean isServiceActive() {
				return true;
			}
		};

		dispatcher.dispatch();

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

	public Label getLabel() {
		return lblBehindAFirewall;
	}

	public StyledText getStyledText() {
		return styledText;
	}

	public Text getServers() {
		return servers;
	}

	public Dispatcher getDispatcher() {
		return dispatcher;
	}

	public Text getInfo() {
		return info;
	}
}

Back to the top