Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 59443f2cfb05525cb6a83d449daca2f1a2ec4c98 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
/*******************************************************************************
 * Copyright (c) 2014 Red Hat.
 * 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:
 *     Red Hat - Initial Contribution
 *******************************************************************************/
package org.eclipse.linuxtools.internal.docker.ui.wizards;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerPortBinding;
import org.eclipse.linuxtools.internal.docker.core.DockerPortBinding;
import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class ContainerCreatePage extends WizardPage {

	private final static String NAME = "ContainerCreate.name"; //$NON-NLS-1$
	private final static String TITLE = "ContainerCreate.title"; //$NON-NLS-1$
	private final static String DESC = "ContainerCreate.desc"; //$NON-NLS-1$
	private final static String CREATE_LABEL = "ContainerCreate.label"; //$NON-NLS-1$
	private final static String IMAGE_LABEL = "Image.label"; //$NON-NLS-1$
	private final static String CMD_LABEL = "Cmd.label"; //$NON-NLS-1$
	private final static String USER_LABEL = "User.label"; //$NON-NLS-1$
	private final static String WORKING_DIR_LABEL = "WorkingDir.label"; //$NON-NLS-1$
	private final static String ENV_LABEL = "Env.label"; //$NON-NLS-1$
	private final static String HOSTNAME_LABEL = "Hostname.label"; //$NON-NLS-1$
	private final static String DOMAINNAME_LABEL = "Domainname.label"; //$NON-NLS-1$
	private final static String MEMORY_LABEL = "Memory.label"; //$NON-NLS-1$
	private final static String MEMORY_SWAP_LABEL = "MemorySwap.label"; //$NON-NLS-1$
	private final static String CPU_SHARES_LABEL = "CpuShares.label"; //$NON-NLS-1$
	private final static String VOLUMES_LABEL = "Volumes.label"; //$NON-NLS-1$
	private final static String PORT_SPECS_LABEL = "PortSpecs.label"; //$NON-NLS-1$
	private final static String EXPOSED_PORTS_LABEL = "ExposedPorts.label"; //$NON-NLS-1$
	private final static String ON_BUILD_LABEL = "OnBuild.label"; //$NON-NLS-1$
	private final static String ENTRY_POINT_LABEL = "EntryPoint.label"; //$NON-NLS-1$
	private final static String CPU_SET_LABEL = "CpuSet.label"; //$NON-NLS-1$
	private final static String ATTACH_STDIN_LABEL = "AttachStdin.label"; //$NON-NLS-1$
	private final static String ATTACH_STDOUT_LABEL = "AttachStdout.label"; //$NON-NLS-1$
	private final static String ATTACH_STDERR_LABEL = "AttachStderr.label"; //$NON-NLS-1$
	private final static String TTY_LABEL = "Tty.label"; //$NON-NLS-1$
	private final static String OPEN_STDIN_LABEL = "OpenStdin.label"; //$NON-NLS-1$
	private final static String STDIN_ONCE_LABEL = "StdinOnce.label"; //$NON-NLS-1$
	private final static String NETWORK_DISABLED_LABEL = "NetworkDisabled.label"; //$NON-NLS-1$
	private final static String PRIVILEGED_LABEL = "Privileged.label"; //$NON-NLS-1$
	private final static String PUBLISH_ALL_LABEL = "PublishAll.label"; //$NON-NLS-1$
	private final static String NETWORK_MODE_LABEL = "NetworkMode.label"; //$NON-NLS-1$

	@SuppressWarnings("unused")
	private IDockerConnection connection;
	private String image;

	private Text imageText;
	private Text hostnameText;
	private Text domainnameText;
	private Text userText;
	private Text cmdText;
	private Text envText;
	private Text cpuSetText;
	private Text workingDirText;
	private Text portSpecsText;
	private Text exposedPortsText;
	private Text volumesText;
	private Text entryPointText;
	private Text onBuildText;
	private Text networkModeText;

	private Text memoryWidget;
	private Text memorySwapWidget;
	private Text cpuSharesWidget;

	private Button attachStdinButton;
	private Button attachStdoutButton;
	private Button attachStderrButton;
	private Button ttyButton;
	private Button openStdinButton;
	private Button stdinOnceButton;
	private Button networkDisabledButton;
	private Button privilegedButton;
	private Button publishAllPortsButton;

	public ContainerCreatePage(IDockerConnection connection, String image) {
		super(WizardMessages.getString(NAME));
		this.connection = connection;
		this.image = image;
		setDescription(WizardMessages.getString(DESC));
		setTitle(WizardMessages.getString(TITLE));
		setImageDescriptor(SWTImagesFactory.DESC_WIZARD);
	}

	public String getImageId() {
		return imageText.getText();
	}

	public String getHostName() {
		return hostnameText.getText();
	}

	public String getDomainName() {
		return domainnameText.getText();
	}

	public String getUser() {
		return userText.getText();
	}

	public List<String> getCmd() {
		return getCmdList(cmdText.getText());
	}

	private List<String> getCmdList(String s) {
		ArrayList<String> list = new ArrayList<>();
		int length = s.length();
		boolean insideQuote1 = false; // single-quote
		boolean insideQuote2 = false; // double-quote
		boolean escaped = false;
		StringBuffer buffer = new StringBuffer();
		// Parse the string and break it up into chunks that are
		// separated by white-space or are quoted. Ignore characters
		// that have been escaped, including the escape character.
		for (int i = 0; i < length; ++i) {
			char c = s.charAt(i);
			if (escaped) {
				buffer.append(c);
				escaped = false;
			}
			switch (c) {
			case '\'':
				if (!insideQuote2)
					insideQuote1 = insideQuote1 ^ true;
				else
					buffer.append(c);
				break;
			case '\"':
				if (!insideQuote1)
					insideQuote2 = insideQuote2 ^ true;
				else
					buffer.append(c);
				break;
			case '\\':
				escaped = true;
				break;
			case ' ':
			case '\t':
			case '\r':
			case '\n':
				if (insideQuote1 || insideQuote2)
					buffer.append(c);
				else {
					String item = buffer.toString();
					buffer.setLength(0);
					if (item.length() > 0)
						list.add(item);
				}
				break;
			default:
				buffer.append(c);
				break;
			}
		}
		// add last item of string that will be in the buffer
		String item = buffer.toString();
		if (item.length() > 0)
			list.add(item);
		return list;
	}

	public List<String> getEnv() {
		return getEnvList(envText.getText());
	}

	private List<String> getEnvList(String str) {
		ArrayList<String> envVars = new ArrayList<>();

		Pattern p1 = Pattern.compile("(\\w+[=]\\\".*?\\\"\\s*).*"); //$NON-NLS-1$
		Pattern p2 = Pattern.compile("(\\w+[=]'.*?'\\s*).*"); //$NON-NLS-1$
		Pattern p3 = Pattern.compile("(\\w+[=][^\\s]+).*"); //$NON-NLS-1$
		Pattern p4 = Pattern.compile("(\\w+[=][\\s]*$)"); //$NON-NLS-1$
		boolean finished = false;
		while (!finished) {
			Matcher m1 = p1.matcher(str);
			if (m1.matches()) {
				str = str.replaceFirst("\\w+[=]\\\".*?\\\"", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
				String s = m1.group(1).trim();
				envVars.add(s.replaceAll("\\\"", "")); //$NON-NLS-1$ //$NON-NLS-2$
			} else {
				Matcher m2 = p2.matcher(str);
				if (m2.matches()) {
					str = str.replaceFirst("\\w+[=]'.*?'", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
					String s = m2.group(1).trim();
					envVars.add(s.replaceAll("'", ""));//$NON-NLS-1$ //$NON-NLS-2$ 
				} else {
					Matcher m3 = p3.matcher(str);
					if (m3.matches()) {
						str = str.replaceFirst("\\w+[=][^\\s]+", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
						envVars.add(m3.group(1).trim());
					} else {
						Matcher m4 = p4.matcher(str);
						if (m4.matches()) {
							str = str.replaceFirst("\\w+[=][\\s]*$", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
							envVars.add(m4.group(1).trim());
						} else {
							finished = true;
						}
					}
				}
			}
		}
		return envVars;
	}

	public String getWorkingDir() {
		return workingDirText.getText();
	}

	public Long getMemory() {
		return getDigitalValue(memoryWidget.getText());
	}

	public Long getMemorySwap() {
		return getDigitalValue(memorySwapWidget.getText());
	}

	private Long getDigitalValue(String s) {
		s = s.trim();
		int len = s.length();
		long factor = 1;
		if (len > 0) {
			char c = s.charAt(len - 1);
			boolean foundSpecifier = false;
			switch (c) {
			case 'k':
				factor = 1000;
				foundSpecifier = true;
				break;
			case 'K':
				factor = 1024;
				foundSpecifier = true;
				break;
			case 'm':
				factor = 1000000;
				foundSpecifier = true;
				break;
			case 'M':
				factor = 1024 * 1024;
				foundSpecifier = true;
				break;
			case 'g':
				factor = 1000000000;
				foundSpecifier = true;
				break;
			case 'G':
				factor = 1024 * 1024 * 1024;
				foundSpecifier = true;
				break;
			case 't':
				factor = 1000000000000L;
				foundSpecifier = true;
				break;
			case 'T':
				factor = 1024 * 1024 * 1024 * 1024;
				foundSpecifier = true;
				break;
			}
			if (foundSpecifier) {
				s = s.substring(len - 1);
			}
		}
		return Long.valueOf(Long.parseLong(s) * factor);
	}

	public Long getCpuShares() {
		return Long.valueOf(cpuSharesWidget.getText());
	}

	public String getCpuSet() {
		return cpuSetText.getText();
	}

	public Boolean getAttachStdin() {
		return attachStdinButton.getSelection();
	}

	public Boolean getAttachStdout() {
		return attachStdoutButton.getSelection();
	}

	public Boolean getAttachStderr() {
		return attachStderrButton.getSelection();
	}

	public Boolean getTty() {
		return ttyButton.getSelection();
	}

	public Boolean getOpenStdin() {
		return openStdinButton.getSelection();
	}

	public Boolean getStdinOnce() {
		return stdinOnceButton.getSelection();
	}

	public Boolean getNetworkDisabled() {
		return networkDisabledButton.getSelection();
	}

	public Boolean getPrivileged() {
		return privilegedButton.getSelection();
	}

	public Boolean getPublishAllPorts() {
		return publishAllPortsButton.getSelection();
	}

	public String getNetworkMode() {
		return networkModeText.getText();
	}

	public Set<String> getVolumes() {
		String s = volumesText.getText().trim();
		if (s.length() == 0)
			return null;
		Set<String> volumeSet = new HashSet<>();
		String[] volumes = s.split("\\s+");
		for (String volume : volumes) {
			volume = volume.trim();
			if (volume.length() > 0 && !volume.contains(":")) //$NON-NLS-1$
				volumeSet.add(volume);
		}
		return volumeSet;
	}

	public List<String> getHostVolumes() {
		String s = volumesText.getText().trim();
		if (s.length() == 0)
			return null;
		List<String> hostVolumes = new ArrayList<>();
		String[] volumes = s.split("\\s+");
		for (String volume : volumes) {
			volume = volume.trim();
			if (volume.length() > 0 && volume.contains(":")) //$NON-NLS-1$
				hostVolumes.add(volume);
		}
		return hostVolumes;
	}

	public List<String> getPortSpecs() {
		String s = portSpecsText.getText().trim();
		if (s.length() == 0)
			return null;
		List<String> specList = new ArrayList<>();
		String[] specs = s.split("\\s+");
		for (String spec : specs) {
			spec = spec.trim();
			if (spec.length() > 0)
				specList.add(spec);
		}
		return specList;
	}

	public Set<String> getExposedPorts() {
		String s = exposedPortsText.getText().trim();
		if (s.length() == 0)
			return null;
		Set<String> exposedPortsSet = new HashSet<>();
		String[] exposedPorts = s.split("\\s+");
		for (String exposedPort : exposedPorts) {
			exposedPort = exposedPort.trim();
			if (exposedPort.length() > 0) {
				String[] segments = exposedPort.split(":"); //$NON-NLS-1$
				if (segments.length == 1) { // containerPort
					exposedPortsSet.add(segments[0]);
				} else if (segments.length == 2) { // hostPort:containerPort
					exposedPortsSet.add(segments[1]);
				} else if (segments.length == 3) { // either
													// ip:hostPort:containerPort
													// or ip::containerPort
					exposedPortsSet.add(segments[2]);
				}
			}
		}
		return exposedPortsSet;
	}

	public Map<String, List<IDockerPortBinding>> getPortBindings() {
		String s = exposedPortsText.getText().trim();
		if (s.length() == 0)
			return null;
		Map<String, List<IDockerPortBinding>> portBindingsMap = new HashMap<>();
		String[] exposedPorts = s.split("\\s+");
		for (String exposedPort : exposedPorts) {
			exposedPort = exposedPort.trim();
			if (exposedPort.length() > 0) {
				String[] segments = exposedPort.split(":"); //$NON-NLS-1$
				if (segments.length == 1) { // containerPort
					portBindingsMap.put(segments[0], Arrays
							.asList((IDockerPortBinding) new DockerPortBinding(
									"", ""))); //$NON-NLS-1$ //$NON-NLS-2$
				} else if (segments.length == 2) { // hostPort:containerPort
					portBindingsMap.put(segments[1], Arrays
							.asList((IDockerPortBinding) new DockerPortBinding(
									"", segments[0]))); //$NON-NLS-1$ //$NON-NLS-2$
				} else if (segments.length == 3) { // either
													// ip:hostPort:containerPort
													// or ip::containerPort
					if (segments[1].isEmpty()) {
						portBindingsMap
								.put(segments[2],
										Arrays.asList((IDockerPortBinding) new DockerPortBinding(
												"", segments[0]))); //$NON-NLS-1$ //$NON-NLS-2$
					} else {
						portBindingsMap
								.put(segments[2],
										Arrays.asList((IDockerPortBinding) new DockerPortBinding(
												segments[0], segments[1]))); //$NON-NLS-1$ //$NON-NLS-2$
					}
				}
			}
		}
		return portBindingsMap;
	}

	public List<String> getOnBuild() {
		String s = onBuildText.getText().trim();
		if (s.length() == 0)
			return null;
		List<String> onBuildList = new ArrayList<>();
		String[] onBuildStrings = s.split("\\s+");
		for (String onBuildString : onBuildStrings) {
			onBuildString = onBuildString.trim();
			if (onBuildString.length() > 0)
				onBuildList.add(onBuildString);
		}
		return onBuildList;
	}

	public List<String> getEntryPoint() {
		String s = entryPointText.getText().trim();
		if (s.length() == 0)
			return null;
		List<String> entryPointList = new ArrayList<>();
		String[] entryPoints = s.split("\\s+");
		for (String entryPoint : entryPoints) {
			entryPoint = entryPoint.trim();
			if (entryPoint.length() > 0)
				entryPointList.add(entryPoint);
		}
		return entryPointList;
	}

	private ModifyListener Listener = new ModifyListener() {

		@Override
		public void modifyText(ModifyEvent e) {
			// TODO Auto-generated method stub
			validate();
		}
	};

	private void validate() {
		boolean complete = true;
		boolean error = false;

		if (imageText.getText().length() == 0)
			complete = false;
		if (!error)
			setErrorMessage(null);
		setPageComplete(complete && !error);
	}

	@Override
	public void createControl(Composite parent) {
		final ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL);
		final Composite container = new Composite(sc, SWT.NULL);
		sc.setContent(container);
		FormLayout layout = new FormLayout();
		layout.marginHeight = 5;
		layout.marginWidth = 5;
		container.setLayout(layout);

		Label label = new Label(container, SWT.NULL);
		label.setText(WizardMessages.getString(CREATE_LABEL));

		Label imageLabel = new Label(container, SWT.NULL);
		imageLabel.setText(WizardMessages.getString(IMAGE_LABEL));

		imageText = new Text(container, SWT.BORDER | SWT.SINGLE);
		if (image != null) {
			imageText.setText(image);
			imageText.setEditable(false);
		}
		imageText.addModifyListener(Listener);

		Label cmdLabel = new Label(container, SWT.NULL);
		cmdLabel.setText(WizardMessages.getString(CMD_LABEL));

		cmdText = new Text(container, SWT.BORDER | SWT.SINGLE);
		cmdText.addModifyListener(Listener);

		Label userLabel = new Label(container, SWT.NULL);
		userLabel.setText(WizardMessages.getString(USER_LABEL));

		userText = new Text(container, SWT.BORDER | SWT.SINGLE);
		userText.addModifyListener(Listener);

		Label workingDirLabel = new Label(container, SWT.NULL);
		workingDirLabel.setText(WizardMessages.getString(WORKING_DIR_LABEL));

		workingDirText = new Text(container, SWT.BORDER | SWT.SINGLE);
		workingDirText.addModifyListener(Listener);

		Label envLabel = new Label(container, SWT.NULL);
		envLabel.setText(WizardMessages.getString(ENV_LABEL));

		envText = new Text(container, SWT.BORDER | SWT.SINGLE);
		envText.addModifyListener(Listener);

		Label hostnameLabel = new Label(container, SWT.NULL);
		hostnameLabel.setText(WizardMessages.getString(HOSTNAME_LABEL));

		hostnameText = new Text(container, SWT.BORDER | SWT.SINGLE);
		hostnameText.addModifyListener(Listener);

		Label domainnameLabel = new Label(container, SWT.NULL);
		domainnameLabel.setText(WizardMessages.getString(DOMAINNAME_LABEL));

		domainnameText = new Text(container, SWT.BORDER | SWT.SINGLE);
		domainnameText.addModifyListener(Listener);

		Label memoryLabel = new Label(container, SWT.NULL);
		memoryLabel.setText(WizardMessages.getString(MEMORY_LABEL));

		memoryWidget = new Text(container, SWT.BORDER | SWT.SINGLE);
		memoryWidget.setText("0"); //$NON-NLS-1$
		memoryWidget.addModifyListener(Listener);

		Label memorySwapLabel = new Label(container, SWT.NULL);
		memorySwapLabel.setText(WizardMessages.getString(MEMORY_SWAP_LABEL));

		memorySwapWidget = new Text(container, SWT.BORDER | SWT.SINGLE);
		memorySwapWidget.setText("0"); //$NON-NLS-1$
		memorySwapWidget.addModifyListener(Listener);

		Label cpuSharesLabel = new Label(container, SWT.NULL);
		cpuSharesLabel.setText(WizardMessages.getString(CPU_SHARES_LABEL));

		cpuSharesWidget = new Text(container, SWT.BORDER | SWT.SINGLE);
		cpuSharesWidget.setText("0"); //$NON-NLS-1$
		cpuSharesWidget.addModifyListener(Listener);

		Label cpuSetLabel = new Label(container, SWT.NULL);
		cpuSetLabel.setText(WizardMessages.getString(CPU_SET_LABEL));

		cpuSetText = new Text(container, SWT.BORDER | SWT.SINGLE);
		cpuSetText.addModifyListener(Listener);

		Label volumesLabel = new Label(container, SWT.NULL);
		volumesLabel.setText(WizardMessages.getString(VOLUMES_LABEL));

		volumesText = new Text(container, SWT.BORDER | SWT.SINGLE);
		volumesText.addModifyListener(Listener);

		Label portSpecsLabel = new Label(container, SWT.NULL);
		portSpecsLabel.setText(WizardMessages.getString(PORT_SPECS_LABEL));

		portSpecsText = new Text(container, SWT.BORDER | SWT.SINGLE);
		portSpecsText.addModifyListener(Listener);

		Label exposedPortsLabel = new Label(container, SWT.NULL);
		exposedPortsLabel
				.setText(WizardMessages.getString(EXPOSED_PORTS_LABEL));

		exposedPortsText = new Text(container, SWT.BORDER | SWT.SINGLE);
		exposedPortsText.addModifyListener(Listener);

		Label onBuildLabel = new Label(container, SWT.NULL);
		onBuildLabel.setText(WizardMessages.getString(ON_BUILD_LABEL));

		onBuildText = new Text(container, SWT.BORDER | SWT.SINGLE);
		onBuildText.addModifyListener(Listener);

		Label entryPointLabel = new Label(container, SWT.NULL);
		entryPointLabel.setText(WizardMessages.getString(ENTRY_POINT_LABEL));

		entryPointText = new Text(container, SWT.BORDER | SWT.SINGLE);
		entryPointText.addModifyListener(Listener);

		Label networkModeLabel = new Label(container, SWT.NULL);
		networkModeLabel.setText(WizardMessages.getString(NETWORK_MODE_LABEL));

		networkModeText = new Text(container, SWT.BORDER | SWT.SINGLE);
		networkModeText.addModifyListener(Listener);

		attachStdinButton = new Button(container, SWT.CHECK);
		attachStdinButton.setText(WizardMessages.getString(ATTACH_STDIN_LABEL));

		attachStdoutButton = new Button(container, SWT.CHECK);
		attachStdoutButton.setText(WizardMessages
				.getString(ATTACH_STDOUT_LABEL));

		attachStderrButton = new Button(container, SWT.CHECK);
		attachStderrButton.setText(WizardMessages
				.getString(ATTACH_STDERR_LABEL));

		ttyButton = new Button(container, SWT.CHECK);
		ttyButton.setText(WizardMessages.getString(TTY_LABEL));

		openStdinButton = new Button(container, SWT.CHECK);
		openStdinButton.setText(WizardMessages.getString(OPEN_STDIN_LABEL));

		stdinOnceButton = new Button(container, SWT.CHECK);
		stdinOnceButton.setText(WizardMessages.getString(STDIN_ONCE_LABEL));

		networkDisabledButton = new Button(container, SWT.CHECK);
		networkDisabledButton.setText(WizardMessages
				.getString(NETWORK_DISABLED_LABEL));

		privilegedButton = new Button(container, SWT.CHECK);
		privilegedButton.setText(WizardMessages.getString(PRIVILEGED_LABEL));

		publishAllPortsButton = new Button(container, SWT.CHECK);
		publishAllPortsButton.setText(WizardMessages
				.getString(PUBLISH_ALL_LABEL));

		Point p1 = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		Point p2 = imageText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		int centering = (p2.y - p1.y + 1) / 2;

		FormData f = new FormData();
		f.top = new FormAttachment(0);
		label.setLayoutData(f);

		Control prevControl = label;
		Control longestLabel = workingDirLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		imageLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		imageText.setLayoutData(f);

		prevControl = imageLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		cmdLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		cmdText.setLayoutData(f);

		prevControl = cmdLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		userLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		userText.setLayoutData(f);

		prevControl = userLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		workingDirLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		workingDirText.setLayoutData(f);

		prevControl = workingDirLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		envLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		envText.setLayoutData(f);

		prevControl = envLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		hostnameLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		hostnameText.setLayoutData(f);

		prevControl = hostnameLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		domainnameLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		domainnameText.setLayoutData(f);

		prevControl = domainnameLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		memoryLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		memoryWidget.setLayoutData(f);

		prevControl = memoryLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		memorySwapLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		memorySwapWidget.setLayoutData(f);

		prevControl = memorySwapLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		cpuSharesLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		cpuSharesWidget.setLayoutData(f);

		prevControl = cpuSharesLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		cpuSetLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		cpuSetText.setLayoutData(f);

		prevControl = cpuSetLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		volumesLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		volumesText.setLayoutData(f);

		prevControl = volumesLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		portSpecsLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		portSpecsText.setLayoutData(f);

		prevControl = portSpecsLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		exposedPortsLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		exposedPortsText.setLayoutData(f);

		prevControl = exposedPortsLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		onBuildLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		onBuildText.setLayoutData(f);

		prevControl = onBuildLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		entryPointLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		entryPointText.setLayoutData(f);

		prevControl = entryPointLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		networkModeLabel.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11);
		f.left = new FormAttachment(longestLabel, 5);
		f.right = new FormAttachment(100);
		networkModeText.setLayoutData(f);

		prevControl = networkModeLabel;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		attachStdinButton.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(attachStdinButton, 10);
		attachStdoutButton.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(attachStdoutButton, 10);
		attachStderrButton.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(attachStderrButton, 10);
		ttyButton.setLayoutData(f);

		prevControl = attachStdinButton;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		openStdinButton.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(openStdinButton, 10);
		stdinOnceButton.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(stdinOnceButton, 10);
		networkDisabledButton.setLayoutData(f);

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(networkDisabledButton, 0);
		privilegedButton.setLayoutData(f);

		prevControl = openStdinButton;

		f = new FormData();
		f.top = new FormAttachment(prevControl, 11 + centering);
		f.left = new FormAttachment(0, 0);
		publishAllPortsButton.setLayoutData(f);

		container.setSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));

		setControl(sc);
		setPageComplete(false);
		cmdText.setFocus();
	}
}

Back to the top