]>
git.argeo.org Git - gpl/argeo-suite.git/blob - DocumentsFileComposite.java
10cf3bd14f492b60d7fc68c8238d534be040bcf2
1 package org
.argeo
.library
.ui
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.Files
;
5 import java
.nio
.file
.Path
;
6 import java
.nio
.file
.spi
.FileSystemProvider
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.cms
.fs
.CmsFsUtils
;
14 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
15 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
16 import org
.argeo
.eclipse
.ui
.fs
.FsUiUtils
;
17 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.browser
.Browser
;
20 import org
.eclipse
.swt
.custom
.SashForm
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Label
;
27 * Default Documents file composite: a sashForm with a browser in the middle and
28 * meta data at right hand side.
30 public class DocumentsFileComposite
extends Composite
{
31 private static final long serialVersionUID
= -7567632342889241793L;
33 private final static Log log
= LogFactory
.getLog(DocumentsFileComposite
.class);
35 private final Node currentBaseContext
;
37 // UI Parts for the browser
38 private Composite rightPannelCmp
;
40 public DocumentsFileComposite(Composite parent
, int style
, Node context
,
41 FileSystemProvider fsp
) {
43 this.currentBaseContext
= context
;
44 this.setLayout(EclipseUiUtils
.noSpaceGridLayout());
45 SashForm form
= new SashForm(this, SWT
.HORIZONTAL
);
47 Composite centerCmp
= new Composite(form
, SWT
.BORDER
| SWT
.NO_FOCUS
);
48 createDisplay(centerCmp
);
50 rightPannelCmp
= new Composite(form
, SWT
.NO_FOCUS
);
52 Path path
= CmsFsUtils
.getPath(fsp
, context
);
53 setOverviewInput(path
);
54 form
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
55 form
.setWeights(new int[] { 55, 20 });
58 private void createDisplay(final Composite parent
) {
59 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
60 Browser browser
= new Browser(parent
, SWT
.NONE
);
61 // browser.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
63 browser
.setLayoutData(EclipseUiUtils
.fillAll());
65 // FIXME make it more robust
66 String url
= CmsUiUtils
.getDataUrl(currentBaseContext
, UiContext
.getHttpRequest());
67 // FIXME issue with the redirection to https
68 if (url
.startsWith("http://") && !url
.startsWith("http://localhost"))
69 url
= "https://" + url
.substring("http://".length(), url
.length());
70 if (log
.isTraceEnabled())
71 log
.debug("Trying to display " + url
);
73 browser
.layout(true, true);
74 } catch (RepositoryException re
) {
75 throw new IllegalStateException("Cannot open file at " + currentBaseContext
, re
);
80 * Recreates the content of the box that displays information about the current
83 private void setOverviewInput(Path path
) {
85 EclipseUiUtils
.clear(rightPannelCmp
);
86 rightPannelCmp
.setLayout(new GridLayout());
88 // if (isImg(context)) {
89 // EditableImage image = new Img(parent, RIGHT, context,
91 // image.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
96 Label contextL
= new Label(rightPannelCmp
, SWT
.NONE
);
97 contextL
.setText(path
.getFileName().toString());
98 contextL
.setFont(EclipseUiUtils
.getBoldFont(rightPannelCmp
));
99 addProperty(rightPannelCmp
, "Last modified", Files
.getLastModifiedTime(path
).toString());
100 // addProperty(rightPannelCmp, "Owner",
101 // Files.getOwner(path).getName());
102 if (Files
.isDirectory(path
)) {
103 addProperty(rightPannelCmp
, "Type", "Folder");
105 String mimeType
= Files
.probeContentType(path
);
106 if (EclipseUiUtils
.isEmpty(mimeType
))
107 mimeType
= "<i>Unknown</i>";
108 addProperty(rightPannelCmp
, "Type", mimeType
);
109 addProperty(rightPannelCmp
, "Size", FsUiUtils
.humanReadableByteCount(Files
.size(path
), false));
112 rightPannelCmp
.layout(true, true);
113 } catch (IOException e
) {
114 throw new IllegalStateException("Cannot display details for " + path
.toString(), e
);
118 // Simplify UI implementation
119 private void addProperty(Composite parent
, String propName
, String value
) {
120 Label propLbl
= new Label(parent
, SWT
.NONE
);
121 //propLbl.setText(ConnectUtils.replaceAmpersand(propName + ": " + value));
122 propLbl
.setText(value
);
123 //CmsUiUtils.markup(propLbl);