Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0857441590c70d6c54d2fe53f3bbb772a6caf514 (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
/*******************************************************************************
 * 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 org.eclipse.jface.wizard.WizardPage;
import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
import org.eclipse.swt.SWT;
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.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class ContainerCommitPage extends WizardPage {

	private final static String NAME = "ContainerCommit.name"; //$NON-NLS-1$
	private final static String TITLE = "ContainerCommit.title"; //$NON-NLS-1$
	private final static String DESC = "ContainerCommit.desc"; //$NON-NLS-1$
	private final static String COMMIT_LABEL = "ContainerCommit.label"; //$NON-NLS-1$
	private final static String NAME_LABEL = "Name.label"; //$NON-NLS-1$
	private final static String NAME_TOOLTIP = "ImageName.toolTip"; //$NON-NLS-1$
	private final static String AUTHOR_LABEL = "Author.label"; //$NON-NLS-1$
	private final static String COMMENT_LABEL = "Comment.label"; //$NON-NLS-1$

	private final static String INVALID_REPO_ID = "ErrorInvalidRepo.msg"; //$NON-NLS-1$

	private String repo;
	private String tag;

	private Text nameText;
	private Text authorText;
	private Text commentText;

	public ContainerCommitPage(String container) {
		super(WizardMessages.getString(NAME));
		setDescription(WizardMessages.getFormattedString(DESC,
				container.substring(0, 8)));
		setTitle(WizardMessages.getString(TITLE));
		setImageDescriptor(SWTImagesFactory.DESC_WIZARD);
	}

	public String getRepo() {
		return repo;
	}

	public String getTag() {
		return tag;
	}

	public String getAuthor() {
		return authorText.getText();
	}

	public String getComment() {
		return commentText.getText();
	}

	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 (nameText.getText().length() == 0)
			complete = false;
		if (!error) {
			String[] tokens = nameText.getText().split(":"); //$NON-NLS-1$
			if (tokens.length == 2) {
				repo = tokens[0];
				tag = tokens[1];
				setErrorMessage(null);
			} else if (tokens.length == 1) {
				repo = tokens[0];
				tag = ""; //$NON-NLS-1$
				setErrorMessage(null);
			} else {
				setErrorMessage(WizardMessages.getString(INVALID_REPO_ID));
			}
		}
		setPageComplete(complete && !error);
	}

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

		Label label = new Label(composite, SWT.NULL);
		label.setText(WizardMessages.getString(COMMIT_LABEL));

		Label nameLabel = new Label(composite, SWT.NULL);
		nameLabel.setText(WizardMessages.getString(NAME_LABEL));

		nameText = new Text(composite, SWT.BORDER | SWT.SINGLE);
		nameText.addModifyListener(Listener);
		nameText.setToolTipText(WizardMessages.getString(NAME_TOOLTIP));

		Label authorLabel = new Label(composite, SWT.NULL);
		authorLabel.setText(WizardMessages.getString(AUTHOR_LABEL));

		authorText = new Text(composite, SWT.BORDER | SWT.SINGLE);
		authorText.addModifyListener(Listener);

		Label commentLabel = new Label(composite, SWT.NULL);
		commentLabel.setText(WizardMessages.getString(COMMENT_LABEL));

		commentText = new Text(composite, SWT.BORDER | SWT.SINGLE);
		commentText.addModifyListener(Listener);

		Point p1 = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		Point p2 = nameText.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 = commentLabel;

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

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

		prevControl = nameLabel;

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

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

		prevControl = authorLabel;

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

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

		prevControl = commentLabel;

		setControl(composite);
		setPageComplete(false);
	}

}

Back to the top