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
;
19 import java
.util
.HashMap
;
22 import javax
.jcr
.Node
;
23 import javax
.jcr
.RepositoryException
;
25 import org
.argeo
.ArgeoException
;
26 import org
.argeo
.eclipse
.ui
.utils
.CommandUtils
;
27 import org
.argeo
.slc
.SlcException
;
28 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
29 import org
.argeo
.slc
.client
.ui
.dist
.utils
.AbstractHyperlinkListener
;
30 import org
.argeo
.slc
.client
.ui
.specific
.OpenJcrFile
;
31 import org
.argeo
.slc
.jcr
.SlcNames
;
32 import org
.argeo
.slc
.repo
.RepoConstants
;
33 import org
.argeo
.slc
.repo
.RepoUtils
;
34 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.layout
.GridData
;
37 import org
.eclipse
.swt
.layout
.GridLayout
;
38 import org
.eclipse
.swt
.layout
.RowLayout
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.swt
.widgets
.Label
;
41 import org
.eclipse
.swt
.widgets
.Text
;
42 import org
.eclipse
.ui
.PlatformUI
;
43 import org
.eclipse
.ui
.browser
.IWebBrowser
;
44 import org
.eclipse
.ui
.browser
.IWorkbenchBrowserSupport
;
45 import org
.eclipse
.ui
.forms
.IManagedForm
;
46 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
47 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
48 import org
.eclipse
.ui
.forms
.events
.HyperlinkEvent
;
49 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
50 import org
.eclipse
.ui
.forms
.widgets
.Hyperlink
;
51 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
52 import org
.eclipse
.ui
.forms
.widgets
.Section
;
55 * Show the details for a given bundle.
57 public class BundleDetailPage
extends FormPage
implements SlcNames
{
59 final static String PAGE_ID
= "BundleDetailPage";
65 private FormToolkit tk
;
67 public BundleDetailPage(FormEditor formEditor
, String title
, Node bundle
) {
68 super(formEditor
, PAGE_ID
, title
);
73 protected void createFormContent(IManagedForm managedForm
) {
74 // General settings for this page
75 ScrolledForm form
= managedForm
.getForm();
76 tk
= managedForm
.getToolkit();
77 Composite body
= form
.getBody();
79 GridLayout layout
= new GridLayout(1, false);
80 layout
.marginWidth
= 5;
81 layout
.marginRight
= 15;
82 layout
.verticalSpacing
= 0;
83 body
.setLayout(layout
);
85 form
.setText(bundle
.hasProperty(SlcNames
.SLC_SYMBOLIC_NAME
) ? bundle
86 .getProperty(SlcNames
.SLC_SYMBOLIC_NAME
).getString() : "");
87 form
.setMessage(bundle
88 .hasProperty(DistConstants
.SLC_BUNDLE_DESCRIPTION
) ? bundle
89 .getProperty(DistConstants
.SLC_BUNDLE_DESCRIPTION
)
90 .getString() : "", IMessageProvider
.NONE
);
91 } catch (RepositoryException re
) {
92 throw new SlcException("Unable to get bundle name for node "
97 Composite header
= tk
.createComposite(body
);
98 header
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
99 populateHeaderPart(header
);
101 Composite mavenSnipet
= tk
.createComposite(body
);
102 mavenSnipet
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
103 populateMavenSnippetPart(mavenSnipet
);
106 private void populateHeaderPart(Composite parent
) {
107 GridLayout layout
= new GridLayout(6, false);
108 // layout.marginWidth = layout.horizontalSpacing = layout.marginHeight =
110 layout
.horizontalSpacing
= 10;
111 parent
.setLayout(layout
);
113 // 1st Line: Category, name version
114 createLT(parent
, "Category",
115 bundle
.hasProperty(SlcNames
.SLC_GROUP_ID
) ? bundle
116 .getProperty(SlcNames
.SLC_GROUP_ID
).getString()
118 createLT(parent
, "Name",
119 bundle
.hasProperty(SlcNames
.SLC_ARTIFACT_ID
) ? bundle
120 .getProperty(SlcNames
.SLC_ARTIFACT_ID
).getString()
122 createLT(parent
, "Version",
123 bundle
.hasProperty(SlcNames
.SLC_ARTIFACT_VERSION
) ? bundle
124 .getProperty(SlcNames
.SLC_ARTIFACT_VERSION
)
127 // 3rd Line: Vendor, licence, sources
131 bundle
.hasProperty(DistConstants
.SLC_BUNDLE_VENDOR
) ? bundle
132 .getProperty(DistConstants
.SLC_BUNDLE_VENDOR
)
133 .getString() : "N/A");
135 createLicencesLink(parent
, "Licence",
136 DistConstants
.SLC_BUNDLE_LICENCE
);
137 addSourceLink(parent
);
139 // 2nd Line: The Jar itself and the Manifest
140 createJarLink(parent
);
141 createManifestLink(parent
);
144 createPomLink(parent
);
146 } catch (RepositoryException re
) {
147 throw new SlcException("Unable to get bundle name for node "
153 private void populateMavenSnippetPart(Composite parent
) {
154 GridLayout layout
= new GridLayout(1, false);
155 layout
.marginWidth
= layout
.horizontalSpacing
= layout
.horizontalSpacing
= layout
.marginHeight
= 0;
156 parent
.setLayout(layout
);
158 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
159 | Section
.DESCRIPTION
);
160 section
.setText("Maven");
161 section
.setDescription("Add the below tag to your Artifact pom dependencies");
162 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
163 Text snippetTxt
= createMavenSnippet(section
);
164 section
.setClient(snippetTxt
);
167 // /////////////////////
170 private Text
createLT(Composite parent
, String labelValue
, String textValue
) {
171 Label label
= tk
.createLabel(parent
, labelValue
, SWT
.RIGHT
);
172 // label.setFont(EclipseUiUtils.getBoldFont(parent));
173 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
174 // Add a trailing space to workaround a display glitch in RAP 1.3
175 Text text
= new Text(parent
, SWT
.LEFT
);
176 text
.setText(textValue
+ " ");
177 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
178 text
.setEditable(false);
182 private void createLicencesLink(Composite parent
, String label
,
183 String jcrPropName
) throws RepositoryException
{
184 tk
.createLabel(parent
, label
, SWT
.NONE
);
185 if (bundle
.hasProperty(jcrPropName
)) {
187 String licenceLinkVal
= bundle
.getProperty(jcrPropName
).getString();
188 String
[] licenceVals
= licenceLinkVal
.split(", ");
190 Composite body
= tk
.createComposite(parent
);
191 body
.setLayout(new RowLayout(SWT
.WRAP
));
193 for (String value
: licenceVals
) {
194 final Hyperlink link
= tk
195 .createHyperlink(body
, value
, SWT
.NONE
);
196 link
.addHyperlinkListener(new AbstractHyperlinkListener() {
198 public void linkActivated(HyperlinkEvent e
) {
200 IWorkbenchBrowserSupport browserSupport
= PlatformUI
201 .getWorkbench().getBrowserSupport();
202 IWebBrowser browser
= browserSupport
204 IWorkbenchBrowserSupport
.LOCATION_BAR
205 | IWorkbenchBrowserSupport
.NAVIGATION_BAR
,
206 "SLC Distribution browser",
207 "SLC Distribution browser",
209 browser
.openURL(new URL(link
.getText()));
210 } catch (Exception ex
) {
211 throw new SlcException("error opening browser", ex
); //$NON-NLS-1$
217 tk
.createLabel(parent
, "N/A", SWT
.NONE
);
220 private void createJarLink(Composite parent
) throws RepositoryException
{
221 Label label
= tk
.createLabel(parent
, "Jar", SWT
.RIGHT
);
222 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
224 Composite body
= tk
.createComposite(parent
);
225 RowLayout rl
= new RowLayout(SWT
.HORIZONTAL
);
228 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 3, 1));
230 Hyperlink jarLink
= tk
231 .createHyperlink(body
, bundle
.getName(), SWT
.NONE
);
232 jarLink
.addHyperlinkListener(new OpenFileLinkListener(bundle
.getPath()));
234 // Corresponding check sums
236 String name
= bundle
.getName() + ".md5";
237 if (bundle
.getParent().hasNode(name
)) {
238 Node md5
= bundle
.getParent().getNode(name
);
239 Hyperlink md5Link
= tk
.createHyperlink(body
, "MD5", SWT
.NONE
);
240 md5Link
.addHyperlinkListener(new OpenFileLinkListener(md5
.getPath()));
243 name
= bundle
.getName() + ".sha1";
244 if (bundle
.getParent().hasNode(name
)) {
245 Node sha1
= bundle
.getParent().getNode(name
);
246 Hyperlink sha1Link
= tk
.createHyperlink(body
, "SHA1", SWT
.NONE
);
247 sha1Link
.addHyperlinkListener(new OpenFileLinkListener(sha1
252 private void createPomLink(Composite parent
) throws RepositoryException
{
253 Label label
= tk
.createLabel(parent
, "Pom", SWT
.RIGHT
);
254 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
256 String name
= bundle
.getName().substring(0, bundle
.getName().length() - "jar".length()) + "pom";
258 if (bundle
.getParent().hasNode(name
)) {
259 Node pom
= bundle
.getParent().getNode(name
);
261 Composite body
= tk
.createComposite(parent
);
262 RowLayout rl
= new RowLayout(SWT
.HORIZONTAL
);
265 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false,
268 Hyperlink pomLink
= tk
.createHyperlink(body
, "pom.xml", SWT
.NONE
);
269 pomLink
.addHyperlinkListener(new OpenFileLinkListener(pom
.getPath()));
271 // Corresponding check sums
273 name
= pom
.getName() + ".md5";
274 if (pom
.getParent().hasNode(name
)) {
275 Node md5
= pom
.getParent().getNode(name
);
276 Hyperlink md5Link
= tk
.createHyperlink(body
, "MD5", SWT
.NONE
);
277 md5Link
.addHyperlinkListener(new OpenFileLinkListener(md5
281 name
= pom
.getName() + ".sha1";
282 if (pom
.getParent().hasNode(name
)) {
283 Node sha1
= pom
.getParent().getNode(name
);
284 Hyperlink sha1Link
= tk
.createHyperlink(body
, "SHA1", SWT
.NONE
);
285 sha1Link
.addHyperlinkListener(new OpenFileLinkListener(sha1
289 tk
.createLabel(parent
, "N/A", SWT
.NONE
);
292 private void createManifestLink(Composite parent
)
293 throws RepositoryException
{
294 tk
.createLabel(parent
, "Manifest", SWT
.NONE
);
295 Hyperlink link
= tk
.createHyperlink(parent
, "MANIFEST.MF", SWT
.NONE
);
296 // link.addHyperlinkListener(new
297 // OpenFileLinkListener(bundle.getPath()));
300 private void createHyperlink(Composite parent
, String label
,
301 String jcrPropName
) throws RepositoryException
{
302 tk
.createLabel(parent
, label
, SWT
.NONE
);
303 if (bundle
.hasProperty(jcrPropName
)) {
304 final Hyperlink link
= tk
.createHyperlink(parent
, bundle
305 .getProperty(jcrPropName
).getString(), SWT
.NONE
);
306 link
.addHyperlinkListener(new AbstractHyperlinkListener() {
308 public void linkActivated(HyperlinkEvent e
) {
310 IWorkbenchBrowserSupport browserSupport
= PlatformUI
311 .getWorkbench().getBrowserSupport();
312 IWebBrowser browser
= browserSupport
314 IWorkbenchBrowserSupport
.LOCATION_BAR
315 | IWorkbenchBrowserSupport
.NAVIGATION_BAR
,
316 "SLC Distribution browser",
317 "SLC Distribution browser",
319 browser
.openURL(new URL(link
.getText()));
320 } catch (Exception ex
) {
321 throw new SlcException("error opening browser", ex
); //$NON-NLS-1$
326 tk
.createLabel(parent
, "N/A", SWT
.NONE
);
329 // helper to check if sources are available
330 private void addSourceLink(Composite parent
) {
332 String srcPath
= RepoUtils
.relatedPdeSourcePath(
333 RepoConstants
.DEFAULT_ARTIFACTS_BASE_PATH
, bundle
);
334 if (!bundle
.getSession().nodeExists(srcPath
)) {
335 createLT(parent
, "Sources", "N/A");
337 final Node sourcesNode
= bundle
.getSession().getNode(srcPath
);
339 String srcName
= null;
340 if (sourcesNode
.hasProperty(SlcNames
.SLC_SYMBOLIC_NAME
))
341 srcName
= sourcesNode
.getProperty(
342 SlcNames
.SLC_SYMBOLIC_NAME
).getString();
344 srcName
= sourcesNode
.getName();
345 Label label
= tk
.createLabel(parent
, "Sources", SWT
.RIGHT
);
346 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false,
348 final Hyperlink link
= tk
.createHyperlink(parent
, srcName
,
350 link
.addHyperlinkListener(new OpenFileLinkListener(sourcesNode
355 // public void linkActivated(HyperlinkEvent e) {
357 // ModuleEditorInput editorInput = (ModuleEditorInput)
359 // Map<String, String> params = new HashMap<String, String>();
360 // params.put(OpenJcrFile.PARAM_REPO_NODE_PATH,
361 // editorInput.getRepoNodePath());
362 // params.put(OpenJcrFile.PARAM_REPO_URI,
363 // editorInput.getUri());
364 // params.put(OpenJcrFile.PARAM_WORKSPACE_NAME,
365 // editorInput.getWorkspaceName());
366 // params.put(OpenJcrFile.PARAM_FILE_PATH,
368 // CommandUtils.callCommand(OpenJcrFile.ID, params);
369 // } catch (Exception ex) {
370 // throw new SlcException("error opening browser", ex); //$NON-NLS-1$
376 } catch (RepositoryException e
) {
377 throw new SlcException("Unable to configure sources link for "
382 private class OpenFileLinkListener
extends AbstractHyperlinkListener
{
383 final private String path
;
385 public OpenFileLinkListener(String path
) {
390 public void linkActivated(HyperlinkEvent e
) {
392 ModuleEditorInput editorInput
= (ModuleEditorInput
) getEditorInput();
393 Map
<String
, String
> params
= new HashMap
<String
, String
>();
394 params
.put(OpenJcrFile
.PARAM_REPO_NODE_PATH
,
395 editorInput
.getRepoNodePath());
396 params
.put(OpenJcrFile
.PARAM_REPO_URI
, editorInput
.getUri());
397 params
.put(OpenJcrFile
.PARAM_WORKSPACE_NAME
,
398 editorInput
.getWorkspaceName());
399 params
.put(OpenJcrFile
.PARAM_FILE_PATH
, path
);
400 CommandUtils
.callCommand(OpenJcrFile
.ID
, params
);
401 } catch (Exception ex
) {
402 throw new SlcException("error opening browser", ex
); //$NON-NLS-1$
407 /** Creates a text area with corresponding maven snippet */
408 private Text
createMavenSnippet(Composite parent
) {
409 Text mavenSnippet
= new Text(parent
, SWT
.MULTI
| SWT
.WRAP
);
410 GridData gd
= new GridData(GridData
.FILL_HORIZONTAL
);
411 gd
.grabExcessHorizontalSpace
= true;
413 mavenSnippet
.setLayoutData(gd
);
414 mavenSnippet
.setText(generateXmlSnippet());
418 private String
generateXmlSnippet() {
420 StringBuffer sb
= new StringBuffer();
421 sb
.append("<dependency>\n");
422 sb
.append("\t<groupId>");
423 sb
.append(bundle
.getProperty(SLC_GROUP_ID
).getString());
424 sb
.append("</groupId>\n");
425 sb
.append("\t<artifactId>");
426 sb
.append(bundle
.getProperty(SLC_ARTIFACT_ID
).getString());
427 sb
.append("</artifactId>\n");
428 sb
.append("\t<version>");
429 sb
.append(bundle
.getProperty(SLC_ARTIFACT_VERSION
).getString());
430 sb
.append("</version>\n");
431 sb
.append("</dependency>");
432 return sb
.toString();
433 } catch (RepositoryException re
) {
434 throw new ArgeoException(
435 "unexpected error while generating maven snippet");