Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 28ed36473d8f8bf7014c15005320e8bfc1f9ecc0 (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
/*******************************************************************************
 * Copyright (c) 2008-2010 Sonatype, Inc.
 * 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:
 *      Sonatype, Inc. - initial API and implementation
 *******************************************************************************/

package org.eclipse.m2e.core.wizards;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import org.apache.maven.model.Model;

import org.eclipse.m2e.core.core.Messages;


public class MavenArtifactComponent extends Composite {

  public static final String JAR = "jar"; //$NON-NLS-1$

  public static final String WAR = "war"; //$NON-NLS-1$

  public static final String EAR = "ear"; //$NON-NLS-1$

  public static final String RAR = "rar"; //$NON-NLS-1$

  public static final String POM = "pom"; //$NON-NLS-1$

  // MNGECLIPSE-688 add EJB Support
  public static final String EJB = "ejb"; //$NON-NLS-1$

  public static final String[] PACKAGING_OPTIONS = {JAR, POM, WAR };

  public static final String DEFAULT_PACKAGING = JAR;

  public static final String DEFAULT_VERSION = "0.0.1-SNAPSHOT"; //$NON-NLS-1$

  /** group id text field */
  protected Combo groupIdCombo;

  /** artifact id text field */
  protected Combo artifactIdCombo;

  /** version text field */
  protected Combo versionCombo;

  /** packaging options combobox */
  protected Combo packagingCombo;

  /** name text field */
  protected Combo nameCombo;

  /** description text field */
  protected Text descriptionText;

  private ModifyListener modifyingListener;

  private Label groupIdlabel;

  private Label artifactIdLabel;

  private Label versionLabel;

  private Label packagingLabel;

  private Label nameLabel;

  private Label descriptionLabel;

  /** Creates a new component. */
  public MavenArtifactComponent(Composite parent, int styles) {
    super(parent, styles);

    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    setLayout(layout);

    Group artifactGroup = new Group(this, SWT.NONE);
    artifactGroup.setText(Messages.getString("artifactComponent.artifact")); //$NON-NLS-1$
    GridData gd_artifactGroup = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    artifactGroup.setLayoutData(gd_artifactGroup);
    artifactGroup.setLayout(new GridLayout(2, false));

    groupIdlabel = new Label(artifactGroup, SWT.NONE);
    groupIdlabel.setText(Messages.getString("artifactComponent.groupId")); //$NON-NLS-1$

    groupIdCombo = new Combo(artifactGroup, SWT.BORDER);
    groupIdCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    groupIdCombo.setData("name", "groupIdCombo"); //$NON-NLS-1$ //$NON-NLS-2$

    artifactIdLabel = new Label(artifactGroup, SWT.NONE);
    artifactIdLabel.setText(Messages.getString("artifactComponent.artifactId")); //$NON-NLS-1$

    artifactIdCombo = new Combo(artifactGroup, SWT.BORDER);
    artifactIdCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
    artifactIdCombo.setData("name", "artifactIdCombo"); //$NON-NLS-1$ //$NON-NLS-2$

    versionLabel = new Label(artifactGroup, SWT.NONE);
    versionLabel.setText(Messages.getString("artifactComponent.version")); //$NON-NLS-1$

    versionCombo = new Combo(artifactGroup, SWT.BORDER);
    versionCombo.setLayoutData(new GridData(150, SWT.DEFAULT));
    versionCombo.setText(DEFAULT_VERSION);
    versionCombo.setData("name", "versionCombo"); //$NON-NLS-1$ //$NON-NLS-2$

    packagingLabel = new Label(artifactGroup, SWT.NONE);
    packagingLabel.setText(Messages.getString("artifactComponent.packaging")); //$NON-NLS-1$

    packagingCombo = new Combo(artifactGroup, SWT.NONE);
    packagingCombo.setItems(PACKAGING_OPTIONS);
    packagingCombo.setText(DEFAULT_PACKAGING);
    packagingCombo.setLayoutData(new GridData(150, SWT.DEFAULT));
    packagingCombo.setData("name", "packagingCombo"); //$NON-NLS-1$ //$NON-NLS-2$

    nameLabel = new Label(artifactGroup, SWT.NONE);
    nameLabel.setLayoutData(new GridData());
    nameLabel.setText(Messages.getString("artifactComponent.name")); //$NON-NLS-1$

    nameCombo = new Combo(artifactGroup, SWT.BORDER);
    nameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    nameCombo.setData("name", "nameCombo"); //$NON-NLS-1$ //$NON-NLS-2$

    descriptionLabel = new Label(artifactGroup, SWT.NONE);
    descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));
    descriptionLabel.setText(Messages.getString("artifactComponent.description")); //$NON-NLS-1$

    descriptionText = new Text(artifactGroup, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
    GridData gd_descriptionText = new GridData(SWT.FILL, SWT.FILL, false, true);
    gd_descriptionText.minimumHeight = 20;
    descriptionText.setLayoutData(gd_descriptionText);
    descriptionText.setData("name", "descriptionText"); //$NON-NLS-1$ //$NON-NLS-2$
  }

  public void setModifyingListener(ModifyListener modifyingListener) {
    this.modifyingListener = modifyingListener;

    groupIdCombo.addModifyListener(modifyingListener);
    artifactIdCombo.addModifyListener(modifyingListener);
    versionCombo.addModifyListener(modifyingListener);
    packagingCombo.addModifyListener(modifyingListener);
  }

  public void dispose() {
    super.dispose();

    if(modifyingListener != null) {
      groupIdCombo.removeModifyListener(modifyingListener);
      artifactIdCombo.removeModifyListener(modifyingListener);
      versionCombo.removeModifyListener(modifyingListener);
      packagingCombo.removeModifyListener(modifyingListener);
    }
  }

  public String getModelName() {
    return nameCombo.getText();
  }

  public String getArtifactId() {
    return this.artifactIdCombo.getText();
  }

  public String getGroupId() {
    return this.groupIdCombo.getText();
  }

  public String getVersion() {
    return this.versionCombo.getText();
  }

  public String getPackaging() {
    return packagingCombo.getText();
  }

  public String getDescription() {
    return descriptionText.getText();
  }

  public void setModelName(String name) {
    nameCombo.setText(name);
  }

  public void setGroupId(String groupId) {
    this.groupIdCombo.setText(groupId);
  }

  public void setArtifactId(String artifact) {
    this.artifactIdCombo.setText(artifact);
  }

  public void setVersion(String version) {
    versionCombo.setText(version);
  }

  public void setPackaging(String packaging) {
    if(packagingCombo != null) {
      packagingCombo.setText(packaging);
    }
  }

  public void setDescription(String description) {
    if(descriptionText != null) {
      descriptionText.setText(description);
    }
  }

  public Model getModel() {
    Model model = new Model();
    model.setModelVersion("4.0.0"); //$NON-NLS-1$
    
    model.setGroupId(getGroupId());
    model.setArtifactId(getArtifactId());
    model.setVersion(getVersion());
    model.setPackaging(getPackaging());
    
    if(getModelName().length()>0) {
      model.setName(getModelName());
    }
    if(getDescription().length()>0) {
      model.setDescription(getDescription());
    }
    
    return model;
  }

  /** Enables or disables the artifact id text field. */
  public void setArtifactIdEditable(boolean b) {
    artifactIdCombo.setEnabled(b);
  }

  public Combo getGroupIdCombo() {
    return groupIdCombo;
  }

  public Combo getArtifactIdCombo() {
    return artifactIdCombo;
  }

  public Combo getVersionCombo() {
    return versionCombo;
  }

  public Combo getNameCombo() {
    return nameCombo;
  }
  
  public void setWidthGroup(WidthGroup widthGroup) {
    widthGroup.addControl(this.groupIdlabel);
    widthGroup.addControl(this.artifactIdLabel);
    widthGroup.addControl(this.versionLabel);
    widthGroup.addControl(this.packagingLabel);
    widthGroup.addControl(this.nameLabel);
    widthGroup.addControl(this.descriptionLabel);
  }

}

Back to the top