+ browserC.setLayoutData(gd);
+// wrapper.setLayoutData(CmsUiUtils.fillAll());
+ Browser browser = new Browser(browserC, SWT.NONE);
+
+ if (editable) {
+ Composite editor = new Composite(wrapper, SWT.BORDER);
+ editor.setLayout(new GridLayout(3, false));
+ editor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ String fileref = DbkUtils.getMediaFileref(mediaobject);
+ Text text = new Text(editor, SWT.SINGLE);
+ if (fileref != null)
+ text.setText(fileref);
+ else
+ text.setMessage("Embed URL of the video");
+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ Button updateB = new Button(editor, SWT.FLAT);
+ updateB.setText("Update");
+ updateB.addSelectionListener(new Selected() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ Node videodata = mediaobject.getNode(DbkType.videoobject.get())
+ .getNode(DbkType.videodata.get());
+ String txt = text.getText();
+ URI uri;
+ try {
+ uri = new URI(txt);
+ } catch (URISyntaxException e1) {
+ text.setText("");
+ text.setMessage("Invalid URL");
+ return;
+ }
+
+ // Transform watch URL in embed
+ // YouTube
+ String videoId = null;
+ if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())
+ || "youtu.be".equals(uri.getHost())) {
+ if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())) {
+ if ("/watch".equals(uri.getPath())) {
+ Map<String, List<String>> map = NamingUtils.queryToMap(uri);
+ videoId = map.get("v").get(0);
+ }
+ } else if ("youtu.be".equals(uri.getHost())) {
+ videoId = uri.getPath().substring(1);
+ }
+ if (videoId != null) {
+ try {
+ uri = new URI("https://www.youtube.com/embed/" + videoId);
+ text.setText(uri.toString());
+ } catch (URISyntaxException e1) {
+ throw new IllegalStateException(e1);
+ }
+ }
+ }
+
+ // Vimeo
+ if ("vimeo.com".equals(uri.getHost())) {
+ videoId = uri.getPath().substring(1);
+ if (videoId != null) {
+ try {
+ uri = new URI("https://player.vimeo.com/video/" + videoId);
+ text.setText(uri.toString());
+ } catch (URISyntaxException e1) {
+ throw new IllegalStateException(e1);
+ }
+ }
+ }
+
+ videodata.setProperty(DbkAttr.fileref.name(), uri.toString());
+ // TODO better integrate it in the edition lifecycle
+ videodata.getSession().save();
+ load(browser);
+ } catch (RepositoryException e1) {
+ throw new JcrException("Cannot update " + mediaobject, e1);
+ }
+
+ }
+ });
+
+ Button deleteB = new Button(editor, SWT.FLAT);
+ deleteB.setText("Delete");
+ deleteB.addSelectionListener(new Selected() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ mediaobject.remove();
+ Composite parent = getParent();
+ dispose();
+ parent.layout(true, true);
+ } catch (RepositoryException e1) {
+ throw new JcrException("Cannot update " + mediaobject, e1);
+ }
+
+ }
+ });
+ }
+
+ // TODO caption