]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/BundleDetailsPage.java
Rough protection against too long workspaces name (causes trouble with PostgreSQL)
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / editors / BundleDetailsPage.java
index c9d927ba7c45979fb0f3a1d823a05653f76f55f6..b9e7ab30662bd947fcf5e0b3820acb3015509895 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.argeo.slc.client.ui.dist.editors;
 
+import java.net.URL;
 import java.util.List;
 
 import javax.jcr.Node;
@@ -27,8 +28,11 @@ import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.client.ui.dist.DistConstants;
 import org.argeo.slc.client.ui.dist.DistImages;
+import org.argeo.slc.client.ui.dist.utils.AbstractHyperlinkListener;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
+import org.argeo.slc.repo.RepoConstants;
+import org.argeo.slc.repo.RepoUtils;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -42,14 +46,20 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
 import org.eclipse.ui.forms.IManagedForm;
 import org.eclipse.ui.forms.editor.FormEditor;
 import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
 import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Hyperlink;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
 import org.eclipse.ui.forms.widgets.Section;
 
@@ -91,7 +101,7 @@ public class BundleDetailsPage extends FormPage implements SlcNames, SlcTypes {
                        createExportPackageSection(body);
                        createImportPackageSection(body);
                        createReqBundleSection(body);
-                       createMavenSnipet(body);
+                       createMavenSnippet(body);
 
                } catch (RepositoryException e) {
                        throw new SlcException("unexpected error "
@@ -109,13 +119,26 @@ public class BundleDetailsPage extends FormPage implements SlcNames, SlcTypes {
                createField(details, "Symbolic name", SlcNames.SLC_SYMBOLIC_NAME);
                createField(details, "Version", SlcNames.SLC_BUNDLE_VERSION);
                createField(details, "Group Id", SlcNames.SLC_GROUP_ID);
-               // Single sourcing issue: this does not works with rap
-               // createHyperlink(details, "Licence",
-               // DistConstants.SLC_BUNDLE_LICENCE);
-               createField(details, "Licence", DistConstants.SLC_BUNDLE_LICENCE);
-
+               createHyperlink(details, "Licence", DistConstants.SLC_BUNDLE_LICENCE);
                createField(details, "Vendor", DistConstants.SLC_BUNDLE_VENDOR);
+               addSourceAvailableLabel(details);
+
+       }
 
+       // helper to check if sources are available
+       private void addSourceAvailableLabel(Composite parent) {
+               Button srcChk = toolkit.createButton(parent, "Sources available",
+                               SWT.CHECK);
+               srcChk.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
+
+               try {
+                       String srcPath = RepoUtils.relatedPdeSourcePath(
+                                       RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH, currBundle);
+                       srcChk.setSelection(currBundle.getSession().nodeExists(srcPath));
+               } catch (RepositoryException e) {
+                       throw new SlcException("Unable to check sources", e);
+               }
+               srcChk.setEnabled(false);
        }
 
        // Workaround to add an artificial level to the export package browser
@@ -171,13 +194,9 @@ public class BundleDetailsPage extends FormPage implements SlcNames, SlcTypes {
                        public Image getImage(Object element) {
                                if (element instanceof Node) {
                                        try {
-
                                                Node node = (Node) element;
                                                if (node.isNodeType(SlcTypes.SLC_EXPORTED_PACKAGE))
                                                        return DistImages.IMG_PACKAGE;
-                                               else if (node.isNodeType(SlcTypes.SLC_JAVA_PACKAGE))
-                                                       return DistImages.IMG_PACKAGE;
-
                                        } catch (RepositoryException e) {
                                                throw new SlcException("Error retriving "
                                                                + "image for the labelProvider", e);
@@ -282,6 +301,11 @@ public class BundleDetailsPage extends FormPage implements SlcNames, SlcTypes {
                        public String getText(Object element) {
                                return JcrUtils.get((Node) element, SLC_NAME);
                        }
+
+                       public Image getImage(Object element) {
+                               return DistImages.IMG_PACKAGE;
+                       }
+
                });
 
                // Version
@@ -338,11 +362,16 @@ public class BundleDetailsPage extends FormPage implements SlcNames, SlcTypes {
                        public String getText(Object element) {
                                return JcrUtils.get((Node) element, SLC_SYMBOLIC_NAME);
                        }
+
+                       @Override
+                       public Image getImage(Object element) {
+                               return DistImages.IMG_BUNDLE;
+                       }
                });
 
                // Version
                col = new TableViewerColumn(viewer, SWT.NONE);
-               col.getColumn().setWidth(100);
+               col.getColumn().setWidth(140);
                col.getColumn().setText("Version");
                col.setLabelProvider(new ColumnLabelProvider() {
                        @Override
@@ -470,37 +499,37 @@ public class BundleDetailsPage extends FormPage implements SlcNames, SlcTypes {
                return section;
        }
 
-       // private void createHyperlink(Composite parent, String label,
-       // String jcrPropName) throws RepositoryException {
-       // toolkit.createLabel(parent, label, SWT.NONE);
-       // if (currBundle.hasProperty(jcrPropName)) {
-       // final Hyperlink link = toolkit.createHyperlink(parent, currBundle
-       // .getProperty(jcrPropName).getString(), SWT.NONE);
-       // link.addHyperlinkListener(new AbstractHyperlinkListener() {
-       // @Override
-       // public void linkActivated(HyperlinkEvent e) {
-       // try {
-       // IWorkbenchBrowserSupport browserSupport = PlatformUI
-       // .getWorkbench().getBrowserSupport();
-       // IWebBrowser browser = browserSupport
-       // .createBrowser(
-       // IWorkbenchBrowserSupport.LOCATION_BAR
-       // | IWorkbenchBrowserSupport.NAVIGATION_BAR,
-       // "SLC Distribution browser",
-       // "SLC Distribution browser",
-       // "A tool tip");
-       // browser.openURL(new URL(link.getText()));
-       // } catch (Exception ex) {
-       //                                              throw new SlcException("error opening browser", ex); //$NON-NLS-1$
-       // }
-       // }
-       // });
-       // } else
-       // toolkit.createLabel(parent, "", SWT.NONE);
-       // }
+       private void createHyperlink(Composite parent, String label,
+                       String jcrPropName) throws RepositoryException {
+               toolkit.createLabel(parent, label, SWT.NONE);
+               if (currBundle.hasProperty(jcrPropName)) {
+                       final Hyperlink link = toolkit.createHyperlink(parent, currBundle
+                                       .getProperty(jcrPropName).getString(), SWT.NONE);
+                       link.addHyperlinkListener(new AbstractHyperlinkListener() {
+                               @Override
+                               public void linkActivated(HyperlinkEvent e) {
+                                       try {
+                                               IWorkbenchBrowserSupport browserSupport = PlatformUI
+                                                               .getWorkbench().getBrowserSupport();
+                                               IWebBrowser browser = browserSupport
+                                                               .createBrowser(
+                                                                               IWorkbenchBrowserSupport.LOCATION_BAR
+                                                                                               | IWorkbenchBrowserSupport.NAVIGATION_BAR,
+                                                                               "SLC Distribution browser",
+                                                                               "SLC Distribution browser",
+                                                                               "A tool tip");
+                                               browser.openURL(new URL(link.getText()));
+                                       } catch (Exception ex) {
+                                               throw new SlcException("error opening browser", ex); //$NON-NLS-1$
+                                       }
+                               }
+                       });
+               } else
+                       toolkit.createLabel(parent, "", SWT.NONE);
+       }
 
        /** Creates a text area with corresponding maven snippet */
-       private void createMavenSnipet(Composite parent) {
+       private void createMavenSnippet(Composite parent) {
                mavenSnippet = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER);
                GridData gd = new GridData(GridData.FILL_HORIZONTAL);
                gd.grabExcessHorizontalSpace = true;
@@ -514,9 +543,9 @@ public class BundleDetailsPage extends FormPage implements SlcNames, SlcTypes {
                try {
                        StringBuffer sb = new StringBuffer();
                        sb.append("<dependency>\n");
-                       sb.append("\t<groupeId>");
+                       sb.append("\t<groupId>");
                        sb.append(currBundle.getProperty(SLC_GROUP_ID).getString());
-                       sb.append("</groupeId>\n");
+                       sb.append("</groupId>\n");
                        sb.append("\t<artifactId>");
                        sb.append(currBundle.getProperty(SLC_ARTIFACT_ID).getString());
                        sb.append("</artifactId>\n");