2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.dist
.editors
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
21 import org
.argeo
.slc
.SlcException
;
22 import org
.argeo
.slc
.SlcNames
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Text
;
28 import org
.eclipse
.ui
.forms
.IManagedForm
;
29 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
30 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
31 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
32 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
33 import org
.eclipse
.ui
.forms
.widgets
.Section
;
35 /** Show the details for a given bundle. */
36 public class ModularDistVersionDetailPage
extends FormPage
implements SlcNames
{
38 final static String PAGE_ID
= "ModularDistVersionDetailPage";
41 private Node modularDistVersion
;
44 private FormToolkit tk
;
46 public ModularDistVersionDetailPage(FormEditor formEditor
, String title
,
47 Node modularDistVersion
) {
48 super(formEditor
, PAGE_ID
, title
);
49 this.modularDistVersion
= modularDistVersion
;
53 protected void createFormContent(IManagedForm managedForm
) {
54 // General settings for this page
55 ScrolledForm form
= managedForm
.getForm();
56 tk
= managedForm
.getToolkit();
57 Composite body
= form
.getBody();
59 GridLayout layout
= new GridLayout(1, false);
60 layout
.marginWidth
= 5;
61 layout
.marginRight
= 15;
62 layout
.verticalSpacing
= 0;
63 body
.setLayout(layout
);
65 form
.setText(modularDistVersion
.hasProperty(SLC_NAME
) ? modularDistVersion
66 .getProperty(SLC_NAME
).getString() : "");
67 } catch (RepositoryException re
) {
68 throw new SlcException("Unable to get slc:name for node "
69 + modularDistVersion
, re
);
73 Composite mavenSnipet
= tk
.createComposite(body
);
74 mavenSnipet
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
75 populateMavenSnippetPart(mavenSnipet
);
78 private void populateMavenSnippetPart(Composite parent
) {
79 GridLayout layout
= new GridLayout(1, false);
80 layout
.marginWidth
= layout
.horizontalSpacing
= layout
.horizontalSpacing
= layout
.marginHeight
= 0;
81 parent
.setLayout(layout
);
83 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
84 | Section
.DESCRIPTION
);
85 section
.setText("Maven");
86 section
.setDescription("In order to rely on the versions defined by this distribution, "
87 + "add the below tag to the dependency management of your parent pom.");
88 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
89 Text snippetTxt
= createMavenSnippet(section
);
90 section
.setClient(snippetTxt
);
93 // /////////////////////
95 /** Creates a text area with corresponding maven snippet */
96 private Text
createMavenSnippet(Composite parent
) {
97 Text mavenSnippet
= new Text(parent
, SWT
.MULTI
| SWT
.WRAP
);
98 GridData gd
= new GridData(GridData
.FILL_HORIZONTAL
);
99 gd
.grabExcessHorizontalSpace
= true;
101 mavenSnippet
.setLayoutData(gd
);
102 mavenSnippet
.setText(generateXmlSnippet());
103 mavenSnippet
.setEditable(false);
107 private String
generateXmlSnippet() {
109 StringBuffer sb
= new StringBuffer();
110 sb
.append("<dependency>\n");
111 sb
.append("\t<groupId>");
112 sb
.append(modularDistVersion
.getProperty(SLC_GROUP_ID
).getString());
113 sb
.append("</groupId>\n");
114 sb
.append("\t<artifactId>");
115 sb
.append(modularDistVersion
.getProperty(SLC_ARTIFACT_ID
)
117 sb
.append("</artifactId>\n");
118 sb
.append("\t<version>");
119 sb
.append(modularDistVersion
.getProperty(SLC_ARTIFACT_VERSION
)
121 sb
.append("</version>\n");
122 sb
.append("\t<type>pom</type>\n");
123 sb
.append("\t<scope>import</scope>\n");
124 sb
.append("</dependency>");
125 return sb
.toString();
126 } catch (RepositoryException re
) {
127 throw new SlcException(
128 "unexpected error while generating maven snippet");