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
.apache
.commons
.logging
.Log
;
26 import org
.apache
.commons
.logging
.LogFactory
;
27 import org
.argeo
.ArgeoException
;
28 import org
.argeo
.eclipse
.ui
.utils
.CommandUtils
;
29 import org
.argeo
.slc
.SlcException
;
30 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
31 import org
.argeo
.slc
.client
.ui
.dist
.utils
.AbstractHyperlinkListener
;
32 import org
.argeo
.slc
.client
.ui
.specific
.OpenJcrFile
;
33 import org
.argeo
.slc
.client
.ui
.specific
.OpenJcrFileCmdId
;
34 import org
.argeo
.slc
.jcr
.SlcNames
;
35 import org
.argeo
.slc
.repo
.RepoConstants
;
36 import org
.argeo
.slc
.repo
.RepoUtils
;
37 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.layout
.GridData
;
40 import org
.eclipse
.swt
.layout
.GridLayout
;
41 import org
.eclipse
.swt
.layout
.RowLayout
;
42 import org
.eclipse
.swt
.widgets
.Composite
;
43 import org
.eclipse
.swt
.widgets
.Label
;
44 import org
.eclipse
.swt
.widgets
.Text
;
45 import org
.eclipse
.ui
.PlatformUI
;
46 import org
.eclipse
.ui
.browser
.IWebBrowser
;
47 import org
.eclipse
.ui
.browser
.IWorkbenchBrowserSupport
;
48 import org
.eclipse
.ui
.forms
.IManagedForm
;
49 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
50 import org
.eclipse
.ui
.forms
.editor
.FormPage
;
51 import org
.eclipse
.ui
.forms
.events
.HyperlinkEvent
;
52 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
53 import org
.eclipse
.ui
.forms
.widgets
.Hyperlink
;
54 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
55 import org
.eclipse
.ui
.forms
.widgets
.Section
;
58 * Show the details for a given bundle.
60 public class BundleDetailPage
extends FormPage
implements SlcNames
{
61 private final static Log log
= LogFactory
.getLog(BundleDetailPage
.class);
63 final static String PAGE_ID
= "BundleDetailPage";
69 private FormToolkit tk
;
71 public BundleDetailPage(FormEditor formEditor
, String title
, Node bundle
) {
72 super(formEditor
, PAGE_ID
, title
);
77 protected void createFormContent(IManagedForm managedForm
) {
78 // General settings for this page
79 ScrolledForm form
= managedForm
.getForm();
80 tk
= managedForm
.getToolkit();
81 Composite body
= form
.getBody();
83 GridLayout layout
= new GridLayout(1, false);
84 layout
.marginWidth
= 5;
85 layout
.marginRight
= 15;
86 layout
.verticalSpacing
= 0;
87 body
.setLayout(layout
);
89 form
.setText(bundle
.hasProperty(SlcNames
.SLC_SYMBOLIC_NAME
) ? bundle
90 .getProperty(SlcNames
.SLC_SYMBOLIC_NAME
).getString() : "");
91 form
.setMessage(bundle
92 .hasProperty(DistConstants
.SLC_BUNDLE_DESCRIPTION
) ? bundle
93 .getProperty(DistConstants
.SLC_BUNDLE_DESCRIPTION
)
94 .getString() : "", IMessageProvider
.NONE
);
95 } catch (RepositoryException re
) {
96 throw new SlcException("Unable to get bundle name for node "
101 Composite header
= tk
.createComposite(body
);
102 header
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
103 populateHeaderPart(header
);
105 Composite mavenSnipet
= tk
.createComposite(body
);
106 mavenSnipet
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
107 populateMavenSnippetPart(mavenSnipet
);
110 private void populateHeaderPart(Composite parent
) {
111 GridLayout layout
= new GridLayout(6, false);
112 // layout.marginWidth = layout.horizontalSpacing = layout.marginHeight =
114 layout
.horizontalSpacing
= 10;
115 parent
.setLayout(layout
);
117 // 1st Line: Category, name version
118 createLT(parent
, "Category",
119 bundle
.hasProperty(SlcNames
.SLC_GROUP_ID
) ? bundle
120 .getProperty(SlcNames
.SLC_GROUP_ID
).getString()
122 createLT(parent
, "Name",
123 bundle
.hasProperty(SlcNames
.SLC_ARTIFACT_ID
) ? bundle
124 .getProperty(SlcNames
.SLC_ARTIFACT_ID
).getString()
126 createLT(parent
, "Version",
127 bundle
.hasProperty(SlcNames
.SLC_ARTIFACT_VERSION
) ? bundle
128 .getProperty(SlcNames
.SLC_ARTIFACT_VERSION
)
131 // 3rd Line: Vendor, licence, sources
135 bundle
.hasProperty(DistConstants
.SLC_BUNDLE_VENDOR
) ? bundle
136 .getProperty(DistConstants
.SLC_BUNDLE_VENDOR
)
137 .getString() : "N/A");
139 createLicencesLink(parent
, "Licence",
140 DistConstants
.SLC_BUNDLE_LICENCE
);
141 addSourceLink(parent
);
143 // 2nd Line: The Jar itself and the Manifest
144 createJarLink(parent
);
145 createManifestLink(parent
);
148 createPomLink(parent
);
150 } catch (RepositoryException re
) {
151 throw new SlcException("Unable to get bundle name for node "
157 private void populateMavenSnippetPart(Composite parent
) {
158 GridLayout layout
= new GridLayout(1, false);
159 layout
.marginWidth
= layout
.horizontalSpacing
= layout
.horizontalSpacing
= layout
.marginHeight
= 0;
160 parent
.setLayout(layout
);
162 Section section
= tk
.createSection(parent
, Section
.TITLE_BAR
163 | Section
.DESCRIPTION
);
164 section
.setText("Maven");
165 section
.setDescription("Add the below tag to your Artifact pom dependencies");
166 section
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
167 Text snippetTxt
= createMavenSnippet(section
);
168 section
.setClient(snippetTxt
);
171 // /////////////////////
174 private Text
createLT(Composite parent
, String labelValue
, String textValue
) {
175 Label label
= tk
.createLabel(parent
, labelValue
, SWT
.RIGHT
);
176 // label.setFont(EclipseUiUtils.getBoldFont(parent));
177 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
178 // Add a trailing space to workaround a display glitch in RAP 1.3
179 Text text
= new Text(parent
, SWT
.LEFT
);
180 text
.setText(textValue
+ " ");
181 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
182 text
.setEditable(false);
186 private void createLicencesLink(Composite parent
, String label
,
187 String jcrPropName
) throws RepositoryException
{
188 tk
.createLabel(parent
, label
, SWT
.NONE
);
189 if (bundle
.hasProperty(jcrPropName
)) {
191 String licenceLinkVal
= bundle
.getProperty(jcrPropName
).getString();
192 String
[] licenceVals
= licenceLinkVal
.split(", ");
194 Composite body
= tk
.createComposite(parent
);
195 body
.setLayout(new RowLayout(SWT
.WRAP
));
197 for (String value
: licenceVals
) {
198 final Hyperlink link
= tk
199 .createHyperlink(body
, value
, SWT
.NONE
);
200 link
.addHyperlinkListener(new AbstractHyperlinkListener() {
202 public void linkActivated(HyperlinkEvent e
) {
204 IWorkbenchBrowserSupport browserSupport
= PlatformUI
205 .getWorkbench().getBrowserSupport();
206 IWebBrowser browser
= browserSupport
208 IWorkbenchBrowserSupport
.LOCATION_BAR
209 | IWorkbenchBrowserSupport
.NAVIGATION_BAR
,
210 "SLC Distribution browser",
211 "SLC Distribution browser",
213 browser
.openURL(new URL(link
.getText()));
214 } catch (Exception ex
) {
215 throw new SlcException("error opening browser", ex
); //$NON-NLS-1$
221 tk
.createLabel(parent
, "N/A", SWT
.NONE
);
224 private void createJarLink(Composite parent
) throws RepositoryException
{
225 Label label
= tk
.createLabel(parent
, "Jar", SWT
.RIGHT
);
226 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
228 Composite body
= tk
.createComposite(parent
);
229 RowLayout rl
= new RowLayout(SWT
.HORIZONTAL
);
232 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 3, 1));
234 Hyperlink jarLink
= tk
235 .createHyperlink(body
, bundle
.getName(), SWT
.NONE
);
236 jarLink
.addHyperlinkListener(new OpenFileLinkListener(bundle
.getPath()));
238 // Corresponding check sums
240 String name
= bundle
.getName() + ".md5";
241 if (bundle
.getParent().hasNode(name
)) {
242 Node md5
= bundle
.getParent().getNode(name
);
243 Hyperlink md5Link
= tk
.createHyperlink(body
, "MD5", SWT
.NONE
);
244 md5Link
.addHyperlinkListener(new OpenFileLinkListener(md5
.getPath()));
247 name
= bundle
.getName() + ".sha1";
248 if (bundle
.getParent().hasNode(name
)) {
249 Node sha1
= bundle
.getParent().getNode(name
);
250 Hyperlink sha1Link
= tk
.createHyperlink(body
, "SHA1", SWT
.NONE
);
251 sha1Link
.addHyperlinkListener(new OpenFileLinkListener(sha1
256 private void createPomLink(Composite parent
) throws RepositoryException
{
257 Label label
= tk
.createLabel(parent
, "Pom", SWT
.RIGHT
);
258 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
260 String name
= bundle
.getName().substring(0,
261 bundle
.getName().length() - "jar".length())
264 if (bundle
.getParent().hasNode(name
)) {
265 Node pom
= bundle
.getParent().getNode(name
);
267 Composite body
= tk
.createComposite(parent
);
268 RowLayout rl
= new RowLayout(SWT
.HORIZONTAL
);
271 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false,
274 Hyperlink pomLink
= tk
.createHyperlink(body
, "pom.xml", SWT
.NONE
);
275 pomLink
.addHyperlinkListener(new OpenFileLinkListener(pom
.getPath()));
277 // Corresponding check sums
279 name
= pom
.getName() + ".md5";
280 if (pom
.getParent().hasNode(name
)) {
281 Node md5
= pom
.getParent().getNode(name
);
282 Hyperlink md5Link
= tk
.createHyperlink(body
, "MD5", SWT
.NONE
);
283 md5Link
.addHyperlinkListener(new OpenFileLinkListener(md5
287 name
= pom
.getName() + ".sha1";
288 if (pom
.getParent().hasNode(name
)) {
289 Node sha1
= pom
.getParent().getNode(name
);
290 Hyperlink sha1Link
= tk
.createHyperlink(body
, "SHA1", SWT
.NONE
);
291 sha1Link
.addHyperlinkListener(new OpenFileLinkListener(sha1
295 tk
.createLabel(parent
, "N/A", SWT
.NONE
);
298 private void createManifestLink(Composite parent
)
299 throws RepositoryException
{
300 tk
.createLabel(parent
, "Manifest", SWT
.NONE
);
301 Hyperlink link
= tk
.createHyperlink(parent
, "MANIFEST.MF", SWT
.NONE
);
302 // link.addHyperlinkListener(new
303 // OpenFileLinkListener(bundle.getPath()));
306 private void createHyperlink(Composite parent
, String label
,
307 String jcrPropName
) throws RepositoryException
{
308 tk
.createLabel(parent
, label
, SWT
.NONE
);
309 if (bundle
.hasProperty(jcrPropName
)) {
310 final Hyperlink link
= tk
.createHyperlink(parent
, bundle
311 .getProperty(jcrPropName
).getString(), SWT
.NONE
);
312 link
.addHyperlinkListener(new AbstractHyperlinkListener() {
314 public void linkActivated(HyperlinkEvent e
) {
316 IWorkbenchBrowserSupport browserSupport
= PlatformUI
317 .getWorkbench().getBrowserSupport();
318 IWebBrowser browser
= browserSupport
320 IWorkbenchBrowserSupport
.LOCATION_BAR
321 | IWorkbenchBrowserSupport
.NAVIGATION_BAR
,
322 "SLC Distribution browser",
323 "SLC Distribution browser",
325 browser
.openURL(new URL(link
.getText()));
326 } catch (Exception ex
) {
327 throw new SlcException("error opening browser", ex
); //$NON-NLS-1$
332 tk
.createLabel(parent
, "N/A", SWT
.NONE
);
335 // helper to check if sources are available
336 private void addSourceLink(Composite parent
) {
338 String srcPath
= RepoUtils
.relatedPdeSourcePath(
339 RepoConstants
.DEFAULT_ARTIFACTS_BASE_PATH
, bundle
);
340 if (!bundle
.getSession().nodeExists(srcPath
)) {
341 createLT(parent
, "Sources", "N/A");
343 final Node sourcesNode
= bundle
.getSession().getNode(srcPath
);
345 String srcName
= null;
346 if (sourcesNode
.hasProperty(SlcNames
.SLC_SYMBOLIC_NAME
))
347 srcName
= sourcesNode
.getProperty(
348 SlcNames
.SLC_SYMBOLIC_NAME
).getString();
350 srcName
= sourcesNode
.getName();
351 Label label
= tk
.createLabel(parent
, "Sources", SWT
.RIGHT
);
352 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false,
354 final Hyperlink link
= tk
.createHyperlink(parent
, srcName
,
356 link
.addHyperlinkListener(new OpenFileLinkListener(sourcesNode
361 // public void linkActivated(HyperlinkEvent e) {
363 // ModuleEditorInput editorInput = (ModuleEditorInput)
365 // Map<String, String> params = new HashMap<String, String>();
366 // params.put(OpenJcrFile.PARAM_REPO_NODE_PATH,
367 // editorInput.getRepoNodePath());
368 // params.put(OpenJcrFile.PARAM_REPO_URI,
369 // editorInput.getUri());
370 // params.put(OpenJcrFile.PARAM_WORKSPACE_NAME,
371 // editorInput.getWorkspaceName());
372 // params.put(OpenJcrFile.PARAM_FILE_PATH,
374 // CommandUtils.callCommand(OpenJcrFile.ID, params);
375 // } catch (Exception ex) {
376 // throw new SlcException("error opening browser", ex); //$NON-NLS-1$
382 } catch (RepositoryException e
) {
383 throw new SlcException("Unable to configure sources link for "
388 private class OpenFileLinkListener
extends AbstractHyperlinkListener
{
389 final private String path
;
391 public OpenFileLinkListener(String path
) {
396 public void linkActivated(HyperlinkEvent e
) {
398 ModuleEditorInput editorInput
= (ModuleEditorInput
) getEditorInput();
399 Map
<String
, String
> params
= new HashMap
<String
, String
>();
400 params
.put(OpenJcrFile
.PARAM_REPO_NODE_PATH
,
401 editorInput
.getRepoNodePath());
402 params
.put(OpenJcrFile
.PARAM_REPO_URI
, editorInput
.getUri());
403 params
.put(OpenJcrFile
.PARAM_WORKSPACE_NAME
,
404 editorInput
.getWorkspaceName());
405 params
.put(OpenJcrFile
.PARAM_FILE_PATH
, path
);
407 String cmdId
= (new OpenJcrFileCmdId()).getCmdId();
408 if (log
.isTraceEnabled())
409 log
.debug("Retrieved openFile Cmd ID: " + cmdId
);
410 CommandUtils
.callCommand(cmdId
, params
);
411 } catch (Exception ex
) {
412 throw new SlcException("error opening browser", ex
); //$NON-NLS-1$
417 /** Creates a text area with corresponding maven snippet */
418 private Text
createMavenSnippet(Composite parent
) {
419 Text mavenSnippet
= new Text(parent
, SWT
.MULTI
| SWT
.WRAP
);
420 GridData gd
= new GridData(GridData
.FILL_HORIZONTAL
);
421 gd
.grabExcessHorizontalSpace
= true;
423 mavenSnippet
.setLayoutData(gd
);
424 mavenSnippet
.setText(generateXmlSnippet());
428 private String
generateXmlSnippet() {
430 StringBuffer sb
= new StringBuffer();
431 sb
.append("<dependency>\n");
432 sb
.append("\t<groupId>");
433 sb
.append(bundle
.getProperty(SLC_GROUP_ID
).getString());
434 sb
.append("</groupId>\n");
435 sb
.append("\t<artifactId>");
436 sb
.append(bundle
.getProperty(SLC_ARTIFACT_ID
).getString());
437 sb
.append("</artifactId>\n");
438 sb
.append("\t<version>");
439 sb
.append(bundle
.getProperty(SLC_ARTIFACT_VERSION
).getString());
440 sb
.append("</version>\n");
441 sb
.append("</dependency>");
442 return sb
.toString();
443 } catch (RepositoryException re
) {
444 throw new ArgeoException(
445 "unexpected error while generating maven snippet");